- 85384BC9E48590DA125A7440103EBC5549A2C1E10DD2335810C06F6BCA4CA4F22F0626B0F625128F8D73DE47C0A2AA9260F1014EACCCC5CBDB2E37498347E99C
+ 587D20E7235B57076203A9C3B8774F60EAD751978F1A4ED87AE7CC96548A021919E77C0799B8FFF9900A83EDB74E173114BAC8FDDB7FF23FF275472FB0C24603
eucrypt/mpi/tests/test_mpi.c
(1 . 4)(1 . 5)
24 #include "mpi.h"
25 #include "mpi-internal.h" /* for BITS_PER_MPI_LIMB */
26 #include <stdlib.h>
27
28 void err(char *msg)
(12 . 10)(13 . 66)
30 fprintf(fp, "\n");
31 }
32
33 void print_results(MPI in, MPI out, char * title)
34 {
35 fprintf(stdout, "******** %s ********", title);
36 terpri(stdout);
37
38 fprintf(stdout, "input : ");
39 mpi_print(stdout, in, 1);
40 terpri(stdout);
41
42 fprintf(stdout, "output: ");
43 mpi_print(stdout, out, 1);
44 terpri(stdout);
45
46 terpri(stdout);
47 fflush(stdout);
48 }
49
50 /*
51 * Test that will fail on original code and will pass after EuCrypt fix is applied.
52 */
53 void test_rshift()
54 {
55 MPI out, in, copy_in;
56 out = mpi_alloc(0);
57 in = mpi_alloc(0);
58 copy_in = mpi_alloc(0);
59
60 mpi_fromstr(out, "0x20E92FE28E1929"); /* some value */
61 mpi_fromstr(in, "0x2000000010000001000000002");
62 mpi_fromstr(copy_in, "0x2000000010000001000000002"); /* to make sure the actual input is print, since call can modify in */
63
64 /* print value of BITS_PER_MPI_LIMB */
65 fprintf(stdout, "BITS_PER_MPI_LIMB is %d\n", BITS_PER_MPI_LIMB);
66
67 /* shift by 0 */
68 mpi_tdiv_q_2exp(out, in, 0);
69 print_results(copy_in, out, "TEST: right shift by 0");
70
71 /* shift by multiple of BITS_PER_MPI_LIMB */
72 mpi_fromstr(in, "0x2000000010000001000000002");
73
74 mpi_tdiv_q_2exp(out, in, BITS_PER_MPI_LIMB);
75 print_results(copy_in, out, "TEST: right shift by BITS_PER_MPI_LIMB");
76
77 /* shift by non-multiple of BITS_PER_MPI_LIMB */
78 mpi_fromstr(in, "0x2000000010000001000000002");
79 mpi_tdiv_q_2exp(out, in, BITS_PER_MPI_LIMB - 3);
80 print_results(copy_in, out, "TEST: right shift by BITS_PER_MPI_LIMB - 3");
81
82 mpi_free(copy_in);
83 mpi_free(out);
84 mpi_free(in);
85 }
86
87 int main(int ac, char **av)
88 {
89 MPI a, b, y;
90 int r;
91
92 test_rshift();
93
94 r = secmem_init(1000);
95 if (r==0) err("secmem init");
(29 . 6)(86 . 8)
97 mpi_free(a);
98 mpi_free(b);
99
100 fprintf(stdout, "******** TEST: mpi_mul, see README ********");
101 terpri(stdout);
102 mpi_print(stdout, y, 1);
103 mpi_free(y);
104