mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:57:35 +00:00
LibCrypto: Add UnsignedBigInteger multiplication
Also added documentation for the runtime complexity of some operations.
This commit is contained in:
parent
2843dce498
commit
2959c4a5e9
3 changed files with 150 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue