/src/openssl/crypto/ec/ec_local.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2001-2024 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved |
4 | | * |
5 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
6 | | * this file except in compliance with the License. You can obtain a copy |
7 | | * in the file LICENSE in the source distribution or at |
8 | | * https://www.openssl.org/source/license.html |
9 | | */ |
10 | | |
11 | | #if !defined(OSSL_LIBCRYPTO_EC_EC_LOCAL_H) |
12 | | #define OSSL_LIBCRYPTO_EC_EC_LOCAL_H |
13 | | |
14 | | #include <stdlib.h> |
15 | | |
16 | | #include <openssl/obj_mac.h> |
17 | | #include <openssl/ec.h> |
18 | | #include <openssl/bn.h> |
19 | | #include "internal/refcount.h" |
20 | | #include "crypto/ec.h" |
21 | | |
22 | | #if defined(__SUNPRO_C) |
23 | | #if __SUNPRO_C >= 0x520 |
24 | | #pragma error_messages(off, E_ARRAY_OF_INCOMPLETE_NONAME, E_ARRAY_OF_INCOMPLETE) |
25 | | #endif |
26 | | #endif |
27 | | |
28 | | /* Use default functions for poin2oct, oct2point and compressed coordinates */ |
29 | 0 | #define EC_FLAGS_DEFAULT_OCT 0x1 |
30 | | |
31 | | /* Use custom formats for EC_GROUP, EC_POINT and EC_KEY */ |
32 | 0 | #define EC_FLAGS_CUSTOM_CURVE 0x2 |
33 | | |
34 | | /* Curve does not support signing operations */ |
35 | 0 | #define EC_FLAGS_NO_SIGN 0x4 |
36 | | |
37 | | #ifdef OPENSSL_NO_DEPRECATED_3_0 |
38 | | typedef struct ec_method_st EC_METHOD; |
39 | | #endif |
40 | | |
41 | | /* |
42 | | * Structure details are not part of the exported interface, so all this may |
43 | | * change in future versions. |
44 | | */ |
45 | | |
46 | | struct ec_method_st { |
47 | | /* Various method flags */ |
48 | | int flags; |
49 | | /* used by EC_METHOD_get_field_type: */ |
50 | | int field_type; /* a NID */ |
51 | | /* |
52 | | * used by EC_GROUP_new, EC_GROUP_free, EC_GROUP_clear_free, |
53 | | * EC_GROUP_copy: |
54 | | */ |
55 | | int (*group_init)(EC_GROUP *); |
56 | | void (*group_finish)(EC_GROUP *); |
57 | | void (*group_clear_finish)(EC_GROUP *); |
58 | | int (*group_copy)(EC_GROUP *, const EC_GROUP *); |
59 | | /* used by EC_GROUP_set_curve, EC_GROUP_get_curve: */ |
60 | | int (*group_set_curve)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, |
61 | | const BIGNUM *b, BN_CTX *); |
62 | | int (*group_get_curve)(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, |
63 | | BN_CTX *); |
64 | | /* used by EC_GROUP_get_degree: */ |
65 | | int (*group_get_degree)(const EC_GROUP *); |
66 | | int (*group_order_bits)(const EC_GROUP *); |
67 | | /* used by EC_GROUP_check: */ |
68 | | int (*group_check_discriminant)(const EC_GROUP *, BN_CTX *); |
69 | | /* |
70 | | * used by EC_POINT_new, EC_POINT_free, EC_POINT_clear_free, |
71 | | * EC_POINT_copy: |
72 | | */ |
73 | | int (*point_init)(EC_POINT *); |
74 | | void (*point_finish)(EC_POINT *); |
75 | | void (*point_clear_finish)(EC_POINT *); |
76 | | int (*point_copy)(EC_POINT *, const EC_POINT *); |
77 | | /*- |
78 | | * used by EC_POINT_set_to_infinity, |
79 | | * EC_POINT_set_Jprojective_coordinates_GFp, |
80 | | * EC_POINT_get_Jprojective_coordinates_GFp, |
81 | | * EC_POINT_set_affine_coordinates, |
82 | | * EC_POINT_get_affine_coordinates, |
83 | | * EC_POINT_set_compressed_coordinates: |
84 | | */ |
85 | | int (*point_set_to_infinity)(const EC_GROUP *, EC_POINT *); |
86 | | int (*point_set_affine_coordinates)(const EC_GROUP *, EC_POINT *, |
87 | | const BIGNUM *x, const BIGNUM *y, |
88 | | BN_CTX *); |
89 | | int (*point_get_affine_coordinates)(const EC_GROUP *, const EC_POINT *, |
90 | | BIGNUM *x, BIGNUM *y, BN_CTX *); |
91 | | int (*point_set_compressed_coordinates)(const EC_GROUP *, EC_POINT *, |
92 | | const BIGNUM *x, int y_bit, |
93 | | BN_CTX *); |
94 | | /* used by EC_POINT_point2oct, EC_POINT_oct2point: */ |
95 | | size_t (*point2oct)(const EC_GROUP *, const EC_POINT *, |
96 | | point_conversion_form_t form, unsigned char *buf, |
97 | | size_t len, BN_CTX *); |
98 | | int (*oct2point)(const EC_GROUP *, EC_POINT *, const unsigned char *buf, |
99 | | size_t len, BN_CTX *); |
100 | | /* used by EC_POINT_add, EC_POINT_dbl, ECP_POINT_invert: */ |
101 | | int (*add)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, |
102 | | const EC_POINT *b, BN_CTX *); |
103 | | int (*dbl)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *); |
104 | | int (*invert)(const EC_GROUP *, EC_POINT *, BN_CTX *); |
105 | | /* |
106 | | * used by EC_POINT_is_at_infinity, EC_POINT_is_on_curve, EC_POINT_cmp: |
107 | | */ |
108 | | int (*is_at_infinity)(const EC_GROUP *, const EC_POINT *); |
109 | | int (*is_on_curve)(const EC_GROUP *, const EC_POINT *, BN_CTX *); |
110 | | int (*point_cmp)(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, |
111 | | BN_CTX *); |
112 | | /* used by EC_POINT_make_affine, EC_POINTs_make_affine: */ |
113 | | int (*make_affine)(const EC_GROUP *, EC_POINT *, BN_CTX *); |
114 | | int (*points_make_affine)(const EC_GROUP *, size_t num, EC_POINT *[], |
115 | | BN_CTX *); |
116 | | /* |
117 | | * used by EC_POINTs_mul, EC_POINT_mul, EC_POINT_precompute_mult, |
118 | | * EC_POINT_have_precompute_mult (default implementations are used if the |
119 | | * 'mul' pointer is 0): |
120 | | */ |
121 | | /*- |
122 | | * mul() calculates the value |
123 | | * |
124 | | * r := generator * scalar |
125 | | * + points[0] * scalars[0] |
126 | | * + ... |
127 | | * + points[num-1] * scalars[num-1]. |
128 | | * |
129 | | * For a fixed point multiplication (scalar != NULL, num == 0) |
130 | | * or a variable point multiplication (scalar == NULL, num == 1), |
131 | | * mul() must use a constant time algorithm: in both cases callers |
132 | | * should provide an input scalar (either scalar or scalars[0]) |
133 | | * in the range [0, ec_group_order); for robustness, implementers |
134 | | * should handle the case when the scalar has not been reduced, but |
135 | | * may treat it as an unusual input, without any constant-timeness |
136 | | * guarantee. |
137 | | */ |
138 | | int (*mul)(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, |
139 | | size_t num, const EC_POINT *points[], const BIGNUM *scalars[], |
140 | | BN_CTX *); |
141 | | int (*precompute_mult)(EC_GROUP *group, BN_CTX *); |
142 | | int (*have_precompute_mult)(const EC_GROUP *group); |
143 | | /* internal functions */ |
144 | | /* |
145 | | * 'field_mul', 'field_sqr', and 'field_div' can be used by 'add' and |
146 | | * 'dbl' so that the same implementations of point operations can be used |
147 | | * with different optimized implementations of expensive field |
148 | | * operations: |
149 | | */ |
150 | | int (*field_mul)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
151 | | const BIGNUM *b, BN_CTX *); |
152 | | int (*field_sqr)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); |
153 | | int (*field_div)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
154 | | const BIGNUM *b, BN_CTX *); |
155 | | /*- |
156 | | * 'field_inv' computes the multiplicative inverse of a in the field, |
157 | | * storing the result in r. |
158 | | * |
159 | | * If 'a' is zero (or equivalent), you'll get an EC_R_CANNOT_INVERT error. |
160 | | */ |
161 | | int (*field_inv)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); |
162 | | /* e.g. to Montgomery */ |
163 | | int (*field_encode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
164 | | BN_CTX *); |
165 | | /* e.g. from Montgomery */ |
166 | | int (*field_decode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
167 | | BN_CTX *); |
168 | | int (*field_set_to_one)(const EC_GROUP *, BIGNUM *r, BN_CTX *); |
169 | | /* private key operations */ |
170 | | size_t (*priv2oct)(const EC_KEY *eckey, unsigned char *buf, size_t len); |
171 | | int (*oct2priv)(EC_KEY *eckey, const unsigned char *buf, size_t len); |
172 | | int (*set_private)(EC_KEY *eckey, const BIGNUM *priv_key); |
173 | | int (*keygen)(EC_KEY *eckey); |
174 | | int (*keycheck)(const EC_KEY *eckey); |
175 | | int (*keygenpub)(EC_KEY *eckey); |
176 | | int (*keycopy)(EC_KEY *dst, const EC_KEY *src); |
177 | | void (*keyfinish)(EC_KEY *eckey); |
178 | | /* custom ECDH operation */ |
179 | | int (*ecdh_compute_key)(unsigned char **pout, size_t *poutlen, |
180 | | const EC_POINT *pub_key, const EC_KEY *ecdh); |
181 | | /* custom ECDSA */ |
182 | | int (*ecdsa_sign_setup)(EC_KEY *eckey, BN_CTX *ctx, BIGNUM **kinvp, |
183 | | BIGNUM **rp); |
184 | | ECDSA_SIG *(*ecdsa_sign_sig)(const unsigned char *dgst, int dgstlen, |
185 | | const BIGNUM *kinv, const BIGNUM *r, |
186 | | EC_KEY *eckey); |
187 | | int (*ecdsa_verify_sig)(const unsigned char *dgst, int dgstlen, |
188 | | const ECDSA_SIG *sig, EC_KEY *eckey); |
189 | | /* Inverse modulo order */ |
190 | | int (*field_inverse_mod_ord)(const EC_GROUP *, BIGNUM *r, |
191 | | const BIGNUM *x, BN_CTX *); |
192 | | int (*blind_coordinates)(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx); |
193 | | int (*ladder_pre)(const EC_GROUP *group, |
194 | | EC_POINT *r, EC_POINT *s, |
195 | | EC_POINT *p, BN_CTX *ctx); |
196 | | int (*ladder_step)(const EC_GROUP *group, |
197 | | EC_POINT *r, EC_POINT *s, |
198 | | EC_POINT *p, BN_CTX *ctx); |
199 | | int (*ladder_post)(const EC_GROUP *group, |
200 | | EC_POINT *r, EC_POINT *s, |
201 | | EC_POINT *p, BN_CTX *ctx); |
202 | | int (*group_full_init)(EC_GROUP *group, const unsigned char *data); |
203 | | }; |
204 | | |
205 | | /* |
206 | | * Types and functions to manipulate pre-computed values. |
207 | | */ |
208 | | typedef struct nistp224_pre_comp_st NISTP224_PRE_COMP; |
209 | | typedef struct nistp256_pre_comp_st NISTP256_PRE_COMP; |
210 | | typedef struct nistp384_pre_comp_st NISTP384_PRE_COMP; |
211 | | typedef struct nistp521_pre_comp_st NISTP521_PRE_COMP; |
212 | | typedef struct nistz256_pre_comp_st NISTZ256_PRE_COMP; |
213 | | typedef struct ec_pre_comp_st EC_PRE_COMP; |
214 | | |
215 | | struct ec_group_st { |
216 | | const EC_METHOD *meth; |
217 | | EC_POINT *generator; /* optional */ |
218 | | BIGNUM *order, *cofactor; |
219 | | int curve_name; /* optional NID for named curve */ |
220 | | int asn1_flag; /* flag to control the asn1 encoding */ |
221 | | int decoded_from_explicit_params; /* set if decoded from explicit |
222 | | * curve parameters encoding */ |
223 | | point_conversion_form_t asn1_form; |
224 | | unsigned char *seed; /* optional seed for parameters (appears in |
225 | | * ASN1) */ |
226 | | size_t seed_len; |
227 | | /* |
228 | | * The following members are handled by the method functions, even if |
229 | | * they appear generic |
230 | | */ |
231 | | /* |
232 | | * Field specification. For curves over GF(p), this is the modulus; for |
233 | | * curves over GF(2^m), this is the irreducible polynomial defining the |
234 | | * field. |
235 | | */ |
236 | | BIGNUM *field; |
237 | | /* |
238 | | * Field specification for curves over GF(2^m). The irreducible f(t) is |
239 | | * then of the form: t^poly[0] + t^poly[1] + ... + t^poly[k] where m = |
240 | | * poly[0] > poly[1] > ... > poly[k] = 0. The array is terminated with |
241 | | * poly[k+1]=-1. All elliptic curve irreducibles have at most 5 non-zero |
242 | | * terms. |
243 | | */ |
244 | | int poly[6]; |
245 | | /* |
246 | | * Curve coefficients. (Here the assumption is that BIGNUMs can be used |
247 | | * or abused for all kinds of fields, not just GF(p).) For characteristic |
248 | | * > 3, the curve is defined by a Weierstrass equation of the form y^2 = |
249 | | * x^3 + a*x + b. For characteristic 2, the curve is defined by an |
250 | | * equation of the form y^2 + x*y = x^3 + a*x^2 + b. |
251 | | */ |
252 | | BIGNUM *a, *b; |
253 | | /* enable optimized point arithmetic for special case */ |
254 | | int a_is_minus3; |
255 | | /* method-specific (e.g., Montgomery structure) */ |
256 | | void *field_data1; |
257 | | /* method-specific */ |
258 | | void *field_data2; |
259 | | /* method-specific */ |
260 | | int (*field_mod_func)(BIGNUM *, const BIGNUM *, const BIGNUM *, |
261 | | BN_CTX *); |
262 | | /* data for ECDSA inverse */ |
263 | | BN_MONT_CTX *mont_data; |
264 | | |
265 | | /* |
266 | | * Precomputed values for speed. The PCT_xxx names match the |
267 | | * pre_comp.xxx union names; see the SETPRECOMP and HAVEPRECOMP |
268 | | * macros, below. |
269 | | */ |
270 | | enum { |
271 | | PCT_none, |
272 | | PCT_nistp224, |
273 | | PCT_nistp256, |
274 | | PCT_nistp384, |
275 | | PCT_nistp521, |
276 | | PCT_nistz256, |
277 | | PCT_ec |
278 | | } pre_comp_type; |
279 | | union { |
280 | | NISTP224_PRE_COMP *nistp224; |
281 | | NISTP256_PRE_COMP *nistp256; |
282 | | NISTP384_PRE_COMP *nistp384; |
283 | | NISTP521_PRE_COMP *nistp521; |
284 | | NISTZ256_PRE_COMP *nistz256; |
285 | | EC_PRE_COMP *ec; |
286 | | } pre_comp; |
287 | | |
288 | | OSSL_LIB_CTX *libctx; |
289 | | char *propq; |
290 | | }; |
291 | | |
292 | | #define SETPRECOMP(g, type, pre) \ |
293 | 0 | g->pre_comp_type = PCT_##type, g->pre_comp.type = pre |
294 | | #define HAVEPRECOMP(g, type) \ |
295 | 0 | g->pre_comp_type == PCT_##type && g->pre_comp.type != NULL |
296 | | |
297 | | struct ec_key_st { |
298 | | const EC_KEY_METHOD *meth; |
299 | | int version; |
300 | | EC_GROUP *group; |
301 | | EC_POINT *pub_key; |
302 | | BIGNUM *priv_key; |
303 | | unsigned int enc_flag; |
304 | | point_conversion_form_t conv_form; |
305 | | CRYPTO_REF_COUNT references; |
306 | | int flags; |
307 | | #ifndef FIPS_MODULE |
308 | | CRYPTO_EX_DATA ex_data; |
309 | | #endif |
310 | | OSSL_LIB_CTX *libctx; |
311 | | char *propq; |
312 | | |
313 | | /* Provider data */ |
314 | | size_t dirty_cnt; /* If any key material changes, increment this */ |
315 | | }; |
316 | | |
317 | | struct ec_point_st { |
318 | | const EC_METHOD *meth; |
319 | | /* NID for the curve if known */ |
320 | | int curve_name; |
321 | | /* |
322 | | * All members except 'meth' are handled by the method functions, even if |
323 | | * they appear generic |
324 | | */ |
325 | | BIGNUM *X; |
326 | | BIGNUM *Y; |
327 | | BIGNUM *Z; /* Jacobian projective coordinates: * (X, Y, |
328 | | * Z) represents (X/Z^2, Y/Z^3) if Z != 0 */ |
329 | | int Z_is_one; /* enable optimized point arithmetic for |
330 | | * special case */ |
331 | | }; |
332 | | |
333 | | static ossl_inline int ec_point_is_compat(const EC_POINT *point, |
334 | | const EC_GROUP *group) |
335 | 0 | { |
336 | 0 | return group->meth == point->meth |
337 | 0 | && (group->curve_name == 0 |
338 | 0 | || point->curve_name == 0 |
339 | 0 | || group->curve_name == point->curve_name); |
340 | 0 | } Unexecuted instantiation: ec_key.c:ec_point_is_compat Unexecuted instantiation: ec_kmeth.c:ec_point_is_compat Unexecuted instantiation: ec_lib.c:ec_point_is_compat Unexecuted instantiation: ec_mult.c:ec_point_is_compat Unexecuted instantiation: ec_oct.c:ec_point_is_compat Unexecuted instantiation: ecdh_ossl.c:ec_point_is_compat Unexecuted instantiation: ecdsa_ossl.c:ec_point_is_compat Unexecuted instantiation: ecdsa_sign.c:ec_point_is_compat Unexecuted instantiation: ecdsa_vrf.c:ec_point_is_compat Unexecuted instantiation: ecp_nistp224.c:ec_point_is_compat Unexecuted instantiation: ecp_nistp256.c:ec_point_is_compat Unexecuted instantiation: ecp_nistp384.c:ec_point_is_compat Unexecuted instantiation: ecp_nistp521.c:ec_point_is_compat Unexecuted instantiation: ecp_nistputil.c:ec_point_is_compat Unexecuted instantiation: ecp_nistz256.c:ec_point_is_compat Unexecuted instantiation: ecp_oct.c:ec_point_is_compat Unexecuted instantiation: ecp_smpl.c:ec_point_is_compat Unexecuted instantiation: curve25519.c:ec_point_is_compat Unexecuted instantiation: ec2_oct.c:ec_point_is_compat Unexecuted instantiation: ec_ameth.c:ec_point_is_compat Unexecuted instantiation: ec_asn1.c:ec_point_is_compat Unexecuted instantiation: ec_backend.c:ec_point_is_compat Unexecuted instantiation: ec_check.c:ec_point_is_compat Unexecuted instantiation: ec_curve.c:ec_point_is_compat Unexecuted instantiation: ec_cvt.c:ec_point_is_compat Unexecuted instantiation: ecdh_kdf.c:ec_point_is_compat Unexecuted instantiation: ecp_mont.c:ec_point_is_compat Unexecuted instantiation: ecp_nist.c:ec_point_is_compat Unexecuted instantiation: ecx_meth.c:ec_point_is_compat Unexecuted instantiation: ec2_smpl.c:ec_point_is_compat |
341 | | |
342 | | NISTP224_PRE_COMP *EC_nistp224_pre_comp_dup(NISTP224_PRE_COMP *); |
343 | | NISTP256_PRE_COMP *EC_nistp256_pre_comp_dup(NISTP256_PRE_COMP *); |
344 | | NISTP384_PRE_COMP *ossl_ec_nistp384_pre_comp_dup(NISTP384_PRE_COMP *); |
345 | | NISTP521_PRE_COMP *EC_nistp521_pre_comp_dup(NISTP521_PRE_COMP *); |
346 | | NISTZ256_PRE_COMP *EC_nistz256_pre_comp_dup(NISTZ256_PRE_COMP *); |
347 | | NISTP256_PRE_COMP *EC_nistp256_pre_comp_dup(NISTP256_PRE_COMP *); |
348 | | EC_PRE_COMP *EC_ec_pre_comp_dup(EC_PRE_COMP *); |
349 | | |
350 | | void EC_pre_comp_free(EC_GROUP *group); |
351 | | void EC_nistp224_pre_comp_free(NISTP224_PRE_COMP *); |
352 | | void EC_nistp256_pre_comp_free(NISTP256_PRE_COMP *); |
353 | | void ossl_ec_nistp384_pre_comp_free(NISTP384_PRE_COMP *); |
354 | | void EC_nistp521_pre_comp_free(NISTP521_PRE_COMP *); |
355 | | void EC_nistz256_pre_comp_free(NISTZ256_PRE_COMP *); |
356 | | void EC_ec_pre_comp_free(EC_PRE_COMP *); |
357 | | |
358 | | /* |
359 | | * method functions in ec_mult.c (ec_lib.c uses these as defaults if |
360 | | * group->method->mul is 0) |
361 | | */ |
362 | | int ossl_ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, |
363 | | size_t num, const EC_POINT *points[], |
364 | | const BIGNUM *scalars[], BN_CTX *); |
365 | | int ossl_ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *); |
366 | | int ossl_ec_wNAF_have_precompute_mult(const EC_GROUP *group); |
367 | | |
368 | | /* method functions in ecp_smpl.c */ |
369 | | int ossl_ec_GFp_simple_group_init(EC_GROUP *); |
370 | | void ossl_ec_GFp_simple_group_finish(EC_GROUP *); |
371 | | void ossl_ec_GFp_simple_group_clear_finish(EC_GROUP *); |
372 | | int ossl_ec_GFp_simple_group_copy(EC_GROUP *, const EC_GROUP *); |
373 | | int ossl_ec_GFp_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, |
374 | | const BIGNUM *a, const BIGNUM *b, |
375 | | BN_CTX *); |
376 | | int ossl_ec_GFp_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, |
377 | | BIGNUM *b, BN_CTX *); |
378 | | int ossl_ec_GFp_simple_group_get_degree(const EC_GROUP *); |
379 | | int ossl_ec_GFp_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *); |
380 | | int ossl_ec_GFp_simple_point_init(EC_POINT *); |
381 | | void ossl_ec_GFp_simple_point_finish(EC_POINT *); |
382 | | void ossl_ec_GFp_simple_point_clear_finish(EC_POINT *); |
383 | | int ossl_ec_GFp_simple_point_copy(EC_POINT *, const EC_POINT *); |
384 | | int ossl_ec_GFp_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *); |
385 | | int ossl_ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *, |
386 | | EC_POINT *, |
387 | | const BIGNUM *x, |
388 | | const BIGNUM *y, |
389 | | const BIGNUM *z, |
390 | | BN_CTX *); |
391 | | int ossl_ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *, |
392 | | const EC_POINT *, |
393 | | BIGNUM *x, |
394 | | BIGNUM *y, BIGNUM *z, |
395 | | BN_CTX *); |
396 | | int ossl_ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *, |
397 | | const BIGNUM *x, |
398 | | const BIGNUM *y, BN_CTX *); |
399 | | int ossl_ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *, |
400 | | const EC_POINT *, BIGNUM *x, |
401 | | BIGNUM *y, BN_CTX *); |
402 | | int ossl_ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *, |
403 | | const BIGNUM *x, int y_bit, |
404 | | BN_CTX *); |
405 | | size_t ossl_ec_GFp_simple_point2oct(const EC_GROUP *, const EC_POINT *, |
406 | | point_conversion_form_t form, |
407 | | unsigned char *buf, size_t len, BN_CTX *); |
408 | | int ossl_ec_GFp_simple_oct2point(const EC_GROUP *, EC_POINT *, |
409 | | const unsigned char *buf, size_t len, BN_CTX *); |
410 | | int ossl_ec_GFp_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, |
411 | | const EC_POINT *b, BN_CTX *); |
412 | | int ossl_ec_GFp_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, |
413 | | BN_CTX *); |
414 | | int ossl_ec_GFp_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *); |
415 | | int ossl_ec_GFp_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *); |
416 | | int ossl_ec_GFp_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *); |
417 | | int ossl_ec_GFp_simple_cmp(const EC_GROUP *, const EC_POINT *a, |
418 | | const EC_POINT *b, BN_CTX *); |
419 | | int ossl_ec_GFp_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *); |
420 | | int ossl_ec_GFp_simple_points_make_affine(const EC_GROUP *, size_t num, |
421 | | EC_POINT *[], BN_CTX *); |
422 | | int ossl_ec_GFp_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
423 | | const BIGNUM *b, BN_CTX *); |
424 | | int ossl_ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
425 | | BN_CTX *); |
426 | | int ossl_ec_GFp_simple_field_inv(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
427 | | BN_CTX *); |
428 | | int ossl_ec_GFp_simple_blind_coordinates(const EC_GROUP *group, EC_POINT *p, |
429 | | BN_CTX *ctx); |
430 | | int ossl_ec_GFp_simple_ladder_pre(const EC_GROUP *group, |
431 | | EC_POINT *r, EC_POINT *s, |
432 | | EC_POINT *p, BN_CTX *ctx); |
433 | | int ossl_ec_GFp_simple_ladder_step(const EC_GROUP *group, |
434 | | EC_POINT *r, EC_POINT *s, |
435 | | EC_POINT *p, BN_CTX *ctx); |
436 | | int ossl_ec_GFp_simple_ladder_post(const EC_GROUP *group, |
437 | | EC_POINT *r, EC_POINT *s, |
438 | | EC_POINT *p, BN_CTX *ctx); |
439 | | |
440 | | /* method functions in ecp_mont.c */ |
441 | | int ossl_ec_GFp_mont_group_init(EC_GROUP *); |
442 | | int ossl_ec_GFp_mont_group_set_curve(EC_GROUP *, const BIGNUM *p, |
443 | | const BIGNUM *a, |
444 | | const BIGNUM *b, BN_CTX *); |
445 | | void ossl_ec_GFp_mont_group_finish(EC_GROUP *); |
446 | | void ossl_ec_GFp_mont_group_clear_finish(EC_GROUP *); |
447 | | int ossl_ec_GFp_mont_group_copy(EC_GROUP *, const EC_GROUP *); |
448 | | int ossl_ec_GFp_mont_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
449 | | const BIGNUM *b, BN_CTX *); |
450 | | int ossl_ec_GFp_mont_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
451 | | BN_CTX *); |
452 | | int ossl_ec_GFp_mont_field_inv(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
453 | | BN_CTX *); |
454 | | int ossl_ec_GFp_mont_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
455 | | BN_CTX *); |
456 | | int ossl_ec_GFp_mont_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
457 | | BN_CTX *); |
458 | | int ossl_ec_GFp_mont_field_set_to_one(const EC_GROUP *, BIGNUM *r, BN_CTX *); |
459 | | |
460 | | /* method functions in ecp_nist.c */ |
461 | | int ossl_ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src); |
462 | | int ossl_ec_GFp_nist_group_set_curve(EC_GROUP *, const BIGNUM *p, |
463 | | const BIGNUM *a, const BIGNUM *b, BN_CTX *); |
464 | | int ossl_ec_GFp_nist_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
465 | | const BIGNUM *b, BN_CTX *); |
466 | | int ossl_ec_GFp_nist_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
467 | | BN_CTX *); |
468 | | |
469 | | /* method functions in ec2_smpl.c */ |
470 | | int ossl_ec_GF2m_simple_group_init(EC_GROUP *); |
471 | | void ossl_ec_GF2m_simple_group_finish(EC_GROUP *); |
472 | | void ossl_ec_GF2m_simple_group_clear_finish(EC_GROUP *); |
473 | | int ossl_ec_GF2m_simple_group_copy(EC_GROUP *, const EC_GROUP *); |
474 | | int ossl_ec_GF2m_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, |
475 | | const BIGNUM *a, const BIGNUM *b, |
476 | | BN_CTX *); |
477 | | int ossl_ec_GF2m_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, |
478 | | BIGNUM *b, BN_CTX *); |
479 | | int ossl_ec_GF2m_simple_group_get_degree(const EC_GROUP *); |
480 | | int ossl_ec_GF2m_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *); |
481 | | int ossl_ec_GF2m_simple_point_init(EC_POINT *); |
482 | | void ossl_ec_GF2m_simple_point_finish(EC_POINT *); |
483 | | void ossl_ec_GF2m_simple_point_clear_finish(EC_POINT *); |
484 | | int ossl_ec_GF2m_simple_point_copy(EC_POINT *, const EC_POINT *); |
485 | | int ossl_ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *); |
486 | | int ossl_ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *, |
487 | | EC_POINT *, |
488 | | const BIGNUM *x, |
489 | | const BIGNUM *y, BN_CTX *); |
490 | | int ossl_ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *, |
491 | | const EC_POINT *, BIGNUM *x, |
492 | | BIGNUM *y, BN_CTX *); |
493 | | int ossl_ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *, |
494 | | const BIGNUM *x, int y_bit, |
495 | | BN_CTX *); |
496 | | size_t ossl_ec_GF2m_simple_point2oct(const EC_GROUP *, const EC_POINT *, |
497 | | point_conversion_form_t form, |
498 | | unsigned char *buf, size_t len, BN_CTX *); |
499 | | int ossl_ec_GF2m_simple_oct2point(const EC_GROUP *, EC_POINT *, |
500 | | const unsigned char *buf, size_t len, BN_CTX *); |
501 | | int ossl_ec_GF2m_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, |
502 | | const EC_POINT *b, BN_CTX *); |
503 | | int ossl_ec_GF2m_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, |
504 | | BN_CTX *); |
505 | | int ossl_ec_GF2m_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *); |
506 | | int ossl_ec_GF2m_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *); |
507 | | int ossl_ec_GF2m_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *); |
508 | | int ossl_ec_GF2m_simple_cmp(const EC_GROUP *, const EC_POINT *a, |
509 | | const EC_POINT *b, BN_CTX *); |
510 | | int ossl_ec_GF2m_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *); |
511 | | int ossl_ec_GF2m_simple_points_make_affine(const EC_GROUP *, size_t num, |
512 | | EC_POINT *[], BN_CTX *); |
513 | | int ossl_ec_GF2m_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
514 | | const BIGNUM *b, BN_CTX *); |
515 | | int ossl_ec_GF2m_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
516 | | BN_CTX *); |
517 | | int ossl_ec_GF2m_simple_field_div(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
518 | | const BIGNUM *b, BN_CTX *); |
519 | | |
520 | | #ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 |
521 | | #ifdef B_ENDIAN |
522 | | #error "Can not enable ec_nistp_64_gcc_128 on big-endian systems" |
523 | | #endif |
524 | | |
525 | | /* method functions in ecp_nistp224.c */ |
526 | | int ossl_ec_GFp_nistp224_group_init(EC_GROUP *group); |
527 | | int ossl_ec_GFp_nistp224_group_set_curve(EC_GROUP *group, const BIGNUM *p, |
528 | | const BIGNUM *a, const BIGNUM *n, |
529 | | BN_CTX *); |
530 | | int ossl_ec_GFp_nistp224_point_get_affine_coordinates(const EC_GROUP *group, |
531 | | const EC_POINT *point, |
532 | | BIGNUM *x, BIGNUM *y, |
533 | | BN_CTX *ctx); |
534 | | int ossl_ec_GFp_nistp224_mul(const EC_GROUP *group, EC_POINT *r, |
535 | | const BIGNUM *scalar, size_t num, |
536 | | const EC_POINT *points[], const BIGNUM *scalars[], |
537 | | BN_CTX *); |
538 | | int ossl_ec_GFp_nistp224_points_mul(const EC_GROUP *group, EC_POINT *r, |
539 | | const BIGNUM *scalar, size_t num, |
540 | | const EC_POINT *points[], |
541 | | const BIGNUM *scalars[], BN_CTX *ctx); |
542 | | int ossl_ec_GFp_nistp224_precompute_mult(EC_GROUP *group, BN_CTX *ctx); |
543 | | int ossl_ec_GFp_nistp224_have_precompute_mult(const EC_GROUP *group); |
544 | | |
545 | | /* method functions in ecp_nistp256.c */ |
546 | | int ossl_ec_GFp_nistp256_group_init(EC_GROUP *group); |
547 | | int ossl_ec_GFp_nistp256_group_set_curve(EC_GROUP *group, const BIGNUM *p, |
548 | | const BIGNUM *a, const BIGNUM *n, |
549 | | BN_CTX *); |
550 | | int ossl_ec_GFp_nistp256_point_get_affine_coordinates(const EC_GROUP *group, |
551 | | const EC_POINT *point, |
552 | | BIGNUM *x, BIGNUM *y, |
553 | | BN_CTX *ctx); |
554 | | int ossl_ec_GFp_nistp256_mul(const EC_GROUP *group, EC_POINT *r, |
555 | | const BIGNUM *scalar, size_t num, |
556 | | const EC_POINT *points[], const BIGNUM *scalars[], |
557 | | BN_CTX *); |
558 | | int ossl_ec_GFp_nistp256_points_mul(const EC_GROUP *group, EC_POINT *r, |
559 | | const BIGNUM *scalar, size_t num, |
560 | | const EC_POINT *points[], |
561 | | const BIGNUM *scalars[], BN_CTX *ctx); |
562 | | int ossl_ec_GFp_nistp256_precompute_mult(EC_GROUP *group, BN_CTX *ctx); |
563 | | int ossl_ec_GFp_nistp256_have_precompute_mult(const EC_GROUP *group); |
564 | | |
565 | | /* method functions in ecp_nistp384.c */ |
566 | | int ossl_ec_GFp_nistp384_group_init(EC_GROUP *group); |
567 | | int ossl_ec_GFp_nistp384_group_set_curve(EC_GROUP *group, const BIGNUM *p, |
568 | | const BIGNUM *a, const BIGNUM *n, |
569 | | BN_CTX *); |
570 | | int ossl_ec_GFp_nistp384_point_get_affine_coordinates(const EC_GROUP *group, |
571 | | const EC_POINT *point, |
572 | | BIGNUM *x, BIGNUM *y, |
573 | | BN_CTX *ctx); |
574 | | int ossl_ec_GFp_nistp384_mul(const EC_GROUP *group, EC_POINT *r, |
575 | | const BIGNUM *scalar, size_t num, |
576 | | const EC_POINT *points[], const BIGNUM *scalars[], |
577 | | BN_CTX *); |
578 | | int ossl_ec_GFp_nistp384_points_mul(const EC_GROUP *group, EC_POINT *r, |
579 | | const BIGNUM *scalar, size_t num, |
580 | | const EC_POINT *points[], |
581 | | const BIGNUM *scalars[], BN_CTX *ctx); |
582 | | int ossl_ec_GFp_nistp384_precompute_mult(EC_GROUP *group, BN_CTX *ctx); |
583 | | int ossl_ec_GFp_nistp384_have_precompute_mult(const EC_GROUP *group); |
584 | | const EC_METHOD *ossl_ec_GFp_nistp384_method(void); |
585 | | |
586 | | /* method functions in ecp_nistp521.c */ |
587 | | int ossl_ec_GFp_nistp521_group_init(EC_GROUP *group); |
588 | | int ossl_ec_GFp_nistp521_group_set_curve(EC_GROUP *group, const BIGNUM *p, |
589 | | const BIGNUM *a, const BIGNUM *n, |
590 | | BN_CTX *); |
591 | | int ossl_ec_GFp_nistp521_point_get_affine_coordinates(const EC_GROUP *group, |
592 | | const EC_POINT *point, |
593 | | BIGNUM *x, BIGNUM *y, |
594 | | BN_CTX *ctx); |
595 | | int ossl_ec_GFp_nistp521_mul(const EC_GROUP *group, EC_POINT *r, |
596 | | const BIGNUM *scalar, size_t num, |
597 | | const EC_POINT *points[], const BIGNUM *scalars[], |
598 | | BN_CTX *); |
599 | | int ossl_ec_GFp_nistp521_points_mul(const EC_GROUP *group, EC_POINT *r, |
600 | | const BIGNUM *scalar, size_t num, |
601 | | const EC_POINT *points[], |
602 | | const BIGNUM *scalars[], BN_CTX *ctx); |
603 | | int ossl_ec_GFp_nistp521_precompute_mult(EC_GROUP *group, BN_CTX *ctx); |
604 | | int ossl_ec_GFp_nistp521_have_precompute_mult(const EC_GROUP *group); |
605 | | |
606 | | /* utility functions in ecp_nistputil.c */ |
607 | | void ossl_ec_GFp_nistp_points_make_affine_internal(size_t num, void *point_array, |
608 | | size_t felem_size, |
609 | | void *tmp_felems, |
610 | | void (*felem_one)(void *out), |
611 | | int (*felem_is_zero)(const void *in), |
612 | | void (*felem_assign)(void *out, const void *in), |
613 | | void (*felem_square)(void *out, const void *in), |
614 | | void (*felem_mul)(void *out, |
615 | | const void *in1, |
616 | | const void *in2), |
617 | | void (*felem_inv)(void *out, const void *in), |
618 | | void (*felem_contract)(void *out, const void *in)); |
619 | | void ossl_ec_GFp_nistp_recode_scalar_bits(unsigned char *sign, |
620 | | unsigned char *digit, |
621 | | unsigned char in); |
622 | | #endif |
623 | | int ossl_ec_group_simple_order_bits(const EC_GROUP *group); |
624 | | |
625 | | /** |
626 | | * Creates a new EC_GROUP object |
627 | | * \param libctx The associated library context or NULL for the default |
628 | | * library context |
629 | | * \param propq Any property query string |
630 | | * \param meth EC_METHOD to use |
631 | | * \return newly created EC_GROUP object or NULL in case of an error. |
632 | | */ |
633 | | EC_GROUP *ossl_ec_group_new_ex(OSSL_LIB_CTX *libctx, const char *propq, |
634 | | const EC_METHOD *meth); |
635 | | |
636 | | #ifdef ECP_NISTZ256_ASM |
637 | | /** Returns GFp methods using montgomery multiplication, with x86-64 optimized |
638 | | * P256. See http://eprint.iacr.org/2013/816. |
639 | | * \return EC_METHOD object |
640 | | */ |
641 | | const EC_METHOD *EC_GFp_nistz256_method(void); |
642 | | #endif |
643 | | #ifdef S390X_EC_ASM |
644 | | const EC_METHOD *EC_GFp_s390x_nistp256_method(void); |
645 | | const EC_METHOD *EC_GFp_s390x_nistp384_method(void); |
646 | | const EC_METHOD *EC_GFp_s390x_nistp521_method(void); |
647 | | #endif |
648 | | |
649 | | size_t ossl_ec_key_simple_priv2oct(const EC_KEY *eckey, |
650 | | unsigned char *buf, size_t len); |
651 | | int ossl_ec_key_simple_oct2priv(EC_KEY *eckey, const unsigned char *buf, |
652 | | size_t len); |
653 | | int ossl_ec_key_simple_generate_key(EC_KEY *eckey); |
654 | | int ossl_ec_key_simple_generate_public_key(EC_KEY *eckey); |
655 | | int ossl_ec_key_simple_check_key(const EC_KEY *eckey); |
656 | | |
657 | | #ifdef ECP_SM2P256_ASM |
658 | | /* Returns optimized methods for SM2 */ |
659 | | const EC_METHOD *EC_GFp_sm2p256_method(void); |
660 | | #endif |
661 | | |
662 | | int ossl_ec_curve_nid_from_params(const EC_GROUP *group, BN_CTX *ctx); |
663 | | |
664 | | /* EC_METHOD definitions */ |
665 | | |
666 | | struct ec_key_method_st { |
667 | | const char *name; |
668 | | int32_t flags; |
669 | | int (*init)(EC_KEY *key); |
670 | | void (*finish)(EC_KEY *key); |
671 | | int (*copy)(EC_KEY *dest, const EC_KEY *src); |
672 | | int (*set_group)(EC_KEY *key, const EC_GROUP *grp); |
673 | | int (*set_private)(EC_KEY *key, const BIGNUM *priv_key); |
674 | | int (*set_public)(EC_KEY *key, const EC_POINT *pub_key); |
675 | | int (*keygen)(EC_KEY *key); |
676 | | int (*compute_key)(unsigned char **pout, size_t *poutlen, |
677 | | const EC_POINT *pub_key, const EC_KEY *ecdh); |
678 | | int (*sign)(int type, const unsigned char *dgst, int dlen, unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv, |
679 | | const BIGNUM *r, EC_KEY *eckey); |
680 | | int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, |
681 | | BIGNUM **rp); |
682 | | ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, int dgst_len, |
683 | | const BIGNUM *in_kinv, const BIGNUM *in_r, |
684 | | EC_KEY *eckey); |
685 | | |
686 | | int (*verify)(int type, const unsigned char *dgst, int dgst_len, |
687 | | const unsigned char *sigbuf, int sig_len, EC_KEY *eckey); |
688 | | int (*verify_sig)(const unsigned char *dgst, int dgst_len, |
689 | | const ECDSA_SIG *sig, EC_KEY *eckey); |
690 | | }; |
691 | | |
692 | 0 | #define EC_KEY_METHOD_DYNAMIC 1 |
693 | | |
694 | | EC_KEY *ossl_ec_key_new_method_int(OSSL_LIB_CTX *libctx, const char *propq); |
695 | | |
696 | | int ossl_ec_key_gen(EC_KEY *eckey); |
697 | | int ossl_ecdh_compute_key(unsigned char **pout, size_t *poutlen, |
698 | | const EC_POINT *pub_key, const EC_KEY *ecdh); |
699 | | int ossl_ecdh_simple_compute_key(unsigned char **pout, size_t *poutlen, |
700 | | const EC_POINT *pub_key, const EC_KEY *ecdh); |
701 | | |
702 | | struct ECDSA_SIG_st { |
703 | | BIGNUM *r; |
704 | | BIGNUM *s; |
705 | | }; |
706 | | |
707 | | int ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, |
708 | | BIGNUM **rp); |
709 | | int ossl_ecdsa_sign(int type, const unsigned char *dgst, int dlen, |
710 | | unsigned char *sig, unsigned int *siglen, |
711 | | const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey); |
712 | | ECDSA_SIG *ossl_ecdsa_sign_sig(const unsigned char *dgst, int dgst_len, |
713 | | const BIGNUM *in_kinv, const BIGNUM *in_r, |
714 | | EC_KEY *eckey); |
715 | | int ossl_ecdsa_verify(int type, const unsigned char *dgst, int dgst_len, |
716 | | const unsigned char *sigbuf, int sig_len, EC_KEY *eckey); |
717 | | int ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len, |
718 | | const ECDSA_SIG *sig, EC_KEY *eckey); |
719 | | int ossl_ecdsa_simple_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, |
720 | | BIGNUM **rp); |
721 | | ECDSA_SIG *ossl_ecdsa_simple_sign_sig(const unsigned char *dgst, int dgst_len, |
722 | | const BIGNUM *in_kinv, const BIGNUM *in_r, |
723 | | EC_KEY *eckey); |
724 | | int ossl_ecdsa_simple_verify_sig(const unsigned char *dgst, int dgst_len, |
725 | | const ECDSA_SIG *sig, EC_KEY *eckey); |
726 | | |
727 | | /*- |
728 | | * This functions computes a single point multiplication over the EC group, |
729 | | * using, at a high level, a Montgomery ladder with conditional swaps, with |
730 | | * various timing attack defenses. |
731 | | * |
732 | | * It performs either a fixed point multiplication |
733 | | * (scalar * generator) |
734 | | * when point is NULL, or a variable point multiplication |
735 | | * (scalar * point) |
736 | | * when point is not NULL. |
737 | | * |
738 | | * `scalar` cannot be NULL and should be in the range [0,n) otherwise all |
739 | | * constant time bets are off (where n is the cardinality of the EC group). |
740 | | * |
741 | | * This function expects `group->order` and `group->cardinality` to be well |
742 | | * defined and non-zero: it fails with an error code otherwise. |
743 | | * |
744 | | * NB: This says nothing about the constant-timeness of the ladder step |
745 | | * implementation (i.e., the default implementation is based on EC_POINT_add and |
746 | | * EC_POINT_dbl, which of course are not constant time themselves) or the |
747 | | * underlying multiprecision arithmetic. |
748 | | * |
749 | | * The product is stored in `r`. |
750 | | * |
751 | | * This is an internal function: callers are in charge of ensuring that the |
752 | | * input parameters `group`, `r`, `scalar` and `ctx` are not NULL. |
753 | | * |
754 | | * Returns 1 on success, 0 otherwise. |
755 | | */ |
756 | | int ossl_ec_scalar_mul_ladder(const EC_GROUP *group, EC_POINT *r, |
757 | | const BIGNUM *scalar, const EC_POINT *point, |
758 | | BN_CTX *ctx); |
759 | | |
760 | | int ossl_ec_point_blind_coordinates(const EC_GROUP *group, EC_POINT *p, |
761 | | BN_CTX *ctx); |
762 | | |
763 | | static ossl_inline int ec_point_ladder_pre(const EC_GROUP *group, |
764 | | EC_POINT *r, EC_POINT *s, |
765 | | EC_POINT *p, BN_CTX *ctx) |
766 | 0 | { |
767 | 0 | if (group->meth->ladder_pre != NULL) |
768 | 0 | return group->meth->ladder_pre(group, r, s, p, ctx); |
769 | | |
770 | 0 | if (!EC_POINT_copy(s, p) |
771 | 0 | || !EC_POINT_dbl(group, r, s, ctx)) |
772 | 0 | return 0; |
773 | | |
774 | 0 | return 1; |
775 | 0 | } Unexecuted instantiation: ec_key.c:ec_point_ladder_pre Unexecuted instantiation: ec_kmeth.c:ec_point_ladder_pre Unexecuted instantiation: ec_lib.c:ec_point_ladder_pre Unexecuted instantiation: ec_mult.c:ec_point_ladder_pre Unexecuted instantiation: ec_oct.c:ec_point_ladder_pre Unexecuted instantiation: ecdh_ossl.c:ec_point_ladder_pre Unexecuted instantiation: ecdsa_ossl.c:ec_point_ladder_pre Unexecuted instantiation: ecdsa_sign.c:ec_point_ladder_pre Unexecuted instantiation: ecdsa_vrf.c:ec_point_ladder_pre Unexecuted instantiation: ecp_nistp224.c:ec_point_ladder_pre Unexecuted instantiation: ecp_nistp256.c:ec_point_ladder_pre Unexecuted instantiation: ecp_nistp384.c:ec_point_ladder_pre Unexecuted instantiation: ecp_nistp521.c:ec_point_ladder_pre Unexecuted instantiation: ecp_nistputil.c:ec_point_ladder_pre Unexecuted instantiation: ecp_nistz256.c:ec_point_ladder_pre Unexecuted instantiation: ecp_oct.c:ec_point_ladder_pre Unexecuted instantiation: ecp_smpl.c:ec_point_ladder_pre Unexecuted instantiation: curve25519.c:ec_point_ladder_pre Unexecuted instantiation: ec2_oct.c:ec_point_ladder_pre Unexecuted instantiation: ec_ameth.c:ec_point_ladder_pre Unexecuted instantiation: ec_asn1.c:ec_point_ladder_pre Unexecuted instantiation: ec_backend.c:ec_point_ladder_pre Unexecuted instantiation: ec_check.c:ec_point_ladder_pre Unexecuted instantiation: ec_curve.c:ec_point_ladder_pre Unexecuted instantiation: ec_cvt.c:ec_point_ladder_pre Unexecuted instantiation: ecdh_kdf.c:ec_point_ladder_pre Unexecuted instantiation: ecp_mont.c:ec_point_ladder_pre Unexecuted instantiation: ecp_nist.c:ec_point_ladder_pre Unexecuted instantiation: ecx_meth.c:ec_point_ladder_pre Unexecuted instantiation: ec2_smpl.c:ec_point_ladder_pre |
776 | | |
777 | | static ossl_inline int ec_point_ladder_step(const EC_GROUP *group, |
778 | | EC_POINT *r, EC_POINT *s, |
779 | | EC_POINT *p, BN_CTX *ctx) |
780 | 0 | { |
781 | 0 | if (group->meth->ladder_step != NULL) |
782 | 0 | return group->meth->ladder_step(group, r, s, p, ctx); |
783 | | |
784 | 0 | if (!EC_POINT_add(group, s, r, s, ctx) |
785 | 0 | || !EC_POINT_dbl(group, r, r, ctx)) |
786 | 0 | return 0; |
787 | | |
788 | 0 | return 1; |
789 | 0 | } Unexecuted instantiation: ec_key.c:ec_point_ladder_step Unexecuted instantiation: ec_kmeth.c:ec_point_ladder_step Unexecuted instantiation: ec_lib.c:ec_point_ladder_step Unexecuted instantiation: ec_mult.c:ec_point_ladder_step Unexecuted instantiation: ec_oct.c:ec_point_ladder_step Unexecuted instantiation: ecdh_ossl.c:ec_point_ladder_step Unexecuted instantiation: ecdsa_ossl.c:ec_point_ladder_step Unexecuted instantiation: ecdsa_sign.c:ec_point_ladder_step Unexecuted instantiation: ecdsa_vrf.c:ec_point_ladder_step Unexecuted instantiation: ecp_nistp224.c:ec_point_ladder_step Unexecuted instantiation: ecp_nistp256.c:ec_point_ladder_step Unexecuted instantiation: ecp_nistp384.c:ec_point_ladder_step Unexecuted instantiation: ecp_nistp521.c:ec_point_ladder_step Unexecuted instantiation: ecp_nistputil.c:ec_point_ladder_step Unexecuted instantiation: ecp_nistz256.c:ec_point_ladder_step Unexecuted instantiation: ecp_oct.c:ec_point_ladder_step Unexecuted instantiation: ecp_smpl.c:ec_point_ladder_step Unexecuted instantiation: curve25519.c:ec_point_ladder_step Unexecuted instantiation: ec2_oct.c:ec_point_ladder_step Unexecuted instantiation: ec_ameth.c:ec_point_ladder_step Unexecuted instantiation: ec_asn1.c:ec_point_ladder_step Unexecuted instantiation: ec_backend.c:ec_point_ladder_step Unexecuted instantiation: ec_check.c:ec_point_ladder_step Unexecuted instantiation: ec_curve.c:ec_point_ladder_step Unexecuted instantiation: ec_cvt.c:ec_point_ladder_step Unexecuted instantiation: ecdh_kdf.c:ec_point_ladder_step Unexecuted instantiation: ecp_mont.c:ec_point_ladder_step Unexecuted instantiation: ecp_nist.c:ec_point_ladder_step Unexecuted instantiation: ecx_meth.c:ec_point_ladder_step Unexecuted instantiation: ec2_smpl.c:ec_point_ladder_step |
790 | | |
791 | | static ossl_inline int ec_point_ladder_post(const EC_GROUP *group, |
792 | | EC_POINT *r, EC_POINT *s, |
793 | | EC_POINT *p, BN_CTX *ctx) |
794 | 0 | { |
795 | 0 | if (group->meth->ladder_post != NULL) |
796 | 0 | return group->meth->ladder_post(group, r, s, p, ctx); |
797 | | |
798 | 0 | return 1; |
799 | 0 | } Unexecuted instantiation: ec_key.c:ec_point_ladder_post Unexecuted instantiation: ec_kmeth.c:ec_point_ladder_post Unexecuted instantiation: ec_lib.c:ec_point_ladder_post Unexecuted instantiation: ec_mult.c:ec_point_ladder_post Unexecuted instantiation: ec_oct.c:ec_point_ladder_post Unexecuted instantiation: ecdh_ossl.c:ec_point_ladder_post Unexecuted instantiation: ecdsa_ossl.c:ec_point_ladder_post Unexecuted instantiation: ecdsa_sign.c:ec_point_ladder_post Unexecuted instantiation: ecdsa_vrf.c:ec_point_ladder_post Unexecuted instantiation: ecp_nistp224.c:ec_point_ladder_post Unexecuted instantiation: ecp_nistp256.c:ec_point_ladder_post Unexecuted instantiation: ecp_nistp384.c:ec_point_ladder_post Unexecuted instantiation: ecp_nistp521.c:ec_point_ladder_post Unexecuted instantiation: ecp_nistputil.c:ec_point_ladder_post Unexecuted instantiation: ecp_nistz256.c:ec_point_ladder_post Unexecuted instantiation: ecp_oct.c:ec_point_ladder_post Unexecuted instantiation: ecp_smpl.c:ec_point_ladder_post Unexecuted instantiation: curve25519.c:ec_point_ladder_post Unexecuted instantiation: ec2_oct.c:ec_point_ladder_post Unexecuted instantiation: ec_ameth.c:ec_point_ladder_post Unexecuted instantiation: ec_asn1.c:ec_point_ladder_post Unexecuted instantiation: ec_backend.c:ec_point_ladder_post Unexecuted instantiation: ec_check.c:ec_point_ladder_post Unexecuted instantiation: ec_curve.c:ec_point_ladder_post Unexecuted instantiation: ec_cvt.c:ec_point_ladder_post Unexecuted instantiation: ecdh_kdf.c:ec_point_ladder_post Unexecuted instantiation: ecp_mont.c:ec_point_ladder_post Unexecuted instantiation: ecp_nist.c:ec_point_ladder_post Unexecuted instantiation: ecx_meth.c:ec_point_ladder_post Unexecuted instantiation: ec2_smpl.c:ec_point_ladder_post |
800 | | |
801 | | #endif /* !defined(OSSL_LIBCRYPTO_EC_EC_LOCAL_H) */ |