diff --git a/tests/prop_test_ascon_aead128.cpp b/tests/prop_test_ascon_aead128.cpp index a49823a..258977d 100644 --- a/tests/prop_test_ascon_aead128.cpp +++ b/tests/prop_test_ascon_aead128.cpp @@ -1,7 +1,39 @@ #include "ascon/aead/ascon_aead128.hpp" #include "test_helper.hpp" +#include #include +constexpr bool +eval_encrypt_decrypt() +{ + constexpr size_t ASSOCIATED_DATA_BYTE_LEN = 32; + constexpr size_t PLAIN_TEXT_BYTE_LEN = 32; + + std::array key; + std::array nonce; + std::array associated_data; + std::array plain_text; + + std::iota(key.begin(), key.end(), 0); + std::iota(nonce.begin(), nonce.end(), 0); + std::iota(associated_data.begin(), associated_data.end(), 0); + std::iota(plain_text.begin(), plain_text.end(), 0); + + std::array cipher_text; + std::array deciphered_text; + std::array tag; + + ascon_aead128::encrypt(key, nonce, associated_data, plain_text, cipher_text, tag); + const bool is_decrypted = ascon_aead128::decrypt(key, nonce, associated_data, cipher_text, deciphered_text, tag); + + return is_decrypted; +} + +TEST(AsconAEAD128, CompileTimeEncryptAndThenDecrypt) +{ + static_assert(eval_encrypt_decrypt(), "Must be able to encrypt and then decrypt using Ascon-AEAD128 during program compilation time itself !"); +} + TEST(AsconAEAD128, EncryptThenDecrypt) { for (size_t associated_data_len = MIN_AD_LEN; associated_data_len <= MAX_AD_LEN; associated_data_len++) { diff --git a/tests/prop_test_ascon_hash256.cpp b/tests/prop_test_ascon_hash256.cpp index 014b37e..c2d0df1 100644 --- a/tests/prop_test_ascon_hash256.cpp +++ b/tests/prop_test_ascon_hash256.cpp @@ -9,7 +9,7 @@ constexpr std::array eval_ascon_hash256() { // Statically defined input. - // Message = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f + // Message = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F std::array data{}; std::iota(data.begin(), data.end(), 0); @@ -27,17 +27,18 @@ eval_ascon_hash256() TEST(AsconHash256, CompileTimeComputeMessageDigest) { - // AsconHash256("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f") = - // "2a4f6f2b6b3ec2a6c47ba08d18c8ea561b493c13ccb35803fa8b9fb00a0f1f35" + constexpr auto expected_md = std::array{ + 'B', 'D', '9', 'D', '3', 'D', '6', '0', 'A', '6', '6', 'B', '5', '3', '8', '6', '8', 'E', 'A', 'B', '2', 'A', + '5', 'C', '7', '4', '5', '3', '9', 'A', '5', '1', '8', 'A', '1', 'F', '6', '0', 'F', '0', '1', 'E', 'B', '1', + '7', '6', 'C', '6', '0', 'E', '4', '3', 'D', 'E', 'E', '8', '1', '6', '8', '0', 'B', '3', '3', 'E', + }; + + // AsconHash256("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F") = "BD9D3D60A66B53868EAB2A5C74539A518A1F60F01EB176C60E43DEE81680B33E" constexpr auto md = eval_ascon_hash256(); - constexpr auto is_match = - md == std::array{ '2', 'a', '4', 'f', '6', 'f', '2', 'b', '6', 'b', '3', 'e', 'c', '2', 'a', '6', - 'c', '4', '7', 'b', 'a', '0', '8', 'd', '1', '8', 'c', '8', 'e', 'a', '5', '6', - '1', 'b', '4', '9', '3', 'c', '1', '3', 'c', 'c', 'b', '3', '5', '8', '0', '3', - 'f', 'a', '8', 'b', '9', 'f', 'b', '0', '0', 'a', '0', 'f', '1', 'f', '3', '5' }; - - static_assert(!is_match, "Must not be able to evaluate Ascon-Hash256 correctly, as expected output is wrong. I'll update it !"); - EXPECT_FALSE(is_match); + constexpr auto is_matching = md == expected_md; + + static_assert(is_matching, "Must be able to evaluate Ascon-Hash256 during program compilation time itself !"); + EXPECT_TRUE(is_matching); } TEST(AsconHash256, ForSameMessageOneshotHashingAndIncrementalHashingProducesSameDigest) diff --git a/tests/prop_test_ascon_xof128.cpp b/tests/prop_test_ascon_xof128.cpp index 31b4e6e..598766e 100644 --- a/tests/prop_test_ascon_xof128.cpp +++ b/tests/prop_test_ascon_xof128.cpp @@ -10,7 +10,7 @@ constexpr std::array eval_ascon_xof128() { // Statically defined input. - // Message = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f + // Message = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F std::array data{}; std::iota(data.begin(), data.end(), 0); @@ -28,15 +28,18 @@ eval_ascon_xof128() TEST(AsconXof128, CompileTimeComputeXofOutput) { - // AsconXof128("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f") = - // "0b8e325b9bbf1bb43e77aa1eed93bee62b4ea1e4b0c5a696b2f5c5b09c968918" - constexpr auto md = eval_ascon_xof128(); - constexpr auto flg = md == std::array{ '0', 'b', '8', 'e', '3', '2', '5', 'b', '9', 'b', 'b', 'f', '1', 'b', 'b', '4', '3', 'e', '7', '7', 'a', 'a', - '1', 'e', 'e', 'd', '9', '3', 'b', 'e', 'e', '6', '2', 'b', '4', 'e', 'a', '1', 'e', '4', 'b', '0', 'c', '5', - 'a', '6', '9', '6', 'b', '2', 'f', '5', 'c', '5', 'b', '0', '9', 'c', '9', '6', '8', '9', '1', '8' }; - - static_assert(!flg, "Must not be able to evaluate Ascon-Xof128 correctly, as expected output is wrong. I'll update it !"); - EXPECT_FALSE(flg); + constexpr auto expected_output = std::array{ + '2', 'E', '5', 'F', '3', '4', '0', '3', 'F', '4', '1', '7', '1', '4', '7', '1', 'C', 'C', '7', '9', '3', '4', + 'B', '5', '1', '9', '8', '2', 'C', 'E', 'C', 'E', '8', 'D', '6', '6', '2', '8', '4', '3', '5', 'D', 'B', '7', + '0', 'E', '8', '9', '8', '8', '0', 'F', '3', 'B', 'E', '4', 'E', '0', 'B', '7', 'B', '0', '5', '2', + }; + + // AsconXof128("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F") = "2E5F3403F4171471CC7934B51982CECE8D6628435DB70E89880F3BE4E0B7B052" + constexpr auto output = eval_ascon_xof128(); + constexpr auto is_matching = output == expected_output; + + static_assert(is_matching, "Must be able to evaluate Ascon-Xof128 during program compilation time itself !"); + EXPECT_TRUE(is_matching); } TEST(AsconXof128, ForSameMessageOneshotHashingAndIncrementalHashingProducesSameOutput) diff --git a/tests/test_helper.hpp b/tests/test_helper.hpp index 78209dc..55317bb 100644 --- a/tests/test_helper.hpp +++ b/tests/test_helper.hpp @@ -69,7 +69,7 @@ template constexpr std::array bytes_to_hex(std::array bytes) { - constexpr std::array table{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; + constexpr std::array table{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; std::array hex{};