@@ -1230,7 +1230,6 @@ static int test_mp_radix_size(void) {
1230
1230
mp_init (& a );
1231
1231
1232
1232
mp_read_radix (& a , rand_a ,64 );
1233
-
1234
1233
for (i = 2 ; i < 65 ; i ++ ) {
1235
1234
mp_radix_size (& a ,i ,& len );
1236
1235
if (len < length_rand [i ]) {
@@ -1252,25 +1251,39 @@ static int test_mp_radix_size(void) {
1252
1251
return EXIT_FAILURE ;
1253
1252
}
1254
1253
1255
- #if ( (defined LTM_USE_FASTER_VERSIONS ) || (defined LTM_USE_FASTER_NTH_ROOT ))
1254
+ #if ( (defined LTM_USE_FASTER_VERSIONS ) || (defined LTM_USE_FASTER_NTH_ROOT ) )
1256
1255
static int test_mp_n_root (void ) {
1257
1256
mp_int a , tmp , root ;
1258
1257
mp_digit b ;
1259
1258
1260
1259
mp_init_multi (& a , & tmp , & root , NULL );
1261
- /* a = 12345^{255} + 12345^{222} + 12345^{123} + 1 */
1260
+
1261
+ #ifdef MP_8BIT
1262
+ /* a bit smaller, MP_MASK = 127 for MP_8BIT */
1263
+ mp_set_int (& a , 12345ul );
1264
+ mp_expt_d (& a , 126u , & tmp );
1265
+ mp_expt_d (& a , 126u , & root );
1266
+ mp_mul (& tmp , & root , & tmp );
1267
+ mp_mul (& a , & tmp , & tmp );
1268
+ mp_expt_d (& a , (mp_digit )123u , & root );
1269
+ mp_add (& tmp , & root , & a );
1270
+ mp_add_d (& a , 1u , & a );
1271
+ #else
1272
+ /* a = 12345^{255} + 12345^{222} + 12345^{123} + 1, 3465 bits */
1262
1273
mp_set_int (& a , 12345ul );
1263
1274
mp_expt_d (& a , (mp_digit )255u , & tmp );
1264
1275
mp_expt_d (& a , (mp_digit )222u , & root );
1265
1276
mp_add (& tmp , & root , & tmp );
1266
1277
mp_expt_d (& a , (mp_digit )123u , & root );
1267
1278
mp_add (& tmp , & root , & a );
1268
1279
mp_add_d (& a , 1u , & a );
1280
+ #endif
1269
1281
1270
- #if (defined MP_8BIT )
1271
- for (b = 2u ; b < 255u , b ++ ) {
1282
+ #ifdef MP_8BIT
1283
+ for (b = 2u ; b < MP_MASK ; b ++ ) {
1272
1284
#else
1273
1285
for (b = 2u ; b < 3466u ; b ++ ) {
1286
+ #endif
1274
1287
printf ("Testing nth-root, large input with index %5u \r" ,(unsigned )b );
1275
1288
fflush (stdout );
1276
1289
mp_n_root (& a , b , & root );
@@ -1286,8 +1299,6 @@ static int test_mp_n_root(void) {
1286
1299
goto LBL_ERR ;
1287
1300
}
1288
1301
}
1289
- #endif
1290
-
1291
1302
mp_clear_multi (& a , & tmp , & root , NULL );
1292
1303
return EXIT_SUCCESS ;
1293
1304
LBL_ERR :
@@ -1300,13 +1311,16 @@ static int test_mp_n_root(void) {
1300
1311
mp_digit b ;
1301
1312
1302
1313
mp_init_multi (& a , & tmp , & root , NULL );
1303
- /* a = 123^{123}} + 1 */
1314
+ /* a = 123^{123}} + 1, 853 bits */
1304
1315
mp_set_int (& a , 123ul );
1305
1316
mp_expt_d (& a , (mp_digit )123u , & a );
1306
1317
mp_add_d (& a , 1u , & a );
1307
-
1308
- /* even 21 is much! */
1309
- for (b = 2u ; b < 21u ; b ++ ) {
1318
+ /* MP_8BIT is really slow here! */
1319
+ #ifdef MP_8BIT
1320
+ for (b = 2u ; b < 10u ; b ++ ) {
1321
+ #else
1322
+ for (b = 2u ; b < 834u ; b ++ ) {
1323
+ #endif
1310
1324
printf ("Testing nth-root, small input with index %2u \r" ,(unsigned )b );
1311
1325
fflush (stdout );
1312
1326
mp_n_root (& a , b , & root );
@@ -1363,7 +1377,7 @@ int unit_tests(void) {
1363
1377
T (mp_tc_or ),
1364
1378
T (mp_tc_xor ),
1365
1379
T (mp_radix_size ),
1366
- T (mp_n_root ),
1380
+ T (mp_n_root )
1367
1381
#undef T
1368
1382
};
1369
1383
unsigned long i ;
0 commit comments