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 6: Output functions
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>
16 #include "mpi.h"
18 void print_buf(FILE *ofp, char *buf, int len)
19 {
20 int ix, brk = 0;
22 for(ix = 0; ix < len; ix++) {
23 fprintf(ofp, "%02X ", buf[ix]);
25 brk = (brk + 1) & 0xF;
26 if(!brk)
27 fputc('\n', ofp);
28 }
30 if(brk)
31 fputc('\n', ofp);
33 }
35 int main(int argc, char *argv[])
36 {
37 int ix, size;
38 mp_int a;
39 char *buf;
41 if(argc < 2) {
42 fprintf(stderr, "Usage: %s <a>\n", argv[0]);
43 return 1;
44 }
46 printf("Test 6: Output functions\n\n");
48 mp_init(&a);
50 mp_read_radix(&a, argv[1], 10);
52 printf("\nConverting to a string:\n");
54 printf("Rx Size Representation\n");
55 for(ix = 2; ix <= MAX_RADIX; ix++) {
56 size = mp_radix_size(&a, ix);
58 buf = calloc(size, sizeof(char));
59 mp_toradix(&a, buf, ix);
60 printf("%2d: %3d: %s\n", ix, size, buf);
61 free(buf);
63 }
65 printf("\nRaw output:\n");
66 size = mp_raw_size(&a);
67 buf = calloc(size, sizeof(char));
69 printf("Size: %d bytes\n", size);
71 mp_toraw(&a, buf);
72 print_buf(stdout, buf, size);
73 free(buf);
75 mp_clear(&a);
77 return 0;
78 }