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