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

NAME

6       ECDSA_SIG_new, ECDSA_SIG_free, ECDSA_SIG_get0, ECDSA_SIG_get0_r,
7       ECDSA_SIG_get0_s, ECDSA_SIG_set0 - Functions for creating, destroying
8       and manipulating ECDSA_SIG objects
9

SYNOPSIS

11        #include <openssl/ecdsa.h>
12
13        ECDSA_SIG *ECDSA_SIG_new(void);
14        void ECDSA_SIG_free(ECDSA_SIG *sig);
15        void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
16        const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig);
17        const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig);
18        int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
19

DESCRIPTION

21       ECDSA_SIG is an opaque structure consisting of two BIGNUMs for the r
22       and s value of an Elliptic Curve Digital Signature Algorithm (ECDSA)
23       signature (see FIPS186-4 or X9.62).  The ECDSA_SIG object was mainly
24       used by the deprecated low level functions described in ECDSA_sign(3),
25       it is still required in order to be able to set or get the values of r
26       and s into or from a signature. This is mainly used for testing
27       purposes as shown in the "EXAMPLES".
28
29       ECDSA_SIG_new() allocates an empty ECDSA_SIG structure.  Note: before
30       OpenSSL 1.1.0, the r and s components were initialised.
31
32       ECDSA_SIG_free() frees the ECDSA_SIG structure sig.
33
34       ECDSA_SIG_get0() returns internal pointers the r and s values contained
35       in sig and stores them in *pr and *ps, respectively.  The pointer pr or
36       ps can be NULL, in which case the corresponding value is not returned.
37
38       The values r, s can also be retrieved separately by the corresponding
39       function ECDSA_SIG_get0_r() and ECDSA_SIG_get0_s(), respectively.
40
41       Non-NULL r and s values can be set on the sig by calling
42       ECDSA_SIG_set0(). Calling this function transfers the memory management
43       of the values to the ECDSA_SIG object, and therefore the values that
44       have been passed in should not be freed by the caller.
45
46       See i2d_ECDSA_SIG(3) and d2i_ECDSA_SIG(3) for information about
47       encoding and decoding ECDSA signatures to/from DER.
48

RETURN VALUES

50       ECDSA_SIG_new() returns NULL if the allocation fails.
51
52       ECDSA_SIG_set0() returns 1 on success or 0 on failure.
53
54       ECDSA_SIG_get0_r() and ECDSA_SIG_get0_s() return the corresponding
55       value, or NULL if it is unset.
56

EXAMPLES

58       Extract signature r and s values from a ECDSA signature of size
59       signaturelen:
60
61        ECDSA_SIG *obj;
62        const BIGNUM *r, *s;
63
64        /* Load a signature into the ECDSA_SIG object */
65        obj = d2i_ECDSA_SIG(NULL, &signature, signaturelen);
66        if (obj == NULL)
67            /* error */
68
69        r = ECDSA_SIG_get0_r(obj);
70        s = ECDSA_SIG_get0_s(obj);
71        if (r == NULL || s == NULL)
72            /* error */
73
74        /* Use BN_bn2binpad() here to convert to r and s into byte arrays */
75
76        /*
77         * Do not try to access I<r> or I<s> after calling ECDSA_SIG_free(),
78         * as they are both freed by this call.
79         */
80        ECDSA_SIG_free(obj);
81
82       Convert r and s byte arrays into an ECDSA_SIG signature of size
83       signaturelen:
84
85        ECDSA_SIG *obj = NULL;
86        unsigned char *signature = NULL;
87        size_t signaturelen;
88        BIGNUM *rbn = NULL, *sbn = NULL;
89
90        obj = ECDSA_SIG_new();
91        if (obj == NULL)
92            /* error */
93        rbn = BN_bin2bn(r, rlen, NULL);
94        sbn = BN_bin2bn(s, slen, NULL);
95        if (rbn == NULL || sbn == NULL)
96            /* error */
97
98        if (!ECDSA_SIG_set0(obj, rbn, sbn))
99            /* error */
100        /* Set these to NULL since they are now owned by obj */
101        rbn = sbn = NULL;
102
103        signaturelen = i2d_ECDSA_SIG(obj, &signature);
104        if (signaturelen <= 0)
105            /* error */
106
107        /*
108         * This signature could now be passed to L<EVP_DigestVerify(3)>
109         * or L<EVP_DigestVerifyFinal(3)>
110         */
111
112        BN_free(rbn);
113        BN_free(sbn);
114        OPENSSL_free(signature);
115        ECDSA_SIG_free(obj);
116

CONFORMING TO

118       ANSI X9.62, US Federal Information Processing Standard FIPS186-4
119       (Digital Signature Standard, DSS)
120

SEE ALSO

122       EC_KEY_new(3), EVP_DigestSignInit(3), EVP_DigestVerifyInit(3),
123       EVP_PKEY_sign(3) i2d_ECDSA_SIG(3), d2i_ECDSA_SIG(3), ECDSA_sign(3)
124
126       Copyright 2004-2022 The OpenSSL Project Authors. All Rights Reserved.
127
128       Licensed under the Apache License 2.0 (the "License").  You may not use
129       this file except in compliance with the License.  You can obtain a copy
130       in the file LICENSE in the source distribution or at
131       <https://www.openssl.org/source/license.html>.
132
133
134
1353.1.1                             2023-08-31              ECDSA_SIG_NEW(3ossl)
Impressum