-/* tests the montgomery routines */\r
-#include <tommath.h>\r
-\r
-int main(void)\r
-{\r
- mp_int modulus, R, p, pp;\r
- mp_digit mp;\r
- long x, y;\r
-\r
- srand(time(NULL));\r
- mp_init_multi(&modulus, &R, &p, &pp, NULL);\r
-\r
- /* loop through various sizes */\r
- for (x = 4; x < 256; x++) {\r
- printf("DIGITS == %3ld...", x); fflush(stdout);\r
- \r
- /* make up the odd modulus */\r
- mp_rand(&modulus, x);\r
- modulus.dp[0] |= 1;\r
- \r
- /* now find the R value */\r
- mp_montgomery_calc_normalization(&R, &modulus);\r
- mp_montgomery_setup(&modulus, &mp);\r
- \r
- /* now run through a bunch tests */\r
- for (y = 0; y < 1000; y++) {\r
- mp_rand(&p, x/2); /* p = random */\r
- mp_mul(&p, &R, &pp); /* pp = R * p */\r
- mp_montgomery_reduce(&pp, &modulus, mp);\r
- \r
- /* should be equal to p */\r
- if (mp_cmp(&pp, &p) != MP_EQ) {\r
- printf("FAILURE!\n");\r
- exit(-1);\r
- }\r
- }\r
- printf("PASSED\n");\r
- }\r
- \r
- return 0;\r
-}\r
-\r
-\r
-\r
-\r
-\r
+/* tests the montgomery routines */
+#include <tommath.h>
+
+int main(void)
+{
+ mp_int modulus, R, p, pp;
+ mp_digit mp;
+ long x, y;
+
+ srand(time(NULL));
+ mp_init_multi(&modulus, &R, &p, &pp, NULL);
+
+ /* loop through various sizes */
+ for (x = 4; x < 256; x++) {
+ printf("DIGITS == %3ld...", x); fflush(stdout);
+
+ /* make up the odd modulus */
+ mp_rand(&modulus, x);
+ modulus.dp[0] |= 1;
+
+ /* now find the R value */
+ mp_montgomery_calc_normalization(&R, &modulus);
+ mp_montgomery_setup(&modulus, &mp);
+
+ /* now run through a bunch tests */
+ for (y = 0; y < 1000; y++) {
+ mp_rand(&p, x/2); /* p = random */
+ mp_mul(&p, &R, &pp); /* pp = R * p */
+ mp_montgomery_reduce(&pp, &modulus, mp);
+
+ /* should be equal to p */
+ if (mp_cmp(&pp, &p) != MP_EQ) {
+ printf("FAILURE!\n");
+ exit(-1);
+ }
+ }
+ printf("PASSED\n");
+ }
+
+ return 0;
+}
+
+
+
+
+