From 198c8abda2dbade2e5be1aebfc5d0c25d2944274 Mon Sep 17 00:00:00 2001 From: tb <> Date: Wed, 30 Oct 2024 18:01:52 +0000 Subject: Rewrite EC_POINT_bn2point() This is slightly asymmetric with EC_POINT_point2bn() and different from the other "print" functions since it has to deal with the asymmetry between BN_bin2bn() and BN_bn2bin() and allocate itself. Still, we can make this substantially shorter than it previously was. ok jsing --- src/lib/libcrypto/ec/ec_print.c | 43 ++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libcrypto/ec/ec_print.c b/src/lib/libcrypto/ec/ec_print.c index be5f845423..7a479a3ddc 100644 --- a/src/lib/libcrypto/ec/ec_print.c +++ b/src/lib/libcrypto/ec/ec_print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_print.c,v 1.18 2024/10/30 17:51:35 tb Exp $ */ +/* $OpenBSD: ec_print.c,v 1.19 2024/10/30 18:01:52 tb Exp $ */ /* ==================================================================== * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. * @@ -84,36 +84,23 @@ EC_POINT * EC_POINT_bn2point(const EC_GROUP *group, const BIGNUM *bn, EC_POINT *point, BN_CTX *ctx) { + unsigned char *buf = NULL; size_t buf_len = 0; - unsigned char *buf; - EC_POINT *ret; + /* Of course BN_bn2bin() is in no way symmetric to BN_bin2bn()... */ if ((buf_len = BN_num_bytes(bn)) == 0) - return NULL; - buf = malloc(buf_len); - if (buf == NULL) - return NULL; - - if (!BN_bn2bin(bn, buf)) { - free(buf); - return NULL; - } - if (point == NULL) { - if ((ret = EC_POINT_new(group)) == NULL) { - free(buf); - return NULL; - } - } else - ret = point; - - if (!EC_POINT_oct2point(group, ret, buf, buf_len, ctx)) { - if (point == NULL) - EC_POINT_free(ret); - free(buf); - return NULL; - } - free(buf); - return ret; + goto err; + if ((buf = calloc(1, buf_len)) == NULL) + goto err; + if (!BN_bn2bin(bn, buf)) + goto err; + if (!ec_point_from_octets(group, buf, buf_len, &point, NULL, ctx)) + goto err; + + err: + freezero(buf, buf_len); + + return point; } LCRYPTO_ALIAS(EC_POINT_bn2point); -- cgit v1.2.3-55-g6feb