From 0b1da5f1fb5e36f4ebab8182d90dfebfa02c2e80 Mon Sep 17 00:00:00 2001 From: tb <> Date: Fri, 7 Jul 2023 06:59:18 +0000 Subject: Mop up remaining uses of ASN1_bn_print() This removes lots of silly buffers and will allow us to make this API go away. ok jsing --- src/lib/libcrypto/ec/ec_ameth.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'src/lib/libcrypto/ec') diff --git a/src/lib/libcrypto/ec/ec_ameth.c b/src/lib/libcrypto/ec/ec_ameth.c index 8676ace9d8..49ae80494d 100644 --- a/src/lib/libcrypto/ec/ec_ameth.c +++ b/src/lib/libcrypto/ec/ec_ameth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_ameth.c,v 1.40 2023/07/03 09:25:44 tb Exp $ */ +/* $OpenBSD: ec_ameth.c,v 1.41 2023/07/07 06:59:18 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -427,9 +427,7 @@ int_ec_free(EVP_PKEY *pkey) static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype) { - unsigned char *buffer = NULL; const char *ecstr; - size_t buf_len = 0, i; int ret = 0, reason = ERR_R_BIO_LIB; BIGNUM *pub_key = NULL; BN_CTX *ctx = NULL; @@ -454,24 +452,13 @@ do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype) reason = ERR_R_EC_LIB; goto err; } - if (pub_key) - buf_len = (size_t) BN_num_bytes(pub_key); } } if (ktype == 2) { priv_key = EC_KEY_get0_private_key(x); - if (priv_key && (i = (size_t) BN_num_bytes(priv_key)) > buf_len) - buf_len = i; } else priv_key = NULL; - if (ktype > 0) { - buf_len += 10; - if ((buffer = malloc(buf_len)) == NULL) { - reason = ERR_R_MALLOC_FAILURE; - goto err; - } - } if (ktype == 2) ecstr = "Private-Key"; else if (ktype == 1) @@ -485,19 +472,21 @@ do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype) EC_GROUP_order_bits(group)) <= 0) goto err; - if (!ASN1_bn_print(bp, "priv:", priv_key, buffer, off)) + if (!bn_printf(bp, priv_key, off, "priv:")) goto err; - if (!ASN1_bn_print(bp, "pub: ", pub_key, buffer, off)) + if (!bn_printf(bp, pub_key, off, "pub: ")) goto err; if (!ECPKParameters_print(bp, group, off)) goto err; + ret = 1; + err: if (!ret) ECerror(reason); BN_free(pub_key); BN_CTX_free(ctx); - free(buffer); + return (ret); } -- cgit v1.2.3-55-g6feb