Simplify code after adding EC_POINT_{s,g}et_affine_coordinates()
authortb <tb@openbsd.org>
Tue, 20 Apr 2021 17:23:37 +0000 (17:23 +0000)
committertb <tb@openbsd.org>
Tue, 20 Apr 2021 17:23:37 +0000 (17:23 +0000)
ok jsing

lib/libcrypto/ec/ec_key.c
lib/libcrypto/ecdh/ech_key.c
lib/libcrypto/ecdsa/ecs_ossl.c

index 348156e..27b8f26 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ec_key.c,v 1.25 2021/04/20 17:16:37 tb Exp $ */
+/* $OpenBSD: ec_key.c,v 1.26 2021/04/20 17:23:37 tb Exp $ */
 /*
  * Written by Nils Larsch for the OpenSSL project.
  */
@@ -381,7 +381,7 @@ EC_KEY_set_public_key_affine_coordinates(EC_KEY * key, BIGNUM * x, BIGNUM * y)
        BN_CTX *ctx = NULL;
        BIGNUM *tx, *ty;
        EC_POINT *point = NULL;
-       int ok = 0, tmp_nid, is_char_two = 0;
+       int ok = 0;
 
        if (!key || !key->group || !x || !y) {
                ECerror(ERR_R_PASSED_NULL_PARAMETER);
@@ -396,34 +396,15 @@ EC_KEY_set_public_key_affine_coordinates(EC_KEY * key, BIGNUM * x, BIGNUM * y)
        if (!point)
                goto err;
 
-       tmp_nid = EC_METHOD_get_field_type(EC_GROUP_method_of(key->group));
-
-       if (tmp_nid == NID_X9_62_characteristic_two_field)
-               is_char_two = 1;
-
        if ((tx = BN_CTX_get(ctx)) == NULL)
                goto err;
        if ((ty = BN_CTX_get(ctx)) == NULL)
                goto err;
 
-#ifndef OPENSSL_NO_EC2M
-       if (is_char_two) {
-               if (!EC_POINT_set_affine_coordinates(key->group, point,
-                       x, y, ctx))
-                       goto err;
-               if (!EC_POINT_get_affine_coordinates(key->group, point,
-                       tx, ty, ctx))
-                       goto err;
-       } else
-#endif
-       {
-               if (!EC_POINT_set_affine_coordinates(key->group, point,
-                       x, y, ctx))
-                       goto err;
-               if (!EC_POINT_get_affine_coordinates(key->group, point,
-                       tx, ty, ctx))
-                       goto err;
-       }
+       if (!EC_POINT_set_affine_coordinates(key->group, point, x, y, ctx))
+               goto err;
+       if (!EC_POINT_get_affine_coordinates(key->group, point, tx, ty, ctx))
+               goto err;
        /*
         * Check if retrieved coordinates match originals: if not values are
         * out of range.
index c82002e..e59ce8b 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ech_key.c,v 1.10 2021/04/20 17:16:38 tb Exp $ */
+/* $OpenBSD: ech_key.c,v 1.11 2021/04/20 17:23:37 tb Exp $ */
 /* ====================================================================
  * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
  *
@@ -140,21 +140,10 @@ ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
                goto err;
        }
 
-       if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) ==
-           NID_X9_62_prime_field) {
-               if (!EC_POINT_get_affine_coordinates(group, tmp, x, y, ctx)) {
-                       ECDHerror(ECDH_R_POINT_ARITHMETIC_FAILURE);
-                       goto err;
-               }
-       }
-#ifndef OPENSSL_NO_EC2M
-       else {
-               if (!EC_POINT_get_affine_coordinates(group, tmp, x, y, ctx)) {
-                       ECDHerror(ECDH_R_POINT_ARITHMETIC_FAILURE);
-                       goto err;
-               }
+       if (!EC_POINT_get_affine_coordinates(group, tmp, x, y, ctx)) {
+               ECDHerror(ECDH_R_POINT_ARITHMETIC_FAILURE);
+               goto err;
        }
-#endif
 
        buflen = ECDH_size(ecdh);
        len = BN_num_bytes(x);
index aa97a3a..e7e7a52 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ecs_ossl.c,v 1.21 2021/04/20 17:16:38 tb Exp $ */
+/* $OpenBSD: ecs_ossl.c,v 1.22 2021/04/20 17:23:37 tb Exp $ */
 /*
  * Written by Nils Larsch for the OpenSSL project
  */
@@ -205,23 +205,11 @@ ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
                        ECDSAerror(ERR_R_EC_LIB);
                        goto err;
                }
-               if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) ==
-                   NID_X9_62_prime_field) {
-                       if (!EC_POINT_get_affine_coordinates(group, point,
-                           X, NULL, ctx)) {
-                               ECDSAerror(ERR_R_EC_LIB);
-                               goto err;
-                       }
-               }
-#ifndef OPENSSL_NO_EC2M
-               else {  /* NID_X9_62_characteristic_two_field */
-                       if (!EC_POINT_get_affine_coordinates(group, point,
-                           X, NULL, ctx)) {
-                               ECDSAerror(ERR_R_EC_LIB);
-                               goto err;
-                       }
+               if (!EC_POINT_get_affine_coordinates(group, point, X, NULL,
+                   ctx)) {
+                       ECDSAerror(ERR_R_EC_LIB);
+                       goto err;
                }
-#endif
                if (!BN_nnmod(r, X, order, ctx)) {
                        ECDSAerror(ERR_R_BN_LIB);
                        goto err;
@@ -521,23 +509,10 @@ ecdsa_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig,
                ECDSAerror(ERR_R_EC_LIB);
                goto err;
        }
-       if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) ==
-           NID_X9_62_prime_field) {
-               if (!EC_POINT_get_affine_coordinates(group, point, X, NULL,
-                   ctx)) {
-                       ECDSAerror(ERR_R_EC_LIB);
-                       goto err;
-               }
-       }
-#ifndef OPENSSL_NO_EC2M
-       else { /* NID_X9_62_characteristic_two_field */
-               if (!EC_POINT_get_affine_coordinates(group, point, X, NULL,
-                   ctx)) {
-                       ECDSAerror(ERR_R_EC_LIB);
-                       goto err;
-               }
+       if (!EC_POINT_get_affine_coordinates(group, point, X, NULL, ctx)) {
+               ECDSAerror(ERR_R_EC_LIB);
+               goto err;
        }
-#endif
        if (!BN_nnmod(u1, X, order, ctx)) {
                ECDSAerror(ERR_R_BN_LIB);
                goto err;