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

LibCrypto: Do not allow signed big integers to be negative zero

If a big integer were to become negative zero, set the sign to instead
be positive. This prevents odd scenarios where users of signed big ints
would falsely think the result of some big int arithmetic is negative.
This commit is contained in:
Timothy Flynn 2022-02-06 13:17:34 +00:00 committed by Linus Groh
parent 4d785b9aa0
commit b0d6399f60
4 changed files with 45 additions and 2 deletions

View file

@ -145,6 +145,16 @@ void UnsignedBigInteger::set_to(const UnsignedBigInteger& other)
m_cached_hash = 0;
}
bool UnsignedBigInteger::is_zero() const
{
for (size_t i = 0; i < length(); ++i) {
if (m_words[i] != 0)
return false;
}
return true;
}
size_t UnsignedBigInteger::trimmed_length() const
{
if (!m_cached_trimmed_length.has_value()) {