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

LibCrypto: Fix a bug in big int addition

There was a bug when dealing with a carry when the addition
result for the current word was UINT32_MAX.

This commit also adds a regression test for the bug.
This commit is contained in:
Itamar 2020-04-08 16:00:02 +03:00 committed by Andreas Kling
parent e0cf40518c
commit 2843dce498
2 changed files with 9 additions and 1 deletions

View file

@ -39,7 +39,7 @@ UnsignedBigInteger UnsignedBigInteger::add(const UnsignedBigInteger& other)
u32 word_addition_result = shorter->m_words[i] + longer->m_words[i];
u8 carry_out = 0;
// if there was a carry, the result will be smaller than any of the operands
if (word_addition_result < shorter->m_words[i]) {
if (word_addition_result + carry < shorter->m_words[i]) {
carry_out = 1;
}
if (carry) {