summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/ec/ec_key.c31
-rw-r--r--src/lib/libcrypto/ecdh/ech_key.c19
-rw-r--r--src/lib/libcrypto/ecdsa/ecs_ossl.c41
3 files changed, 18 insertions, 73 deletions
diff --git a/src/lib/libcrypto/ec/ec_key.c b/src/lib/libcrypto/ec/ec_key.c
index 348156e680..27b8f26608 100644
--- a/src/lib/libcrypto/ec/ec_key.c
+++ b/src/lib/libcrypto/ec/ec_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_key.c,v 1.25 2021/04/20 17:16:37 tb Exp $ */ 1/* $OpenBSD: ec_key.c,v 1.26 2021/04/20 17:23:37 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -381,7 +381,7 @@ EC_KEY_set_public_key_affine_coordinates(EC_KEY * key, BIGNUM * x, BIGNUM * y)
381 BN_CTX *ctx = NULL; 381 BN_CTX *ctx = NULL;
382 BIGNUM *tx, *ty; 382 BIGNUM *tx, *ty;
383 EC_POINT *point = NULL; 383 EC_POINT *point = NULL;
384 int ok = 0, tmp_nid, is_char_two = 0; 384 int ok = 0;
385 385
386 if (!key || !key->group || !x || !y) { 386 if (!key || !key->group || !x || !y) {
387 ECerror(ERR_R_PASSED_NULL_PARAMETER); 387 ECerror(ERR_R_PASSED_NULL_PARAMETER);
@@ -396,34 +396,15 @@ EC_KEY_set_public_key_affine_coordinates(EC_KEY * key, BIGNUM * x, BIGNUM * y)
396 if (!point) 396 if (!point)
397 goto err; 397 goto err;
398 398
399 tmp_nid = EC_METHOD_get_field_type(EC_GROUP_method_of(key->group));
400
401 if (tmp_nid == NID_X9_62_characteristic_two_field)
402 is_char_two = 1;
403
404 if ((tx = BN_CTX_get(ctx)) == NULL) 399 if ((tx = BN_CTX_get(ctx)) == NULL)
405 goto err; 400 goto err;
406 if ((ty = BN_CTX_get(ctx)) == NULL) 401 if ((ty = BN_CTX_get(ctx)) == NULL)
407 goto err; 402 goto err;
408 403
409#ifndef OPENSSL_NO_EC2M 404 if (!EC_POINT_set_affine_coordinates(key->group, point, x, y, ctx))
410 if (is_char_two) { 405 goto err;
411 if (!EC_POINT_set_affine_coordinates(key->group, point, 406 if (!EC_POINT_get_affine_coordinates(key->group, point, tx, ty, ctx))
412 x, y, ctx)) 407 goto err;
413 goto err;
414 if (!EC_POINT_get_affine_coordinates(key->group, point,
415 tx, ty, ctx))
416 goto err;
417 } else
418#endif
419 {
420 if (!EC_POINT_set_affine_coordinates(key->group, point,
421 x, y, ctx))
422 goto err;
423 if (!EC_POINT_get_affine_coordinates(key->group, point,
424 tx, ty, ctx))
425 goto err;
426 }
427 /* 408 /*
428 * Check if retrieved coordinates match originals: if not values are 409 * Check if retrieved coordinates match originals: if not values are
429 * out of range. 410 * out of range.
diff --git a/src/lib/libcrypto/ecdh/ech_key.c b/src/lib/libcrypto/ecdh/ech_key.c
index c82002ea46..e59ce8bc3c 100644
--- a/src/lib/libcrypto/ecdh/ech_key.c
+++ b/src/lib/libcrypto/ecdh/ech_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ech_key.c,v 1.10 2021/04/20 17:16:38 tb Exp $ */ 1/* $OpenBSD: ech_key.c,v 1.11 2021/04/20 17:23:37 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -140,21 +140,10 @@ ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
140 goto err; 140 goto err;
141 } 141 }
142 142
143 if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == 143 if (!EC_POINT_get_affine_coordinates(group, tmp, x, y, ctx)) {
144 NID_X9_62_prime_field) { 144 ECDHerror(ECDH_R_POINT_ARITHMETIC_FAILURE);
145 if (!EC_POINT_get_affine_coordinates(group, tmp, x, y, ctx)) { 145 goto err;
146 ECDHerror(ECDH_R_POINT_ARITHMETIC_FAILURE);
147 goto err;
148 }
149 }
150#ifndef OPENSSL_NO_EC2M
151 else {
152 if (!EC_POINT_get_affine_coordinates(group, tmp, x, y, ctx)) {
153 ECDHerror(ECDH_R_POINT_ARITHMETIC_FAILURE);
154 goto err;
155 }
156 } 146 }
157#endif
158 147
159 buflen = ECDH_size(ecdh); 148 buflen = ECDH_size(ecdh);
160 len = BN_num_bytes(x); 149 len = BN_num_bytes(x);
diff --git a/src/lib/libcrypto/ecdsa/ecs_ossl.c b/src/lib/libcrypto/ecdsa/ecs_ossl.c
index aa97a3ad73..e7e7a52665 100644
--- a/src/lib/libcrypto/ecdsa/ecs_ossl.c
+++ b/src/lib/libcrypto/ecdsa/ecs_ossl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecs_ossl.c,v 1.21 2021/04/20 17:16:38 tb Exp $ */ 1/* $OpenBSD: ecs_ossl.c,v 1.22 2021/04/20 17:23:37 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project 3 * Written by Nils Larsch for the OpenSSL project
4 */ 4 */
@@ -205,23 +205,11 @@ ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
205 ECDSAerror(ERR_R_EC_LIB); 205 ECDSAerror(ERR_R_EC_LIB);
206 goto err; 206 goto err;
207 } 207 }
208 if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == 208 if (!EC_POINT_get_affine_coordinates(group, point, X, NULL,
209 NID_X9_62_prime_field) { 209 ctx)) {
210 if (!EC_POINT_get_affine_coordinates(group, point, 210 ECDSAerror(ERR_R_EC_LIB);
211 X, NULL, ctx)) { 211 goto err;
212 ECDSAerror(ERR_R_EC_LIB);
213 goto err;
214 }
215 }
216#ifndef OPENSSL_NO_EC2M
217 else { /* NID_X9_62_characteristic_two_field */
218 if (!EC_POINT_get_affine_coordinates(group, point,
219 X, NULL, ctx)) {
220 ECDSAerror(ERR_R_EC_LIB);
221 goto err;
222 }
223 } 212 }
224#endif
225 if (!BN_nnmod(r, X, order, ctx)) { 213 if (!BN_nnmod(r, X, order, ctx)) {
226 ECDSAerror(ERR_R_BN_LIB); 214 ECDSAerror(ERR_R_BN_LIB);
227 goto err; 215 goto err;
@@ -521,23 +509,10 @@ ecdsa_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig,
521 ECDSAerror(ERR_R_EC_LIB); 509 ECDSAerror(ERR_R_EC_LIB);
522 goto err; 510 goto err;
523 } 511 }
524 if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == 512 if (!EC_POINT_get_affine_coordinates(group, point, X, NULL, ctx)) {
525 NID_X9_62_prime_field) { 513 ECDSAerror(ERR_R_EC_LIB);
526 if (!EC_POINT_get_affine_coordinates(group, point, X, NULL, 514 goto err;
527 ctx)) {
528 ECDSAerror(ERR_R_EC_LIB);
529 goto err;
530 }
531 }
532#ifndef OPENSSL_NO_EC2M
533 else { /* NID_X9_62_characteristic_two_field */
534 if (!EC_POINT_get_affine_coordinates(group, point, X, NULL,
535 ctx)) {
536 ECDSAerror(ERR_R_EC_LIB);
537 goto err;
538 }
539 } 515 }
540#endif
541 if (!BN_nnmod(u1, X, order, ctx)) { 516 if (!BN_nnmod(u1, X, order, ctx)) {
542 ECDSAerror(ERR_R_BN_LIB); 517 ECDSAerror(ERR_R_BN_LIB);
543 goto err; 518 goto err;