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>
diff --git a/crypto/evp/evp_extra_test.cc b/crypto/evp/evp_extra_test.cc
index a606f68..c88ad7f 100644
--- a/crypto/evp/evp_extra_test.cc
+++ b/crypto/evp/evp_extra_test.cc
@@ -585,7 +585,8 @@
EVP_PKEY_DSA, kExampleDSAKeyDER, sizeof(kExampleDSAKeyDER));
ASSERT_TRUE(dsa);
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:
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:
@@ -629,7 +630,8 @@
61
)");
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:
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:
diff --git a/crypto/evp/print.c b/crypto/evp/print.c
index 56645b5..ff3868e 100644
--- a/crypto/evp/print.c
+++ b/crypto/evp/print.c
@@ -210,14 +210,11 @@
ktype = "Public-Key";
}
- if (priv_key) {
- if (!BIO_indent(bp, off, 128) ||
- BIO_printf(bp, "%s: (%u bit)\n", ktype, BN_num_bits(x->p)) <= 0) {
- return 0;
- }
- }
-
- if (!bn_print(bp, "priv:", priv_key, off) ||
+ if (!BIO_indent(bp, off, 128) ||
+ 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
+ // silently skip them.
+ !bn_print(bp, "priv:", priv_key, off) ||
!bn_print(bp, "pub:", pub_key, off) ||
!bn_print(bp, "P:", x->p, off) ||
!bn_print(bp, "Q:", x->q, off) ||