1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 01:07:34 +00:00

LibCrypto: Do not trim leading zeros in export_data by default

This fixes the issue with the exported data having a leading zero,
causing RSA::encrypt to trim the block down, and ruining the encryption.

Fixes #2691 :^)
This commit is contained in:
AnotherTest 2020-07-31 13:33:14 +04:30 committed by Andreas Kling
parent 180207062c
commit b00ffc860b
6 changed files with 27 additions and 19 deletions

View file

@ -36,11 +36,15 @@ SignedBigInteger SignedBigInteger::import_data(const u8* ptr, size_t length)
return { move(unsigned_data), sign };
}
size_t SignedBigInteger::export_data(Bytes data) const
size_t SignedBigInteger::export_data(Bytes data, bool remove_leading_zeros) const
{
// FIXME: Support this:
// m <0XX> -> m <XX> (if remove_leading_zeros)
ASSERT(!remove_leading_zeros);
data[0] = m_sign;
auto bytes_view = data.slice(1, data.size() - 1);
return m_unsigned_data.export_data(bytes_view) + 1;
return m_unsigned_data.export_data(bytes_view, remove_leading_zeros) + 1;
}
SignedBigInteger SignedBigInteger::from_base10(StringView str)