From 3f8bbe23cf07f18c4427f571246e7e65c6e767c7 Mon Sep 17 00:00:00 2001 From: Samuel Chiang Date: Thu, 16 Jan 2025 02:49:44 +0000 Subject: [PATCH] Align BN_bn2hex behavior with OpenSSL --- crypto/bn_extra/convert.c | 2 +- crypto/fipsmodule/bn/bn_test.cc | 4 ++-- crypto/fipsmodule/ec/ec_test.cc | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crypto/bn_extra/convert.c b/crypto/bn_extra/convert.c index 7a02e105f5..f863dd6ae6 100644 --- a/crypto/bn_extra/convert.c +++ b/crypto/bn_extra/convert.c @@ -74,7 +74,7 @@ int BN_bn2cbb_padded(CBB *out, size_t len, const BIGNUM *in) { return CBB_add_space(out, &ptr, len) && BN_bn2bin_padded(ptr, len, in); } -static const char hextable[] = "0123456789abcdef"; +static const char hextable[] = "0123456789ABCDEF"; char *BN_bn2hex(const BIGNUM *bn) { int width = bn_minimal_width(bn); diff --git a/crypto/fipsmodule/bn/bn_test.cc b/crypto/fipsmodule/bn/bn_test.cc index b14a86725b..8e747722e2 100644 --- a/crypto/fipsmodule/bn/bn_test.cc +++ b/crypto/fipsmodule/bn/bn_test.cc @@ -2682,7 +2682,7 @@ TEST_F(BNTest, NonMinimal) { EXPECT_FALSE(BN_is_pow2(ten.get())); bssl::UniquePtr hex(BN_bn2hex(ten.get())); - EXPECT_STREQ("0a", hex.get()); + EXPECT_STREQ("0A", hex.get()); hex.reset(BN_bn2hex(zero.get())); EXPECT_STREQ("0", hex.get()); @@ -2695,7 +2695,7 @@ TEST_F(BNTest, NonMinimal) { // TODO(davidben): |BN_print| removes leading zeros within a byte, while // |BN_bn2hex| rounds up to a byte, except for zero which it prints as // "0". Fix this discrepancy? - EXPECT_EQ(Bytes("a"), Bytes(ptr, len)); + EXPECT_EQ(Bytes("A"), Bytes(ptr, len)); bio.reset(BIO_new(BIO_s_mem())); ASSERT_TRUE(bio); diff --git a/crypto/fipsmodule/ec/ec_test.cc b/crypto/fipsmodule/ec/ec_test.cc index b65d53215b..d5c5ad9b91 100644 --- a/crypto/fipsmodule/ec/ec_test.cc +++ b/crypto/fipsmodule/ec/ec_test.cc @@ -179,10 +179,10 @@ TEST(ECTest, Encoding) { ASSERT_TRUE(y_hex); EXPECT_STREQ( - "c81561ecf2e54edefe6617db1c7a34a70744ddb261f269b83dacfcd2ade5a681", + "C81561ECF2E54EDEFE6617DB1C7A34A70744DDB261F269B83DACFCD2ADE5A681", x_hex.get()); EXPECT_STREQ( - "e0e2afa3f9b6abe4c698ef6495f1be49a3196c5056acb3763fe4507eec596e88", + "E0E2AFA3F9B6ABE4C698EF6495F1BE49A3196C5056ACB3763FE4507EEC596E88", y_hex.get()); }