#include <tommath.h>
int main(void)
{
mp_int modulus, R, p, pp;
mp_digit mp;
long x, y;
srand(time(NULL));
mp_init_multi(&modulus, &R, &p, &pp, NULL);
for (x = 4; x < 256; x++) {
printf("DIGITS == %3ld...", x); fflush(stdout);
mp_rand(&modulus, x);
modulus.dp[0] |= 1;
mp_montgomery_calc_normalization(&R, &modulus);
mp_montgomery_setup(&modulus, &mp);
for (y = 0; y < 1000; y++) {
mp_rand(&p, x/2);
mp_mul(&p, &R, &pp);
mp_montgomery_reduce(&pp, &modulus, mp);
if (mp_cmp(&pp, &p) != MP_EQ) {
printf("FAILURE!\n");
exit(-1);
}
}
printf("PASSED\n");
}
return 0;
}