xref: /freebsd/crypto/libecc/include/libecc/curves/known/ec_params_sm2p256test.h (revision f0865ec9906d5a18fa2a3b61381f22ce16e606ad)
1 /*
2  *  Copyright (C) 2021 - This file is part of libecc project
3  *
4  *  Authors:
5  *      Arnaud EBALARD <arnaud.ebalard@ssi.gouv.fr>
6  *      Ryad BENADJILA <ryadbenadjila@gmail.com>
7  *
8  *  This software is licensed under a dual BSD and GPL v2 license.
9  *  See LICENSE file at the root folder of the project.
10  */
11 #include <libecc/lib_ecc_config.h>
12 #ifdef WITH_CURVE_SM2P256TEST
13 
14 #ifndef __EC_PARAMS_SM2P256TEST_H__
15 #define __EC_PARAMS_SM2P256TEST_H__
16 #include <libecc/curves/known/ec_params_external.h>
17 
18 static const u8 sm2p256test_p[] = {
19 	0x85, 0x42, 0xd6, 0x9e, 0x4c, 0x04, 0x4f, 0x18,
20 	0xe8, 0xb9, 0x24, 0x35, 0xbf, 0x6f, 0xf7, 0xde,
21 	0x45, 0x72, 0x83, 0x91, 0x5c, 0x45, 0x51, 0x7d,
22 	0x72, 0x2e, 0xdb, 0x8b, 0x08, 0xf1, 0xdf, 0xc3,
23 };
24 
25 TO_EC_STR_PARAM(sm2p256test_p);
26 
27 #define CURVE_SM2P256TEST_P_BITLEN 256
28 static const u8 sm2p256test_p_bitlen[] = {
29 	0x01, 0x00,
30 };
31 
32 TO_EC_STR_PARAM(sm2p256test_p_bitlen);
33 
34 #if (WORD_BYTES == 8)     /* 64-bit words */
35 static const u8 sm2p256test_r[] = {
36 	0x7a, 0xbd, 0x29, 0x61, 0xb3, 0xfb, 0xb0, 0xe7,
37 	0x17, 0x46, 0xdb, 0xca, 0x40, 0x90, 0x08, 0x21,
38 	0xba, 0x8d, 0x7c, 0x6e, 0xa3, 0xba, 0xae, 0x82,
39 	0x8d, 0xd1, 0x24, 0x74, 0xf7, 0x0e, 0x20, 0x3d,
40 };
41 
42 TO_EC_STR_PARAM(sm2p256test_r);
43 
44 static const u8 sm2p256test_r_square[] = {
45 	0x0a, 0xe5, 0x52, 0x29, 0x28, 0x3c, 0xd9, 0x6a,
46 	0xee, 0x4d, 0x87, 0xda, 0x90, 0xd8, 0xc6, 0x6c,
47 	0xeb, 0x37, 0x2d, 0xa8, 0x3f, 0xc9, 0xc6, 0x36,
48 	0x3d, 0x57, 0x9c, 0x46, 0xf6, 0xde, 0x18, 0xf2,
49 };
50 
51 TO_EC_STR_PARAM(sm2p256test_r_square);
52 
53 static const u8 sm2p256test_mpinv[] = {
54 	0xa2, 0xa0, 0x38, 0x0c, 0x50, 0xf7, 0x77, 0x15,
55 };
56 
57 TO_EC_STR_PARAM(sm2p256test_mpinv);
58 
59 static const u8 sm2p256test_p_shift[] = {
60 	0x00,
61 };
62 
63 TO_EC_STR_PARAM(sm2p256test_p_shift);
64 
65 static const u8 sm2p256test_p_normalized[] = {
66 	0x85, 0x42, 0xd6, 0x9e, 0x4c, 0x04, 0x4f, 0x18,
67 	0xe8, 0xb9, 0x24, 0x35, 0xbf, 0x6f, 0xf7, 0xde,
68 	0x45, 0x72, 0x83, 0x91, 0x5c, 0x45, 0x51, 0x7d,
69 	0x72, 0x2e, 0xdb, 0x8b, 0x08, 0xf1, 0xdf, 0xc3,
70 };
71 
72 TO_EC_STR_PARAM(sm2p256test_p_normalized);
73 
74 static const u8 sm2p256test_p_reciprocal[] = {
75 	0xeb, 0xc9, 0x56, 0x3c, 0x60, 0x57, 0x6b, 0xb9,
76 };
77 
78 TO_EC_STR_PARAM(sm2p256test_p_reciprocal);
79 
80 #elif (WORD_BYTES == 4)   /* 32-bit words */
81 static const u8 sm2p256test_r[] = {
82 	0x7a, 0xbd, 0x29, 0x61, 0xb3, 0xfb, 0xb0, 0xe7,
83 	0x17, 0x46, 0xdb, 0xca, 0x40, 0x90, 0x08, 0x21,
84 	0xba, 0x8d, 0x7c, 0x6e, 0xa3, 0xba, 0xae, 0x82,
85 	0x8d, 0xd1, 0x24, 0x74, 0xf7, 0x0e, 0x20, 0x3d,
86 };
87 
88 TO_EC_STR_PARAM(sm2p256test_r);
89 
90 static const u8 sm2p256test_r_square[] = {
91 	0x0a, 0xe5, 0x52, 0x29, 0x28, 0x3c, 0xd9, 0x6a,
92 	0xee, 0x4d, 0x87, 0xda, 0x90, 0xd8, 0xc6, 0x6c,
93 	0xeb, 0x37, 0x2d, 0xa8, 0x3f, 0xc9, 0xc6, 0x36,
94 	0x3d, 0x57, 0x9c, 0x46, 0xf6, 0xde, 0x18, 0xf2,
95 };
96 
97 TO_EC_STR_PARAM(sm2p256test_r_square);
98 
99 static const u8 sm2p256test_mpinv[] = {
100 	0x50, 0xf7, 0x77, 0x15,
101 };
102 
103 TO_EC_STR_PARAM(sm2p256test_mpinv);
104 
105 static const u8 sm2p256test_p_shift[] = {
106 	0x00,
107 };
108 
109 TO_EC_STR_PARAM(sm2p256test_p_shift);
110 
111 static const u8 sm2p256test_p_normalized[] = {
112 	0x85, 0x42, 0xd6, 0x9e, 0x4c, 0x04, 0x4f, 0x18,
113 	0xe8, 0xb9, 0x24, 0x35, 0xbf, 0x6f, 0xf7, 0xde,
114 	0x45, 0x72, 0x83, 0x91, 0x5c, 0x45, 0x51, 0x7d,
115 	0x72, 0x2e, 0xdb, 0x8b, 0x08, 0xf1, 0xdf, 0xc3,
116 };
117 
118 TO_EC_STR_PARAM(sm2p256test_p_normalized);
119 
120 static const u8 sm2p256test_p_reciprocal[] = {
121 	0xeb, 0xc9, 0x56, 0x3c,
122 };
123 
124 TO_EC_STR_PARAM(sm2p256test_p_reciprocal);
125 
126 #elif (WORD_BYTES == 2)   /* 16-bit words */
127 static const u8 sm2p256test_r[] = {
128 	0x7a, 0xbd, 0x29, 0x61, 0xb3, 0xfb, 0xb0, 0xe7,
129 	0x17, 0x46, 0xdb, 0xca, 0x40, 0x90, 0x08, 0x21,
130 	0xba, 0x8d, 0x7c, 0x6e, 0xa3, 0xba, 0xae, 0x82,
131 	0x8d, 0xd1, 0x24, 0x74, 0xf7, 0x0e, 0x20, 0x3d,
132 };
133 
134 TO_EC_STR_PARAM(sm2p256test_r);
135 
136 static const u8 sm2p256test_r_square[] = {
137 	0x0a, 0xe5, 0x52, 0x29, 0x28, 0x3c, 0xd9, 0x6a,
138 	0xee, 0x4d, 0x87, 0xda, 0x90, 0xd8, 0xc6, 0x6c,
139 	0xeb, 0x37, 0x2d, 0xa8, 0x3f, 0xc9, 0xc6, 0x36,
140 	0x3d, 0x57, 0x9c, 0x46, 0xf6, 0xde, 0x18, 0xf2,
141 };
142 
143 TO_EC_STR_PARAM(sm2p256test_r_square);
144 
145 static const u8 sm2p256test_mpinv[] = {
146 	0x77, 0x15,
147 };
148 
149 TO_EC_STR_PARAM(sm2p256test_mpinv);
150 
151 static const u8 sm2p256test_p_shift[] = {
152 	0x00,
153 };
154 
155 TO_EC_STR_PARAM(sm2p256test_p_shift);
156 
157 static const u8 sm2p256test_p_normalized[] = {
158 	0x85, 0x42, 0xd6, 0x9e, 0x4c, 0x04, 0x4f, 0x18,
159 	0xe8, 0xb9, 0x24, 0x35, 0xbf, 0x6f, 0xf7, 0xde,
160 	0x45, 0x72, 0x83, 0x91, 0x5c, 0x45, 0x51, 0x7d,
161 	0x72, 0x2e, 0xdb, 0x8b, 0x08, 0xf1, 0xdf, 0xc3,
162 };
163 
164 TO_EC_STR_PARAM(sm2p256test_p_normalized);
165 
166 static const u8 sm2p256test_p_reciprocal[] = {
167 	0xeb, 0xc9,
168 };
169 
170 TO_EC_STR_PARAM(sm2p256test_p_reciprocal);
171 
172 #else                     /* unknown word size */
173 #error "Unsupported word size"
174 #endif
175 
176 static const u8 sm2p256test_a[] = {
177 	0x78, 0x79, 0x68, 0xb4, 0xfa, 0x32, 0xc3, 0xfd,
178 	0x24, 0x17, 0x84, 0x2e, 0x73, 0xbb, 0xfe, 0xff,
179 	0x2f, 0x3c, 0x84, 0x8b, 0x68, 0x31, 0xd7, 0xe0,
180 	0xec, 0x65, 0x22, 0x8b, 0x39, 0x37, 0xe4, 0x98,
181 };
182 
183 TO_EC_STR_PARAM(sm2p256test_a);
184 
185 static const u8 sm2p256test_b[] = {
186 	0x63, 0xe4, 0xc6, 0xd3, 0xb2, 0x3b, 0x0c, 0x84,
187 	0x9c, 0xf8, 0x42, 0x41, 0x48, 0x4b, 0xfe, 0x48,
188 	0xf6, 0x1d, 0x59, 0xa5, 0xb1, 0x6b, 0xa0, 0x6e,
189 	0x6e, 0x12, 0xd1, 0xda, 0x27, 0xc5, 0x24, 0x9a,
190 };
191 
192 TO_EC_STR_PARAM(sm2p256test_b);
193 
194 #define CURVE_SM2P256TEST_CURVE_ORDER_BITLEN 256
195 static const u8 sm2p256test_order[] = {
196 	0x85, 0x42, 0xd6, 0x9e, 0x4c, 0x04, 0x4f, 0x18,
197 	0xe8, 0xb9, 0x24, 0x35, 0xbf, 0x6f, 0xf7, 0xdd,
198 	0x29, 0x77, 0x20, 0x63, 0x04, 0x85, 0x62, 0x8d,
199 	0x5a, 0xe7, 0x4e, 0xe7, 0xc3, 0x2e, 0x79, 0xb7,
200 };
201 
202 TO_EC_STR_PARAM(sm2p256test_order);
203 
204 static const u8 sm2p256test_gx[] = {
205 	0x42, 0x1d, 0xeb, 0xd6, 0x1b, 0x62, 0xea, 0xb6,
206 	0x74, 0x64, 0x34, 0xeb, 0xc3, 0xcc, 0x31, 0x5e,
207 	0x32, 0x22, 0x0b, 0x3b, 0xad, 0xd5, 0x0b, 0xdc,
208 	0x4c, 0x4e, 0x6c, 0x14, 0x7f, 0xed, 0xd4, 0x3d,
209 };
210 
211 TO_EC_STR_PARAM(sm2p256test_gx);
212 
213 static const u8 sm2p256test_gy[] = {
214 	0x06, 0x80, 0x51, 0x2b, 0xcb, 0xb4, 0x2c, 0x07,
215 	0xd4, 0x73, 0x49, 0xd2, 0x15, 0x3b, 0x70, 0xc4,
216 	0xe5, 0xd7, 0xfd, 0xfc, 0xbf, 0xa3, 0x6e, 0xa1,
217 	0xa8, 0x58, 0x41, 0xb9, 0xe4, 0x6e, 0x09, 0xa2,
218 };
219 
220 TO_EC_STR_PARAM(sm2p256test_gy);
221 
222 static const u8 sm2p256test_gz[] = {
223 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
224 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
225 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
226 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
227 };
228 
229 TO_EC_STR_PARAM(sm2p256test_gz);
230 
231 static const u8 sm2p256test_gen_order[] = {
232 	0x85, 0x42, 0xd6, 0x9e, 0x4c, 0x04, 0x4f, 0x18,
233 	0xe8, 0xb9, 0x24, 0x35, 0xbf, 0x6f, 0xf7, 0xdd,
234 	0x29, 0x77, 0x20, 0x63, 0x04, 0x85, 0x62, 0x8d,
235 	0x5a, 0xe7, 0x4e, 0xe7, 0xc3, 0x2e, 0x79, 0xb7,
236 };
237 
238 TO_EC_STR_PARAM(sm2p256test_gen_order);
239 
240 #define CURVE_SM2P256TEST_Q_BITLEN 256
241 static const u8 sm2p256test_gen_order_bitlen[] = {
242 	0x01, 0x00,
243 };
244 
245 TO_EC_STR_PARAM(sm2p256test_gen_order_bitlen);
246 
247 static const u8 sm2p256test_cofactor[] = {
248 	0x01,
249 };
250 
251 TO_EC_STR_PARAM(sm2p256test_cofactor);
252 
253 
254 static const u8 sm2p256test_alpha_montgomery[] = {
255         0x00,
256 };
257 
258 TO_EC_STR_PARAM_FIXED_SIZE(sm2p256test_alpha_montgomery, 0);
259 
260 static const u8 sm2p256test_gamma_montgomery[] = {
261         0x00,
262 };
263 
264 TO_EC_STR_PARAM_FIXED_SIZE(sm2p256test_gamma_montgomery, 0);
265 
266 static const u8 sm2p256test_alpha_edwards[] = {
267         0x00,
268 };
269 
270 TO_EC_STR_PARAM_FIXED_SIZE(sm2p256test_alpha_edwards, 0);
271 
272 
273 static const u8 sm2p256test_name[] = "SM2P256TEST";
274 TO_EC_STR_PARAM(sm2p256test_name);
275 
276 static const u8 sm2p256test_oid[] = "sm2-iso14888-test-curve";
277 TO_EC_STR_PARAM(sm2p256test_oid);
278 
279 static const ec_str_params sm2p256test_str_params = {
280 	.p = &sm2p256test_p_str_param,
281 	.p_bitlen = &sm2p256test_p_bitlen_str_param,
282 	.r = &sm2p256test_r_str_param,
283 	.r_square = &sm2p256test_r_square_str_param,
284 	.mpinv = &sm2p256test_mpinv_str_param,
285 	.p_shift = &sm2p256test_p_shift_str_param,
286 	.p_normalized = &sm2p256test_p_normalized_str_param,
287 	.p_reciprocal = &sm2p256test_p_reciprocal_str_param,
288 	.a = &sm2p256test_a_str_param,
289 	.b = &sm2p256test_b_str_param,
290 	.curve_order = &sm2p256test_order_str_param,
291 	.gx = &sm2p256test_gx_str_param,
292 	.gy = &sm2p256test_gy_str_param,
293 	.gz = &sm2p256test_gz_str_param,
294 	.gen_order = &sm2p256test_gen_order_str_param,
295 	.gen_order_bitlen = &sm2p256test_gen_order_bitlen_str_param,
296 	.cofactor = &sm2p256test_cofactor_str_param,
297         .alpha_montgomery = &sm2p256test_alpha_montgomery_str_param,
298         .gamma_montgomery = &sm2p256test_gamma_montgomery_str_param,
299         .alpha_edwards = &sm2p256test_alpha_edwards_str_param,
300 	.oid = &sm2p256test_oid_str_param,
301 	.name = &sm2p256test_name_str_param,
302 };
303 
304 /*
305  * Compute max bit length of all curves for p and q
306  */
307 #ifndef CURVES_MAX_P_BIT_LEN
308 #define CURVES_MAX_P_BIT_LEN    0
309 #endif
310 #if (CURVES_MAX_P_BIT_LEN < CURVE_SM2P256TEST_P_BITLEN)
311 #undef CURVES_MAX_P_BIT_LEN
312 #define CURVES_MAX_P_BIT_LEN CURVE_SM2P256TEST_P_BITLEN
313 #endif
314 #ifndef CURVES_MAX_Q_BIT_LEN
315 #define CURVES_MAX_Q_BIT_LEN    0
316 #endif
317 #if (CURVES_MAX_Q_BIT_LEN < CURVE_SM2P256TEST_Q_BITLEN)
318 #undef CURVES_MAX_Q_BIT_LEN
319 #define CURVES_MAX_Q_BIT_LEN CURVE_SM2P256TEST_Q_BITLEN
320 #endif
321 #ifndef CURVES_MAX_CURVE_ORDER_BIT_LEN
322 #define CURVES_MAX_CURVE_ORDER_BIT_LEN  0
323 #endif
324 #if (CURVES_MAX_CURVE_ORDER_BIT_LEN < CURVE_SM2P256TEST_CURVE_ORDER_BITLEN)
325 #undef CURVES_MAX_CURVE_ORDER_BIT_LEN
326 #define CURVES_MAX_CURVE_ORDER_BIT_LEN CURVE_SM2P256TEST_CURVE_ORDER_BITLEN
327 #endif
328 
329 /*
330  * Compute and adapt max name and oid length
331  */
332 #ifndef MAX_CURVE_OID_LEN
333 #define MAX_CURVE_OID_LEN 0
334 #endif
335 #ifndef MAX_CURVE_NAME_LEN
336 #define MAX_CURVE_NAME_LEN 0
337 #endif
338 #if (MAX_CURVE_OID_LEN < 24)
339 #undef MAX_CURVE_OID_LEN
340 #define MAX_CURVE_OID_LEN 24
341 #endif
342 #if (MAX_CURVE_NAME_LEN < 24)
343 #undef MAX_CURVE_NAME_LEN
344 #define MAX_CURVE_NAME_LEN 24
345 #endif
346 
347 #endif /* __EC_PARAMS_SM2P256TEST_H__ */
348 
349 #endif /* WITH_CURVE_SM2P256TEST */
350