webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
internal.h
Go to the documentation of this file.
1 /* Originally written by Bodo Moeller for the OpenSSL project.
2  * ====================================================================
3  * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  *
17  * 3. All advertising materials mentioning features or use of this
18  * software must display the following acknowledgment:
19  * "This product includes software developed by the OpenSSL Project
20  * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21  *
22  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23  * endorse or promote products derived from this software without
24  * prior written permission. For written permission, please contact
25  * openssl-core@openssl.org.
26  *
27  * 5. Products derived from this software may not be called "OpenSSL"
28  * nor may "OpenSSL" appear in their names without prior written
29  * permission of the OpenSSL Project.
30  *
31  * 6. Redistributions of any form whatsoever must retain the following
32  * acknowledgment:
33  * "This product includes software developed by the OpenSSL Project
34  * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35  *
36  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47  * OF THE POSSIBILITY OF SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This product includes cryptographic software written by Eric Young
51  * (eay@cryptsoft.com). This product includes software written by Tim
52  * Hudson (tjh@cryptsoft.com).
53  *
54  */
55 /* ====================================================================
56  * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
57  *
58  * Portions of the attached software ("Contribution") are developed by
59  * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
60  *
61  * The Contribution is licensed pursuant to the OpenSSL open source
62  * license provided above.
63  *
64  * The elliptic curve binary polynomial software is originally written by
65  * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems
66  * Laboratories. */
67 
68 #ifndef OPENSSL_HEADER_EC_INTERNAL_H
69 #define OPENSSL_HEADER_EC_INTERNAL_H
70 
71 #include <openssl/base.h>
72 
73 #include <openssl/bn.h>
74 #include <openssl/ex_data.h>
75 #include <openssl/thread.h>
76 
77 #if defined(__cplusplus)
78 extern "C" {
79 #endif
80 
81 
82 struct ec_method_st {
85  int (*group_copy)(EC_GROUP *, const EC_GROUP *);
86  int (*group_set_curve)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a,
87  const BIGNUM *b, BN_CTX *);
89  BIGNUM *x, BIGNUM *y, BN_CTX *);
90 
91  /* Computes |r = g_scalar*generator + p_scalar*p| if |g_scalar| and |p_scalar|
92  * are both non-null. Computes |r = g_scalar*generator| if |p_scalar| is null.
93  * Computes |r = p_scalar*p| if g_scalar is null. At least one of |g_scalar|
94  * and |p_scalar| must be non-null, and |p| must be non-null if |p_scalar| is
95  * non-null. */
96  int (*mul)(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,
97  const EC_POINT *p, const BIGNUM *p_scalar, BN_CTX *ctx);
98 
99  /* 'field_mul' and 'field_sqr' can be used by 'add' and 'dbl' so that the
100  * same implementations of point operations can be used with different
101  * optimized implementations of expensive field operations: */
102  int (*field_mul)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
103  const BIGNUM *b, BN_CTX *);
104  int (*field_sqr)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
105 
106  int (*field_encode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
107  BN_CTX *); /* e.g. to Montgomery */
108  int (*field_decode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
109  BN_CTX *); /* e.g. from Montgomery */
110 } /* EC_METHOD */;
111 
112 extern const EC_METHOD EC_GFp_mont_method;
113 
114 struct ec_group_st {
115  const EC_METHOD *meth;
116 
119 
120  int curve_name; /* optional NID for named curve */
121 
122  const BN_MONT_CTX *mont_data; /* data for ECDSA inverse */
123 
124  /* The following members are handled by the method functions,
125  * even if they appear generic */
126 
127  BIGNUM field; /* For curves over GF(p), this is the modulus. */
128 
129  BIGNUM a, b; /* Curve coefficients. */
130 
131  int a_is_minus3; /* enable optimized point arithmetics for special case */
132 
133  BN_MONT_CTX *mont; /* Montgomery structure. */
134 
135  BIGNUM one; /* The value one. */
136 } /* EC_GROUP */;
137 
138 struct ec_point_st {
139  const EC_METHOD *meth;
140 
143  BIGNUM Z; /* Jacobian projective coordinates:
144  * (X, Y, Z) represents (X/Z^2, Y/Z^3) if Z != 0 */
145 } /* EC_POINT */;
146 
147 EC_GROUP *ec_group_new(const EC_METHOD *meth);
148 int ec_group_copy(EC_GROUP *dest, const EC_GROUP *src);
149 
150 /* ec_group_get_mont_data returns a Montgomery context for operations in the
151  * scalar field of |group|. It may return NULL in the case that |group| is not
152  * a built-in group. */
154 
155 int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,
156  const EC_POINT *p, const BIGNUM *p_scalar, BN_CTX *ctx);
157 
158 /* method functions in simple.c */
162 int ec_GFp_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a,
163  const BIGNUM *b, BN_CTX *);
165  BIGNUM *b, BN_CTX *);
166 unsigned ec_GFp_simple_group_get_degree(const EC_GROUP *);
173  const BIGNUM *x,
174  const BIGNUM *y,
175  const BIGNUM *z, BN_CTX *);
177  const EC_POINT *, BIGNUM *x,
178  BIGNUM *y, BIGNUM *z,
179  BN_CTX *);
181  const BIGNUM *x, const BIGNUM *y,
182  BN_CTX *);
184  const BIGNUM *x, int y_bit,
185  BN_CTX *);
186 int ec_GFp_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a,
187  const EC_POINT *b, BN_CTX *);
188 int ec_GFp_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a,
189  BN_CTX *);
190 int ec_GFp_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
191 int ec_GFp_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *);
192 int ec_GFp_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
193 int ec_GFp_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b,
194  BN_CTX *);
196 int ec_GFp_simple_points_make_affine(const EC_GROUP *, size_t num,
197  EC_POINT * [], BN_CTX *);
198 int ec_GFp_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
199  const BIGNUM *b, BN_CTX *);
200 int ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
201  BN_CTX *);
202 
203 /* method functions in montgomery.c */
205 int ec_GFp_mont_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a,
206  const BIGNUM *b, BN_CTX *);
209 int ec_GFp_mont_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
210  const BIGNUM *b, BN_CTX *);
211 int ec_GFp_mont_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
212  BN_CTX *);
213 int ec_GFp_mont_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
214  BN_CTX *);
215 int ec_GFp_mont_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
216  BN_CTX *);
217 
219  EC_POINT *point, const BIGNUM *x,
220  const BIGNUM *y, const BIGNUM *z,
221  BN_CTX *ctx);
222 
224 
225 extern const EC_METHOD EC_GFp_nistp224_method;
226 extern const EC_METHOD EC_GFp_nistp256_method;
227 
228 /* EC_GFp_nistz256_method is a GFp method using montgomery multiplication, with
229  * x86-64 optimized P256. See http://eprint.iacr.org/2013/816. */
230 extern const EC_METHOD EC_GFp_nistz256_method;
231 
232 struct ec_key_st {
234 
237 
238  unsigned int enc_flag;
240 
242 
244 
246 } /* EC_KEY */;
247 
248 /* curve_data contains data about a built-in elliptic curve. */
249 struct curve_data {
250  /* comment is a human-readable string describing the curve. */
251  const char *comment;
252  /* param_len is the number of bytes needed to store a field element. */
254  /* data points to an array of 6*|param_len| bytes which hold the field
255  * elements of the following (in big-endian order): prime, a, b, generator x,
256  * generator y, order. */
257  const uint8_t data[];
258 };
259 
261  int nid;
262  uint8_t oid[8];
264  const struct curve_data *data;
266 };
267 
268 /* OPENSSL_built_in_curves is terminated with an entry where |nid| is
269  * |NID_undef|. */
270 extern const struct built_in_curve OPENSSL_built_in_curves[];
271 
272 #if defined(__cplusplus)
273 } /* extern C */
274 #endif
275 
276 #endif /* OPENSSL_HEADER_EC_INTERNAL_H */
EC_GROUP * ec_group_new(const EC_METHOD *meth)
Definition: ec.c:335
GLboolean GLuint group
Definition: gl2ext.h:780
int(* group_init)(EC_GROUP *)
Definition: internal.h:83
const EC_METHOD EC_GFp_nistp224_method
DOMString p
Definition: WebCryptoAPI.idl:116
int ec_GFp_mont_group_init(EC_GROUP *)
Definition: ec_montgomery.c:77
BIGNUM order
Definition: internal.h:118
const BN_MONT_CTX * ec_group_get_mont_data(const EC_GROUP *group)
Definition: ec.c:517
const struct built_in_curve OPENSSL_built_in_curves[]
Definition: ec.c:226
int ec_GFp_simple_point_init(EC_POINT *)
Definition: simple.c:237
int a_is_minus3
Definition: internal.h:131
int(* field_encode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *)
Definition: internal.h:106
uint8_t oid_len
Definition: internal.h:263
int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *)
Definition: simple.c:315
void ec_GFp_simple_group_finish(EC_GROUP *)
Definition: simple.c:99
unsigned int enc_flag
Definition: internal.h:238
uint32_t CRYPTO_refcount_t
Definition: thread.h:101
ECDSA_METHOD * ecdsa_meth
Definition: internal.h:243
BIGNUM X
Definition: internal.h:141
dest
Definition: upload.py:394
void ec_GFp_nistp_recode_scalar_bits(uint8_t *sign, uint8_t *digit, uint8_t in)
int ec_GFp_mont_group_copy(EC_GROUP *, const EC_GROUP *)
Definition: ec_montgomery.c:91
Definition: bn.h:902
Definition: bn.h:893
const EC_METHOD EC_GFp_mont_method
Definition: ec_montgomery.c:297
BIGNUM * priv_key
Definition: internal.h:236
int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar, const EC_POINT *p, const BIGNUM *p_scalar, BN_CTX *ctx)
Definition: wnaf.c:227
int(* group_copy)(EC_GROUP *, const EC_GROUP *)
Definition: internal.h:85
uint8_t param_len
Definition: internal.h:253
const BN_MONT_CTX * mont_data
Definition: internal.h:122
BIGNUM Y
Definition: internal.h:142
const EC_METHOD * meth
Definition: internal.h:139
Definition: internal.h:232
int ec_GFp_simple_group_copy(EC_GROUP *, const EC_GROUP *)
Definition: simple.c:106
void
Definition: AVFoundationCFSoftLinking.h:81
EC_POINT * generator
Definition: internal.h:117
int
Definition: runtests.py:53
int ec_GFp_mont_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *)
Definition: ec_montgomery.c:178
int ec_GFp_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *)
Definition: simple.c:193
unsigned ec_GFp_simple_group_get_degree(const EC_GROUP *)
Definition: simple.c:233
int(* mul)(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar, const EC_POINT *p, const BIGNUM *p_scalar, BN_CTX *ctx)
Definition: internal.h:96
Definition: WebCryptoAPI.idl:29
int(* field_mul)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *)
Definition: internal.h:102
int(* group_set_curve)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *)
Definition: internal.h:86
EGLSurface EGLint x
Definition: eglext.h:950
int ec_GFp_simple_points_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *)
Definition: simple.c:962
BIGNUM field
Definition: internal.h:127
int ec_GFp_mont_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *)
Definition: ec_montgomery.c:168
point_conversion_form_t
Definition: ec.h:83
EGLContext ctx
Definition: eglext.h:192
unsigned char uint8_t
Definition: ptypes.h:89
int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *, const BIGNUM *x, int y_bit, BN_CTX *)
Definition: oct.c:283
int ec_GFp_simple_point_copy(EC_POINT *, const EC_POINT *)
Definition: simple.c:257
point_conversion_form_t conv_form
Definition: internal.h:239
int nid
Definition: internal.h:261
EC_GROUP * group
Definition: internal.h:233
int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *, const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *)
Definition: simple.c:289
BIGNUM Z
Definition: internal.h:143
void ec_GFp_simple_point_clear_finish(EC_POINT *)
Definition: simple.c:251
void ec_GFp_mont_group_finish(EC_GROUP *)
Definition: ec_montgomery.c:85
EGLSurface EGLint EGLint y
Definition: eglext.h:950
void ec_GFp_simple_point_finish(EC_POINT *)
Definition: simple.c:245
int(* point_get_affine_coordinates)(const EC_GROUP *, const EC_POINT *, BIGNUM *x, BIGNUM *y, BN_CTX *)
Definition: internal.h:88
Definition: internal.h:260
GLboolean GLboolean GLboolean GLboolean a
Definition: gl2ext.h:306
int ec_GFp_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *)
Definition: simple.c:804
const char * comment
Definition: internal.h:251
int ec_GFp_mont_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *)
Definition: ec_montgomery.c:117
int ec_GFp_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *)
Definition: simple.c:564
EGLStreamKHR EGLint EGLint EGLint const void * data
Definition: eglext.h:984
Definition: internal.h:138
GLenum src
Definition: gl2ext.h:304
int(* field_sqr)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *)
Definition: internal.h:104
const struct curve_data * data
Definition: internal.h:264
BIGNUM b
Definition: internal.h:129
void(* group_finish)(EC_GROUP *)
Definition: internal.h:84
int ec_GFp_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *)
Definition: simple.c:1109
EC_POINT * pub_key
Definition: internal.h:235
Definition: ec_key.h:233
int ec_GFp_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *)
Definition: simple.c:118
int ec_GFp_mont_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *)
Definition: ec_montgomery.c:188
Definition: internal.h:114
GLfloat GLfloat GLfloat z
Definition: gl2.h:517
int ec_point_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *point, const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx)
Definition: ec.c:803
BN_MONT_CTX * mont
Definition: internal.h:133
int(* field_decode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *)
Definition: internal.h:108
int ec_GFp_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *)
Definition: simple.c:689
GLboolean GLboolean GLboolean b
Definition: gl2ext.h:306
int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *, const BIGNUM *x, const BIGNUM *y, BN_CTX *)
Definition: simple.c:358
Definition: ctx.c:111
int ec_GFp_simple_group_init(EC_GROUP *)
Definition: simple.c:90
int ec_GFp_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *)
Definition: simple.c:371
int ec_GFp_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *)
Definition: simple.c:920
Definition: ex_data.h:204
int ec_GFp_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *)
Definition: simple.c:698
const EC_METHOD EC_GFp_nistp256_method
const EC_METHOD EC_GFp_nistz256_method
CRYPTO_refcount_t references
Definition: internal.h:241
int ec_GFp_mont_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *)
Definition: ec_montgomery.c:158
CRYPTO_EX_DATA ex_data
Definition: internal.h:245
int ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *)
Definition: simple.c:1114
BIGNUM one
Definition: internal.h:135
int curve_name
Definition: internal.h:120
int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *)
Definition: simple.c:267
Definition: internal.h:249
const EC_METHOD * method
Definition: internal.h:265
int ec_group_copy(EC_GROUP *dest, const EC_GROUP *src)
int ec_GFp_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *)
Definition: simple.c:702
GLboolean r
Definition: gl2ext.h:306
const EC_METHOD * meth
Definition: internal.h:115
Definition: internal.h:82