Skip to content

Commit 232b7b3

Browse files
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: ruby/openssl#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.
1 parent ed5764b commit 232b7b3

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

crypto/bn_extra/convert.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ int BN_bn2cbb_padded(CBB *out, size_t len, const BIGNUM *in) {
7474
return CBB_add_space(out, &ptr, len) && BN_bn2bin_padded(ptr, len, in);
7575
}
7676

77-
static const char hextable[] = "0123456789abcdef";
77+
static const char hextable[] = "0123456789ABCDEF";
7878

7979
char *BN_bn2hex(const BIGNUM *bn) {
8080
int width = bn_minimal_width(bn);

crypto/fipsmodule/bn/bn_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,7 +2682,7 @@ TEST_F(BNTest, NonMinimal) {
26822682
EXPECT_FALSE(BN_is_pow2(ten.get()));
26832683

26842684
bssl::UniquePtr<char> hex(BN_bn2hex(ten.get()));
2685-
EXPECT_STREQ("0a", hex.get());
2685+
EXPECT_STREQ("0A", hex.get());
26862686
hex.reset(BN_bn2hex(zero.get()));
26872687
EXPECT_STREQ("0", hex.get());
26882688

@@ -2695,7 +2695,7 @@ TEST_F(BNTest, NonMinimal) {
26952695
// TODO(davidben): |BN_print| removes leading zeros within a byte, while
26962696
// |BN_bn2hex| rounds up to a byte, except for zero which it prints as
26972697
// "0". Fix this discrepancy?
2698-
EXPECT_EQ(Bytes("a"), Bytes(ptr, len));
2698+
EXPECT_EQ(Bytes("A"), Bytes(ptr, len));
26992699

27002700
bio.reset(BIO_new(BIO_s_mem()));
27012701
ASSERT_TRUE(bio);

crypto/fipsmodule/ec/ec_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ TEST(ECTest, Encoding) {
179179
ASSERT_TRUE(y_hex);
180180

181181
EXPECT_STREQ(
182-
"c81561ecf2e54edefe6617db1c7a34a70744ddb261f269b83dacfcd2ade5a681",
182+
"C81561ECF2E54EDEFE6617DB1C7A34A70744DDB261F269B83DACFCD2ADE5A681",
183183
x_hex.get());
184184
EXPECT_STREQ(
185-
"e0e2afa3f9b6abe4c698ef6495f1be49a3196c5056acb3763fe4507eec596e88",
185+
"E0E2AFA3F9B6ABE4C698EF6495F1BE49A3196C5056ACB3763FE4507EEC596E88",
186186
y_hex.get());
187187
}
188188

0 commit comments

Comments
 (0)