diff options
Diffstat (limited to 'src/lib/libcrypto/rsa/rsa.h')
-rw-r--r-- | src/lib/libcrypto/rsa/rsa.h | 203 |
1 files changed, 98 insertions, 105 deletions
diff --git a/src/lib/libcrypto/rsa/rsa.h b/src/lib/libcrypto/rsa/rsa.h index aeb78ffcd3..9230b2fcc9 100644 --- a/src/lib/libcrypto/rsa/rsa.h +++ b/src/lib/libcrypto/rsa/rsa.h | |||
@@ -63,26 +63,37 @@ | |||
63 | extern "C" { | 63 | extern "C" { |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | #include "bn.h" | 66 | #include <openssl/bn.h> |
67 | #include "crypto.h" | 67 | #include <openssl/crypto.h> |
68 | |||
69 | #ifdef NO_RSA | ||
70 | #error RSA is disabled. | ||
71 | #endif | ||
72 | |||
73 | typedef struct rsa_st RSA; | ||
68 | 74 | ||
69 | typedef struct rsa_meth_st | 75 | typedef struct rsa_meth_st |
70 | { | 76 | { |
71 | char *name; | 77 | const char *name; |
72 | int (*rsa_pub_enc)(); | 78 | int (*rsa_pub_enc)(int flen,unsigned char *from,unsigned char *to, |
73 | int (*rsa_pub_dec)(); | 79 | RSA *rsa,int padding); |
74 | int (*rsa_priv_enc)(); | 80 | int (*rsa_pub_dec)(int flen,unsigned char *from,unsigned char *to, |
75 | int (*rsa_priv_dec)(); | 81 | RSA *rsa,int padding); |
76 | int (*rsa_mod_exp)(); /* Can be null */ | 82 | int (*rsa_priv_enc)(int flen,unsigned char *from,unsigned char *to, |
77 | int (*bn_mod_exp)(); /* Can be null */ | 83 | RSA *rsa,int padding); |
78 | int (*init)(/* RSA * */); /* called at new */ | 84 | int (*rsa_priv_dec)(int flen,unsigned char *from,unsigned char *to, |
79 | int (*finish)(/* RSA * */); /* called at free */ | 85 | RSA *rsa,int padding); |
80 | 86 | int (*rsa_mod_exp)(BIGNUM *r0,BIGNUM *I,RSA *rsa); /* Can be null */ | |
87 | int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
88 | const BIGNUM *m, BN_CTX *ctx, | ||
89 | BN_MONT_CTX *m_ctx); /* Can be null */ | ||
90 | int (*init)(RSA *rsa); /* called at new */ | ||
91 | int (*finish)(RSA *rsa); /* called at free */ | ||
81 | int flags; /* RSA_METHOD_FLAG_* things */ | 92 | int flags; /* RSA_METHOD_FLAG_* things */ |
82 | char *app_data; /* may be needed! */ | 93 | char *app_data; /* may be needed! */ |
83 | } RSA_METHOD; | 94 | } RSA_METHOD; |
84 | 95 | ||
85 | typedef struct rsa_st | 96 | struct rsa_st |
86 | { | 97 | { |
87 | /* The first parameter is used to pickup errors where | 98 | /* The first parameter is used to pickup errors where |
88 | * this is passed instead of aEVP_PKEY, it is set to 0 */ | 99 | * this is passed instead of aEVP_PKEY, it is set to 0 */ |
@@ -97,41 +108,52 @@ typedef struct rsa_st | |||
97 | BIGNUM *dmp1; | 108 | BIGNUM *dmp1; |
98 | BIGNUM *dmq1; | 109 | BIGNUM *dmq1; |
99 | BIGNUM *iqmp; | 110 | BIGNUM *iqmp; |
100 | /* be carefull using this if the RSA structure is shared */ | 111 | /* be careful using this if the RSA structure is shared */ |
101 | CRYPTO_EX_DATA ex_data; | 112 | CRYPTO_EX_DATA ex_data; |
102 | int references; | 113 | int references; |
103 | int flags; | 114 | int flags; |
104 | 115 | ||
105 | /* Normally used to cached montgomery values */ | 116 | /* Used to cache montgomery values */ |
106 | char *method_mod_n; | 117 | BN_MONT_CTX *_method_mod_n; |
107 | char *method_mod_p; | 118 | BN_MONT_CTX *_method_mod_p; |
108 | char *method_mod_q; | 119 | BN_MONT_CTX *_method_mod_q; |
109 | 120 | ||
121 | /* all BIGNUM values are actually in the following data, if it is not | ||
122 | * NULL */ | ||
123 | char *bignum_data; | ||
110 | BN_BLINDING *blinding; | 124 | BN_BLINDING *blinding; |
111 | } RSA; | 125 | }; |
112 | 126 | ||
113 | #define RSA_3 0x3L | 127 | #define RSA_3 0x3L |
114 | #define RSA_F4 0x10001L | 128 | #define RSA_F4 0x10001L |
115 | 129 | ||
116 | #define RSA_METHOD_FLAG_NO_CHECK 0x01 /* don't check pub/private match */ | 130 | #define RSA_METHOD_FLAG_NO_CHECK 0x01 /* don't check pub/private match */ |
131 | |||
117 | #define RSA_FLAG_CACHE_PUBLIC 0x02 | 132 | #define RSA_FLAG_CACHE_PUBLIC 0x02 |
118 | #define RSA_FLAG_CACHE_PRIVATE 0x04 | 133 | #define RSA_FLAG_CACHE_PRIVATE 0x04 |
119 | #define RSA_FLAG_BLINDING 0x08 | 134 | #define RSA_FLAG_BLINDING 0x08 |
120 | #define RSA_FLAG_THREAD_SAFE 0x10 | 135 | #define RSA_FLAG_THREAD_SAFE 0x10 |
136 | /* This flag means the private key operations will be handled by rsa_mod_exp | ||
137 | * and that they do not depend on the private key components being present: | ||
138 | * for example a key stored in external hardware. Without this flag bn_mod_exp | ||
139 | * gets called when private key components are absent. | ||
140 | */ | ||
141 | #define RSA_FLAG_EXT_PKEY 0x20 | ||
121 | 142 | ||
122 | #define RSA_PKCS1_PADDING 1 | 143 | #define RSA_PKCS1_PADDING 1 |
123 | #define RSA_SSLV23_PADDING 2 | 144 | #define RSA_SSLV23_PADDING 2 |
124 | #define RSA_NO_PADDING 3 | 145 | #define RSA_NO_PADDING 3 |
146 | #define RSA_PKCS1_OAEP_PADDING 4 | ||
125 | 147 | ||
126 | #define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,(char *)arg) | 148 | #define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,(char *)arg) |
127 | #define RSA_get_app_data(s) RSA_get_ex_data(s,0) | 149 | #define RSA_get_app_data(s) RSA_get_ex_data(s,0) |
128 | 150 | ||
129 | #ifndef NOPROTO | ||
130 | RSA * RSA_new(void); | 151 | RSA * RSA_new(void); |
131 | RSA * RSA_new_method(RSA_METHOD *method); | 152 | RSA * RSA_new_method(RSA_METHOD *method); |
132 | int RSA_size(RSA *); | 153 | int RSA_size(RSA *); |
133 | RSA * RSA_generate_key(int bits, unsigned long e,void | 154 | RSA * RSA_generate_key(int bits, unsigned long e,void |
134 | (*callback)(int,int,char *),char *cb_arg); | 155 | (*callback)(int,int,void *),void *cb_arg); |
156 | int RSA_check_key(RSA *); | ||
135 | /* next 4 return -1 on error */ | 157 | /* next 4 return -1 on error */ |
136 | int RSA_public_encrypt(int flen, unsigned char *from, | 158 | int RSA_public_encrypt(int flen, unsigned char *from, |
137 | unsigned char *to, RSA *rsa,int padding); | 159 | unsigned char *to, RSA *rsa,int padding); |
@@ -146,6 +168,12 @@ void RSA_free (RSA *r); | |||
146 | int RSA_flags(RSA *r); | 168 | int RSA_flags(RSA *r); |
147 | 169 | ||
148 | void RSA_set_default_method(RSA_METHOD *meth); | 170 | void RSA_set_default_method(RSA_METHOD *meth); |
171 | RSA_METHOD *RSA_get_default_method(void); | ||
172 | RSA_METHOD *RSA_get_method(RSA *rsa); | ||
173 | RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth); | ||
174 | |||
175 | /* This function needs the memory locking malloc callbacks to be installed */ | ||
176 | int RSA_memory_lock(RSA *r); | ||
149 | 177 | ||
150 | /* If you have RSAref compiled in. */ | 178 | /* If you have RSAref compiled in. */ |
151 | RSA_METHOD *RSA_PKCS1_RSAref(void); | 179 | RSA_METHOD *RSA_PKCS1_RSAref(void); |
@@ -193,107 +221,63 @@ void RSA_blinding_off(RSA *rsa); | |||
193 | int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen, | 221 | int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen, |
194 | unsigned char *f,int fl); | 222 | unsigned char *f,int fl); |
195 | int RSA_padding_check_PKCS1_type_1(unsigned char *to,int tlen, | 223 | int RSA_padding_check_PKCS1_type_1(unsigned char *to,int tlen, |
196 | unsigned char *f,int fl); | 224 | unsigned char *f,int fl,int rsa_len); |
197 | int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen, | 225 | int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen, |
198 | unsigned char *f,int fl); | 226 | unsigned char *f,int fl); |
199 | int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen, | 227 | int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen, |
200 | unsigned char *f,int fl); | 228 | unsigned char *f,int fl,int rsa_len); |
229 | int RSA_padding_add_PKCS1_OAEP(unsigned char *to,int tlen, | ||
230 | unsigned char *f,int fl,unsigned char *p, | ||
231 | int pl); | ||
232 | int RSA_padding_check_PKCS1_OAEP(unsigned char *to,int tlen, | ||
233 | unsigned char *f,int fl,int rsa_len, | ||
234 | unsigned char *p,int pl); | ||
201 | int RSA_padding_add_SSLv23(unsigned char *to,int tlen, | 235 | int RSA_padding_add_SSLv23(unsigned char *to,int tlen, |
202 | unsigned char *f,int fl); | 236 | unsigned char *f,int fl); |
203 | int RSA_padding_check_SSLv23(unsigned char *to,int tlen, | 237 | int RSA_padding_check_SSLv23(unsigned char *to,int tlen, |
204 | unsigned char *f,int fl); | 238 | unsigned char *f,int fl,int rsa_len); |
205 | int RSA_padding_add_none(unsigned char *to,int tlen, | 239 | int RSA_padding_add_none(unsigned char *to,int tlen, |
206 | unsigned char *f,int fl); | 240 | unsigned char *f,int fl); |
207 | int RSA_padding_check_none(unsigned char *to,int tlen, | 241 | int RSA_padding_check_none(unsigned char *to,int tlen, |
208 | unsigned char *f,int fl); | 242 | unsigned char *f,int fl,int rsa_len); |
209 | 243 | ||
210 | int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(), | 244 | int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(), |
211 | int (*dup_func)(), void (*free_func)()); | 245 | int (*dup_func)(), void (*free_func)()); |
212 | int RSA_set_ex_data(RSA *r,int idx,char *arg); | 246 | int RSA_set_ex_data(RSA *r,int idx,char *arg); |
213 | char *RSA_get_ex_data(RSA *r, int idx); | 247 | char *RSA_get_ex_data(RSA *r, int idx); |
214 | 248 | ||
215 | #else | ||
216 | |||
217 | RSA * RSA_new(); | ||
218 | RSA * RSA_new_method(); | ||
219 | int RSA_size(); | ||
220 | RSA * RSA_generate_key(); | ||
221 | int RSA_public_encrypt(); | ||
222 | int RSA_private_encrypt(); | ||
223 | int RSA_public_decrypt(); | ||
224 | int RSA_private_decrypt(); | ||
225 | void RSA_free (); | ||
226 | |||
227 | int RSA_flags(); | ||
228 | |||
229 | void RSA_set_default_method(); | ||
230 | |||
231 | /* RSA_METHOD *RSA_PKCS1_RSAref(); */ | ||
232 | RSA_METHOD *RSA_PKCS1_SSLeay(); | ||
233 | |||
234 | void ERR_load_RSA_strings(); | ||
235 | |||
236 | RSA * d2i_RSAPublicKey(); | ||
237 | int i2d_RSAPublicKey(); | ||
238 | RSA * d2i_RSAPrivateKey(); | ||
239 | int i2d_RSAPrivateKey(); | ||
240 | #ifndef NO_FP_API | ||
241 | int RSA_print_fp(); | ||
242 | #endif | ||
243 | |||
244 | int RSA_print(); | ||
245 | |||
246 | int i2d_Netscape_RSA(); | ||
247 | RSA *d2i_Netscape_RSA(); | ||
248 | RSA *d2i_Netscape_RSA_2(); | ||
249 | |||
250 | int RSA_sign(); | ||
251 | int RSA_verify(); | ||
252 | |||
253 | int RSA_sign_ASN1_OCTET_STRING(); | ||
254 | int RSA_verify_ASN1_OCTET_STRING(); | ||
255 | int RSA_blinding_on(); | ||
256 | void RSA_blinding_off(); | ||
257 | |||
258 | int RSA_padding_add_PKCS1_type_1(); | ||
259 | int RSA_padding_check_PKCS1_type_1(); | ||
260 | int RSA_padding_add_PKCS1_type_2(); | ||
261 | int RSA_padding_check_PKCS1_type_2(); | ||
262 | int RSA_padding_add_SSLv23(); | ||
263 | int RSA_padding_check_SSLv23(); | ||
264 | int RSA_padding_add_none(); | ||
265 | int RSA_padding_check_none(); | ||
266 | |||
267 | int RSA_get_ex_new_index(); | ||
268 | int RSA_set_ex_data(); | ||
269 | char *RSA_get_ex_data(); | ||
270 | |||
271 | #endif | ||
272 | |||
273 | /* BEGIN ERROR CODES */ | 249 | /* BEGIN ERROR CODES */ |
250 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
251 | * made after this point may be overwritten when the script is next run. | ||
252 | */ | ||
253 | |||
274 | /* Error codes for the RSA functions. */ | 254 | /* Error codes for the RSA functions. */ |
275 | 255 | ||
276 | /* Function codes. */ | 256 | /* Function codes. */ |
277 | #define RSA_F_RSA_EAY_PRIVATE_DECRYPT 100 | 257 | #define RSA_F_MEMORY_LOCK 100 |
278 | #define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 101 | 258 | #define RSA_F_RSA_CHECK_KEY 123 |
279 | #define RSA_F_RSA_EAY_PUBLIC_DECRYPT 102 | 259 | #define RSA_F_RSA_EAY_PRIVATE_DECRYPT 101 |
280 | #define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 103 | 260 | #define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 102 |
281 | #define RSA_F_RSA_GENERATE_KEY 104 | 261 | #define RSA_F_RSA_EAY_PUBLIC_DECRYPT 103 |
282 | #define RSA_F_RSA_NEW_METHOD 105 | 262 | #define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 104 |
283 | #define RSA_F_RSA_PADDING_ADD_NONE 106 | 263 | #define RSA_F_RSA_GENERATE_KEY 105 |
284 | #define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 107 | 264 | #define RSA_F_RSA_NEW_METHOD 106 |
285 | #define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 108 | 265 | #define RSA_F_RSA_PADDING_ADD_NONE 107 |
286 | #define RSA_F_RSA_PADDING_ADD_SSLV23 109 | 266 | #define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121 |
287 | #define RSA_F_RSA_PADDING_CHECK_NONE 110 | 267 | #define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108 |
288 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 111 | 268 | #define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109 |
289 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 112 | 269 | #define RSA_F_RSA_PADDING_ADD_SSLV23 110 |
290 | #define RSA_F_RSA_PADDING_CHECK_SSLV23 113 | 270 | #define RSA_F_RSA_PADDING_CHECK_NONE 111 |
291 | #define RSA_F_RSA_PRINT 114 | 271 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122 |
292 | #define RSA_F_RSA_PRINT_FP 115 | 272 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112 |
293 | #define RSA_F_RSA_SIGN 116 | 273 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113 |
294 | #define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 117 | 274 | #define RSA_F_RSA_PADDING_CHECK_SSLV23 114 |
295 | #define RSA_F_RSA_VERIFY 118 | 275 | #define RSA_F_RSA_PRINT 115 |
296 | #define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 119 | 276 | #define RSA_F_RSA_PRINT_FP 116 |
277 | #define RSA_F_RSA_SIGN 117 | ||
278 | #define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118 | ||
279 | #define RSA_F_RSA_VERIFY 119 | ||
280 | #define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120 | ||
297 | 281 | ||
298 | /* Reason codes. */ | 282 | /* Reason codes. */ |
299 | #define RSA_R_ALGORITHM_MISMATCH 100 | 283 | #define RSA_R_ALGORITHM_MISMATCH 100 |
@@ -301,22 +285,31 @@ char *RSA_get_ex_data(); | |||
301 | #define RSA_R_BAD_FIXED_HEADER_DECRYPT 102 | 285 | #define RSA_R_BAD_FIXED_HEADER_DECRYPT 102 |
302 | #define RSA_R_BAD_PAD_BYTE_COUNT 103 | 286 | #define RSA_R_BAD_PAD_BYTE_COUNT 103 |
303 | #define RSA_R_BAD_SIGNATURE 104 | 287 | #define RSA_R_BAD_SIGNATURE 104 |
304 | #define RSA_R_BAD_ZERO_BYTE 105 | ||
305 | #define RSA_R_BLOCK_TYPE_IS_NOT_01 106 | 288 | #define RSA_R_BLOCK_TYPE_IS_NOT_01 106 |
306 | #define RSA_R_BLOCK_TYPE_IS_NOT_02 107 | 289 | #define RSA_R_BLOCK_TYPE_IS_NOT_02 107 |
307 | #define RSA_R_DATA_GREATER_THAN_MOD_LEN 108 | 290 | #define RSA_R_DATA_GREATER_THAN_MOD_LEN 108 |
308 | #define RSA_R_DATA_TOO_LARGE 109 | 291 | #define RSA_R_DATA_TOO_LARGE 109 |
309 | #define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110 | 292 | #define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110 |
310 | #define RSA_R_DATA_TOO_SMALL 111 | 293 | #define RSA_R_DATA_TOO_SMALL 111 |
294 | #define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122 | ||
295 | #define RSA_R_D_E_NOT_CONGRUENT_TO_1 123 | ||
311 | #define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112 | 296 | #define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112 |
297 | #define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124 | ||
298 | #define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125 | ||
299 | #define RSA_R_IQMP_NOT_INVERSE_OF_Q 126 | ||
300 | #define RSA_R_KEY_SIZE_TOO_SMALL 120 | ||
312 | #define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 | 301 | #define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 |
302 | #define RSA_R_N_DOES_NOT_EQUAL_P_Q 127 | ||
303 | #define RSA_R_OAEP_DECODING_ERROR 121 | ||
313 | #define RSA_R_PADDING_CHECK_FAILED 114 | 304 | #define RSA_R_PADDING_CHECK_FAILED 114 |
305 | #define RSA_R_P_NOT_PRIME 128 | ||
306 | #define RSA_R_Q_NOT_PRIME 129 | ||
314 | #define RSA_R_SSLV3_ROLLBACK_ATTACK 115 | 307 | #define RSA_R_SSLV3_ROLLBACK_ATTACK 115 |
315 | #define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116 | 308 | #define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116 |
316 | #define RSA_R_UNKNOWN_ALGORITHM_TYPE 117 | 309 | #define RSA_R_UNKNOWN_ALGORITHM_TYPE 117 |
317 | #define RSA_R_UNKNOWN_PADDING_TYPE 118 | 310 | #define RSA_R_UNKNOWN_PADDING_TYPE 118 |
318 | #define RSA_R_WRONG_SIGNATURE_LENGTH 119 | 311 | #define RSA_R_WRONG_SIGNATURE_LENGTH 119 |
319 | 312 | ||
320 | #ifdef __cplusplus | 313 | #ifdef __cplusplus |
321 | } | 314 | } |
322 | #endif | 315 | #endif |