@@ -1425,38 +1425,20 @@ static mp_err s_rs(const mp_int *a, int radix, int *size)
1425
1425
return MP_OKAY ;
1426
1426
}
1427
1427
1428
- /* The internal functions that compute the logarithm base two with MP_PRECISION_FIXED_LOG */
1429
- static int test_s_mp_fp_log (void )
1430
- {
1431
- /* s_mp_fp_log(const mp_int *a, mp_int *c) */
1432
-
1433
-
1434
- /*
1435
- "a" some large constants.
1436
- No random values because it would be quite involved to check the results
1437
-
1438
- Some checks are made earlier so no tests with "a" a power of two are needed.
1439
- */
1440
-
1441
-
1442
- return MP_OKAY ;
1443
- }
1444
- static int test_s_mp_fp_log_d (void )
1445
- {
1446
- /* s_mp_fp_log_d(const mp_int *a, mp_word *c) */
1447
- /* See test_s_mp_fp_log() for details */
1448
- return MP_OKAY ;
1449
- }
1450
-
1451
1428
1452
- /* TODO: Cleanup (not everything is still needed) and construct (find) testvalues for each correction loop */
1453
1429
static int test_mp_log_n (void )
1454
1430
{
1455
1431
mp_int a ;
1456
1432
mp_digit d ;
1457
- int base , lb , size ;
1433
+ int base , lb , size , i ;
1458
1434
const int max_base = MP_MIN (INT_MAX , MP_DIGIT_MAX );
1459
1435
1436
+ if (MP_HAS (S_MP_WORD_TOO_SMALL )) {
1437
+ fprintf (stderr , "Testing mp_log_n with restricted size of mp_word.\n" );
1438
+ } else {
1439
+ fprintf (stderr , "Testing mp_log_n with normal size of mp_word.\n" );
1440
+ }
1441
+
1460
1442
DOR (mp_init (& a ));
1461
1443
1462
1444
/*
@@ -1509,25 +1491,32 @@ static int test_mp_log_n(void)
1509
1491
DO (mp_rand (& a , 10 ));
1510
1492
for (base = 2 ; base < 65 ; base ++ ) {
1511
1493
DO (mp_log_n (& a , base , & lb ));
1512
- DO (s_rs (& a ,( int ) base , & size ));
1494
+ DO (s_rs (& a ,base , & size ));
1513
1495
/* radix_size includes the memory needed for '\0', too*/
1514
1496
size -= 2 ;
1515
1497
EXPECT (lb == size );
1516
1498
}
1517
1499
1518
1500
/*
1519
- bases 2..64 with "a" a random small constant to
1520
- test the part of mp_ilogb that uses native types.
1501
+ bases 2..64 with "a" a small constant and a small exponent "n" to test
1502
+ in the range a^n - 10 .. a^n + 10. That will check the correction loops
1503
+ and the test for perfect power.
1504
+ For simplicity a = base and n = 23 (64^23 == 2^138 > 2^128)
1521
1505
*/
1522
- DO (mp_rand (& a , 1 ));
1523
1506
for (base = 2 ; base < 65 ; base ++ ) {
1524
- DO (mp_log_n (& a , base , & lb ));
1525
- DO (s_rs (& a ,(int )base , & size ));
1526
- size -= 2 ;
1527
- EXPECT (lb == size );
1507
+ mp_set (& a ,(mp_digit )base );
1508
+ DO (mp_expt_n (& a , 23 , & a ));
1509
+ DO (mp_sub_d (& a , 10u , & a ));
1510
+ for (i = 0 ; i < 20 ; i ++ ) {
1511
+ DO (mp_log_n (& a , base , & lb ));
1512
+ DO (s_rs (& a , base , & size ));
1513
+ size -= 2 ;
1514
+ EXPECT (lb == size );
1515
+ DO (mp_add_d (& a , 1u , & a ));
1516
+ }
1528
1517
}
1529
1518
1530
- /*Test upper edgecase with base UINT32_MAX and number (UINT32_MAX/2)*UINT32_MAX^10 */
1519
+ /*Test base upper edgecase with base = UINT32_MAX and number = (UINT32_MAX/2)*UINT32_MAX^10 */
1531
1520
mp_set (& a , max_base );
1532
1521
DO (mp_expt_n (& a , 10uL , & a ));
1533
1522
DO (mp_add_d (& a , max_base / 2 , & a ));
@@ -1546,6 +1535,12 @@ static int test_mp_log(void)
1546
1535
mp_int a , base , bn , t ;
1547
1536
int lb , lb2 , i , j ;
1548
1537
1538
+ if (MP_HAS (S_MP_WORD_TOO_SMALL )) {
1539
+ fprintf (stdout , "Testing mp_log with restricted size of mp_word.\n" );
1540
+ } else {
1541
+ fprintf (stdout , "Testing mp_log with normal size of mp_word.\n" );
1542
+ }
1543
+
1549
1544
DOR (mp_init_multi (& a , & base , & bn , & t , NULL ));
1550
1545
1551
1546
/*
@@ -2461,8 +2456,6 @@ static int unit_tests(int argc, char **argv)
2461
2456
T1 (mp_get_u32 , MP_GET_I32 ),
2462
2457
T1 (mp_get_u64 , MP_GET_I64 ),
2463
2458
T1 (mp_get_ul , MP_GET_L ),
2464
- T1 (s_mp_fp_log_d , S_MP_FP_LOG_D ),
2465
- T1 (s_mp_fp_log , S_MP_FP_LOG ),
2466
2459
T1 (mp_log_n , MP_LOG_N ),
2467
2460
T1 (mp_log , MP_LOG ),
2468
2461
T1 (mp_incr , MP_ADD_D ),
0 commit comments