1ecdsa(3)                            OpenSSL                           ecdsa(3)
2
3
4

NAME

6       ECDSA_SIG_new, ECDSA_SIG_free, i2d_ECDSA_SIG, d2i_ECDSA_SIG,
7       ECDSA_size, ECDSA_sign_setup, ECDSA_sign, ECDSA_sign_ex, ECDSA_verify,
8       ECDSA_do_sign, ECDSA_do_sign_ex, ECDSA_do_verify - Elliptic Curve
9       Digital Signature Algorithm
10

SYNOPSIS

12        #include <openssl/ecdsa.h>
13
14        ECDSA_SIG*     ECDSA_SIG_new(void);
15        void           ECDSA_SIG_free(ECDSA_SIG *sig);
16        int            i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp);
17        ECDSA_SIG*     d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp,
18                       long len);
19
20        ECDSA_SIG*     ECDSA_do_sign(const unsigned char *dgst, int dgst_len,
21                               EC_KEY *eckey);
22        ECDSA_SIG*     ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
23                               const BIGNUM *kinv, const BIGNUM *rp,
24                               EC_KEY *eckey);
25        int            ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
26                               const ECDSA_SIG *sig, EC_KEY* eckey);
27        int            ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx,
28                               BIGNUM **kinv, BIGNUM **rp);
29        int            ECDSA_sign(int type, const unsigned char *dgst,
30                               int dgstlen, unsigned char *sig,
31                               unsigned int *siglen, EC_KEY *eckey);
32        int            ECDSA_sign_ex(int type, const unsigned char *dgst,
33                               int dgstlen, unsigned char *sig,
34                               unsigned int *siglen, const BIGNUM *kinv,
35                               const BIGNUM *rp, EC_KEY *eckey);
36        int            ECDSA_verify(int type, const unsigned char *dgst,
37                               int dgstlen, const unsigned char *sig,
38                               int siglen, EC_KEY *eckey);
39        int            ECDSA_size(const EC_KEY *eckey);
40
41        const ECDSA_METHOD*    ECDSA_OpenSSL(void);
42        void           ECDSA_set_default_method(const ECDSA_METHOD *meth);
43        const ECDSA_METHOD*    ECDSA_get_default_method(void);
44        int            ECDSA_set_method(EC_KEY *eckey,const ECDSA_METHOD *meth);
45
46        int            ECDSA_get_ex_new_index(long argl, void *argp,
47                               CRYPTO_EX_new *new_func,
48                               CRYPTO_EX_dup *dup_func,
49                               CRYPTO_EX_free *free_func);
50        int            ECDSA_set_ex_data(EC_KEY *d, int idx, void *arg);
51        void*          ECDSA_get_ex_data(EC_KEY *d, int idx);
52

DESCRIPTION

54       The ECDSA_SIG structure consists of two BIGNUMs for the r and s value
55       of a ECDSA signature (see X9.62 or FIPS 186-2).
56
57        struct
58               {
59               BIGNUM *r;
60               BIGNUM *s;
61        } ECDSA_SIG;
62
63       ECDSA_SIG_new() allocates a new ECDSA_SIG structure (note: this
64       function also allocates the BIGNUMs) and initialize it.
65
66       ECDSA_SIG_free() frees the ECDSA_SIG structure sig.
67
68       i2d_ECDSA_SIG() creates the DER encoding of the ECDSA signature sig and
69       writes the encoded signature to *pp (note: if pp is NULL i2d_ECDSA_SIG
70       returns the expected length in bytes of the DER encoded signature).
71       i2d_ECDSA_SIG returns the length of the DER encoded signature (or 0 on
72       error).
73
74       d2i_ECDSA_SIG() decodes a DER encoded ECDSA signature and returns the
75       decoded signature in a newly allocated ECDSA_SIG structure.  *sig
76       points to the buffer containing the DER encoded signature of size len.
77
78       ECDSA_size() returns the maximum length of a DER encoded ECDSA
79       signature created with the private EC key eckey.
80
81       ECDSA_sign_setup() may be used to precompute parts of the signing
82       operation. eckey is the private EC key and ctx is a pointer to BN_CTX
83       structure (or NULL). The precomputed values or returned in kinv and rp
84       and can be used in a later call to ECDSA_sign_ex or ECDSA_do_sign_ex.
85
86       ECDSA_sign() is wrapper function for ECDSA_sign_ex with kinv and rp set
87       to NULL.
88
89       ECDSA_sign_ex() computes a digital signature of the dgstlen bytes hash
90       value dgst using the private EC key eckey and the optional pre-computed
91       values kinv and rp. The DER encoded signatures is stored in sig and
92       it's length is returned in sig_len. Note: sig must point to ECDSA_size
93       bytes of memory. The parameter type is ignored.
94
95       ECDSA_verify() verifies that the signature in sig of size siglen is a
96       valid ECDSA signature of the hash value dgst of size dgstlen using the
97       public key eckey.  The parameter type is ignored.
98
99       ECDSA_do_sign() is wrapper function for ECDSA_do_sign_ex with kinv and
100       rp set to NULL.
101
102       ECDSA_do_sign_ex() computes a digital signature of the dgst_len bytes
103       hash value dgst using the private key eckey and the optional pre-
104       computed values kinv and rp. The signature is returned in a newly
105       allocated ECDSA_SIG structure (or NULL on error).
106
107       ECDSA_do_verify() verifies that the signature sig is a valid ECDSA
108       signature of the hash value dgst of size dgst_len using the public key
109       eckey.
110

RETURN VALUES

112       ECDSA_size() returns the maximum length signature or 0 on error.
113
114       ECDSA_sign_setup() and ECDSA_sign() return 1 if successful or 0 on
115       error.
116
117       ECDSA_verify() and ECDSA_do_verify() return 1 for a valid signature, 0
118       for an invalid signature and -1 on error.  The error codes can be
119       obtained by ERR_get_error(3).
120

EXAMPLES

122       Creating a ECDSA signature of given SHA-1 hash value using the named
123       curve secp192k1.
124
125       First step: create a EC_KEY object (note: this part is not ECDSA
126       specific)
127
128        int        ret;
129        ECDSA_SIG *sig;
130        EC_KEY    *eckey;
131        eckey = EC_KEY_new_by_curve_name(NID_secp192k1);
132        if (eckey == NULL)
133               {
134               /* error */
135               }
136        if (!EC_KEY_generate_key(eckey))
137               {
138               /* error */
139               }
140
141       Second step: compute the ECDSA signature of a SHA-1 hash value using
142       ECDSA_do_sign
143
144        sig = ECDSA_do_sign(digest, 20, eckey);
145        if (sig == NULL)
146               {
147               /* error */
148               }
149
150       or using ECDSA_sign
151
152        unsigned char *buffer, *pp;
153        int            buf_len;
154        buf_len = ECDSA_size(eckey);
155        buffer  = OPENSSL_malloc(buf_len);
156        pp = buffer;
157        if (!ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey);
158               {
159               /* error */
160               }
161
162       Third step: verify the created ECDSA signature using ECDSA_do_verify
163
164        ret = ECDSA_do_verify(digest, 20, sig, eckey);
165
166       or using ECDSA_verify
167
168        ret = ECDSA_verify(0, digest, 20, buffer, buf_len, eckey);
169
170       and finally evaluate the return value:
171
172        if (ret == -1)
173               {
174               /* error */
175               }
176        else if (ret == 0)
177               {
178               /* incorrect signature */
179               }
180        else   /* ret == 1 */
181               {
182               /* signature ok */
183               }
184

CONFORMING TO

186       ANSI X9.62, US Federal Information Processing Standard FIPS 186-2
187       (Digital Signature Standard, DSS)
188

SEE ALSO

190       dsa(3), rsa(3)
191

HISTORY

193       The ecdsa implementation was first introduced in OpenSSL 0.9.8
194

AUTHOR

196       Nils Larsch for the OpenSSL project (http://www.openssl.org).
197
198
199
2001.0.2o                            2020-01-28                          ecdsa(3)
Impressum