@@ -1425,38 +1425,20 @@ static mp_err s_rs(const mp_int *a, int radix, int *size)
14251425 return MP_OKAY ;
14261426}
14271427
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-
14511428
1452- /* TODO: Cleanup (not everything is still needed) and construct (find) testvalues for each correction loop */
14531429static int test_mp_log_n (void )
14541430{
14551431 mp_int a ;
14561432 mp_digit d ;
1457- int base , lb , size ;
1433+ int base , lb , size , i ;
14581434 const int max_base = MP_MIN (INT_MAX , MP_DIGIT_MAX );
14591435
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+
14601442 DOR (mp_init (& a ));
14611443
14621444 /*
@@ -1509,25 +1491,32 @@ static int test_mp_log_n(void)
15091491 DO (mp_rand (& a , 10 ));
15101492 for (base = 2 ; base < 65 ; base ++ ) {
15111493 DO (mp_log_n (& a , base , & lb ));
1512- DO (s_rs (& a ,( int ) base , & size ));
1494+ DO (s_rs (& a ,base , & size ));
15131495 /* radix_size includes the memory needed for '\0', too*/
15141496 size -= 2 ;
15151497 EXPECT (lb == size );
15161498 }
15171499
15181500 /*
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)
15211505 */
1522- DO (mp_rand (& a , 1 ));
15231506 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+ }
15281517 }
15291518
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 */
15311520 mp_set (& a , max_base );
15321521 DO (mp_expt_n (& a , 10uL , & a ));
15331522 DO (mp_add_d (& a , max_base / 2 , & a ));
@@ -1546,6 +1535,12 @@ static int test_mp_log(void)
15461535 mp_int a , base , bn , t ;
15471536 int lb , lb2 , i , j ;
15481537
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+
15491544 DOR (mp_init_multi (& a , & base , & bn , & t , NULL ));
15501545
15511546 /*
@@ -2461,8 +2456,6 @@ static int unit_tests(int argc, char **argv)
24612456 T1 (mp_get_u32 , MP_GET_I32 ),
24622457 T1 (mp_get_u64 , MP_GET_I64 ),
24632458 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 ),
24662459 T1 (mp_log_n , MP_LOG_N ),
24672460 T1 (mp_log , MP_LOG ),
24682461 T1 (mp_incr , MP_ADD_D ),
0 commit comments