grpc 1.10.0.pre1 → 1.10.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +3 -3
- data/src/core/ext/filters/max_age/max_age_filter.cc +3 -0
- data/src/core/lib/surface/version.cc +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/third_party/boringssl/crypto/fipsmodule/aes/aes.c +1100 -0
- data/third_party/boringssl/crypto/fipsmodule/aes/key_wrap.c +138 -0
- data/third_party/boringssl/crypto/fipsmodule/aes/mode_wrappers.c +112 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/add.c +375 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/asm/x86_64-gcc.c +537 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/bn.c +370 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/bytes.c +269 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/cmp.c +239 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/ctx.c +303 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/div.c +726 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/exponentiation.c +1233 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/gcd.c +627 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/generic.c +715 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/jacobi.c +146 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/montgomery.c +430 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/montgomery_inv.c +207 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/mul.c +869 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/prime.c +894 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/random.c +283 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/rsaz_exp.c +254 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/shift.c +307 -0
- data/third_party/boringssl/crypto/fipsmodule/bn/sqrt.c +502 -0
- data/third_party/boringssl/crypto/fipsmodule/cipher/aead.c +284 -0
- data/third_party/boringssl/crypto/fipsmodule/cipher/cipher.c +613 -0
- data/third_party/boringssl/crypto/fipsmodule/cipher/e_aes.c +1437 -0
- data/third_party/boringssl/crypto/fipsmodule/cipher/e_des.c +233 -0
- data/third_party/boringssl/crypto/fipsmodule/des/des.c +785 -0
- data/third_party/boringssl/crypto/fipsmodule/digest/digest.c +256 -0
- data/third_party/boringssl/crypto/fipsmodule/digest/digests.c +280 -0
- data/third_party/boringssl/crypto/fipsmodule/ec/ec.c +842 -0
- data/third_party/boringssl/crypto/fipsmodule/ec/ec_key.c +517 -0
- data/third_party/boringssl/crypto/fipsmodule/ec/ec_montgomery.c +304 -0
- data/third_party/boringssl/crypto/fipsmodule/ec/oct.c +404 -0
- data/third_party/boringssl/crypto/fipsmodule/ec/p224-64.c +1165 -0
- data/third_party/boringssl/crypto/fipsmodule/ec/p256-64.c +1708 -0
- data/third_party/boringssl/crypto/fipsmodule/ec/p256-x86_64.c +561 -0
- data/third_party/boringssl/crypto/fipsmodule/ec/simple.c +1113 -0
- data/third_party/boringssl/crypto/fipsmodule/ec/util-64.c +109 -0
- data/third_party/boringssl/crypto/fipsmodule/ec/wnaf.c +456 -0
- data/third_party/boringssl/crypto/fipsmodule/ecdsa/ecdsa.c +444 -0
- data/third_party/boringssl/crypto/fipsmodule/hmac/hmac.c +228 -0
- data/third_party/boringssl/crypto/fipsmodule/md4/md4.c +254 -0
- data/third_party/boringssl/crypto/fipsmodule/md5/md5.c +298 -0
- data/third_party/boringssl/crypto/fipsmodule/modes/cbc.c +212 -0
- data/third_party/boringssl/crypto/fipsmodule/modes/cfb.c +230 -0
- data/third_party/boringssl/crypto/fipsmodule/modes/ctr.c +219 -0
- data/third_party/boringssl/crypto/fipsmodule/modes/gcm.c +1074 -0
- data/third_party/boringssl/crypto/fipsmodule/modes/ofb.c +95 -0
- data/third_party/boringssl/crypto/fipsmodule/modes/polyval.c +91 -0
- data/third_party/boringssl/crypto/fipsmodule/rand/ctrdrbg.c +200 -0
- data/third_party/boringssl/crypto/fipsmodule/rand/rand.c +358 -0
- data/third_party/boringssl/crypto/fipsmodule/rand/urandom.c +302 -0
- data/third_party/boringssl/crypto/fipsmodule/rsa/blinding.c +263 -0
- data/third_party/boringssl/crypto/fipsmodule/rsa/padding.c +692 -0
- data/third_party/boringssl/crypto/fipsmodule/rsa/rsa.c +855 -0
- data/third_party/boringssl/crypto/fipsmodule/rsa/rsa_impl.c +1061 -0
- data/third_party/boringssl/crypto/fipsmodule/sha/sha1-altivec.c +361 -0
- data/third_party/boringssl/crypto/fipsmodule/sha/sha1.c +375 -0
- data/third_party/boringssl/crypto/fipsmodule/sha/sha256.c +337 -0
- data/third_party/boringssl/crypto/fipsmodule/sha/sha512.c +608 -0
- metadata +62 -2
@@ -0,0 +1,517 @@
|
|
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
|
+
#include <openssl/ec_key.h>
|
69
|
+
|
70
|
+
#include <string.h>
|
71
|
+
|
72
|
+
#include <openssl/ec.h>
|
73
|
+
#include <openssl/ecdsa.h>
|
74
|
+
#include <openssl/engine.h>
|
75
|
+
#include <openssl/err.h>
|
76
|
+
#include <openssl/ex_data.h>
|
77
|
+
#include <openssl/mem.h>
|
78
|
+
#include <openssl/thread.h>
|
79
|
+
|
80
|
+
#include "internal.h"
|
81
|
+
#include "../delocate.h"
|
82
|
+
#include "../../internal.h"
|
83
|
+
|
84
|
+
|
85
|
+
DEFINE_STATIC_EX_DATA_CLASS(g_ec_ex_data_class);
|
86
|
+
|
87
|
+
EC_KEY *EC_KEY_new(void) { return EC_KEY_new_method(NULL); }
|
88
|
+
|
89
|
+
EC_KEY *EC_KEY_new_method(const ENGINE *engine) {
|
90
|
+
EC_KEY *ret = OPENSSL_malloc(sizeof(EC_KEY));
|
91
|
+
if (ret == NULL) {
|
92
|
+
OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
|
93
|
+
return NULL;
|
94
|
+
}
|
95
|
+
|
96
|
+
OPENSSL_memset(ret, 0, sizeof(EC_KEY));
|
97
|
+
|
98
|
+
if (engine) {
|
99
|
+
ret->ecdsa_meth = ENGINE_get_ECDSA_method(engine);
|
100
|
+
}
|
101
|
+
if (ret->ecdsa_meth) {
|
102
|
+
METHOD_ref(ret->ecdsa_meth);
|
103
|
+
}
|
104
|
+
|
105
|
+
ret->conv_form = POINT_CONVERSION_UNCOMPRESSED;
|
106
|
+
ret->references = 1;
|
107
|
+
|
108
|
+
CRYPTO_new_ex_data(&ret->ex_data);
|
109
|
+
|
110
|
+
if (ret->ecdsa_meth && ret->ecdsa_meth->init && !ret->ecdsa_meth->init(ret)) {
|
111
|
+
CRYPTO_free_ex_data(g_ec_ex_data_class_bss_get(), ret, &ret->ex_data);
|
112
|
+
if (ret->ecdsa_meth) {
|
113
|
+
METHOD_unref(ret->ecdsa_meth);
|
114
|
+
}
|
115
|
+
OPENSSL_free(ret);
|
116
|
+
return NULL;
|
117
|
+
}
|
118
|
+
|
119
|
+
return ret;
|
120
|
+
}
|
121
|
+
|
122
|
+
EC_KEY *EC_KEY_new_by_curve_name(int nid) {
|
123
|
+
EC_KEY *ret = EC_KEY_new();
|
124
|
+
if (ret == NULL) {
|
125
|
+
OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
|
126
|
+
return NULL;
|
127
|
+
}
|
128
|
+
ret->group = EC_GROUP_new_by_curve_name(nid);
|
129
|
+
if (ret->group == NULL) {
|
130
|
+
EC_KEY_free(ret);
|
131
|
+
return NULL;
|
132
|
+
}
|
133
|
+
return ret;
|
134
|
+
}
|
135
|
+
|
136
|
+
void EC_KEY_free(EC_KEY *r) {
|
137
|
+
if (r == NULL) {
|
138
|
+
return;
|
139
|
+
}
|
140
|
+
|
141
|
+
if (!CRYPTO_refcount_dec_and_test_zero(&r->references)) {
|
142
|
+
return;
|
143
|
+
}
|
144
|
+
|
145
|
+
if (r->ecdsa_meth) {
|
146
|
+
if (r->ecdsa_meth->finish) {
|
147
|
+
r->ecdsa_meth->finish(r);
|
148
|
+
}
|
149
|
+
METHOD_unref(r->ecdsa_meth);
|
150
|
+
}
|
151
|
+
|
152
|
+
EC_GROUP_free(r->group);
|
153
|
+
EC_POINT_free(r->pub_key);
|
154
|
+
BN_clear_free(r->priv_key);
|
155
|
+
BN_free(r->fixed_k);
|
156
|
+
|
157
|
+
CRYPTO_free_ex_data(g_ec_ex_data_class_bss_get(), r, &r->ex_data);
|
158
|
+
|
159
|
+
OPENSSL_free(r);
|
160
|
+
}
|
161
|
+
|
162
|
+
EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src) {
|
163
|
+
if (dest == NULL || src == NULL) {
|
164
|
+
OPENSSL_PUT_ERROR(EC, ERR_R_PASSED_NULL_PARAMETER);
|
165
|
+
return NULL;
|
166
|
+
}
|
167
|
+
// Copy the parameters.
|
168
|
+
if (src->group) {
|
169
|
+
// TODO(fork): duplicating the group seems wasteful.
|
170
|
+
EC_GROUP_free(dest->group);
|
171
|
+
dest->group = EC_GROUP_dup(src->group);
|
172
|
+
if (dest->group == NULL) {
|
173
|
+
return NULL;
|
174
|
+
}
|
175
|
+
}
|
176
|
+
|
177
|
+
// Copy the public key.
|
178
|
+
if (src->pub_key && src->group) {
|
179
|
+
EC_POINT_free(dest->pub_key);
|
180
|
+
dest->pub_key = EC_POINT_dup(src->pub_key, src->group);
|
181
|
+
if (dest->pub_key == NULL) {
|
182
|
+
return NULL;
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
// copy the private key
|
187
|
+
if (src->priv_key) {
|
188
|
+
if (dest->priv_key == NULL) {
|
189
|
+
dest->priv_key = BN_new();
|
190
|
+
if (dest->priv_key == NULL) {
|
191
|
+
return NULL;
|
192
|
+
}
|
193
|
+
}
|
194
|
+
if (!BN_copy(dest->priv_key, src->priv_key)) {
|
195
|
+
return NULL;
|
196
|
+
}
|
197
|
+
}
|
198
|
+
// copy method/extra data
|
199
|
+
if (src->ecdsa_meth) {
|
200
|
+
METHOD_unref(dest->ecdsa_meth);
|
201
|
+
dest->ecdsa_meth = src->ecdsa_meth;
|
202
|
+
METHOD_ref(dest->ecdsa_meth);
|
203
|
+
}
|
204
|
+
|
205
|
+
// copy the rest
|
206
|
+
dest->enc_flag = src->enc_flag;
|
207
|
+
dest->conv_form = src->conv_form;
|
208
|
+
|
209
|
+
return dest;
|
210
|
+
}
|
211
|
+
|
212
|
+
EC_KEY *EC_KEY_dup(const EC_KEY *ec_key) {
|
213
|
+
EC_KEY *ret = EC_KEY_new();
|
214
|
+
if (ret == NULL) {
|
215
|
+
return NULL;
|
216
|
+
}
|
217
|
+
if (EC_KEY_copy(ret, ec_key) == NULL) {
|
218
|
+
EC_KEY_free(ret);
|
219
|
+
return NULL;
|
220
|
+
}
|
221
|
+
return ret;
|
222
|
+
}
|
223
|
+
|
224
|
+
int EC_KEY_up_ref(EC_KEY *r) {
|
225
|
+
CRYPTO_refcount_inc(&r->references);
|
226
|
+
return 1;
|
227
|
+
}
|
228
|
+
|
229
|
+
int EC_KEY_is_opaque(const EC_KEY *key) {
|
230
|
+
return key->ecdsa_meth && (key->ecdsa_meth->flags & ECDSA_FLAG_OPAQUE);
|
231
|
+
}
|
232
|
+
|
233
|
+
const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key) { return key->group; }
|
234
|
+
|
235
|
+
int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group) {
|
236
|
+
EC_GROUP_free(key->group);
|
237
|
+
// TODO(fork): duplicating the group seems wasteful but see
|
238
|
+
// |EC_KEY_set_conv_form|.
|
239
|
+
key->group = EC_GROUP_dup(group);
|
240
|
+
if (key->group == NULL) {
|
241
|
+
return 0;
|
242
|
+
}
|
243
|
+
// XXX: |BN_cmp| is not constant time.
|
244
|
+
if (key->priv_key != NULL &&
|
245
|
+
BN_cmp(key->priv_key, EC_GROUP_get0_order(group)) >= 0) {
|
246
|
+
return 0;
|
247
|
+
}
|
248
|
+
return 1;
|
249
|
+
}
|
250
|
+
|
251
|
+
const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key) {
|
252
|
+
return key->priv_key;
|
253
|
+
}
|
254
|
+
|
255
|
+
int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key) {
|
256
|
+
// XXX: |BN_cmp| is not constant time.
|
257
|
+
if (key->group != NULL &&
|
258
|
+
BN_cmp(priv_key, EC_GROUP_get0_order(key->group)) >= 0) {
|
259
|
+
OPENSSL_PUT_ERROR(EC, EC_R_WRONG_ORDER);
|
260
|
+
return 0;
|
261
|
+
}
|
262
|
+
BN_clear_free(key->priv_key);
|
263
|
+
key->priv_key = BN_dup(priv_key);
|
264
|
+
return (key->priv_key == NULL) ? 0 : 1;
|
265
|
+
}
|
266
|
+
|
267
|
+
const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key) {
|
268
|
+
return key->pub_key;
|
269
|
+
}
|
270
|
+
|
271
|
+
int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub_key) {
|
272
|
+
EC_POINT_free(key->pub_key);
|
273
|
+
key->pub_key = EC_POINT_dup(pub_key, key->group);
|
274
|
+
return (key->pub_key == NULL) ? 0 : 1;
|
275
|
+
}
|
276
|
+
|
277
|
+
unsigned int EC_KEY_get_enc_flags(const EC_KEY *key) { return key->enc_flag; }
|
278
|
+
|
279
|
+
void EC_KEY_set_enc_flags(EC_KEY *key, unsigned int flags) {
|
280
|
+
key->enc_flag = flags;
|
281
|
+
}
|
282
|
+
|
283
|
+
point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *key) {
|
284
|
+
return key->conv_form;
|
285
|
+
}
|
286
|
+
|
287
|
+
void EC_KEY_set_conv_form(EC_KEY *key, point_conversion_form_t cform) {
|
288
|
+
key->conv_form = cform;
|
289
|
+
}
|
290
|
+
|
291
|
+
int EC_KEY_check_key(const EC_KEY *eckey) {
|
292
|
+
int ok = 0;
|
293
|
+
BN_CTX *ctx = NULL;
|
294
|
+
EC_POINT *point = NULL;
|
295
|
+
|
296
|
+
if (!eckey || !eckey->group || !eckey->pub_key) {
|
297
|
+
OPENSSL_PUT_ERROR(EC, ERR_R_PASSED_NULL_PARAMETER);
|
298
|
+
return 0;
|
299
|
+
}
|
300
|
+
|
301
|
+
if (EC_POINT_is_at_infinity(eckey->group, eckey->pub_key)) {
|
302
|
+
OPENSSL_PUT_ERROR(EC, EC_R_POINT_AT_INFINITY);
|
303
|
+
goto err;
|
304
|
+
}
|
305
|
+
|
306
|
+
ctx = BN_CTX_new();
|
307
|
+
|
308
|
+
if (ctx == NULL) {
|
309
|
+
goto err;
|
310
|
+
}
|
311
|
+
|
312
|
+
// testing whether the pub_key is on the elliptic curve
|
313
|
+
if (!EC_POINT_is_on_curve(eckey->group, eckey->pub_key, ctx)) {
|
314
|
+
OPENSSL_PUT_ERROR(EC, EC_R_POINT_IS_NOT_ON_CURVE);
|
315
|
+
goto err;
|
316
|
+
}
|
317
|
+
// in case the priv_key is present :
|
318
|
+
// check if generator * priv_key == pub_key
|
319
|
+
if (eckey->priv_key) {
|
320
|
+
// XXX: |BN_cmp| is not constant time.
|
321
|
+
if (BN_cmp(eckey->priv_key, EC_GROUP_get0_order(eckey->group)) >= 0) {
|
322
|
+
OPENSSL_PUT_ERROR(EC, EC_R_WRONG_ORDER);
|
323
|
+
goto err;
|
324
|
+
}
|
325
|
+
point = EC_POINT_new(eckey->group);
|
326
|
+
if (point == NULL ||
|
327
|
+
!EC_POINT_mul(eckey->group, point, eckey->priv_key, NULL, NULL, ctx)) {
|
328
|
+
OPENSSL_PUT_ERROR(EC, ERR_R_EC_LIB);
|
329
|
+
goto err;
|
330
|
+
}
|
331
|
+
if (EC_POINT_cmp(eckey->group, point, eckey->pub_key, ctx) != 0) {
|
332
|
+
OPENSSL_PUT_ERROR(EC, EC_R_INVALID_PRIVATE_KEY);
|
333
|
+
goto err;
|
334
|
+
}
|
335
|
+
}
|
336
|
+
ok = 1;
|
337
|
+
|
338
|
+
err:
|
339
|
+
BN_CTX_free(ctx);
|
340
|
+
EC_POINT_free(point);
|
341
|
+
return ok;
|
342
|
+
}
|
343
|
+
|
344
|
+
int EC_KEY_check_fips(const EC_KEY *key) {
|
345
|
+
if (EC_KEY_is_opaque(key)) {
|
346
|
+
// Opaque keys can't be checked.
|
347
|
+
OPENSSL_PUT_ERROR(EC, EC_R_PUBLIC_KEY_VALIDATION_FAILED);
|
348
|
+
return 0;
|
349
|
+
}
|
350
|
+
|
351
|
+
if (!EC_KEY_check_key(key)) {
|
352
|
+
return 0;
|
353
|
+
}
|
354
|
+
|
355
|
+
if (key->priv_key) {
|
356
|
+
uint8_t data[16] = {0};
|
357
|
+
ECDSA_SIG *sig = ECDSA_do_sign(data, sizeof(data), key);
|
358
|
+
#if defined(BORINGSSL_FIPS_BREAK_ECDSA_PWCT)
|
359
|
+
data[0] = ~data[0];
|
360
|
+
#endif
|
361
|
+
int ok = sig != NULL &&
|
362
|
+
ECDSA_do_verify(data, sizeof(data), sig, key);
|
363
|
+
ECDSA_SIG_free(sig);
|
364
|
+
if (!ok) {
|
365
|
+
OPENSSL_PUT_ERROR(EC, EC_R_PUBLIC_KEY_VALIDATION_FAILED);
|
366
|
+
return 0;
|
367
|
+
}
|
368
|
+
}
|
369
|
+
|
370
|
+
return 1;
|
371
|
+
}
|
372
|
+
|
373
|
+
int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x,
|
374
|
+
BIGNUM *y) {
|
375
|
+
BN_CTX *ctx = NULL;
|
376
|
+
BIGNUM *tx, *ty;
|
377
|
+
EC_POINT *point = NULL;
|
378
|
+
int ok = 0;
|
379
|
+
|
380
|
+
if (!key || !key->group || !x || !y) {
|
381
|
+
OPENSSL_PUT_ERROR(EC, ERR_R_PASSED_NULL_PARAMETER);
|
382
|
+
return 0;
|
383
|
+
}
|
384
|
+
ctx = BN_CTX_new();
|
385
|
+
|
386
|
+
if (ctx == NULL) {
|
387
|
+
return 0;
|
388
|
+
}
|
389
|
+
|
390
|
+
BN_CTX_start(ctx);
|
391
|
+
point = EC_POINT_new(key->group);
|
392
|
+
|
393
|
+
if (point == NULL) {
|
394
|
+
goto err;
|
395
|
+
}
|
396
|
+
|
397
|
+
tx = BN_CTX_get(ctx);
|
398
|
+
ty = BN_CTX_get(ctx);
|
399
|
+
if (tx == NULL ||
|
400
|
+
ty == NULL) {
|
401
|
+
goto err;
|
402
|
+
}
|
403
|
+
|
404
|
+
if (!EC_POINT_set_affine_coordinates_GFp(key->group, point, x, y, ctx) ||
|
405
|
+
!EC_POINT_get_affine_coordinates_GFp(key->group, point, tx, ty, ctx)) {
|
406
|
+
goto err;
|
407
|
+
}
|
408
|
+
|
409
|
+
// Check if retrieved coordinates match originals: if not values
|
410
|
+
// are out of range.
|
411
|
+
if (BN_cmp(x, tx) || BN_cmp(y, ty)) {
|
412
|
+
OPENSSL_PUT_ERROR(EC, EC_R_COORDINATES_OUT_OF_RANGE);
|
413
|
+
goto err;
|
414
|
+
}
|
415
|
+
|
416
|
+
if (!EC_KEY_set_public_key(key, point)) {
|
417
|
+
goto err;
|
418
|
+
}
|
419
|
+
|
420
|
+
if (EC_KEY_check_key(key) == 0) {
|
421
|
+
goto err;
|
422
|
+
}
|
423
|
+
|
424
|
+
ok = 1;
|
425
|
+
|
426
|
+
err:
|
427
|
+
BN_CTX_end(ctx);
|
428
|
+
BN_CTX_free(ctx);
|
429
|
+
EC_POINT_free(point);
|
430
|
+
return ok;
|
431
|
+
}
|
432
|
+
|
433
|
+
int EC_KEY_generate_key(EC_KEY *eckey) {
|
434
|
+
int ok = 0;
|
435
|
+
BIGNUM *priv_key = NULL;
|
436
|
+
EC_POINT *pub_key = NULL;
|
437
|
+
|
438
|
+
if (!eckey || !eckey->group) {
|
439
|
+
OPENSSL_PUT_ERROR(EC, ERR_R_PASSED_NULL_PARAMETER);
|
440
|
+
return 0;
|
441
|
+
}
|
442
|
+
|
443
|
+
if (eckey->priv_key == NULL) {
|
444
|
+
priv_key = BN_new();
|
445
|
+
if (priv_key == NULL) {
|
446
|
+
goto err;
|
447
|
+
}
|
448
|
+
} else {
|
449
|
+
priv_key = eckey->priv_key;
|
450
|
+
}
|
451
|
+
|
452
|
+
const BIGNUM *order = EC_GROUP_get0_order(eckey->group);
|
453
|
+
|
454
|
+
// Check that the size of the group order is FIPS compliant (FIPS 186-4
|
455
|
+
// B.4.2).
|
456
|
+
if (BN_num_bits(order) < 160) {
|
457
|
+
OPENSSL_PUT_ERROR(EC, EC_R_INVALID_GROUP_ORDER);
|
458
|
+
goto err;
|
459
|
+
}
|
460
|
+
|
461
|
+
// Generate the private key by testing candidates (FIPS 186-4 B.4.2).
|
462
|
+
if (!BN_rand_range_ex(priv_key, 1, order)) {
|
463
|
+
goto err;
|
464
|
+
}
|
465
|
+
|
466
|
+
if (eckey->pub_key == NULL) {
|
467
|
+
pub_key = EC_POINT_new(eckey->group);
|
468
|
+
if (pub_key == NULL) {
|
469
|
+
goto err;
|
470
|
+
}
|
471
|
+
} else {
|
472
|
+
pub_key = eckey->pub_key;
|
473
|
+
}
|
474
|
+
|
475
|
+
if (!EC_POINT_mul(eckey->group, pub_key, priv_key, NULL, NULL, NULL)) {
|
476
|
+
goto err;
|
477
|
+
}
|
478
|
+
|
479
|
+
eckey->priv_key = priv_key;
|
480
|
+
eckey->pub_key = pub_key;
|
481
|
+
|
482
|
+
ok = 1;
|
483
|
+
|
484
|
+
err:
|
485
|
+
if (eckey->pub_key == NULL) {
|
486
|
+
EC_POINT_free(pub_key);
|
487
|
+
}
|
488
|
+
if (eckey->priv_key == NULL) {
|
489
|
+
BN_free(priv_key);
|
490
|
+
}
|
491
|
+
return ok;
|
492
|
+
}
|
493
|
+
|
494
|
+
int EC_KEY_generate_key_fips(EC_KEY *eckey) {
|
495
|
+
return EC_KEY_generate_key(eckey) && EC_KEY_check_fips(eckey);
|
496
|
+
}
|
497
|
+
|
498
|
+
int EC_KEY_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused,
|
499
|
+
CRYPTO_EX_dup *dup_unused,
|
500
|
+
CRYPTO_EX_free *free_func) {
|
501
|
+
int index;
|
502
|
+
if (!CRYPTO_get_ex_new_index(g_ec_ex_data_class_bss_get(), &index, argl, argp,
|
503
|
+
free_func)) {
|
504
|
+
return -1;
|
505
|
+
}
|
506
|
+
return index;
|
507
|
+
}
|
508
|
+
|
509
|
+
int EC_KEY_set_ex_data(EC_KEY *d, int idx, void *arg) {
|
510
|
+
return CRYPTO_set_ex_data(&d->ex_data, idx, arg);
|
511
|
+
}
|
512
|
+
|
513
|
+
void *EC_KEY_get_ex_data(const EC_KEY *d, int idx) {
|
514
|
+
return CRYPTO_get_ex_data(&d->ex_data, idx);
|
515
|
+
}
|
516
|
+
|
517
|
+
void EC_KEY_set_asn1_flag(EC_KEY *key, int flag) {}
|