From 232b7b3fad9cda6a79c2698b31e4d2af3bb8315e Mon Sep 17 00:00:00 2001 From: Samuel Chiang Date: Thu, 16 Jan 2025 09:39:12 -0800 Subject: [PATCH] Align BN_bn2hex behavior with OpenSSL (#2122) OpenSSL's historically printed `BN_bn2hex` with upper case letters, as opposed to our original upstream predecessors. We haven't had a concrete ask to change this until recently: https://github.com/ruby/openssl/issues/833. As most of the open source community and our integration targets still depend on OpenSSL as their main libcrypto dependency, we should consider making the minor adjustment to minimize churn for us and our consumers. ### Testing: Tweaks to existing tests. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license. --- 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()); }