diff options
author | Itamar <itamar8910@gmail.com> | 2020-04-08 19:04:36 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-02 12:24:10 +0200 |
commit | 2959c4a5e93cbdda3dd5bf44c6151fedb97a8d82 (patch) | |
tree | cb5a306dc97cd9809ed9a9f8289350258ef03fc0 /Userland | |
parent | 2843dce49847857e68c602dd37357c1c278d5cb9 (diff) | |
download | serenity-2959c4a5e93cbdda3dd5bf44c6151fedb97a8d82.zip |
LibCrypto: Add UnsignedBigInteger multiplication
Also added documentation for the runtime complexity of some operations.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/test-crypto.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Userland/test-crypto.cpp b/Userland/test-crypto.cpp index 5b38d8a692..c8e9759bde 100644 --- a/Userland/test-crypto.cpp +++ b/Userland/test-crypto.cpp @@ -305,6 +305,7 @@ void hmac_sha512_test_process(); void bigint_test_fibo500(); void bigint_addition_edgecases(); void bigint_subtraction(); +void bigint_multiplication(); int aes_cbc_tests() { @@ -799,6 +800,7 @@ int bigint_tests() bigint_test_fibo500(); bigint_addition_edgecases(); bigint_subtraction(); + bigint_multiplication(); return 0; } @@ -851,6 +853,8 @@ void bigint_addition_edgecases() PASS; } else { FAIL(Incorrect Result); + } + } } void bigint_subtraction() @@ -902,3 +906,41 @@ void bigint_subtraction() } } } + +void bigint_multiplication() +{ + { + I_TEST((BigInteger | Simple Multipliction)); + Crypto::UnsignedBigInteger num1(8); + Crypto::UnsignedBigInteger num2(251); + Crypto::UnsignedBigInteger result = num1.multiply(num2); + dbg() << "result: " << result; + if (result.words() == Vector<u32> { 2008 }) { + PASS; + } else { + FAIL(Incorrect Result); + } + } + { + I_TEST((BigInteger | Multiplications with big numbers 1)); + Crypto::UnsignedBigInteger num1 = bigint_fibonacci(200); + Crypto::UnsignedBigInteger num2(12345678); + Crypto::UnsignedBigInteger result = num1.multiply(num2); + if (result.words() == Vector<u32> { 669961318, 143970113, 4028714974, 3164551305, 1589380278, 2 }) { + PASS; + } else { + FAIL(Incorrect Result); + } + } + { + I_TEST((BigInteger | Multiplications with big numbers 2)); + Crypto::UnsignedBigInteger num1 = bigint_fibonacci(200); + Crypto::UnsignedBigInteger num2 = bigint_fibonacci(341); + Crypto::UnsignedBigInteger result = num1.multiply(num2); + if (result.words() == Vector<u32> { 3017415433, 2741793511, 1957755698, 3731653885, 3154681877, 785762127, 3200178098, 4260616581, 529754471, 3632684436, 1073347813, 2516430 }) { + PASS; + } else { + FAIL(Incorrect Result); + } + } +} |