1 .\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35)
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'.
60 . tm Index:\\$1\t\\n%\t"\\$2"
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
79 . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
85 . \" simple accents for nroff and troff
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'
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 \
129 .\" ========================================================================
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.
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
140 .IX Header "SYNOPSIS"
142 \& #include <openssl/ecdsa.h>
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);
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,
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);
164 \& ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
165 \& const BIGNUM *kinv, const BIGNUM *rp,
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);
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.
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).
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.
184 \&\fIECDSA_SIG_free()\fR frees the \fB\s-1ECDSA_SIG\s0\fR structure \fBsig\fR.
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
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.
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.
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
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.
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.
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
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
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.
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.
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.
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.
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.
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).
251 .IX Header "RETURN VALUES"
252 \&\fIECDSA_SIG_new()\fR returns \s-1NULL\s0 if the allocation fails.
254 \&\fIECDSA_SIG_set0()\fR returns 1 on success or 0 on failure.
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.
259 \&\fIECDSA_size()\fR returns the maximum length signature or 0 on error.
261 \&\fIECDSA_sign()\fR, \fIECDSA_sign_ex()\fR and \fIECDSA_sign_setup()\fR return 1 if successful
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.
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).
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).
275 First step: create an \s-1EC_KEY\s0 object (note: this part is \fBnot\fR \s-1ECDSA\s0
283 \& eckey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
284 \& if (eckey == NULL)
286 \& if (EC_KEY_generate_key(eckey) == 0)
290 Second step: compute the \s-1ECDSA\s0 signature of a \s-1SHA\-256\s0 hash value
291 using \fIECDSA_do_sign()\fR:
294 \& sig = ECDSA_do_sign(digest, 32, eckey);
299 or using \fIECDSA_sign()\fR:
302 \& unsigned char *buffer, *pp;
305 \& buf_len = ECDSA_size(eckey);
306 \& buffer = OPENSSL_malloc(buf_len);
308 \& if (ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey) == 0)
312 Third step: verify the created \s-1ECDSA\s0 signature using \fIECDSA_do_verify()\fR:
315 \& ret = ECDSA_do_verify(digest, 32, sig, eckey);
318 or using \fIECDSA_verify()\fR:
321 \& ret = ECDSA_verify(0, digest, 32, buffer, buf_len, eckey);
324 and finally evaluate the return value:
328 \& /* signature ok */
329 \& else if (ret == 0)
330 \& /* incorrect signature */
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)
339 .IX Header "SEE ALSO"
340 \&\fIDSA_new\fR\|(3),
341 \&\fIEVP_DigestSignInit\fR\|(3),
342 \&\fIEVP_DigestVerifyInit\fR\|(3)
344 .IX Header "COPYRIGHT"
345 Copyright 2004\-2018 The OpenSSL Project Authors. All Rights Reserved.
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>.