From a7e9e84df4b1bb92bc901512f88edfe5105ff524 Mon Sep 17 00:00:00 2001 From: tb Date: Wed, 26 Jul 2023 12:16:13 +0000 Subject: [PATCH] Streamline check_discriminant() Instead of inlining EC_GROUP_get_curve(), we can simply call it... ok jsing --- lib/libcrypto/ec/ecp_smpl.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/lib/libcrypto/ec/ecp_smpl.c b/lib/libcrypto/ec/ecp_smpl.c index 21d0d32ef98..1a467d4f8f6 100644 --- a/lib/libcrypto/ec/ecp_smpl.c +++ b/lib/libcrypto/ec/ecp_smpl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecp_smpl.c,v 1.50 2023/07/26 12:12:13 tb Exp $ */ +/* $OpenBSD: ecp_smpl.c,v 1.51 2023/07/26 12:16:13 tb Exp $ */ /* Includes code written by Lenka Fibikova * for the OpenSSL project. * Includes code written by Bodo Moeller for the OpenSSL project. @@ -203,12 +203,13 @@ ec_GFp_simple_group_get_degree(const EC_GROUP *group) int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) { - BIGNUM *a, *b, *order, *tmp_1, *tmp_2; - const BIGNUM *p = &group->field; + BIGNUM *p, *a, *b, *order, *tmp_1, *tmp_2; int ret = 0; BN_CTX_start(ctx); + if ((p = BN_CTX_get(ctx)) == NULL) + goto err; if ((a = BN_CTX_get(ctx)) == NULL) goto err; if ((b = BN_CTX_get(ctx)) == NULL) @@ -220,17 +221,8 @@ ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) if ((order = BN_CTX_get(ctx)) == NULL) goto err; - if (group->meth->field_decode) { - if (!group->meth->field_decode(group, a, &group->a, ctx)) - goto err; - if (!group->meth->field_decode(group, b, &group->b, ctx)) - goto err; - } else { - if (!bn_copy(a, &group->a)) - goto err; - if (!bn_copy(b, &group->b)) - goto err; - } + if (!EC_GROUP_get_curve(group, p, a, b, ctx)) + goto err; /* * check the discriminant: y^2 = x^3 + a*x + b is an elliptic curve -- 2.20.1