xref: /freebsd/crypto/libecc/include/libecc/curves/ec_params.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_H__
17 #define __EC_PARAMS_H__
18 #include <libecc/fp/fp.h>
19 #include <libecc/curves/prj_pt.h>
20 #include <libecc/curves/known/ec_params_external.h>
21 
22 /* Info: this include is here because an update on
23  * MAX_CURVE_OID_LEN and MAX_CURVE_NAME_LEN can be done
24  * through preprocessing of the curves at compile time.
25  */
26 #include <libecc/curves/curves_list.h>
27 /* These default sizes should be enough for the known curves */
28 #ifdef MAX_CURVE_NAME_LEN
29 #if (MAX_CURVE_OID_LEN < 32)
30 #undef MAX_CURVE_OID_LEN
31 #define MAX_CURVE_OID_LEN  32	/* including trailing 0 */
32 #endif
33 #else
34 #define MAX_CURVE_OID_LEN  32	/* including trailing 0 */
35 #endif
36 
37 #ifdef MAX_CURVE_NAME_LEN
38 #if (MAX_CURVE_NAME_LEN < 32)
39 #undef MAX_CURVE_NAME_LEN
40 #define MAX_CURVE_NAME_LEN 32	/* including trailing 0 */
41 #endif
42 #else
43 #define MAX_CURVE_NAME_LEN 32
44 #endif
45 
46 /*
47  * Elliptic curves parameters. We only support
48  * curves defined on prime fields (i.e. Fp,
49  * with p prime).
50  */
51 typedef struct {
52 	/* Fp */
53 	fp_ctx ec_fp;
54 
55 	/* Curve */
56 	ec_shortw_crv ec_curve;
57 
58 	/*
59 	 * Generator G defining our group, in projective
60 	 * coordinates.
61 	 */
62 	prj_pt ec_gen;
63 
64 	/* Number of points on group generated by G */
65 	nn ec_gen_order;
66 	bitcnt_t ec_gen_order_bitlen;
67 
68 	/* Curve cofactor */
69 	nn ec_gen_cofactor;
70 
71 #if !defined(USE_SMALL_STACK)
72 	/* Optional transfer coefficients with Montgomery curves */
73 	fp ec_alpha_montgomery;
74 	fp ec_gamma_montgomery;
75 	/* Optional transfer coefficient with Edwards curves */
76 	fp ec_alpha_edwards;
77 #endif
78 
79 	/* Object Identifier for the curve */
80 	u8 curve_oid[MAX_CURVE_OID_LEN];
81 
82 	/* Short name for the curve */
83 	u8 curve_name[MAX_CURVE_NAME_LEN];
84 
85 	/* Type of the curve */
86 	ec_curve_type curve_type;
87 } ec_params;
88 
89 ATTRIBUTE_WARN_UNUSED_RET int import_params(ec_params *out_params, const ec_str_params *in_str_params);
90 
91 #endif /* __EC_PARAMS_H__ */
92