demo: "improve" a bit allow reproducible testcases add easy switch to compile either a version for "test vs. mtest" or to run internal tests
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
diff --git a/demo/demo.c b/demo/demo.c
index 89bdea3..77b2c44 100644
--- a/demo/demo.c
+++ b/demo/demo.c
@@ -7,6 +7,19 @@
#define SLEEP
#endif
+/*
+ * Configuration
+ */
+#ifndef LTM_DEMO_TEST_VS_MTEST
+#define LTM_DEMO_TEST_VS_MTEST 1
+#endif
+
+#ifdef LTM_DEMO_REAL_RAND
+#define LTM_DEMO_RAND_SEED time(NULL)
+#else
+#define LTM_DEMO_RAND_SEED 23
+#endif
+
#include "tommath.h"
void ndraw(mp_int * a, char *name)
@@ -66,9 +79,9 @@ int main(void)
mp_init(&e);
mp_init(&f);
- srand(time(NULL));
+ srand(LTM_DEMO_RAND_SEED);
-#if 0
+#if LTM_DEMO_TEST_VS_MTEST == 0
// test montgomery
printf("Testing montgomery...\n");
for (i = 1; i < 10; i++) {
@@ -332,11 +345,8 @@ printf("compare no compare!\n"); exit(EXIT_FAILURE); }
printf("Passed DR test for %d digits\n", cnt);
}
-#endif
-
/* test the mp_reduce_2k_l code */
#if 0
-#if 0
/* first load P with 2^1024 - 0x2A434 B9FDEC95 D8F9D550 FFFFFFFF FFFFFFFF */
mp_2expt(&a, 1024);
mp_read_radix(&b, "2A434B9FDEC95D8F9D550FFFFFFFFFFFFFFFF", 16);
@@ -381,7 +391,8 @@ printf("compare no compare!\n"); exit(EXIT_FAILURE); }
}
}
printf("...Passed\n");
-#endif
+
+#else
div2_n = mul2_n = inv_n = expt_n = lcm_n = gcd_n = add_n =
sub_n = mul_n = div_n = sqr_n = mul2d_n = div2d_n = cnt = add_d_n =
@@ -731,6 +742,7 @@ printf("compare no compare!\n"); exit(EXIT_FAILURE); }
}
}
}
+#endif
return 0;
}