1 .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.41)
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
9 .de Vb \" Begin verbatim text
14 .de Ve \" End verbatim text
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<>.
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
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
45 .\" Escape single quotes in literal strings from groff's Unicode transform.
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.
54 .\" Avoid warning from groff about undefined register 'F'.
58 .if \n(.g .if rF .nr rF 1
59 .if (\n(rF:(\n(.g==0)) \{\
62 . tm Index:\\$1\t\\n%\t"\\$2"
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
83 . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
89 . \" simple accents for nroff and troff
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'
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 \
133 .\" ========================================================================
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.
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
144 .IX Header "SYNOPSIS"
146 \& #include <openssl/ecdsa.h>
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);
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,
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);
166 \& ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
167 \& const BIGNUM *kinv, const BIGNUM *rp,
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);
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.
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).
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.
186 \&\fBECDSA_SIG_free()\fR frees the \fB\s-1ECDSA_SIG\s0\fR structure \fBsig\fR.
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
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.
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.
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
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.
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
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
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.
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.
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.
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.
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.
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).
246 .IX Header "RETURN VALUES"
247 \&\fBECDSA_SIG_new()\fR returns \s-1NULL\s0 if the allocation fails.
249 \&\fBECDSA_SIG_set0()\fR returns 1 on success or 0 on failure.
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.
254 \&\fBECDSA_size()\fR returns the maximum length signature or 0 on error.
256 \&\fBECDSA_sign()\fR, \fBECDSA_sign_ex()\fR and \fBECDSA_sign_setup()\fR return 1 if successful
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.
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).
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).
270 First step: create an \s-1EC_KEY\s0 object (note: this part is \fBnot\fR \s-1ECDSA\s0
278 \& eckey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
279 \& if (eckey == NULL)
281 \& if (EC_KEY_generate_key(eckey) == 0)
285 Second step: compute the \s-1ECDSA\s0 signature of a \s-1SHA\-256\s0 hash value
286 using \fBECDSA_do_sign()\fR:
289 \& sig = ECDSA_do_sign(digest, 32, eckey);
294 or using \fBECDSA_sign()\fR:
297 \& unsigned char *buffer, *pp;
300 \& buf_len = ECDSA_size(eckey);
301 \& buffer = OPENSSL_malloc(buf_len);
303 \& if (ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey) == 0)
307 Third step: verify the created \s-1ECDSA\s0 signature using \fBECDSA_do_verify()\fR:
310 \& ret = ECDSA_do_verify(digest, 32, sig, eckey);
313 or using \fBECDSA_verify()\fR:
316 \& ret = ECDSA_verify(0, digest, 32, buffer, buf_len, eckey);
319 and finally evaluate the return value:
323 \& /* signature ok */
324 \& else if (ret == 0)
325 \& /* incorrect signature */
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)
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)
341 .IX Header "COPYRIGHT"
342 Copyright 2004\-2020 The OpenSSL Project Authors. All Rights Reserved.
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>.