diff options
author | Itamar <itamar8910@gmail.com> | 2020-04-08 16:00:02 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-02 12:24:10 +0200 |
commit | 2843dce49847857e68c602dd37357c1c278d5cb9 (patch) | |
tree | e30ed72876b8760b29a79f2184c69e80daec626c /Libraries/LibCrypto | |
parent | e0cf40518c2bde05030058c487268d2001c79cda (diff) | |
download | serenity-2843dce49847857e68c602dd37357c1c278d5cb9.zip |
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.
Diffstat (limited to 'Libraries/LibCrypto')
-rw-r--r-- | Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp b/Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp index 987abce7bd..57c0bae64d 100644 --- a/Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp +++ b/Libraries/LibCrypto/BigInt/UnsignedBigInteger.cpp @@ -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) { |