diff options
author | Michiel Visser <opensource@webmichiel.nl> | 2022-03-05 18:13:39 +0100 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-03-20 00:51:50 +0330 |
commit | c1b041e761b99679a3998dbd81821febdecd2df9 (patch) | |
tree | cada4f602056e63597eb2ba12f76fb4723272d6c /Tests/LibCrypto | |
parent | 21bbff03498de4d7029ec3b37a7ae96dad063332 (diff) | |
download | serenity-c1b041e761b99679a3998dbd81821febdecd2df9.zip |
LibCrypto+LibTLS: Generalize the elliptic curve interface
These changes generalize the interface with an elliptic curve
implementation. This allows LibTLS to support elliptic curves generally
without needing the specifics of elliptic curve implementations.
This should allow for easier addition of other elliptic curves.
Diffstat (limited to 'Tests/LibCrypto')
-rw-r--r-- | Tests/LibCrypto/TestCurves.cpp | 39 |
1 files changed, 12 insertions, 27 deletions
diff --git a/Tests/LibCrypto/TestCurves.cpp b/Tests/LibCrypto/TestCurves.cpp index 91189803d0..c7a40c351c 100644 --- a/Tests/LibCrypto/TestCurves.cpp +++ b/Tests/LibCrypto/TestCurves.cpp @@ -48,30 +48,24 @@ TEST_CASE(test_x25519) 0x76, 0xf0, 0x9b, 0x3c, 0x1e, 0x16, 0x17, 0x42 }; - u8 coordinate_data[32] { - 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; - - ReadonlyBytes coordinate { coordinate_data, 32 }; ReadonlyBytes alice_public_key { alice_public_key_data, 32 }; ReadonlyBytes alice_private_key { alice_private_key_data, 32 }; ReadonlyBytes bob_public_key { bob_public_key_data, 32 }; ReadonlyBytes bob_private_key { bob_private_key_data, 32 }; ReadonlyBytes shared_secret { shared_secret_data, 32 }; - auto generated_alice_public = MUST(Crypto::Curves::X25519::compute_coordinate(alice_private_key, coordinate)); + Crypto::Curves::X25519 curve; + + auto generated_alice_public = MUST(curve.generate_public_key(alice_private_key)); EXPECT_EQ(alice_public_key, generated_alice_public); - auto generated_bob_public = MUST(Crypto::Curves::X25519::compute_coordinate(bob_private_key, coordinate)); + auto generated_bob_public = MUST(curve.generate_public_key(bob_private_key)); EXPECT_EQ(bob_public_key, generated_bob_public); - auto shared_alice = MUST(Crypto::Curves::X25519::compute_coordinate(alice_private_key, bob_public_key)); + auto shared_alice = MUST(curve.compute_coordinate(alice_private_key, bob_public_key)); EXPECT_EQ(shared_alice, shared_secret); - auto shared_bob = MUST(Crypto::Curves::X25519::compute_coordinate(bob_private_key, alice_public_key)); + auto shared_bob = MUST(curve.compute_coordinate(bob_private_key, alice_public_key)); EXPECT_EQ(shared_bob, shared_secret); EXPECT_EQ(shared_alice, shared_bob); @@ -130,33 +124,24 @@ TEST_CASE(test_x448) 0x44, 0x9a, 0x50, 0x37, 0x51, 0x4a, 0x87, 0x9d }; - u8 coordinate_data[56] { - 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; - - ReadonlyBytes coordinate { coordinate_data, 56 }; ReadonlyBytes alice_public_key { alice_public_key_data, 56 }; ReadonlyBytes alice_private_key { alice_private_key_data, 56 }; ReadonlyBytes bob_public_key { bob_public_key_data, 56 }; ReadonlyBytes bob_private_key { bob_private_key_data, 56 }; ReadonlyBytes shared_secret { shared_secret_data, 56 }; - auto generated_alice_public = MUST(Crypto::Curves::X448::compute_coordinate(alice_private_key, coordinate)); + Crypto::Curves::X448 curve; + + auto generated_alice_public = MUST(curve.generate_public_key(alice_private_key)); EXPECT_EQ(alice_public_key, generated_alice_public); - auto generated_bob_public = MUST(Crypto::Curves::X448::compute_coordinate(bob_private_key, coordinate)); + auto generated_bob_public = MUST(curve.generate_public_key(bob_private_key)); EXPECT_EQ(bob_public_key, generated_bob_public); - auto shared_alice = MUST(Crypto::Curves::X448::compute_coordinate(alice_private_key, bob_public_key)); + auto shared_alice = MUST(curve.compute_coordinate(alice_private_key, bob_public_key)); EXPECT_EQ(shared_alice, shared_secret); - auto shared_bob = MUST(Crypto::Curves::X448::compute_coordinate(bob_private_key, alice_public_key)); + auto shared_bob = MUST(curve.compute_coordinate(bob_private_key, alice_public_key)); EXPECT_EQ(shared_bob, shared_secret); EXPECT_EQ(shared_alice, shared_bob); |