diff options
Diffstat (limited to 'src/lib/libcrypto/rsa/rsa_test.c')
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_test.c | 32 |
1 files changed, 5 insertions, 27 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_test.c b/src/lib/libcrypto/rsa/rsa_test.c index 4080de8bcf..218bb2a39b 100644 --- a/src/lib/libcrypto/rsa/rsa_test.c +++ b/src/lib/libcrypto/rsa/rsa_test.c | |||
@@ -8,7 +8,6 @@ | |||
8 | #include <openssl/crypto.h> | 8 | #include <openssl/crypto.h> |
9 | #include <openssl/err.h> | 9 | #include <openssl/err.h> |
10 | #include <openssl/rand.h> | 10 | #include <openssl/rand.h> |
11 | #include <openssl/bn.h> | ||
12 | #ifdef OPENSSL_NO_RSA | 11 | #ifdef OPENSSL_NO_RSA |
13 | int main(int argc, char *argv[]) | 12 | int main(int argc, char *argv[]) |
14 | { | 13 | { |
@@ -219,7 +218,6 @@ int main(int argc, char *argv[]) | |||
219 | int plen; | 218 | int plen; |
220 | int clen = 0; | 219 | int clen = 0; |
221 | int num; | 220 | int num; |
222 | int n; | ||
223 | 221 | ||
224 | CRYPTO_malloc_debug_init(); | 222 | CRYPTO_malloc_debug_init(); |
225 | CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); | 223 | CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); |
@@ -243,7 +241,7 @@ int main(int argc, char *argv[]) | |||
243 | clen = key3(key, ctext_ex); | 241 | clen = key3(key, ctext_ex); |
244 | break; | 242 | break; |
245 | } | 243 | } |
246 | if (v/3 >= 1) key->flags |= RSA_FLAG_NO_CONSTTIME; | 244 | if (v/3 > 1) key->flags |= RSA_FLAG_NO_EXP_CONSTTIME; |
247 | 245 | ||
248 | num = RSA_public_encrypt(plen, ptext_ex, ctext, key, | 246 | num = RSA_public_encrypt(plen, ptext_ex, ctext, key, |
249 | RSA_PKCS1_PADDING); | 247 | RSA_PKCS1_PADDING); |
@@ -279,7 +277,7 @@ int main(int argc, char *argv[]) | |||
279 | err=1; | 277 | err=1; |
280 | goto next; | 278 | goto next; |
281 | } | 279 | } |
282 | 280 | ||
283 | num = RSA_private_decrypt(num, ctext, ptext, key, | 281 | num = RSA_private_decrypt(num, ctext, ptext, key, |
284 | RSA_PKCS1_OAEP_PADDING); | 282 | RSA_PKCS1_OAEP_PADDING); |
285 | if (num != plen || memcmp(ptext, ptext_ex, num) != 0) | 283 | if (num != plen || memcmp(ptext, ptext_ex, num) != 0) |
@@ -288,7 +286,10 @@ int main(int argc, char *argv[]) | |||
288 | err=1; | 286 | err=1; |
289 | } | 287 | } |
290 | else if (memcmp(ctext, ctext_ex, num) == 0) | 288 | else if (memcmp(ctext, ctext_ex, num) == 0) |
289 | { | ||
291 | printf("OAEP test vector %d passed!\n", v); | 290 | printf("OAEP test vector %d passed!\n", v); |
291 | goto next; | ||
292 | } | ||
292 | 293 | ||
293 | /* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT). | 294 | /* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT). |
294 | Try decrypting ctext_ex */ | 295 | Try decrypting ctext_ex */ |
@@ -303,26 +304,6 @@ int main(int argc, char *argv[]) | |||
303 | } | 304 | } |
304 | else | 305 | else |
305 | printf("OAEP encryption/decryption ok\n"); | 306 | printf("OAEP encryption/decryption ok\n"); |
306 | |||
307 | /* Try decrypting corrupted ciphertexts */ | ||
308 | for(n = 0 ; n < clen ; ++n) | ||
309 | { | ||
310 | int b; | ||
311 | unsigned char saved = ctext[n]; | ||
312 | for(b = 0 ; b < 256 ; ++b) | ||
313 | { | ||
314 | if(b == saved) | ||
315 | continue; | ||
316 | ctext[n] = b; | ||
317 | num = RSA_private_decrypt(num, ctext, ptext, key, | ||
318 | RSA_PKCS1_OAEP_PADDING); | ||
319 | if(num > 0) | ||
320 | { | ||
321 | printf("Corrupt data decrypted!\n"); | ||
322 | err = 1; | ||
323 | } | ||
324 | } | ||
325 | } | ||
326 | next: | 307 | next: |
327 | RSA_free(key); | 308 | RSA_free(key); |
328 | } | 309 | } |
@@ -332,9 +313,6 @@ int main(int argc, char *argv[]) | |||
332 | 313 | ||
333 | CRYPTO_mem_leaks_fp(stderr); | 314 | CRYPTO_mem_leaks_fp(stderr); |
334 | 315 | ||
335 | #ifdef OPENSSL_SYS_NETWARE | ||
336 | if (err) printf("ERROR: %d\n", err); | ||
337 | #endif | ||
338 | return err; | 316 | return err; |
339 | } | 317 | } |
340 | #endif | 318 | #endif |