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