]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - secure/lib/libcrypto/man/ECDSA_SIG_new.3
MFC: r340705, r340708
[FreeBSD/FreeBSD.git] / secure / lib / libcrypto / man / ECDSA_SIG_new.3
1 .\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
18 .\" Set up some character translations and predefined strings.  \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
29 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 .    ds C`
42 .    ds C'
43 'br\}
44 .\"
45 .\" Escape single quotes in literal strings from groff's Unicode transform.
46 .ie \n(.g .ds Aq \(aq
47 .el       .ds Aq '
48 .\"
49 .\" If the F register is >0, we'll generate index entries on stderr for
50 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
51 .\" entries marked with X<> in POD.  Of course, you'll have to process the
52 .\" output yourself in some meaningful fashion.
53 .\"
54 .\" Avoid warning from groff about undefined register 'F'.
55 .de IX
56 ..
57 .if !\nF .nr F 0
58 .if \nF>0 \{\
59 .    de IX
60 .    tm Index:\\$1\t\\n%\t"\\$2"
61 ..
62 .    if !\nF==2 \{\
63 .        nr % 0
64 .        nr F 2
65 .    \}
66 .\}
67 .\"
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
70 .    \" fudge factors for nroff and troff
71 .if n \{\
72 .    ds #H 0
73 .    ds #V .8m
74 .    ds #F .3m
75 .    ds #[ \f1
76 .    ds #] \fP
77 .\}
78 .if t \{\
79 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80 .    ds #V .6m
81 .    ds #F 0
82 .    ds #[ \&
83 .    ds #] \&
84 .\}
85 .    \" simple accents for nroff and troff
86 .if n \{\
87 .    ds ' \&
88 .    ds ` \&
89 .    ds ^ \&
90 .    ds , \&
91 .    ds ~ ~
92 .    ds /
93 .\}
94 .if t \{\
95 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101 .\}
102 .    \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 .    \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 .    \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
117 \{\
118 .    ds : e
119 .    ds 8 ss
120 .    ds o a
121 .    ds d- d\h'-1'\(ga
122 .    ds D- D\h'-1'\(hy
123 .    ds th \o'bp'
124 .    ds Th \o'LP'
125 .    ds ae ae
126 .    ds Ae AE
127 .\}
128 .rm #[ #] #H #V #F C
129 .\" ========================================================================
130 .\"
131 .IX Title "ECDSA_SIG_NEW 3"
132 .TH ECDSA_SIG_NEW 3 "2018-11-20" "1.1.1a" "OpenSSL"
133 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
134 .\" way too many mistakes in technical documents.
135 .if n .ad l
136 .nh
137 .SH "NAME"
138 ECDSA_SIG_get0, ECDSA_SIG_get0_r, ECDSA_SIG_get0_s, ECDSA_SIG_set0, ECDSA_SIG_new, ECDSA_SIG_free, i2d_ECDSA_SIG, d2i_ECDSA_SIG, ECDSA_size, ECDSA_sign, ECDSA_do_sign, ECDSA_verify, ECDSA_do_verify, ECDSA_sign_setup, ECDSA_sign_ex, ECDSA_do_sign_ex \- low level elliptic curve digital signature algorithm (ECDSA) functions
139 .SH "SYNOPSIS"
140 .IX Header "SYNOPSIS"
141 .Vb 1
142 \& #include <openssl/ecdsa.h>
143 \&
144 \& ECDSA_SIG *ECDSA_SIG_new(void);
145 \& void ECDSA_SIG_free(ECDSA_SIG *sig);
146 \& void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
147 \& const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig);
148 \& const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig);
149 \& int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
150 \& int i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp);
151 \& ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp, long len);
152 \& int ECDSA_size(const EC_KEY *eckey);
153 \&
154 \& int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen,
155 \&                unsigned char *sig, unsigned int *siglen, EC_KEY *eckey);
156 \& ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len,
157 \&                          EC_KEY *eckey);
158 \&
159 \& int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen,
160 \&                  const unsigned char *sig, int siglen, EC_KEY *eckey);
161 \& int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
162 \&                     const ECDSA_SIG *sig, EC_KEY* eckey);
163 \&
164 \& ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
165 \&                             const BIGNUM *kinv, const BIGNUM *rp,
166 \&                             EC_KEY *eckey);
167 \& int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp);
168 \& int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen,
169 \&                   unsigned char *sig, unsigned int *siglen,
170 \&                   const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey);
171 .Ve
172 .SH "DESCRIPTION"
173 .IX Header "DESCRIPTION"
174 Note: these functions provide a low level interface to \s-1ECDSA.\s0 Most
175 applications should use the higher level \fB\s-1EVP\s0\fR interface such as
176 \&\fIEVP_DigestSignInit\fR\|(3) or \fIEVP_DigestVerifyInit\fR\|(3) instead.
177 .PP
178 \&\fB\s-1ECDSA_SIG\s0\fR is an opaque structure consisting of two BIGNUMs for the
179 \&\fBr\fR and \fBs\fR value of an \s-1ECDSA\s0 signature (see X9.62 or \s-1FIPS 186\-2\s0).
180 .PP
181 \&\fIECDSA_SIG_new()\fR allocates an empty \fB\s-1ECDSA_SIG\s0\fR structure. Note: before
182 OpenSSL 1.1.0 the: the \fBr\fR and \fBs\fR components were initialised.
183 .PP
184 \&\fIECDSA_SIG_free()\fR frees the \fB\s-1ECDSA_SIG\s0\fR structure \fBsig\fR.
185 .PP
186 \&\fIECDSA_SIG_get0()\fR returns internal pointers the \fBr\fR and \fBs\fR values contained
187 in \fBsig\fR and stores them in \fB*pr\fR and \fB*ps\fR, respectively.
188 The pointer \fBpr\fR or \fBps\fR can be \s-1NULL,\s0 in which case the corresponding value
189 is not returned.
190 .PP
191 The values \fBr\fR, \fBs\fR can also be retrieved separately by the corresponding
192 function \fIECDSA_SIG_get0_r()\fR and \fIECDSA_SIG_get0_s()\fR, respectively.
193 .PP
194 The \fBr\fR and \fBs\fR values can be set by calling \fIECDSA_SIG_set0()\fR and passing the
195 new values for \fBr\fR and \fBs\fR as parameters to the function. Calling this
196 function transfers the memory management of the values to the \s-1ECDSA_SIG\s0 object,
197 and therefore the values that have been passed in should not be freed directly
198 after this function has been called.
199 .PP
200 \&\fIi2d_ECDSA_SIG()\fR creates the \s-1DER\s0 encoding of the \s-1ECDSA\s0 signature \fBsig\fR and
201 writes the encoded signature to \fB*pp\fR (note: if \fBpp\fR is \s-1NULL\s0 \fIi2d_ECDSA_SIG()\fR
202 returns the expected length in bytes of the \s-1DER\s0 encoded signature).
203 \&\fIi2d_ECDSA_SIG()\fR returns the length of the \s-1DER\s0 encoded signature (or 0 on
204 error).
205 .PP
206 \&\fId2i_ECDSA_SIG()\fR decodes a \s-1DER\s0 encoded \s-1ECDSA\s0 signature and returns the decoded
207 signature in a newly allocated \fB\s-1ECDSA_SIG\s0\fR structure. \fB*sig\fR points to the
208 buffer containing the \s-1DER\s0 encoded signature of size \fBlen\fR.
209 .PP
210 \&\fIECDSA_size()\fR returns the maximum length of a \s-1DER\s0 encoded \s-1ECDSA\s0 signature
211 created with the private \s-1EC\s0 key \fBeckey\fR.
212 .PP
213 \&\fIECDSA_sign()\fR computes a digital signature of the \fBdgstlen\fR bytes hash value
214 \&\fBdgst\fR using the private \s-1EC\s0 key \fBeckey\fR. The \s-1DER\s0 encoded signatures is
215 stored in \fBsig\fR and its length is returned in \fBsig_len\fR. Note: \fBsig\fR must
216 point to ECDSA_size(eckey) bytes of memory. The parameter \fBtype\fR is currently
217 ignored. \fIECDSA_sign()\fR is wrapper function for \fIECDSA_sign_ex()\fR with \fBkinv\fR
218 and \fBrp\fR set to \s-1NULL.\s0
219 .PP
220 \&\fIECDSA_do_sign()\fR is similar to \fIECDSA_sign()\fR except the signature is returned
221 as a newly allocated \fB\s-1ECDSA_SIG\s0\fR structure (or \s-1NULL\s0 on error). \fIECDSA_do_sign()\fR
222 is a wrapper function for \fIECDSA_do_sign_ex()\fR with \fBkinv\fR and \fBrp\fR set to
223 \&\s-1NULL.\s0
224 .PP
225 \&\fIECDSA_verify()\fR verifies that the signature in \fBsig\fR of size \fBsiglen\fR is a
226 valid \s-1ECDSA\s0 signature of the hash value \fBdgst\fR of size \fBdgstlen\fR using the
227 public key \fBeckey\fR.  The parameter \fBtype\fR is ignored.
228 .PP
229 \&\fIECDSA_do_verify()\fR is similar to \fIECDSA_verify()\fR except the signature is
230 presented in the form of a pointer to an \fB\s-1ECDSA_SIG\s0\fR structure.
231 .PP
232 The remaining functions utilise the internal \fBkinv\fR and \fBr\fR values used
233 during signature computation. Most applications will never need to call these
234 and some external \s-1ECDSA ENGINE\s0 implementations may not support them at all if
235 either \fBkinv\fR or \fBr\fR is not \fB\s-1NULL\s0\fR.
236 .PP
237 \&\fIECDSA_sign_setup()\fR may be used to precompute parts of the signing operation.
238 \&\fBeckey\fR is the private \s-1EC\s0 key and \fBctx\fR is a pointer to \fB\s-1BN_CTX\s0\fR structure
239 (or \s-1NULL\s0). The precomputed values or returned in \fBkinv\fR and \fBrp\fR and can be
240 used in a later call to \fIECDSA_sign_ex()\fR or \fIECDSA_do_sign_ex()\fR.
241 .PP
242 \&\fIECDSA_sign_ex()\fR computes a digital signature of the \fBdgstlen\fR bytes hash value
243 \&\fBdgst\fR using the private \s-1EC\s0 key \fBeckey\fR and the optional pre-computed values
244 \&\fBkinv\fR and \fBrp\fR. The \s-1DER\s0 encoded signature is stored in \fBsig\fR and its
245 length is returned in \fBsig_len\fR. Note: \fBsig\fR must point to ECDSA_size(eckey)
246 bytes of memory. The parameter \fBtype\fR is ignored.
247 .PP
248 \&\fIECDSA_do_sign_ex()\fR is similar to \fIECDSA_sign_ex()\fR except the signature is
249 returned as a newly allocated \fB\s-1ECDSA_SIG\s0\fR structure (or \s-1NULL\s0 on error).
250 .SH "RETURN VALUES"
251 .IX Header "RETURN VALUES"
252 \&\fIECDSA_SIG_new()\fR returns \s-1NULL\s0 if the allocation fails.
253 .PP
254 \&\fIECDSA_SIG_set0()\fR returns 1 on success or 0 on failure.
255 .PP
256 \&\fIECDSA_SIG_get0_r()\fR and \fIECDSA_SIG_get0_s()\fR return the corresponding value,
257 or \s-1NULL\s0 if it is unset.
258 .PP
259 \&\fIECDSA_size()\fR returns the maximum length signature or 0 on error.
260 .PP
261 \&\fIECDSA_sign()\fR, \fIECDSA_sign_ex()\fR and \fIECDSA_sign_setup()\fR return 1 if successful
262 or 0 on error.
263 .PP
264 \&\fIECDSA_do_sign()\fR and \fIECDSA_do_sign_ex()\fR return a pointer to an allocated
265 \&\fB\s-1ECDSA_SIG\s0\fR structure or \s-1NULL\s0 on error.
266 .PP
267 \&\fIECDSA_verify()\fR and \fIECDSA_do_verify()\fR return 1 for a valid
268 signature, 0 for an invalid signature and \-1 on error.
269 The error codes can be obtained by \fIERR_get_error\fR\|(3).
270 .SH "EXAMPLES"
271 .IX Header "EXAMPLES"
272 Creating an \s-1ECDSA\s0 signature of a given \s-1SHA\-256\s0 hash value using the
273 named curve prime256v1 (aka P\-256).
274 .PP
275 First step: create an \s-1EC_KEY\s0 object (note: this part is \fBnot\fR \s-1ECDSA\s0
276 specific)
277 .PP
278 .Vb 3
279 \& int ret;
280 \& ECDSA_SIG *sig;
281 \& EC_KEY *eckey;
282 \&
283 \& eckey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
284 \& if (eckey == NULL)
285 \&     /* error */
286 \& if (EC_KEY_generate_key(eckey) == 0)
287 \&     /* error */
288 .Ve
289 .PP
290 Second step: compute the \s-1ECDSA\s0 signature of a \s-1SHA\-256\s0 hash value
291 using \fIECDSA_do_sign()\fR:
292 .PP
293 .Vb 3
294 \& sig = ECDSA_do_sign(digest, 32, eckey);
295 \& if (sig == NULL)
296 \&     /* error */
297 .Ve
298 .PP
299 or using \fIECDSA_sign()\fR:
300 .PP
301 .Vb 2
302 \& unsigned char *buffer, *pp;
303 \& int buf_len;
304 \&
305 \& buf_len = ECDSA_size(eckey);
306 \& buffer = OPENSSL_malloc(buf_len);
307 \& pp = buffer;
308 \& if (ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey) == 0)
309 \&     /* error */
310 .Ve
311 .PP
312 Third step: verify the created \s-1ECDSA\s0 signature using \fIECDSA_do_verify()\fR:
313 .PP
314 .Vb 1
315 \& ret = ECDSA_do_verify(digest, 32, sig, eckey);
316 .Ve
317 .PP
318 or using \fIECDSA_verify()\fR:
319 .PP
320 .Vb 1
321 \& ret = ECDSA_verify(0, digest, 32, buffer, buf_len, eckey);
322 .Ve
323 .PP
324 and finally evaluate the return value:
325 .PP
326 .Vb 6
327 \& if (ret == 1)
328 \&     /* signature ok */
329 \& else if (ret == 0)
330 \&     /* incorrect signature */
331 \& else
332 \&     /* error */
333 .Ve
334 .SH "CONFORMING TO"
335 .IX Header "CONFORMING TO"
336 \&\s-1ANSI X9.62, US\s0 Federal Information Processing Standard \s-1FIPS 186\-2\s0
337 (Digital Signature Standard, \s-1DSS\s0)
338 .SH "SEE ALSO"
339 .IX Header "SEE ALSO"
340 \&\fIDSA_new\fR\|(3),
341 \&\fIEVP_DigestSignInit\fR\|(3),
342 \&\fIEVP_DigestVerifyInit\fR\|(3)
343 .SH "COPYRIGHT"
344 .IX Header "COPYRIGHT"
345 Copyright 2004\-2018 The OpenSSL Project Authors. All Rights Reserved.
346 .PP
347 Licensed under the OpenSSL license (the \*(L"License\*(R").  You may not use
348 this file except in compliance with the License.  You can obtain a copy
349 in the file \s-1LICENSE\s0 in the source distribution or at
350 <https://www.openssl.org/source/license.html>.