diff options
Diffstat (limited to 'src/lib/libcrypto/ec')
| -rw-r--r-- | src/lib/libcrypto/ec/ec_ameth.c | 23 |
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) | |||
| 427 | static int | 427 | static int |
| 428 | do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype) | 428 | do_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 | ||
