summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-04-10 01:00:37 +0430
committerAndreas Kling <kling@serenityos.org>2020-05-02 12:24:10 +0200
commit6b742c69bd407cb2178b5915c2269f7ecc64b503 (patch)
tree09dbb0f329e4ccf72a38ae542c03baa336491cc5 /Userland
parentc52d3e65b90a166741ca5e1fb6c9cb36b5db305a (diff)
downloadserenity-6b742c69bd407cb2178b5915c2269f7ecc64b503.zip
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
Diffstat (limited to 'Userland')
-rw-r--r--Userland/test-crypto.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/Userland/test-crypto.cpp b/Userland/test-crypto.cpp
index 7496a3df07..19acf079c6 100644
--- a/Userland/test-crypto.cpp
+++ b/Userland/test-crypto.cpp
@@ -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;
+ }
+}