1 1.1 christos =pod 2 1.1 christos 3 1.1 christos =head1 NAME 4 1.1 christos 5 1.1 christos ECDSA_size, ECDSA_sign, ECDSA_do_sign, 6 1.1 christos ECDSA_verify, ECDSA_do_verify, ECDSA_sign_setup, ECDSA_sign_ex, 7 1.1 christos ECDSA_do_sign_ex - deprecated low-level elliptic curve digital signature algorithm 8 1.1 christos (ECDSA) functions 9 1.1 christos 10 1.1 christos =head1 SYNOPSIS 11 1.1 christos 12 1.1 christos #include <openssl/ecdsa.h> 13 1.1 christos 14 1.1 christos The following functions have been deprecated since OpenSSL 3.0, and can be 15 1.1 christos hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value, 16 1.1 christos see L<openssl_user_macros(7)>: 17 1.1 christos 18 1.1 christos int ECDSA_size(const EC_KEY *eckey); 19 1.1 christos 20 1.1 christos int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen, 21 1.1 christos unsigned char *sig, unsigned int *siglen, EC_KEY *eckey); 22 1.1 christos ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dgst_len, 23 1.1 christos EC_KEY *eckey); 24 1.1 christos 25 1.1 christos int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen, 26 1.1 christos const unsigned char *sig, int siglen, EC_KEY *eckey); 27 1.1 christos int ECDSA_do_verify(const unsigned char *dgst, int dgst_len, 28 1.1 christos const ECDSA_SIG *sig, EC_KEY* eckey); 29 1.1 christos 30 1.1 christos ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen, 31 1.1 christos const BIGNUM *kinv, const BIGNUM *rp, 32 1.1 christos EC_KEY *eckey); 33 1.1 christos int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, BIGNUM **rp); 34 1.1 christos int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen, 35 1.1 christos unsigned char *sig, unsigned int *siglen, 36 1.1 christos const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey); 37 1.1 christos 38 1.1 christos =head1 DESCRIPTION 39 1.1 christos 40 1.1 christos See L<ECDSA_SIG_new(3)> for a description of the B<ECDSA_SIG> object. 41 1.1 christos 42 1.1 christos See L<i2d_ECDSA_SIG(3)> and L<d2i_ECDSA_SIG(3)> for information about encoding 43 1.1 christos and decoding ECDSA signatures to/from DER. 44 1.1 christos 45 1.1 christos All of the functions described below are deprecated. Applications should 46 1.1 christos use the higher level B<EVP> interface such as L<EVP_DigestSignInit(3)> 47 1.1 christos or L<EVP_DigestVerifyInit(3)> instead. 48 1.1 christos 49 1.1 christos ECDSA_size() returns the maximum length of a DER encoded ECDSA signature 50 1.1 christos created with the private EC key I<eckey>. To obtain the actual signature 51 1.1 christos size use L<EVP_PKEY_sign(3)> with a NULL I<sig> parameter. 52 1.1 christos 53 1.1 christos ECDSA_sign() computes a digital signature of the I<dgstlen> bytes hash value 54 1.1 christos I<dgst> using the private EC key I<eckey>. The DER encoded signatures is 55 1.3 christos stored in I<sig> and its length is returned in I<siglen>. Note: I<sig> must 56 1.1 christos point to ECDSA_size(eckey) bytes of memory. The parameter I<type> is currently 57 1.1 christos ignored. ECDSA_sign() is wrapper function for ECDSA_sign_ex() with I<kinv> 58 1.1 christos and I<rp> set to NULL. 59 1.1 christos 60 1.1 christos ECDSA_do_sign() is similar to ECDSA_sign() except the signature is returned 61 1.1 christos as a newly allocated B<ECDSA_SIG> structure (or NULL on error). ECDSA_do_sign() 62 1.1 christos is a wrapper function for ECDSA_do_sign_ex() with I<kinv> and I<rp> set to 63 1.1 christos NULL. 64 1.1 christos 65 1.1 christos ECDSA_verify() verifies that the signature in I<sig> of size I<siglen> is a 66 1.1 christos valid ECDSA signature of the hash value I<dgst> of size I<dgstlen> using the 67 1.1 christos public key I<eckey>. The parameter I<type> is ignored. 68 1.1 christos 69 1.1 christos ECDSA_do_verify() is similar to ECDSA_verify() except the signature is 70 1.1 christos presented in the form of a pointer to an B<ECDSA_SIG> structure. 71 1.1 christos 72 1.1 christos The remaining functions utilise the internal I<kinv> and I<r> values used 73 1.1 christos during signature computation. Most applications will never need to call these 74 1.1 christos and some external ECDSA ENGINE implementations may not support them at all if 75 1.1 christos either I<kinv> or I<r> is not NULL. 76 1.1 christos 77 1.1 christos ECDSA_sign_setup() may be used to precompute parts of the signing operation. 78 1.1 christos I<eckey> is the private EC key and I<ctx> is a pointer to B<BN_CTX> structure 79 1.1 christos (or NULL). The precomputed values or returned in I<kinv> and I<rp> and can be 80 1.1 christos used in a later call to ECDSA_sign_ex() or ECDSA_do_sign_ex(). 81 1.1 christos 82 1.1 christos ECDSA_sign_ex() computes a digital signature of the I<dgstlen> bytes hash value 83 1.1 christos I<dgst> using the private EC key I<eckey> and the optional pre-computed values 84 1.1 christos I<kinv> and I<rp>. The DER encoded signature is stored in I<sig> and its 85 1.3 christos length is returned in I<siglen>. Note: I<sig> must point to ECDSA_size(eckey) 86 1.1 christos bytes of memory. The parameter I<type> is ignored. 87 1.1 christos 88 1.1 christos ECDSA_do_sign_ex() is similar to ECDSA_sign_ex() except the signature is 89 1.1 christos returned as a newly allocated B<ECDSA_SIG> structure (or NULL on error). 90 1.1 christos 91 1.1 christos =head1 RETURN VALUES 92 1.1 christos 93 1.1 christos ECDSA_size() returns the maximum length signature or 0 on error. 94 1.1 christos 95 1.1 christos ECDSA_sign(), ECDSA_sign_ex() and ECDSA_sign_setup() return 1 if successful 96 1.1 christos or 0 on error. 97 1.1 christos 98 1.1 christos ECDSA_do_sign() and ECDSA_do_sign_ex() return a pointer to an allocated 99 1.1 christos B<ECDSA_SIG> structure or NULL on error. 100 1.1 christos 101 1.1 christos ECDSA_verify() and ECDSA_do_verify() return 1 for a valid 102 1.1 christos signature, 0 for an invalid signature and -1 on error. 103 1.1 christos The error codes can be obtained by L<ERR_get_error(3)>. 104 1.1 christos 105 1.1 christos =head1 EXAMPLES 106 1.1 christos 107 1.1 christos Creating an ECDSA signature of a given SHA-256 hash value using the 108 1.1 christos named curve prime256v1 (aka P-256). 109 1.1 christos This example uses deprecated functionality. See L</DESCRIPTION>. 110 1.1 christos 111 1.1 christos First step: create an EC_KEY object (note: this part is B<not> ECDSA 112 1.1 christos specific) 113 1.1 christos 114 1.1 christos int ret; 115 1.1 christos ECDSA_SIG *sig; 116 1.1 christos EC_KEY *eckey; 117 1.1 christos 118 1.1 christos eckey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); 119 1.1 christos if (eckey == NULL) 120 1.1 christos /* error */ 121 1.1 christos if (EC_KEY_generate_key(eckey) == 0) 122 1.1 christos /* error */ 123 1.1 christos 124 1.1 christos Second step: compute the ECDSA signature of a SHA-256 hash value 125 1.1 christos using ECDSA_do_sign(): 126 1.1 christos 127 1.1 christos sig = ECDSA_do_sign(digest, 32, eckey); 128 1.1 christos if (sig == NULL) 129 1.1 christos /* error */ 130 1.1 christos 131 1.1 christos or using ECDSA_sign(): 132 1.1 christos 133 1.1 christos unsigned char *buffer, *pp; 134 1.1 christos int buf_len; 135 1.1 christos 136 1.1 christos buf_len = ECDSA_size(eckey); 137 1.1 christos buffer = OPENSSL_malloc(buf_len); 138 1.1 christos pp = buffer; 139 1.1 christos if (ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey) == 0) 140 1.1 christos /* error */ 141 1.1 christos 142 1.1 christos Third step: verify the created ECDSA signature using ECDSA_do_verify(): 143 1.1 christos 144 1.1 christos ret = ECDSA_do_verify(digest, 32, sig, eckey); 145 1.1 christos 146 1.1 christos or using ECDSA_verify(): 147 1.1 christos 148 1.1 christos ret = ECDSA_verify(0, digest, 32, buffer, buf_len, eckey); 149 1.1 christos 150 1.1 christos and finally evaluate the return value: 151 1.1 christos 152 1.1 christos if (ret == 1) 153 1.1 christos /* signature ok */ 154 1.1 christos else if (ret == 0) 155 1.1 christos /* incorrect signature */ 156 1.1 christos else 157 1.1 christos /* error */ 158 1.1 christos 159 1.1 christos =head1 CONFORMING TO 160 1.1 christos 161 1.1 christos ANSI X9.62, US Federal Information Processing Standard FIPS186-2 162 1.1 christos (Digital Signature Standard, DSS) 163 1.1 christos 164 1.1 christos =head1 SEE ALSO 165 1.1 christos 166 1.1 christos L<EC_KEY_new(3)>, 167 1.1 christos L<EVP_DigestSignInit(3)>, 168 1.1 christos L<EVP_DigestVerifyInit(3)>, 169 1.1 christos L<EVP_PKEY_sign(3)> 170 1.1 christos L<i2d_ECDSA_SIG(3)>, 171 1.1 christos L<d2i_ECDSA_SIG(3)> 172 1.1 christos 173 1.1 christos =head1 HISTORY 174 1.1 christos 175 1.1 christos All functionality described here was deprecated in OpenSSL 3.0. 176 1.1 christos 177 1.1 christos =head1 COPYRIGHT 178 1.1 christos 179 1.1 christos Copyright 2004-2022 The OpenSSL Project Authors. All Rights Reserved. 180 1.1 christos 181 1.1 christos Licensed under the Apache License 2.0 (the "License"). You may not use 182 1.1 christos this file except in compliance with the License. You can obtain a copy 183 1.1 christos in the file LICENSE in the source distribution or at 184 1.1 christos L<https://www.openssl.org/source/license.html>. 185 1.1 christos 186 1.1 christos =cut 187