Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
czurnieden committed Oct 19, 2019
1 parent 2c35ed9 commit 929ef57
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions demo/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2271,6 +2271,60 @@ static int test_s_mp_toom_sqr(void)
return EXIT_FAILURE;
}

static int test_mp_radix_size(void)
{
mp_err err;
mp_int a;
int radix, size;
/* *INDENT-OFF* */
int results[65] = {
0, 0, 1627, 1027, 814, 702, 630, 581, 543,
514, 491, 471, 455, 441, 428, 418, 408, 399,
391, 384, 378, 372, 366, 361, 356, 352, 347,
343, 340, 336, 333, 330, 327, 324, 321, 318,
316, 314, 311, 309, 307, 305, 303, 301, 299,
298, 296, 294, 293, 291, 290, 288, 287, 285,
284, 283, 281, 280, 279, 278, 277, 276, 275,
273, 272
};
/* *INDENT-ON* */

mp_init(&a);

/* number to result in a different size for every base: 67^(4 * 67) */
mp_set(&a, 67);
if ((err = mp_expt_u32(&a, 268u, &a)) != MP_OKAY) {
goto LTM_ERR;
}

for (radix = 2; radix < 65; radix++) {
if ((err = mp_radix_size(&a, radix, &size)) != MP_OKAY) {
goto LTM_ERR;
}
if (size != results[radix]) {
fprintf(stderr, "mp_radix_size: result for base %d was %d instead of %d\n",
radix, size, results[radix]);
goto LTM_ERR;
}
a.sign = MP_NEG;
if ((err = mp_radix_size(&a, radix, &size)) != MP_OKAY) {
goto LTM_ERR;
}
if (size != (results[radix] + 1)) {
fprintf(stderr, "mp_radix_size: result for base %d was %d instead of %d\n",
radix, size, results[radix]);
goto LTM_ERR;
}
a.sign = MP_ZPOS;
}

mp_clear(&a);
return EXIT_SUCCESS;
LTM_ERR:
mp_clear(&a);
return EXIT_FAILURE;
}

#ifndef BN_S_MP_DIV_SMALL
/* Some larger values to test the fast division algorithm */
static int test_s_mp_div(void)
Expand Down

0 comments on commit 929ef57

Please sign in to comment.