1 .\" $OpenBSD: ECDSA_SIG_new.3,v 1.8 2017/01/06 20:35:23 schwarze Exp $
2 .\" OpenSSL e6390aca Jul 21 10:06:03 2015 -0400
4 .\" This file was written by Nils Larsch <nils@openssl.org>.
5 .\" Copyright (c) 2004, 2005, 2012, 2013 The OpenSSL Project.
6 .\" All rights reserved.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\" notice, this list of conditions and the following disclaimer in
17 .\" the documentation and/or other materials provided with the
20 .\" 3. All advertising materials mentioning features or use of this
21 .\" software must display the following acknowledgment:
22 .\" "This product includes software developed by the OpenSSL Project
23 .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 .\" endorse or promote products derived from this software without
27 .\" prior written permission. For written permission, please contact
28 .\" openssl-core@openssl.org.
30 .\" 5. Products derived from this software may not be called "OpenSSL"
31 .\" nor may "OpenSSL" appear in their names without prior written
32 .\" permission of the OpenSSL Project.
34 .\" 6. Redistributions of any form whatsoever must retain the following
36 .\" "This product includes software developed by the OpenSSL Project
37 .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
52 .Dd $Mdocdate: January 6 2017 $
61 .Nm ECDSA_sign_setup ,
66 .Nm ECDSA_do_sign_ex ,
69 .Nm ECDSA_get_default_method ,
70 .Nm ECDSA_set_default_method ,
72 .Nd Elliptic Curve Digital Signature Algorithm
85 .Fa "const ECDSA_SIG *sig"
86 .Fa "unsigned char **pp"
91 .Fa "const unsigned char **pp"
96 .Fa "const EC_KEY *eckey"
108 .Fa "const unsigned char *dgst"
110 .Fa "unsigned char *sig"
111 .Fa "unsigned int *siglen"
117 .Fa "const unsigned char *dgst"
119 .Fa "unsigned char *sig"
120 .Fa "unsigned int *siglen"
121 .Fa "const BIGNUM *kinv"
122 .Fa "const BIGNUM *rp"
128 .Fa "const unsigned char *dgst"
130 .Fa "const unsigned char *sig"
136 .Fa "const unsigned char *dgst"
142 .Fa "const unsigned char *dgst"
144 .Fa "const BIGNUM *kinv"
145 .Fa "const BIGNUM *rp"
150 .Fa "const unsigned char *dgst"
152 .Fa "const ECDSA_SIG *sig"
155 .Ft const ECDSA_METHOD*
159 .Ft const ECDSA_METHOD*
160 .Fo ECDSA_get_default_method
164 .Fo ECDSA_set_default_method
165 .Fa "const ECDSA_METHOD *meth"
170 .Fa "const ECDSA_METHOD *meth"
173 These functions provide a low level interface to ECDSA.
174 Most applications should use the higher level EVP interface such as
175 .Xr EVP_DigestSignInit 3
177 .Xr EVP_DigestVerifyInit 3
179 Creation of the required
181 objects is described in
186 structure consists of two
192 value of an ECDSA signature (see X9.62 or FIPS 186-2).
193 .Bd -literal -offset indent
203 structure (note: this function also allocates the
214 creates the DER encoding of the ECDSA signature
216 and writes the encoded signature to
223 returns the expected length in bytes of the DER-encoded signature).
225 returns the length of the DER-encoded signature (or 0 on error).
228 decodes a DER-encoded ECDSA signature and returns the decoded signature
233 points to the buffer containing the DER-encoded signature of size
237 returns the maximum length of a DER-encoded ECDSA signature created with
242 may be used to precompute parts of the signing operation.
244 is the private EC key and
250 The precomputed values are returned in
254 and can be used in a later call to
257 .Fa ECDSA_do_sign_ex .
260 is a wrapper function for
270 computes a digital signature of the
274 using the private EC key
276 and the optional pre-computed values
280 The DER-encoded signature is stored in
282 and its length is returned in
294 verifies that the signature in
298 is a valid ECDSA signature of the hash value
309 is a wrapper function for
319 computes a digital signature of the
323 using the private key
325 and the optional pre-computed values
329 The signature is returned in a newly allocated
336 verifies that the signature
338 is a valid ECDSA signature of the hash value
346 returns the maximum length signature or 0 on error.
352 return 1 if successful or 0 on error.
357 return a pointer to an allocated
366 return 1 for a valid signature, 0 for an invalid signature and -1 on
368 The error codes can be obtained by
369 .Xr ERR_get_error 3 .
371 Creating an ECDSA signature of given SHA-1 hash value using the named
374 First step: create an
380 .Bd -literal -offset indent
385 eckey = EC_KEY_new_by_curve_name(NID_secp192k1);
389 if (!EC_KEY_generate_key(eckey)) {
394 Second step: compute the ECDSA signature of a SHA-1 hash value using
396 .Bd -literal -offset indent
397 sig = ECDSA_do_sign(digest, 20, eckey);
405 .Bd -literal -offset indent
406 unsigned char *buffer, *pp;
409 buf_len = ECDSA_size(eckey);
410 buffer = malloc(buf_len);
412 if (!ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey) {
417 Third step: verify the created ECDSA signature using
420 .Dl ret = ECDSA_do_verify(digest, 20, sig, eckey);
425 .Dl ret = ECDSA_verify(0, digest, 20, buffer, buf_len, eckey);
427 and finally evaluate the return value:
428 .Bd -literal -offset indent
431 } else if (ret == 0) {
432 /* incorrect signature */
439 .Xr d2i_ECPKParameters 3 ,
443 .Xr ECDSA_set_ex_data 3 ,
444 .Xr EVP_DigestSignInit 3 ,
445 .Xr EVP_DigestVerifyInit 3 ,
448 ANSI X9.62, US Federal Information Processing Standard FIPS 186-2
449 (Digital Signature Standard, DSS)
451 The ECDSA implementation was first introduced in OpenSSL 0.9.8.
454 for the OpenSSL project.