OLD | NEW |
1 /* crypto/ecdsa/ecdsa.h */ | 1 /* crypto/ecdsa/ecdsa.h */ |
2 /** | 2 /** |
3 * \file crypto/ecdsa/ecdsa.h Include file for the OpenSSL ECDSA functions | 3 * \file crypto/ecdsa/ecdsa.h Include file for the OpenSSL ECDSA functions |
4 * \author Written by Nils Larsch for the OpenSSL project | 4 * \author Written by Nils Larsch for the OpenSSL project |
5 */ | 5 */ |
6 /* ==================================================================== | 6 /* ==================================================================== |
7 * Copyright (c) 2000-2003 The OpenSSL Project. All rights reserved. | 7 * Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved. |
8 * | 8 * |
9 * Redistribution and use in source and binary forms, with or without | 9 * Redistribution and use in source and binary forms, with or without |
10 * modification, are permitted provided that the following conditions | 10 * modification, are permitted provided that the following conditions |
11 * are met: | 11 * are met: |
12 * | 12 * |
13 * 1. Redistributions of source code must retain the above copyright | 13 * 1. Redistributions of source code must retain the above copyright |
14 * notice, this list of conditions and the following disclaimer. | 14 * notice, this list of conditions and the following disclaimer. |
15 * | 15 * |
16 * 2. Redistributions in binary form must reproduce the above copyright | 16 * 2. Redistributions in binary form must reproduce the above copyright |
17 * notice, this list of conditions and the following disclaimer in | 17 * notice, this list of conditions and the following disclaimer in |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 #ifdef __cplusplus | 74 #ifdef __cplusplus |
75 extern "C" { | 75 extern "C" { |
76 #endif | 76 #endif |
77 | 77 |
78 typedef struct ECDSA_SIG_st | 78 typedef struct ECDSA_SIG_st |
79 { | 79 { |
80 BIGNUM *r; | 80 BIGNUM *r; |
81 BIGNUM *s; | 81 BIGNUM *s; |
82 } ECDSA_SIG; | 82 } ECDSA_SIG; |
83 | 83 |
84 /** ECDSA_SIG *ECDSA_SIG_new(void) | 84 /** Allocates and initialize a ECDSA_SIG structure |
85 * allocates and initialize a ECDSA_SIG structure | 85 * \return pointer to a ECDSA_SIG structure or NULL if an error occurred |
86 * \return pointer to a ECDSA_SIG structure or NULL if an error occurred | |
87 */ | 86 */ |
88 ECDSA_SIG *ECDSA_SIG_new(void); | 87 ECDSA_SIG *ECDSA_SIG_new(void); |
89 | 88 |
90 /** ECDSA_SIG_free | 89 /** frees a ECDSA_SIG structure |
91 * frees a ECDSA_SIG structure | 90 * \param sig pointer to the ECDSA_SIG structure |
92 * \param a pointer to the ECDSA_SIG structure | |
93 */ | 91 */ |
94 void» ECDSA_SIG_free(ECDSA_SIG *a); | 92 void» ECDSA_SIG_free(ECDSA_SIG *sig); |
95 | 93 |
96 /** i2d_ECDSA_SIG | 94 /** DER encode content of ECDSA_SIG object (note: this function modifies *pp |
97 * DER encode content of ECDSA_SIG object (note: this function modifies *pp | 95 * (*pp += length of the DER encoded signature)). |
98 * (*pp += length of the DER encoded signature)). | 96 * \param sig pointer to the ECDSA_SIG object |
99 * \param a pointer to the ECDSA_SIG object | 97 * \param pp pointer to a unsigned char pointer for the output or NULL |
100 * \param pp pointer to a unsigned char pointer for the output or NULL | 98 * \return the length of the DER encoded ECDSA_SIG object or 0 |
101 * \return the length of the DER encoded ECDSA_SIG object or 0 | |
102 */ | 99 */ |
103 int» i2d_ECDSA_SIG(const ECDSA_SIG *a, unsigned char **pp); | 100 int» i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp); |
104 | 101 |
105 /** d2i_ECDSA_SIG | 102 /** Decodes a DER encoded ECDSA signature (note: this function changes *pp |
106 * decodes a DER encoded ECDSA signature (note: this function changes *pp | 103 * (*pp += len)). |
107 * (*pp += len)). | 104 * \param sig pointer to ECDSA_SIG pointer (may be NULL) |
108 * \param v pointer to ECDSA_SIG pointer (may be NULL) | 105 * \param pp memory buffer with the DER encoded signature |
109 * \param pp buffer with the DER encoded signature | 106 * \param len length of the buffer |
110 * \param len bufferlength | 107 * \return pointer to the decoded ECDSA_SIG structure (or NULL) |
111 * \return pointer to the decoded ECDSA_SIG structure (or NULL) | |
112 */ | 108 */ |
113 ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **v, const unsigned char **pp, long len); | 109 ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp, long len); |
114 | 110 |
115 /** ECDSA_do_sign | 111 /** Computes the ECDSA signature of the given hash value using |
116 * computes the ECDSA signature of the given hash value using | 112 * the supplied private key and returns the created signature. |
117 * the supplied private key and returns the created signature. | 113 * \param dgst pointer to the hash value |
118 * \param dgst pointer to the hash value | 114 * \param dgst_len length of the hash value |
119 * \param dgst_len length of the hash value | 115 * \param eckey EC_KEY object containing a private EC key |
120 * \param eckey pointer to the EC_KEY object containing a private EC key | 116 * \return pointer to a ECDSA_SIG structure or NULL if an error occurred |
121 * \return pointer to a ECDSA_SIG structure or NULL | |
122 */ | 117 */ |
123 ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst,int dgst_len,EC_KEY *eckey); | 118 ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst,int dgst_len,EC_KEY *eckey); |
124 | 119 |
125 /** ECDSA_do_sign_ex | 120 /** Computes ECDSA signature of a given hash value using the supplied |
126 * computes ECDSA signature of a given hash value using the supplied | 121 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). |
127 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). | 122 * \param dgst pointer to the hash value to sign |
128 * \param dgst pointer to the hash value to sign | 123 * \param dgstlen length of the hash value |
129 * \param dgstlen length of the hash value | 124 * \param kinv BIGNUM with a pre-computed inverse k (optional) |
130 * \param kinv optional pointer to a pre-computed inverse k | 125 * \param rp BIGNUM with a pre-computed rp value (optioanl), |
131 * \param rp optional pointer to the pre-computed rp value (see | 126 * see ECDSA_sign_setup |
132 * ECDSA_sign_setup | 127 * \param eckey EC_KEY object containing a private EC key |
133 * \param eckey pointer to the EC_KEY object containing a private EC key | 128 * \return pointer to a ECDSA_SIG structure or NULL if an error occurred |
134 * \return pointer to a ECDSA_SIG structure or NULL | |
135 */ | 129 */ |
136 ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen, | 130 ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dgstlen, |
137 const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey); | 131 const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey); |
138 | 132 |
139 /** ECDSA_do_verify | 133 /** Verifies that the supplied signature is a valid ECDSA |
140 * verifies that the supplied signature is a valid ECDSA | 134 * signature of the supplied hash value using the supplied public key. |
141 * signature of the supplied hash value using the supplied public key. | 135 * \param dgst pointer to the hash value |
142 * \param dgst pointer to the hash value | 136 * \param dgst_len length of the hash value |
143 * \param dgst_len length of the hash value | 137 * \param sig ECDSA_SIG structure |
144 * \param sig pointer to the ECDSA_SIG structure | 138 * \param eckey EC_KEY object containing a public EC key |
145 * \param eckey pointer to the EC_KEY object containing a public EC key | 139 * \return 1 if the signature is valid, 0 if the signature is invalid |
146 * \return 1 if the signature is valid, 0 if the signature is invalid and -1 on
error | 140 * and -1 on error |
147 */ | 141 */ |
148 int ECDSA_do_verify(const unsigned char *dgst, int dgst_len, | 142 int ECDSA_do_verify(const unsigned char *dgst, int dgst_len, |
149 const ECDSA_SIG *sig, EC_KEY* eckey); | 143 const ECDSA_SIG *sig, EC_KEY* eckey); |
150 | 144 |
151 const ECDSA_METHOD *ECDSA_OpenSSL(void); | 145 const ECDSA_METHOD *ECDSA_OpenSSL(void); |
152 | 146 |
153 /** ECDSA_set_default_method | 147 /** Sets the default ECDSA method |
154 * sets the default ECDSA method | 148 * \param meth new default ECDSA_METHOD |
155 * \param meth the new default ECDSA_METHOD | |
156 */ | 149 */ |
157 void ECDSA_set_default_method(const ECDSA_METHOD *meth); | 150 void ECDSA_set_default_method(const ECDSA_METHOD *meth); |
158 | 151 |
159 /** ECDSA_get_default_method | 152 /** Returns the default ECDSA method |
160 * returns the default ECDSA method | 153 * \return pointer to ECDSA_METHOD structure containing the default method |
161 * \return pointer to ECDSA_METHOD structure containing the default method | |
162 */ | 154 */ |
163 const ECDSA_METHOD *ECDSA_get_default_method(void); | 155 const ECDSA_METHOD *ECDSA_get_default_method(void); |
164 | 156 |
165 /** ECDSA_set_method | 157 /** Sets method to be used for the ECDSA operations |
166 * sets method to be used for the ECDSA operations | 158 * \param eckey EC_KEY object |
167 * \param eckey pointer to the EC_KEY object | 159 * \param meth new method |
168 * \param meth pointer to the new method | 160 * \return 1 on success and 0 otherwise |
169 * \return 1 on success and 0 otherwise | |
170 */ | 161 */ |
171 int ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth); | 162 int ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth); |
172 | 163 |
173 /** ECDSA_size | 164 /** Returns the maximum length of the DER encoded signature |
174 * returns the maximum length of the DER encoded signature | 165 * \param eckey EC_KEY object |
175 * \param eckey pointer to a EC_KEY object | 166 * \return numbers of bytes required for the DER encoded signature |
176 * \return numbers of bytes required for the DER encoded signature | |
177 */ | 167 */ |
178 int ECDSA_size(const EC_KEY *eckey); | 168 int ECDSA_size(const EC_KEY *eckey); |
179 | 169 |
180 /** ECDSA_sign_setup | 170 /** Precompute parts of the signing operation |
181 * precompute parts of the signing operation. | 171 * \param eckey EC_KEY object containing a private EC key |
182 * \param eckey pointer to the EC_KEY object containing a private EC key | 172 * \param ctx BN_CTX object (optional) |
183 * \param ctx pointer to a BN_CTX object (may be NULL) | 173 * \param kinv BIGNUM pointer for the inverse of k |
184 * \param kinv pointer to a BIGNUM pointer for the inverse of k | 174 * \param rp BIGNUM pointer for x coordinate of k * generator |
185 * \param rp pointer to a BIGNUM pointer for x coordinate of k * generator | 175 * \return 1 on success and 0 otherwise |
186 * \return 1 on success and 0 otherwise | |
187 */ | 176 */ |
188 int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, | 177 int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinv, |
189 BIGNUM **rp); | 178 BIGNUM **rp); |
190 | 179 |
191 /** ECDSA_sign | 180 /** Computes ECDSA signature of a given hash value using the supplied |
192 * computes ECDSA signature of a given hash value using the supplied | 181 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). |
193 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). | 182 * \param type this parameter is ignored |
194 * \param type this parameter is ignored | 183 * \param dgst pointer to the hash value to sign |
195 * \param dgst pointer to the hash value to sign | 184 * \param dgstlen length of the hash value |
196 * \param dgstlen length of the hash value | 185 * \param sig memory for the DER encoded created signature |
197 * \param sig buffer to hold the DER encoded signature | 186 * \param siglen pointer to the length of the returned signature |
198 * \param siglen pointer to the length of the returned signature | 187 * \param eckey EC_KEY object containing a private EC key |
199 * \param eckey pointer to the EC_KEY object containing a private EC key | 188 * \return 1 on success and 0 otherwise |
200 * \return 1 on success and 0 otherwise | |
201 */ | 189 */ |
202 int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen, | 190 int ECDSA_sign(int type, const unsigned char *dgst, int dgstlen, |
203 unsigned char *sig, unsigned int *siglen, EC_KEY *eckey); | 191 unsigned char *sig, unsigned int *siglen, EC_KEY *eckey); |
204 | 192 |
205 | 193 |
206 /** ECDSA_sign_ex | 194 /** Computes ECDSA signature of a given hash value using the supplied |
207 * computes ECDSA signature of a given hash value using the supplied | 195 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). |
208 * private key (note: sig must point to ECDSA_size(eckey) bytes of memory). | 196 * \param type this parameter is ignored |
209 * \param type this parameter is ignored | 197 * \param dgst pointer to the hash value to sign |
210 * \param dgst pointer to the hash value to sign | 198 * \param dgstlen length of the hash value |
211 * \param dgstlen length of the hash value | 199 * \param sig buffer to hold the DER encoded signature |
212 * \param sig buffer to hold the DER encoded signature | 200 * \param siglen pointer to the length of the returned signature |
213 * \param siglen pointer to the length of the returned signature | 201 * \param kinv BIGNUM with a pre-computed inverse k (optional) |
214 * \param kinv optional pointer to a pre-computed inverse k | 202 * \param rp BIGNUM with a pre-computed rp value (optioanl), |
215 * \param rp optional pointer to the pre-computed rp value (see | 203 * see ECDSA_sign_setup |
216 * ECDSA_sign_setup | 204 * \param eckey EC_KEY object containing a private EC key |
217 * \param eckey pointer to the EC_KEY object containing a private EC key | 205 * \return 1 on success and 0 otherwise |
218 * \return 1 on success and 0 otherwise | |
219 */ | 206 */ |
220 int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen, | 207 int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen, |
221 unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv, | 208 unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv, |
222 const BIGNUM *rp, EC_KEY *eckey); | 209 const BIGNUM *rp, EC_KEY *eckey); |
223 | 210 |
224 /** ECDSA_verify | 211 /** Verifies that the given signature is valid ECDSA signature |
225 * verifies that the given signature is valid ECDSA signature | 212 * of the supplied hash value using the specified public key. |
226 * of the supplied hash value using the specified public key. | 213 * \param type this parameter is ignored |
227 * \param type this parameter is ignored | 214 * \param dgst pointer to the hash value |
228 * \param dgst pointer to the hash value | 215 * \param dgstlen length of the hash value |
229 * \param dgstlen length of the hash value | 216 * \param sig pointer to the DER encoded signature |
230 * \param sig pointer to the DER encoded signature | 217 * \param siglen length of the DER encoded signature |
231 * \param siglen length of the DER encoded signature | 218 * \param eckey EC_KEY object containing a public EC key |
232 * \param eckey pointer to the EC_KEY object containing a public EC key | 219 * \return 1 if the signature is valid, 0 if the signature is invalid |
233 * \return 1 if the signature is valid, 0 if the signature is invalid and -1 on
error | 220 * and -1 on error |
234 */ | 221 */ |
235 int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen, | 222 int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen, |
236 const unsigned char *sig, int siglen, EC_KEY *eckey); | 223 const unsigned char *sig, int siglen, EC_KEY *eckey); |
237 | 224 |
238 /* the standard ex_data functions */ | 225 /* the standard ex_data functions */ |
239 int ECDSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new | 226 int ECDSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new |
240 *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | 227 *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); |
241 int ECDSA_set_ex_data(EC_KEY *d, int idx, void *arg); | 228 int ECDSA_set_ex_data(EC_KEY *d, int idx, void *arg); |
242 void *ECDSA_get_ex_data(EC_KEY *d, int idx); | 229 void *ECDSA_get_ex_data(EC_KEY *d, int idx); |
243 | 230 |
(...skipping 18 matching lines...) Expand all Loading... |
262 #define ECDSA_R_ERR_EC_LIB 102 | 249 #define ECDSA_R_ERR_EC_LIB 102 |
263 #define ECDSA_R_MISSING_PARAMETERS 103 | 250 #define ECDSA_R_MISSING_PARAMETERS 103 |
264 #define ECDSA_R_NEED_NEW_SETUP_VALUES 106 | 251 #define ECDSA_R_NEED_NEW_SETUP_VALUES 106 |
265 #define ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED 104 | 252 #define ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED 104 |
266 #define ECDSA_R_SIGNATURE_MALLOC_FAILED 105 | 253 #define ECDSA_R_SIGNATURE_MALLOC_FAILED 105 |
267 | 254 |
268 #ifdef __cplusplus | 255 #ifdef __cplusplus |
269 } | 256 } |
270 #endif | 257 #endif |
271 #endif | 258 #endif |
OLD | NEW |