1 =pod 2 3 =head1 NAME 4 5 ECDSA_SIG_new, ECDSA_SIG_free, 6 ECDSA_SIG_get0, ECDSA_SIG_get0_r, ECDSA_SIG_get0_s, ECDSA_SIG_set0 7 - Functions for creating, destroying and manipulating ECDSA_SIG objects 8 9 =head1 SYNOPSIS 10 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 20 =head1 DESCRIPTION 21 22 B<ECDSA_SIG> is an opaque structure consisting of two BIGNUMs for the 23 I<r> and I<s> value of an Elliptic Curve Digital Signature Algorithm (ECDSA) signature 24 (see FIPS186-4 or X9.62). 25 The B<ECDSA_SIG> object was mainly used by the deprecated low level functions described in 26 L<ECDSA_sign(3)>, it is still required in order to be able to set or get the values of 27 I<r> and I<s> into or from a signature. This is mainly used for testing purposes as shown 28 in the L</EXAMPLES>. 29 30 ECDSA_SIG_new() allocates an empty B<ECDSA_SIG> structure. 31 Note: before OpenSSL 1.1.0, the I<r> and I<s> components were initialised. 32 33 ECDSA_SIG_free() frees the B<ECDSA_SIG> structure I<sig>. 34 If the argument is NULL, nothing is done. 35 36 ECDSA_SIG_get0() returns internal pointers the I<r> and I<s> values contained 37 in I<sig> and stores them in I<*pr> and I<*ps>, respectively. 38 The pointer I<pr> or I<ps> can be NULL, in which case the corresponding value 39 is not returned. 40 41 The values I<r>, I<s> can also be retrieved separately by the corresponding 42 function ECDSA_SIG_get0_r() and ECDSA_SIG_get0_s(), respectively. 43 44 Non-NULL I<r> and I<s> values can be set on the I<sig> by calling 45 ECDSA_SIG_set0(). Calling this function transfers the memory management of the 46 values to the B<ECDSA_SIG> object, and therefore the values that have been 47 passed in should not be freed by the caller. 48 49 See L<i2d_ECDSA_SIG(3)> and L<d2i_ECDSA_SIG(3)> for information about encoding 50 and decoding ECDSA signatures to/from DER. 51 52 =head1 RETURN VALUES 53 54 ECDSA_SIG_new() returns NULL if the allocation fails. 55 56 ECDSA_SIG_set0() returns 1 on success or 0 on failure. 57 58 ECDSA_SIG_get0_r() and ECDSA_SIG_get0_s() return the corresponding value, 59 or NULL if it is unset. 60 61 =head1 EXAMPLES 62 63 Extract signature I<r> and I<s> values from a ECDSA I<signature> 64 of size I<signaturelen>: 65 66 ECDSA_SIG *obj; 67 const BIGNUM *r, *s; 68 69 /* Load a signature into the ECDSA_SIG object */ 70 obj = d2i_ECDSA_SIG(NULL, &signature, signaturelen); 71 if (obj == NULL) 72 /* error */ 73 74 r = ECDSA_SIG_get0_r(obj); 75 s = ECDSA_SIG_get0_s(obj); 76 if (r == NULL || s == NULL) 77 /* error */ 78 79 /* Use BN_bn2binpad() here to convert to r and s into byte arrays */ 80 81 /* 82 * Do not try to access I<r> or I<s> after calling ECDSA_SIG_free(), 83 * as they are both freed by this call. 84 */ 85 ECDSA_SIG_free(obj); 86 87 Convert I<r> and I<s> byte arrays into an ECDSA_SIG I<signature> of 88 size I<signaturelen>: 89 90 ECDSA_SIG *obj = NULL; 91 unsigned char *signature = NULL; 92 size_t signaturelen; 93 BIGNUM *rbn = NULL, *sbn = NULL; 94 95 obj = ECDSA_SIG_new(); 96 if (obj == NULL) 97 /* error */ 98 rbn = BN_bin2bn(r, rlen, NULL); 99 sbn = BN_bin2bn(s, slen, NULL); 100 if (rbn == NULL || sbn == NULL) 101 /* error */ 102 103 if (!ECDSA_SIG_set0(obj, rbn, sbn)) 104 /* error */ 105 /* Set these to NULL since they are now owned by obj */ 106 rbn = sbn = NULL; 107 108 signaturelen = i2d_ECDSA_SIG(obj, &signature); 109 if (signaturelen <= 0) 110 /* error */ 111 112 /* 113 * This signature could now be passed to L<EVP_DigestVerify(3)> 114 * or L<EVP_DigestVerifyFinal(3)> 115 */ 116 117 BN_free(rbn); 118 BN_free(sbn); 119 OPENSSL_free(signature); 120 ECDSA_SIG_free(obj); 121 122 =head1 CONFORMING TO 123 124 ANSI X9.62, 125 US Federal Information Processing Standard FIPS186-4 126 (Digital Signature Standard, DSS) 127 128 =head1 SEE ALSO 129 130 L<EC_KEY_new(3)>, 131 L<EVP_DigestSignInit(3)>, 132 L<EVP_DigestVerifyInit(3)>, 133 L<EVP_PKEY_sign(3)> 134 L<i2d_ECDSA_SIG(3)>, 135 L<d2i_ECDSA_SIG(3)>, 136 L<ECDSA_sign(3)> 137 138 =head1 COPYRIGHT 139 140 Copyright 2004-2024 The OpenSSL Project Authors. All Rights Reserved. 141 142 Licensed under the Apache License 2.0 (the "License"). You may not use 143 this file except in compliance with the License. You can obtain a copy 144 in the file LICENSE in the source distribution or at 145 L<https://www.openssl.org/source/license.html>. 146 147 =cut 148