1*2139Sjp161948 /* crypto/ecdsa/ecdsa.h */ 2*2139Sjp161948 /** 3*2139Sjp161948 * \file crypto/ecdsa/ecdsa.h Include file for the OpenSSL ECDSA functions 4*2139Sjp161948 * \author Written by Nils Larsch for the OpenSSL project 5*2139Sjp161948 */ 6*2139Sjp161948 /* ==================================================================== 7*2139Sjp161948 * Copyright (c) 2000-2003 The OpenSSL Project. All rights reserved. 8*2139Sjp161948 * 9*2139Sjp161948 * Redistribution and use in source and binary forms, with or without 10*2139Sjp161948 * modification, are permitted provided that the following conditions 11*2139Sjp161948 * are met: 12*2139Sjp161948 * 13*2139Sjp161948 * 1. Redistributions of source code must retain the above copyright 14*2139Sjp161948 * notice, this list of conditions and the following disclaimer. 15*2139Sjp161948 * 16*2139Sjp161948 * 2. Redistributions in binary form must reproduce the above copyright 17*2139Sjp161948 * notice, this list of conditions and the following disclaimer in 18*2139Sjp161948 * the documentation and/or other materials provided with the 19*2139Sjp161948 * distribution. 20*2139Sjp161948 * 21*2139Sjp161948 * 3. All advertising materials mentioning features or use of this 22*2139Sjp161948 * software must display the following acknowledgment: 23*2139Sjp161948 * "This product includes software developed by the OpenSSL Project 24*2139Sjp161948 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 25*2139Sjp161948 * 26*2139Sjp161948 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 27*2139Sjp161948 * endorse or promote products derived from this software without 28*2139Sjp161948 * prior written permission. For written permission, please contact 29*2139Sjp161948 * licensing@OpenSSL.org. 30*2139Sjp161948 * 31*2139Sjp161948 * 5. Products derived from this software may not be called "OpenSSL" 32*2139Sjp161948 * nor may "OpenSSL" appear in their names without prior written 33*2139Sjp161948 * permission of the OpenSSL Project. 34*2139Sjp161948 * 35*2139Sjp161948 * 6. Redistributions of any form whatsoever must retain the following 36*2139Sjp161948 * acknowledgment: 37*2139Sjp161948 * "This product includes software developed by the OpenSSL Project 38*2139Sjp161948 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 39*2139Sjp161948 * 40*2139Sjp161948 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 41*2139Sjp161948 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42*2139Sjp161948 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 43*2139Sjp161948 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 44*2139Sjp161948 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45*2139Sjp161948 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 46*2139Sjp161948 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 47*2139Sjp161948 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48*2139Sjp161948 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 49*2139Sjp161948 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 50*2139Sjp161948 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 51*2139Sjp161948 * OF THE POSSIBILITY OF SUCH DAMAGE. 52*2139Sjp161948 * ==================================================================== 53*2139Sjp161948 * 54*2139Sjp161948 * This product includes cryptographic software written by Eric Young 55*2139Sjp161948 * (eay@cryptsoft.com). This product includes software written by Tim 56*2139Sjp161948 * Hudson (tjh@cryptsoft.com). 57*2139Sjp161948 * 58*2139Sjp161948 */ 59*2139Sjp161948 #ifndef HEADER_ECDSA_H 60*2139Sjp161948 #define HEADER_ECDSA_H 61*2139Sjp161948 62*2139Sjp161948 #include <openssl/opensslconf.h> 63*2139Sjp161948 64*2139Sjp161948 #ifdef OPENSSL_NO_ECDSA 65*2139Sjp161948 #error ECDSA is disabled. 66*2139Sjp161948 #endif 67*2139Sjp161948 68*2139Sjp161948 #include <openssl/ec.h> 69*2139Sjp161948 #include <openssl/ossl_typ.h> 70*2139Sjp161948 #ifndef OPENSSL_NO_DEPRECATED 71*2139Sjp161948 #include <openssl/bn.h> 72*2139Sjp161948 #endif 73*2139Sjp161948 74*2139Sjp161948 #ifdef __cplusplus 75*2139Sjp161948 extern "C" { 76*2139Sjp161948 #endif 77*2139Sjp161948 78*2139Sjp161948 typedef struct ECDSA_SIG_st 79*2139Sjp161948 { 80*2139Sjp161948 BIGNUM *r; 81*2139Sjp161948 BIGNUM *s; 82*2139Sjp161948 } ECDSA_SIG; 83*2139Sjp161948 84*2139Sjp161948 /** ECDSA_SIG *ECDSA_SIG_new(void) 85*2139Sjp161948 * allocates and initialize a ECDSA_SIG structure 86*2139Sjp161948 * \return pointer to a ECDSA_SIG structure or NULL if an error occurred 87*2139Sjp161948 */ 88*2139Sjp161948 ECDSA_SIG *ECDSA_SIG_new(void); 89*2139Sjp161948 90*2139Sjp161948 /** ECDSA_SIG_free 91*2139Sjp161948 * frees a ECDSA_SIG structure 92*2139Sjp161948 * \param a pointer to the ECDSA_SIG structure 93*2139Sjp161948 */ 94*2139Sjp161948 void ECDSA_SIG_free(ECDSA_SIG *a); 95*2139Sjp161948 96*2139Sjp161948 /** i2d_ECDSA_SIG 97*2139Sjp161948 * DER encode content of ECDSA_SIG object (note: this function modifies *pp 98*2139Sjp161948 * (*pp += length of the DER encoded signature)). 99*2139Sjp161948 * \param a pointer to the ECDSA_SIG object 100*2139Sjp161948 * \param pp pointer to a unsigned char pointer for the output or NULL 101*2139Sjp161948 * \return the length of the DER encoded ECDSA_SIG object or 0 102*2139Sjp161948 */ 103*2139Sjp161948 int i2d_ECDSA_SIG(const ECDSA_SIG *a, unsigned char **pp); 104*2139Sjp161948 105*2139Sjp161948 /** d2i_ECDSA_SIG 106*2139Sjp161948 * decodes a DER encoded ECDSA signature (note: this function changes *pp 107*2139Sjp161948 * (*pp += len)). 108*2139Sjp161948 * \param v pointer to ECDSA_SIG pointer (may be NULL) 109*2139Sjp161948 * \param pp buffer with the DER encoded signature 110*2139Sjp161948 * \param len bufferlength 111*2139Sjp161948 * \return pointer to the decoded ECDSA_SIG structure (or NULL) 112*2139Sjp161948 */ 113*2139Sjp161948 ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **v, const unsigned char **pp, long len); 114*2139Sjp161948 115*2139Sjp161948 /** ECDSA_do_sign 116*2139Sjp161948 * computes the ECDSA signature of the given hash value using 117*2139Sjp161948 * the supplied private key and returns the created signature. 118*2139Sjp161948 * \param dgst pointer to the hash value 119*2139Sjp161948 * \param dgst_len length of the hash value 120*2139Sjp161948 * \param eckey pointer to the EC_KEY object containing a private EC key 121*2139Sjp161948 * \return pointer to a ECDSA_SIG structure or NULL 122*2139Sjp161948 */ 123*2139Sjp161948 ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst,int dgst_len,EC_KEY *eckey); 124*2139Sjp161948 125*2139Sjp161948 /** ECDSA_do_sign_ex 126*2139Sjp161948 * computes ECDSA signature of a given hash value using the supplied 127*2139Sjp161948 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). 128*2139Sjp161948 * \param dgst pointer to the hash value to sign 129*2139Sjp161948 * \param dgstlen length of the hash value 130*2139Sjp161948 * \param kinv optional pointer to a pre-computed inverse k 131*2139Sjp161948 * \param rp optional pointer to the pre-computed rp value (see 132*2139Sjp161948 * ECDSA_sign_setup 133*2139Sjp161948 * \param eckey pointer to the EC_KEY object containing a private EC key 134*2139Sjp161948 * \return pointer to a ECDSA_SIG structure or NULL 135*2139Sjp161948 */ 136*2139Sjp161948 ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen, 137*2139Sjp161948 const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey); 138*2139Sjp161948 139*2139Sjp161948 /** ECDSA_do_verify 140*2139Sjp161948 * verifies that the supplied signature is a valid ECDSA 141*2139Sjp161948 * signature of the supplied hash value using the supplied public key. 142*2139Sjp161948 * \param dgst pointer to the hash value 143*2139Sjp161948 * \param dgst_len length of the hash value 144*2139Sjp161948 * \param sig pointer to the ECDSA_SIG structure 145*2139Sjp161948 * \param eckey pointer to the EC_KEY object containing a public EC key 146*2139Sjp161948 * \return 1 if the signature is valid, 0 if the signature is invalid and -1 on error 147*2139Sjp161948 */ 148*2139Sjp161948 int ECDSA_do_verify(const unsigned char *dgst, int dgst_len, 149*2139Sjp161948 const ECDSA_SIG *sig, EC_KEY* eckey); 150*2139Sjp161948 151*2139Sjp161948 const ECDSA_METHOD *ECDSA_OpenSSL(void); 152*2139Sjp161948 153*2139Sjp161948 /** ECDSA_set_default_method 154*2139Sjp161948 * sets the default ECDSA method 155*2139Sjp161948 * \param meth the new default ECDSA_METHOD 156*2139Sjp161948 */ 157*2139Sjp161948 void ECDSA_set_default_method(const ECDSA_METHOD *meth); 158*2139Sjp161948 159*2139Sjp161948 /** ECDSA_get_default_method 160*2139Sjp161948 * returns the default ECDSA method 161*2139Sjp161948 * \return pointer to ECDSA_METHOD structure containing the default method 162*2139Sjp161948 */ 163*2139Sjp161948 const ECDSA_METHOD *ECDSA_get_default_method(void); 164*2139Sjp161948 165*2139Sjp161948 /** ECDSA_set_method 166*2139Sjp161948 * sets method to be used for the ECDSA operations 167*2139Sjp161948 * \param eckey pointer to the EC_KEY object 168*2139Sjp161948 * \param meth pointer to the new method 169*2139Sjp161948 * \return 1 on success and 0 otherwise 170*2139Sjp161948 */ 171*2139Sjp161948 int ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth); 172*2139Sjp161948 173*2139Sjp161948 /** ECDSA_size 174*2139Sjp161948 * returns the maximum length of the DER encoded signature 175*2139Sjp161948 * \param eckey pointer to a EC_KEY object 176*2139Sjp161948 * \return numbers of bytes required for the DER encoded signature 177*2139Sjp161948 */ 178*2139Sjp161948 int ECDSA_size(const EC_KEY *eckey); 179*2139Sjp161948 180*2139Sjp161948 /** ECDSA_sign_setup 181*2139Sjp161948 * precompute parts of the signing operation. 182*2139Sjp161948 * \param eckey pointer to the EC_KEY object containing a private EC key 183*2139Sjp161948 * \param ctx pointer to a BN_CTX object (may be NULL) 184*2139Sjp161948 * \param kinv pointer to a BIGNUM pointer for the inverse of k 185*2139Sjp161948 * \param rp pointer to a BIGNUM pointer for x coordinate of k * generator 186*2139Sjp161948 * \return 1 on success and 0 otherwise 187*2139Sjp161948 */ 188*2139Sjp161948 int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, 189*2139Sjp161948 BIGNUM **rp); 190*2139Sjp161948 191*2139Sjp161948 /** ECDSA_sign 192*2139Sjp161948 * computes ECDSA signature of a given hash value using the supplied 193*2139Sjp161948 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). 194*2139Sjp161948 * \param type this parameter is ignored 195*2139Sjp161948 * \param dgst pointer to the hash value to sign 196*2139Sjp161948 * \param dgstlen length of the hash value 197*2139Sjp161948 * \param sig buffer to hold the DER encoded signature 198*2139Sjp161948 * \param siglen pointer to the length of the returned signature 199*2139Sjp161948 * \param eckey pointer to the EC_KEY object containing a private EC key 200*2139Sjp161948 * \return 1 on success and 0 otherwise 201*2139Sjp161948 */ 202*2139Sjp161948 int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen, 203*2139Sjp161948 unsigned char *sig, unsigned int *siglen, EC_KEY *eckey); 204*2139Sjp161948 205*2139Sjp161948 206*2139Sjp161948 /** ECDSA_sign_ex 207*2139Sjp161948 * computes ECDSA signature of a given hash value using the supplied 208*2139Sjp161948 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). 209*2139Sjp161948 * \param type this parameter is ignored 210*2139Sjp161948 * \param dgst pointer to the hash value to sign 211*2139Sjp161948 * \param dgstlen length of the hash value 212*2139Sjp161948 * \param sig buffer to hold the DER encoded signature 213*2139Sjp161948 * \param siglen pointer to the length of the returned signature 214*2139Sjp161948 * \param kinv optional pointer to a pre-computed inverse k 215*2139Sjp161948 * \param rp optional pointer to the pre-computed rp value (see 216*2139Sjp161948 * ECDSA_sign_setup 217*2139Sjp161948 * \param eckey pointer to the EC_KEY object containing a private EC key 218*2139Sjp161948 * \return 1 on success and 0 otherwise 219*2139Sjp161948 */ 220*2139Sjp161948 int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen, 221*2139Sjp161948 unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv, 222*2139Sjp161948 const BIGNUM *rp, EC_KEY *eckey); 223*2139Sjp161948 224*2139Sjp161948 /** ECDSA_verify 225*2139Sjp161948 * verifies that the given signature is valid ECDSA signature 226*2139Sjp161948 * of the supplied hash value using the specified public key. 227*2139Sjp161948 * \param type this parameter is ignored 228*2139Sjp161948 * \param dgst pointer to the hash value 229*2139Sjp161948 * \param dgstlen length of the hash value 230*2139Sjp161948 * \param sig pointer to the DER encoded signature 231*2139Sjp161948 * \param siglen length of the DER encoded signature 232*2139Sjp161948 * \param eckey pointer to the EC_KEY object containing a public EC key 233*2139Sjp161948 * \return 1 if the signature is valid, 0 if the signature is invalid and -1 on error 234*2139Sjp161948 */ 235*2139Sjp161948 int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen, 236*2139Sjp161948 const unsigned char *sig, int siglen, EC_KEY *eckey); 237*2139Sjp161948 238*2139Sjp161948 /* the standard ex_data functions */ 239*2139Sjp161948 int ECDSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new 240*2139Sjp161948 *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); 241*2139Sjp161948 int ECDSA_set_ex_data(EC_KEY *d, int idx, void *arg); 242*2139Sjp161948 void *ECDSA_get_ex_data(EC_KEY *d, int idx); 243*2139Sjp161948 244*2139Sjp161948 245*2139Sjp161948 /* BEGIN ERROR CODES */ 246*2139Sjp161948 /* The following lines are auto generated by the script mkerr.pl. Any changes 247*2139Sjp161948 * made after this point may be overwritten when the script is next run. 248*2139Sjp161948 */ 249*2139Sjp161948 void ERR_load_ECDSA_strings(void); 250*2139Sjp161948 251*2139Sjp161948 /* Error codes for the ECDSA functions. */ 252*2139Sjp161948 253*2139Sjp161948 /* Function codes. */ 254*2139Sjp161948 #define ECDSA_F_ECDSA_DATA_NEW_METHOD 100 255*2139Sjp161948 #define ECDSA_F_ECDSA_DO_SIGN 101 256*2139Sjp161948 #define ECDSA_F_ECDSA_DO_VERIFY 102 257*2139Sjp161948 #define ECDSA_F_ECDSA_SIGN_SETUP 103 258*2139Sjp161948 259*2139Sjp161948 /* Reason codes. */ 260*2139Sjp161948 #define ECDSA_R_BAD_SIGNATURE 100 261*2139Sjp161948 #define ECDSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 101 262*2139Sjp161948 #define ECDSA_R_ERR_EC_LIB 102 263*2139Sjp161948 #define ECDSA_R_MISSING_PARAMETERS 103 264*2139Sjp161948 #define ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED 104 265*2139Sjp161948 #define ECDSA_R_SIGNATURE_MALLOC_FAILED 105 266*2139Sjp161948 267*2139Sjp161948 #ifdef __cplusplus 268*2139Sjp161948 } 269*2139Sjp161948 #endif 270*2139Sjp161948 #endif 271