tree checksum vpatch file split hunks
all signers: diana_coman
antecedents: ch1_mpi
press order:
eucrypt_genesis | diana_coman |
ch1_mpi | diana_coman |
eucrypt_mpi_fix_copy_incr | diana_coman |
patch:
(1 . 5)(1 . 6)- 85384BC9E48590DA125A7440103EBC5549A2C1E10DD2335810C06F6BCA4CA4F22F0626B0F625128F8D73DE47C0A2AA9260F1014EACCCC5CBDB2E37498347E99C
5 /* mpi-internal.h - Internal to the Multi Precision Integers
6 * Modified by No Such Labs. (C) 2015. See README.
7 * Modified by S.MG, 2017: fixing broken MPN_COPY_INCR macro. See EuCrypt patches.
8 *
9 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
10 * SHA256(gnupg-1.4.10.tar.gz):
(100 . 7)(101 . 7)
12 do { \
13 mpi_size_t _i; \
14 for( _i = 0; _i < (n); _i++ ) \
15 (d)[_i] = (d)[_i]; \
16 (d)[_i] = (s)[_i]; \
17 } while (0)
18
19 #define MPN_COPY_DECR( d, s, n ) \
(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