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 * exptmod.c
3 *
4 * Command line tool to perform modular exponentiation on arbitrary
5 * precision integers.
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
15 #include "mpi.h"
17 int main(int argc, char *argv[])
18 {
19 mp_int a, b, m;
20 mp_err res;
21 char *str;
22 int len, rval = 0;
24 if(argc < 3) {
25 fprintf(stderr, "Usage: %s <a> <b> <m>\n", argv[0]);
26 return 1;
27 }
29 mp_init(&a); mp_init(&b); mp_init(&m);
30 mp_read_radix(&a, argv[1], 10);
31 mp_read_radix(&b, argv[2], 10);
32 mp_read_radix(&m, argv[3], 10);
34 if((res = mp_exptmod(&a, &b, &m, &a)) != MP_OKAY) {
35 fprintf(stderr, "%s: error: %s\n", argv[0], mp_strerror(res));
36 rval = 1;
37 } else {
38 len = mp_radix_size(&a, 10);
39 str = calloc(len, sizeof(char));
40 mp_toradix(&a, str, 10);
42 printf("%s\n", str);
44 free(str);
45 }
47 mp_clear(&a); mp_clear(&b); mp_clear(&m);
49 return rval;
50 }