summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bntest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/bntest.c')
-rw-r--r--src/lib/libcrypto/bn/bntest.c239
1 files changed, 150 insertions, 89 deletions
diff --git a/src/lib/libcrypto/bn/bntest.c b/src/lib/libcrypto/bn/bntest.c
index df4b81f5b2..41c22f5954 100644
--- a/src/lib/libcrypto/bn/bntest.c
+++ b/src/lib/libcrypto/bn/bntest.c
@@ -72,6 +72,10 @@
72#include "../bio/bss_file.c" 72#include "../bio/bss_file.c"
73#endif 73#endif
74 74
75const int num0 = 100; /* number of tests */
76const int num1 = 50; /* additional tests for some functions */
77const int num2 = 5; /* number of tests for slow functions */
78
75int test_add(BIO *bp); 79int test_add(BIO *bp);
76int test_sub(BIO *bp); 80int test_sub(BIO *bp);
77int test_lshift1(BIO *bp); 81int test_lshift1(BIO *bp);
@@ -95,15 +99,33 @@ static int results=0;
95#include "bss_file.c" 99#include "bss_file.c"
96#endif 100#endif
97 101
98static unsigned char lst1[]="\xC6\x4F\x43\x04\x2A\xEA\xCA\x6E\x58\x36\x80\x5B\xE8\xC9" 102static unsigned char lst[]="\xC6\x4F\x43\x04\x2A\xEA\xCA\x6E\x58\x36\x80\x5B\xE8\xC9"
99"\x9B\x04\x5D\x48\x36\xC2\xFD\x16\xC9\x64\xF0"; 103"\x9B\x04\x5D\x48\x36\xC2\xFD\x16\xC9\x64\xF0";
100 104
105static const char rnd_seed[] = "string to make the random number generator think it has entropy";
106
107static void message(BIO *out, char *m)
108 {
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 ");
112 BIO_puts(out, m);
113 BIO_puts(out, "\\n\"\n");
114#endif
115 }
116
101int main(int argc, char *argv[]) 117int main(int argc, char *argv[])
102 { 118 {
103 BN_CTX *ctx; 119 BN_CTX *ctx;
104 BIO *out; 120 BIO *out;
105 char *outfile=NULL; 121 char *outfile=NULL;
106 122
123 results = 0;
124
125 RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_rand may fail, and we don't
126 * even check its return value
127 * (which we should) */
128
107 argc--; 129 argc--;
108 argv++; 130 argv++;
109 while (argc >= 1) 131 while (argc >= 1)
@@ -141,78 +163,81 @@ int main(int argc, char *argv[])
141 if (!results) 163 if (!results)
142 BIO_puts(out,"obase=16\nibase=16\n"); 164 BIO_puts(out,"obase=16\nibase=16\n");
143 165
144 fprintf(stderr,"test BN_add\n"); 166 message(out,"BN_add");
145 if (!test_add(out)) goto err; 167 if (!test_add(out)) goto err;
146 fflush(stdout); 168 BIO_flush(out);
147 169
148 fprintf(stderr,"test BN_sub\n"); 170 message(out,"BN_sub");
149 if (!test_sub(out)) goto err; 171 if (!test_sub(out)) goto err;
150 fflush(stdout); 172 BIO_flush(out);
151 173
152 fprintf(stderr,"test BN_lshift1\n"); 174 message(out,"BN_lshift1");
153 if (!test_lshift1(out)) goto err; 175 if (!test_lshift1(out)) goto err;
154 fflush(stdout); 176 BIO_flush(out);
155 177
156 fprintf(stderr,"test BN_lshift (fixed)\n"); 178 message(out,"BN_lshift (fixed)");
157 if (!test_lshift(out,ctx,BN_bin2bn(lst1,sizeof(lst1)-1,NULL))) 179 if (!test_lshift(out,ctx,BN_bin2bn(lst,sizeof(lst)-1,NULL)))
158 goto err; 180 goto err;
159 fflush(stdout); 181 BIO_flush(out);
160 182
161 fprintf(stderr,"test BN_lshift\n"); 183 message(out,"BN_lshift");
162 if (!test_lshift(out,ctx,NULL)) goto err; 184 if (!test_lshift(out,ctx,NULL)) goto err;
163 fflush(stdout); 185 BIO_flush(out);
164 186
165 fprintf(stderr,"test BN_rshift1\n"); 187 message(out,"BN_rshift1");
166 if (!test_rshift1(out)) goto err; 188 if (!test_rshift1(out)) goto err;
167 fflush(stdout); 189 BIO_flush(out);
168 190
169 fprintf(stderr,"test BN_rshift\n"); 191 message(out,"BN_rshift");
170 if (!test_rshift(out,ctx)) goto err; 192 if (!test_rshift(out,ctx)) goto err;
171 fflush(stdout); 193 BIO_flush(out);
172 194
173 fprintf(stderr,"test BN_sqr\n"); 195 message(out,"BN_sqr");
174 if (!test_sqr(out,ctx)) goto err; 196 if (!test_sqr(out,ctx)) goto err;
175 fflush(stdout); 197 BIO_flush(out);
176 198
177 fprintf(stderr,"test BN_mul\n"); 199 message(out,"BN_mul");
178 if (!test_mul(out)) goto err; 200 if (!test_mul(out)) goto err;
179 fflush(stdout); 201 BIO_flush(out);
180 202
181 fprintf(stderr,"test BN_div\n"); 203 message(out,"BN_div");
182 if (!test_div(out,ctx)) goto err; 204 if (!test_div(out,ctx)) goto err;
183 fflush(stdout); 205 BIO_flush(out);
184 206
185 fprintf(stderr,"test BN_div_recp\n"); 207 message(out,"BN_div_recp");
186 if (!test_div_recp(out,ctx)) goto err; 208 if (!test_div_recp(out,ctx)) goto err;
187 fflush(stdout); 209 BIO_flush(out);
188 210
189 fprintf(stderr,"test BN_mod\n"); 211 message(out,"BN_mod");
190 if (!test_mod(out,ctx)) goto err; 212 if (!test_mod(out,ctx)) goto err;
191 fflush(stdout); 213 BIO_flush(out);
192 214
193 fprintf(stderr,"test BN_mod_mul\n"); 215 message(out,"BN_mod_mul");
194 if (!test_mod_mul(out,ctx)) goto err; 216 if (!test_mod_mul(out,ctx)) goto err;
195 fflush(stdout); 217 BIO_flush(out);
196 218
197/* 219 message(out,"BN_mont");
198 fprintf(stderr,"test BN_mont\n");
199 if (!test_mont(out,ctx)) goto err; 220 if (!test_mont(out,ctx)) goto err;
200 fflush(stdout); 221 BIO_flush(out);
201*/ 222
202 fprintf(stderr,"test BN_mod_exp\n"); 223 message(out,"BN_mod_exp");
203 if (!test_mod_exp(out,ctx)) goto err; 224 if (!test_mod_exp(out,ctx)) goto err;
204 fflush(stdout); 225 BIO_flush(out);
205 226
206 fprintf(stderr,"test BN_exp\n"); 227 message(out,"BN_exp");
207 if (!test_exp(out,ctx)) goto err; 228 if (!test_exp(out,ctx)) goto err;
208 fflush(stdout); 229 BIO_flush(out);
230
231 BN_CTX_free(ctx);
232 BIO_free(out);
209 233
210/**/ 234/**/
211 exit(0); 235 exit(0);
212err: 236err:
213 BIO_puts(out,"1\n"); /* make sure bc fails if we are piping to it */ 237 BIO_puts(out,"1\n"); /* make sure bc fails if we are piping to it */
238 BIO_flush(out);
214 ERR_load_crypto_strings(); 239 ERR_load_crypto_strings();
215 ERR_print_errors(out); 240 ERR_print_errors_fp(stderr);
216 exit(1); 241 exit(1);
217 return(1); 242 return(1);
218 } 243 }
@@ -228,7 +253,7 @@ int test_add(BIO *bp)
228 BN_init(&c); 253 BN_init(&c);
229 254
230 BN_rand(&a,512,0,0); 255 BN_rand(&a,512,0,0);
231 for (i=0; i<100; i++) 256 for (i=0; i<num0; i++)
232 { 257 {
233 BN_rand(&b,450+i,0,0); 258 BN_rand(&b,450+i,0,0);
234 a.neg=rand_neg(); 259 a.neg=rand_neg();
@@ -255,7 +280,7 @@ int test_add(BIO *bp)
255 BN_add(&c,&c,&a); 280 BN_add(&c,&c,&a);
256 if(!BN_is_zero(&c)) 281 if(!BN_is_zero(&c))
257 { 282 {
258 BIO_puts(bp,"Add test failed!\n"); 283 fprintf(stderr,"Add test failed!\n");
259 return 0; 284 return 0;
260 } 285 }
261 } 286 }
@@ -275,12 +300,21 @@ int test_sub(BIO *bp)
275 BN_init(&b); 300 BN_init(&b);
276 BN_init(&c); 301 BN_init(&c);
277 302
278 BN_rand(&a,512,0,0); 303 for (i=0; i<num0+num1; i++)
279 for (i=0; i<100; i++)
280 { 304 {
281 BN_rand(&b,400+i,0,0); 305 if (i < num1)
282 a.neg=rand_neg(); 306 {
283 b.neg=rand_neg(); 307 BN_rand(&a,512,0,0);
308 BN_copy(&b,&a);
309 if (BN_set_bit(&a,i)==0) return(0);
310 BN_add_word(&b,i);
311 }
312 else
313 {
314 BN_rand(&b,400+i-num1,0,0);
315 a.neg=rand_neg();
316 b.neg=rand_neg();
317 }
284 if (bp == NULL) 318 if (bp == NULL)
285 for (j=0; j<10000; j++) 319 for (j=0; j<10000; j++)
286 BN_sub(&c,&a,&b); 320 BN_sub(&c,&a,&b);
@@ -301,7 +335,7 @@ int test_sub(BIO *bp)
301 BN_sub(&c,&c,&a); 335 BN_sub(&c,&c,&a);
302 if(!BN_is_zero(&c)) 336 if(!BN_is_zero(&c))
303 { 337 {
304 BIO_puts(bp,"Subtract test failed!\n"); 338 fprintf(stderr,"Subtract test failed!\n");
305 return 0; 339 return 0;
306 } 340 }
307 } 341 }
@@ -323,10 +357,17 @@ int test_div(BIO *bp, BN_CTX *ctx)
323 BN_init(&d); 357 BN_init(&d);
324 BN_init(&e); 358 BN_init(&e);
325 359
326 BN_rand(&a,400,0,0); 360 for (i=0; i<num0+num1; i++)
327 for (i=0; i<100; i++)
328 { 361 {
329 BN_rand(&b,50+i,0,0); 362 if (i < num1)
363 {
364 BN_rand(&a,400,0,0);
365 BN_copy(&b,&a);
366 BN_lshift(&a,&a,i);
367 BN_add_word(&a,i);
368 }
369 else
370 BN_rand(&b,50+3*(i-num1),0,0);
330 a.neg=rand_neg(); 371 a.neg=rand_neg();
331 b.neg=rand_neg(); 372 b.neg=rand_neg();
332 if (bp == NULL) 373 if (bp == NULL)
@@ -360,7 +401,7 @@ int test_div(BIO *bp, BN_CTX *ctx)
360 BN_sub(&d,&d,&a); 401 BN_sub(&d,&d,&a);
361 if(!BN_is_zero(&d)) 402 if(!BN_is_zero(&d))
362 { 403 {
363 BIO_puts(bp,"Division test failed!\n"); 404 fprintf(stderr,"Division test failed!\n");
364 return 0; 405 return 0;
365 } 406 }
366 } 407 }
@@ -386,10 +427,17 @@ int test_div_recp(BIO *bp, BN_CTX *ctx)
386 BN_init(&d); 427 BN_init(&d);
387 BN_init(&e); 428 BN_init(&e);
388 429
389 BN_rand(&a,400,0,0); 430 for (i=0; i<num0+num1; i++)
390 for (i=0; i<100; i++)
391 { 431 {
392 BN_rand(&b,50+i,0,0); 432 if (i < num1)
433 {
434 BN_rand(&a,400,0,0);
435 BN_copy(&b,&a);
436 BN_lshift(&a,&a,i);
437 BN_add_word(&a,i);
438 }
439 else
440 BN_rand(&b,50+3*(i-num1),0,0);
393 a.neg=rand_neg(); 441 a.neg=rand_neg();
394 b.neg=rand_neg(); 442 b.neg=rand_neg();
395 BN_RECP_CTX_set(&recp,&b,ctx); 443 BN_RECP_CTX_set(&recp,&b,ctx);
@@ -424,7 +472,12 @@ int test_div_recp(BIO *bp, BN_CTX *ctx)
424 BN_sub(&d,&d,&a); 472 BN_sub(&d,&d,&a);
425 if(!BN_is_zero(&d)) 473 if(!BN_is_zero(&d))
426 { 474 {
427 BIO_puts(bp,"Reciprocal division test failed!\n"); 475 fprintf(stderr,"Reciprocal division test failed!\n");
476 fprintf(stderr,"a=");
477 BN_print_fp(stderr,&a);
478 fprintf(stderr,"\nb=");
479 BN_print_fp(stderr,&b);
480 fprintf(stderr,"\n");
428 return 0; 481 return 0;
429 } 482 }
430 } 483 }
@@ -451,11 +504,15 @@ int test_mul(BIO *bp)
451 BN_init(&d); 504 BN_init(&d);
452 BN_init(&e); 505 BN_init(&e);
453 506
454 BN_rand(&a,200,0,0); 507 for (i=0; i<num0+num1; i++)
455 for (i=0; i<100; i++)
456 { 508 {
457 BN_rand(&b,250+i,0,0); 509 if (i <= num1)
458 BN_rand(&b,200,0,0); 510 {
511 BN_rand(&a,100,0,0);
512 BN_rand(&b,100,0,0);
513 }
514 else
515 BN_rand(&b,i-num1,0,0);
459 a.neg=rand_neg(); 516 a.neg=rand_neg();
460 b.neg=rand_neg(); 517 b.neg=rand_neg();
461 if (bp == NULL) 518 if (bp == NULL)
@@ -478,7 +535,7 @@ int test_mul(BIO *bp)
478 BN_sub(&d,&d,&b); 535 BN_sub(&d,&d,&b);
479 if(!BN_is_zero(&d) || !BN_is_zero(&e)) 536 if(!BN_is_zero(&d) || !BN_is_zero(&e))
480 { 537 {
481 BIO_puts(bp,"Multiplication test failed!\n"); 538 fprintf(stderr,"Multiplication test failed!\n");
482 return 0; 539 return 0;
483 } 540 }
484 } 541 }
@@ -502,7 +559,7 @@ int test_sqr(BIO *bp, BN_CTX *ctx)
502 BN_init(&d); 559 BN_init(&d);
503 BN_init(&e); 560 BN_init(&e);
504 561
505 for (i=0; i<40; i++) 562 for (i=0; i<num0; i++)
506 { 563 {
507 BN_rand(&a,40+i*10,0,0); 564 BN_rand(&a,40+i*10,0,0);
508 a.neg=rand_neg(); 565 a.neg=rand_neg();
@@ -526,7 +583,7 @@ int test_sqr(BIO *bp, BN_CTX *ctx)
526 BN_sub(&d,&d,&a); 583 BN_sub(&d,&d,&a);
527 if(!BN_is_zero(&d) || !BN_is_zero(&e)) 584 if(!BN_is_zero(&d) || !BN_is_zero(&e))
528 { 585 {
529 BIO_puts(bp,"Square test failed!\n"); 586 fprintf(stderr,"Square test failed!\n");
530 return 0; 587 return 0;
531 } 588 }
532 } 589 }
@@ -557,9 +614,13 @@ int test_mont(BIO *bp, BN_CTX *ctx)
557 614
558 BN_rand(&a,100,0,0); /**/ 615 BN_rand(&a,100,0,0); /**/
559 BN_rand(&b,100,0,0); /**/ 616 BN_rand(&b,100,0,0); /**/
560 for (i=0; i<10; i++) 617 for (i=0; i<num2; i++)
561 { 618 {
562 BN_rand(&n,(100%BN_BITS2+1)*BN_BITS2*i*BN_BITS2,0,1); /**/ 619 int bits = (200*(i+1))/num2;
620
621 if (bits == 0)
622 continue;
623 BN_rand(&n,bits,0,1);
563 BN_MONT_CTX_set(mont,&n,ctx); 624 BN_MONT_CTX_set(mont,&n,ctx);
564 625
565 BN_to_montgomery(&A,&a,mont,ctx); 626 BN_to_montgomery(&A,&a,mont,ctx);
@@ -594,7 +655,7 @@ BN_num_bits(mont->N));
594 BN_sub(&d,&d,&A); 655 BN_sub(&d,&d,&A);
595 if(!BN_is_zero(&d)) 656 if(!BN_is_zero(&d))
596 { 657 {
597 BIO_puts(bp,"Montgomery multiplication test failed!\n"); 658 fprintf(stderr,"Montgomery multiplication test failed!\n");
598 return 0; 659 return 0;
599 } 660 }
600 } 661 }
@@ -622,7 +683,7 @@ int test_mod(BIO *bp, BN_CTX *ctx)
622 e=BN_new(); 683 e=BN_new();
623 684
624 BN_rand(a,1024,0,0); /**/ 685 BN_rand(a,1024,0,0); /**/
625 for (i=0; i<20; i++) 686 for (i=0; i<num0; i++)
626 { 687 {
627 BN_rand(b,450+i*10,0,0); /**/ 688 BN_rand(b,450+i*10,0,0); /**/
628 a->neg=rand_neg(); 689 a->neg=rand_neg();
@@ -647,7 +708,7 @@ int test_mod(BIO *bp, BN_CTX *ctx)
647 BN_sub(e,e,c); 708 BN_sub(e,e,c);
648 if(!BN_is_zero(e)) 709 if(!BN_is_zero(e))
649 { 710 {
650 BIO_puts(bp,"Modulo test failed!\n"); 711 fprintf(stderr,"Modulo test failed!\n");
651 return 0; 712 return 0;
652 } 713 }
653 } 714 }
@@ -671,10 +732,10 @@ int test_mod_mul(BIO *bp, BN_CTX *ctx)
671 e=BN_new(); 732 e=BN_new();
672 733
673 BN_rand(c,1024,0,0); /**/ 734 BN_rand(c,1024,0,0); /**/
674 for (i=0; i<10; i++) 735 for (i=0; i<num0; i++)
675 { 736 {
676 BN_rand(a,475+i*10,0,0); /**/ 737 BN_rand(a,475+i*10,0,0); /**/
677 BN_rand(b,425+i*10,0,0); /**/ 738 BN_rand(b,425+i*11,0,0); /**/
678 a->neg=rand_neg(); 739 a->neg=rand_neg();
679 b->neg=rand_neg(); 740 b->neg=rand_neg();
680 /* if (bp == NULL) 741 /* if (bp == NULL)
@@ -709,7 +770,7 @@ int test_mod_mul(BIO *bp, BN_CTX *ctx)
709 BN_div(a,b,d,c,ctx); 770 BN_div(a,b,d,c,ctx);
710 if(!BN_is_zero(b)) 771 if(!BN_is_zero(b))
711 { 772 {
712 BIO_puts(bp,"Modulo multiply test failed!\n"); 773 fprintf(stderr,"Modulo multiply test failed!\n");
713 return 0; 774 return 0;
714 } 775 }
715 } 776 }
@@ -733,7 +794,7 @@ int test_mod_exp(BIO *bp, BN_CTX *ctx)
733 e=BN_new(); 794 e=BN_new();
734 795
735 BN_rand(c,30,0,1); /* must be odd for montgomery */ 796 BN_rand(c,30,0,1); /* must be odd for montgomery */
736 for (i=0; i<6; i++) 797 for (i=0; i<num2; i++)
737 { 798 {
738 BN_rand(a,20+i*5,0,0); /**/ 799 BN_rand(a,20+i*5,0,0); /**/
739 BN_rand(b,2+i,0,0); /**/ 800 BN_rand(b,2+i,0,0); /**/
@@ -760,7 +821,7 @@ int test_mod_exp(BIO *bp, BN_CTX *ctx)
760 BN_div(a,b,e,c,ctx); 821 BN_div(a,b,e,c,ctx);
761 if(!BN_is_zero(b)) 822 if(!BN_is_zero(b))
762 { 823 {
763 BIO_puts(bp,"Modulo exponentiation test failed!\n"); 824 fprintf(stderr,"Modulo exponentiation test failed!\n");
764 return 0; 825 return 0;
765 } 826 }
766 } 827 }
@@ -784,7 +845,7 @@ int test_exp(BIO *bp, BN_CTX *ctx)
784 one=BN_new(); 845 one=BN_new();
785 BN_one(one); 846 BN_one(one);
786 847
787 for (i=0; i<6; i++) 848 for (i=0; i<num2; i++)
788 { 849 {
789 BN_rand(a,20+i*5,0,0); /**/ 850 BN_rand(a,20+i*5,0,0); /**/
790 BN_rand(b,2+i,0,0); /**/ 851 BN_rand(b,2+i,0,0); /**/
@@ -810,7 +871,7 @@ int test_exp(BIO *bp, BN_CTX *ctx)
810 BN_sub(e,e,d); 871 BN_sub(e,e,d);
811 if(!BN_is_zero(e)) 872 if(!BN_is_zero(e))
812 { 873 {
813 BIO_puts(bp,"Exponentiation test failed!\n"); 874 fprintf(stderr,"Exponentiation test failed!\n");
814 return 0; 875 return 0;
815 } 876 }
816 } 877 }
@@ -840,7 +901,7 @@ int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_)
840 BN_rand(a,200,0,0); /**/ 901 BN_rand(a,200,0,0); /**/
841 a->neg=rand_neg(); 902 a->neg=rand_neg();
842 } 903 }
843 for (i=0; i<70; i++) 904 for (i=0; i<num0; i++)
844 { 905 {
845 BN_lshift(b,a,i+1); 906 BN_lshift(b,a,i+1);
846 BN_add(c,c,c); 907 BN_add(c,c,c);
@@ -860,16 +921,16 @@ int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_)
860 BN_sub(d,d,b); 921 BN_sub(d,d,b);
861 if(!BN_is_zero(d)) 922 if(!BN_is_zero(d))
862 { 923 {
863 BIO_puts(bp,"Left shift test failed!\n"); 924 fprintf(stderr,"Left shift test failed!\n");
864 BIO_puts(bp,"a="); 925 fprintf(stderr,"a=");
865 BN_print(bp,a); 926 BN_print_fp(stderr,a);
866 BIO_puts(bp,"\nb="); 927 fprintf(stderr,"\nb=");
867 BN_print(bp,b); 928 BN_print_fp(stderr,b);
868 BIO_puts(bp,"\nc="); 929 fprintf(stderr,"\nc=");
869 BN_print(bp,c); 930 BN_print_fp(stderr,c);
870 BIO_puts(bp,"\nd="); 931 fprintf(stderr,"\nd=");
871 BN_print(bp,d); 932 BN_print_fp(stderr,d);
872 BIO_puts(bp,"\n"); 933 fprintf(stderr,"\n");
873 return 0; 934 return 0;
874 } 935 }
875 } 936 }
@@ -891,7 +952,7 @@ int test_lshift1(BIO *bp)
891 952
892 BN_rand(a,200,0,0); /**/ 953 BN_rand(a,200,0,0); /**/
893 a->neg=rand_neg(); 954 a->neg=rand_neg();
894 for (i=0; i<70; i++) 955 for (i=0; i<num0; i++)
895 { 956 {
896 BN_lshift1(b,a); 957 BN_lshift1(b,a);
897 if (bp != NULL) 958 if (bp != NULL)
@@ -909,7 +970,7 @@ int test_lshift1(BIO *bp)
909 BN_sub(a,b,c); 970 BN_sub(a,b,c);
910 if(!BN_is_zero(a)) 971 if(!BN_is_zero(a))
911 { 972 {
912 BIO_puts(bp,"Left shift one test failed!\n"); 973 fprintf(stderr,"Left shift one test failed!\n");
913 return 0; 974 return 0;
914 } 975 }
915 976
@@ -935,7 +996,7 @@ int test_rshift(BIO *bp,BN_CTX *ctx)
935 996
936 BN_rand(a,200,0,0); /**/ 997 BN_rand(a,200,0,0); /**/
937 a->neg=rand_neg(); 998 a->neg=rand_neg();
938 for (i=0; i<70; i++) 999 for (i=0; i<num0; i++)
939 { 1000 {
940 BN_rshift(b,a,i+1); 1001 BN_rshift(b,a,i+1);
941 BN_add(c,c,c); 1002 BN_add(c,c,c);
@@ -955,7 +1016,7 @@ int test_rshift(BIO *bp,BN_CTX *ctx)
955 BN_sub(d,d,b); 1016 BN_sub(d,d,b);
956 if(!BN_is_zero(d)) 1017 if(!BN_is_zero(d))
957 { 1018 {
958 BIO_puts(bp,"Right shift test failed!\n"); 1019 fprintf(stderr,"Right shift test failed!\n");
959 return 0; 1020 return 0;
960 } 1021 }
961 } 1022 }
@@ -978,7 +1039,7 @@ int test_rshift1(BIO *bp)
978 1039
979 BN_rand(a,200,0,0); /**/ 1040 BN_rand(a,200,0,0); /**/
980 a->neg=rand_neg(); 1041 a->neg=rand_neg();
981 for (i=0; i<70; i++) 1042 for (i=0; i<num0; i++)
982 { 1043 {
983 BN_rshift1(b,a); 1044 BN_rshift1(b,a);
984 if (bp != NULL) 1045 if (bp != NULL)
@@ -996,7 +1057,7 @@ int test_rshift1(BIO *bp)
996 BN_sub(c,c,b); 1057 BN_sub(c,c,b);
997 if(!BN_is_zero(c) && !BN_is_one(c)) 1058 if(!BN_is_zero(c) && !BN_is_one(c))
998 { 1059 {
999 BIO_puts(bp,"Right shift one test failed!\n"); 1060 fprintf(stderr,"Right shift one test failed!\n");
1000 return 0; 1061 return 0;
1001 } 1062 }
1002 BN_copy(a,b); 1063 BN_copy(a,b);