Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conform to Ascon Draft Standard #26

Merged
merged 71 commits into from
Dec 6, 2024
Merged
Changes from 1 commit
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
7f8f98a
Increase column limit in clang-format style spec. file
itzmeanjan Nov 10, 2024
97c1cf6
Format source files with new style spec
itzmeanjan Nov 10, 2024
c7fab00
Define MACRO using compiler attributes for ease of force inlining fun…
itzmeanjan Nov 10, 2024
25e06f6
Extend Ascon permutation to support till 16 -rounds
itzmeanjan Nov 10, 2024
9b97d4f
Make necessary changes to ensure that existing tests keep running
itzmeanjan Nov 10, 2024
aff84b8
Remove dudect as git submodule based dependency
itzmeanjan Nov 10, 2024
56af54c
Move benchmark files to different directory
itzmeanjan Nov 10, 2024
a268170
Format headers in include directory
itzmeanjan Nov 10, 2024
39b9f6e
Remove dudect tests
itzmeanjan Nov 10, 2024
b30037e
Improve the organization of Makefile(s)
itzmeanjan Nov 10, 2024
053d3f7
Update Github Actions CI script to run all test targets
itzmeanjan Nov 10, 2024
e2f0a48
Register 10 -rounds Ascon permutation for benchmarking
itzmeanjan Nov 10, 2024
39f30e4
Add benchmark result (in JSON format) collected on Intel x86_64 machi…
itzmeanjan Nov 10, 2024
78f5c80
Subtle must be downloaded before we try to compile any translation units
itzmeanjan Nov 10, 2024
c818659
Make std::span extent statically defined
itzmeanjan Nov 27, 2024
e561b69
Make to/from bytes function little-endian
itzmeanjan Nov 27, 2024
6605dd5
Remove obsolete AEAD implementations
itzmeanjan Nov 27, 2024
4be239a
Reorganize ascon permutation and utility headers
itzmeanjan Nov 30, 2024
e836285
Compile-time evaluated function for computing IV for Ascon variants
itzmeanjan Nov 30, 2024
9fcbfb6
Implement Ascon AEAD mode of operation
itzmeanjan Nov 30, 2024
02e0c74
Implement Ascon-AEAD128
itzmeanjan Nov 30, 2024
83442e6
Remove Ascon permutation based authentication schemes
itzmeanjan Nov 30, 2024
f68c879
Implement sponge mode of operation for Ascon -based hashing
itzmeanjan Nov 30, 2024
1f20652
Add useful constants and compile-time evaluable constraints on Ascon …
itzmeanjan Nov 30, 2024
0008300
Remove unnecessary header include
itzmeanjan Nov 30, 2024
ea7a8cb
Implement Ascon-Hash256 hash function
itzmeanjan Nov 30, 2024
220d10b
Rename Ascon hash header file
itzmeanjan Nov 30, 2024
97fc615
Refactor how ascon-hash256 digest byte length is computed
itzmeanjan Nov 30, 2024
6319795
Implement Ascon-Xof128
itzmeanjan Nov 30, 2024
c32e913
Refactor common utility functions
itzmeanjan Nov 30, 2024
94777a5
Use correct namespace for utility functions
itzmeanjan Nov 30, 2024
86f6f96
Rename Ascon AEAD mode as Duplex mode of operation
itzmeanjan Nov 30, 2024
67e576c
Use Gemini to write better comments for Ascon-AEAD128 public API
itzmeanjan Nov 30, 2024
c2d346d
Add Ascon-cxof128
itzmeanjan Dec 1, 2024
6067539
Remove reset function from ascon-hash256 struct
itzmeanjan Dec 1, 2024
9772c2e
Remove reset function from ascon-xof128 struct
itzmeanjan Dec 1, 2024
21d2cda
Add common helper functions for Ascon tests
itzmeanjan Dec 1, 2024
b429700
Add property -based tests ensuring functional correctness of Ascon-AE…
itzmeanjan Dec 1, 2024
d6bd709
Split Ascon-AEAD128 decryption failure tests into mutiple test cases …
itzmeanjan Dec 1, 2024
d5f758b
Implement bit-flipping logic correctly
itzmeanjan Dec 1, 2024
7a774c6
Add missing `[[nodiscard]]` attribute to functions which return values
itzmeanjan Dec 2, 2024
1d7a563
Add property based tests ensuring functional correctness of Ascon-Has…
itzmeanjan Dec 2, 2024
b8c0c59
Make AEAD mode functions `constexpr` and explicitly ignore return val…
itzmeanjan Dec 2, 2024
c1abcef
Add property based tests ensuring functional correctness of Ascon-Xof…
itzmeanjan Dec 2, 2024
955d674
Remove tests for schemes which are not proposed in Ascon IPD
itzmeanjan Dec 2, 2024
53108af
Add function for ease of generating random data for bencmarking
itzmeanjan Dec 2, 2024
40b2965
Add benchmark function for Ascon-AEAD128 encrypt function
itzmeanjan Dec 2, 2024
3775ef8
Update benchmark function for Ascon permutation
itzmeanjan Dec 2, 2024
99242db
Add benchmark function for Ascon-Hash256
itzmeanjan Dec 2, 2024
844e6f5
Add benchmark function for Ascon-Xof128
itzmeanjan Dec 2, 2024
a3051c2
Remove benchmark functions for schemes which are not part of Ascon IPD
itzmeanjan Dec 2, 2024
3a95daf
Add property based tests for Ascon-CXOF128, ensuring functional corre…
itzmeanjan Dec 2, 2024
6317df4
Update Ascon-AEAD128 KAT file
itzmeanjan Dec 2, 2024
098bbc0
Update Ascon-Hash256 KAT file
itzmeanjan Dec 2, 2024
04a66bf
Update Ascon-Xof128 KAT file
itzmeanjan Dec 2, 2024
9df9a60
Fix padding to use little-endian convention
itzmeanjan Dec 3, 2024
597e267
Fix domain separation to use little-endian convention
itzmeanjan Dec 3, 2024
26ee0a2
Delete KATs for schemes which are not being standardized by NIST
itzmeanjan Dec 3, 2024
3fe3806
Add function for parsing hex-string in KAT files
itzmeanjan Dec 3, 2024
4bbc331
Add known answer tests (KATs) for Ascon-AEAD128
itzmeanjan Dec 3, 2024
becf099
Add Known Answer Tests for Ascon-Hash256
itzmeanjan Dec 3, 2024
01dcae1
Fix padding issue in Ascon sponge mode of operation
itzmeanjan Dec 3, 2024
3cbf186
Add Known Answer Tests for Ascon-Xof128
itzmeanjan Dec 3, 2024
70f4f41
Add examples demonstrating how to use Ascon AEAD, Hash and Xof API
itzmeanjan Dec 3, 2024
d03abe7
Manually unroll Ascon permutation loop
itzmeanjan Dec 3, 2024
a7381fe
Update Github Actions CI script to be more compact
itzmeanjan Dec 3, 2024
eed9683
Update benchmark results JSON file for x86_64 target running Linux ke…
itzmeanjan Dec 3, 2024
ea12463
Add benchmark results JSON file for aarch64 target running Linux kern…
itzmeanjan Dec 3, 2024
f154991
Add compile-time evaluated tests to ensure that the library is `const…
itzmeanjan Dec 4, 2024
2e994f9
Ensure that the tag matches in compile-time evaluable test for Ascon-…
itzmeanjan Dec 4, 2024
a568295
Update project documentation
itzmeanjan Dec 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add compile-time evaluated tests to ensure that the library is `const…
…expr`

Signed-off-by: Anjan Roy <[email protected]>
itzmeanjan committed Dec 4, 2024
commit f154991c01751ae5d495441a2456f9f2dd99d8b8
32 changes: 32 additions & 0 deletions tests/prop_test_ascon_aead128.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
#include "ascon/aead/ascon_aead128.hpp"
#include "test_helper.hpp"
#include <array>
#include <gtest/gtest.h>

constexpr bool
eval_encrypt_decrypt()
{
constexpr size_t ASSOCIATED_DATA_BYTE_LEN = 32;
constexpr size_t PLAIN_TEXT_BYTE_LEN = 32;

std::array<uint8_t, ascon_aead128::KEY_BYTE_LEN> key;
std::array<uint8_t, ascon_aead128::NONCE_BYTE_LEN> nonce;
std::array<uint8_t, ASSOCIATED_DATA_BYTE_LEN> associated_data;
std::array<uint8_t, PLAIN_TEXT_BYTE_LEN> 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<uint8_t, PLAIN_TEXT_BYTE_LEN> cipher_text;
std::array<uint8_t, PLAIN_TEXT_BYTE_LEN> deciphered_text;
std::array<uint8_t, ascon_aead128::TAG_BYTE_LEN> 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++) {
23 changes: 12 additions & 11 deletions tests/prop_test_ascon_hash256.cpp
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ constexpr std::array<char, 2 * ascon_hash256::DIGEST_BYTE_LEN>
eval_ascon_hash256()
{
// Statically defined input.
// Message = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
// Message = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F
std::array<uint8_t, 32> 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<char, ascon_hash256::DIGEST_BYTE_LEN * 2>{
'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<char, ascon_hash256::DIGEST_BYTE_LEN * 2>{ '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)
23 changes: 13 additions & 10 deletions tests/prop_test_ascon_xof128.cpp
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ constexpr std::array<char, 2 * olen>
eval_ascon_xof128()
{
// Statically defined input.
// Message = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
// Message = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F
std::array<uint8_t, 32> 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<char, 64>{ '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<char, 64>{
'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)
2 changes: 1 addition & 1 deletion tests/test_helper.hpp
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ template<size_t L>
constexpr std::array<char, L * 2>
bytes_to_hex(std::array<uint8_t, L> bytes)
{
constexpr std::array<char, 16> table{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
constexpr std::array<char, 16> table{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

std::array<char, bytes.size() * 2> hex{};