diff options
Diffstat (limited to 'src/lib/libcrypto/rsa/rsa_ameth.c')
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_ameth.c | 51 |
1 files changed, 10 insertions, 41 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_ameth.c b/src/lib/libcrypto/rsa/rsa_ameth.c index 1cf2069a18..825a9f4447 100644 --- a/src/lib/libcrypto/rsa/rsa_ameth.c +++ b/src/lib/libcrypto/rsa/rsa_ameth.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: rsa_ameth.c,v 1.29 2023/05/19 17:31:20 tb Exp $ */ | 1 | /* $OpenBSD: rsa_ameth.c,v 1.30 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 | */ |
| @@ -68,6 +68,7 @@ | |||
| 68 | #include <openssl/x509.h> | 68 | #include <openssl/x509.h> |
| 69 | 69 | ||
| 70 | #include "asn1_local.h" | 70 | #include "asn1_local.h" |
| 71 | #include "bn_local.h" | ||
| 71 | #include "cryptlib.h" | 72 | #include "cryptlib.h" |
| 72 | #include "evp_local.h" | 73 | #include "evp_local.h" |
| 73 | #include "rsa_local.h" | 74 | #include "rsa_local.h" |
| @@ -408,44 +409,13 @@ rsa_pss_param_print(BIO *bp, int pss_key, RSA_PSS_PARAMS *pss, int indent) | |||
| 408 | 409 | ||
| 409 | } | 410 | } |
| 410 | 411 | ||
| 411 | static void | ||
| 412 | update_buflen(const BIGNUM *b, size_t *pbuflen) | ||
| 413 | { | ||
| 414 | size_t i; | ||
| 415 | |||
| 416 | if (!b) | ||
| 417 | return; | ||
| 418 | if (*pbuflen < (i = (size_t)BN_num_bytes(b))) | ||
| 419 | *pbuflen = i; | ||
| 420 | } | ||
| 421 | |||
| 422 | static int | 412 | static int |
| 423 | pkey_rsa_print(BIO *bp, const EVP_PKEY *pkey, int off, int priv) | 413 | pkey_rsa_print(BIO *bp, const EVP_PKEY *pkey, int off, int priv) |
| 424 | { | 414 | { |
| 425 | const RSA *x = pkey->pkey.rsa; | 415 | const RSA *x = pkey->pkey.rsa; |
| 426 | unsigned char *m = NULL; | ||
| 427 | char *str; | 416 | char *str; |
| 428 | const char *s; | 417 | const char *s; |
| 429 | int ret = 0, mod_len = 0; | 418 | int ret = 0, mod_len = 0; |
| 430 | size_t buf_len = 0; | ||
| 431 | |||
| 432 | update_buflen(x->n, &buf_len); | ||
| 433 | update_buflen(x->e, &buf_len); | ||
| 434 | |||
| 435 | if (priv) { | ||
| 436 | update_buflen(x->d, &buf_len); | ||
| 437 | update_buflen(x->p, &buf_len); | ||
| 438 | update_buflen(x->q, &buf_len); | ||
| 439 | update_buflen(x->dmp1, &buf_len); | ||
| 440 | update_buflen(x->dmq1, &buf_len); | ||
| 441 | update_buflen(x->iqmp, &buf_len); | ||
| 442 | } | ||
| 443 | |||
| 444 | m = malloc(buf_len + 10); | ||
| 445 | if (m == NULL) { | ||
| 446 | RSAerror(ERR_R_MALLOC_FAILURE); | ||
| 447 | goto err; | ||
| 448 | } | ||
| 449 | 419 | ||
| 450 | if (x->n != NULL) | 420 | if (x->n != NULL) |
| 451 | mod_len = BN_num_bits(x->n); | 421 | mod_len = BN_num_bits(x->n); |
| @@ -467,29 +437,28 @@ pkey_rsa_print(BIO *bp, const EVP_PKEY *pkey, int off, int priv) | |||
| 467 | str = "Modulus:"; | 437 | str = "Modulus:"; |
| 468 | s = "Exponent:"; | 438 | s = "Exponent:"; |
| 469 | } | 439 | } |
| 470 | if (!ASN1_bn_print(bp, str, x->n, m, off)) | 440 | if (!bn_printf(bp, x->n, off, "%s", str)) |
| 471 | goto err; | 441 | goto err; |
| 472 | if (!ASN1_bn_print(bp, s, x->e, m, off)) | 442 | if (!bn_printf(bp, x->e, off, "%s", s)) |
| 473 | goto err; | 443 | goto err; |
| 474 | if (priv) { | 444 | if (priv) { |
| 475 | if (!ASN1_bn_print(bp, "privateExponent:", x->d, m, off)) | 445 | if (!bn_printf(bp, x->d, off, "privateExponent:")) |
| 476 | goto err; | 446 | goto err; |
| 477 | if (!ASN1_bn_print(bp, "prime1:", x->p, m, off)) | 447 | if (!bn_printf(bp, x->p, off, "prime1:")) |
| 478 | goto err; | 448 | goto err; |
| 479 | if (!ASN1_bn_print(bp, "prime2:", x->q, m, off)) | 449 | if (!bn_printf(bp, x->q, off, "prime2:")) |
| 480 | goto err; | 450 | goto err; |
| 481 | if (!ASN1_bn_print(bp, "exponent1:", x->dmp1, m, off)) | 451 | if (!bn_printf(bp, x->dmp1, off, "exponent1:")) |
| 482 | goto err; | 452 | goto err; |
| 483 | if (!ASN1_bn_print(bp, "exponent2:", x->dmq1, m, off)) | 453 | if (!bn_printf(bp, x->dmq1, off, "exponent2:")) |
| 484 | goto err; | 454 | goto err; |
| 485 | if (!ASN1_bn_print(bp, "coefficient:", x->iqmp, m, off)) | 455 | if (!bn_printf(bp, x->iqmp, off, "coefficient:")) |
| 486 | goto err; | 456 | goto err; |
| 487 | } | 457 | } |
| 488 | if (pkey_is_pss(pkey) && !rsa_pss_param_print(bp, 1, x->pss, off)) | 458 | if (pkey_is_pss(pkey) && !rsa_pss_param_print(bp, 1, x->pss, off)) |
| 489 | goto err; | 459 | goto err; |
| 490 | ret = 1; | 460 | ret = 1; |
| 491 | err: | 461 | err: |
| 492 | free(m); | ||
| 493 | return ret; | 462 | return ret; |
| 494 | } | 463 | } |
| 495 | 464 | ||
