1 /* tests the montgomery routines */
6 mp_int modulus, R, p, pp;
11 mp_init_multi(&modulus, &R, &p, &pp, NULL);
13 /* loop through various sizes */
14 for (x = 4; x < 256; x++) {
15 printf("DIGITS == %3ld...", x); fflush(stdout);
17 /* make up the odd modulus */
21 /* now find the R value */
22 mp_montgomery_calc_normalization(&R, &modulus);
23 mp_montgomery_setup(&modulus, &mp);
25 /* now run through a bunch tests */
26 for (y = 0; y < 1000; y++) {
27 mp_rand(&p, x/2); /* p = random */
28 mp_mul(&p, &R, &pp); /* pp = R * p */
29 mp_montgomery_reduce(&pp, &modulus, mp);
31 /* should be equal to p */
32 if (mp_cmp(&pp, &p) != MP_EQ) {