OLD | NEW |
1 /* crypto/bn/bntest.c */ | 1 /* crypto/bn/bntest.c */ |
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
8 * | 8 * |
9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 if (sizeof(w) > sizeof(unsigned long)) | 479 if (sizeof(w) > sizeof(unsigned long)) |
480 { | 480 { |
481 unsigned long h=(unsigned long)(w>>32), | 481 unsigned long h=(unsigned long)(w>>32), |
482 l=(unsigned long)(w); | 482 l=(unsigned long)(w); |
483 | 483 |
484 if (h) BIO_printf(bp,"%lX%08lX",h,l); | 484 if (h) BIO_printf(bp,"%lX%08lX",h,l); |
485 else BIO_printf(bp,"%lX",l); | 485 else BIO_printf(bp,"%lX",l); |
486 return; | 486 return; |
487 } | 487 } |
488 #endif | 488 #endif |
489 » BIO_printf(bp,"%lX",w); | 489 » BIO_printf(bp,BN_HEX_FMT1,w); |
490 } | 490 } |
491 | 491 |
492 int test_div_word(BIO *bp) | 492 int test_div_word(BIO *bp) |
493 { | 493 { |
494 BIGNUM a,b; | 494 BIGNUM a,b; |
495 BN_ULONG r,s; | 495 BN_ULONG r,s; |
496 int i; | 496 int i; |
497 | 497 |
498 BN_init(&a); | 498 BN_init(&a); |
499 BN_init(&b); | 499 BN_init(&b); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 | 725 |
726 BN_init(&a); | 726 BN_init(&a); |
727 BN_init(&b); | 727 BN_init(&b); |
728 BN_init(&c); | 728 BN_init(&c); |
729 BN_init(&d); | 729 BN_init(&d); |
730 BN_init(&A); | 730 BN_init(&A); |
731 BN_init(&B); | 731 BN_init(&B); |
732 BN_init(&n); | 732 BN_init(&n); |
733 | 733 |
734 mont=BN_MONT_CTX_new(); | 734 mont=BN_MONT_CTX_new(); |
| 735 if (mont == NULL) |
| 736 return 0; |
735 | 737 |
736 BN_bntest_rand(&a,100,0,0); /**/ | 738 BN_bntest_rand(&a,100,0,0); /**/ |
737 BN_bntest_rand(&b,100,0,0); /**/ | 739 BN_bntest_rand(&b,100,0,0); /**/ |
738 for (i=0; i<num2; i++) | 740 for (i=0; i<num2; i++) |
739 { | 741 { |
740 int bits = (200*(i+1))/num2; | 742 int bits = (200*(i+1))/num2; |
741 | 743 |
742 if (bits == 0) | 744 if (bits == 0) |
743 continue; | 745 continue; |
744 BN_bntest_rand(&n,bits,0,1); | 746 BN_bntest_rand(&n,bits,0,1); |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 BN_free(&a); | 1111 BN_free(&a); |
1110 BN_free(&b); | 1112 BN_free(&b); |
1111 BN_free(&c); | 1113 BN_free(&c); |
1112 return ret; | 1114 return ret; |
1113 } | 1115 } |
1114 | 1116 |
1115 int test_gf2m_mod(BIO *bp) | 1117 int test_gf2m_mod(BIO *bp) |
1116 { | 1118 { |
1117 BIGNUM *a,*b[2],*c,*d,*e; | 1119 BIGNUM *a,*b[2],*c,*d,*e; |
1118 int i, j, ret = 0; | 1120 int i, j, ret = 0; |
1119 » unsigned int p0[] = {163,7,6,3,0}; | 1121 » int p0[] = {163,7,6,3,0,-1}; |
1120 » unsigned int p1[] = {193,15,0}; | 1122 » int p1[] = {193,15,0,-1}; |
1121 | 1123 |
1122 a=BN_new(); | 1124 a=BN_new(); |
1123 b[0]=BN_new(); | 1125 b[0]=BN_new(); |
1124 b[1]=BN_new(); | 1126 b[1]=BN_new(); |
1125 c=BN_new(); | 1127 c=BN_new(); |
1126 d=BN_new(); | 1128 d=BN_new(); |
1127 e=BN_new(); | 1129 e=BN_new(); |
1128 | 1130 |
1129 BN_GF2m_arr2poly(p0, b[0]); | 1131 BN_GF2m_arr2poly(p0, b[0]); |
1130 BN_GF2m_arr2poly(p1, b[1]); | 1132 BN_GF2m_arr2poly(p1, b[1]); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 BN_free(c); | 1169 BN_free(c); |
1168 BN_free(d); | 1170 BN_free(d); |
1169 BN_free(e); | 1171 BN_free(e); |
1170 return ret; | 1172 return ret; |
1171 } | 1173 } |
1172 | 1174 |
1173 int test_gf2m_mod_mul(BIO *bp,BN_CTX *ctx) | 1175 int test_gf2m_mod_mul(BIO *bp,BN_CTX *ctx) |
1174 { | 1176 { |
1175 BIGNUM *a,*b[2],*c,*d,*e,*f,*g,*h; | 1177 BIGNUM *a,*b[2],*c,*d,*e,*f,*g,*h; |
1176 int i, j, ret = 0; | 1178 int i, j, ret = 0; |
1177 » unsigned int p0[] = {163,7,6,3,0}; | 1179 » int p0[] = {163,7,6,3,0,-1}; |
1178 » unsigned int p1[] = {193,15,0}; | 1180 » int p1[] = {193,15,0,-1}; |
1179 | 1181 |
1180 a=BN_new(); | 1182 a=BN_new(); |
1181 b[0]=BN_new(); | 1183 b[0]=BN_new(); |
1182 b[1]=BN_new(); | 1184 b[1]=BN_new(); |
1183 c=BN_new(); | 1185 c=BN_new(); |
1184 d=BN_new(); | 1186 d=BN_new(); |
1185 e=BN_new(); | 1187 e=BN_new(); |
1186 f=BN_new(); | 1188 f=BN_new(); |
1187 g=BN_new(); | 1189 g=BN_new(); |
1188 h=BN_new(); | 1190 h=BN_new(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 BN_free(f); | 1240 BN_free(f); |
1239 BN_free(g); | 1241 BN_free(g); |
1240 BN_free(h); | 1242 BN_free(h); |
1241 return ret; | 1243 return ret; |
1242 } | 1244 } |
1243 | 1245 |
1244 int test_gf2m_mod_sqr(BIO *bp,BN_CTX *ctx) | 1246 int test_gf2m_mod_sqr(BIO *bp,BN_CTX *ctx) |
1245 { | 1247 { |
1246 BIGNUM *a,*b[2],*c,*d; | 1248 BIGNUM *a,*b[2],*c,*d; |
1247 int i, j, ret = 0; | 1249 int i, j, ret = 0; |
1248 » unsigned int p0[] = {163,7,6,3,0}; | 1250 » int p0[] = {163,7,6,3,0,-1}; |
1249 » unsigned int p1[] = {193,15,0}; | 1251 » int p1[] = {193,15,0,-1}; |
1250 | 1252 |
1251 a=BN_new(); | 1253 a=BN_new(); |
1252 b[0]=BN_new(); | 1254 b[0]=BN_new(); |
1253 b[1]=BN_new(); | 1255 b[1]=BN_new(); |
1254 c=BN_new(); | 1256 c=BN_new(); |
1255 d=BN_new(); | 1257 d=BN_new(); |
1256 | 1258 |
1257 BN_GF2m_arr2poly(p0, b[0]); | 1259 BN_GF2m_arr2poly(p0, b[0]); |
1258 BN_GF2m_arr2poly(p1, b[1]); | 1260 BN_GF2m_arr2poly(p1, b[1]); |
1259 | 1261 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 BN_free(b[1]); | 1299 BN_free(b[1]); |
1298 BN_free(c); | 1300 BN_free(c); |
1299 BN_free(d); | 1301 BN_free(d); |
1300 return ret; | 1302 return ret; |
1301 } | 1303 } |
1302 | 1304 |
1303 int test_gf2m_mod_inv(BIO *bp,BN_CTX *ctx) | 1305 int test_gf2m_mod_inv(BIO *bp,BN_CTX *ctx) |
1304 { | 1306 { |
1305 BIGNUM *a,*b[2],*c,*d; | 1307 BIGNUM *a,*b[2],*c,*d; |
1306 int i, j, ret = 0; | 1308 int i, j, ret = 0; |
1307 » unsigned int p0[] = {163,7,6,3,0}; | 1309 » int p0[] = {163,7,6,3,0,-1}; |
1308 » unsigned int p1[] = {193,15,0}; | 1310 » int p1[] = {193,15,0,-1}; |
1309 | 1311 |
1310 a=BN_new(); | 1312 a=BN_new(); |
1311 b[0]=BN_new(); | 1313 b[0]=BN_new(); |
1312 b[1]=BN_new(); | 1314 b[1]=BN_new(); |
1313 c=BN_new(); | 1315 c=BN_new(); |
1314 d=BN_new(); | 1316 d=BN_new(); |
1315 | 1317 |
1316 BN_GF2m_arr2poly(p0, b[0]); | 1318 BN_GF2m_arr2poly(p0, b[0]); |
1317 BN_GF2m_arr2poly(p1, b[1]); | 1319 BN_GF2m_arr2poly(p1, b[1]); |
1318 | 1320 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 BN_free(b[1]); | 1354 BN_free(b[1]); |
1353 BN_free(c); | 1355 BN_free(c); |
1354 BN_free(d); | 1356 BN_free(d); |
1355 return ret; | 1357 return ret; |
1356 } | 1358 } |
1357 | 1359 |
1358 int test_gf2m_mod_div(BIO *bp,BN_CTX *ctx) | 1360 int test_gf2m_mod_div(BIO *bp,BN_CTX *ctx) |
1359 { | 1361 { |
1360 BIGNUM *a,*b[2],*c,*d,*e,*f; | 1362 BIGNUM *a,*b[2],*c,*d,*e,*f; |
1361 int i, j, ret = 0; | 1363 int i, j, ret = 0; |
1362 » unsigned int p0[] = {163,7,6,3,0}; | 1364 » int p0[] = {163,7,6,3,0,-1}; |
1363 » unsigned int p1[] = {193,15,0}; | 1365 » int p1[] = {193,15,0,-1}; |
1364 | 1366 |
1365 a=BN_new(); | 1367 a=BN_new(); |
1366 b[0]=BN_new(); | 1368 b[0]=BN_new(); |
1367 b[1]=BN_new(); | 1369 b[1]=BN_new(); |
1368 c=BN_new(); | 1370 c=BN_new(); |
1369 d=BN_new(); | 1371 d=BN_new(); |
1370 e=BN_new(); | 1372 e=BN_new(); |
1371 f=BN_new(); | 1373 f=BN_new(); |
1372 | 1374 |
1373 BN_GF2m_arr2poly(p0, b[0]); | 1375 BN_GF2m_arr2poly(p0, b[0]); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 BN_free(d); | 1417 BN_free(d); |
1416 BN_free(e); | 1418 BN_free(e); |
1417 BN_free(f); | 1419 BN_free(f); |
1418 return ret; | 1420 return ret; |
1419 } | 1421 } |
1420 | 1422 |
1421 int test_gf2m_mod_exp(BIO *bp,BN_CTX *ctx) | 1423 int test_gf2m_mod_exp(BIO *bp,BN_CTX *ctx) |
1422 { | 1424 { |
1423 BIGNUM *a,*b[2],*c,*d,*e,*f; | 1425 BIGNUM *a,*b[2],*c,*d,*e,*f; |
1424 int i, j, ret = 0; | 1426 int i, j, ret = 0; |
1425 » unsigned int p0[] = {163,7,6,3,0}; | 1427 » int p0[] = {163,7,6,3,0,-1}; |
1426 » unsigned int p1[] = {193,15,0}; | 1428 » int p1[] = {193,15,0,-1}; |
1427 | 1429 |
1428 a=BN_new(); | 1430 a=BN_new(); |
1429 b[0]=BN_new(); | 1431 b[0]=BN_new(); |
1430 b[1]=BN_new(); | 1432 b[1]=BN_new(); |
1431 c=BN_new(); | 1433 c=BN_new(); |
1432 d=BN_new(); | 1434 d=BN_new(); |
1433 e=BN_new(); | 1435 e=BN_new(); |
1434 f=BN_new(); | 1436 f=BN_new(); |
1435 | 1437 |
1436 BN_GF2m_arr2poly(p0, b[0]); | 1438 BN_GF2m_arr2poly(p0, b[0]); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1486 BN_free(d); | 1488 BN_free(d); |
1487 BN_free(e); | 1489 BN_free(e); |
1488 BN_free(f); | 1490 BN_free(f); |
1489 return ret; | 1491 return ret; |
1490 } | 1492 } |
1491 | 1493 |
1492 int test_gf2m_mod_sqrt(BIO *bp,BN_CTX *ctx) | 1494 int test_gf2m_mod_sqrt(BIO *bp,BN_CTX *ctx) |
1493 { | 1495 { |
1494 BIGNUM *a,*b[2],*c,*d,*e,*f; | 1496 BIGNUM *a,*b[2],*c,*d,*e,*f; |
1495 int i, j, ret = 0; | 1497 int i, j, ret = 0; |
1496 » unsigned int p0[] = {163,7,6,3,0}; | 1498 » int p0[] = {163,7,6,3,0,-1}; |
1497 » unsigned int p1[] = {193,15,0}; | 1499 » int p1[] = {193,15,0,-1}; |
1498 | 1500 |
1499 a=BN_new(); | 1501 a=BN_new(); |
1500 b[0]=BN_new(); | 1502 b[0]=BN_new(); |
1501 b[1]=BN_new(); | 1503 b[1]=BN_new(); |
1502 c=BN_new(); | 1504 c=BN_new(); |
1503 d=BN_new(); | 1505 d=BN_new(); |
1504 e=BN_new(); | 1506 e=BN_new(); |
1505 f=BN_new(); | 1507 f=BN_new(); |
1506 | 1508 |
1507 BN_GF2m_arr2poly(p0, b[0]); | 1509 BN_GF2m_arr2poly(p0, b[0]); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 BN_free(d); | 1547 BN_free(d); |
1546 BN_free(e); | 1548 BN_free(e); |
1547 BN_free(f); | 1549 BN_free(f); |
1548 return ret; | 1550 return ret; |
1549 } | 1551 } |
1550 | 1552 |
1551 int test_gf2m_mod_solve_quad(BIO *bp,BN_CTX *ctx) | 1553 int test_gf2m_mod_solve_quad(BIO *bp,BN_CTX *ctx) |
1552 { | 1554 { |
1553 BIGNUM *a,*b[2],*c,*d,*e; | 1555 BIGNUM *a,*b[2],*c,*d,*e; |
1554 int i, j, s = 0, t, ret = 0; | 1556 int i, j, s = 0, t, ret = 0; |
1555 » unsigned int p0[] = {163,7,6,3,0}; | 1557 » int p0[] = {163,7,6,3,0,-1}; |
1556 » unsigned int p1[] = {193,15,0}; | 1558 » int p1[] = {193,15,0,-1}; |
1557 | 1559 |
1558 a=BN_new(); | 1560 a=BN_new(); |
1559 b[0]=BN_new(); | 1561 b[0]=BN_new(); |
1560 b[1]=BN_new(); | 1562 b[1]=BN_new(); |
1561 c=BN_new(); | 1563 c=BN_new(); |
1562 d=BN_new(); | 1564 d=BN_new(); |
1563 e=BN_new(); | 1565 e=BN_new(); |
1564 | 1566 |
1565 BN_GF2m_arr2poly(p0, b[0]); | 1567 BN_GF2m_arr2poly(p0, b[0]); |
1566 BN_GF2m_arr2poly(p1, b[1]); | 1568 BN_GF2m_arr2poly(p1, b[1]); |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2002 return(1); | 2004 return(1); |
2003 } | 2005 } |
2004 | 2006 |
2005 int rand_neg(void) | 2007 int rand_neg(void) |
2006 { | 2008 { |
2007 static unsigned int neg=0; | 2009 static unsigned int neg=0; |
2008 static int sign[8]={0,0,0,1,1,0,1,1}; | 2010 static int sign[8]={0,0,0,1,1,0,1,1}; |
2009 | 2011 |
2010 return(sign[(neg++)%8]); | 2012 return(sign[(neg++)%8]); |
2011 } | 2013 } |
OLD | NEW |