1 #include "cado.h" // IWYU pragma: keep
2 #include <stdint.h> /* AIX wants it first (it's a bug) */
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <limits.h>
6 #include <gmp.h>
7 #include <time.h>
8 #include "tests_common.h"
9 #include ARITHMETIC
10 #include "macros.h"
11 #include "misc.h"
12
13
14 /* Mask the (possibly multi-word) integer m so that only the
15 low maxbits can be non-zero */
16
17 static void
limit_integer(modint_t m,const int maxbits)18 limit_integer (modint_t m, const int maxbits)
19 {
20 int i, j;
21 for (i = 0, j = maxbits; i < MOD_SIZE; i++)
22 {
23 if (j < LONG_BIT)
24 {
25 m[i] &= (1UL << j) - 1UL;
26 j = 0;
27 }
28 else
29 j -= LONG_BIT;
30 }
31 }
32
33
34 static void
limit_modulus(modint_t m)35 limit_modulus (modint_t m)
36 {
37 limit_integer (m, MOD_MAXBITS);
38 }
39
40
41 static void
random_modulus(modint_t m)42 random_modulus (modint_t m)
43 {
44 int i;
45
46 #ifdef MOD_MINBITS
47 modint_t minmod;
48
49 mod_intinit (minmod);
50 mod_intset_ul (minmod, 1);
51 mod_intshl (minmod, minmod, MOD_MINBITS);
52 do {
53 #endif
54
55 mod_intset_ul (m, 0UL);
56 for (i = 0; i < MOD_SIZE; i++)
57 {
58 m[i] = u64_random(state);
59 }
60 m[0] |= 1UL;
61
62 limit_modulus (m);
63
64 #ifdef MOD_MINBITS
65 } while (mod_intcmp (m, minmod) < 0);
66 mod_intclear (minmod);
67 #endif
68
69
70 #if 0
71 printf ("Random modulus is ");
72 for (i = MOD_SIZE - 1; i >= 0; i--)
73 printf ("%lx%s", m[i], (i>0) ? ":" : "\n");
74 #endif
75 }
76
77
78 static void
random_integer(modint_t z)79 random_integer (modint_t z)
80 {
81 int i;
82
83 for (i = 0; i < MOD_SIZE; i++)
84 {
85 z[i] = (unsigned long) rand () +
86 (RAND_MAX + 1UL) * (unsigned long) rand ();
87 }
88 }
89
90
91 static void
mpz_set_modint(mpz_t r,const modint_t s)92 mpz_set_modint (mpz_t r, const modint_t s)
93 {
94 mpz_import (r, MOD_SIZE, -1, sizeof (unsigned long), 0, 0, s);
95 }
96
97
98 static inline void
mod_intset_mpz(modint_t r,const mpz_t s)99 mod_intset_mpz (modint_t r, const mpz_t s)
100 {
101 unsigned long t[MOD_SIZE];
102 size_t written;
103 mpz_export (t, &written, -1, sizeof(unsigned long), 0, 0, s);
104 ASSERT_ALWAYS(written <= MOD_SIZE);
105 mod_intset_uls(r, t, written);
106 }
107
108 static void
test_mod_intmod(const modint_t la,const modint_t lm)109 test_mod_intmod (const modint_t la, const modint_t lm)
110 {
111 modint_t s;
112 mpz_t mm, ma, mr, ms;
113
114 mod_intinit (s);
115 mod_intmod (s, la, lm);
116
117 mpz_init (mm);
118 mpz_init (ma);
119 mpz_init (mr);
120 mpz_init (ms);
121
122 mpz_set_modint (mm, lm);
123 mpz_set_modint (ma, la);
124 mpz_mod (mr, ma, mm);
125 mpz_set_modint (ms, s);
126
127 if (mpz_cmp (mr, ms) != 0)
128 {
129 gmp_printf ("mod_intmod(%Zd, %Zd) wrong (%Zd), GMP has %Zd\n",
130 ma, mm, ms, mr);
131 abort ();
132 }
133
134 mpz_clear (mm);
135 mpz_clear (ma);
136 mpz_clear (mr);
137 mpz_clear (ms);
138 mod_intclear (s);
139 }
140
141 void
tests_mod_intmod(int iter)142 tests_mod_intmod (int iter)
143 {
144 modint_t tm, tr;
145 int i, j;
146
147 mod_intinit (tm);
148 mod_intinit (tr);
149 /* Test large moduli */
150 for (i = 0; i < MOD_SIZE; i++)
151 tm[i] = ULONG_MAX;
152
153 for (i = 1; i < iter; i++) /* Test i/2 and (m-i)/2 for i=0, ..., 99 */
154 {
155 mod_intset_ul (tr, (unsigned long) i);
156 test_mod_intmod (tr, tm);
157 mod_intset (tr, tm);
158 tr[0] -= i;
159 test_mod_intmod (tr, tm);
160 }
161
162 /* Test random moduli of different size */
163 for (i = 2; i < MOD_MAXBITS; i++)
164 {
165 do {
166 random_integer (tm);
167 limit_integer (tm, i);
168 } while (mod_intcmp_ul (tm, 0UL) == 0);
169
170 /* Test random integers of different size */
171 for (j = 1; j < MOD_MAXBITS; j++)
172 {
173 random_integer (tr);
174 limit_integer (tr, j);
175 test_mod_intmod (tr, tm);
176 }
177 }
178 mod_intclear (tm);
179 mod_intclear (tr);
180 }
181
182
183 static void
test_mod_set_int(const modint_t la,const modint_t lm)184 test_mod_set_int(const modint_t la, const modint_t lm)
185 {
186 modulus_t m;
187 residue_t r;
188 modint_t s;
189 mpz_t mm, ma, mr, ms;
190
191 mod_intinit (s);
192 mod_initmod_int (m, lm);
193 mod_init (r, m);
194 mod_set_int (r, la, m);
195 mod_get_int (s, r, m);
196
197 mpz_init (mm);
198 mpz_init (ma);
199 mpz_init (mr);
200 mpz_init (ms);
201 mpz_set_modint (mm, lm);
202 mpz_set_modint (ma, la);
203 mpz_mod (mr, ma, mm);
204 mpz_set_modint (ms, s);
205
206 if (mpz_cmp (mr, ms) != 0)
207 {
208 gmp_printf ("mod_set(%Zd, %Zd) wrong (%Zd), GMP has %Zd\n",
209 ma, mm, ms, mr);
210 abort ();
211 }
212 mpz_clear (mm);
213 mpz_clear (ma);
214 mpz_clear (mr);
215 mpz_clear (ms);
216 mod_clear (r, m);
217 mod_clearmod (m);
218 mod_intclear (s);
219 }
220
221
222 void
tests_mod_set_int(int iter)223 tests_mod_set_int(int iter)
224 {
225 modint_t tm, tr;
226 int i, j;
227
228 mod_intinit (tm);
229 mod_intinit (tr);
230 /* Test large moduli */
231 for (i = 0; i < MOD_SIZE; i++)
232 tm[i] = ULONG_MAX;
233 limit_modulus (tm);
234
235 for (i = 1; i < 100; i++) /* Test i/2 and (m-i)/2 for i=0, ..., 99 */
236 {
237 mod_intset_ul (tr, (unsigned long) i);
238 test_mod_set_int (tr, tm);
239 mod_intset (tr, tm);
240 tr[0] -= i;
241 test_mod_set_int (tr, tm);
242 }
243
244 for (i = 0; i < iter; i++)
245 {
246 random_modulus (tm);
247
248 /* Test 0, 1 and -1 residue */
249 mod_intset_ul (tr, 0UL);
250 test_mod_set_int (tr, tm);
251 mod_intset_ul (tr, 1UL);
252 test_mod_set_int (tr, tm);
253 mod_intset (tr, tm);
254 tr[0]--;
255 test_mod_set_int (tr, tm);
256
257 /* Test 10 random residues */
258 for (j = 0; j < 10; j++)
259 {
260 random_integer (tr);
261 test_mod_set_int (tr, tm);
262 }
263 }
264 mod_intclear (tm);
265 mod_intclear (tr);
266 }
267
268
269 static void
test_mod_divn(const modint_t la,const modint_t lm,const unsigned long n)270 test_mod_divn(const modint_t la, const modint_t lm, const unsigned long n)
271 {
272 modulus_t m;
273 residue_t r, s, t;
274
275 mod_initmod_int (m, lm);
276 mod_init (r, m);
277 mod_init (s, m);
278 mod_init (t, m);
279 mod_set_int (r, la, m);
280 if (n == 2UL)
281 mod_div2 (s, r, m); /* s = r/n */
282 else if (n == 3UL)
283 mod_div3 (s, r, m);
284 else if (n == 5UL)
285 mod_div5 (s, r, m);
286 else if (n == 7UL)
287 mod_div7 (s, r, m);
288 else if (n == 11UL)
289 mod_div11 (s, r, m);
290 else if (n == 13UL)
291 mod_div13 (s, r, m);
292
293 mod_set_ul (t, n, m);
294 mod_mul (t, t, s, m); /* t = s*n = r */
295
296 if (!mod_equal (r, t, m))
297 {
298 printf ("mod_div%lu(%lu, %lu) wrong\n",
299 n, la[0], lm[0]);
300 abort ();
301 }
302 mod_clear (r, m);
303 mod_clear (s, m);
304 mod_clearmod (m);
305 }
306
307
308 void
tests_mod_divn(const int iter,const unsigned long n)309 tests_mod_divn(const int iter, const unsigned long n)
310 {
311 modint_t tm, tr;
312 int i, j;
313 mpz_t mod;
314
315 mod_intinit (tm);
316 mod_intinit (tr);
317 mpz_init (mod);
318
319 /* Test large moduli */
320 for (i = 0; i < MOD_SIZE; i++)
321 tm[i] = ULONG_MAX;
322 limit_modulus (tm);
323 mpz_set_modint (mod, tm);
324 while (mpz_divisible_ui_p (mod, n))
325 {
326 tm[0] = ULONG_MAX - 2UL;
327 mpz_set_modint (mod, tm);
328 }
329
330 for (i = 0; i < 100; i++) /* Test i/n and (m-i)/n for i=0, ..., 99 */
331 {
332 mod_intset_ul (tr, (unsigned long) i);
333 test_mod_divn (tr, tm, n);
334 mod_intset (tr, tm);
335 tr[0] -= i;
336 test_mod_divn (tr, tm, n);
337 }
338
339 for (i = 0; i < iter; i++)
340 {
341 do {
342 random_modulus (tm);
343 mpz_set_modint (mod, tm);
344 } while (mpz_divisible_ui_p (mod, n));
345
346 /* Test 0, 1 and -1 residue */
347 mod_intset_ul (tr, 0UL);
348 test_mod_divn (tr, tm, n);
349 mod_intset_ul (tr, 1UL);
350 test_mod_divn (tr, tm, n);
351 mod_intset (tr, tm);
352 tr[0]--;
353 test_mod_divn (tr, tm, n);
354
355 /* Test 10 random residues */
356 for (j = 0; j < 10; j++)
357 {
358 random_integer (tr);
359 test_mod_divn (tr, tm, n);
360 }
361 }
362 mod_intclear (tm);
363 mod_intclear (tr);
364 mpz_clear (mod);
365 }
366
367
368 static void
test_mod_gcd(const modint_t la,const modint_t lm)369 test_mod_gcd (const modint_t la, const modint_t lm)
370 {
371 modulus_t m;
372 residue_t a;
373 modint_t lt;
374 mpz_t mt, ma, mr, mm;
375
376 mod_intinit (lt);
377 mod_initmod_int (m, lm);
378 mod_init (a, m);
379 mod_set_int (a, la, m);
380
381 mod_gcd (lt, a, m);
382
383 mpz_init (ma);
384 mpz_init (mr);
385 mpz_init (mm);
386 mpz_init (mt);
387 mpz_set_modint (mm, lm); /* modulus */
388 mpz_set_modint (ma, la); /* input */
389 mpz_set_modint (mt, lt); /* gcd */
390 mpz_gcd (mr, ma, mm); /* re-compute gcd */
391 if (mpz_cmp (mr, mt) != 0)
392 {
393 gmp_printf ("mod_gcd(%Zd, %Zd) wrong (%Zd), GMP has %Zd\n",
394 ma, mm, mt, mr);
395 abort ();
396 }
397 mpz_clear (mt);
398 mpz_clear (mm);
399 mpz_clear (mr);
400 mpz_clear (ma);
401
402 mod_clear (a, m);
403 mod_clearmod (m);
404 mod_intclear (lt);
405 }
406
407
408 void
tests_mod_gcd(int iter)409 tests_mod_gcd (int iter)
410 {
411 modint_t tm, tr;
412 int i, j;
413
414 mod_intinit (tm);
415 mod_intinit (tr);
416 for (i = 0; i < iter; i++)
417 {
418 random_modulus (tm);
419
420 /* Test 0, 1 and -1 residue */
421 mod_intset_ul (tr, 0UL);
422 test_mod_gcd (tr, tm);
423 mod_intset_ul (tr, 1UL);
424 test_mod_gcd (tr, tm);
425 mod_intset (tr, tm);
426 tr[0]--;
427 test_mod_gcd (tr, tm);
428
429 /* Test 10 random residues */
430 for (j = 0; j < 10; j++)
431 {
432 random_integer (tr);
433 test_mod_gcd (tr, tm);
434 }
435 }
436 mod_intclear (tm);
437 mod_intclear (tr);
438 }
439
440
441 static void
test_mod_pow_ul(const modint_t la,const modint_t lm,const unsigned long e)442 test_mod_pow_ul (const modint_t la, const modint_t lm,
443 const unsigned long e)
444 {
445 modulus_t m;
446 residue_t a, r;
447 modint_t lt;
448 mpz_t mt, ma, mr, mm;
449
450 mod_intinit (lt);
451 mod_initmod_int (m, lm);
452 mod_init (a, m);
453 mod_set_int (a, la, m);
454 mod_init (r, m);
455
456 mod_pow_ul (r, a, e, m); /* s = a^e % m */
457 mod_get_int (lt, r, m); /* result as integer in t */
458
459 mpz_init (mm);
460 mpz_init (ma);
461 mpz_init (mr);
462 mpz_init (mt);
463 mpz_set_modint (mm, lm); /* modulus */
464 mpz_set_modint (ma, la); /* input */
465 mpz_set_modint (mt, lt); /* result of modul function */
466
467 mpz_powm_ui (mr, ma, e, mm);
468 if (mpz_cmp (mr, mt) != 0)
469 {
470 gmp_printf ("mod_pow_ui(%Zd, %lu, %Zd) wrong (%Zd)\n",
471 ma, e, mm, mt);
472 abort ();
473 }
474 mpz_clear (mt);
475 mpz_clear (mr);
476 mpz_clear (ma);
477 mpz_clear (mm);
478
479 mod_clear (a, m);
480 mod_clear (r, m);
481 mod_clearmod (m);
482 mod_intclear (lt);
483 }
484
485
486 void
tests_mod_pow_ul(int iter)487 tests_mod_pow_ul (int iter)
488 {
489 modint_t tm, tr;
490 unsigned long e;
491 int i, j;
492
493 for (i = 0; i < iter; i++)
494 {
495 random_modulus (tm);
496 e = (unsigned long) rand ();
497
498 /* Test 0, 1 and -1 residue */
499 mod_intset_ul (tr, 0UL);
500 test_mod_pow_ul (tr, tm, e);
501 mod_intset_ul (tr, 1UL);
502 test_mod_pow_ul (tr, tm, e);
503 mod_intset (tr, tm);
504 tr[0]--;
505 test_mod_pow_ul (tr, tm, e);
506
507 /* Test 10 random residues */
508 for (j = 0; j < 10; j++)
509 {
510 random_integer (tr);
511 test_mod_pow_ul (tr, tm, e);
512 }
513 }
514 }
515
516
517 static void
test_mod_2pow_ul(const modint_t lm,const unsigned long e)518 test_mod_2pow_ul (const modint_t lm, const unsigned long e)
519 {
520 modulus_t m;
521 residue_t r;
522 modint_t lt;
523 mpz_t mt, mr, mm, m2;
524
525 mod_intinit (lt);
526 mod_initmod_int (m, lm);
527 mod_init (r, m);
528
529 mod_2pow_ul (r, e, m); /* s = 2^e % m */
530 mod_get_int (lt, r, m); /* result as integer in t */
531
532 mpz_init (mm);
533 mpz_init (mr);
534 mpz_init (mt);
535 mpz_init (m2);
536 mpz_set_modint (mm, lm); /* modulus */
537 mpz_set_ui (m2, 2UL);
538 mpz_set_modint (mt, lt); /* result of mod_2pow_ul() */
539
540 mpz_powm_ui (mr, m2, e, mm);
541 if (mpz_cmp (mr, mt) != 0)
542 {
543 gmp_printf ("mod_pow_ui(2, %lu, %Zd) wrong (%Zd)\n",
544 e, mm, mt);
545 abort ();
546 }
547 mpz_clear (mt);
548 mpz_clear (mr);
549 mpz_clear (m2);
550 mpz_clear (mm);
551
552 mod_clear (r, m);
553 mod_clearmod (m);
554 mod_intclear (lt);
555 }
556
557
558 void
tests_mod_2pow_ul(int iter)559 tests_mod_2pow_ul (int iter)
560 {
561 modint_t tm;
562 unsigned long e;
563 int i;
564
565 mod_intinit (tm);
566 for (i = 0; i < iter; i++)
567 {
568 random_modulus (tm);
569 test_mod_2pow_ul (tm, 0UL);
570 test_mod_2pow_ul (tm, 1UL);
571 test_mod_2pow_ul (tm, 2UL);
572 test_mod_2pow_ul (tm, 3UL);
573 test_mod_2pow_ul (tm, 4UL);
574 test_mod_2pow_ul (tm, ~0UL);
575 e = (unsigned long) rand ();
576 test_mod_2pow_ul (tm, e);
577 }
578 mod_intclear (tm);
579 }
580
581
582 static void
test_mod_inv(const modint_t la,const modint_t lm)583 test_mod_inv (const modint_t la, const modint_t lm)
584 {
585 modulus_t m;
586 residue_t a, r;
587 modint_t lt;
588 mpz_t mr, ma, mm, mt;
589 int ok1, ok2;
590
591 mod_intinit (lt);
592 mod_initmod_int (m, lm);
593 mod_init (a, m);
594 mod_set_int (a, la, m);
595 mod_init (r, m);
596
597 ok1 = mod_inv (r, a, m) ? 1 : 0; /* r = 1/a (mod lm) */
598 mod_get_int (lt, r, m);
599
600 mpz_init (ma);
601 mpz_init (mr);
602 mpz_init (mm);
603 mpz_init (mt);
604 mpz_set_modint (ma, la);
605 mpz_set_modint (mm, lm);
606 mpz_set_modint (mt, lt);
607 ok2 = mpz_invert (mr, ma, mm) ? 1 : 0;
608
609 if (ok1 != ok2)
610 {
611 gmp_printf ("mod_inv(%Zd, %Zd) wrong, return code %d, GMP has code %d\n",
612 ma, mm, ok1, ok2);
613 abort ();
614 }
615 else if (ok1 == 1)
616 {
617 if (mpz_cmp (mt, mr) != 0)
618 {
619 gmp_printf ("mod_inv(%Zd, %Zd) wrong (%Zd), GMP has %Zd\n",
620 ma, mm, mt, mr);
621 abort ();
622 }
623 }
624
625 mpz_clear (mr);
626 mpz_clear (ma);
627 mpz_clear (mm);
628 mpz_clear (mt);
629
630 mod_clear (a, m);
631 mod_clear (r, m);
632 mod_clearmod (m);
633 mod_intclear (lt);
634 }
635
636
637 void
tests_mod_inv(int iter)638 tests_mod_inv (int iter)
639 {
640 modint_t tm, tr;
641 int i, j;
642
643 mod_intinit (tm);
644 mod_intinit (tr);
645 for (i = 0; i < iter; i++)
646 {
647 random_modulus (tm);
648
649 /* Test 0, 1 and -1 residue */
650 mod_intset_ul (tr, 0UL);
651 test_mod_inv (tr, tm);
652 mod_intset_ul (tr, 1UL);
653 test_mod_inv (tr, tm);
654 mod_intset (tr, tm);
655 tr[0]--;
656 test_mod_inv (tr, tm);
657
658 /* Test 10 random residues */
659 for (j = 0; j < 10; j++)
660 {
661 random_integer (tr);
662 test_mod_inv (tr, tm);
663 }
664 }
665 mod_intclear (tm);
666 mod_intclear (tr);
667 }
668
669
670 static void
test_mod_jacobi(const modint_t la,const modint_t lm)671 test_mod_jacobi (const modint_t la, const modint_t lm)
672 {
673 modulus_t m;
674 residue_t a;
675 mpz_t ma, mm;
676 int j1, j2;
677
678 mod_initmod_int (m, lm);
679 mod_init (a, m);
680 mod_set_int (a, la, m);
681
682 j1 = mod_jacobi (a, m);
683
684 mpz_init (ma);
685 mpz_init (mm);
686 mpz_set_modint (ma, la);
687 mpz_set_modint (mm, lm);
688 j2 = mpz_jacobi (ma, mm);
689
690 if (j1 != j2)
691 {
692 gmp_printf ("mod_jacobi(%Zd, %Zd) wrong (%d), GMP has %d\n",
693 ma, mm, j1, j2);
694 abort ();
695 }
696
697 mpz_clear (ma);
698 mpz_clear (mm);
699
700 mod_clear (a, m);
701 mod_clearmod (m);
702 }
703
704
705 void
tests_mod_jacobi(int iter)706 tests_mod_jacobi (int iter)
707 {
708 modint_t tm, tr;
709 int i, j;
710
711 mod_intinit (tm);
712 mod_intinit (tr);
713 for (i = 0; i < iter; i++)
714 {
715 random_modulus (tm);
716
717 /* Test 0, 1 and -1 residue */
718 mod_intset_ul (tr, 0UL);
719 test_mod_jacobi (tr, tm);
720 mod_intset_ul (tr, 1UL);
721 test_mod_jacobi (tr, tm);
722 mod_intset (tr, tm);
723 tr[0]--;
724 test_mod_jacobi (tr, tm);
725
726 /* Test 10 random residues */
727 for (j = 0; j < 10; j++)
728 {
729 random_integer (tr);
730 test_mod_jacobi (tr, tm);
731 }
732 }
733 mod_intclear (tm);
734 mod_intclear (tr);
735 }
736
737 #if MOD_MINBITS <= 65 && MOD_MAXBITS >= 65 && LONG_BIT == 64
test_sprp(const mpz_t n,const int is_prime)738 void test_sprp(const mpz_t n, const int is_prime)
739 {
740 const char *prime_str[2] = {"composite", "prime"};
741 modint_t ni;
742 modulus_t m;
743
744 mod_intinit(ni);
745 mod_intset_mpz(ni, n);
746 mod_initmod_int(m, ni);
747 mod_intclear(ni);
748
749 if (mod_sprp2(m) != is_prime) {
750 gmp_fprintf (stderr, "%Zd incorrectly declared %s by mod_sprp2()\n",
751 n, prime_str[!is_prime]);
752 abort();
753 }
754
755 for (unsigned long b = 2; b < 10; b++) {
756 residue_t r;
757 mod_init(r, m);
758 mod_set_ul(r, b, m);
759 if (mod_sprp(r, m) != is_prime) {
760 gmp_fprintf (stderr, "%Zd incorrectly declared %s by mod_sprp(%lu)\n",
761 n, prime_str[!is_prime], b);
762 abort();
763 }
764 mod_clear(r, m);
765 }
766 mod_clearmod(m);
767 }
768 #endif
769
tests_sprp()770 void tests_sprp()
771 {
772 #if MOD_MINBITS <= 65 && MOD_MAXBITS >= 65 && LONG_BIT == 64
773 mpz_t n;
774 mpz_init(n);
775 mpz_set_str(n, "22626675434590779179", 10); /* a prime */
776 test_sprp(n, 1);
777 mpz_set_str(n, "22626675434590779197", 10); /* a composite */
778 test_sprp(n, 0);
779 mpz_clear(n);
780 #endif
781 }
782
783
784 // coverity[root_function]
main(int argc,const char ** argv)785 int main(int argc, const char **argv)
786 {
787 unsigned long iter = 10000;
788
789 tests_common_cmdline(&argc, &argv, PARSE_SEED | PARSE_ITER);
790 tests_common_get_iter(&iter);
791
792 printf ("Testing mod_intmod()\n");
793 tests_mod_intmod (iter);
794 printf ("Testing mod_set_int()\n");
795 tests_mod_set_int (iter);
796 printf ("Testing mod_div2()\n");
797 tests_mod_divn (iter, 2);
798 printf ("Testing mod_div3()\n");
799 tests_mod_divn (iter, 3);
800 printf ("Testing mod_div5()\n");
801 tests_mod_divn (iter, 5);
802 printf ("Testing mod_div7()\n");
803 tests_mod_divn (iter, 7);
804 printf ("Testing mod_div11()\n");
805 tests_mod_divn (iter, 11);
806 printf ("Testing mod_div13()\n");
807 tests_mod_divn (iter, 13);
808 printf ("Testing mod_gcd()\n");
809 tests_mod_gcd (iter);
810 printf ("Testing mod_pow_ul()\n");
811 tests_mod_pow_ul (iter);
812 printf ("Testing mod_2pow_ul()\n");
813 tests_mod_2pow_ul (iter);
814 printf ("Testing mod_inv()\n");
815 tests_mod_inv (iter);
816 printf ("Testing mod_jacobi()\n");
817 tests_mod_jacobi (iter);
818 printf ("Testing mod_sprp2()\n");
819 tests_sprp();
820 tests_common_clear();
821 return 0;
822 }
823