diff options
Diffstat (limited to 'src/lib/libcrypto/bn/bntest.c')
-rw-r--r-- | src/lib/libcrypto/bn/bntest.c | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/src/lib/libcrypto/bn/bntest.c b/src/lib/libcrypto/bn/bntest.c index 0a97af69c5..af0c2629e8 100644 --- a/src/lib/libcrypto/bn/bntest.c +++ b/src/lib/libcrypto/bn/bntest.c | |||
@@ -107,11 +107,9 @@ static const char rnd_seed[] = "string to make the random number generator think | |||
107 | static void message(BIO *out, char *m) | 107 | static void message(BIO *out, char *m) |
108 | { | 108 | { |
109 | fprintf(stderr, "test %s\n", m); | 109 | fprintf(stderr, "test %s\n", m); |
110 | #if defined(linux) || defined(__FreeBSD__) /* can we use GNU bc features? */ | ||
111 | BIO_puts(out, "print \"test "); | 110 | BIO_puts(out, "print \"test "); |
112 | BIO_puts(out, m); | 111 | BIO_puts(out, m); |
113 | BIO_puts(out, "\\n\"\n"); | 112 | BIO_puts(out, "\\n\"\n"); |
114 | #endif | ||
115 | } | 113 | } |
116 | 114 | ||
117 | int main(int argc, char *argv[]) | 115 | int main(int argc, char *argv[]) |
@@ -122,9 +120,7 @@ int main(int argc, char *argv[]) | |||
122 | 120 | ||
123 | results = 0; | 121 | results = 0; |
124 | 122 | ||
125 | RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_rand may fail, and we don't | 123 | RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_generate_prime may fail */ |
126 | * even check its return value | ||
127 | * (which we should) */ | ||
128 | 124 | ||
129 | argc--; | 125 | argc--; |
130 | argv++; | 126 | argv++; |
@@ -253,10 +249,10 @@ int test_add(BIO *bp) | |||
253 | BN_init(&b); | 249 | BN_init(&b); |
254 | BN_init(&c); | 250 | BN_init(&c); |
255 | 251 | ||
256 | BN_rand(&a,512,0,0); | 252 | BN_bntest_rand(&a,512,0,0); |
257 | for (i=0; i<num0; i++) | 253 | for (i=0; i<num0; i++) |
258 | { | 254 | { |
259 | BN_rand(&b,450+i,0,0); | 255 | BN_bntest_rand(&b,450+i,0,0); |
260 | a.neg=rand_neg(); | 256 | a.neg=rand_neg(); |
261 | b.neg=rand_neg(); | 257 | b.neg=rand_neg(); |
262 | if (bp == NULL) | 258 | if (bp == NULL) |
@@ -305,14 +301,14 @@ int test_sub(BIO *bp) | |||
305 | { | 301 | { |
306 | if (i < num1) | 302 | if (i < num1) |
307 | { | 303 | { |
308 | BN_rand(&a,512,0,0); | 304 | BN_bntest_rand(&a,512,0,0); |
309 | BN_copy(&b,&a); | 305 | BN_copy(&b,&a); |
310 | if (BN_set_bit(&a,i)==0) return(0); | 306 | if (BN_set_bit(&a,i)==0) return(0); |
311 | BN_add_word(&b,i); | 307 | BN_add_word(&b,i); |
312 | } | 308 | } |
313 | else | 309 | else |
314 | { | 310 | { |
315 | BN_rand(&b,400+i-num1,0,0); | 311 | BN_bntest_rand(&b,400+i-num1,0,0); |
316 | a.neg=rand_neg(); | 312 | a.neg=rand_neg(); |
317 | b.neg=rand_neg(); | 313 | b.neg=rand_neg(); |
318 | } | 314 | } |
@@ -362,13 +358,13 @@ int test_div(BIO *bp, BN_CTX *ctx) | |||
362 | { | 358 | { |
363 | if (i < num1) | 359 | if (i < num1) |
364 | { | 360 | { |
365 | BN_rand(&a,400,0,0); | 361 | BN_bntest_rand(&a,400,0,0); |
366 | BN_copy(&b,&a); | 362 | BN_copy(&b,&a); |
367 | BN_lshift(&a,&a,i); | 363 | BN_lshift(&a,&a,i); |
368 | BN_add_word(&a,i); | 364 | BN_add_word(&a,i); |
369 | } | 365 | } |
370 | else | 366 | else |
371 | BN_rand(&b,50+3*(i-num1),0,0); | 367 | BN_bntest_rand(&b,50+3*(i-num1),0,0); |
372 | a.neg=rand_neg(); | 368 | a.neg=rand_neg(); |
373 | b.neg=rand_neg(); | 369 | b.neg=rand_neg(); |
374 | if (bp == NULL) | 370 | if (bp == NULL) |
@@ -432,13 +428,13 @@ int test_div_recp(BIO *bp, BN_CTX *ctx) | |||
432 | { | 428 | { |
433 | if (i < num1) | 429 | if (i < num1) |
434 | { | 430 | { |
435 | BN_rand(&a,400,0,0); | 431 | BN_bntest_rand(&a,400,0,0); |
436 | BN_copy(&b,&a); | 432 | BN_copy(&b,&a); |
437 | BN_lshift(&a,&a,i); | 433 | BN_lshift(&a,&a,i); |
438 | BN_add_word(&a,i); | 434 | BN_add_word(&a,i); |
439 | } | 435 | } |
440 | else | 436 | else |
441 | BN_rand(&b,50+3*(i-num1),0,0); | 437 | BN_bntest_rand(&b,50+3*(i-num1),0,0); |
442 | a.neg=rand_neg(); | 438 | a.neg=rand_neg(); |
443 | b.neg=rand_neg(); | 439 | b.neg=rand_neg(); |
444 | BN_RECP_CTX_set(&recp,&b,ctx); | 440 | BN_RECP_CTX_set(&recp,&b,ctx); |
@@ -509,11 +505,11 @@ int test_mul(BIO *bp) | |||
509 | { | 505 | { |
510 | if (i <= num1) | 506 | if (i <= num1) |
511 | { | 507 | { |
512 | BN_rand(&a,100,0,0); | 508 | BN_bntest_rand(&a,100,0,0); |
513 | BN_rand(&b,100,0,0); | 509 | BN_bntest_rand(&b,100,0,0); |
514 | } | 510 | } |
515 | else | 511 | else |
516 | BN_rand(&b,i-num1,0,0); | 512 | BN_bntest_rand(&b,i-num1,0,0); |
517 | a.neg=rand_neg(); | 513 | a.neg=rand_neg(); |
518 | b.neg=rand_neg(); | 514 | b.neg=rand_neg(); |
519 | if (bp == NULL) | 515 | if (bp == NULL) |
@@ -562,7 +558,7 @@ int test_sqr(BIO *bp, BN_CTX *ctx) | |||
562 | 558 | ||
563 | for (i=0; i<num0; i++) | 559 | for (i=0; i<num0; i++) |
564 | { | 560 | { |
565 | BN_rand(&a,40+i*10,0,0); | 561 | BN_bntest_rand(&a,40+i*10,0,0); |
566 | a.neg=rand_neg(); | 562 | a.neg=rand_neg(); |
567 | if (bp == NULL) | 563 | if (bp == NULL) |
568 | for (j=0; j<100; j++) | 564 | for (j=0; j<100; j++) |
@@ -613,15 +609,15 @@ int test_mont(BIO *bp, BN_CTX *ctx) | |||
613 | 609 | ||
614 | mont=BN_MONT_CTX_new(); | 610 | mont=BN_MONT_CTX_new(); |
615 | 611 | ||
616 | BN_rand(&a,100,0,0); /**/ | 612 | BN_bntest_rand(&a,100,0,0); /**/ |
617 | BN_rand(&b,100,0,0); /**/ | 613 | BN_bntest_rand(&b,100,0,0); /**/ |
618 | for (i=0; i<num2; i++) | 614 | for (i=0; i<num2; i++) |
619 | { | 615 | { |
620 | int bits = (200*(i+1))/num2; | 616 | int bits = (200*(i+1))/num2; |
621 | 617 | ||
622 | if (bits == 0) | 618 | if (bits == 0) |
623 | continue; | 619 | continue; |
624 | BN_rand(&n,bits,0,1); | 620 | BN_bntest_rand(&n,bits,0,1); |
625 | BN_MONT_CTX_set(mont,&n,ctx); | 621 | BN_MONT_CTX_set(mont,&n,ctx); |
626 | 622 | ||
627 | BN_to_montgomery(&A,&a,mont,ctx); | 623 | BN_to_montgomery(&A,&a,mont,ctx); |
@@ -683,10 +679,10 @@ int test_mod(BIO *bp, BN_CTX *ctx) | |||
683 | d=BN_new(); | 679 | d=BN_new(); |
684 | e=BN_new(); | 680 | e=BN_new(); |
685 | 681 | ||
686 | BN_rand(a,1024,0,0); /**/ | 682 | BN_bntest_rand(a,1024,0,0); /**/ |
687 | for (i=0; i<num0; i++) | 683 | for (i=0; i<num0; i++) |
688 | { | 684 | { |
689 | BN_rand(b,450+i*10,0,0); /**/ | 685 | BN_bntest_rand(b,450+i*10,0,0); /**/ |
690 | a->neg=rand_neg(); | 686 | a->neg=rand_neg(); |
691 | b->neg=rand_neg(); | 687 | b->neg=rand_neg(); |
692 | if (bp == NULL) | 688 | if (bp == NULL) |
@@ -732,11 +728,11 @@ int test_mod_mul(BIO *bp, BN_CTX *ctx) | |||
732 | d=BN_new(); | 728 | d=BN_new(); |
733 | e=BN_new(); | 729 | e=BN_new(); |
734 | 730 | ||
735 | BN_rand(c,1024,0,0); /**/ | 731 | BN_bntest_rand(c,1024,0,0); /**/ |
736 | for (i=0; i<num0; i++) | 732 | for (i=0; i<num0; i++) |
737 | { | 733 | { |
738 | BN_rand(a,475+i*10,0,0); /**/ | 734 | BN_bntest_rand(a,475+i*10,0,0); /**/ |
739 | BN_rand(b,425+i*11,0,0); /**/ | 735 | BN_bntest_rand(b,425+i*11,0,0); /**/ |
740 | a->neg=rand_neg(); | 736 | a->neg=rand_neg(); |
741 | b->neg=rand_neg(); | 737 | b->neg=rand_neg(); |
742 | /* if (bp == NULL) | 738 | /* if (bp == NULL) |
@@ -794,11 +790,11 @@ int test_mod_exp(BIO *bp, BN_CTX *ctx) | |||
794 | d=BN_new(); | 790 | d=BN_new(); |
795 | e=BN_new(); | 791 | e=BN_new(); |
796 | 792 | ||
797 | BN_rand(c,30,0,1); /* must be odd for montgomery */ | 793 | BN_bntest_rand(c,30,0,1); /* must be odd for montgomery */ |
798 | for (i=0; i<num2; i++) | 794 | for (i=0; i<num2; i++) |
799 | { | 795 | { |
800 | BN_rand(a,20+i*5,0,0); /**/ | 796 | BN_bntest_rand(a,20+i*5,0,0); /**/ |
801 | BN_rand(b,2+i,0,0); /**/ | 797 | BN_bntest_rand(b,2+i,0,0); /**/ |
802 | 798 | ||
803 | if (!BN_mod_exp(d,a,b,c,ctx)) | 799 | if (!BN_mod_exp(d,a,b,c,ctx)) |
804 | return(00); | 800 | return(00); |
@@ -848,8 +844,8 @@ int test_exp(BIO *bp, BN_CTX *ctx) | |||
848 | 844 | ||
849 | for (i=0; i<num2; i++) | 845 | for (i=0; i<num2; i++) |
850 | { | 846 | { |
851 | BN_rand(a,20+i*5,0,0); /**/ | 847 | BN_bntest_rand(a,20+i*5,0,0); /**/ |
852 | BN_rand(b,2+i,0,0); /**/ | 848 | BN_bntest_rand(b,2+i,0,0); /**/ |
853 | 849 | ||
854 | if (!BN_exp(d,a,b,ctx)) | 850 | if (!BN_exp(d,a,b,ctx)) |
855 | return(00); | 851 | return(00); |
@@ -899,7 +895,7 @@ int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_) | |||
899 | else | 895 | else |
900 | { | 896 | { |
901 | a=BN_new(); | 897 | a=BN_new(); |
902 | BN_rand(a,200,0,0); /**/ | 898 | BN_bntest_rand(a,200,0,0); /**/ |
903 | a->neg=rand_neg(); | 899 | a->neg=rand_neg(); |
904 | } | 900 | } |
905 | for (i=0; i<num0; i++) | 901 | for (i=0; i<num0; i++) |
@@ -951,7 +947,7 @@ int test_lshift1(BIO *bp) | |||
951 | b=BN_new(); | 947 | b=BN_new(); |
952 | c=BN_new(); | 948 | c=BN_new(); |
953 | 949 | ||
954 | BN_rand(a,200,0,0); /**/ | 950 | BN_bntest_rand(a,200,0,0); /**/ |
955 | a->neg=rand_neg(); | 951 | a->neg=rand_neg(); |
956 | for (i=0; i<num0; i++) | 952 | for (i=0; i<num0; i++) |
957 | { | 953 | { |
@@ -995,7 +991,7 @@ int test_rshift(BIO *bp,BN_CTX *ctx) | |||
995 | e=BN_new(); | 991 | e=BN_new(); |
996 | BN_one(c); | 992 | BN_one(c); |
997 | 993 | ||
998 | BN_rand(a,200,0,0); /**/ | 994 | BN_bntest_rand(a,200,0,0); /**/ |
999 | a->neg=rand_neg(); | 995 | a->neg=rand_neg(); |
1000 | for (i=0; i<num0; i++) | 996 | for (i=0; i<num0; i++) |
1001 | { | 997 | { |
@@ -1038,7 +1034,7 @@ int test_rshift1(BIO *bp) | |||
1038 | b=BN_new(); | 1034 | b=BN_new(); |
1039 | c=BN_new(); | 1035 | c=BN_new(); |
1040 | 1036 | ||
1041 | BN_rand(a,200,0,0); /**/ | 1037 | BN_bntest_rand(a,200,0,0); /**/ |
1042 | a->neg=rand_neg(); | 1038 | a->neg=rand_neg(); |
1043 | for (i=0; i<num0; i++) | 1039 | for (i=0; i<num0; i++) |
1044 | { | 1040 | { |