source: EcnlProtoTool/trunk/openssl-1.1.0e/crypto/ec/ec_lcl.h@ 331

Last change on this file since 331 was 331, checked in by coas-nagasima, 6 years ago

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr
File size: 29.1 KB
Line 
1/*
2 * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10/* ====================================================================
11 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
12 *
13 * Portions of the attached software ("Contribution") are developed by
14 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
15 *
16 * The Contribution is licensed pursuant to the OpenSSL open source
17 * license provided above.
18 *
19 * The elliptic curve binary polynomial software is originally written by
20 * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
21 *
22 */
23
24#include <stdlib.h>
25
26#include <openssl/obj_mac.h>
27#include <openssl/ec.h>
28#include <openssl/bn.h>
29
30#include "e_os.h"
31
32#if defined(__SUNPRO_C)
33# if __SUNPRO_C >= 0x520
34# pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
35# endif
36#endif
37
38/* Use default functions for poin2oct, oct2point and compressed coordinates */
39#define EC_FLAGS_DEFAULT_OCT 0x1
40
41/* Use custom formats for EC_GROUP, EC_POINT and EC_KEY */
42#define EC_FLAGS_CUSTOM_CURVE 0x2
43
44/* Curve does not support signing operations */
45#define EC_FLAGS_NO_SIGN 0x4
46
47/*
48 * Structure details are not part of the exported interface, so all this may
49 * change in future versions.
50 */
51
52struct ec_method_st {
53 /* Various method flags */
54 int flags;
55 /* used by EC_METHOD_get_field_type: */
56 int field_type; /* a NID */
57 /*
58 * used by EC_GROUP_new, EC_GROUP_free, EC_GROUP_clear_free,
59 * EC_GROUP_copy:
60 */
61 int (*group_init) (EC_GROUP *);
62 void (*group_finish) (EC_GROUP *);
63 void (*group_clear_finish) (EC_GROUP *);
64 int (*group_copy) (EC_GROUP *, const EC_GROUP *);
65 /* used by EC_GROUP_set_curve_GFp, EC_GROUP_get_curve_GFp, */
66 /* EC_GROUP_set_curve_GF2m, and EC_GROUP_get_curve_GF2m: */
67 int (*group_set_curve) (EC_GROUP *, const BIGNUM *p, const BIGNUM *a,
68 const BIGNUM *b, BN_CTX *);
69 int (*group_get_curve) (const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b,
70 BN_CTX *);
71 /* used by EC_GROUP_get_degree: */
72 int (*group_get_degree) (const EC_GROUP *);
73 int (*group_order_bits) (const EC_GROUP *);
74 /* used by EC_GROUP_check: */
75 int (*group_check_discriminant) (const EC_GROUP *, BN_CTX *);
76 /*
77 * used by EC_POINT_new, EC_POINT_free, EC_POINT_clear_free,
78 * EC_POINT_copy:
79 */
80 int (*point_init) (EC_POINT *);
81 void (*point_finish) (EC_POINT *);
82 void (*point_clear_finish) (EC_POINT *);
83 int (*point_copy) (EC_POINT *, const EC_POINT *);
84 /*-
85 * used by EC_POINT_set_to_infinity,
86 * EC_POINT_set_Jprojective_coordinates_GFp,
87 * EC_POINT_get_Jprojective_coordinates_GFp,
88 * EC_POINT_set_affine_coordinates_GFp, ..._GF2m,
89 * EC_POINT_get_affine_coordinates_GFp, ..._GF2m,
90 * EC_POINT_set_compressed_coordinates_GFp, ..._GF2m:
91 */
92 int (*point_set_to_infinity) (const EC_GROUP *, EC_POINT *);
93 int (*point_set_Jprojective_coordinates_GFp) (const EC_GROUP *,
94 EC_POINT *, const BIGNUM *x,
95 const BIGNUM *y,
96 const BIGNUM *z, BN_CTX *);
97 int (*point_get_Jprojective_coordinates_GFp) (const EC_GROUP *,
98 const EC_POINT *, BIGNUM *x,
99 BIGNUM *y, BIGNUM *z,
100 BN_CTX *);
101 int (*point_set_affine_coordinates) (const EC_GROUP *, EC_POINT *,
102 const BIGNUM *x, const BIGNUM *y,
103 BN_CTX *);
104 int (*point_get_affine_coordinates) (const EC_GROUP *, const EC_POINT *,
105 BIGNUM *x, BIGNUM *y, BN_CTX *);
106 int (*point_set_compressed_coordinates) (const EC_GROUP *, EC_POINT *,
107 const BIGNUM *x, int y_bit,
108 BN_CTX *);
109 /* used by EC_POINT_point2oct, EC_POINT_oct2point: */
110 size_t (*point2oct) (const EC_GROUP *, const EC_POINT *,
111 point_conversion_form_t form, unsigned char *buf,
112 size_t len, BN_CTX *);
113 int (*oct2point) (const EC_GROUP *, EC_POINT *, const unsigned char *buf,
114 size_t len, BN_CTX *);
115 /* used by EC_POINT_add, EC_POINT_dbl, ECP_POINT_invert: */
116 int (*add) (const EC_GROUP *, EC_POINT *r, const EC_POINT *a,
117 const EC_POINT *b, BN_CTX *);
118 int (*dbl) (const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
119 int (*invert) (const EC_GROUP *, EC_POINT *, BN_CTX *);
120 /*
121 * used by EC_POINT_is_at_infinity, EC_POINT_is_on_curve, EC_POINT_cmp:
122 */
123 int (*is_at_infinity) (const EC_GROUP *, const EC_POINT *);
124 int (*is_on_curve) (const EC_GROUP *, const EC_POINT *, BN_CTX *);
125 int (*point_cmp) (const EC_GROUP *, const EC_POINT *a, const EC_POINT *b,
126 BN_CTX *);
127 /* used by EC_POINT_make_affine, EC_POINTs_make_affine: */
128 int (*make_affine) (const EC_GROUP *, EC_POINT *, BN_CTX *);
129 int (*points_make_affine) (const EC_GROUP *, size_t num, EC_POINT *[],
130 BN_CTX *);
131 /*
132 * used by EC_POINTs_mul, EC_POINT_mul, EC_POINT_precompute_mult,
133 * EC_POINT_have_precompute_mult (default implementations are used if the
134 * 'mul' pointer is 0):
135 */
136 int (*mul) (const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
137 size_t num, const EC_POINT *points[], const BIGNUM *scalars[],
138 BN_CTX *);
139 int (*precompute_mult) (EC_GROUP *group, BN_CTX *);
140 int (*have_precompute_mult) (const EC_GROUP *group);
141 /* internal functions */
142 /*
143 * 'field_mul', 'field_sqr', and 'field_div' can be used by 'add' and
144 * 'dbl' so that the same implementations of point operations can be used
145 * with different optimized implementations of expensive field
146 * operations:
147 */
148 int (*field_mul) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
149 const BIGNUM *b, BN_CTX *);
150 int (*field_sqr) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
151 int (*field_div) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
152 const BIGNUM *b, BN_CTX *);
153 /* e.g. to Montgomery */
154 int (*field_encode) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
155 BN_CTX *);
156 /* e.g. from Montgomery */
157 int (*field_decode) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
158 BN_CTX *);
159 int (*field_set_to_one) (const EC_GROUP *, BIGNUM *r, BN_CTX *);
160 /* private key operations */
161 size_t (*priv2oct)(const EC_KEY *eckey, unsigned char *buf, size_t len);
162 int (*oct2priv)(EC_KEY *eckey, const unsigned char *buf, size_t len);
163 int (*set_private)(EC_KEY *eckey, const BIGNUM *priv_key);
164 int (*keygen)(EC_KEY *eckey);
165 int (*keycheck)(const EC_KEY *eckey);
166 int (*keygenpub)(EC_KEY *eckey);
167 int (*keycopy)(EC_KEY *dst, const EC_KEY *src);
168 void (*keyfinish)(EC_KEY *eckey);
169 /* custom ECDH operation */
170 int (*ecdh_compute_key)(unsigned char **pout, size_t *poutlen,
171 const EC_POINT *pub_key, const EC_KEY *ecdh);
172};
173
174/*
175 * Types and functions to manipulate pre-computed values.
176 */
177typedef struct nistp224_pre_comp_st NISTP224_PRE_COMP;
178typedef struct nistp256_pre_comp_st NISTP256_PRE_COMP;
179typedef struct nistp521_pre_comp_st NISTP521_PRE_COMP;
180typedef struct nistz256_pre_comp_st NISTZ256_PRE_COMP;
181typedef struct ec_pre_comp_st EC_PRE_COMP;
182
183struct ec_group_st {
184 const EC_METHOD *meth;
185 EC_POINT *generator; /* optional */
186 BIGNUM *order, *cofactor;
187 int curve_name; /* optional NID for named curve */
188 int asn1_flag; /* flag to control the asn1 encoding */
189 point_conversion_form_t asn1_form;
190 unsigned char *seed; /* optional seed for parameters (appears in
191 * ASN1) */
192 size_t seed_len;
193 /*
194 * The following members are handled by the method functions, even if
195 * they appear generic
196 */
197 /*
198 * Field specification. For curves over GF(p), this is the modulus; for
199 * curves over GF(2^m), this is the irreducible polynomial defining the
200 * field.
201 */
202 BIGNUM *field;
203 /*
204 * Field specification for curves over GF(2^m). The irreducible f(t) is
205 * then of the form: t^poly[0] + t^poly[1] + ... + t^poly[k] where m =
206 * poly[0] > poly[1] > ... > poly[k] = 0. The array is terminated with
207 * poly[k+1]=-1. All elliptic curve irreducibles have at most 5 non-zero
208 * terms.
209 */
210 int poly[6];
211 /*
212 * Curve coefficients. (Here the assumption is that BIGNUMs can be used
213 * or abused for all kinds of fields, not just GF(p).) For characteristic
214 * > 3, the curve is defined by a Weierstrass equation of the form y^2 =
215 * x^3 + a*x + b. For characteristic 2, the curve is defined by an
216 * equation of the form y^2 + x*y = x^3 + a*x^2 + b.
217 */
218 BIGNUM *a, *b;
219 /* enable optimized point arithmetics for special case */
220 int a_is_minus3;
221 /* method-specific (e.g., Montgomery structure) */
222 void *field_data1;
223 /* method-specific */
224 void *field_data2;
225 /* method-specific */
226 int (*field_mod_func) (BIGNUM *, const BIGNUM *, const BIGNUM *,
227 BN_CTX *);
228 /* data for ECDSA inverse */
229 BN_MONT_CTX *mont_data;
230
231 /*
232 * Precomputed values for speed. The PCT_xxx names match the
233 * pre_comp.xxx union names; see the SETPRECOMP and HAVEPRECOMP
234 * macros, below.
235 */
236 enum {
237 PCT_none,
238 PCT_nistp224, PCT_nistp256, PCT_nistp521, PCT_nistz256,
239 PCT_ec
240 } pre_comp_type;
241 union {
242 NISTP224_PRE_COMP *nistp224;
243 NISTP256_PRE_COMP *nistp256;
244 NISTP521_PRE_COMP *nistp521;
245 NISTZ256_PRE_COMP *nistz256;
246 EC_PRE_COMP *ec;
247 } pre_comp;
248};
249
250#define SETPRECOMP(g, type, pre) \
251 g->pre_comp_type = PCT_##type, g->pre_comp.type = pre
252#define HAVEPRECOMP(g, type) \
253 g->pre_comp_type == PCT_##type && g->pre_comp.type != NULL
254
255struct ec_key_st {
256 const EC_KEY_METHOD *meth;
257 ENGINE *engine;
258 int version;
259 EC_GROUP *group;
260 EC_POINT *pub_key;
261 BIGNUM *priv_key;
262 unsigned int enc_flag;
263 point_conversion_form_t conv_form;
264 int references;
265 int flags;
266 CRYPTO_EX_DATA ex_data;
267 CRYPTO_RWLOCK *lock;
268};
269
270struct ec_point_st {
271 const EC_METHOD *meth;
272 /*
273 * All members except 'meth' are handled by the method functions, even if
274 * they appear generic
275 */
276 BIGNUM *X;
277 BIGNUM *Y;
278 BIGNUM *Z; /* Jacobian projective coordinates: * (X, Y,
279 * Z) represents (X/Z^2, Y/Z^3) if Z != 0 */
280 int Z_is_one; /* enable optimized point arithmetics for
281 * special case */
282};
283
284NISTP224_PRE_COMP *EC_nistp224_pre_comp_dup(NISTP224_PRE_COMP *);
285NISTP256_PRE_COMP *EC_nistp256_pre_comp_dup(NISTP256_PRE_COMP *);
286NISTP521_PRE_COMP *EC_nistp521_pre_comp_dup(NISTP521_PRE_COMP *);
287NISTZ256_PRE_COMP *EC_nistz256_pre_comp_dup(NISTZ256_PRE_COMP *);
288NISTP256_PRE_COMP *EC_nistp256_pre_comp_dup(NISTP256_PRE_COMP *);
289EC_PRE_COMP *EC_ec_pre_comp_dup(EC_PRE_COMP *);
290
291void EC_pre_comp_free(EC_GROUP *group);
292void EC_nistp224_pre_comp_free(NISTP224_PRE_COMP *);
293void EC_nistp256_pre_comp_free(NISTP256_PRE_COMP *);
294void EC_nistp521_pre_comp_free(NISTP521_PRE_COMP *);
295void EC_nistz256_pre_comp_free(NISTZ256_PRE_COMP *);
296void EC_ec_pre_comp_free(EC_PRE_COMP *);
297
298/*
299 * method functions in ec_mult.c (ec_lib.c uses these as defaults if
300 * group->method->mul is 0)
301 */
302int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
303 size_t num, const EC_POINT *points[], const BIGNUM *scalars[],
304 BN_CTX *);
305int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *);
306int ec_wNAF_have_precompute_mult(const EC_GROUP *group);
307
308/* method functions in ecp_smpl.c */
309int ec_GFp_simple_group_init(EC_GROUP *);
310void ec_GFp_simple_group_finish(EC_GROUP *);
311void ec_GFp_simple_group_clear_finish(EC_GROUP *);
312int ec_GFp_simple_group_copy(EC_GROUP *, const EC_GROUP *);
313int ec_GFp_simple_group_set_curve(EC_GROUP *, const BIGNUM *p,
314 const BIGNUM *a, const BIGNUM *b, BN_CTX *);
315int ec_GFp_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a,
316 BIGNUM *b, BN_CTX *);
317int ec_GFp_simple_group_get_degree(const EC_GROUP *);
318int ec_GFp_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *);
319int ec_GFp_simple_point_init(EC_POINT *);
320void ec_GFp_simple_point_finish(EC_POINT *);
321void ec_GFp_simple_point_clear_finish(EC_POINT *);
322int ec_GFp_simple_point_copy(EC_POINT *, const EC_POINT *);
323int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *);
324int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *,
325 EC_POINT *, const BIGNUM *x,
326 const BIGNUM *y,
327 const BIGNUM *z, BN_CTX *);
328int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *,
329 const EC_POINT *, BIGNUM *x,
330 BIGNUM *y, BIGNUM *z,
331 BN_CTX *);
332int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *,
333 const BIGNUM *x,
334 const BIGNUM *y, BN_CTX *);
335int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *,
336 const EC_POINT *, BIGNUM *x,
337 BIGNUM *y, BN_CTX *);
338int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *,
339 const BIGNUM *x, int y_bit,
340 BN_CTX *);
341size_t ec_GFp_simple_point2oct(const EC_GROUP *, const EC_POINT *,
342 point_conversion_form_t form,
343 unsigned char *buf, size_t len, BN_CTX *);
344int ec_GFp_simple_oct2point(const EC_GROUP *, EC_POINT *,
345 const unsigned char *buf, size_t len, BN_CTX *);
346int ec_GFp_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a,
347 const EC_POINT *b, BN_CTX *);
348int ec_GFp_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a,
349 BN_CTX *);
350int ec_GFp_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
351int ec_GFp_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *);
352int ec_GFp_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
353int ec_GFp_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b,
354 BN_CTX *);
355int ec_GFp_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
356int ec_GFp_simple_points_make_affine(const EC_GROUP *, size_t num,
357 EC_POINT *[], BN_CTX *);
358int ec_GFp_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
359 const BIGNUM *b, BN_CTX *);
360int ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
361 BN_CTX *);
362
363/* method functions in ecp_mont.c */
364int ec_GFp_mont_group_init(EC_GROUP *);
365int ec_GFp_mont_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a,
366 const BIGNUM *b, BN_CTX *);
367void ec_GFp_mont_group_finish(EC_GROUP *);
368void ec_GFp_mont_group_clear_finish(EC_GROUP *);
369int ec_GFp_mont_group_copy(EC_GROUP *, const EC_GROUP *);
370int ec_GFp_mont_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
371 const BIGNUM *b, BN_CTX *);
372int ec_GFp_mont_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
373 BN_CTX *);
374int ec_GFp_mont_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
375 BN_CTX *);
376int ec_GFp_mont_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
377 BN_CTX *);
378int ec_GFp_mont_field_set_to_one(const EC_GROUP *, BIGNUM *r, BN_CTX *);
379
380/* method functions in ecp_nist.c */
381int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src);
382int ec_GFp_nist_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a,
383 const BIGNUM *b, BN_CTX *);
384int ec_GFp_nist_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
385 const BIGNUM *b, BN_CTX *);
386int ec_GFp_nist_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
387 BN_CTX *);
388
389/* method functions in ec2_smpl.c */
390int ec_GF2m_simple_group_init(EC_GROUP *);
391void ec_GF2m_simple_group_finish(EC_GROUP *);
392void ec_GF2m_simple_group_clear_finish(EC_GROUP *);
393int ec_GF2m_simple_group_copy(EC_GROUP *, const EC_GROUP *);
394int ec_GF2m_simple_group_set_curve(EC_GROUP *, const BIGNUM *p,
395 const BIGNUM *a, const BIGNUM *b,
396 BN_CTX *);
397int ec_GF2m_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a,
398 BIGNUM *b, BN_CTX *);
399int ec_GF2m_simple_group_get_degree(const EC_GROUP *);
400int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *);
401int ec_GF2m_simple_point_init(EC_POINT *);
402void ec_GF2m_simple_point_finish(EC_POINT *);
403void ec_GF2m_simple_point_clear_finish(EC_POINT *);
404int ec_GF2m_simple_point_copy(EC_POINT *, const EC_POINT *);
405int ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *);
406int ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *,
407 const BIGNUM *x,
408 const BIGNUM *y, BN_CTX *);
409int ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *,
410 const EC_POINT *, BIGNUM *x,
411 BIGNUM *y, BN_CTX *);
412int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *,
413 const BIGNUM *x, int y_bit,
414 BN_CTX *);
415size_t ec_GF2m_simple_point2oct(const EC_GROUP *, const EC_POINT *,
416 point_conversion_form_t form,
417 unsigned char *buf, size_t len, BN_CTX *);
418int ec_GF2m_simple_oct2point(const EC_GROUP *, EC_POINT *,
419 const unsigned char *buf, size_t len, BN_CTX *);
420int ec_GF2m_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a,
421 const EC_POINT *b, BN_CTX *);
422int ec_GF2m_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a,
423 BN_CTX *);
424int ec_GF2m_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
425int ec_GF2m_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *);
426int ec_GF2m_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
427int ec_GF2m_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b,
428 BN_CTX *);
429int ec_GF2m_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
430int ec_GF2m_simple_points_make_affine(const EC_GROUP *, size_t num,
431 EC_POINT *[], BN_CTX *);
432int ec_GF2m_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
433 const BIGNUM *b, BN_CTX *);
434int ec_GF2m_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
435 BN_CTX *);
436int ec_GF2m_simple_field_div(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
437 const BIGNUM *b, BN_CTX *);
438
439/* method functions in ec2_mult.c */
440int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r,
441 const BIGNUM *scalar, size_t num,
442 const EC_POINT *points[], const BIGNUM *scalars[],
443 BN_CTX *);
444int ec_GF2m_precompute_mult(EC_GROUP *group, BN_CTX *ctx);
445int ec_GF2m_have_precompute_mult(const EC_GROUP *group);
446
447#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
448/* method functions in ecp_nistp224.c */
449int ec_GFp_nistp224_group_init(EC_GROUP *group);
450int ec_GFp_nistp224_group_set_curve(EC_GROUP *group, const BIGNUM *p,
451 const BIGNUM *a, const BIGNUM *n,
452 BN_CTX *);
453int ec_GFp_nistp224_point_get_affine_coordinates(const EC_GROUP *group,
454 const EC_POINT *point,
455 BIGNUM *x, BIGNUM *y,
456 BN_CTX *ctx);
457int ec_GFp_nistp224_mul(const EC_GROUP *group, EC_POINT *r,
458 const BIGNUM *scalar, size_t num,
459 const EC_POINT *points[], const BIGNUM *scalars[],
460 BN_CTX *);
461int ec_GFp_nistp224_points_mul(const EC_GROUP *group, EC_POINT *r,
462 const BIGNUM *scalar, size_t num,
463 const EC_POINT *points[],
464 const BIGNUM *scalars[], BN_CTX *ctx);
465int ec_GFp_nistp224_precompute_mult(EC_GROUP *group, BN_CTX *ctx);
466int ec_GFp_nistp224_have_precompute_mult(const EC_GROUP *group);
467
468/* method functions in ecp_nistp256.c */
469int ec_GFp_nistp256_group_init(EC_GROUP *group);
470int ec_GFp_nistp256_group_set_curve(EC_GROUP *group, const BIGNUM *p,
471 const BIGNUM *a, const BIGNUM *n,
472 BN_CTX *);
473int ec_GFp_nistp256_point_get_affine_coordinates(const EC_GROUP *group,
474 const EC_POINT *point,
475 BIGNUM *x, BIGNUM *y,
476 BN_CTX *ctx);
477int ec_GFp_nistp256_mul(const EC_GROUP *group, EC_POINT *r,
478 const BIGNUM *scalar, size_t num,
479 const EC_POINT *points[], const BIGNUM *scalars[],
480 BN_CTX *);
481int ec_GFp_nistp256_points_mul(const EC_GROUP *group, EC_POINT *r,
482 const BIGNUM *scalar, size_t num,
483 const EC_POINT *points[],
484 const BIGNUM *scalars[], BN_CTX *ctx);
485int ec_GFp_nistp256_precompute_mult(EC_GROUP *group, BN_CTX *ctx);
486int ec_GFp_nistp256_have_precompute_mult(const EC_GROUP *group);
487
488/* method functions in ecp_nistp521.c */
489int ec_GFp_nistp521_group_init(EC_GROUP *group);
490int ec_GFp_nistp521_group_set_curve(EC_GROUP *group, const BIGNUM *p,
491 const BIGNUM *a, const BIGNUM *n,
492 BN_CTX *);
493int ec_GFp_nistp521_point_get_affine_coordinates(const EC_GROUP *group,
494 const EC_POINT *point,
495 BIGNUM *x, BIGNUM *y,
496 BN_CTX *ctx);
497int ec_GFp_nistp521_mul(const EC_GROUP *group, EC_POINT *r,
498 const BIGNUM *scalar, size_t num,
499 const EC_POINT *points[], const BIGNUM *scalars[],
500 BN_CTX *);
501int ec_GFp_nistp521_points_mul(const EC_GROUP *group, EC_POINT *r,
502 const BIGNUM *scalar, size_t num,
503 const EC_POINT *points[],
504 const BIGNUM *scalars[], BN_CTX *ctx);
505int ec_GFp_nistp521_precompute_mult(EC_GROUP *group, BN_CTX *ctx);
506int ec_GFp_nistp521_have_precompute_mult(const EC_GROUP *group);
507
508/* utility functions in ecp_nistputil.c */
509void ec_GFp_nistp_points_make_affine_internal(size_t num, void *point_array,
510 size_t felem_size,
511 void *tmp_felems,
512 void (*felem_one) (void *out),
513 int (*felem_is_zero) (const void
514 *in),
515 void (*felem_assign) (void *out,
516 const void
517 *in),
518 void (*felem_square) (void *out,
519 const void
520 *in),
521 void (*felem_mul) (void *out,
522 const void
523 *in1,
524 const void
525 *in2),
526 void (*felem_inv) (void *out,
527 const void
528 *in),
529 void (*felem_contract) (void
530 *out,
531 const
532 void
533 *in));
534void ec_GFp_nistp_recode_scalar_bits(unsigned char *sign,
535 unsigned char *digit, unsigned char in);
536#endif
537int ec_precompute_mont_data(EC_GROUP *);
538int ec_group_simple_order_bits(const EC_GROUP *group);
539
540#ifdef ECP_NISTZ256_ASM
541/** Returns GFp methods using montgomery multiplication, with x86-64 optimized
542 * P256. See http://eprint.iacr.org/2013/816.
543 * \return EC_METHOD object
544 */
545const EC_METHOD *EC_GFp_nistz256_method(void);
546#endif
547
548size_t ec_key_simple_priv2oct(const EC_KEY *eckey,
549 unsigned char *buf, size_t len);
550int ec_key_simple_oct2priv(EC_KEY *eckey, const unsigned char *buf, size_t len);
551int ec_key_simple_generate_key(EC_KEY *eckey);
552int ec_key_simple_generate_public_key(EC_KEY *eckey);
553int ec_key_simple_check_key(const EC_KEY *eckey);
554
555/* EC_METHOD definitions */
556
557struct ec_key_method_st {
558 const char *name;
559 int32_t flags;
560 int (*init)(EC_KEY *key);
561 void (*finish)(EC_KEY *key);
562 int (*copy)(EC_KEY *dest, const EC_KEY *src);
563 int (*set_group)(EC_KEY *key, const EC_GROUP *grp);
564 int (*set_private)(EC_KEY *key, const BIGNUM *priv_key);
565 int (*set_public)(EC_KEY *key, const EC_POINT *pub_key);
566 int (*keygen)(EC_KEY *key);
567 int (*compute_key)(unsigned char **pout, size_t *poutlen,
568 const EC_POINT *pub_key, const EC_KEY *ecdh);
569 int (*sign)(int type, const unsigned char *dgst, int dlen, unsigned char
570 *sig, unsigned int *siglen, const BIGNUM *kinv,
571 const BIGNUM *r, EC_KEY *eckey);
572 int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
573 BIGNUM **rp);
574 ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, int dgst_len,
575 const BIGNUM *in_kinv, const BIGNUM *in_r,
576 EC_KEY *eckey);
577
578 int (*verify)(int type, const unsigned char *dgst, int dgst_len,
579 const unsigned char *sigbuf, int sig_len, EC_KEY *eckey);
580 int (*verify_sig)(const unsigned char *dgst, int dgst_len,
581 const ECDSA_SIG *sig, EC_KEY *eckey);
582};
583
584#define EC_KEY_METHOD_DYNAMIC 1
585
586int ossl_ec_key_gen(EC_KEY *eckey);
587int ossl_ecdh_compute_key(unsigned char **pout, size_t *poutlen,
588 const EC_POINT *pub_key, const EC_KEY *ecdh);
589int ecdh_simple_compute_key(unsigned char **pout, size_t *poutlen,
590 const EC_POINT *pub_key, const EC_KEY *ecdh);
591
592struct ECDSA_SIG_st {
593 BIGNUM *r;
594 BIGNUM *s;
595};
596
597int ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
598 BIGNUM **rp);
599int ossl_ecdsa_sign(int type, const unsigned char *dgst, int dlen,
600 unsigned char *sig, unsigned int *siglen,
601 const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey);
602ECDSA_SIG *ossl_ecdsa_sign_sig(const unsigned char *dgst, int dgst_len,
603 const BIGNUM *in_kinv, const BIGNUM *in_r,
604 EC_KEY *eckey);
605int ossl_ecdsa_verify(int type, const unsigned char *dgst, int dgst_len,
606 const unsigned char *sigbuf, int sig_len, EC_KEY *eckey);
607int ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len,
608 const ECDSA_SIG *sig, EC_KEY *eckey);
609
610int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32],
611 const uint8_t peer_public_value[32]);
612void X25519_public_from_private(uint8_t out_public_value[32],
613 const uint8_t private_key[32]);
Note: See TracBrowser for help on using the repository browser.