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
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
ColumnLimit: 160
CommentPragmas: '^ IWYU pragma:'
QualifierAlignment: Leave
CompactNamespaces: false
Expand Down
74 changes: 50 additions & 24 deletions .github/workflows/test_ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Test Ascon Cipher Suite on CI
# Taken from https://github.com/itzmeanjan/ml-kem/blob/61cf680b1c0e2590bd7b650c07cd477e90cab46d/.github/workflows/test_ci.yml
name: Test Ascon LwC Cipher Suite i.e. NIST SP 800-232

on:
push:
Expand All @@ -11,28 +12,53 @@ jobs:
runs-on: ${{matrix.os}}
strategy:
matrix:
os: [ubuntu-latest, # x86_64
macos-14 # Apple Silicon
]
os: [ubuntu-latest, macos-latest]
compiler: [g++, clang++]
build_type: [debug, release]
test_type: [standard, asan, ubsan]
max-parallel: 4

steps:
- uses: actions/checkout@v4
- name: Setup Google-Test
run: |
pushd ~
git clone https://github.com/google/googletest.git -b v1.14.0
pushd googletest
mkdir build
pushd build
cmake .. -DBUILD_GMOCK=OFF
make
sudo make install
popd
popd
popd
- name: Execute Tests on ${{matrix.os}}
run: make -j
- name: Execute Tests with AddressSanitizer on ${{matrix.os}}
run: make asan_test -j
- name: Execute Tests with UndefinedBehaviourSanitizer on ${{matrix.os}}
run: make ubsan_test -j
- uses: actions/checkout@v4

- name: Setup Google Test
uses: Bacondish2023/setup-googletest@v1
with:
tag: v1.15.2


- name: Build and Test (${{ matrix.compiler }}, ${{ matrix.build_type }}, ${{ matrix.test_type }})
run: |
CXX=${{ matrix.compiler }}
if [[ ${{ matrix.test_type }} == "standard" ]]; then
make test -j 2>&1 | tee build.log
else
make ${{ matrix.build_type }}_${{ matrix.test_type }}_test -j 2>&1 | tee build.log
fi
if [ $? -ne 0 ]; then
echo "Build or Test Failed! See build.log for details."
exit 1
fi

- name: Upload Build Log
uses: actions/upload-artifact@v3
with:
name: build-log-${{ matrix.compiler }}-${{ matrix.build_type }}-${{ matrix.test_type }}
path: build.log


- name: Run Examples
if: ${{ matrix.test_type == 'standard' && matrix.build_type == 'release' }}
run: |
CXX=${{ matrix.compiler }} make example -j 2>&1 | tee example.log
if [ $? -ne 0 ]; then
echo "Example execution Failed! See example.log for details."
exit 1
fi

- name: Upload Example Log (if failed)
if: ${{ steps.Run_Examples.outcome != 'success' && matrix.test_type == 'standard' && matrix.build_type == 'release' }}
uses: actions/upload-artifact@v3
with:
name: example-log-${{ matrix.compiler }}
path: example.log
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
[submodule "gtest-parallel"]
path = gtest-parallel
url = https://github.com/google/gtest-parallel.git
[submodule "dudect"]
path = dudect
url = https://github.com/oreparaz/dudect.git
155 changes: 30 additions & 125 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,140 +1,45 @@
CXX ?= clang++
CXX_FLAGS = -std=c++20
WARN_FLAGS = -Wall -Wextra -pedantic
OPT_FLAGS = -O3 -march=native
LINK_FLAGS = -flto
PERF_DEFS = -DCYCLES_PER_BYTE
ASAN_FLAGS = -g -O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize=address # From https://clang.llvm.org/docs/AddressSanitizer.html
UBSAN_FLAGS = -g -O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize=undefined # From https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html

SRC_DIR = include
SUBTLE_INC_DIR = ./subtle/include
DUDECT_INC_DIR = ./dudect/src
I_FLAGS = -I $(SRC_DIR)
DEP_IFLAGS = -I $(SUBTLE_INC_DIR)
DUDECT_DEP_IFLAGS = $(DEP_IFLAGS) -I $(DUDECT_INC_DIR)
ASCON_SOURCES := $(wildcard $(SRC_DIR)/*.hpp)
BUILD_DIR = build

TEST_DIR = tests
DUDECT_TEST_DIR = $(TEST_DIR)/dudect
TEST_BUILD_DIR := $(BUILD_DIR)/$(TEST_DIR)
ASAN_BUILD_DIR = $(TEST_BUILD_DIR)/asan
UBSAN_BUILD_DIR = $(TEST_BUILD_DIR)/ubsan
DUDECT_BUILD_DIR = $(BUILD_DIR)/dudect
TEST_SOURCES := $(wildcard $(TEST_DIR)/*.cpp)
TEST_HEADERS := $(wildcard $(TEST_DIR)/*.hpp)
DUDECT_TEST_SOURCES := $(wildcard $(DUDECT_TEST_DIR)/*.cpp)
TEST_OBJECTS := $(addprefix $(TEST_BUILD_DIR)/, $(notdir $(patsubst %.cpp,%.o,$(TEST_SOURCES))))
ASAN_TEST_OBJECTS := $(addprefix $(ASAN_BUILD_DIR)/, $(notdir $(patsubst %.cpp,%.o,$(TEST_SOURCES))))
UBSAN_TEST_OBJECTS := $(addprefix $(UBSAN_BUILD_DIR)/, $(notdir $(patsubst %.cpp,%.o,$(TEST_SOURCES))))
TEST_LINK_FLAGS = -lgtest -lgtest_main
TEST_BINARY = $(TEST_BUILD_DIR)/test.out
ASAN_TEST_BINARY = $(ASAN_BUILD_DIR)/test.out
UBSAN_TEST_BINARY = $(UBSAN_BUILD_DIR)/test.out
DUDECT_TEST_BINARIES := $(addprefix $(DUDECT_BUILD_DIR)/, $(notdir $(patsubst %.cpp,%.out,$(DUDECT_TEST_SOURCES))))
GTEST_PARALLEL = ./gtest-parallel/gtest-parallel

BENCHMARK_DIR = benchmarks
BENCHMARK_SOURCES := $(wildcard $(BENCHMARK_DIR)/*.cpp)
BENCHMARK_HEADERS := $(wildcard $(BENCHMARK_DIR)/*.hpp)
BENCHMARK_BUILD_DIR := $(BUILD_DIR)/$(BENCHMARK_DIR)
PERF_BUILD_DIR := $(BUILD_DIR)/perfs
BENCHMARK_OBJECTS := $(addprefix $(BENCHMARK_BUILD_DIR)/, $(notdir $(patsubst %.cpp,%.o,$(BENCHMARK_SOURCES))))
PERF_OBJECTS := $(addprefix $(PERF_BUILD_DIR)/, $(notdir $(patsubst %.cpp,%.o,$(BENCHMARK_SOURCES))))
BENCHMARK_LINK_FLAGS = -lbenchmark -lbenchmark_main
BENCHMARK_BINARY = $(BENCHMARK_BUILD_DIR)/bench.out
PERF_LINK_FLAGS = -lbenchmark -lbenchmark_main -lpthread -lpfm
PERF_BINARY = $(PERF_BUILD_DIR)/perf.out

all: test

$(BUILD_DIR):
mkdir -p $@
.DEFAULT_GOAL := help

$(TEST_BUILD_DIR): $(BUILD_DIR)
mkdir -p $@
# Collects inspiration from https://github.com/0xPolygonMiden/crypto/blob/3909b0199368b13fdfa934a324f984572d521e39/Makefile#L1-L5
# and https://github.com/gtramontina/sourcing/blob/853252ee184c16bc69dd53e8457107d718aca04f/Makefile#L68-L72
.PHONY: help
help:
@for file in $(MAKEFILE_LIST); do \
grep -E '^[a-zA-Z_-]+:.*?## .*$$' $${file} | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}';\
done

$(ASAN_BUILD_DIR): $(TEST_BUILD_DIR)
mkdir -p $@

$(UBSAN_BUILD_DIR): $(TEST_BUILD_DIR)
mkdir -p $@

$(DUDECT_BUILD_DIR): $(TEST_BUILD_DIR)
mkdir -p $@
CXX ?= clang++
CXX_DEFS +=
CXX_FLAGS := -std=c++20
WARN_FLAGS := -Wall -Wextra -Wpedantic
DEBUG_FLAGS := -O1 -g
RELEASE_FLAGS := -O3 -march=native
LINK_OPT_FLAGS := -flto

I_FLAGS := -I ./include
SUBTLE_INC_DIR = ./subtle/include
DEP_IFLAGS := -I $(SUBTLE_INC_DIR)
PERF_DEFS = -DCYCLES_PER_BYTE

$(BENCHMARK_BUILD_DIR): $(BUILD_DIR)
mkdir -p $@
SRC_DIR := include
ASCON_SOURCES := $(shell find $(SRC_DIR) -name '*.hpp')
BUILD_DIR := build

$(PERF_BUILD_DIR): $(BUILD_DIR)
mkdir -p $@
include tests/test.mk
include benches/bench.mk
include examples/example.mk

$(SUBTLE_INC_DIR):
git submodule update --init subtle

$(GTEST_PARALLEL): $(SUBTLE_INC_DIR)
git submodule update --init gtest-parallel

$(DUDECT_INC_DIR): $(GTEST_PARALLEL)
git submodule update --init dudect

$(TEST_BUILD_DIR)/%.o: $(TEST_DIR)/%.cpp $(TEST_BUILD_DIR) $(SUBTLE_INC_DIR)
$(CXX) $(CXX_FLAGS) $(WARN_FLAGS) $(OPT_FLAGS) $(I_FLAGS) $(DEP_IFLAGS) -c $< -o $@

$(ASAN_BUILD_DIR)/%.o: $(TEST_DIR)/%.cpp $(ASAN_BUILD_DIR) $(SUBTLE_INC_DIR)
$(CXX) $(CXX_FLAGS) $(WARN_FLAGS) $(ASAN_FLAGS) $(I_FLAGS) $(DEP_IFLAGS) -c $< -o $@

$(UBSAN_BUILD_DIR)/%.o: $(TEST_DIR)/%.cpp $(UBSAN_BUILD_DIR) $(SUBTLE_INC_DIR)
$(CXX) $(CXX_FLAGS) $(WARN_FLAGS) $(UBSAN_FLAGS) $(I_FLAGS) $(DEP_IFLAGS) -c $< -o $@

$(TEST_BINARY): $(TEST_OBJECTS)
$(CXX) $(OPT_FLAGS) $(LINK_FLAGS) $^ $(TEST_LINK_FLAGS) -o $@

$(ASAN_TEST_BINARY): $(ASAN_TEST_OBJECTS)
$(CXX) $(ASAN_FLAGS) $^ $(TEST_LINK_FLAGS) -o $@

$(UBSAN_TEST_BINARY): $(UBSAN_TEST_OBJECTS)
$(CXX) $(UBSAN_FLAGS) $^ $(TEST_LINK_FLAGS) -o $@

$(DUDECT_BUILD_DIR)/%.out: $(DUDECT_TEST_DIR)/%.cpp $(DUDECT_BUILD_DIR) $(SUBTLE_INC_DIR) $(DUDECT_INC_DIR)
$(CXX) $(CXX_FLAGS) $(WARN_FLAGS) $(OPT_FLAGS) $(I_FLAGS) $(DUDECT_DEP_IFLAGS) -lm $(LINK_FLAGS) $< -o $@

test: $(TEST_BINARY) $(GTEST_PARALLEL)
$(GTEST_PARALLEL) $< --print_test_times

asan_test: $(ASAN_TEST_BINARY) $(GTEST_PARALLEL)
$(GTEST_PARALLEL) $< --print_test_times

ubsan_test: $(UBSAN_TEST_BINARY) $(GTEST_PARALLEL)
$(GTEST_PARALLEL) $< --print_test_times

dudect_test_build: $(DUDECT_TEST_BINARIES)

$(BENCHMARK_BUILD_DIR)/%.o: $(BENCHMARK_DIR)/%.cpp $(BENCHMARK_BUILD_DIR)
$(CXX) $(CXX_FLAGS) $(WARN_FLAGS) $(OPT_FLAGS) $(I_FLAGS) $(DEP_IFLAGS) -c $< -o $@

$(PERF_BUILD_DIR)/%.o: $(BENCHMARK_DIR)/%.cpp $(PERF_BUILD_DIR)
$(CXX) $(CXX_FLAGS) $(WARN_FLAGS) $(OPT_FLAGS) $(PERF_DEFS) $(I_FLAGS) $(DEP_IFLAGS) -c $< -o $@

$(BENCHMARK_BINARY): $(BENCHMARK_OBJECTS)
$(CXX) $(OPT_FLAGS) $(LINK_FLAGS) $^ $(BENCHMARK_LINK_FLAGS) -o $@

benchmark: $(BENCHMARK_BINARY)
# Must *not* build google-benchmark with libPFM
./$< --benchmark_min_warmup_time=.1 --benchmark_enable_random_interleaving=true --benchmark_repetitions=10 --benchmark_min_time=0.1s --benchmark_counters_tabular=true --benchmark_display_aggregates_only=true

$(PERF_BINARY): $(PERF_OBJECTS)
$(CXX) $(OPT_FLAGS) $(LINK_FLAGS) $^ $(PERF_LINK_FLAGS) -o $@

perf: $(PERF_BINARY)
# Must build google-benchmark with libPFM, follow https://gist.github.com/itzmeanjan/05dc3e946f635d00c5e0b21aae6203a7
./$< --benchmark_min_warmup_time=.1 --benchmark_enable_random_interleaving=true --benchmark_repetitions=10 --benchmark_min_time=0.1s --benchmark_counters_tabular=true --benchmark_display_aggregates_only=true --benchmark_perf_counters=CYCLES

.PHONY: format clean

clean:
.PHONY: clean
clean: ## Remove build directory
rm -rf $(BUILD_DIR)

format: $(ASCON_SOURCES) $(TEST_SOURCES) $(TEST_HEADERS) $(DUDECT_TEST_SOURCES) $(BENCHMARK_SOURCES) $(BENCHMARK_HEADERS)
.PHONY: format
format: $(ASCON_SOURCES) $(TEST_SOURCES) $(TEST_HEADERS) $(BENCHMARK_SOURCES) $(BENCHMARK_HEADERS) $(EXAMPLE_SOURCES) $(EXAMPLE_HEADERS) ## Format source code
clang-format -i $^
Loading
Loading