summaryrefslogtreecommitdiffstats
path: root/libtommath/etc/mont.c
diff options
context:
space:
mode:
authorKevin B Kenny <kennykb@acm.org>2005-01-19 22:41:26 (GMT)
committerKevin B Kenny <kennykb@acm.org>2005-01-19 22:41:26 (GMT)
commitef78ca64ce6ba6a8786f083318fe536f2bd52925 (patch)
tree47f8ad0d7291237c7f9af988c5e05275ed9286ee /libtommath/etc/mont.c
parentb23d942a1e86ddee18c2309afd7fa7e9afa79ef8 (diff)
downloadtcl-ef78ca64ce6ba6a8786f083318fe536f2bd52925.zip
tcl-ef78ca64ce6ba6a8786f083318fe536f2bd52925.tar.gz
tcl-ef78ca64ce6ba6a8786f083318fe536f2bd52925.tar.bz2
Import of libtommath 0.33
Diffstat (limited to 'libtommath/etc/mont.c')
-rw-r--r--libtommath/etc/mont.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/libtommath/etc/mont.c b/libtommath/etc/mont.c
new file mode 100644
index 0000000..dbf1735
--- /dev/null
+++ b/libtommath/etc/mont.c
@@ -0,0 +1,46 @@
+/* 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;
+}
+
+
+
+
+