]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - secure/lib/libcrypto/man/man3/ECDSA_SIG_new.3
Merge OpenSSL 1.1.1i.
[FreeBSD/FreeBSD.git] / secure / lib / libcrypto / man / man3 / ECDSA_SIG_new.3
1 .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.41)
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 .nr rF 0
58 .if \n(.g .if rF .nr rF 1
59 .if (\n(rF:(\n(.g==0)) \{\
60 .    if \nF \{\
61 .        de IX
62 .        tm Index:\\$1\t\\n%\t"\\$2"
63 ..
64 .        if !\nF==2 \{\
65 .            nr % 0
66 .            nr F 2
67 .        \}
68 .    \}
69 .\}
70 .rr rF
71 .\"
72 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
73 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
74 .    \" fudge factors for nroff and troff
75 .if n \{\
76 .    ds #H 0
77 .    ds #V .8m
78 .    ds #F .3m
79 .    ds #[ \f1
80 .    ds #] \fP
81 .\}
82 .if t \{\
83 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
84 .    ds #V .6m
85 .    ds #F 0
86 .    ds #[ \&
87 .    ds #] \&
88 .\}
89 .    \" simple accents for nroff and troff
90 .if n \{\
91 .    ds ' \&
92 .    ds ` \&
93 .    ds ^ \&
94 .    ds , \&
95 .    ds ~ ~
96 .    ds /
97 .\}
98 .if t \{\
99 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
100 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
101 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
102 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
103 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
104 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
105 .\}
106 .    \" troff and (daisy-wheel) nroff accents
107 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
108 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
109 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
110 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
111 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
112 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
113 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
114 .ds ae a\h'-(\w'a'u*4/10)'e
115 .ds Ae A\h'-(\w'A'u*4/10)'E
116 .    \" corrections for vroff
117 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
118 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
119 .    \" for low resolution devices (crt and lpr)
120 .if \n(.H>23 .if \n(.V>19 \
121 \{\
122 .    ds : e
123 .    ds 8 ss
124 .    ds o a
125 .    ds d- d\h'-1'\(ga
126 .    ds D- D\h'-1'\(hy
127 .    ds th \o'bp'
128 .    ds Th \o'LP'
129 .    ds ae ae
130 .    ds Ae AE
131 .\}
132 .rm #[ #] #H #V #F C
133 .\" ========================================================================
134 .\"
135 .IX Title "ECDSA_SIG_NEW 3"
136 .TH ECDSA_SIG_NEW 3 "2020-12-08" "1.1.1i" "OpenSSL"
137 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
138 .\" way too many mistakes in technical documents.
139 .if n .ad l
140 .nh
141 .SH "NAME"
142 ECDSA_SIG_get0, ECDSA_SIG_get0_r, ECDSA_SIG_get0_s, ECDSA_SIG_set0, ECDSA_SIG_new, ECDSA_SIG_free, 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
143 .SH "SYNOPSIS"
144 .IX Header "SYNOPSIS"
145 .Vb 1
146 \& #include <openssl/ecdsa.h>
147 \&
148 \& ECDSA_SIG *ECDSA_SIG_new(void);
149 \& void ECDSA_SIG_free(ECDSA_SIG *sig);
150 \& void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
151 \& const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig);
152 \& const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig);
153 \& int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
154 \& int ECDSA_size(const EC_KEY *eckey);
155 \&
156 \& int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen,
157 \&                unsigned char *sig, unsigned int *siglen, EC_KEY *eckey);
158 \& ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len,
159 \&                          EC_KEY *eckey);
160 \&
161 \& int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen,
162 \&                  const unsigned char *sig, int siglen, EC_KEY *eckey);
163 \& int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
164 \&                     const ECDSA_SIG *sig, EC_KEY* eckey);
165 \&
166 \& ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
167 \&                             const BIGNUM *kinv, const BIGNUM *rp,
168 \&                             EC_KEY *eckey);
169 \& int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp);
170 \& int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen,
171 \&                   unsigned char *sig, unsigned int *siglen,
172 \&                   const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey);
173 .Ve
174 .SH "DESCRIPTION"
175 .IX Header "DESCRIPTION"
176 Note: these functions provide a low-level interface to \s-1ECDSA.\s0 Most
177 applications should use the higher level \fB\s-1EVP\s0\fR interface such as
178 \&\fBEVP_DigestSignInit\fR\|(3) or \fBEVP_DigestVerifyInit\fR\|(3) instead.
179 .PP
180 \&\fB\s-1ECDSA_SIG\s0\fR is an opaque structure consisting of two BIGNUMs for the
181 \&\fBr\fR and \fBs\fR value of an \s-1ECDSA\s0 signature (see X9.62 or \s-1FIPS 186\-2\s0).
182 .PP
183 \&\fBECDSA_SIG_new()\fR allocates an empty \fB\s-1ECDSA_SIG\s0\fR structure. Note: before
184 OpenSSL 1.1.0 the: the \fBr\fR and \fBs\fR components were initialised.
185 .PP
186 \&\fBECDSA_SIG_free()\fR frees the \fB\s-1ECDSA_SIG\s0\fR structure \fBsig\fR.
187 .PP
188 \&\fBECDSA_SIG_get0()\fR returns internal pointers the \fBr\fR and \fBs\fR values contained
189 in \fBsig\fR and stores them in \fB*pr\fR and \fB*ps\fR, respectively.
190 The pointer \fBpr\fR or \fBps\fR can be \s-1NULL,\s0 in which case the corresponding value
191 is not returned.
192 .PP
193 The values \fBr\fR, \fBs\fR can also be retrieved separately by the corresponding
194 function \fBECDSA_SIG_get0_r()\fR and \fBECDSA_SIG_get0_s()\fR, respectively.
195 .PP
196 The \fBr\fR and \fBs\fR values can be set by calling \fBECDSA_SIG_set0()\fR and passing the
197 new values for \fBr\fR and \fBs\fR as parameters to the function. Calling this
198 function transfers the memory management of the values to the \s-1ECDSA_SIG\s0 object,
199 and therefore the values that have been passed in should not be freed directly
200 after this function has been called.
201 .PP
202 See \fBi2d_ECDSA_SIG\fR\|(3) and \fBd2i_ECDSA_SIG\fR\|(3) for information about encoding
203 and decoding \s-1ECDSA\s0 signatures to/from \s-1DER.\s0
204 .PP
205 \&\fBECDSA_size()\fR returns the maximum length of a \s-1DER\s0 encoded \s-1ECDSA\s0 signature
206 created with the private \s-1EC\s0 key \fBeckey\fR.
207 .PP
208 \&\fBECDSA_sign()\fR computes a digital signature of the \fBdgstlen\fR bytes hash value
209 \&\fBdgst\fR using the private \s-1EC\s0 key \fBeckey\fR. The \s-1DER\s0 encoded signatures is
210 stored in \fBsig\fR and its length is returned in \fBsig_len\fR. Note: \fBsig\fR must
211 point to ECDSA_size(eckey) bytes of memory. The parameter \fBtype\fR is currently
212 ignored. \fBECDSA_sign()\fR is wrapper function for \fBECDSA_sign_ex()\fR with \fBkinv\fR
213 and \fBrp\fR set to \s-1NULL.\s0
214 .PP
215 \&\fBECDSA_do_sign()\fR is similar to \fBECDSA_sign()\fR except the signature is returned
216 as a newly allocated \fB\s-1ECDSA_SIG\s0\fR structure (or \s-1NULL\s0 on error). \fBECDSA_do_sign()\fR
217 is a wrapper function for \fBECDSA_do_sign_ex()\fR with \fBkinv\fR and \fBrp\fR set to
218 \&\s-1NULL.\s0
219 .PP
220 \&\fBECDSA_verify()\fR verifies that the signature in \fBsig\fR of size \fBsiglen\fR is a
221 valid \s-1ECDSA\s0 signature of the hash value \fBdgst\fR of size \fBdgstlen\fR using the
222 public key \fBeckey\fR.  The parameter \fBtype\fR is ignored.
223 .PP
224 \&\fBECDSA_do_verify()\fR is similar to \fBECDSA_verify()\fR except the signature is
225 presented in the form of a pointer to an \fB\s-1ECDSA_SIG\s0\fR structure.
226 .PP
227 The remaining functions utilise the internal \fBkinv\fR and \fBr\fR values used
228 during signature computation. Most applications will never need to call these
229 and some external \s-1ECDSA ENGINE\s0 implementations may not support them at all if
230 either \fBkinv\fR or \fBr\fR is not \fB\s-1NULL\s0\fR.
231 .PP
232 \&\fBECDSA_sign_setup()\fR may be used to precompute parts of the signing operation.
233 \&\fBeckey\fR is the private \s-1EC\s0 key and \fBctx\fR is a pointer to \fB\s-1BN_CTX\s0\fR structure
234 (or \s-1NULL\s0). The precomputed values or returned in \fBkinv\fR and \fBrp\fR and can be
235 used in a later call to \fBECDSA_sign_ex()\fR or \fBECDSA_do_sign_ex()\fR.
236 .PP
237 \&\fBECDSA_sign_ex()\fR computes a digital signature of the \fBdgstlen\fR bytes hash value
238 \&\fBdgst\fR using the private \s-1EC\s0 key \fBeckey\fR and the optional pre-computed values
239 \&\fBkinv\fR and \fBrp\fR. The \s-1DER\s0 encoded signature is stored in \fBsig\fR and its
240 length is returned in \fBsig_len\fR. Note: \fBsig\fR must point to ECDSA_size(eckey)
241 bytes of memory. The parameter \fBtype\fR is ignored.
242 .PP
243 \&\fBECDSA_do_sign_ex()\fR is similar to \fBECDSA_sign_ex()\fR except the signature is
244 returned as a newly allocated \fB\s-1ECDSA_SIG\s0\fR structure (or \s-1NULL\s0 on error).
245 .SH "RETURN VALUES"
246 .IX Header "RETURN VALUES"
247 \&\fBECDSA_SIG_new()\fR returns \s-1NULL\s0 if the allocation fails.
248 .PP
249 \&\fBECDSA_SIG_set0()\fR returns 1 on success or 0 on failure.
250 .PP
251 \&\fBECDSA_SIG_get0_r()\fR and \fBECDSA_SIG_get0_s()\fR return the corresponding value,
252 or \s-1NULL\s0 if it is unset.
253 .PP
254 \&\fBECDSA_size()\fR returns the maximum length signature or 0 on error.
255 .PP
256 \&\fBECDSA_sign()\fR, \fBECDSA_sign_ex()\fR and \fBECDSA_sign_setup()\fR return 1 if successful
257 or 0 on error.
258 .PP
259 \&\fBECDSA_do_sign()\fR and \fBECDSA_do_sign_ex()\fR return a pointer to an allocated
260 \&\fB\s-1ECDSA_SIG\s0\fR structure or \s-1NULL\s0 on error.
261 .PP
262 \&\fBECDSA_verify()\fR and \fBECDSA_do_verify()\fR return 1 for a valid
263 signature, 0 for an invalid signature and \-1 on error.
264 The error codes can be obtained by \fBERR_get_error\fR\|(3).
265 .SH "EXAMPLES"
266 .IX Header "EXAMPLES"
267 Creating an \s-1ECDSA\s0 signature of a given \s-1SHA\-256\s0 hash value using the
268 named curve prime256v1 (aka P\-256).
269 .PP
270 First step: create an \s-1EC_KEY\s0 object (note: this part is \fBnot\fR \s-1ECDSA\s0
271 specific)
272 .PP
273 .Vb 3
274 \& int ret;
275 \& ECDSA_SIG *sig;
276 \& EC_KEY *eckey;
277 \&
278 \& eckey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
279 \& if (eckey == NULL)
280 \&     /* error */
281 \& if (EC_KEY_generate_key(eckey) == 0)
282 \&     /* error */
283 .Ve
284 .PP
285 Second step: compute the \s-1ECDSA\s0 signature of a \s-1SHA\-256\s0 hash value
286 using \fBECDSA_do_sign()\fR:
287 .PP
288 .Vb 3
289 \& sig = ECDSA_do_sign(digest, 32, eckey);
290 \& if (sig == NULL)
291 \&     /* error */
292 .Ve
293 .PP
294 or using \fBECDSA_sign()\fR:
295 .PP
296 .Vb 2
297 \& unsigned char *buffer, *pp;
298 \& int buf_len;
299 \&
300 \& buf_len = ECDSA_size(eckey);
301 \& buffer = OPENSSL_malloc(buf_len);
302 \& pp = buffer;
303 \& if (ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey) == 0)
304 \&     /* error */
305 .Ve
306 .PP
307 Third step: verify the created \s-1ECDSA\s0 signature using \fBECDSA_do_verify()\fR:
308 .PP
309 .Vb 1
310 \& ret = ECDSA_do_verify(digest, 32, sig, eckey);
311 .Ve
312 .PP
313 or using \fBECDSA_verify()\fR:
314 .PP
315 .Vb 1
316 \& ret = ECDSA_verify(0, digest, 32, buffer, buf_len, eckey);
317 .Ve
318 .PP
319 and finally evaluate the return value:
320 .PP
321 .Vb 6
322 \& if (ret == 1)
323 \&     /* signature ok */
324 \& else if (ret == 0)
325 \&     /* incorrect signature */
326 \& else
327 \&     /* error */
328 .Ve
329 .SH "CONFORMING TO"
330 .IX Header "CONFORMING TO"
331 \&\s-1ANSI X9.62, US\s0 Federal Information Processing Standard \s-1FIPS 186\-2\s0
332 (Digital Signature Standard, \s-1DSS\s0)
333 .SH "SEE ALSO"
334 .IX Header "SEE ALSO"
335 \&\fBEC_KEY_new\fR\|(3),
336 \&\fBEVP_DigestSignInit\fR\|(3),
337 \&\fBEVP_DigestVerifyInit\fR\|(3),
338 \&\fBi2d_ECDSA_SIG\fR\|(3),
339 \&\fBd2i_ECDSA_SIG\fR\|(3)
340 .SH "COPYRIGHT"
341 .IX Header "COPYRIGHT"
342 Copyright 2004\-2020 The OpenSSL Project Authors. All Rights Reserved.
343 .PP
344 Licensed under the OpenSSL license (the \*(L"License\*(R").  You may not use
345 this file except in compliance with the License.  You can obtain a copy
346 in the file \s-1LICENSE\s0 in the source distribution or at
347 <https://www.openssl.org/source/license.html>.