Commit 0ad7e68b authored by Kevin Jacobs's avatar Kevin Jacobs

Bug 1605922 - Account for negative sign in mp_radix_size r=bbeurdouche

Differential Revision: https://phabricator.services.mozilla.com/D86443

--HG--
extra : moz-landing-system : lando
parent 7290f543
......@@ -192,6 +192,39 @@ TEST_F(MPITest, MpiFixlenOctetsZero) {
TestToFixedOctets(zero, sizeof(mp_digit) + 1);
}
TEST_F(MPITest, MpiRadixSizeNeg) {
char* str;
mp_int a;
mp_err rv;
const char* negative_edge =
"-5400000000000000003000000002200020090919017007777777777870000090"
"00000000007500443416610000000000000000000000000000000000000000000"
"00000000000000000000000000000000000000000000000000000000075049054"
"18610000800555594485440016000031555550000000000000000220030200909"
"19017007777777700000000000000000000000000000000000000000000000000"
"00000000000500000000000000000000000000004668129841661000071000000"
"00000000000000000000000000000000000000000000000007504434166100000"
"00000000000000000000000000000000000000000000000000000000000000000"
"00000000075049054186100008005555944854400184572169555500000000000"
"0000022003020090919017007777777700000000000000000000";
rv = mp_init(&a);
ASSERT_EQ(MP_OKAY, rv);
rv = mp_read_variable_radix(&a, negative_edge, 10);
ASSERT_EQ(MP_OKAY, rv);
const int radixSize = mp_radix_size(&a, 10);
ASSERT_LE(0, radixSize);
str = (char*)malloc(radixSize);
ASSERT_NE(nullptr, str);
rv = mp_toradix(&a, str, 10);
ASSERT_EQ(MP_OKAY, rv);
ASSERT_EQ(0, strcmp(negative_edge, str));
free(str);
mp_clear(&a);
}
TEST_F(MPITest, MpiFixlenOctetsVarlen) {
std::vector<uint8_t> packed;
for (size_t i = 0; i < sizeof(mp_digit) * 2; ++i) {
......
......@@ -2693,7 +2693,7 @@ mp_radix_size(mp_int *mp, int radix)
bits = USED(mp) * DIGIT_BIT - 1;
return s_mp_outlen(bits, radix);
return SIGN(mp) + s_mp_outlen(bits, radix);
} /* end mp_radix_size() */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment