Skip to content

Commit

Permalink
Align BN_bn2hex behavior with OpenSSL
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel40791765 committed Jan 16, 2025
1 parent 94daeb2 commit 3f8bbe2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crypto/bn_extra/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions crypto/fipsmodule/bn/bn_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2682,7 +2682,7 @@ TEST_F(BNTest, NonMinimal) {
EXPECT_FALSE(BN_is_pow2(ten.get()));

bssl::UniquePtr<char> 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());

Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions crypto/fipsmodule/ec/ec_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit 3f8bbe2

Please sign in to comment.