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