1 /* makes a bignum test harness with NUM tests per operation
3 * the output is made in the following format [one parameter per line]
13 So for example "a * b mod n" would be
21 e.g. if a=3, b=4 n=11 then
38 void rand_num(mp_int *a)
41 unsigned char buf[2048];
43 size = 1 + ((fgetc(rng)<<8) + fgetc(rng)) % 1031;
44 buf[0] = (fgetc(rng)&1)?1:0;
45 fread(buf+1, 1, size, rng);
46 while (buf[1] == 0) buf[1] = fgetc(rng);
47 mp_read_raw(a, buf, 1+size);
50 void rand_num2(mp_int *a)
53 unsigned char buf[2048];
55 size = 1 + ((fgetc(rng)<<8) + fgetc(rng)) % 97;
56 buf[0] = (fgetc(rng)&1)?1:0;
57 fread(buf+1, 1, size, rng);
58 while (buf[1] == 0) buf[1] = fgetc(rng);
59 mp_read_raw(a, buf, 1+size);
62 #define mp_to64(a, b) mp_toradix(a, b, 64)
78 /* initial (2^n - 1)^2 testing, makes sure the comba multiplier works [it has the new carry code] */
81 for (n = 1; n < 8192; n++) {
85 printf("%s\n%s\n", buf, buf);
95 rng = fopen("/dev/urandom", "rb");
97 rng = fopen("/dev/random", "rb");
99 fprintf(stderr, "\nWarning: stdin used as random source\n\n");
106 if (clock() - t1 > CLOCKS_PER_SEC) {
153 mp_div(&a, &b, &c, &d);
177 mp_mul_2d(&b, n, &b);
189 mp_div_2d(&b, n, &b, NULL);
229 // if (c.dp[0]&1) mp_add_d(&c, 1, &c);
230 a.sign = b.sign = c.sign = 0;
231 mp_exptmod(&a, &b, &c, &d);
241 } else if (n == 10) {
248 if (mp_cmp_d(&c, 1) != 0) continue;
249 if (mp_cmp_d(&b, 1) == 0) continue;
250 mp_invmod(&a, &b, &c);
258 } else if (n == 11) {
267 } else if (n == 12) {