Mercurial > dropbear
comparison libtommath/etc/mont.c @ 297:79bf1023cf11 agent-client
propagate from branch 'au.asn.ucc.matt.dropbear' (head 0501e6f661b5415eb76f3b312d183c3adfbfb712)
to branch 'au.asn.ucc.matt.dropbear.cli-agent' (head 01038174ec27245b51bd43a66c01ad930880f67b)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 21 Mar 2006 16:20:59 +0000 |
parents | eed26cff980b |
children | 5ff8218bcee9 |
comparison
equal
deleted
inserted
replaced
225:ca7e76d981d9 | 297:79bf1023cf11 |
---|---|
1 /* tests the montgomery routines */ | |
2 #include <tommath.h> | |
3 | |
4 int main(void) | |
5 { | |
6 mp_int modulus, R, p, pp; | |
7 mp_digit mp; | |
8 long x, y; | |
9 | |
10 srand(time(NULL)); | |
11 mp_init_multi(&modulus, &R, &p, &pp, NULL); | |
12 | |
13 /* loop through various sizes */ | |
14 for (x = 4; x < 256; x++) { | |
15 printf("DIGITS == %3ld...", x); fflush(stdout); | |
16 | |
17 /* make up the odd modulus */ | |
18 mp_rand(&modulus, x); | |
19 modulus.dp[0] |= 1; | |
20 | |
21 /* now find the R value */ | |
22 mp_montgomery_calc_normalization(&R, &modulus); | |
23 mp_montgomery_setup(&modulus, &mp); | |
24 | |
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); | |
30 | |
31 /* should be equal to p */ | |
32 if (mp_cmp(&pp, &p) != MP_EQ) { | |
33 printf("FAILURE!\n"); | |
34 exit(-1); | |
35 } | |
36 } | |
37 printf("PASSED\n"); | |
38 } | |
39 | |
40 return 0; | |
41 } | |
42 | |
43 | |
44 | |
45 | |
46 |