diff options
author | Guillaume Endignoux <guillaumee@google.com> | 2024-06-26 09:29:27 +0000 |
---|---|---|
committer | Boringssl LUCI CQ <boringssl-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-07-03 13:34:58 +0000 |
commit | 7c2b62e93487b772990fddc1905f22d4cfaee4a4 (patch) | |
tree | 90629338991e81240718c1a69db4814cd4eef239 /crypto/dilithium/dilithium_test.cc | |
parent | 12f0f4bec2a6db53a53748dd6001d1aacaae26ba (diff) | |
download | boringssl-7c2b62e93487b772990fddc1905f22d4cfaee4a4.zip boringssl-7c2b62e93487b772990fddc1905f22d4cfaee4a4.tar.gz boringssl-7c2b62e93487b772990fddc1905f22d4cfaee4a4.tar.bz2 |
Add DILITHIUM_public_from_private function.
Change-Id: I9b9c53d4f994bd0fc731c9fff3119f0d388900e9
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/69667
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/dilithium/dilithium_test.cc')
-rw-r--r-- | crypto/dilithium/dilithium_test.cc | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/crypto/dilithium/dilithium_test.cc b/crypto/dilithium/dilithium_test.cc index dcd2e8b..51cb295 100644 --- a/crypto/dilithium/dilithium_test.cc +++ b/crypto/dilithium/dilithium_test.cc @@ -92,6 +92,23 @@ TEST(DilithiumTest, SignatureIsRandomized) { 1); } +TEST(DilithiumTest, PublicFromPrivateIsConsistent) { + std::vector<uint8_t> encoded_public_key(DILITHIUM_PUBLIC_KEY_BYTES); + auto priv = std::make_unique<DILITHIUM_private_key>(); + EXPECT_TRUE(DILITHIUM_generate_key(encoded_public_key.data(), priv.get())); + + auto pub = std::make_unique<DILITHIUM_public_key>(); + EXPECT_TRUE(DILITHIUM_public_from_private(pub.get(), priv.get())); + + std::vector<uint8_t> encoded_public_key2(DILITHIUM_PUBLIC_KEY_BYTES); + + CBB cbb; + CBB_init_fixed(&cbb, encoded_public_key2.data(), encoded_public_key2.size()); + ASSERT_TRUE(DILITHIUM_marshal_public_key(&cbb, pub.get())); + + EXPECT_EQ(Bytes(encoded_public_key2), Bytes(encoded_public_key)); +} + TEST(DilithiumTest, InvalidPublicKeyEncodingLength) { // Encode a public key with a trailing 0 at the end. std::vector<uint8_t> encoded_public_key(DILITHIUM_PUBLIC_KEY_BYTES + 1); @@ -100,13 +117,13 @@ TEST(DilithiumTest, InvalidPublicKeyEncodingLength) { // Public key is 1 byte too short. CBS cbs = bssl::MakeConstSpan(encoded_public_key) - .first(DILITHIUM_PUBLIC_KEY_BYTES - 1); + .first(DILITHIUM_PUBLIC_KEY_BYTES - 1); auto parsed_pub = std::make_unique<DILITHIUM_public_key>(); EXPECT_FALSE(DILITHIUM_parse_public_key(parsed_pub.get(), &cbs)); // Public key has the correct length. - cbs = bssl::MakeConstSpan(encoded_public_key) - .first(DILITHIUM_PUBLIC_KEY_BYTES); + cbs = + bssl::MakeConstSpan(encoded_public_key).first(DILITHIUM_PUBLIC_KEY_BYTES); EXPECT_TRUE(DILITHIUM_parse_public_key(parsed_pub.get(), &cbs)); // Public key is 1 byte too long. @@ -142,10 +159,6 @@ TEST(DilithiumTest, InvalidPrivateKeyEncodingLength) { EXPECT_FALSE(DILITHIUM_parse_private_key(parsed_priv.get(), &cbs)); } -// TODO: Add more parsing tests: -// - signed values out of range (private key's s1/s2 beyond ETA) -// - signature hints not in the canonical order (signature malleability) - static void DilithiumFileTest(FileTest *t) { std::vector<uint8_t> seed, message, public_key_expected, private_key_expected, signed_message_expected; |