diff options
author | cvs2svn <admin@example.com> | 2001-10-01 21:58:54 +0000 |
---|---|---|
committer | cvs2svn <admin@example.com> | 2001-10-01 21:58:54 +0000 |
commit | 2b482d950b0e856294fcd4c1068c1b21939a7240 (patch) | |
tree | aa05f6be64877f76547f1b54ad84f7bfcb291f5d /src/lib/libcrypto/rsa | |
parent | d7b0aad33e28dafbbef67eb5b84ecb05a844fc88 (diff) | |
download | openbsd-OPENBSD_3_0_BASE.tar.gz openbsd-OPENBSD_3_0_BASE.tar.bz2 openbsd-OPENBSD_3_0_BASE.zip |
This commit was manufactured by cvs2git to create tag 'OPENBSD_3_0_BASE'.OPENBSD_3_0_BASE
Diffstat (limited to 'src/lib/libcrypto/rsa')
-rw-r--r-- | src/lib/libcrypto/rsa/rsa.h | 357 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_chk.c | 184 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_eay.c | 579 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_err.c | 148 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_gen.c | 197 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_lib.c | 388 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_none.c | 98 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_oaep.c | 168 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_pk1.c | 224 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_saos.c | 144 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_sign.c | 224 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_ssl.c | 154 |
12 files changed, 0 insertions, 2865 deletions
diff --git a/src/lib/libcrypto/rsa/rsa.h b/src/lib/libcrypto/rsa/rsa.h deleted file mode 100644 index bda636a365..0000000000 --- a/src/lib/libcrypto/rsa/rsa.h +++ /dev/null | |||
@@ -1,357 +0,0 @@ | |||
1 | /* crypto/rsa/rsa.h */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #ifndef HEADER_RSA_H | ||
60 | #define HEADER_RSA_H | ||
61 | |||
62 | #ifndef NO_BIO | ||
63 | #include <openssl/bio.h> | ||
64 | #endif | ||
65 | #include <openssl/bn.h> | ||
66 | #include <openssl/crypto.h> | ||
67 | |||
68 | #ifdef NO_RSA | ||
69 | #error RSA is disabled. | ||
70 | #endif | ||
71 | |||
72 | #ifdef __cplusplus | ||
73 | extern "C" { | ||
74 | #endif | ||
75 | |||
76 | typedef struct rsa_st RSA; | ||
77 | |||
78 | typedef struct rsa_meth_st | ||
79 | { | ||
80 | const char *name; | ||
81 | int (*rsa_pub_enc)(int flen,unsigned char *from,unsigned char *to, | ||
82 | RSA *rsa,int padding); | ||
83 | int (*rsa_pub_dec)(int flen,unsigned char *from,unsigned char *to, | ||
84 | RSA *rsa,int padding); | ||
85 | int (*rsa_priv_enc)(int flen,unsigned char *from,unsigned char *to, | ||
86 | RSA *rsa,int padding); | ||
87 | int (*rsa_priv_dec)(int flen,unsigned char *from,unsigned char *to, | ||
88 | RSA *rsa,int padding); | ||
89 | int (*rsa_mod_exp)(BIGNUM *r0,BIGNUM *I,RSA *rsa); /* Can be null */ | ||
90 | int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
91 | const BIGNUM *m, BN_CTX *ctx, | ||
92 | BN_MONT_CTX *m_ctx); /* Can be null */ | ||
93 | int (*init)(RSA *rsa); /* called at new */ | ||
94 | int (*finish)(RSA *rsa); /* called at free */ | ||
95 | int flags; /* RSA_METHOD_FLAG_* things */ | ||
96 | char *app_data; /* may be needed! */ | ||
97 | /* New sign and verify functions: some libraries don't allow arbitrary data | ||
98 | * to be signed/verified: this allows them to be used. Note: for this to work | ||
99 | * the RSA_public_decrypt() and RSA_private_encrypt() should *NOT* be used | ||
100 | * RSA_sign(), RSA_verify() should be used instead. Note: for backwards | ||
101 | * compatibility this functionality is only enabled if the RSA_FLAG_SIGN_VER | ||
102 | * option is set in 'flags'. | ||
103 | */ | ||
104 | int (*rsa_sign)(int type, unsigned char *m, unsigned int m_len, | ||
105 | unsigned char *sigret, unsigned int *siglen, RSA *rsa); | ||
106 | int (*rsa_verify)(int dtype, unsigned char *m, unsigned int m_len, | ||
107 | unsigned char *sigbuf, unsigned int siglen, RSA *rsa); | ||
108 | |||
109 | } RSA_METHOD; | ||
110 | |||
111 | struct rsa_st | ||
112 | { | ||
113 | /* The first parameter is used to pickup errors where | ||
114 | * this is passed instead of aEVP_PKEY, it is set to 0 */ | ||
115 | int pad; | ||
116 | int version; | ||
117 | #if 0 | ||
118 | RSA_METHOD *meth; | ||
119 | #else | ||
120 | struct engine_st *engine; | ||
121 | #endif | ||
122 | BIGNUM *n; | ||
123 | BIGNUM *e; | ||
124 | BIGNUM *d; | ||
125 | BIGNUM *p; | ||
126 | BIGNUM *q; | ||
127 | BIGNUM *dmp1; | ||
128 | BIGNUM *dmq1; | ||
129 | BIGNUM *iqmp; | ||
130 | /* be careful using this if the RSA structure is shared */ | ||
131 | CRYPTO_EX_DATA ex_data; | ||
132 | int references; | ||
133 | int flags; | ||
134 | |||
135 | /* Used to cache montgomery values */ | ||
136 | BN_MONT_CTX *_method_mod_n; | ||
137 | BN_MONT_CTX *_method_mod_p; | ||
138 | BN_MONT_CTX *_method_mod_q; | ||
139 | |||
140 | /* all BIGNUM values are actually in the following data, if it is not | ||
141 | * NULL */ | ||
142 | char *bignum_data; | ||
143 | BN_BLINDING *blinding; | ||
144 | }; | ||
145 | |||
146 | #define RSA_3 0x3L | ||
147 | #define RSA_F4 0x10001L | ||
148 | |||
149 | #define RSA_METHOD_FLAG_NO_CHECK 0x01 /* don't check pub/private match */ | ||
150 | |||
151 | #define RSA_FLAG_CACHE_PUBLIC 0x02 | ||
152 | #define RSA_FLAG_CACHE_PRIVATE 0x04 | ||
153 | #define RSA_FLAG_BLINDING 0x08 | ||
154 | #define RSA_FLAG_THREAD_SAFE 0x10 | ||
155 | /* This flag means the private key operations will be handled by rsa_mod_exp | ||
156 | * and that they do not depend on the private key components being present: | ||
157 | * for example a key stored in external hardware. Without this flag bn_mod_exp | ||
158 | * gets called when private key components are absent. | ||
159 | */ | ||
160 | #define RSA_FLAG_EXT_PKEY 0x20 | ||
161 | |||
162 | /* This flag in the RSA_METHOD enables the new rsa_sign, rsa_verify functions. | ||
163 | */ | ||
164 | #define RSA_FLAG_SIGN_VER 0x40 | ||
165 | |||
166 | #define RSA_PKCS1_PADDING 1 | ||
167 | #define RSA_SSLV23_PADDING 2 | ||
168 | #define RSA_NO_PADDING 3 | ||
169 | #define RSA_PKCS1_OAEP_PADDING 4 | ||
170 | |||
171 | #define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg) | ||
172 | #define RSA_get_app_data(s) RSA_get_ex_data(s,0) | ||
173 | |||
174 | RSA * RSA_new(void); | ||
175 | #if 0 | ||
176 | RSA * RSA_new_method(RSA_METHOD *method); | ||
177 | #else | ||
178 | RSA * RSA_new_method(struct engine_st *engine); | ||
179 | #endif | ||
180 | int RSA_size(RSA *); | ||
181 | RSA * RSA_generate_key(int bits, unsigned long e,void | ||
182 | (*callback)(int,int,void *),void *cb_arg); | ||
183 | int RSA_check_key(RSA *); | ||
184 | /* next 4 return -1 on error */ | ||
185 | int RSA_public_encrypt(int flen, unsigned char *from, | ||
186 | unsigned char *to, RSA *rsa,int padding); | ||
187 | int RSA_private_encrypt(int flen, unsigned char *from, | ||
188 | unsigned char *to, RSA *rsa,int padding); | ||
189 | int RSA_public_decrypt(int flen, unsigned char *from, | ||
190 | unsigned char *to, RSA *rsa,int padding); | ||
191 | int RSA_private_decrypt(int flen, unsigned char *from, | ||
192 | unsigned char *to, RSA *rsa,int padding); | ||
193 | void RSA_free (RSA *r); | ||
194 | |||
195 | int RSA_flags(RSA *r); | ||
196 | |||
197 | void RSA_set_default_openssl_method(RSA_METHOD *meth); | ||
198 | RSA_METHOD *RSA_get_default_openssl_method(void); | ||
199 | RSA_METHOD *RSA_get_method(RSA *rsa); | ||
200 | #if 0 | ||
201 | RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth); | ||
202 | #else | ||
203 | int RSA_set_method(RSA *rsa, struct engine_st *engine); | ||
204 | #endif | ||
205 | |||
206 | /* This function needs the memory locking malloc callbacks to be installed */ | ||
207 | int RSA_memory_lock(RSA *r); | ||
208 | |||
209 | /* If you have RSAref compiled in. */ | ||
210 | RSA_METHOD *RSA_PKCS1_RSAref(void); | ||
211 | |||
212 | /* these are the actual SSLeay RSA functions */ | ||
213 | RSA_METHOD *RSA_PKCS1_SSLeay(void); | ||
214 | |||
215 | RSA_METHOD *RSA_null_method(void); | ||
216 | |||
217 | void ERR_load_RSA_strings(void ); | ||
218 | |||
219 | RSA * d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length); | ||
220 | int i2d_RSAPublicKey(RSA *a, unsigned char **pp); | ||
221 | RSA * d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length); | ||
222 | int i2d_RSAPrivateKey(RSA *a, unsigned char **pp); | ||
223 | #ifndef NO_FP_API | ||
224 | int RSA_print_fp(FILE *fp, RSA *r,int offset); | ||
225 | #endif | ||
226 | |||
227 | #ifndef NO_BIO | ||
228 | int RSA_print(BIO *bp, RSA *r,int offset); | ||
229 | #endif | ||
230 | |||
231 | int i2d_RSA_NET(RSA *a, unsigned char **pp, int (*cb)(), int sgckey); | ||
232 | RSA *d2i_RSA_NET(RSA **a, unsigned char **pp, long length, int (*cb)(), int sgckey); | ||
233 | RSA *d2i_RSA_NET_2(RSA **a, unsigned char **pp, long length, int (*cb)(), int sgckey); | ||
234 | |||
235 | int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)()); | ||
236 | RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)()); | ||
237 | /* Naughty internal function required elsewhere, to handle a MS structure | ||
238 | * that is the same as the netscape one :-) */ | ||
239 | RSA *d2i_Netscape_RSA_2(RSA **a, unsigned char **pp, long length, int (*cb)()); | ||
240 | |||
241 | /* The following 2 functions sign and verify a X509_SIG ASN1 object | ||
242 | * inside PKCS#1 padded RSA encryption */ | ||
243 | int RSA_sign(int type, unsigned char *m, unsigned int m_len, | ||
244 | unsigned char *sigret, unsigned int *siglen, RSA *rsa); | ||
245 | int RSA_verify(int type, unsigned char *m, unsigned int m_len, | ||
246 | unsigned char *sigbuf, unsigned int siglen, RSA *rsa); | ||
247 | |||
248 | /* The following 2 function sign and verify a ASN1_OCTET_STRING | ||
249 | * object inside PKCS#1 padded RSA encryption */ | ||
250 | int RSA_sign_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len, | ||
251 | unsigned char *sigret, unsigned int *siglen, RSA *rsa); | ||
252 | int RSA_verify_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len, | ||
253 | unsigned char *sigbuf, unsigned int siglen, RSA *rsa); | ||
254 | |||
255 | int RSA_blinding_on(RSA *rsa, BN_CTX *ctx); | ||
256 | void RSA_blinding_off(RSA *rsa); | ||
257 | |||
258 | int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen, | ||
259 | unsigned char *f,int fl); | ||
260 | int RSA_padding_check_PKCS1_type_1(unsigned char *to,int tlen, | ||
261 | unsigned char *f,int fl,int rsa_len); | ||
262 | int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen, | ||
263 | unsigned char *f,int fl); | ||
264 | int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen, | ||
265 | unsigned char *f,int fl,int rsa_len); | ||
266 | int RSA_padding_add_PKCS1_OAEP(unsigned char *to,int tlen, | ||
267 | unsigned char *f,int fl,unsigned char *p, | ||
268 | int pl); | ||
269 | int RSA_padding_check_PKCS1_OAEP(unsigned char *to,int tlen, | ||
270 | unsigned char *f,int fl,int rsa_len, | ||
271 | unsigned char *p,int pl); | ||
272 | int RSA_padding_add_SSLv23(unsigned char *to,int tlen, | ||
273 | unsigned char *f,int fl); | ||
274 | int RSA_padding_check_SSLv23(unsigned char *to,int tlen, | ||
275 | unsigned char *f,int fl,int rsa_len); | ||
276 | int RSA_padding_add_none(unsigned char *to,int tlen, | ||
277 | unsigned char *f,int fl); | ||
278 | int RSA_padding_check_none(unsigned char *to,int tlen, | ||
279 | unsigned char *f,int fl,int rsa_len); | ||
280 | |||
281 | int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
282 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
283 | int RSA_set_ex_data(RSA *r,int idx,void *arg); | ||
284 | void *RSA_get_ex_data(RSA *r, int idx); | ||
285 | |||
286 | /* BEGIN ERROR CODES */ | ||
287 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
288 | * made after this point may be overwritten when the script is next run. | ||
289 | */ | ||
290 | |||
291 | /* Error codes for the RSA functions. */ | ||
292 | |||
293 | /* Function codes. */ | ||
294 | #define RSA_F_MEMORY_LOCK 100 | ||
295 | #define RSA_F_RSA_CHECK_KEY 123 | ||
296 | #define RSA_F_RSA_EAY_PRIVATE_DECRYPT 101 | ||
297 | #define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 102 | ||
298 | #define RSA_F_RSA_EAY_PUBLIC_DECRYPT 103 | ||
299 | #define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 104 | ||
300 | #define RSA_F_RSA_GENERATE_KEY 105 | ||
301 | #define RSA_F_RSA_NEW_METHOD 106 | ||
302 | #define RSA_F_RSA_NULL 124 | ||
303 | #define RSA_F_RSA_PADDING_ADD_NONE 107 | ||
304 | #define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121 | ||
305 | #define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108 | ||
306 | #define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109 | ||
307 | #define RSA_F_RSA_PADDING_ADD_SSLV23 110 | ||
308 | #define RSA_F_RSA_PADDING_CHECK_NONE 111 | ||
309 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122 | ||
310 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112 | ||
311 | #define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113 | ||
312 | #define RSA_F_RSA_PADDING_CHECK_SSLV23 114 | ||
313 | #define RSA_F_RSA_PRINT 115 | ||
314 | #define RSA_F_RSA_PRINT_FP 116 | ||
315 | #define RSA_F_RSA_SIGN 117 | ||
316 | #define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118 | ||
317 | #define RSA_F_RSA_VERIFY 119 | ||
318 | #define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120 | ||
319 | |||
320 | /* Reason codes. */ | ||
321 | #define RSA_R_ALGORITHM_MISMATCH 100 | ||
322 | #define RSA_R_BAD_E_VALUE 101 | ||
323 | #define RSA_R_BAD_FIXED_HEADER_DECRYPT 102 | ||
324 | #define RSA_R_BAD_PAD_BYTE_COUNT 103 | ||
325 | #define RSA_R_BAD_SIGNATURE 104 | ||
326 | #define RSA_R_BLOCK_TYPE_IS_NOT_01 106 | ||
327 | #define RSA_R_BLOCK_TYPE_IS_NOT_02 107 | ||
328 | #define RSA_R_DATA_GREATER_THAN_MOD_LEN 108 | ||
329 | #define RSA_R_DATA_TOO_LARGE 109 | ||
330 | #define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110 | ||
331 | #define RSA_R_DATA_TOO_SMALL 111 | ||
332 | #define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122 | ||
333 | #define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112 | ||
334 | #define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124 | ||
335 | #define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125 | ||
336 | #define RSA_R_D_E_NOT_CONGRUENT_TO_1 123 | ||
337 | #define RSA_R_INVALID_MESSAGE_LENGTH 131 | ||
338 | #define RSA_R_IQMP_NOT_INVERSE_OF_Q 126 | ||
339 | #define RSA_R_KEY_SIZE_TOO_SMALL 120 | ||
340 | #define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 | ||
341 | #define RSA_R_N_DOES_NOT_EQUAL_P_Q 127 | ||
342 | #define RSA_R_OAEP_DECODING_ERROR 121 | ||
343 | #define RSA_R_PADDING_CHECK_FAILED 114 | ||
344 | #define RSA_R_P_NOT_PRIME 128 | ||
345 | #define RSA_R_Q_NOT_PRIME 129 | ||
346 | #define RSA_R_RSA_OPERATIONS_NOT_SUPPORTED 130 | ||
347 | #define RSA_R_SSLV3_ROLLBACK_ATTACK 115 | ||
348 | #define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116 | ||
349 | #define RSA_R_UNKNOWN_ALGORITHM_TYPE 117 | ||
350 | #define RSA_R_UNKNOWN_PADDING_TYPE 118 | ||
351 | #define RSA_R_WRONG_SIGNATURE_LENGTH 119 | ||
352 | |||
353 | #ifdef __cplusplus | ||
354 | } | ||
355 | #endif | ||
356 | #endif | ||
357 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_chk.c b/src/lib/libcrypto/rsa/rsa_chk.c deleted file mode 100644 index 91b9115798..0000000000 --- a/src/lib/libcrypto/rsa/rsa_chk.c +++ /dev/null | |||
@@ -1,184 +0,0 @@ | |||
1 | /* crypto/rsa/rsa_chk.c -*- Mode: C; c-file-style: "eay" -*- */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | */ | ||
50 | |||
51 | #include <openssl/bn.h> | ||
52 | #include <openssl/err.h> | ||
53 | #include <openssl/rsa.h> | ||
54 | |||
55 | |||
56 | int RSA_check_key(RSA *key) | ||
57 | { | ||
58 | BIGNUM *i, *j, *k, *l, *m; | ||
59 | BN_CTX *ctx; | ||
60 | int r; | ||
61 | int ret=1; | ||
62 | |||
63 | i = BN_new(); | ||
64 | j = BN_new(); | ||
65 | k = BN_new(); | ||
66 | l = BN_new(); | ||
67 | m = BN_new(); | ||
68 | ctx = BN_CTX_new(); | ||
69 | if (i == NULL || j == NULL || k == NULL || l == NULL || | ||
70 | m == NULL || ctx == NULL) | ||
71 | { | ||
72 | ret = -1; | ||
73 | RSAerr(RSA_F_RSA_CHECK_KEY, ERR_R_MALLOC_FAILURE); | ||
74 | goto err; | ||
75 | } | ||
76 | |||
77 | /* p prime? */ | ||
78 | r = BN_is_prime(key->p, BN_prime_checks, NULL, NULL, NULL); | ||
79 | if (r != 1) | ||
80 | { | ||
81 | ret = r; | ||
82 | if (r != 0) | ||
83 | goto err; | ||
84 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_P_NOT_PRIME); | ||
85 | } | ||
86 | |||
87 | /* q prime? */ | ||
88 | r = BN_is_prime(key->q, BN_prime_checks, NULL, NULL, NULL); | ||
89 | if (r != 1) | ||
90 | { | ||
91 | ret = r; | ||
92 | if (r != 0) | ||
93 | goto err; | ||
94 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_Q_NOT_PRIME); | ||
95 | } | ||
96 | |||
97 | /* n = p*q? */ | ||
98 | r = BN_mul(i, key->p, key->q, ctx); | ||
99 | if (!r) { ret = -1; goto err; } | ||
100 | |||
101 | if (BN_cmp(i, key->n) != 0) | ||
102 | { | ||
103 | ret = 0; | ||
104 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_N_DOES_NOT_EQUAL_P_Q); | ||
105 | } | ||
106 | |||
107 | /* d*e = 1 mod lcm(p-1,q-1)? */ | ||
108 | |||
109 | r = BN_sub(i, key->p, BN_value_one()); | ||
110 | if (!r) { ret = -1; goto err; } | ||
111 | r = BN_sub(j, key->q, BN_value_one()); | ||
112 | if (!r) { ret = -1; goto err; } | ||
113 | |||
114 | /* now compute k = lcm(i,j) */ | ||
115 | r = BN_mul(l, i, j, ctx); | ||
116 | if (!r) { ret = -1; goto err; } | ||
117 | r = BN_gcd(m, i, j, ctx); | ||
118 | if (!r) { ret = -1; goto err; } | ||
119 | r = BN_div(k, NULL, l, m, ctx); /* remainder is 0 */ | ||
120 | if (!r) { ret = -1; goto err; } | ||
121 | |||
122 | r = BN_mod_mul(i, key->d, key->e, k, ctx); | ||
123 | if (!r) { ret = -1; goto err; } | ||
124 | |||
125 | if (!BN_is_one(i)) | ||
126 | { | ||
127 | ret = 0; | ||
128 | RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_D_E_NOT_CONGRUENT_TO_1); | ||
129 | } | ||
130 | |||
131 | if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL) | ||
132 | { | ||
133 | /* dmp1 = d mod (p-1)? */ | ||
134 | r = BN_sub(i, key->p, BN_value_one()); | ||
135 | if (!r) { ret = -1; goto err; } | ||
136 | |||
137 | r = BN_mod(j, key->d, i, ctx); | ||
138 | if (!r) { ret = -1; goto err; } | ||
139 | |||
140 | if (BN_cmp(j, key->dmp1) != 0) | ||
141 | { | ||
142 | ret = 0; | ||
143 | RSAerr(RSA_F_RSA_CHECK_KEY, | ||
144 | RSA_R_DMP1_NOT_CONGRUENT_TO_D); | ||
145 | } | ||
146 | |||
147 | /* dmq1 = d mod (q-1)? */ | ||
148 | r = BN_sub(i, key->q, BN_value_one()); | ||
149 | if (!r) { ret = -1; goto err; } | ||
150 | |||
151 | r = BN_mod(j, key->d, i, ctx); | ||
152 | if (!r) { ret = -1; goto err; } | ||
153 | |||
154 | if (BN_cmp(j, key->dmq1) != 0) | ||
155 | { | ||
156 | ret = 0; | ||
157 | RSAerr(RSA_F_RSA_CHECK_KEY, | ||
158 | RSA_R_DMQ1_NOT_CONGRUENT_TO_D); | ||
159 | } | ||
160 | |||
161 | /* iqmp = q^-1 mod p? */ | ||
162 | if(!BN_mod_inverse(i, key->q, key->p, ctx)) | ||
163 | { | ||
164 | ret = -1; | ||
165 | goto err; | ||
166 | } | ||
167 | |||
168 | if (BN_cmp(i, key->iqmp) != 0) | ||
169 | { | ||
170 | ret = 0; | ||
171 | RSAerr(RSA_F_RSA_CHECK_KEY, | ||
172 | RSA_R_IQMP_NOT_INVERSE_OF_Q); | ||
173 | } | ||
174 | } | ||
175 | |||
176 | err: | ||
177 | if (i != NULL) BN_free(i); | ||
178 | if (j != NULL) BN_free(j); | ||
179 | if (k != NULL) BN_free(k); | ||
180 | if (l != NULL) BN_free(l); | ||
181 | if (m != NULL) BN_free(m); | ||
182 | if (ctx != NULL) BN_CTX_free(ctx); | ||
183 | return (ret); | ||
184 | } | ||
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c deleted file mode 100644 index cde5ca27d5..0000000000 --- a/src/lib/libcrypto/rsa/rsa_eay.c +++ /dev/null | |||
@@ -1,579 +0,0 @@ | |||
1 | /* crypto/rsa/rsa_eay.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/bn.h> | ||
62 | #include <openssl/rsa.h> | ||
63 | #include <openssl/rand.h> | ||
64 | #include <openssl/engine.h> | ||
65 | |||
66 | #ifndef RSA_NULL | ||
67 | |||
68 | static int RSA_eay_public_encrypt(int flen, unsigned char *from, | ||
69 | unsigned char *to, RSA *rsa,int padding); | ||
70 | static int RSA_eay_private_encrypt(int flen, unsigned char *from, | ||
71 | unsigned char *to, RSA *rsa,int padding); | ||
72 | static int RSA_eay_public_decrypt(int flen, unsigned char *from, | ||
73 | unsigned char *to, RSA *rsa,int padding); | ||
74 | static int RSA_eay_private_decrypt(int flen, unsigned char *from, | ||
75 | unsigned char *to, RSA *rsa,int padding); | ||
76 | static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *i, RSA *rsa); | ||
77 | static int RSA_eay_init(RSA *rsa); | ||
78 | static int RSA_eay_finish(RSA *rsa); | ||
79 | static RSA_METHOD rsa_pkcs1_eay_meth={ | ||
80 | "Eric Young's PKCS#1 RSA", | ||
81 | RSA_eay_public_encrypt, | ||
82 | RSA_eay_public_decrypt, | ||
83 | RSA_eay_private_encrypt, | ||
84 | RSA_eay_private_decrypt, | ||
85 | RSA_eay_mod_exp, | ||
86 | BN_mod_exp_mont, | ||
87 | RSA_eay_init, | ||
88 | RSA_eay_finish, | ||
89 | 0, | ||
90 | NULL, | ||
91 | }; | ||
92 | |||
93 | RSA_METHOD *RSA_PKCS1_SSLeay(void) | ||
94 | { | ||
95 | return(&rsa_pkcs1_eay_meth); | ||
96 | } | ||
97 | |||
98 | static int RSA_eay_public_encrypt(int flen, unsigned char *from, | ||
99 | unsigned char *to, RSA *rsa, int padding) | ||
100 | { | ||
101 | const RSA_METHOD *meth; | ||
102 | BIGNUM f,ret; | ||
103 | int i,j,k,num=0,r= -1; | ||
104 | unsigned char *buf=NULL; | ||
105 | BN_CTX *ctx=NULL; | ||
106 | |||
107 | meth = ENGINE_get_RSA(rsa->engine); | ||
108 | BN_init(&f); | ||
109 | BN_init(&ret); | ||
110 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
111 | num=BN_num_bytes(rsa->n); | ||
112 | if ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL) | ||
113 | { | ||
114 | RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE); | ||
115 | goto err; | ||
116 | } | ||
117 | |||
118 | switch (padding) | ||
119 | { | ||
120 | case RSA_PKCS1_PADDING: | ||
121 | i=RSA_padding_add_PKCS1_type_2(buf,num,from,flen); | ||
122 | break; | ||
123 | #ifndef NO_SHA | ||
124 | case RSA_PKCS1_OAEP_PADDING: | ||
125 | i=RSA_padding_add_PKCS1_OAEP(buf,num,from,flen,NULL,0); | ||
126 | break; | ||
127 | #endif | ||
128 | case RSA_SSLV23_PADDING: | ||
129 | i=RSA_padding_add_SSLv23(buf,num,from,flen); | ||
130 | break; | ||
131 | case RSA_NO_PADDING: | ||
132 | i=RSA_padding_add_none(buf,num,from,flen); | ||
133 | break; | ||
134 | default: | ||
135 | RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE); | ||
136 | goto err; | ||
137 | } | ||
138 | if (i <= 0) goto err; | ||
139 | |||
140 | if (BN_bin2bn(buf,num,&f) == NULL) goto err; | ||
141 | |||
142 | if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC)) | ||
143 | { | ||
144 | BN_MONT_CTX* bn_mont_ctx; | ||
145 | if ((bn_mont_ctx=BN_MONT_CTX_new()) == NULL) | ||
146 | goto err; | ||
147 | if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->n,ctx)) | ||
148 | { | ||
149 | BN_MONT_CTX_free(bn_mont_ctx); | ||
150 | goto err; | ||
151 | } | ||
152 | if (rsa->_method_mod_n == NULL) /* other thread may have finished first */ | ||
153 | { | ||
154 | CRYPTO_w_lock(CRYPTO_LOCK_RSA); | ||
155 | if (rsa->_method_mod_n == NULL) | ||
156 | { | ||
157 | rsa->_method_mod_n = bn_mont_ctx; | ||
158 | bn_mont_ctx = NULL; | ||
159 | } | ||
160 | CRYPTO_w_unlock(CRYPTO_LOCK_RSA); | ||
161 | } | ||
162 | if (bn_mont_ctx) | ||
163 | BN_MONT_CTX_free(bn_mont_ctx); | ||
164 | } | ||
165 | |||
166 | if (!meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx, | ||
167 | rsa->_method_mod_n)) goto err; | ||
168 | |||
169 | /* put in leading 0 bytes if the number is less than the | ||
170 | * length of the modulus */ | ||
171 | j=BN_num_bytes(&ret); | ||
172 | i=BN_bn2bin(&ret,&(to[num-j])); | ||
173 | for (k=0; k<(num-i); k++) | ||
174 | to[k]=0; | ||
175 | |||
176 | r=num; | ||
177 | err: | ||
178 | if (ctx != NULL) BN_CTX_free(ctx); | ||
179 | BN_clear_free(&f); | ||
180 | BN_clear_free(&ret); | ||
181 | if (buf != NULL) | ||
182 | { | ||
183 | memset(buf,0,num); | ||
184 | OPENSSL_free(buf); | ||
185 | } | ||
186 | return(r); | ||
187 | } | ||
188 | |||
189 | static int RSA_eay_private_encrypt(int flen, unsigned char *from, | ||
190 | unsigned char *to, RSA *rsa, int padding) | ||
191 | { | ||
192 | const RSA_METHOD *meth; | ||
193 | BIGNUM f,ret; | ||
194 | int i,j,k,num=0,r= -1; | ||
195 | unsigned char *buf=NULL; | ||
196 | BN_CTX *ctx=NULL; | ||
197 | |||
198 | meth = ENGINE_get_RSA(rsa->engine); | ||
199 | BN_init(&f); | ||
200 | BN_init(&ret); | ||
201 | |||
202 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
203 | num=BN_num_bytes(rsa->n); | ||
204 | if ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL) | ||
205 | { | ||
206 | RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,ERR_R_MALLOC_FAILURE); | ||
207 | goto err; | ||
208 | } | ||
209 | |||
210 | switch (padding) | ||
211 | { | ||
212 | case RSA_PKCS1_PADDING: | ||
213 | i=RSA_padding_add_PKCS1_type_1(buf,num,from,flen); | ||
214 | break; | ||
215 | case RSA_NO_PADDING: | ||
216 | i=RSA_padding_add_none(buf,num,from,flen); | ||
217 | break; | ||
218 | case RSA_SSLV23_PADDING: | ||
219 | default: | ||
220 | RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE); | ||
221 | goto err; | ||
222 | } | ||
223 | if (i <= 0) goto err; | ||
224 | |||
225 | if (BN_bin2bn(buf,num,&f) == NULL) goto err; | ||
226 | |||
227 | if ((rsa->flags & RSA_FLAG_BLINDING) && (rsa->blinding == NULL)) | ||
228 | RSA_blinding_on(rsa,ctx); | ||
229 | if (rsa->flags & RSA_FLAG_BLINDING) | ||
230 | if (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err; | ||
231 | |||
232 | if ( (rsa->flags & RSA_FLAG_EXT_PKEY) || | ||
233 | ((rsa->p != NULL) && | ||
234 | (rsa->q != NULL) && | ||
235 | (rsa->dmp1 != NULL) && | ||
236 | (rsa->dmq1 != NULL) && | ||
237 | (rsa->iqmp != NULL)) ) | ||
238 | { if (!meth->rsa_mod_exp(&ret,&f,rsa)) goto err; } | ||
239 | else | ||
240 | { | ||
241 | if (!meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL)) goto err; | ||
242 | } | ||
243 | |||
244 | if (rsa->flags & RSA_FLAG_BLINDING) | ||
245 | if (!BN_BLINDING_invert(&ret,rsa->blinding,ctx)) goto err; | ||
246 | |||
247 | /* put in leading 0 bytes if the number is less than the | ||
248 | * length of the modulus */ | ||
249 | j=BN_num_bytes(&ret); | ||
250 | i=BN_bn2bin(&ret,&(to[num-j])); | ||
251 | for (k=0; k<(num-i); k++) | ||
252 | to[k]=0; | ||
253 | |||
254 | r=num; | ||
255 | err: | ||
256 | if (ctx != NULL) BN_CTX_free(ctx); | ||
257 | BN_clear_free(&ret); | ||
258 | BN_clear_free(&f); | ||
259 | if (buf != NULL) | ||
260 | { | ||
261 | memset(buf,0,num); | ||
262 | OPENSSL_free(buf); | ||
263 | } | ||
264 | return(r); | ||
265 | } | ||
266 | |||
267 | static int RSA_eay_private_decrypt(int flen, unsigned char *from, | ||
268 | unsigned char *to, RSA *rsa, int padding) | ||
269 | { | ||
270 | const RSA_METHOD *meth; | ||
271 | BIGNUM f,ret; | ||
272 | int j,num=0,r= -1; | ||
273 | unsigned char *p; | ||
274 | unsigned char *buf=NULL; | ||
275 | BN_CTX *ctx=NULL; | ||
276 | |||
277 | meth = ENGINE_get_RSA(rsa->engine); | ||
278 | BN_init(&f); | ||
279 | BN_init(&ret); | ||
280 | ctx=BN_CTX_new(); | ||
281 | if (ctx == NULL) goto err; | ||
282 | |||
283 | num=BN_num_bytes(rsa->n); | ||
284 | |||
285 | if ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL) | ||
286 | { | ||
287 | RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,ERR_R_MALLOC_FAILURE); | ||
288 | goto err; | ||
289 | } | ||
290 | |||
291 | /* This check was for equality but PGP does evil things | ||
292 | * and chops off the top '0' bytes */ | ||
293 | if (flen > num) | ||
294 | { | ||
295 | RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN); | ||
296 | goto err; | ||
297 | } | ||
298 | |||
299 | /* make data into a big number */ | ||
300 | if (BN_bin2bn(from,(int)flen,&f) == NULL) goto err; | ||
301 | |||
302 | if ((rsa->flags & RSA_FLAG_BLINDING) && (rsa->blinding == NULL)) | ||
303 | RSA_blinding_on(rsa,ctx); | ||
304 | if (rsa->flags & RSA_FLAG_BLINDING) | ||
305 | if (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err; | ||
306 | |||
307 | /* do the decrypt */ | ||
308 | if ( (rsa->flags & RSA_FLAG_EXT_PKEY) || | ||
309 | ((rsa->p != NULL) && | ||
310 | (rsa->q != NULL) && | ||
311 | (rsa->dmp1 != NULL) && | ||
312 | (rsa->dmq1 != NULL) && | ||
313 | (rsa->iqmp != NULL)) ) | ||
314 | { if (!meth->rsa_mod_exp(&ret,&f,rsa)) goto err; } | ||
315 | else | ||
316 | { | ||
317 | if (!meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL)) | ||
318 | goto err; | ||
319 | } | ||
320 | |||
321 | if (rsa->flags & RSA_FLAG_BLINDING) | ||
322 | if (!BN_BLINDING_invert(&ret,rsa->blinding,ctx)) goto err; | ||
323 | |||
324 | p=buf; | ||
325 | j=BN_bn2bin(&ret,p); /* j is only used with no-padding mode */ | ||
326 | |||
327 | switch (padding) | ||
328 | { | ||
329 | case RSA_PKCS1_PADDING: | ||
330 | r=RSA_padding_check_PKCS1_type_2(to,num,buf,j,num); | ||
331 | break; | ||
332 | #ifndef NO_SHA | ||
333 | case RSA_PKCS1_OAEP_PADDING: | ||
334 | r=RSA_padding_check_PKCS1_OAEP(to,num,buf,j,num,NULL,0); | ||
335 | break; | ||
336 | #endif | ||
337 | case RSA_SSLV23_PADDING: | ||
338 | r=RSA_padding_check_SSLv23(to,num,buf,j,num); | ||
339 | break; | ||
340 | case RSA_NO_PADDING: | ||
341 | r=RSA_padding_check_none(to,num,buf,j,num); | ||
342 | break; | ||
343 | default: | ||
344 | RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE); | ||
345 | goto err; | ||
346 | } | ||
347 | if (r < 0) | ||
348 | RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_PADDING_CHECK_FAILED); | ||
349 | |||
350 | err: | ||
351 | if (ctx != NULL) BN_CTX_free(ctx); | ||
352 | BN_clear_free(&f); | ||
353 | BN_clear_free(&ret); | ||
354 | if (buf != NULL) | ||
355 | { | ||
356 | memset(buf,0,num); | ||
357 | OPENSSL_free(buf); | ||
358 | } | ||
359 | return(r); | ||
360 | } | ||
361 | |||
362 | static int RSA_eay_public_decrypt(int flen, unsigned char *from, | ||
363 | unsigned char *to, RSA *rsa, int padding) | ||
364 | { | ||
365 | const RSA_METHOD *meth; | ||
366 | BIGNUM f,ret; | ||
367 | int i,num=0,r= -1; | ||
368 | unsigned char *p; | ||
369 | unsigned char *buf=NULL; | ||
370 | BN_CTX *ctx=NULL; | ||
371 | |||
372 | meth = ENGINE_get_RSA(rsa->engine); | ||
373 | BN_init(&f); | ||
374 | BN_init(&ret); | ||
375 | ctx=BN_CTX_new(); | ||
376 | if (ctx == NULL) goto err; | ||
377 | |||
378 | num=BN_num_bytes(rsa->n); | ||
379 | buf=(unsigned char *)OPENSSL_malloc(num); | ||
380 | if (buf == NULL) | ||
381 | { | ||
382 | RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE); | ||
383 | goto err; | ||
384 | } | ||
385 | |||
386 | /* This check was for equality but PGP does evil things | ||
387 | * and chops off the top '0' bytes */ | ||
388 | if (flen > num) | ||
389 | { | ||
390 | RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN); | ||
391 | goto err; | ||
392 | } | ||
393 | |||
394 | if (BN_bin2bn(from,flen,&f) == NULL) goto err; | ||
395 | /* do the decrypt */ | ||
396 | if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC)) | ||
397 | { | ||
398 | BN_MONT_CTX* bn_mont_ctx; | ||
399 | if ((bn_mont_ctx=BN_MONT_CTX_new()) == NULL) | ||
400 | goto err; | ||
401 | if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->n,ctx)) | ||
402 | { | ||
403 | BN_MONT_CTX_free(bn_mont_ctx); | ||
404 | goto err; | ||
405 | } | ||
406 | if (rsa->_method_mod_n == NULL) /* other thread may have finished first */ | ||
407 | { | ||
408 | CRYPTO_w_lock(CRYPTO_LOCK_RSA); | ||
409 | if (rsa->_method_mod_n == NULL) | ||
410 | { | ||
411 | rsa->_method_mod_n = bn_mont_ctx; | ||
412 | bn_mont_ctx = NULL; | ||
413 | } | ||
414 | CRYPTO_w_unlock(CRYPTO_LOCK_RSA); | ||
415 | } | ||
416 | if (bn_mont_ctx) | ||
417 | BN_MONT_CTX_free(bn_mont_ctx); | ||
418 | } | ||
419 | |||
420 | if (!meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx, | ||
421 | rsa->_method_mod_n)) goto err; | ||
422 | |||
423 | p=buf; | ||
424 | i=BN_bn2bin(&ret,p); | ||
425 | |||
426 | switch (padding) | ||
427 | { | ||
428 | case RSA_PKCS1_PADDING: | ||
429 | r=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num); | ||
430 | break; | ||
431 | case RSA_NO_PADDING: | ||
432 | r=RSA_padding_check_none(to,num,buf,i,num); | ||
433 | break; | ||
434 | default: | ||
435 | RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE); | ||
436 | goto err; | ||
437 | } | ||
438 | if (r < 0) | ||
439 | RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED); | ||
440 | |||
441 | err: | ||
442 | if (ctx != NULL) BN_CTX_free(ctx); | ||
443 | BN_clear_free(&f); | ||
444 | BN_clear_free(&ret); | ||
445 | if (buf != NULL) | ||
446 | { | ||
447 | memset(buf,0,num); | ||
448 | OPENSSL_free(buf); | ||
449 | } | ||
450 | return(r); | ||
451 | } | ||
452 | |||
453 | static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa) | ||
454 | { | ||
455 | const RSA_METHOD *meth; | ||
456 | BIGNUM r1,m1,vrfy; | ||
457 | int ret=0; | ||
458 | BN_CTX *ctx; | ||
459 | |||
460 | meth = ENGINE_get_RSA(rsa->engine); | ||
461 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
462 | BN_init(&m1); | ||
463 | BN_init(&r1); | ||
464 | BN_init(&vrfy); | ||
465 | |||
466 | if (rsa->flags & RSA_FLAG_CACHE_PRIVATE) | ||
467 | { | ||
468 | if (rsa->_method_mod_p == NULL) | ||
469 | { | ||
470 | BN_MONT_CTX* bn_mont_ctx; | ||
471 | if ((bn_mont_ctx=BN_MONT_CTX_new()) == NULL) | ||
472 | goto err; | ||
473 | if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->p,ctx)) | ||
474 | { | ||
475 | BN_MONT_CTX_free(bn_mont_ctx); | ||
476 | goto err; | ||
477 | } | ||
478 | if (rsa->_method_mod_p == NULL) /* other thread may have finished first */ | ||
479 | { | ||
480 | CRYPTO_w_lock(CRYPTO_LOCK_RSA); | ||
481 | if (rsa->_method_mod_p == NULL) | ||
482 | { | ||
483 | rsa->_method_mod_p = bn_mont_ctx; | ||
484 | bn_mont_ctx = NULL; | ||
485 | } | ||
486 | CRYPTO_w_unlock(CRYPTO_LOCK_RSA); | ||
487 | } | ||
488 | if (bn_mont_ctx) | ||
489 | BN_MONT_CTX_free(bn_mont_ctx); | ||
490 | } | ||
491 | |||
492 | if (rsa->_method_mod_q == NULL) | ||
493 | { | ||
494 | BN_MONT_CTX* bn_mont_ctx; | ||
495 | if ((bn_mont_ctx=BN_MONT_CTX_new()) == NULL) | ||
496 | goto err; | ||
497 | if (!BN_MONT_CTX_set(bn_mont_ctx,rsa->q,ctx)) | ||
498 | { | ||
499 | BN_MONT_CTX_free(bn_mont_ctx); | ||
500 | goto err; | ||
501 | } | ||
502 | if (rsa->_method_mod_q == NULL) /* other thread may have finished first */ | ||
503 | { | ||
504 | CRYPTO_w_lock(CRYPTO_LOCK_RSA); | ||
505 | if (rsa->_method_mod_q == NULL) | ||
506 | { | ||
507 | rsa->_method_mod_q = bn_mont_ctx; | ||
508 | bn_mont_ctx = NULL; | ||
509 | } | ||
510 | CRYPTO_w_unlock(CRYPTO_LOCK_RSA); | ||
511 | } | ||
512 | if (bn_mont_ctx) | ||
513 | BN_MONT_CTX_free(bn_mont_ctx); | ||
514 | } | ||
515 | } | ||
516 | |||
517 | if (!BN_mod(&r1,I,rsa->q,ctx)) goto err; | ||
518 | if (!meth->bn_mod_exp(&m1,&r1,rsa->dmq1,rsa->q,ctx, | ||
519 | rsa->_method_mod_q)) goto err; | ||
520 | |||
521 | if (!BN_mod(&r1,I,rsa->p,ctx)) goto err; | ||
522 | if (!meth->bn_mod_exp(r0,&r1,rsa->dmp1,rsa->p,ctx, | ||
523 | rsa->_method_mod_p)) goto err; | ||
524 | |||
525 | if (!BN_sub(r0,r0,&m1)) goto err; | ||
526 | /* This will help stop the size of r0 increasing, which does | ||
527 | * affect the multiply if it optimised for a power of 2 size */ | ||
528 | if (r0->neg) | ||
529 | if (!BN_add(r0,r0,rsa->p)) goto err; | ||
530 | |||
531 | if (!BN_mul(&r1,r0,rsa->iqmp,ctx)) goto err; | ||
532 | if (!BN_mod(r0,&r1,rsa->p,ctx)) goto err; | ||
533 | /* If p < q it is occasionally possible for the correction of | ||
534 | * adding 'p' if r0 is negative above to leave the result still | ||
535 | * negative. This can break the private key operations: the following | ||
536 | * second correction should *always* correct this rare occurrence. | ||
537 | * This will *never* happen with OpenSSL generated keys because | ||
538 | * they ensure p > q [steve] | ||
539 | */ | ||
540 | if (r0->neg) | ||
541 | if (!BN_add(r0,r0,rsa->p)) goto err; | ||
542 | if (!BN_mul(&r1,r0,rsa->q,ctx)) goto err; | ||
543 | if (!BN_add(r0,&r1,&m1)) goto err; | ||
544 | |||
545 | if (rsa->e && rsa->n) | ||
546 | { | ||
547 | if (!meth->bn_mod_exp(&vrfy,r0,rsa->e,rsa->n,ctx,NULL)) goto err; | ||
548 | if (BN_cmp(I, &vrfy) != 0) | ||
549 | { | ||
550 | if (!meth->bn_mod_exp(r0,I,rsa->d,rsa->n,ctx,NULL)) goto err; | ||
551 | } | ||
552 | } | ||
553 | ret=1; | ||
554 | err: | ||
555 | BN_clear_free(&m1); | ||
556 | BN_clear_free(&r1); | ||
557 | BN_clear_free(&vrfy); | ||
558 | BN_CTX_free(ctx); | ||
559 | return(ret); | ||
560 | } | ||
561 | |||
562 | static int RSA_eay_init(RSA *rsa) | ||
563 | { | ||
564 | rsa->flags|=RSA_FLAG_CACHE_PUBLIC|RSA_FLAG_CACHE_PRIVATE; | ||
565 | return(1); | ||
566 | } | ||
567 | |||
568 | static int RSA_eay_finish(RSA *rsa) | ||
569 | { | ||
570 | if (rsa->_method_mod_n != NULL) | ||
571 | BN_MONT_CTX_free(rsa->_method_mod_n); | ||
572 | if (rsa->_method_mod_p != NULL) | ||
573 | BN_MONT_CTX_free(rsa->_method_mod_p); | ||
574 | if (rsa->_method_mod_q != NULL) | ||
575 | BN_MONT_CTX_free(rsa->_method_mod_q); | ||
576 | return(1); | ||
577 | } | ||
578 | |||
579 | #endif | ||
diff --git a/src/lib/libcrypto/rsa/rsa_err.c b/src/lib/libcrypto/rsa/rsa_err.c deleted file mode 100644 index 1cde7c0da4..0000000000 --- a/src/lib/libcrypto/rsa/rsa_err.c +++ /dev/null | |||
@@ -1,148 +0,0 @@ | |||
1 | /* crypto/rsa/rsa_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include <openssl/rsa.h> | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef NO_ERR | ||
67 | static ERR_STRING_DATA RSA_str_functs[]= | ||
68 | { | ||
69 | {ERR_PACK(0,RSA_F_MEMORY_LOCK,0), "MEMORY_LOCK"}, | ||
70 | {ERR_PACK(0,RSA_F_RSA_CHECK_KEY,0), "RSA_check_key"}, | ||
71 | {ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_DECRYPT,0), "RSA_EAY_PRIVATE_DECRYPT"}, | ||
72 | {ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_ENCRYPT,0), "RSA_EAY_PRIVATE_ENCRYPT"}, | ||
73 | {ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_DECRYPT,0), "RSA_EAY_PUBLIC_DECRYPT"}, | ||
74 | {ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_ENCRYPT,0), "RSA_EAY_PUBLIC_ENCRYPT"}, | ||
75 | {ERR_PACK(0,RSA_F_RSA_GENERATE_KEY,0), "RSA_generate_key"}, | ||
76 | {ERR_PACK(0,RSA_F_RSA_NEW_METHOD,0), "RSA_new_method"}, | ||
77 | {ERR_PACK(0,RSA_F_RSA_NULL,0), "RSA_NULL"}, | ||
78 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_NONE,0), "RSA_padding_add_none"}, | ||
79 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_OAEP,0), "RSA_padding_add_PKCS1_OAEP"}, | ||
80 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,0), "RSA_padding_add_PKCS1_type_1"}, | ||
81 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,0), "RSA_padding_add_PKCS1_type_2"}, | ||
82 | {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_SSLV23,0), "RSA_padding_add_SSLv23"}, | ||
83 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_NONE,0), "RSA_padding_check_none"}, | ||
84 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP,0), "RSA_padding_check_PKCS1_OAEP"}, | ||
85 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,0), "RSA_padding_check_PKCS1_type_1"}, | ||
86 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,0), "RSA_padding_check_PKCS1_type_2"}, | ||
87 | {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_SSLV23,0), "RSA_padding_check_SSLv23"}, | ||
88 | {ERR_PACK(0,RSA_F_RSA_PRINT,0), "RSA_print"}, | ||
89 | {ERR_PACK(0,RSA_F_RSA_PRINT_FP,0), "RSA_print_fp"}, | ||
90 | {ERR_PACK(0,RSA_F_RSA_SIGN,0), "RSA_sign"}, | ||
91 | {ERR_PACK(0,RSA_F_RSA_SIGN_ASN1_OCTET_STRING,0), "RSA_sign_ASN1_OCTET_STRING"}, | ||
92 | {ERR_PACK(0,RSA_F_RSA_VERIFY,0), "RSA_verify"}, | ||
93 | {ERR_PACK(0,RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,0), "RSA_verify_ASN1_OCTET_STRING"}, | ||
94 | {0,NULL} | ||
95 | }; | ||
96 | |||
97 | static ERR_STRING_DATA RSA_str_reasons[]= | ||
98 | { | ||
99 | {RSA_R_ALGORITHM_MISMATCH ,"algorithm mismatch"}, | ||
100 | {RSA_R_BAD_E_VALUE ,"bad e value"}, | ||
101 | {RSA_R_BAD_FIXED_HEADER_DECRYPT ,"bad fixed header decrypt"}, | ||
102 | {RSA_R_BAD_PAD_BYTE_COUNT ,"bad pad byte count"}, | ||
103 | {RSA_R_BAD_SIGNATURE ,"bad signature"}, | ||
104 | {RSA_R_BLOCK_TYPE_IS_NOT_01 ,"block type is not 01"}, | ||
105 | {RSA_R_BLOCK_TYPE_IS_NOT_02 ,"block type is not 02"}, | ||
106 | {RSA_R_DATA_GREATER_THAN_MOD_LEN ,"data greater than mod len"}, | ||
107 | {RSA_R_DATA_TOO_LARGE ,"data too large"}, | ||
108 | {RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"}, | ||
109 | {RSA_R_DATA_TOO_SMALL ,"data too small"}, | ||
110 | {RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE ,"data too small for key size"}, | ||
111 | {RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY ,"digest too big for rsa key"}, | ||
112 | {RSA_R_DMP1_NOT_CONGRUENT_TO_D ,"dmp1 not congruent to d"}, | ||
113 | {RSA_R_DMQ1_NOT_CONGRUENT_TO_D ,"dmq1 not congruent to d"}, | ||
114 | {RSA_R_D_E_NOT_CONGRUENT_TO_1 ,"d e not congruent to 1"}, | ||
115 | {RSA_R_INVALID_MESSAGE_LENGTH ,"invalid message length"}, | ||
116 | {RSA_R_IQMP_NOT_INVERSE_OF_Q ,"iqmp not inverse of q"}, | ||
117 | {RSA_R_KEY_SIZE_TOO_SMALL ,"key size too small"}, | ||
118 | {RSA_R_NULL_BEFORE_BLOCK_MISSING ,"null before block missing"}, | ||
119 | {RSA_R_N_DOES_NOT_EQUAL_P_Q ,"n does not equal p q"}, | ||
120 | {RSA_R_OAEP_DECODING_ERROR ,"oaep decoding error"}, | ||
121 | {RSA_R_PADDING_CHECK_FAILED ,"padding check failed"}, | ||
122 | {RSA_R_P_NOT_PRIME ,"p not prime"}, | ||
123 | {RSA_R_Q_NOT_PRIME ,"q not prime"}, | ||
124 | {RSA_R_RSA_OPERATIONS_NOT_SUPPORTED ,"rsa operations not supported"}, | ||
125 | {RSA_R_SSLV3_ROLLBACK_ATTACK ,"sslv3 rollback attack"}, | ||
126 | {RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"}, | ||
127 | {RSA_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"}, | ||
128 | {RSA_R_UNKNOWN_PADDING_TYPE ,"unknown padding type"}, | ||
129 | {RSA_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"}, | ||
130 | {0,NULL} | ||
131 | }; | ||
132 | |||
133 | #endif | ||
134 | |||
135 | void ERR_load_RSA_strings(void) | ||
136 | { | ||
137 | static int init=1; | ||
138 | |||
139 | if (init) | ||
140 | { | ||
141 | init=0; | ||
142 | #ifndef NO_ERR | ||
143 | ERR_load_strings(ERR_LIB_RSA,RSA_str_functs); | ||
144 | ERR_load_strings(ERR_LIB_RSA,RSA_str_reasons); | ||
145 | #endif | ||
146 | |||
147 | } | ||
148 | } | ||
diff --git a/src/lib/libcrypto/rsa/rsa_gen.c b/src/lib/libcrypto/rsa/rsa_gen.c deleted file mode 100644 index 00c25adbc5..0000000000 --- a/src/lib/libcrypto/rsa/rsa_gen.c +++ /dev/null | |||
@@ -1,197 +0,0 @@ | |||
1 | /* crypto/rsa/rsa_gen.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <time.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/bn.h> | ||
63 | #include <openssl/rsa.h> | ||
64 | |||
65 | RSA *RSA_generate_key(int bits, unsigned long e_value, | ||
66 | void (*callback)(int,int,void *), void *cb_arg) | ||
67 | { | ||
68 | RSA *rsa=NULL; | ||
69 | BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL,*tmp; | ||
70 | int bitsp,bitsq,ok= -1,n=0,i; | ||
71 | BN_CTX *ctx=NULL,*ctx2=NULL; | ||
72 | |||
73 | ctx=BN_CTX_new(); | ||
74 | if (ctx == NULL) goto err; | ||
75 | ctx2=BN_CTX_new(); | ||
76 | if (ctx2 == NULL) goto err; | ||
77 | BN_CTX_start(ctx); | ||
78 | r0 = BN_CTX_get(ctx); | ||
79 | r1 = BN_CTX_get(ctx); | ||
80 | r2 = BN_CTX_get(ctx); | ||
81 | r3 = BN_CTX_get(ctx); | ||
82 | if (r3 == NULL) goto err; | ||
83 | |||
84 | bitsp=(bits+1)/2; | ||
85 | bitsq=bits-bitsp; | ||
86 | rsa=RSA_new(); | ||
87 | if (rsa == NULL) goto err; | ||
88 | |||
89 | /* set e */ | ||
90 | rsa->e=BN_new(); | ||
91 | if (rsa->e == NULL) goto err; | ||
92 | |||
93 | #if 1 | ||
94 | /* The problem is when building with 8, 16, or 32 BN_ULONG, | ||
95 | * unsigned long can be larger */ | ||
96 | for (i=0; i<sizeof(unsigned long)*8; i++) | ||
97 | { | ||
98 | if (e_value & (1UL<<i)) | ||
99 | BN_set_bit(rsa->e,i); | ||
100 | } | ||
101 | #else | ||
102 | if (!BN_set_word(rsa->e,e_value)) goto err; | ||
103 | #endif | ||
104 | |||
105 | /* generate p and q */ | ||
106 | for (;;) | ||
107 | { | ||
108 | rsa->p=BN_generate_prime(NULL,bitsp,0,NULL,NULL,callback,cb_arg); | ||
109 | if (rsa->p == NULL) goto err; | ||
110 | if (!BN_sub(r2,rsa->p,BN_value_one())) goto err; | ||
111 | if (!BN_gcd(r1,r2,rsa->e,ctx)) goto err; | ||
112 | if (BN_is_one(r1)) break; | ||
113 | if (callback != NULL) callback(2,n++,cb_arg); | ||
114 | BN_free(rsa->p); | ||
115 | } | ||
116 | if (callback != NULL) callback(3,0,cb_arg); | ||
117 | for (;;) | ||
118 | { | ||
119 | rsa->q=BN_generate_prime(NULL,bitsq,0,NULL,NULL,callback,cb_arg); | ||
120 | if (rsa->q == NULL) goto err; | ||
121 | if (!BN_sub(r2,rsa->q,BN_value_one())) goto err; | ||
122 | if (!BN_gcd(r1,r2,rsa->e,ctx)) goto err; | ||
123 | if (BN_is_one(r1) && (BN_cmp(rsa->p,rsa->q) != 0)) | ||
124 | break; | ||
125 | if (callback != NULL) callback(2,n++,cb_arg); | ||
126 | BN_free(rsa->q); | ||
127 | } | ||
128 | if (callback != NULL) callback(3,1,cb_arg); | ||
129 | if (BN_cmp(rsa->p,rsa->q) < 0) | ||
130 | { | ||
131 | tmp=rsa->p; | ||
132 | rsa->p=rsa->q; | ||
133 | rsa->q=tmp; | ||
134 | } | ||
135 | |||
136 | /* calculate n */ | ||
137 | rsa->n=BN_new(); | ||
138 | if (rsa->n == NULL) goto err; | ||
139 | if (!BN_mul(rsa->n,rsa->p,rsa->q,ctx)) goto err; | ||
140 | |||
141 | /* calculate d */ | ||
142 | if (!BN_sub(r1,rsa->p,BN_value_one())) goto err; /* p-1 */ | ||
143 | if (!BN_sub(r2,rsa->q,BN_value_one())) goto err; /* q-1 */ | ||
144 | if (!BN_mul(r0,r1,r2,ctx)) goto err; /* (p-1)(q-1) */ | ||
145 | |||
146 | /* should not be needed, since gcd(p-1,e) == 1 and gcd(q-1,e) == 1 */ | ||
147 | /* for (;;) | ||
148 | { | ||
149 | if (!BN_gcd(r3,r0,rsa->e,ctx)) goto err; | ||
150 | if (BN_is_one(r3)) break; | ||
151 | |||
152 | if (1) | ||
153 | { | ||
154 | if (!BN_add_word(rsa->e,2L)) goto err; | ||
155 | continue; | ||
156 | } | ||
157 | RSAerr(RSA_F_RSA_GENERATE_KEY,RSA_R_BAD_E_VALUE); | ||
158 | goto err; | ||
159 | } | ||
160 | */ | ||
161 | rsa->d=BN_mod_inverse(NULL,rsa->e,r0,ctx2); /* d */ | ||
162 | if (rsa->d == NULL) goto err; | ||
163 | |||
164 | /* calculate d mod (p-1) */ | ||
165 | rsa->dmp1=BN_new(); | ||
166 | if (rsa->dmp1 == NULL) goto err; | ||
167 | if (!BN_mod(rsa->dmp1,rsa->d,r1,ctx)) goto err; | ||
168 | |||
169 | /* calculate d mod (q-1) */ | ||
170 | rsa->dmq1=BN_new(); | ||
171 | if (rsa->dmq1 == NULL) goto err; | ||
172 | if (!BN_mod(rsa->dmq1,rsa->d,r2,ctx)) goto err; | ||
173 | |||
174 | /* calculate inverse of q mod p */ | ||
175 | rsa->iqmp=BN_mod_inverse(NULL,rsa->q,rsa->p,ctx2); | ||
176 | if (rsa->iqmp == NULL) goto err; | ||
177 | |||
178 | ok=1; | ||
179 | err: | ||
180 | if (ok == -1) | ||
181 | { | ||
182 | RSAerr(RSA_F_RSA_GENERATE_KEY,ERR_LIB_BN); | ||
183 | ok=0; | ||
184 | } | ||
185 | BN_CTX_end(ctx); | ||
186 | BN_CTX_free(ctx); | ||
187 | BN_CTX_free(ctx2); | ||
188 | |||
189 | if (!ok) | ||
190 | { | ||
191 | if (rsa != NULL) RSA_free(rsa); | ||
192 | return(NULL); | ||
193 | } | ||
194 | else | ||
195 | return(rsa); | ||
196 | } | ||
197 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c deleted file mode 100644 index 94395cc22c..0000000000 --- a/src/lib/libcrypto/rsa/rsa_lib.c +++ /dev/null | |||
@@ -1,388 +0,0 @@ | |||
1 | /* crypto/rsa/rsa_lib.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <openssl/crypto.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/lhash.h> | ||
63 | #include <openssl/bn.h> | ||
64 | #include <openssl/rsa.h> | ||
65 | #include <openssl/engine.h> | ||
66 | |||
67 | const char *RSA_version="RSA" OPENSSL_VERSION_PTEXT; | ||
68 | |||
69 | static RSA_METHOD *default_RSA_meth=NULL; | ||
70 | static int rsa_meth_num=0; | ||
71 | static STACK_OF(CRYPTO_EX_DATA_FUNCS) *rsa_meth=NULL; | ||
72 | |||
73 | RSA *RSA_new(void) | ||
74 | { | ||
75 | return(RSA_new_method(NULL)); | ||
76 | } | ||
77 | |||
78 | void RSA_set_default_openssl_method(RSA_METHOD *meth) | ||
79 | { | ||
80 | ENGINE *e; | ||
81 | /* We'll need to notify the "openssl" ENGINE of this | ||
82 | * change too. We won't bother locking things down at | ||
83 | * our end as there was never any locking in these | ||
84 | * functions! */ | ||
85 | if(default_RSA_meth != meth) | ||
86 | { | ||
87 | default_RSA_meth = meth; | ||
88 | e = ENGINE_by_id("openssl"); | ||
89 | if(e) | ||
90 | { | ||
91 | ENGINE_set_RSA(e, meth); | ||
92 | ENGINE_free(e); | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | |||
97 | RSA_METHOD *RSA_get_default_openssl_method(void) | ||
98 | { | ||
99 | if (default_RSA_meth == NULL) | ||
100 | { | ||
101 | #ifdef RSA_NULL | ||
102 | default_RSA_meth=RSA_null_method(); | ||
103 | #else | ||
104 | #ifdef RSAref | ||
105 | default_RSA_meth=RSA_PKCS1_RSAref(); | ||
106 | #else | ||
107 | default_RSA_meth=RSA_PKCS1_SSLeay(); | ||
108 | #endif | ||
109 | #endif | ||
110 | } | ||
111 | |||
112 | return default_RSA_meth; | ||
113 | } | ||
114 | |||
115 | RSA_METHOD *RSA_get_method(RSA *rsa) | ||
116 | { | ||
117 | return ENGINE_get_RSA(rsa->engine); | ||
118 | } | ||
119 | |||
120 | #if 0 | ||
121 | RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth) | ||
122 | { | ||
123 | RSA_METHOD *mtmp; | ||
124 | mtmp = rsa->meth; | ||
125 | if (mtmp->finish) mtmp->finish(rsa); | ||
126 | rsa->meth = meth; | ||
127 | if (meth->init) meth->init(rsa); | ||
128 | return mtmp; | ||
129 | } | ||
130 | #else | ||
131 | int RSA_set_method(RSA *rsa, ENGINE *engine) | ||
132 | { | ||
133 | ENGINE *mtmp; | ||
134 | RSA_METHOD *meth; | ||
135 | mtmp = rsa->engine; | ||
136 | meth = ENGINE_get_RSA(mtmp); | ||
137 | if (!ENGINE_init(engine)) | ||
138 | return 0; | ||
139 | if (meth->finish) meth->finish(rsa); | ||
140 | rsa->engine = engine; | ||
141 | meth = ENGINE_get_RSA(engine); | ||
142 | if (meth->init) meth->init(rsa); | ||
143 | /* SHOULD ERROR CHECK THIS!!! */ | ||
144 | ENGINE_finish(mtmp); | ||
145 | return 1; | ||
146 | } | ||
147 | #endif | ||
148 | |||
149 | #if 0 | ||
150 | RSA *RSA_new_method(RSA_METHOD *meth) | ||
151 | #else | ||
152 | RSA *RSA_new_method(ENGINE *engine) | ||
153 | #endif | ||
154 | { | ||
155 | RSA_METHOD *meth; | ||
156 | RSA *ret; | ||
157 | |||
158 | ret=(RSA *)OPENSSL_malloc(sizeof(RSA)); | ||
159 | if (ret == NULL) | ||
160 | { | ||
161 | RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE); | ||
162 | return(NULL); | ||
163 | } | ||
164 | |||
165 | if (engine == NULL) | ||
166 | { | ||
167 | if((ret->engine=ENGINE_get_default_RSA()) == NULL) | ||
168 | { | ||
169 | OPENSSL_free(ret); | ||
170 | return NULL; | ||
171 | } | ||
172 | } | ||
173 | else | ||
174 | ret->engine=engine; | ||
175 | meth = ENGINE_get_RSA(ret->engine); | ||
176 | |||
177 | ret->pad=0; | ||
178 | ret->version=0; | ||
179 | ret->n=NULL; | ||
180 | ret->e=NULL; | ||
181 | ret->d=NULL; | ||
182 | ret->p=NULL; | ||
183 | ret->q=NULL; | ||
184 | ret->dmp1=NULL; | ||
185 | ret->dmq1=NULL; | ||
186 | ret->iqmp=NULL; | ||
187 | ret->references=1; | ||
188 | ret->_method_mod_n=NULL; | ||
189 | ret->_method_mod_p=NULL; | ||
190 | ret->_method_mod_q=NULL; | ||
191 | ret->blinding=NULL; | ||
192 | ret->bignum_data=NULL; | ||
193 | ret->flags=meth->flags; | ||
194 | CRYPTO_new_ex_data(rsa_meth,ret,&ret->ex_data); | ||
195 | if ((meth->init != NULL) && !meth->init(ret)) | ||
196 | { | ||
197 | CRYPTO_free_ex_data(rsa_meth,ret,&ret->ex_data); | ||
198 | OPENSSL_free(ret); | ||
199 | ret=NULL; | ||
200 | } | ||
201 | return(ret); | ||
202 | } | ||
203 | |||
204 | void RSA_free(RSA *r) | ||
205 | { | ||
206 | RSA_METHOD *meth; | ||
207 | int i; | ||
208 | |||
209 | if (r == NULL) return; | ||
210 | |||
211 | i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_RSA); | ||
212 | #ifdef REF_PRINT | ||
213 | REF_PRINT("RSA",r); | ||
214 | #endif | ||
215 | if (i > 0) return; | ||
216 | #ifdef REF_CHECK | ||
217 | if (i < 0) | ||
218 | { | ||
219 | fprintf(stderr,"RSA_free, bad reference count\n"); | ||
220 | abort(); | ||
221 | } | ||
222 | #endif | ||
223 | |||
224 | meth = ENGINE_get_RSA(r->engine); | ||
225 | if (meth->finish != NULL) | ||
226 | meth->finish(r); | ||
227 | ENGINE_finish(r->engine); | ||
228 | |||
229 | CRYPTO_free_ex_data(rsa_meth,r,&r->ex_data); | ||
230 | |||
231 | if (r->n != NULL) BN_clear_free(r->n); | ||
232 | if (r->e != NULL) BN_clear_free(r->e); | ||
233 | if (r->d != NULL) BN_clear_free(r->d); | ||
234 | if (r->p != NULL) BN_clear_free(r->p); | ||
235 | if (r->q != NULL) BN_clear_free(r->q); | ||
236 | if (r->dmp1 != NULL) BN_clear_free(r->dmp1); | ||
237 | if (r->dmq1 != NULL) BN_clear_free(r->dmq1); | ||
238 | if (r->iqmp != NULL) BN_clear_free(r->iqmp); | ||
239 | if (r->blinding != NULL) BN_BLINDING_free(r->blinding); | ||
240 | if (r->bignum_data != NULL) OPENSSL_free_locked(r->bignum_data); | ||
241 | OPENSSL_free(r); | ||
242 | } | ||
243 | |||
244 | int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
245 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
246 | { | ||
247 | rsa_meth_num++; | ||
248 | return(CRYPTO_get_ex_new_index(rsa_meth_num-1, | ||
249 | &rsa_meth,argl,argp,new_func,dup_func,free_func)); | ||
250 | } | ||
251 | |||
252 | int RSA_set_ex_data(RSA *r, int idx, void *arg) | ||
253 | { | ||
254 | return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); | ||
255 | } | ||
256 | |||
257 | void *RSA_get_ex_data(RSA *r, int idx) | ||
258 | { | ||
259 | return(CRYPTO_get_ex_data(&r->ex_data,idx)); | ||
260 | } | ||
261 | |||
262 | int RSA_size(RSA *r) | ||
263 | { | ||
264 | return(BN_num_bytes(r->n)); | ||
265 | } | ||
266 | |||
267 | int RSA_public_encrypt(int flen, unsigned char *from, unsigned char *to, | ||
268 | RSA *rsa, int padding) | ||
269 | { | ||
270 | return(ENGINE_get_RSA(rsa->engine)->rsa_pub_enc(flen, | ||
271 | from, to, rsa, padding)); | ||
272 | } | ||
273 | |||
274 | int RSA_private_encrypt(int flen, unsigned char *from, unsigned char *to, | ||
275 | RSA *rsa, int padding) | ||
276 | { | ||
277 | return(ENGINE_get_RSA(rsa->engine)->rsa_priv_enc(flen, | ||
278 | from, to, rsa, padding)); | ||
279 | } | ||
280 | |||
281 | int RSA_private_decrypt(int flen, unsigned char *from, unsigned char *to, | ||
282 | RSA *rsa, int padding) | ||
283 | { | ||
284 | return(ENGINE_get_RSA(rsa->engine)->rsa_priv_dec(flen, | ||
285 | from, to, rsa, padding)); | ||
286 | } | ||
287 | |||
288 | int RSA_public_decrypt(int flen, unsigned char *from, unsigned char *to, | ||
289 | RSA *rsa, int padding) | ||
290 | { | ||
291 | return(ENGINE_get_RSA(rsa->engine)->rsa_pub_dec(flen, | ||
292 | from, to, rsa, padding)); | ||
293 | } | ||
294 | |||
295 | int RSA_flags(RSA *r) | ||
296 | { | ||
297 | return((r == NULL)?0:ENGINE_get_RSA(r->engine)->flags); | ||
298 | } | ||
299 | |||
300 | void RSA_blinding_off(RSA *rsa) | ||
301 | { | ||
302 | if (rsa->blinding != NULL) | ||
303 | { | ||
304 | BN_BLINDING_free(rsa->blinding); | ||
305 | rsa->blinding=NULL; | ||
306 | } | ||
307 | rsa->flags&= ~RSA_FLAG_BLINDING; | ||
308 | } | ||
309 | |||
310 | int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx) | ||
311 | { | ||
312 | BIGNUM *A,*Ai; | ||
313 | BN_CTX *ctx; | ||
314 | int ret=0; | ||
315 | |||
316 | if (p_ctx == NULL) | ||
317 | { | ||
318 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
319 | } | ||
320 | else | ||
321 | ctx=p_ctx; | ||
322 | |||
323 | if (rsa->blinding != NULL) | ||
324 | BN_BLINDING_free(rsa->blinding); | ||
325 | |||
326 | BN_CTX_start(ctx); | ||
327 | A = BN_CTX_get(ctx); | ||
328 | if (!BN_rand_range(A,rsa->n)) goto err; | ||
329 | if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err; | ||
330 | |||
331 | if (!ENGINE_get_RSA(rsa->engine)->bn_mod_exp(A,A, | ||
332 | rsa->e,rsa->n,ctx,rsa->_method_mod_n)) | ||
333 | goto err; | ||
334 | rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n); | ||
335 | rsa->flags|=RSA_FLAG_BLINDING; | ||
336 | BN_free(Ai); | ||
337 | ret=1; | ||
338 | err: | ||
339 | BN_CTX_end(ctx); | ||
340 | if (ctx != p_ctx) BN_CTX_free(ctx); | ||
341 | return(ret); | ||
342 | } | ||
343 | |||
344 | int RSA_memory_lock(RSA *r) | ||
345 | { | ||
346 | int i,j,k,off; | ||
347 | char *p; | ||
348 | BIGNUM *bn,**t[6],*b; | ||
349 | BN_ULONG *ul; | ||
350 | |||
351 | if (r->d == NULL) return(1); | ||
352 | t[0]= &r->d; | ||
353 | t[1]= &r->p; | ||
354 | t[2]= &r->q; | ||
355 | t[3]= &r->dmp1; | ||
356 | t[4]= &r->dmq1; | ||
357 | t[5]= &r->iqmp; | ||
358 | k=sizeof(BIGNUM)*6; | ||
359 | off=k/sizeof(BN_ULONG)+1; | ||
360 | j=1; | ||
361 | for (i=0; i<6; i++) | ||
362 | j+= (*t[i])->top; | ||
363 | if ((p=OPENSSL_malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL) | ||
364 | { | ||
365 | RSAerr(RSA_F_MEMORY_LOCK,ERR_R_MALLOC_FAILURE); | ||
366 | return(0); | ||
367 | } | ||
368 | bn=(BIGNUM *)p; | ||
369 | ul=(BN_ULONG *)&(p[off]); | ||
370 | for (i=0; i<6; i++) | ||
371 | { | ||
372 | b= *(t[i]); | ||
373 | *(t[i])= &(bn[i]); | ||
374 | memcpy((char *)&(bn[i]),(char *)b,sizeof(BIGNUM)); | ||
375 | bn[i].flags=BN_FLG_STATIC_DATA; | ||
376 | bn[i].d=ul; | ||
377 | memcpy((char *)ul,b->d,sizeof(BN_ULONG)*b->top); | ||
378 | ul+=b->top; | ||
379 | BN_clear_free(b); | ||
380 | } | ||
381 | |||
382 | /* I should fix this so it can still be done */ | ||
383 | r->flags&= ~(RSA_FLAG_CACHE_PRIVATE|RSA_FLAG_CACHE_PUBLIC); | ||
384 | |||
385 | r->bignum_data=p; | ||
386 | return(1); | ||
387 | } | ||
388 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_none.c b/src/lib/libcrypto/rsa/rsa_none.c deleted file mode 100644 index f22fce5016..0000000000 --- a/src/lib/libcrypto/rsa/rsa_none.c +++ /dev/null | |||
@@ -1,98 +0,0 @@ | |||
1 | /* crypto/rsa/rsa_none.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/bn.h> | ||
62 | #include <openssl/rsa.h> | ||
63 | #include <openssl/rand.h> | ||
64 | |||
65 | int RSA_padding_add_none(unsigned char *to, int tlen, unsigned char *from, | ||
66 | int flen) | ||
67 | { | ||
68 | if (flen > tlen) | ||
69 | { | ||
70 | RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
71 | return(0); | ||
72 | } | ||
73 | |||
74 | if (flen < tlen) | ||
75 | { | ||
76 | RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE); | ||
77 | return(0); | ||
78 | } | ||
79 | |||
80 | memcpy(to,from,(unsigned int)flen); | ||
81 | return(1); | ||
82 | } | ||
83 | |||
84 | int RSA_padding_check_none(unsigned char *to, int tlen, unsigned char *from, | ||
85 | int flen, int num) | ||
86 | { | ||
87 | |||
88 | if (flen > tlen) | ||
89 | { | ||
90 | RSAerr(RSA_F_RSA_PADDING_CHECK_NONE,RSA_R_DATA_TOO_LARGE); | ||
91 | return(-1); | ||
92 | } | ||
93 | |||
94 | memset(to,0,tlen-flen); | ||
95 | memcpy(to+tlen-flen,from,flen); | ||
96 | return(tlen); | ||
97 | } | ||
98 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_oaep.c b/src/lib/libcrypto/rsa/rsa_oaep.c deleted file mode 100644 index 1849e55cd5..0000000000 --- a/src/lib/libcrypto/rsa/rsa_oaep.c +++ /dev/null | |||
@@ -1,168 +0,0 @@ | |||
1 | /* crypto/rsa/rsa_oaep.c */ | ||
2 | /* Written by Ulf Moeller. This software is distributed on an "AS IS" | ||
3 | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. */ | ||
4 | |||
5 | /* EME_OAEP as defined in RFC 2437 (PKCS #1 v2.0) */ | ||
6 | |||
7 | #if !defined(NO_SHA) && !defined(NO_SHA1) | ||
8 | #include <stdio.h> | ||
9 | #include "cryptlib.h" | ||
10 | #include <openssl/bn.h> | ||
11 | #include <openssl/rsa.h> | ||
12 | #include <openssl/sha.h> | ||
13 | #include <openssl/rand.h> | ||
14 | |||
15 | int MGF1(unsigned char *mask, long len, unsigned char *seed, long seedlen); | ||
16 | |||
17 | int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, | ||
18 | unsigned char *from, int flen, unsigned char *param, int plen) | ||
19 | { | ||
20 | int i, emlen = tlen - 1; | ||
21 | unsigned char *db, *seed; | ||
22 | unsigned char *dbmask, seedmask[SHA_DIGEST_LENGTH]; | ||
23 | |||
24 | if (flen > emlen - 2 * SHA_DIGEST_LENGTH - 1) | ||
25 | { | ||
26 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, | ||
27 | RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
28 | return (0); | ||
29 | } | ||
30 | |||
31 | if (emlen < 2 * SHA_DIGEST_LENGTH + 1) | ||
32 | { | ||
33 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_KEY_SIZE_TOO_SMALL); | ||
34 | return (0); | ||
35 | } | ||
36 | |||
37 | dbmask = OPENSSL_malloc(emlen - SHA_DIGEST_LENGTH); | ||
38 | if (dbmask == NULL) | ||
39 | { | ||
40 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE); | ||
41 | return (0); | ||
42 | } | ||
43 | |||
44 | to[0] = 0; | ||
45 | seed = to + 1; | ||
46 | db = to + SHA_DIGEST_LENGTH + 1; | ||
47 | |||
48 | SHA1(param, plen, db); | ||
49 | memset(db + SHA_DIGEST_LENGTH, 0, | ||
50 | emlen - flen - 2 * SHA_DIGEST_LENGTH - 1); | ||
51 | db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01; | ||
52 | memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, (unsigned int) flen); | ||
53 | if (RAND_bytes(seed, SHA_DIGEST_LENGTH) <= 0) | ||
54 | return (0); | ||
55 | #ifdef PKCS_TESTVECT | ||
56 | memcpy(seed, | ||
57 | "\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2\xf0\x6c\xb5\x8f", | ||
58 | 20); | ||
59 | #endif | ||
60 | |||
61 | MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH); | ||
62 | for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++) | ||
63 | db[i] ^= dbmask[i]; | ||
64 | |||
65 | MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH); | ||
66 | for (i = 0; i < SHA_DIGEST_LENGTH; i++) | ||
67 | seed[i] ^= seedmask[i]; | ||
68 | |||
69 | OPENSSL_free(dbmask); | ||
70 | return (1); | ||
71 | } | ||
72 | |||
73 | int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen, | ||
74 | unsigned char *from, int flen, int num, unsigned char *param, | ||
75 | int plen) | ||
76 | { | ||
77 | int i, dblen, mlen = -1; | ||
78 | unsigned char *maskeddb; | ||
79 | int lzero; | ||
80 | unsigned char *db = NULL, seed[SHA_DIGEST_LENGTH], phash[SHA_DIGEST_LENGTH]; | ||
81 | |||
82 | if (--num < 2 * SHA_DIGEST_LENGTH + 1) | ||
83 | goto decoding_err; | ||
84 | |||
85 | lzero = num - flen; | ||
86 | if (lzero < 0) | ||
87 | goto decoding_err; | ||
88 | maskeddb = from - lzero + SHA_DIGEST_LENGTH; | ||
89 | |||
90 | dblen = num - SHA_DIGEST_LENGTH; | ||
91 | db = OPENSSL_malloc(dblen); | ||
92 | if (db == NULL) | ||
93 | { | ||
94 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE); | ||
95 | return (-1); | ||
96 | } | ||
97 | |||
98 | MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen); | ||
99 | for (i = lzero; i < SHA_DIGEST_LENGTH; i++) | ||
100 | seed[i] ^= from[i - lzero]; | ||
101 | |||
102 | MGF1(db, dblen, seed, SHA_DIGEST_LENGTH); | ||
103 | for (i = 0; i < dblen; i++) | ||
104 | db[i] ^= maskeddb[i]; | ||
105 | |||
106 | SHA1(param, plen, phash); | ||
107 | |||
108 | if (memcmp(db, phash, SHA_DIGEST_LENGTH) != 0) | ||
109 | goto decoding_err; | ||
110 | else | ||
111 | { | ||
112 | for (i = SHA_DIGEST_LENGTH; i < dblen; i++) | ||
113 | if (db[i] != 0x00) | ||
114 | break; | ||
115 | if (db[i] != 0x01 || i++ >= dblen) | ||
116 | goto decoding_err; | ||
117 | else | ||
118 | { | ||
119 | mlen = dblen - i; | ||
120 | if (tlen < mlen) | ||
121 | { | ||
122 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_DATA_TOO_LARGE); | ||
123 | mlen = -1; | ||
124 | } | ||
125 | else | ||
126 | memcpy(to, db + i, mlen); | ||
127 | } | ||
128 | } | ||
129 | OPENSSL_free(db); | ||
130 | return (mlen); | ||
131 | |||
132 | decoding_err: | ||
133 | /* to avoid chosen ciphertext attacks, the error message should not reveal | ||
134 | * which kind of decoding error happened */ | ||
135 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR); | ||
136 | if (db != NULL) OPENSSL_free(db); | ||
137 | return -1; | ||
138 | } | ||
139 | |||
140 | int MGF1(unsigned char *mask, long len, unsigned char *seed, long seedlen) | ||
141 | { | ||
142 | long i, outlen = 0; | ||
143 | unsigned char cnt[4]; | ||
144 | SHA_CTX c; | ||
145 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
146 | |||
147 | for (i = 0; outlen < len; i++) | ||
148 | { | ||
149 | cnt[0] = (i >> 24) & 255, cnt[1] = (i >> 16) & 255, | ||
150 | cnt[2] = (i >> 8) & 255, cnt[3] = i & 255; | ||
151 | SHA1_Init(&c); | ||
152 | SHA1_Update(&c, seed, seedlen); | ||
153 | SHA1_Update(&c, cnt, 4); | ||
154 | if (outlen + SHA_DIGEST_LENGTH <= len) | ||
155 | { | ||
156 | SHA1_Final(mask + outlen, &c); | ||
157 | outlen += SHA_DIGEST_LENGTH; | ||
158 | } | ||
159 | else | ||
160 | { | ||
161 | SHA1_Final(md, &c); | ||
162 | memcpy(mask + outlen, md, len - outlen); | ||
163 | outlen = len; | ||
164 | } | ||
165 | } | ||
166 | return (0); | ||
167 | } | ||
168 | #endif | ||
diff --git a/src/lib/libcrypto/rsa/rsa_pk1.c b/src/lib/libcrypto/rsa/rsa_pk1.c deleted file mode 100644 index 48a32bc264..0000000000 --- a/src/lib/libcrypto/rsa/rsa_pk1.c +++ /dev/null | |||
@@ -1,224 +0,0 @@ | |||
1 | /* crypto/rsa/rsa_pk1.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/bn.h> | ||
62 | #include <openssl/rsa.h> | ||
63 | #include <openssl/rand.h> | ||
64 | |||
65 | int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, | ||
66 | unsigned char *from, int flen) | ||
67 | { | ||
68 | int j; | ||
69 | unsigned char *p; | ||
70 | |||
71 | if (flen > (tlen-11)) | ||
72 | { | ||
73 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
74 | return(0); | ||
75 | } | ||
76 | |||
77 | p=(unsigned char *)to; | ||
78 | |||
79 | *(p++)=0; | ||
80 | *(p++)=1; /* Private Key BT (Block Type) */ | ||
81 | |||
82 | /* pad out with 0xff data */ | ||
83 | j=tlen-3-flen; | ||
84 | memset(p,0xff,j); | ||
85 | p+=j; | ||
86 | *(p++)='\0'; | ||
87 | memcpy(p,from,(unsigned int)flen); | ||
88 | return(1); | ||
89 | } | ||
90 | |||
91 | int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen, | ||
92 | unsigned char *from, int flen, int num) | ||
93 | { | ||
94 | int i,j; | ||
95 | unsigned char *p; | ||
96 | |||
97 | p=from; | ||
98 | if ((num != (flen+1)) || (*(p++) != 01)) | ||
99 | { | ||
100 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BLOCK_TYPE_IS_NOT_01); | ||
101 | return(-1); | ||
102 | } | ||
103 | |||
104 | /* scan over padding data */ | ||
105 | j=flen-1; /* one for type. */ | ||
106 | for (i=0; i<j; i++) | ||
107 | { | ||
108 | if (*p != 0xff) /* should decrypt to 0xff */ | ||
109 | { | ||
110 | if (*p == 0) | ||
111 | { p++; break; } | ||
112 | else { | ||
113 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BAD_FIXED_HEADER_DECRYPT); | ||
114 | return(-1); | ||
115 | } | ||
116 | } | ||
117 | p++; | ||
118 | } | ||
119 | |||
120 | if (i == j) | ||
121 | { | ||
122 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_NULL_BEFORE_BLOCK_MISSING); | ||
123 | return(-1); | ||
124 | } | ||
125 | |||
126 | if (i < 8) | ||
127 | { | ||
128 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BAD_PAD_BYTE_COUNT); | ||
129 | return(-1); | ||
130 | } | ||
131 | i++; /* Skip over the '\0' */ | ||
132 | j-=i; | ||
133 | if (j > tlen) | ||
134 | { | ||
135 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_DATA_TOO_LARGE); | ||
136 | return(-1); | ||
137 | } | ||
138 | memcpy(to,p,(unsigned int)j); | ||
139 | |||
140 | return(j); | ||
141 | } | ||
142 | |||
143 | int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, | ||
144 | unsigned char *from, int flen) | ||
145 | { | ||
146 | int i,j; | ||
147 | unsigned char *p; | ||
148 | |||
149 | if (flen > (tlen-11)) | ||
150 | { | ||
151 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
152 | return(0); | ||
153 | } | ||
154 | |||
155 | p=(unsigned char *)to; | ||
156 | |||
157 | *(p++)=0; | ||
158 | *(p++)=2; /* Public Key BT (Block Type) */ | ||
159 | |||
160 | /* pad out with non-zero random data */ | ||
161 | j=tlen-3-flen; | ||
162 | |||
163 | if (RAND_bytes(p,j) <= 0) | ||
164 | return(0); | ||
165 | for (i=0; i<j; i++) | ||
166 | { | ||
167 | if (*p == '\0') | ||
168 | do { | ||
169 | if (RAND_bytes(p,1) <= 0) | ||
170 | return(0); | ||
171 | } while (*p == '\0'); | ||
172 | p++; | ||
173 | } | ||
174 | |||
175 | *(p++)='\0'; | ||
176 | |||
177 | memcpy(p,from,(unsigned int)flen); | ||
178 | return(1); | ||
179 | } | ||
180 | |||
181 | int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen, | ||
182 | unsigned char *from, int flen, int num) | ||
183 | { | ||
184 | int i,j; | ||
185 | unsigned char *p; | ||
186 | |||
187 | p=from; | ||
188 | if ((num != (flen+1)) || (*(p++) != 02)) | ||
189 | { | ||
190 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BLOCK_TYPE_IS_NOT_02); | ||
191 | return(-1); | ||
192 | } | ||
193 | #ifdef PKCS1_CHECK | ||
194 | return(num-11); | ||
195 | #endif | ||
196 | |||
197 | /* scan over padding data */ | ||
198 | j=flen-1; /* one for type. */ | ||
199 | for (i=0; i<j; i++) | ||
200 | if (*(p++) == 0) break; | ||
201 | |||
202 | if (i == j) | ||
203 | { | ||
204 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_NULL_BEFORE_BLOCK_MISSING); | ||
205 | return(-1); | ||
206 | } | ||
207 | |||
208 | if (i < 8) | ||
209 | { | ||
210 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BAD_PAD_BYTE_COUNT); | ||
211 | return(-1); | ||
212 | } | ||
213 | i++; /* Skip over the '\0' */ | ||
214 | j-=i; | ||
215 | if (j > tlen) | ||
216 | { | ||
217 | RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_DATA_TOO_LARGE); | ||
218 | return(-1); | ||
219 | } | ||
220 | memcpy(to,p,(unsigned int)j); | ||
221 | |||
222 | return(j); | ||
223 | } | ||
224 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_saos.c b/src/lib/libcrypto/rsa/rsa_saos.c deleted file mode 100644 index c77f4381ff..0000000000 --- a/src/lib/libcrypto/rsa/rsa_saos.c +++ /dev/null | |||
@@ -1,144 +0,0 @@ | |||
1 | /* crypto/rsa/rsa_saos.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/bn.h> | ||
62 | #include <openssl/rsa.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include <openssl/x509.h> | ||
65 | |||
66 | int RSA_sign_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len, | ||
67 | unsigned char *sigret, unsigned int *siglen, RSA *rsa) | ||
68 | { | ||
69 | ASN1_OCTET_STRING sig; | ||
70 | int i,j,ret=1; | ||
71 | unsigned char *p,*s; | ||
72 | |||
73 | sig.type=V_ASN1_OCTET_STRING; | ||
74 | sig.length=m_len; | ||
75 | sig.data=m; | ||
76 | |||
77 | i=i2d_ASN1_OCTET_STRING(&sig,NULL); | ||
78 | j=RSA_size(rsa); | ||
79 | if ((i-RSA_PKCS1_PADDING) > j) | ||
80 | { | ||
81 | RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); | ||
82 | return(0); | ||
83 | } | ||
84 | s=(unsigned char *)OPENSSL_malloc((unsigned int)j+1); | ||
85 | if (s == NULL) | ||
86 | { | ||
87 | RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE); | ||
88 | return(0); | ||
89 | } | ||
90 | p=s; | ||
91 | i2d_ASN1_OCTET_STRING(&sig,&p); | ||
92 | i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING); | ||
93 | if (i <= 0) | ||
94 | ret=0; | ||
95 | else | ||
96 | *siglen=i; | ||
97 | |||
98 | memset(s,0,(unsigned int)j+1); | ||
99 | OPENSSL_free(s); | ||
100 | return(ret); | ||
101 | } | ||
102 | |||
103 | int RSA_verify_ASN1_OCTET_STRING(int dtype, unsigned char *m, | ||
104 | unsigned int m_len, unsigned char *sigbuf, unsigned int siglen, | ||
105 | RSA *rsa) | ||
106 | { | ||
107 | int i,ret=0; | ||
108 | unsigned char *p,*s; | ||
109 | ASN1_OCTET_STRING *sig=NULL; | ||
110 | |||
111 | if (siglen != (unsigned int)RSA_size(rsa)) | ||
112 | { | ||
113 | RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,RSA_R_WRONG_SIGNATURE_LENGTH); | ||
114 | return(0); | ||
115 | } | ||
116 | |||
117 | s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen); | ||
118 | if (s == NULL) | ||
119 | { | ||
120 | RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE); | ||
121 | goto err; | ||
122 | } | ||
123 | i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING); | ||
124 | |||
125 | if (i <= 0) goto err; | ||
126 | |||
127 | p=s; | ||
128 | sig=d2i_ASN1_OCTET_STRING(NULL,&p,(long)i); | ||
129 | if (sig == NULL) goto err; | ||
130 | |||
131 | if ( ((unsigned int)sig->length != m_len) || | ||
132 | (memcmp(m,sig->data,m_len) != 0)) | ||
133 | { | ||
134 | RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,RSA_R_BAD_SIGNATURE); | ||
135 | } | ||
136 | else | ||
137 | ret=1; | ||
138 | err: | ||
139 | if (sig != NULL) M_ASN1_OCTET_STRING_free(sig); | ||
140 | memset(s,0,(unsigned int)siglen); | ||
141 | OPENSSL_free(s); | ||
142 | return(ret); | ||
143 | } | ||
144 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c deleted file mode 100644 index cf00876292..0000000000 --- a/src/lib/libcrypto/rsa/rsa_sign.c +++ /dev/null | |||
@@ -1,224 +0,0 @@ | |||
1 | /* crypto/rsa/rsa_sign.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/bn.h> | ||
62 | #include <openssl/rsa.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include <openssl/x509.h> | ||
65 | #include <openssl/engine.h> | ||
66 | |||
67 | /* Size of an SSL signature: MD5+SHA1 */ | ||
68 | #define SSL_SIG_LENGTH 36 | ||
69 | |||
70 | int RSA_sign(int type, unsigned char *m, unsigned int m_len, | ||
71 | unsigned char *sigret, unsigned int *siglen, RSA *rsa) | ||
72 | { | ||
73 | X509_SIG sig; | ||
74 | ASN1_TYPE parameter; | ||
75 | int i,j,ret=1; | ||
76 | unsigned char *p,*s = NULL; | ||
77 | X509_ALGOR algor; | ||
78 | ASN1_OCTET_STRING digest; | ||
79 | if(rsa->flags & RSA_FLAG_SIGN_VER) | ||
80 | return ENGINE_get_RSA(rsa->engine)->rsa_sign(type, | ||
81 | m, m_len, sigret, siglen, rsa); | ||
82 | /* Special case: SSL signature, just check the length */ | ||
83 | if(type == NID_md5_sha1) { | ||
84 | if(m_len != SSL_SIG_LENGTH) { | ||
85 | RSAerr(RSA_F_RSA_SIGN,RSA_R_INVALID_MESSAGE_LENGTH); | ||
86 | return(0); | ||
87 | } | ||
88 | i = SSL_SIG_LENGTH; | ||
89 | s = m; | ||
90 | } else { | ||
91 | sig.algor= &algor; | ||
92 | sig.algor->algorithm=OBJ_nid2obj(type); | ||
93 | if (sig.algor->algorithm == NULL) | ||
94 | { | ||
95 | RSAerr(RSA_F_RSA_SIGN,RSA_R_UNKNOWN_ALGORITHM_TYPE); | ||
96 | return(0); | ||
97 | } | ||
98 | if (sig.algor->algorithm->length == 0) | ||
99 | { | ||
100 | RSAerr(RSA_F_RSA_SIGN,RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD); | ||
101 | return(0); | ||
102 | } | ||
103 | parameter.type=V_ASN1_NULL; | ||
104 | parameter.value.ptr=NULL; | ||
105 | sig.algor->parameter= ¶meter; | ||
106 | |||
107 | sig.digest= &digest; | ||
108 | sig.digest->data=m; | ||
109 | sig.digest->length=m_len; | ||
110 | |||
111 | i=i2d_X509_SIG(&sig,NULL); | ||
112 | } | ||
113 | j=RSA_size(rsa); | ||
114 | if ((i-RSA_PKCS1_PADDING) > j) | ||
115 | { | ||
116 | RSAerr(RSA_F_RSA_SIGN,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); | ||
117 | return(0); | ||
118 | } | ||
119 | if(type != NID_md5_sha1) { | ||
120 | s=(unsigned char *)OPENSSL_malloc((unsigned int)j+1); | ||
121 | if (s == NULL) | ||
122 | { | ||
123 | RSAerr(RSA_F_RSA_SIGN,ERR_R_MALLOC_FAILURE); | ||
124 | return(0); | ||
125 | } | ||
126 | p=s; | ||
127 | i2d_X509_SIG(&sig,&p); | ||
128 | } | ||
129 | i=RSA_private_encrypt(i,s,sigret,rsa,RSA_PKCS1_PADDING); | ||
130 | if (i <= 0) | ||
131 | ret=0; | ||
132 | else | ||
133 | *siglen=i; | ||
134 | |||
135 | if(type != NID_md5_sha1) { | ||
136 | memset(s,0,(unsigned int)j+1); | ||
137 | OPENSSL_free(s); | ||
138 | } | ||
139 | return(ret); | ||
140 | } | ||
141 | |||
142 | int RSA_verify(int dtype, unsigned char *m, unsigned int m_len, | ||
143 | unsigned char *sigbuf, unsigned int siglen, RSA *rsa) | ||
144 | { | ||
145 | int i,ret=0,sigtype; | ||
146 | unsigned char *p,*s; | ||
147 | X509_SIG *sig=NULL; | ||
148 | |||
149 | if (siglen != (unsigned int)RSA_size(rsa)) | ||
150 | { | ||
151 | RSAerr(RSA_F_RSA_VERIFY,RSA_R_WRONG_SIGNATURE_LENGTH); | ||
152 | return(0); | ||
153 | } | ||
154 | |||
155 | if(rsa->flags & RSA_FLAG_SIGN_VER) | ||
156 | return ENGINE_get_RSA(rsa->engine)->rsa_verify(dtype, | ||
157 | m, m_len, sigbuf, siglen, rsa); | ||
158 | |||
159 | s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen); | ||
160 | if (s == NULL) | ||
161 | { | ||
162 | RSAerr(RSA_F_RSA_VERIFY,ERR_R_MALLOC_FAILURE); | ||
163 | goto err; | ||
164 | } | ||
165 | if((dtype == NID_md5_sha1) && (m_len != SSL_SIG_LENGTH) ) { | ||
166 | RSAerr(RSA_F_RSA_VERIFY,RSA_R_INVALID_MESSAGE_LENGTH); | ||
167 | return(0); | ||
168 | } | ||
169 | i=RSA_public_decrypt((int)siglen,sigbuf,s,rsa,RSA_PKCS1_PADDING); | ||
170 | |||
171 | if (i <= 0) goto err; | ||
172 | |||
173 | /* Special case: SSL signature */ | ||
174 | if(dtype == NID_md5_sha1) { | ||
175 | if((i != SSL_SIG_LENGTH) || memcmp(s, m, SSL_SIG_LENGTH)) | ||
176 | RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE); | ||
177 | else ret = 1; | ||
178 | } else { | ||
179 | p=s; | ||
180 | sig=d2i_X509_SIG(NULL,&p,(long)i); | ||
181 | |||
182 | if (sig == NULL) goto err; | ||
183 | sigtype=OBJ_obj2nid(sig->algor->algorithm); | ||
184 | |||
185 | |||
186 | #ifdef RSA_DEBUG | ||
187 | /* put a backward compatibility flag in EAY */ | ||
188 | fprintf(stderr,"in(%s) expect(%s)\n",OBJ_nid2ln(sigtype), | ||
189 | OBJ_nid2ln(dtype)); | ||
190 | #endif | ||
191 | if (sigtype != dtype) | ||
192 | { | ||
193 | if (((dtype == NID_md5) && | ||
194 | (sigtype == NID_md5WithRSAEncryption)) || | ||
195 | ((dtype == NID_md2) && | ||
196 | (sigtype == NID_md2WithRSAEncryption))) | ||
197 | { | ||
198 | /* ok, we will let it through */ | ||
199 | #if !defined(NO_STDIO) && !defined(WIN16) | ||
200 | fprintf(stderr,"signature has problems, re-make with post SSLeay045\n"); | ||
201 | #endif | ||
202 | } | ||
203 | else | ||
204 | { | ||
205 | RSAerr(RSA_F_RSA_VERIFY, | ||
206 | RSA_R_ALGORITHM_MISMATCH); | ||
207 | goto err; | ||
208 | } | ||
209 | } | ||
210 | if ( ((unsigned int)sig->digest->length != m_len) || | ||
211 | (memcmp(m,sig->digest->data,m_len) != 0)) | ||
212 | { | ||
213 | RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE); | ||
214 | } | ||
215 | else | ||
216 | ret=1; | ||
217 | } | ||
218 | err: | ||
219 | if (sig != NULL) X509_SIG_free(sig); | ||
220 | memset(s,0,(unsigned int)siglen); | ||
221 | OPENSSL_free(s); | ||
222 | return(ret); | ||
223 | } | ||
224 | |||
diff --git a/src/lib/libcrypto/rsa/rsa_ssl.c b/src/lib/libcrypto/rsa/rsa_ssl.c deleted file mode 100644 index 482f4a8273..0000000000 --- a/src/lib/libcrypto/rsa/rsa_ssl.c +++ /dev/null | |||
@@ -1,154 +0,0 @@ | |||
1 | /* crypto/rsa/rsa_ssl.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/bn.h> | ||
62 | #include <openssl/rsa.h> | ||
63 | #include <openssl/rand.h> | ||
64 | |||
65 | int RSA_padding_add_SSLv23(unsigned char *to, int tlen, unsigned char *from, | ||
66 | int flen) | ||
67 | { | ||
68 | int i,j; | ||
69 | unsigned char *p; | ||
70 | |||
71 | if (flen > (tlen-11)) | ||
72 | { | ||
73 | RSAerr(RSA_F_RSA_PADDING_ADD_SSLV23,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | ||
74 | return(0); | ||
75 | } | ||
76 | |||
77 | p=(unsigned char *)to; | ||
78 | |||
79 | *(p++)=0; | ||
80 | *(p++)=2; /* Public Key BT (Block Type) */ | ||
81 | |||
82 | /* pad out with non-zero random data */ | ||
83 | j=tlen-3-8-flen; | ||
84 | |||
85 | if (RAND_bytes(p,j) <= 0) | ||
86 | return(0); | ||
87 | for (i=0; i<j; i++) | ||
88 | { | ||
89 | if (*p == '\0') | ||
90 | do { | ||
91 | if (RAND_bytes(p,1) <= 0) | ||
92 | return(0); | ||
93 | } while (*p == '\0'); | ||
94 | p++; | ||
95 | } | ||
96 | |||
97 | memset(p,3,8); | ||
98 | p+=8; | ||
99 | *(p++)='\0'; | ||
100 | |||
101 | memcpy(p,from,(unsigned int)flen); | ||
102 | return(1); | ||
103 | } | ||
104 | |||
105 | int RSA_padding_check_SSLv23(unsigned char *to, int tlen, unsigned char *from, | ||
106 | int flen, int num) | ||
107 | { | ||
108 | int i,j,k; | ||
109 | unsigned char *p; | ||
110 | |||
111 | p=from; | ||
112 | if (flen < 10) | ||
113 | { | ||
114 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_DATA_TOO_SMALL); | ||
115 | return(-1); | ||
116 | } | ||
117 | if ((num != (flen+1)) || (*(p++) != 02)) | ||
118 | { | ||
119 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_BLOCK_TYPE_IS_NOT_02); | ||
120 | return(-1); | ||
121 | } | ||
122 | |||
123 | /* scan over padding data */ | ||
124 | j=flen-1; /* one for type */ | ||
125 | for (i=0; i<j; i++) | ||
126 | if (*(p++) == 0) break; | ||
127 | |||
128 | if ((i == j) || (i < 8)) | ||
129 | { | ||
130 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_NULL_BEFORE_BLOCK_MISSING); | ||
131 | return(-1); | ||
132 | } | ||
133 | for (k= -8; k<0; k++) | ||
134 | { | ||
135 | if (p[k] != 0x03) break; | ||
136 | } | ||
137 | if (k == -1) | ||
138 | { | ||
139 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_SSLV3_ROLLBACK_ATTACK); | ||
140 | return(-1); | ||
141 | } | ||
142 | |||
143 | i++; /* Skip over the '\0' */ | ||
144 | j-=i; | ||
145 | if (j > tlen) | ||
146 | { | ||
147 | RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_DATA_TOO_LARGE); | ||
148 | return(-1); | ||
149 | } | ||
150 | memcpy(to,p,(unsigned int)j); | ||
151 | |||
152 | return(j); | ||
153 | } | ||
154 | |||