xref: /freebsd/crypto/libecc/include/libecc/curves/known/ec_params_external.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 #ifndef __EC_PARAMS_EXTERNAL_H__
17 #define __EC_PARAMS_EXTERNAL_H__
18 #include <libecc/words/words.h>
19 
20 typedef struct {
21 	const u8 *buf;
22 	const u8 buflen;
23 } ec_str_param;
24 
25 #define TO_EC_STR_PARAM(pname) \
26 	static const ec_str_param pname##_str_param = { \
27 		.buf = pname,				\
28 		.buflen = sizeof(pname)                 \
29 	}
30 
31 
32 #define TO_EC_STR_PARAM_FIXED_SIZE(pname, sz) \
33 	static const ec_str_param pname##_str_param = { \
34 		.buf = pname,				\
35 		.buflen = (sz)				\
36 	}
37 
38 
39 #define PARAM_BUF_LEN(param) ((param)->buflen)
40 #define PARAM_BUF_PTR(param) ((param)->buf)
41 
42 typedef struct {
43 	/*
44 	 * Prime p:
45 	 *  o p_bitlen = bitsizeof(p)
46 	 */
47 	const ec_str_param *p;
48 	const ec_str_param *p_bitlen;
49 
50 	/*
51 	 * Precomputed Montgomery parameters:
52 	 *  o r = 2^bitsizeof(p) mod p
53 	 *  o r_square = 2^(2*bitsizeof(p)) mod p
54 	 *  o mpinv = -p^-1 mod B
55 	 * where B = 2^(bitsizeof(word_t))
56 	 */
57 	const ec_str_param *r;
58 	const ec_str_param *r_square;
59 	const ec_str_param *mpinv;
60 
61 	/*
62 	 * Precomputed division parameters:
63 	 *  o p_shift = nn_clz(p)
64 	 *  o p_normalized =  p << p_shift
65 	 *  o p_reciprocal = floor(B^3/(DMSW(p_normalized) + 1)) - B
66 	 * where B = 2^(bitsizeof(word_t))
67 	 */
68 	const ec_str_param *p_shift;
69 	const ec_str_param *p_normalized;
70 	const ec_str_param *p_reciprocal;
71 
72 	/* Curve coefficients and number of points */
73 	const ec_str_param *a;
74 	const ec_str_param *b;
75 	const ec_str_param *curve_order;
76 
77 	/*
78 	 * Projective coordinates of generator
79 	 * and order and cofactor of associated subgroup.
80 	 */
81 	const ec_str_param *gx;
82 	const ec_str_param *gy;
83 	const ec_str_param *gz;
84 	const ec_str_param *gen_order;
85 	const ec_str_param *gen_order_bitlen;
86 	const ec_str_param *cofactor;
87 
88 	/*
89 	 * Optional transfert coefficients to Montgomery curve.
90 	 */
91 	const ec_str_param *alpha_montgomery;
92 	const ec_str_param *gamma_montgomery;
93 
94 	/*
95 	 * Optional transfert coefficient to Edwards curve.
96 	 */
97 	const ec_str_param *alpha_edwards;
98 
99 	/* OID and pretty name */
100 	const ec_str_param *oid;
101 	const ec_str_param *name;
102 } ec_str_params;
103 
104 #endif /* __EC_PARAMS_EXTERNAL_H__ */
105