1ECDSA_SIG_NEW(3)                    OpenSSL                   ECDSA_SIG_NEW(3)
2
3
4

NAME

6       ECDSA_SIG_get0, ECDSA_SIG_get0_r, ECDSA_SIG_get0_s, ECDSA_SIG_set0,
7       ECDSA_SIG_new, ECDSA_SIG_free, ECDSA_size, ECDSA_sign, ECDSA_do_sign,
8       ECDSA_verify, ECDSA_do_verify, ECDSA_sign_setup, ECDSA_sign_ex,
9       ECDSA_do_sign_ex - low level elliptic curve digital signature algorithm
10       (ECDSA) functions
11

SYNOPSIS

13        #include <openssl/ecdsa.h>
14
15        ECDSA_SIG *ECDSA_SIG_new(void);
16        void ECDSA_SIG_free(ECDSA_SIG *sig);
17        void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
18        const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig);
19        const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig);
20        int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
21        int ECDSA_size(const EC_KEY *eckey);
22
23        int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen,
24                       unsigned char *sig, unsigned int *siglen, EC_KEY *eckey);
25        ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len,
26                                 EC_KEY *eckey);
27
28        int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen,
29                         const unsigned char *sig, int siglen, EC_KEY *eckey);
30        int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
31                            const ECDSA_SIG *sig, EC_KEY* eckey);
32
33        ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen,
34                                    const BIGNUM *kinv, const BIGNUM *rp,
35                                    EC_KEY *eckey);
36        int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp);
37        int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen,
38                          unsigned char *sig, unsigned int *siglen,
39                          const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey);
40

DESCRIPTION

42       Note: these functions provide a low level interface to ECDSA. Most
43       applications should use the higher level EVP interface such as
44       EVP_DigestSignInit(3) or EVP_DigestVerifyInit(3) instead.
45
46       ECDSA_SIG is an opaque structure consisting of two BIGNUMs for the r
47       and s value of an ECDSA signature (see X9.62 or FIPS 186-2).
48
49       ECDSA_SIG_new() allocates an empty ECDSA_SIG structure. Note: before
50       OpenSSL 1.1.0 the: the r and s components were initialised.
51
52       ECDSA_SIG_free() frees the ECDSA_SIG structure sig.
53
54       ECDSA_SIG_get0() returns internal pointers the r and s values contained
55       in sig and stores them in *pr and *ps, respectively.  The pointer pr or
56       ps can be NULL, in which case the corresponding value is not returned.
57
58       The values r, s can also be retrieved separately by the corresponding
59       function ECDSA_SIG_get0_r() and ECDSA_SIG_get0_s(), respectively.
60
61       The r and s values can be set by calling ECDSA_SIG_set0() and passing
62       the new values for r and s as parameters to the function. Calling this
63       function transfers the memory management of the values to the ECDSA_SIG
64       object, and therefore the values that have been passed in should not be
65       freed directly after this function has been called.
66
67       See i2d_ECDSA_SIG(3) and d2i_ECDSA_SIG(3) for information about
68       encoding and decoding ECDSA signatures to/from DER.
69
70       ECDSA_size() returns the maximum length of a DER encoded ECDSA
71       signature created with the private EC key eckey.
72
73       ECDSA_sign() computes a digital signature of the dgstlen bytes hash
74       value dgst using the private EC key eckey. The DER encoded signatures
75       is stored in sig and its length is returned in sig_len. Note: sig must
76       point to ECDSA_size(eckey) bytes of memory. The parameter type is
77       currently ignored. ECDSA_sign() is wrapper function for ECDSA_sign_ex()
78       with kinv and rp set to NULL.
79
80       ECDSA_do_sign() is similar to ECDSA_sign() except the signature is
81       returned as a newly allocated ECDSA_SIG structure (or NULL on error).
82       ECDSA_do_sign() is a wrapper function for ECDSA_do_sign_ex() with kinv
83       and rp set to NULL.
84
85       ECDSA_verify() verifies that the signature in sig of size siglen is a
86       valid ECDSA signature of the hash value dgst of size dgstlen using the
87       public key eckey.  The parameter type is ignored.
88
89       ECDSA_do_verify() is similar to ECDSA_verify() except the signature is
90       presented in the form of a pointer to an ECDSA_SIG structure.
91
92       The remaining functions utilise the internal kinv and r values used
93       during signature computation. Most applications will never need to call
94       these and some external ECDSA ENGINE implementations may not support
95       them at all if either kinv or r is not NULL.
96
97       ECDSA_sign_setup() may be used to precompute parts of the signing
98       operation.  eckey is the private EC key and ctx is a pointer to BN_CTX
99       structure (or NULL). The precomputed values or returned in kinv and rp
100       and can be used in a later call to ECDSA_sign_ex() or
101       ECDSA_do_sign_ex().
102
103       ECDSA_sign_ex() computes a digital signature of the dgstlen bytes hash
104       value dgst using the private EC key eckey and the optional pre-computed
105       values kinv and rp. The DER encoded signature is stored in sig and its
106       length is returned in sig_len. Note: sig must point to
107       ECDSA_size(eckey) bytes of memory. The parameter type is ignored.
108
109       ECDSA_do_sign_ex() is similar to ECDSA_sign_ex() except the signature
110       is returned as a newly allocated ECDSA_SIG structure (or NULL on
111       error).
112

RETURN VALUES

114       ECDSA_SIG_new() returns NULL if the allocation fails.
115
116       ECDSA_SIG_set0() returns 1 on success or 0 on failure.
117
118       ECDSA_SIG_get0_r() and ECDSA_SIG_get0_s() return the corresponding
119       value, or NULL if it is unset.
120
121       ECDSA_size() returns the maximum length signature or 0 on error.
122
123       ECDSA_sign(), ECDSA_sign_ex() and ECDSA_sign_setup() return 1 if
124       successful or 0 on error.
125
126       ECDSA_do_sign() and ECDSA_do_sign_ex() return a pointer to an allocated
127       ECDSA_SIG structure or NULL on error.
128
129       ECDSA_verify() and ECDSA_do_verify() return 1 for a valid signature, 0
130       for an invalid signature and -1 on error.  The error codes can be
131       obtained by ERR_get_error(3).
132

EXAMPLES

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

CONFORMING TO

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

SEE ALSO

190       EC_KEY_new(3), EVP_DigestSignInit(3), EVP_DigestVerifyInit(3),
191       i2d_ECDSA_SIG(3), d2i_ECDSA_SIG(3)
192
194       Copyright 2004-2019 The OpenSSL Project Authors. All Rights Reserved.
195
196       Licensed under the OpenSSL license (the "License").  You may not use
197       this file except in compliance with the License.  You can obtain a copy
198       in the file LICENSE in the source distribution or at
199       <https://www.openssl.org/source/license.html>.
200
201
202
2031.1.1d                            2019-10-03                  ECDSA_SIG_NEW(3)
Impressum