Add missing heading to DSA output.

This seems to just have been a bug. OpenSSL partially fixed it in
https://github.com/openssl/openssl/pull/9983, but upstream's fix
duplicated some logic and outputs "Public-Key" in the ptype == 0
(parameters) case.

Change-Id: I2c669c1cb1a4af50858afd5b1179d3550f3c119a
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/54950
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
fips-20230428
David Benjamin 2 years ago committed by Boringssl LUCI CQ
parent 1e0f0423dd
commit 11c25a65cf
  1. 6
      crypto/evp/evp_extra_test.cc
  2. 13
      crypto/evp/print.c

@ -585,7 +585,8 @@ TEST(EVPExtraTest, Print) {
EVP_PKEY_DSA, kExampleDSAKeyDER, sizeof(kExampleDSAKeyDER)); EVP_PKEY_DSA, kExampleDSAKeyDER, sizeof(kExampleDSAKeyDER));
ASSERT_TRUE(dsa); ASSERT_TRUE(dsa);
EXPECT_EQ(PrintToString(dsa.get(), /*indent=*/2, &EVP_PKEY_print_params), EXPECT_EQ(PrintToString(dsa.get(), /*indent=*/2, &EVP_PKEY_print_params),
R"( P: R"( DSA-Parameters: (2048 bit)
P:
00:9e:12:fa:b3:de:12:21:35:01:dd:82:aa:10:ca: 00:9e:12:fa:b3:de:12:21:35:01:dd:82:aa:10:ca:
2d:10:1d:2d:4e:bf:ef:4d:2a:3f:8d:aa:0f:e0:ce: 2d:10:1d:2d:4e:bf:ef:4d:2a:3f:8d:aa:0f:e0:ce:
da:d8:d6:af:85:61:6a:a2:f3:25:2c:0a:2b:5a:6d: da:d8:d6:af:85:61:6a:a2:f3:25:2c:0a:2b:5a:6d:
@ -629,7 +630,8 @@ TEST(EVPExtraTest, Print) {
61 61
)"); )");
EXPECT_EQ(PrintToString(dsa.get(), /*indent=*/2, &EVP_PKEY_print_public), EXPECT_EQ(PrintToString(dsa.get(), /*indent=*/2, &EVP_PKEY_print_public),
R"( pub: R"( Public-Key: (2048 bit)
pub:
31:97:31:a1:4e:38:56:88:db:94:1d:bf:65:5c:da: 31:97:31:a1:4e:38:56:88:db:94:1d:bf:65:5c:da:
4b:c2:10:de:74:20:03:ce:13:60:f2:25:1d:55:7c: 4b:c2:10:de:74:20:03:ce:13:60:f2:25:1d:55:7c:
5d:94:82:54:08:53:db:85:95:bf:dd:5e:50:d5:96: 5d:94:82:54:08:53:db:85:95:bf:dd:5e:50:d5:96:

@ -210,14 +210,11 @@ static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype) {
ktype = "Public-Key"; ktype = "Public-Key";
} }
if (priv_key) { if (!BIO_indent(bp, off, 128) ||
if (!BIO_indent(bp, off, 128) || BIO_printf(bp, "%s: (%u bit)\n", ktype, BN_num_bits(x->p)) <= 0 ||
BIO_printf(bp, "%s: (%u bit)\n", ktype, BN_num_bits(x->p)) <= 0) { // |priv_key| and |pub_key| may be NULL, in which case |bn_print| will
return 0; // silently skip them.
} !bn_print(bp, "priv:", priv_key, off) ||
}
if (!bn_print(bp, "priv:", priv_key, off) ||
!bn_print(bp, "pub:", pub_key, off) || !bn_print(bp, "pub:", pub_key, off) ||
!bn_print(bp, "P:", x->p, off) || !bn_print(bp, "P:", x->p, off) ||
!bn_print(bp, "Q:", x->q, off) || !bn_print(bp, "Q:", x->q, off) ||

Loading…
Cancel
Save