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