Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /*
2 * Simple test driver for MPI library
3 *
4 * Test 8: Probabilistic primality tester
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <ctype.h>
14 #include <limits.h>
15 #include <time.h>
17 #define MP_IOFUNC 1
18 #include "mpi.h"
20 #include "mpprime.h"
22 int main(int argc, char *argv[])
23 {
24 int ix;
25 mp_digit num;
26 mp_int a;
28 srand(time(NULL));
30 if(argc < 2) {
31 fprintf(stderr, "Usage: %s <a>\n", argv[0]);
32 return 1;
33 }
35 printf("Test 8: Probabilistic primality testing\n\n");
37 mp_init(&a);
39 mp_read_radix(&a, argv[1], 10);
41 printf("a = "); mp_print(&a, stdout); fputc('\n', stdout);
43 printf("\nChecking for divisibility by small primes ... \n");
44 num = 170;
45 if(mpp_divis_primes(&a, &num) == MP_YES) {
46 printf("it is not prime\n");
47 goto CLEANUP;
48 }
49 printf("Passed that test (not divisible by any small primes).\n");
51 for(ix = 0; ix < 10; ix++) {
52 printf("\nPerforming Rabin-Miller test, iteration %d\n", ix + 1);
54 if(mpp_pprime(&a, 5) == MP_NO) {
55 printf("it is not prime\n");
56 goto CLEANUP;
57 }
58 }
59 printf("All tests passed; a is probably prime\n");
61 CLEANUP:
62 mp_clear(&a);
64 return 0;
65 }