summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec
diff options
context:
space:
mode:
authortb <>2023-07-07 06:59:18 +0000
committertb <>2023-07-07 06:59:18 +0000
commitded7e344eeedbff393fe259288df7a0f543c49ba (patch)
treea7603816da4ccfb40c5056865d5382fd66d77983 /src/lib/libcrypto/ec
parent3e9606d3676b918eec4f58130ce87818363373b2 (diff)
downloadopenbsd-ded7e344eeedbff393fe259288df7a0f543c49ba.tar.gz
openbsd-ded7e344eeedbff393fe259288df7a0f543c49ba.tar.bz2
openbsd-ded7e344eeedbff393fe259288df7a0f543c49ba.zip
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
Diffstat (limited to 'src/lib/libcrypto/ec')
-rw-r--r--src/lib/libcrypto/ec/ec_ameth.c23
1 files changed, 6 insertions, 17 deletions
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 @@
1/* $OpenBSD: ec_ameth.c,v 1.40 2023/07/03 09:25:44 tb Exp $ */ 1/* $OpenBSD: ec_ameth.c,v 1.41 2023/07/07 06:59:18 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -427,9 +427,7 @@ int_ec_free(EVP_PKEY *pkey)
427static int 427static int
428do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype) 428do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype)
429{ 429{
430 unsigned char *buffer = NULL;
431 const char *ecstr; 430 const char *ecstr;
432 size_t buf_len = 0, i;
433 int ret = 0, reason = ERR_R_BIO_LIB; 431 int ret = 0, reason = ERR_R_BIO_LIB;
434 BIGNUM *pub_key = NULL; 432 BIGNUM *pub_key = NULL;
435 BN_CTX *ctx = NULL; 433 BN_CTX *ctx = NULL;
@@ -454,24 +452,13 @@ do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype)
454 reason = ERR_R_EC_LIB; 452 reason = ERR_R_EC_LIB;
455 goto err; 453 goto err;
456 } 454 }
457 if (pub_key)
458 buf_len = (size_t) BN_num_bytes(pub_key);
459 } 455 }
460 } 456 }
461 if (ktype == 2) { 457 if (ktype == 2) {
462 priv_key = EC_KEY_get0_private_key(x); 458 priv_key = EC_KEY_get0_private_key(x);
463 if (priv_key && (i = (size_t) BN_num_bytes(priv_key)) > buf_len)
464 buf_len = i;
465 } else 459 } else
466 priv_key = NULL; 460 priv_key = NULL;
467 461
468 if (ktype > 0) {
469 buf_len += 10;
470 if ((buffer = malloc(buf_len)) == NULL) {
471 reason = ERR_R_MALLOC_FAILURE;
472 goto err;
473 }
474 }
475 if (ktype == 2) 462 if (ktype == 2)
476 ecstr = "Private-Key"; 463 ecstr = "Private-Key";
477 else if (ktype == 1) 464 else if (ktype == 1)
@@ -485,19 +472,21 @@ do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype)
485 EC_GROUP_order_bits(group)) <= 0) 472 EC_GROUP_order_bits(group)) <= 0)
486 goto err; 473 goto err;
487 474
488 if (!ASN1_bn_print(bp, "priv:", priv_key, buffer, off)) 475 if (!bn_printf(bp, priv_key, off, "priv:"))
489 goto err; 476 goto err;
490 if (!ASN1_bn_print(bp, "pub: ", pub_key, buffer, off)) 477 if (!bn_printf(bp, pub_key, off, "pub: "))
491 goto err; 478 goto err;
492 if (!ECPKParameters_print(bp, group, off)) 479 if (!ECPKParameters_print(bp, group, off))
493 goto err; 480 goto err;
481
494 ret = 1; 482 ret = 1;
483
495 err: 484 err:
496 if (!ret) 485 if (!ret)
497 ECerror(reason); 486 ECerror(reason);
498 BN_free(pub_key); 487 BN_free(pub_key);
499 BN_CTX_free(ctx); 488 BN_CTX_free(ctx);
500 free(buffer); 489
501 return (ret); 490 return (ret);
502} 491}
503 492