summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2020-04-08 16:00:02 +0300
committerAndreas Kling <kling@serenityos.org>2020-05-02 12:24:10 +0200
commit2843dce49847857e68c602dd37357c1c278d5cb9 (patch)
treee30ed72876b8760b29a79f2184c69e80daec626c /Userland
parente0cf40518c2bde05030058c487268d2001c79cda (diff)
downloadserenity-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 'Userland')
-rw-r--r--Userland/test-crypto.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/Userland/test-crypto.cpp b/Userland/test-crypto.cpp
index 127bf55989..5b38d8a692 100644
--- a/Userland/test-crypto.cpp
+++ b/Userland/test-crypto.cpp
@@ -843,6 +843,14 @@ void bigint_addition_edgecases()
FAIL(Incorrect Result);
}
}
+ {
+ I_TEST((BigInteger | Borrow with zero));
+ Crypto::UnsignedBigInteger num1({ UINT32_MAX - 3, UINT32_MAX });
+ Crypto::UnsignedBigInteger num2({ UINT32_MAX - 2, 0 });
+ if (num1.add(num2).words() == Vector<u32> { 4294967289, 0, 1 }) {
+ PASS;
+ } else {
+ FAIL(Incorrect Result);
}
void bigint_subtraction()