@@ -729,7 +729,7 @@ static int test_mp_sqrt(void)
729
729
printf ("\nmp_sqrt() error!" );
730
730
goto LBL_ERR ;
731
731
}
732
- DO (mp_root_u32 (& a , 2u , & c ));
732
+ DO (mp_root_n (& a , 2u , & c ));
733
733
if (mp_cmp_mag (& b , & c ) != MP_EQ ) {
734
734
printf ("mp_sqrt() bad result!\n" );
735
735
goto LBL_ERR ;
@@ -1396,10 +1396,10 @@ static int test_mp_reduce_2k_l(void)
1396
1396
/* stripped down version of mp_radix_size. The faster version can be off by up t
1397
1397
o +3 */
1398
1398
/* TODO: This function should be removed, replaced by mp_radix_size, mp_radix_size_overestimate in 2.0 */
1399
- static mp_err s_rs (const mp_int * a , int radix , uint32_t * size )
1399
+ static mp_err s_rs (const mp_int * a , int radix , int * size )
1400
1400
{
1401
1401
mp_err res ;
1402
- uint32_t digs = 0u ;
1402
+ int digs = 0u ;
1403
1403
mp_int t ;
1404
1404
mp_digit d ;
1405
1405
* size = 0u ;
@@ -1408,7 +1408,7 @@ static mp_err s_rs(const mp_int *a, int radix, uint32_t *size)
1408
1408
return MP_OKAY ;
1409
1409
}
1410
1410
if (radix == 2 ) {
1411
- * size = ( uint32_t ) mp_count_bits (a ) + 1u ;
1411
+ * size = mp_count_bits (a ) + 1 ;
1412
1412
return MP_OKAY ;
1413
1413
}
1414
1414
DOR (mp_init_copy (& t , a ));
@@ -1424,12 +1424,12 @@ static mp_err s_rs(const mp_int *a, int radix, uint32_t *size)
1424
1424
* size = digs + 1 ;
1425
1425
return MP_OKAY ;
1426
1426
}
1427
- static int test_mp_log_u32 (void )
1427
+ static int test_mp_log_n (void )
1428
1428
{
1429
1429
mp_int a ;
1430
1430
mp_digit d ;
1431
- uint32_t base , lb , size ;
1432
- const uint32_t max_base = MP_MIN (UINT32_MAX , MP_DIGIT_MAX );
1431
+ int base , lb , size ;
1432
+ const int max_base = MP_MIN (INT_MAX , MP_DIGIT_MAX );
1433
1433
1434
1434
DOR (mp_init (& a ));
1435
1435
@@ -1440,11 +1440,11 @@ static int test_mp_log_u32(void)
1440
1440
*/
1441
1441
mp_set (& a , 42u );
1442
1442
base = 0u ;
1443
- if (mp_log_u32 (& a , base , & lb ) != MP_VAL ) {
1443
+ if (mp_log_n (& a , base , & lb ) != MP_VAL ) {
1444
1444
goto LBL_ERR ;
1445
1445
}
1446
1446
base = 1u ;
1447
- if (mp_log_u32 (& a , base , & lb ) != MP_VAL ) {
1447
+ if (mp_log_n (& a , base , & lb ) != MP_VAL ) {
1448
1448
goto LBL_ERR ;
1449
1449
}
1450
1450
/*
@@ -1456,14 +1456,14 @@ static int test_mp_log_u32(void)
1456
1456
*/
1457
1457
base = 2u ;
1458
1458
mp_zero (& a );
1459
- if (mp_log_u32 (& a , base , & lb ) != MP_VAL ) {
1459
+ if (mp_log_n (& a , base , & lb ) != MP_VAL ) {
1460
1460
goto LBL_ERR ;
1461
1461
}
1462
1462
1463
1463
for (d = 1 ; d < 4 ; d ++ ) {
1464
1464
mp_set (& a , d );
1465
- DO (mp_log_u32 (& a , base , & lb ));
1466
- if (lb != ((d == 1 )?0uL : 1uL )) {
1465
+ DO (mp_log_n (& a , base , & lb ));
1466
+ if (lb != ((d == 1 )?0 : 1 )) {
1467
1467
goto LBL_ERR ;
1468
1468
}
1469
1469
}
@@ -1476,13 +1476,13 @@ static int test_mp_log_u32(void)
1476
1476
*/
1477
1477
base = 3u ;
1478
1478
mp_zero (& a );
1479
- if (mp_log_u32 (& a , base , & lb ) != MP_VAL ) {
1479
+ if (mp_log_n (& a , base , & lb ) != MP_VAL ) {
1480
1480
goto LBL_ERR ;
1481
1481
}
1482
1482
for (d = 1 ; d < 4 ; d ++ ) {
1483
1483
mp_set (& a , d );
1484
- DO (mp_log_u32 (& a , base , & lb ));
1485
- if (lb != ((d < base )?0uL : 1uL )) {
1484
+ DO (mp_log_n (& a , base , & lb ));
1485
+ if (lb != ((( int ) d < base )?0 : 1 )) {
1486
1486
goto LBL_ERR ;
1487
1487
}
1488
1488
}
@@ -1493,8 +1493,8 @@ static int test_mp_log_u32(void)
1493
1493
radix_size.
1494
1494
*/
1495
1495
DO (mp_rand (& a , 10 ));
1496
- for (base = 2u ; base < 65u ; base ++ ) {
1497
- DO (mp_log_u32 (& a , base , & lb ));
1496
+ for (base = 2 ; base < 65 ; base ++ ) {
1497
+ DO (mp_log_n (& a , base , & lb ));
1498
1498
DO (s_rs (& a ,(int )base , & size ));
1499
1499
/* radix_size includes the memory needed for '\0', too*/
1500
1500
size -= 2 ;
@@ -1508,8 +1508,8 @@ static int test_mp_log_u32(void)
1508
1508
test the part of mp_ilogb that uses native types.
1509
1509
*/
1510
1510
DO (mp_rand (& a , 1 ));
1511
- for (base = 2u ; base < 65u ; base ++ ) {
1512
- DO (mp_log_u32 (& a , base , & lb ));
1511
+ for (base = 2 ; base < 65 ; base ++ ) {
1512
+ DO (mp_log_n (& a , base , & lb ));
1513
1513
DO (s_rs (& a ,(int )base , & size ));
1514
1514
size -= 2 ;
1515
1515
if (lb != size ) {
@@ -1519,9 +1519,9 @@ static int test_mp_log_u32(void)
1519
1519
1520
1520
/*Test upper edgecase with base UINT32_MAX and number (UINT32_MAX/2)*UINT32_MAX^10 */
1521
1521
mp_set (& a , max_base );
1522
- DO (mp_expt_u32 (& a , 10u , & a ));
1523
- DO (mp_add_d (& a , max_base / 2u , & a ));
1524
- DO (mp_log_u32 (& a , max_base , & lb ));
1522
+ DO (mp_expt_n (& a , 10uL , & a ));
1523
+ DO (mp_add_d (& a , max_base / 2 , & a ));
1524
+ DO (mp_log_n (& a , max_base , & lb ));
1525
1525
if (lb != 10u ) {
1526
1526
goto LBL_ERR ;
1527
1527
}
@@ -1636,7 +1636,7 @@ static int test_mp_decr(void)
1636
1636
}
1637
1637
1638
1638
/*
1639
- Cannot test mp_exp(_d) without mp_root and vice versa.
1639
+ Cannot test mp_exp(_d) without mp_root_n and vice versa.
1640
1640
So one of the two has to be tested from scratch.
1641
1641
1642
1642
Numbers generated by
@@ -1658,7 +1658,7 @@ static int test_mp_decr(void)
1658
1658
low-mp branch.
1659
1659
*/
1660
1660
1661
- static int test_mp_root_u32 (void )
1661
+ static int test_mp_root_n (void )
1662
1662
{
1663
1663
mp_int a , c , r ;
1664
1664
int i , j ;
@@ -1850,10 +1850,10 @@ static int test_mp_root_u32(void)
1850
1850
for (i = 0 ; i < 10 ; i ++ ) {
1851
1851
DO (mp_read_radix (& a , input [i ], 64 ));
1852
1852
for (j = 3 ; j < 100 ; j ++ ) {
1853
- DO (mp_root_u32 (& a , ( uint32_t ) j , & c ));
1853
+ DO (mp_root_n (& a , j , & c ));
1854
1854
DO (mp_read_radix (& r , root [i ][j - 3 ], 10 ));
1855
1855
if (mp_cmp (& r , & c ) != MP_EQ ) {
1856
- fprintf (stderr , "mp_root_u32 failed at input #%d, root #%d\n" , i , j );
1856
+ fprintf (stderr , "mp_root_n failed at input #%d, root #%d\n" , i , j );
1857
1857
goto LBL_ERR ;
1858
1858
}
1859
1859
}
@@ -2037,8 +2037,8 @@ static int test_mp_radix_size(void)
2037
2037
DOR (mp_init (& a ));
2038
2038
2039
2039
/* number to result in a different size for every base: 67^(4 * 67) */
2040
- mp_set (& a , 67u );
2041
- DO (mp_expt_u32 (& a , 268u , & a ));
2040
+ mp_set (& a , 67 );
2041
+ DO (mp_expt_n (& a , 268 , & a ));
2042
2042
2043
2043
for (radix = 2 ; radix < 65 ; radix ++ ) {
2044
2044
DO (mp_radix_size (& a , radix , & size ));
@@ -2304,13 +2304,13 @@ static int unit_tests(int argc, char **argv)
2304
2304
T1 (mp_get_u32 , MP_GET_I32 ),
2305
2305
T1 (mp_get_u64 , MP_GET_I64 ),
2306
2306
T1 (mp_get_ul , MP_GET_L ),
2307
- T1 (mp_log_u32 , MP_LOG_U32 ),
2307
+ T1 (mp_log_n , MP_LOG_N ),
2308
2308
T1 (mp_incr , MP_ADD_D ),
2309
2309
T1 (mp_invmod , MP_INVMOD ),
2310
2310
T1 (mp_is_square , MP_IS_SQUARE ),
2311
2311
T1 (mp_kronecker , MP_KRONECKER ),
2312
2312
T1 (mp_montgomery_reduce , MP_MONTGOMERY_REDUCE ),
2313
- T1 (mp_root_u32 , MP_ROOT_U32 ),
2313
+ T1 (mp_root_n , MP_ROOT_N ),
2314
2314
T1 (mp_or , MP_OR ),
2315
2315
T1 (mp_prime_is_prime , MP_PRIME_IS_PRIME ),
2316
2316
T1 (mp_prime_next_prime , MP_PRIME_NEXT_PRIME ),
@@ -2326,7 +2326,7 @@ static int unit_tests(int argc, char **argv)
2326
2326
T1 (mp_set_double , MP_SET_DOUBLE ),
2327
2327
#endif
2328
2328
T1 (mp_signed_rsh , MP_SIGNED_RSH ),
2329
- T1 (mp_sqrt , MP_SQRT ),
2329
+ T2 (mp_sqrt , MP_SQRT , mp_root_n ),
2330
2330
T1 (mp_sqrtmod_prime , MP_SQRTMOD_PRIME ),
2331
2331
T1 (mp_xor , MP_XOR ),
2332
2332
T2 (s_mp_div_recursive , S_MP_DIV_RECURSIVE , S_MP_DIV_SCHOOL ),
0 commit comments