From f7e8676e318ad7ddea4d4a7d69a79f053bb4c58c Mon Sep 17 00:00:00 2001 From: Theo Buehler Date: Fri, 25 Oct 2024 18:06:43 +0000 Subject: Cosmetic tweak to make point2oct and oct2point more symmetric This can't be perfectly symmetric, but the logic is now roughly the same in both these functions. --- lib/libcrypto/ec/ecp_oct.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/libcrypto/ec/ecp_oct.c b/lib/libcrypto/ec/ecp_oct.c index 0d9a73c5b87..ce63bfadc49 100644 --- a/lib/libcrypto/ec/ecp_oct.c +++ b/lib/libcrypto/ec/ecp_oct.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecp_oct.c,v 1.28 2024/10/24 05:57:25 tb Exp $ */ +/* $OpenBSD: ecp_oct.c,v 1.29 2024/10/25 18:06:42 tb Exp $ */ /* Includes code written by Lenka Fibikova * for the OpenSSL project. * Includes code written by Bodo Moeller for the OpenSSL project. @@ -434,18 +434,22 @@ ec_GFp_simple_oct2point(const EC_GROUP *group, EC_POINT *point, BN_CTX_start(ctx); CBS_init(&cbs, buf, len); - if ((x = BN_CTX_get(ctx)) == NULL) - goto err; - if ((y = BN_CTX_get(ctx)) == NULL) - goto err; - if (!ec_oct_get_leading_octet_cbs(&cbs, &form, &ybit)) goto err; if (form == EC_OCT_POINT_AT_INFINITY) { if (!EC_POINT_set_to_infinity(group, point)) goto err; - } else if (form == EC_OCT_POINT_COMPRESSED) { + + goto done; + } + + if ((x = BN_CTX_get(ctx)) == NULL) + goto err; + if ((y = BN_CTX_get(ctx)) == NULL) + goto err; + + if (form == EC_OCT_POINT_COMPRESSED) { if (!ec_oct_get_field_element_cbs(&cbs, group, x)) goto err; if (!EC_POINT_set_compressed_coordinates(group, point, x, ybit, ctx)) @@ -461,6 +465,7 @@ ec_GFp_simple_oct2point(const EC_GROUP *group, EC_POINT *point, goto err; } + done: if (CBS_len(&cbs) > 0) { ECerror(EC_R_INVALID_ENCODING); goto err; -- cgit v1.2.3