mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:47:35 +00:00
LibCrypto: Add ::import_data() and ::export_data() to UnsignedBigInteger
These functions allow conversion to-and-from big-endian buffers This commit also adds a ""_bigint operator for easy bigint use
This commit is contained in:
parent
c52d3e65b9
commit
6b742c69bd
3 changed files with 66 additions and 0 deletions
|
@ -183,6 +183,9 @@ auto main(int argc, char** argv) -> int
|
|||
puts("\tencrypt -- Access encryption functions");
|
||||
puts("\tdecrypt -- Access decryption functions");
|
||||
puts("\tlist -- List all known modes");
|
||||
puts("these modes only contain tests");
|
||||
puts("\tbigint -- Run big integer test suite");
|
||||
puts("\tpk -- Run Public-key system tests");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -308,6 +311,7 @@ void bigint_subtraction();
|
|||
void bigint_multiplication();
|
||||
void bigint_division();
|
||||
void bigint_base10();
|
||||
void bigint_import_export();
|
||||
|
||||
int aes_cbc_tests()
|
||||
{
|
||||
|
@ -805,6 +809,7 @@ int bigint_tests()
|
|||
bigint_multiplication();
|
||||
bigint_division();
|
||||
bigint_base10();
|
||||
bigint_import_export();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1027,3 +1032,19 @@ void bigint_base10()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void bigint_import_export()
|
||||
{
|
||||
{
|
||||
I_TEST((BigInteger | BigEndian Decode / Encode roundtrip));
|
||||
u8 random_bytes[128];
|
||||
u8 target_buffer[128];
|
||||
arc4random_buf(random_bytes, 128);
|
||||
auto encoded = Crypto::UnsignedBigInteger::import_data(random_bytes, 128);
|
||||
encoded.export_data(target_buffer, 128);
|
||||
if (memcmp(target_buffer, random_bytes, 128) != 0)
|
||||
FAIL(Could not roundtrip);
|
||||
else
|
||||
PASS;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue