1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 00:37:35 +00:00

LibCrypto: Add base-10 string de/serialization methods for bigint

This commit is contained in:
Itamar 2020-04-09 17:09:11 +03:00 committed by Andreas Kling
parent 709c691f38
commit 2125a4debb
3 changed files with 67 additions and 2 deletions

View file

@ -307,6 +307,7 @@ void bigint_addition_edgecases();
void bigint_subtraction();
void bigint_multiplication();
void bigint_division();
void bigint_base10();
int aes_cbc_tests()
{
@ -803,6 +804,7 @@ int bigint_tests()
bigint_subtraction();
bigint_multiplication();
bigint_division();
bigint_base10();
return 0;
}
@ -933,7 +935,6 @@ void bigint_multiplication()
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 {
@ -1004,3 +1005,25 @@ void bigint_division()
}
}
}
void bigint_base10()
{
{
I_TEST((BigInteger | From String));
auto result = Crypto::UnsignedBigInteger::from_base10("57195071295721390579057195715793");
if (result.words() == Vector<u32> { 3806301393, 954919431, 3879607298, 721 }) {
PASS;
} else {
FAIL(Incorrect Result);
}
}
{
I_TEST((BigInteger | To String));
auto result = Crypto::UnsignedBigInteger { Vector<u32> { 3806301393, 954919431, 3879607298, 721 } }.to_base10();
if (result == "57195071295721390579057195715793") {
PASS;
} else {
FAIL(Incorrect Result);
}
}
}