summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/rsa/rsa_ameth.c50
1 files changed, 41 insertions, 9 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_ameth.c b/src/lib/libcrypto/rsa/rsa_ameth.c
index a7e042ef2c..255ccb4d13 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.22 2019/11/01 15:13:05 jsing Exp $ */ 1/* $OpenBSD: rsa_ameth.c,v 1.23 2019/11/02 14:35:48 jsing 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 */
@@ -401,13 +401,44 @@ rsa_pss_param_print(BIO *bp, int pss_key, RSA_PSS_PARAMS *pss, int indent)
401 401
402} 402}
403 403
404static void
405update_buflen(const BIGNUM *b, size_t *pbuflen)
406{
407 size_t i;
408
409 if (!b)
410 return;
411 if (*pbuflen < (i = (size_t)BN_num_bytes(b)))
412 *pbuflen = i;
413}
414
404static int 415static int
405pkey_rsa_print(BIO *bp, const EVP_PKEY *pkey, int off, int priv) 416pkey_rsa_print(BIO *bp, const EVP_PKEY *pkey, int off, int priv)
406{ 417{
407 const RSA *x = pkey->pkey.rsa; 418 const RSA *x = pkey->pkey.rsa;
419 unsigned char *m = NULL;
408 char *str; 420 char *str;
409 const char *s; 421 const char *s;
410 int ret = 0, mod_len = 0; 422 int ret = 0, mod_len = 0;
423 size_t buf_len = 0;
424
425 update_buflen(x->n, &buf_len);
426 update_buflen(x->e, &buf_len);
427
428 if (priv) {
429 update_buflen(x->d, &buf_len);
430 update_buflen(x->p, &buf_len);
431 update_buflen(x->q, &buf_len);
432 update_buflen(x->dmp1, &buf_len);
433 update_buflen(x->dmq1, &buf_len);
434 update_buflen(x->iqmp, &buf_len);
435 }
436
437 m = malloc(buf_len + 10);
438 if (m == NULL) {
439 RSAerror(ERR_R_MALLOC_FAILURE);
440 goto err;
441 }
411 442
412 if (x->n != NULL) 443 if (x->n != NULL)
413 mod_len = BN_num_bits(x->n); 444 mod_len = BN_num_bits(x->n);
@@ -422,28 +453,29 @@ pkey_rsa_print(BIO *bp, const EVP_PKEY *pkey, int off, int priv)
422 goto err; 453 goto err;
423 str = "Modulus:"; 454 str = "Modulus:";
424 s = "Exponent:"; 455 s = "Exponent:";
425 if (!ASN1_bn_print(bp, str, x->n, NULL, off)) 456 if (!ASN1_bn_print(bp, str, x->n, m, off))
426 goto err; 457 goto err;
427 if (!ASN1_bn_print(bp, s, x->e, NULL, off)) 458 if (!ASN1_bn_print(bp, s, x->e, m, off))
428 goto err; 459 goto err;
429 if (priv) { 460 if (priv) {
430 if (!ASN1_bn_print(bp, "privateExponent:", x->d, NULL, off)) 461 if (!ASN1_bn_print(bp, "privateExponent:", x->d, m, off))
431 goto err; 462 goto err;
432 if (!ASN1_bn_print(bp, "prime1:", x->p, NULL, off)) 463 if (!ASN1_bn_print(bp, "prime1:", x->p, m, off))
433 goto err; 464 goto err;
434 if (!ASN1_bn_print(bp, "prime2:", x->q, NULL, off)) 465 if (!ASN1_bn_print(bp, "prime2:", x->q, m, off))
435 goto err; 466 goto err;
436 if (!ASN1_bn_print(bp, "exponent1:", x->dmp1, NULL, off)) 467 if (!ASN1_bn_print(bp, "exponent1:", x->dmp1, m, off))
437 goto err; 468 goto err;
438 if (!ASN1_bn_print(bp, "exponent2:", x->dmq1, NULL, off)) 469 if (!ASN1_bn_print(bp, "exponent2:", x->dmq1, m, off))
439 goto err; 470 goto err;
440 if (!ASN1_bn_print(bp, "coefficient:", x->iqmp, NULL, off)) 471 if (!ASN1_bn_print(bp, "coefficient:", x->iqmp, m, off))
441 goto err; 472 goto err;
442 } 473 }
443 if (pkey_is_pss(pkey) && !rsa_pss_param_print(bp, 1, x->pss, off)) 474 if (pkey_is_pss(pkey) && !rsa_pss_param_print(bp, 1, x->pss, off))
444 goto err; 475 goto err;
445 ret = 1; 476 ret = 1;
446 err: 477 err:
478 free(m);
447 return ret; 479 return ret;
448} 480}
449 481