diff options
author | djm <> | 2008-09-06 12:17:54 +0000 |
---|---|---|
committer | djm <> | 2008-09-06 12:17:54 +0000 |
commit | 38ce604e3cc97706b876b0525ddff0121115456d (patch) | |
tree | 7ccc28afe1789ea3dbedf72365f955d5b8e105b5 /src/lib/libcrypto/rsa/rsa_test.c | |
parent | 12867252827c8efaa8ddd1fa3b3d6e321e2bcdef (diff) | |
download | openbsd-38ce604e3cc97706b876b0525ddff0121115456d.tar.gz openbsd-38ce604e3cc97706b876b0525ddff0121115456d.tar.bz2 openbsd-38ce604e3cc97706b876b0525ddff0121115456d.zip |
resolve conflicts
Diffstat (limited to 'src/lib/libcrypto/rsa/rsa_test.c')
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_test.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_test.c b/src/lib/libcrypto/rsa/rsa_test.c index 218bb2a39b..4080de8bcf 100644 --- a/src/lib/libcrypto/rsa/rsa_test.c +++ b/src/lib/libcrypto/rsa/rsa_test.c | |||
@@ -8,6 +8,7 @@ | |||
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> | ||
11 | #ifdef OPENSSL_NO_RSA | 12 | #ifdef OPENSSL_NO_RSA |
12 | int main(int argc, char *argv[]) | 13 | int main(int argc, char *argv[]) |
13 | { | 14 | { |
@@ -218,6 +219,7 @@ int main(int argc, char *argv[]) | |||
218 | int plen; | 219 | int plen; |
219 | int clen = 0; | 220 | int clen = 0; |
220 | int num; | 221 | int num; |
222 | int n; | ||
221 | 223 | ||
222 | CRYPTO_malloc_debug_init(); | 224 | CRYPTO_malloc_debug_init(); |
223 | CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); | 225 | CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); |
@@ -241,7 +243,7 @@ int main(int argc, char *argv[]) | |||
241 | clen = key3(key, ctext_ex); | 243 | clen = key3(key, ctext_ex); |
242 | break; | 244 | break; |
243 | } | 245 | } |
244 | if (v/3 > 1) key->flags |= RSA_FLAG_NO_EXP_CONSTTIME; | 246 | if (v/3 >= 1) key->flags |= RSA_FLAG_NO_CONSTTIME; |
245 | 247 | ||
246 | num = RSA_public_encrypt(plen, ptext_ex, ctext, key, | 248 | num = RSA_public_encrypt(plen, ptext_ex, ctext, key, |
247 | RSA_PKCS1_PADDING); | 249 | RSA_PKCS1_PADDING); |
@@ -277,7 +279,7 @@ int main(int argc, char *argv[]) | |||
277 | err=1; | 279 | err=1; |
278 | goto next; | 280 | goto next; |
279 | } | 281 | } |
280 | 282 | ||
281 | num = RSA_private_decrypt(num, ctext, ptext, key, | 283 | num = RSA_private_decrypt(num, ctext, ptext, key, |
282 | RSA_PKCS1_OAEP_PADDING); | 284 | RSA_PKCS1_OAEP_PADDING); |
283 | if (num != plen || memcmp(ptext, ptext_ex, num) != 0) | 285 | if (num != plen || memcmp(ptext, ptext_ex, num) != 0) |
@@ -286,10 +288,7 @@ int main(int argc, char *argv[]) | |||
286 | err=1; | 288 | err=1; |
287 | } | 289 | } |
288 | else if (memcmp(ctext, ctext_ex, num) == 0) | 290 | else if (memcmp(ctext, ctext_ex, num) == 0) |
289 | { | ||
290 | printf("OAEP test vector %d passed!\n", v); | 291 | printf("OAEP test vector %d passed!\n", v); |
291 | goto next; | ||
292 | } | ||
293 | 292 | ||
294 | /* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT). | 293 | /* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT). |
295 | Try decrypting ctext_ex */ | 294 | Try decrypting ctext_ex */ |
@@ -304,6 +303,26 @@ int main(int argc, char *argv[]) | |||
304 | } | 303 | } |
305 | else | 304 | else |
306 | printf("OAEP encryption/decryption ok\n"); | 305 | 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 | } | ||
307 | next: | 326 | next: |
308 | RSA_free(key); | 327 | RSA_free(key); |
309 | } | 328 | } |
@@ -313,6 +332,9 @@ int main(int argc, char *argv[]) | |||
313 | 332 | ||
314 | CRYPTO_mem_leaks_fp(stderr); | 333 | CRYPTO_mem_leaks_fp(stderr); |
315 | 334 | ||
335 | #ifdef OPENSSL_SYS_NETWARE | ||
336 | if (err) printf("ERROR: %d\n", err); | ||
337 | #endif | ||
316 | return err; | 338 | return err; |
317 | } | 339 | } |
318 | #endif | 340 | #endif |