diff options
author | tb <> | 2023-07-07 06:59:18 +0000 |
---|---|---|
committer | tb <> | 2023-07-07 06:59:18 +0000 |
commit | ded7e344eeedbff393fe259288df7a0f543c49ba (patch) | |
tree | a7603816da4ccfb40c5056865d5382fd66d77983 /src/lib/libcrypto/dsa | |
parent | 3e9606d3676b918eec4f58130ce87818363373b2 (diff) | |
download | openbsd-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/dsa')
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_ameth.c | 61 |
1 files changed, 13 insertions, 48 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_ameth.c b/src/lib/libcrypto/dsa/dsa_ameth.c index f282caae06..5a0c3116aa 100644 --- a/src/lib/libcrypto/dsa/dsa_ameth.c +++ b/src/lib/libcrypto/dsa/dsa_ameth.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dsa_ameth.c,v 1.42 2023/03/04 21:42:49 tb Exp $ */ | 1 | /* $OpenBSD: dsa_ameth.c,v 1.43 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 | */ |
@@ -385,25 +385,12 @@ int_dsa_free(EVP_PKEY *pkey) | |||
385 | DSA_free(pkey->pkey.dsa); | 385 | DSA_free(pkey->pkey.dsa); |
386 | } | 386 | } |
387 | 387 | ||
388 | static void | ||
389 | update_buflen(const BIGNUM *b, size_t *pbuflen) | ||
390 | { | ||
391 | size_t i; | ||
392 | |||
393 | if (!b) | ||
394 | return; | ||
395 | if (*pbuflen < (i = (size_t)BN_num_bytes(b))) | ||
396 | *pbuflen = i; | ||
397 | } | ||
398 | |||
399 | static int | 388 | static int |
400 | do_dsa_print(BIO *bp, const DSA *x, int off, int ptype) | 389 | do_dsa_print(BIO *bp, const DSA *x, int off, int ptype) |
401 | { | 390 | { |
402 | unsigned char *m = NULL; | ||
403 | int ret = 0; | ||
404 | size_t buf_len = 0; | ||
405 | const char *ktype = NULL; | 391 | const char *ktype = NULL; |
406 | const BIGNUM *priv_key, *pub_key; | 392 | const BIGNUM *priv_key, *pub_key; |
393 | int ret = 0; | ||
407 | 394 | ||
408 | if (ptype == 2) | 395 | if (ptype == 2) |
409 | priv_key = x->priv_key; | 396 | priv_key = x->priv_key; |
@@ -422,18 +409,6 @@ do_dsa_print(BIO *bp, const DSA *x, int off, int ptype) | |||
422 | else | 409 | else |
423 | ktype = "DSA-Parameters"; | 410 | ktype = "DSA-Parameters"; |
424 | 411 | ||
425 | update_buflen(x->p, &buf_len); | ||
426 | update_buflen(x->q, &buf_len); | ||
427 | update_buflen(x->g, &buf_len); | ||
428 | update_buflen(priv_key, &buf_len); | ||
429 | update_buflen(pub_key, &buf_len); | ||
430 | |||
431 | m = malloc(buf_len + 10); | ||
432 | if (m == NULL) { | ||
433 | DSAerror(ERR_R_MALLOC_FAILURE); | ||
434 | goto err; | ||
435 | } | ||
436 | |||
437 | if (priv_key) { | 412 | if (priv_key) { |
438 | if (!BIO_indent(bp, off, 128)) | 413 | if (!BIO_indent(bp, off, 128)) |
439 | goto err; | 414 | goto err; |
@@ -442,19 +417,20 @@ do_dsa_print(BIO *bp, const DSA *x, int off, int ptype) | |||
442 | goto err; | 417 | goto err; |
443 | } | 418 | } |
444 | 419 | ||
445 | if (!ASN1_bn_print(bp, "priv:", priv_key, m, off)) | 420 | if (!bn_printf(bp, priv_key, off, "priv:")) |
446 | goto err; | 421 | goto err; |
447 | if (!ASN1_bn_print(bp, "pub: ", pub_key, m, off)) | 422 | if (!bn_printf(bp, pub_key, off, "pub: ")) |
448 | goto err; | 423 | goto err; |
449 | if (!ASN1_bn_print(bp, "P: ", x->p, m, off)) | 424 | if (!bn_printf(bp, x->p, off, "P: ")) |
450 | goto err; | 425 | goto err; |
451 | if (!ASN1_bn_print(bp, "Q: ", x->q, m, off)) | 426 | if (!bn_printf(bp, x->q, off, "Q: ")) |
452 | goto err; | 427 | goto err; |
453 | if (!ASN1_bn_print(bp, "G: ", x->g, m, off)) | 428 | if (!bn_printf(bp, x->g, off, "G: ")) |
454 | goto err; | 429 | goto err; |
430 | |||
455 | ret = 1; | 431 | ret = 1; |
456 | err: | 432 | |
457 | free(m); | 433 | err: |
458 | return ret; | 434 | return ret; |
459 | } | 435 | } |
460 | 436 | ||
@@ -594,27 +570,16 @@ dsa_sig_print(BIO *bp, const X509_ALGOR *sigalg, const ASN1_STRING *sig, | |||
594 | dsa_sig = d2i_DSA_SIG(NULL, &p, sig->length); | 570 | dsa_sig = d2i_DSA_SIG(NULL, &p, sig->length); |
595 | if (dsa_sig) { | 571 | if (dsa_sig) { |
596 | int rv = 0; | 572 | int rv = 0; |
597 | size_t buf_len = 0; | ||
598 | unsigned char *m = NULL; | ||
599 | |||
600 | update_buflen(dsa_sig->r, &buf_len); | ||
601 | update_buflen(dsa_sig->s, &buf_len); | ||
602 | m = malloc(buf_len + 10); | ||
603 | if (m == NULL) { | ||
604 | DSAerror(ERR_R_MALLOC_FAILURE); | ||
605 | goto err; | ||
606 | } | ||
607 | 573 | ||
608 | if (BIO_write(bp, "\n", 1) != 1) | 574 | if (BIO_write(bp, "\n", 1) != 1) |
609 | goto err; | 575 | goto err; |
610 | 576 | ||
611 | if (!ASN1_bn_print(bp, "r: ", dsa_sig->r, m, indent)) | 577 | if (!bn_printf(bp, dsa_sig->r, indent, "r: ")) |
612 | goto err; | 578 | goto err; |
613 | if (!ASN1_bn_print(bp, "s: ", dsa_sig->s, m, indent)) | 579 | if (!bn_printf(bp, dsa_sig->s, indent, "s: ")) |
614 | goto err; | 580 | goto err; |
615 | rv = 1; | 581 | rv = 1; |
616 | err: | 582 | err: |
617 | free(m); | ||
618 | DSA_SIG_free(dsa_sig); | 583 | DSA_SIG_free(dsa_sig); |
619 | return rv; | 584 | return rv; |
620 | } | 585 | } |