xref: /freebsd/crypto/libecc/include/libecc/curves/known/ec_params_gost256.h (revision f0865ec9906d5a18fa2a3b61381f22ce16e606ad)
1 /*
2  *  Copyright (C) 2017 - This file is part of libecc project
3  *
4  *  Authors:
5  *      Ryad BENADJILA <ryadbenadjila@gmail.com>
6  *      Arnaud EBALARD <arnaud.ebalard@ssi.gouv.fr>
7  *      Jean-Pierre FLORI <jean-pierre.flori@ssi.gouv.fr>
8  *
9  *  Contributors:
10  *      Nicolas VIVET <nicolas.vivet@ssi.gouv.fr>
11  *      Karim KHALFALLAH <karim.khalfallah@ssi.gouv.fr>
12  *
13  *  This software is licensed under a dual BSD and GPL v2 license.
14  *  See LICENSE file at the root folder of the project.
15  */
16 #include <libecc/lib_ecc_config.h>
17 #ifdef WITH_CURVE_GOST256
18 
19 #ifndef __EC_PARAMS_GOST256_H__
20 #define __EC_PARAMS_GOST256_H__
21 #include "ec_params_external.h"
22 
23 static const u8 GOST_256bits_curve_p[] = {
24 	0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
25 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
26 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
27 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x31
28 };
29 
30 TO_EC_STR_PARAM(GOST_256bits_curve_p);
31 
32 #define CURVE_GOST256_P_BITLEN 256
33 static const u8 GOST_256bits_curve_p_bitlen[] = { 0x01, 0x00 };
34 
35 TO_EC_STR_PARAM(GOST_256bits_curve_p_bitlen);
36 
37 static const u8 GOST_256bits_curve_r[] = {
38 	0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
39 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
40 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
41 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfb, 0xcf
42 };
43 
44 TO_EC_STR_PARAM(GOST_256bits_curve_r);
45 
46 static const u8 GOST_256bits_curve_r_square[] = {
47 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
50 	0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x45, 0x84
51 };
52 
53 TO_EC_STR_PARAM(GOST_256bits_curve_r_square);
54 
55 static const u8 GOST_256bits_curve_mpinv[] = {
56 	0xdb, 0xf9, 0x51, 0xd5, 0x88, 0x3b, 0x2b, 0x2f
57 };
58 
59 TO_EC_STR_PARAM(GOST_256bits_curve_mpinv);
60 
61 static const u8 GOST_256bits_curve_p_shift[] = {
62 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
63 };
64 
65 TO_EC_STR_PARAM(GOST_256bits_curve_p_shift);
66 
67 #if (WORD_BYTES == 8)		/* 64-bit words */
68 static const u8 GOST_256bits_curve_p_reciprocal[] = {
69 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
70 };
71 #elif (WORD_BYTES == 4)		/* 32-bit words */
72 static const u8 GOST_256bits_curve_p_reciprocal[] = {
73 	0xff, 0xff, 0xff, 0xff
74 };
75 #elif (WORD_BYTES == 2)		/* 16-bit words */
76 static const u8 GOST_256bits_curve_p_reciprocal[] = {
77 	0xff, 0xff
78 };
79 #else /* unknown word size */
80 #error "Unsupported word size"
81 #endif
82 TO_EC_STR_PARAM(GOST_256bits_curve_p_reciprocal);
83 
84 static const u8 GOST_256bits_curve_a[] = {
85 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
86 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07
89 };
90 
91 TO_EC_STR_PARAM(GOST_256bits_curve_a);
92 
93 static const u8 GOST_256bits_curve_b[] = {
94 	0x5F, 0xBF, 0xF4, 0x98, 0xAA, 0x93, 0x8C, 0xE7,
95 	0x39, 0xB8, 0xE0, 0x22, 0xFB, 0xAF, 0xEF, 0x40,
96 	0x56, 0x3F, 0x6E, 0x6A, 0x34, 0x72, 0xFC, 0x2A,
97 	0x51, 0x4C, 0x0C, 0xE9, 0xDA, 0xE2, 0x3B, 0x7E
98 };
99 
100 TO_EC_STR_PARAM(GOST_256bits_curve_b);
101 
102 #define CURVE_GOST256_CURVE_ORDER_BITLEN 256
103 static const u8 GOST_256bits_curve_order[] = {
104 	0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
105 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
106 	0x50, 0xFE, 0x8A, 0x18, 0x92, 0x97, 0x61, 0x54,
107 	0xC5, 0x9C, 0xFC, 0x19, 0x3A, 0xCC, 0xF5, 0xB3
108 };
109 
110 TO_EC_STR_PARAM(GOST_256bits_curve_order);
111 
112 static const u8 GOST_256bits_curve_gx[] = {
113 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
114 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
115 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
116 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02
117 };
118 
119 TO_EC_STR_PARAM(GOST_256bits_curve_gx);
120 
121 static const u8 GOST_256bits_curve_gy[] = {
122 	0x08, 0xE2, 0xA8, 0xA0, 0xE6, 0x51, 0x47, 0xD4,
123 	0xBD, 0x63, 0x16, 0x03, 0x0E, 0x16, 0xD1, 0x9C,
124 	0x85, 0xC9, 0x7F, 0x0A, 0x9C, 0xA2, 0x67, 0x12,
125 	0x2B, 0x96, 0xAB, 0xBC, 0xEA, 0x7E, 0x8F, 0xC8
126 };
127 
128 TO_EC_STR_PARAM(GOST_256bits_curve_gy);
129 
130 static const u8 GOST_256bits_curve_gz[] = {
131 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
132 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
133 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
135 };
136 
137 TO_EC_STR_PARAM(GOST_256bits_curve_gz);
138 
139 static const u8 GOST_256bits_curve_gen_order[] = {
140 	0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
141 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
142 	0x50, 0xFE, 0x8A, 0x18, 0x92, 0x97, 0x61, 0x54,
143 	0xC5, 0x9C, 0xFC, 0x19, 0x3A, 0xCC, 0xF5, 0xB3
144 };
145 
146 TO_EC_STR_PARAM(GOST_256bits_curve_gen_order);
147 
148 #define CURVE_GOST256_Q_BITLEN 256
149 static const u8 GOST_256bits_curve_gen_order_bitlen[] = { 0x01, 0x00 };
150 
151 TO_EC_STR_PARAM(GOST_256bits_curve_gen_order_bitlen);
152 
153 static const u8 GOST_256bits_curve_cofactor[] = { 0x01 };
154 
155 TO_EC_STR_PARAM(GOST_256bits_curve_cofactor);
156 
157 static const u8 GOST_256bits_curve_alpha_montgomery[] = {
158 	0x00,
159 };
160 
161 TO_EC_STR_PARAM_FIXED_SIZE(GOST_256bits_curve_alpha_montgomery, 0);
162 
163 static const u8 GOST_256bits_curve_gamma_montgomery[] = {
164 	0x00,
165 };
166 
167 TO_EC_STR_PARAM_FIXED_SIZE(GOST_256bits_curve_gamma_montgomery, 0);
168 
169 static const u8 GOST_256bits_curve_alpha_edwards[] = {
170 	0x00,
171 };
172 
173 TO_EC_STR_PARAM_FIXED_SIZE(GOST_256bits_curve_alpha_edwards, 0);
174 
175 static const u8 GOST_256bits_curve_oid[] = "unknown";
176 TO_EC_STR_PARAM(GOST_256bits_curve_oid);
177 
178 static const u8 GOST_256bits_curve_name[] = "GOST256";
179 TO_EC_STR_PARAM(GOST_256bits_curve_name);
180 
181 static const ec_str_params GOST_256bits_curve_str_params = {
182 	.p = &GOST_256bits_curve_p_str_param,
183 	.p_bitlen = &GOST_256bits_curve_p_bitlen_str_param,
184 	.r = &GOST_256bits_curve_r_str_param,
185 	.r_square = &GOST_256bits_curve_r_square_str_param,
186 	.mpinv = &GOST_256bits_curve_mpinv_str_param,
187 	.p_shift = &GOST_256bits_curve_p_shift_str_param,
188 	.p_normalized = &GOST_256bits_curve_p_str_param,
189 	.p_reciprocal = &GOST_256bits_curve_p_reciprocal_str_param,
190 	.a = &GOST_256bits_curve_a_str_param,
191 	.b = &GOST_256bits_curve_b_str_param,
192 	.curve_order = &GOST_256bits_curve_order_str_param,
193 	.gx = &GOST_256bits_curve_gx_str_param,
194 	.gy = &GOST_256bits_curve_gy_str_param,
195 	.gz = &GOST_256bits_curve_gz_str_param,
196 	.gen_order = &GOST_256bits_curve_gen_order_str_param,
197 	.gen_order_bitlen = &GOST_256bits_curve_gen_order_bitlen_str_param,
198 	.cofactor = &GOST_256bits_curve_cofactor_str_param,
199 	.alpha_montgomery = &GOST_256bits_curve_alpha_montgomery_str_param,
200 	.gamma_montgomery = &GOST_256bits_curve_gamma_montgomery_str_param,
201 	.alpha_edwards = &GOST_256bits_curve_alpha_edwards_str_param,
202 	.oid = &GOST_256bits_curve_oid_str_param,
203 	.name = &GOST_256bits_curve_name_str_param,
204 };
205 
206 /*
207  * Compute max bit length of all curves for p and q
208  */
209 #ifndef CURVES_MAX_P_BIT_LEN
210 #define CURVES_MAX_P_BIT_LEN	0
211 #endif
212 #if (CURVES_MAX_P_BIT_LEN < CURVE_GOST256_P_BITLEN)
213 #undef CURVES_MAX_P_BIT_LEN
214 #define CURVES_MAX_P_BIT_LEN CURVE_GOST256_P_BITLEN
215 #endif
216 #ifndef CURVES_MAX_Q_BIT_LEN
217 #define CURVES_MAX_Q_BIT_LEN    0
218 #endif
219 #if (CURVES_MAX_Q_BIT_LEN < CURVE_GOST256_Q_BITLEN)
220 #undef CURVES_MAX_Q_BIT_LEN
221 #define CURVES_MAX_Q_BIT_LEN CURVE_GOST256_Q_BITLEN
222 #endif
223 #ifndef CURVES_MAX_CURVE_ORDER_BIT_LEN
224 #define CURVES_MAX_CURVE_ORDER_BIT_LEN  0
225 #endif
226 #if (CURVES_MAX_CURVE_ORDER_BIT_LEN < CURVE_GOST256_CURVE_ORDER_BITLEN)
227 #undef CURVES_MAX_CURVE_ORDER_BIT_LEN
228 #define CURVES_MAX_CURVE_ORDER_BIT_LEN CURVE_GOST256_CURVE_ORDER_BITLEN
229 #endif
230 
231 #endif /* __EC_PARAMS_GOST256_H__ */
232 
233 #endif /* WITH_CURVE_GOST256 */
234