/src/nettle/ecc-gost-gc256b.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /* ecc-gost-gc256b.c  | 
2  |  |  | 
3  |  |    Copyright (C) 2016-2020 Dmitry Eremin-Solenikov  | 
4  |  |  | 
5  |  |    This file is part of GNU Nettle.  | 
6  |  |  | 
7  |  |    GNU Nettle is free software: you can redistribute it and/or  | 
8  |  |    modify it under the terms of either:  | 
9  |  |  | 
10  |  |      * the GNU Lesser General Public License as published by the Free  | 
11  |  |        Software Foundation; either version 3 of the License, or (at your  | 
12  |  |        option) any later version.  | 
13  |  |  | 
14  |  |    or  | 
15  |  |  | 
16  |  |      * the GNU General Public License as published by the Free  | 
17  |  |        Software Foundation; either version 2 of the License, or (at your  | 
18  |  |        option) any later version.  | 
19  |  |  | 
20  |  |    or both in parallel, as here.  | 
21  |  |  | 
22  |  |    GNU Nettle is distributed in the hope that it will be useful,  | 
23  |  |    but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
24  |  |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  | 
25  |  |    General Public License for more details.  | 
26  |  |  | 
27  |  |    You should have received copies of the GNU General Public License and  | 
28  |  |    the GNU Lesser General Public License along with this program.  If  | 
29  |  |    not, see http://www.gnu.org/licenses/.  | 
30  |  | */  | 
31  |  |  | 
32  |  | #if HAVE_CONFIG_H  | 
33  |  | # include "config.h"  | 
34  |  | #endif  | 
35  |  |  | 
36  |  | #include <assert.h>  | 
37  |  |  | 
38  |  | #include "ecc.h"  | 
39  |  | #include "ecc-internal.h"  | 
40  |  |  | 
41  |  | #define USE_REDC 0  | 
42  |  |  | 
43  |  | #include "ecc-gost-gc256b.h"  | 
44  |  |  | 
45  |  | static void  | 
46  |  | ecc_gost_gc256b_modp (const struct ecc_modulo *m, mp_limb_t *rp, mp_limb_t *xp)  | 
47  | 0  | { | 
48  | 0  |   mp_size_t mn = m->size;  | 
49  | 0  |   mp_limb_t hi;  | 
50  |  | 
  | 
51  | 0  |   hi = mpn_addmul_1(xp, xp + mn, mn, 0x269);  | 
52  | 0  |   hi = sec_add_1 (xp, xp, mn, hi * 0x269);  | 
53  | 0  |   hi = sec_add_1 (rp, xp, mn, hi * 0x269);  | 
54  | 0  |   assert(hi == 0);  | 
55  | 0  | }  | 
56  |  |  | 
57  |  | #define ecc_gost_gc256b_modp ecc_gost_gc256b_modp  | 
58  |  | #define ecc_gost_gc256b_modq ecc_mod  | 
59  |  |  | 
60  |  | const struct ecc_curve _nettle_gost_gc256b =  | 
61  |  | { | 
62  |  |   { | 
63  |  |     256,  | 
64  |  |     ECC_LIMB_SIZE,  | 
65  |  |     ECC_BMODP_SIZE,  | 
66  |  |     ECC_REDC_SIZE,  | 
67  |  |     ECC_MOD_INV_ITCH (ECC_LIMB_SIZE),  | 
68  |  |     0,  | 
69  |  |     0,  | 
70  |  |  | 
71  |  |     ecc_p,  | 
72  |  |     ecc_Bmodp,  | 
73  |  |     ecc_Bmodp_shifted,  | 
74  |  |     ecc_Bm2p,  | 
75  |  |     ecc_redc_ppm1,  | 
76  |  |  | 
77  |  |     ecc_pp1h,  | 
78  |  |     ecc_gost_gc256b_modp,  | 
79  |  |     ecc_gost_gc256b_modp,  | 
80  |  |     ecc_mod_inv,  | 
81  |  |     NULL,  | 
82  |  |     NULL,  | 
83  |  |   },  | 
84  |  |   { | 
85  |  |     256,  | 
86  |  |     ECC_LIMB_SIZE,  | 
87  |  |     ECC_BMODQ_SIZE,  | 
88  |  |     0,  | 
89  |  |     ECC_MOD_INV_ITCH (ECC_LIMB_SIZE),  | 
90  |  |     0,  | 
91  |  |     0,  | 
92  |  |  | 
93  |  |     ecc_q,  | 
94  |  |     ecc_Bmodq,  | 
95  |  |     ecc_Bmodq_shifted,  | 
96  |  |     ecc_Bm2q,  | 
97  |  |     NULL,  | 
98  |  |     ecc_qp1h,  | 
99  |  |  | 
100  |  |     ecc_gost_gc256b_modq,  | 
101  |  |     ecc_gost_gc256b_modq,  | 
102  |  |     ecc_mod_inv,  | 
103  |  |     NULL,  | 
104  |  |     NULL,  | 
105  |  |   },  | 
106  |  |  | 
107  |  |   USE_REDC,  | 
108  |  |   ECC_PIPPENGER_K,  | 
109  |  |   ECC_PIPPENGER_C,  | 
110  |  |  | 
111  |  |   ECC_ADD_JJA_ITCH (ECC_LIMB_SIZE),  | 
112  |  |   ECC_ADD_JJJ_ITCH (ECC_LIMB_SIZE),  | 
113  |  |   ECC_DUP_JJ_ITCH (ECC_LIMB_SIZE),  | 
114  |  |   ECC_MUL_A_ITCH (ECC_LIMB_SIZE),  | 
115  |  |   ECC_MUL_G_ITCH (ECC_LIMB_SIZE),  | 
116  |  |   ECC_J_TO_A_ITCH (ECC_LIMB_SIZE, ECC_MOD_INV_ITCH(ECC_LIMB_SIZE)),  | 
117  |  |  | 
118  |  |   ecc_add_jja,  | 
119  |  |   ecc_add_jjj,  | 
120  |  |   ecc_dup_jj,  | 
121  |  |   ecc_mul_a,  | 
122  |  |   ecc_mul_g,  | 
123  |  |   ecc_j_to_a,  | 
124  |  |  | 
125  |  |   ecc_b,  | 
126  |  |   ecc_unit,  | 
127  |  |   ecc_table  | 
128  |  | };  | 
129  |  |  | 
130  |  | const struct ecc_curve *nettle_get_gost_gc256b(void)  | 
131  | 0  | { | 
132  | 0  |   return &_nettle_gost_gc256b;  | 
133  | 0  | }  |