1 /* $NetBSD: mont.c,v 1.1.1.2 2014/04/24 12:45:39 pettai Exp $ */
3 /* 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 == %3ld...", x
); fflush(stdout
);
19 /* make up the odd modulus */
23 /* now find the R value */
24 mp_montgomery_calc_normalization(&R
, &modulus
);
25 mp_montgomery_setup(&modulus
, &mp
);
27 /* now run through a bunch tests */
28 for (y
= 0; y
< 1000; y
++) {
29 mp_rand(&p
, x
/2); /* p = random */
30 mp_mul(&p
, &R
, &pp
); /* pp = R * p */
31 mp_montgomery_reduce(&pp
, &modulus
, mp
);
33 /* should be equal to p */
34 if (mp_cmp(&pp
, &p
) != MP_EQ
) {
50 /* Source: /cvs/libtom/libtommath/etc/mont.c,v */
52 /* Date: 2005/05/05 14:38:47 */