Remove building with NOCRYPTO option
[minix.git] / crypto / external / bsd / heimdal / dist / lib / hcrypto / libtommath / etc / mont.c
blobbd8ccfdbcd7eef3ee55772341bc77d84ddfaa1b3
1 /* $NetBSD: mont.c,v 1.1.1.2 2014/04/24 12:45:39 pettai Exp $ */
3 /* tests the montgomery routines */
4 #include <tommath.h>
6 int main(void)
8 mp_int modulus, R, p, pp;
9 mp_digit mp;
10 long x, y;
12 srand(time(NULL));
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 */
20 mp_rand(&modulus, x);
21 modulus.dp[0] |= 1;
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) {
35 printf("FAILURE!\n");
36 exit(-1);
39 printf("PASSED\n");
42 return 0;
50 /* Source: /cvs/libtom/libtommath/etc/mont.c,v */
51 /* Revision: 1.2 */
52 /* Date: 2005/05/05 14:38:47 */