Skip to content

Commit 11ff0f0

Browse files
bhessWardBeullenssopmacFmkannwischerilway25
authored
NIST Round 2 (#8)
NIST Round 2 --------- Co-authored-by: Basil Hess <[email protected]> Co-authored-by: Ward Beullens <[email protected]> Co-authored-by: Fabio Campos <[email protected]> Co-authored-by: Matthias J. Kannwischer <[email protected]> Co-authored-by: ilway25 <[email protected]> Co-authored-by: Sofía Celi <[email protected]>
1 parent 46887d7 commit 11ff0f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+6213
-5219
lines changed

.cmake/sanitizers.cmake

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,54 @@ set(CMAKE_C_FLAGS_COVERAGE
2828
"-fprofile-arcs -ftest-coverage"
2929
CACHE STRING "Flags used by the C compiler during Coverage builds."
3030
FORCE)
31+
32+
# CT-testing configs
33+
set(CMAKE_C_FLAGS_CTOS
34+
"-Os -gdwarf-4"
35+
CACHE STRING "Flags used by the C compiler during CT builds."
36+
FORCE)
37+
38+
set(CMAKE_C_FLAGS_CTO0
39+
"-O0 -gdwarf-4"
40+
CACHE STRING "Flags used by the C compiler during CT builds."
41+
FORCE)
42+
43+
set(CMAKE_C_FLAGS_CTO1
44+
"-O1 -gdwarf-4"
45+
CACHE STRING "Flags used by the C compiler during CT builds."
46+
FORCE)
47+
48+
set(CMAKE_C_FLAGS_CTO2
49+
"-O2 -gdwarf-4"
50+
CACHE STRING "Flags used by the C compiler during CT builds."
51+
FORCE)
52+
53+
set(CMAKE_C_FLAGS_CTO3
54+
"-O3 -gdwarf-4"
55+
CACHE STRING "Flags used by the C compiler during CT builds."
56+
FORCE)
57+
58+
set(CMAKE_C_FLAGS_CTOSNOVEC
59+
"-Os -fno-vectorize -gdwarf-4"
60+
CACHE STRING "Flags used by the C compiler during CT builds."
61+
FORCE)
62+
63+
set(CMAKE_C_FLAGS_CTO0NOVEC
64+
"-O0 -fno-vectorize -gdwarf-4"
65+
CACHE STRING "Flags used by the C compiler during CT builds."
66+
FORCE)
67+
68+
set(CMAKE_C_FLAGS_CTO1NOVEC
69+
"-O1 -fno-vectorize -gdwarf-4"
70+
CACHE STRING "Flags used by the C compiler during CT builds."
71+
FORCE)
72+
73+
set(CMAKE_C_FLAGS_CTO2NOVEC
74+
"-O2 -fno-vectorize -gdwarf-4"
75+
CACHE STRING "Flags used by the C compiler during CT builds."
76+
FORCE)
77+
78+
set(CMAKE_C_FLAGS_CTO3NOVEC
79+
"-O3 -fno-vectorize -gdwarf-4"
80+
CACHE STRING "Flags used by the C compiler during CT builds."
81+
FORCE)

.cmake/target.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
3+
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
44
add_definitions(-DTARGET_ARM64)
55
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
66
add_definitions(-DTARGET_ARM)
@@ -15,7 +15,9 @@ else()
1515
add_definitions(-DTARGET_OTHER)
1616
endif()
1717

18-
if (UNIX)
18+
if (APPLE)
19+
add_definitions(-DTARGET_OS_MAC)
20+
elseif (UNIX)
1921
add_definitions(-DTARGET_OS_UNIX)
2022
else()
2123
add_definitions(-DTARGET_OS_OTHER)
@@ -47,19 +49,23 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
4749
-mcpu=apple-m1)
4850
endif()
4951
option(ENABLE_AESNI "Use AESni" OFF)
52+
option(ENABLE_AESNEON "Use AES-NEON" ON)
5053
endif()
5154

5255

5356
if (${MAYO_BUILD_TYPE} MATCHES "ref")
5457
option(ENABLE_AESNI "Use AESni" OFF)
5558
option(ENABLE_PARAMS_DYNAMIC "Use dynamic parameters" ON)
5659
add_definitions(-DMAYO_BUILD_TYPE_REF)
57-
elseif(${MAYO_BUILD_TYPE} MATCHES "ref")
60+
elseif(${MAYO_BUILD_TYPE} MATCHES "opt")
5861
add_definitions(-DMAYO_BUILD_TYPE_OPT)
5962
option(ENABLE_PARAMS_DYNAMIC "Use dynamic parameters" OFF)
6063
elseif(${MAYO_BUILD_TYPE} MATCHES "avx2")
6164
add_definitions(-DMAYO_BUILD_TYPE_AVX2)
6265
option(ENABLE_PARAMS_DYNAMIC "Use dynamic parameters" OFF)
66+
elseif(${MAYO_BUILD_TYPE} MATCHES "neon")
67+
add_definitions(-DMAYO_BUILD_TYPE_NEON)
68+
option(ENABLE_PARAMS_DYNAMIC "Use dynamic parameters" OFF)
6369
endif()
6470

6571
separate_arguments(C_OPT_FLAGS UNIX_COMMAND "${G_C_OPT_FLAGS}")

.github/workflows/ci_clang.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: CT-tests (clang, clang-14 and clang-18)
4+
5+
# Controls when the workflow will run
6+
on:
7+
# Triggers the workflow on push or pull request events but only for the "github" branch
8+
push:
9+
branches: [ '*' ]
10+
pull_request:
11+
branches: [ "main" ]
12+
13+
# Allows you to run this workflow manually from the Actions tab
14+
workflow_dispatch:
15+
16+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
17+
jobs:
18+
# This workflow contains a single job called "build"
19+
ct:
20+
# The type of runner that the job will run on
21+
runs-on: ubuntu-latest
22+
strategy:
23+
matrix:
24+
clang_config: [CTOS, CTO0, CTO2, CTO3, CTOSNOVEC, CTO0NOVEC, CTO2NOVEC, CTO3NOVEC]
25+
# Note: valgrind seems buggy with CT01 and CT01NOVEC, we skip them
26+
clang_version: [clang, clang-15, clang-18]
27+
mayo_build_type: [ref, opt, avx2]
28+
29+
30+
# Steps represent a sequence of tasks that will be executed as part of the job
31+
steps:
32+
- uses: actions/checkout@v4
33+
- name: Set up Python 3.10
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: "3.10"
37+
38+
- name: Install dependencies
39+
run: wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - && wget https://apt.llvm.org/llvm.sh && sudo bash ./llvm.sh 18 && sudo apt update && sudo apt -y install build-essential valgrind cmake libboost-tools-dev libpthread-stubs0-dev libssl-dev clang-15 clang-18 clang gcc gcc-12
40+
41+
- name: CT-Test (clang)
42+
run: |
43+
ldd --version
44+
rm -rf build && mkdir build && cd build && cmake -DENABLE_CT_TESTING=ON -DMAYO_BUILD_TYPE=${{ matrix.mayo_build_type }} -DCMAKE_C_COMPILER=${{ matrix.clang_version }} -DCMAKE_BUILD_TYPE=${{ matrix.clang_config }} -DMAYO_MARCH="-march=haswell -maes" .. && make -j
45+
valgrind --max-stackframe=3190968 --tool=memcheck --error-exitcode=1 --track-origins=yes test/mayo_test_scheme_MAYO_1
46+
valgrind --max-stackframe=3190968 --tool=memcheck --error-exitcode=1 --track-origins=yes test/mayo_test_scheme_MAYO_2
47+
valgrind --max-stackframe=3190968 --tool=memcheck --error-exitcode=1 --track-origins=yes test/mayo_test_scheme_MAYO_3
48+
valgrind --max-stackframe=3190968 --tool=memcheck --error-exitcode=1 --track-origins=yes test/mayo_test_scheme_MAYO_5
49+
cd ..
50+
if: (matrix.mayo_build_type == 'opt' || matrix.mayo_build_type == 'avx2') && !(matrix.clang_config == 'CTO3' && matrix.mayo_build_type == 'opt')
51+
52+
- name: CT-Test (clang)
53+
run: |
54+
ldd --version
55+
rm -rf build && mkdir build && cd build && cmake -DENABLE_CT_TESTING=ON -DMAYO_BUILD_TYPE=${{ matrix.mayo_build_type }} -DCMAKE_C_COMPILER=${{ matrix.clang_version }} -DCMAKE_BUILD_TYPE=${{ matrix.clang_config }} -DMAYO_MARCH="-march=haswell -maes" .. && make -j
56+
valgrind --max-stackframe=3190968 --tool=memcheck --error-exitcode=1 --track-origins=yes test/mayo_test_scheme MAYO-1
57+
valgrind --max-stackframe=3190968 --tool=memcheck --error-exitcode=1 --track-origins=yes test/mayo_test_scheme MAYO-2
58+
valgrind --max-stackframe=3190968 --tool=memcheck --error-exitcode=1 --track-origins=yes test/mayo_test_scheme MAYO-3
59+
valgrind --max-stackframe=3190968 --tool=memcheck --error-exitcode=1 --track-origins=yes test/mayo_test_scheme MAYO-5
60+
cd ..
61+
if: matrix.mayo_build_type == 'ref'

.github/workflows/ci_gcc.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: CT-tests (gcc and gcc-12)
4+
5+
# Controls when the workflow will run
6+
on:
7+
# Triggers the workflow on push or pull request events but only for the "github" branch
8+
push:
9+
branches: [ '*' ]
10+
pull_request:
11+
branches: [ "main" ]
12+
13+
# Allows you to run this workflow manually from the Actions tab
14+
workflow_dispatch:
15+
16+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
17+
jobs:
18+
# This workflow contains a single job called "build"
19+
ct:
20+
# The type of runner that the job will run on
21+
runs-on: ubuntu-latest
22+
strategy:
23+
matrix:
24+
gcc_config: [CTOS, CTO0, CTO1, CTO2, CTO3]
25+
gcc_version: [gcc, gcc-12]
26+
mayo_build_type: [ref, opt, avx2]
27+
28+
29+
# Steps represent a sequence of tasks that will be executed as part of the job
30+
steps:
31+
- uses: actions/checkout@v4
32+
- name: Set up Python 3.10
33+
uses: actions/setup-python@v5
34+
with:
35+
python-version: "3.10"
36+
37+
- name: Install dependencies
38+
run: sudo apt update && sudo apt -y install build-essential valgrind cmake libboost-tools-dev libpthread-stubs0-dev libssl-dev clang-15 clang gcc gcc-12
39+
40+
- name: CT-Test (gcc)
41+
run: |
42+
ldd --version
43+
rm -rf build && mkdir build && cd build && cmake -DENABLE_CT_TESTING=ON -DMAYO_BUILD_TYPE=${{ matrix.mayo_build_type }} -DCMAKE_C_COMPILER=${{ matrix.gcc_version }} -DCMAKE_BUILD_TYPE=${{ matrix.gcc_config }} -DMAYO_MARCH="-march=haswell -maes" .. && make -j
44+
valgrind --tool=memcheck --error-exitcode=1 --track-origins=yes test/mayo_test_scheme_MAYO_1
45+
valgrind --tool=memcheck --error-exitcode=1 --track-origins=yes test/mayo_test_scheme_MAYO_2
46+
valgrind --tool=memcheck --error-exitcode=1 --track-origins=yes test/mayo_test_scheme_MAYO_3
47+
valgrind --tool=memcheck --error-exitcode=1 --track-origins=yes test/mayo_test_scheme_MAYO_5
48+
cd ..
49+
if: matrix.mayo_build_type == 'opt' || matrix.mayo_build_type == 'avx2'
50+
51+
- name: CT-Test (clang)
52+
run: |
53+
ldd --version
54+
rm -rf build && mkdir build && cd build && cmake -DENABLE_CT_TESTING=ON -DMAYO_BUILD_TYPE=${{ matrix.mayo_build_type }} -DCMAKE_C_COMPILER=${{ matrix.gcc_version }} -DCMAKE_BUILD_TYPE=${{ matrix.gcc_config }} -DMAYO_MARCH="-march=haswell -maes" .. && make -j
55+
valgrind --tool=memcheck --error-exitcode=1 --track-origins=yes test/mayo_test_scheme MAYO-1
56+
valgrind --tool=memcheck --error-exitcode=1 --track-origins=yes test/mayo_test_scheme MAYO-2
57+
valgrind --tool=memcheck --error-exitcode=1 --track-origins=yes test/mayo_test_scheme MAYO-3
58+
valgrind --tool=memcheck --error-exitcode=1 --track-origins=yes test/mayo_test_scheme MAYO-5
59+
cd ..
60+
if: matrix.mayo_build_type == 'ref'

.github/workflows/cmake.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ env:
1212

1313
jobs:
1414
build_test:
15-
runs-on: ubuntu-20.04
15+
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
1818
mayo_build_type: [ref, opt, avx2]
1919

2020
steps:
2121
- uses: actions/checkout@v3
2222
- name: Set up Python 3.10
23-
uses: actions/setup-python@v3
23+
uses: actions/setup-python@v5
2424
with:
2525
python-version: "3.10"
2626

@@ -29,7 +29,7 @@ jobs:
2929

3030
- name: Install Valgrind
3131
run: |
32-
sudo apt install valgrind
32+
sudo apt-get update && sudo apt install valgrind
3333
echo "Valgrind installed"
3434
3535
- name: Install Valgrind dependencies
@@ -103,21 +103,21 @@ jobs:
103103
rm -rf build
104104
cmake -Bbuild -DENABLE_CT_TESTING=ON -DCMAKE_BUILD_TYPE=Debug -DMAYO_BUILD_TYPE=${{ matrix.mayo_build_type }} -DMAYO_MARCH="-march=haswell -maes"
105105
cmake --build build
106-
valgrind --error-exitcode=1 --track-origins=yes build/test/mayo_test_scheme MAYO_1
107-
valgrind --error-exitcode=1 --track-origins=yes build/test/mayo_test_scheme MAYO_2
108-
valgrind --error-exitcode=1 --track-origins=yes build/test/mayo_test_scheme MAYO_3
109-
valgrind --error-exitcode=1 --track-origins=yes build/test/mayo_test_scheme MAYO_5
106+
valgrind --error-exitcode=1 --track-origins=yes build/test/mayo_test_scheme MAYO-1
107+
valgrind --error-exitcode=1 --track-origins=yes build/test/mayo_test_scheme MAYO-2
108+
valgrind --error-exitcode=1 --track-origins=yes build/test/mayo_test_scheme MAYO-3
109+
valgrind --error-exitcode=1 --track-origins=yes build/test/mayo_test_scheme MAYO-5
110110
if: matrix.mayo_build_type == 'ref'
111111

112112
- name: Memcheck
113113
run: |
114114
rm -rf build
115115
cmake -Bbuild -DCMAKE_BUILD_TYPE=Debug -DMAYO_BUILD_TYPE=${{ matrix.mayo_build_type }} -DMAYO_MARCH="-march=haswell -maes"
116116
cmake --build build
117-
valgrind --error-exitcode=1 --track-origins=yes build/test/mayo_test_scheme MAYO_1
118-
valgrind --error-exitcode=1 --track-origins=yes build/test/mayo_test_scheme MAYO_2
119-
valgrind --error-exitcode=1 --track-origins=yes build/test/mayo_test_scheme MAYO_3
120-
valgrind --error-exitcode=1 --track-origins=yes build/test/mayo_test_scheme MAYO_5
117+
valgrind --error-exitcode=1 --track-origins=yes build/test/mayo_test_scheme MAYO-1
118+
valgrind --error-exitcode=1 --track-origins=yes build/test/mayo_test_scheme MAYO-2
119+
valgrind --error-exitcode=1 --track-origins=yes build/test/mayo_test_scheme MAYO-3
120+
valgrind --error-exitcode=1 --track-origins=yes build/test/mayo_test_scheme MAYO-5
121121
if: matrix.mayo_build_type == 'ref'
122122

123123
- name: Memcheck
@@ -136,25 +136,25 @@ jobs:
136136
rm -rf build
137137
cmake -Bbuild -DCMAKE_BUILD_TYPE=ASAN -DMAYO_BUILD_TYPE=${{ matrix.mayo_build_type }} -DCMAKE_C_COMPILER=clang
138138
cmake --build build
139-
ctest -VV --test-dir build
139+
ctest -V --test-dir build
140140
141141
- name: Memory Sanitizer MSAN
142142
run: |
143143
rm -rf build
144144
cmake -Bbuild -DCMAKE_BUILD_TYPE=MSAN -DMAYO_BUILD_TYPE=${{ matrix.mayo_build_type }} -DCMAKE_C_COMPILER=clang
145145
cmake --build build
146-
ctest -VV --test-dir build
146+
ctest -V --test-dir build
147147
148148
- name: Leak Sanitizer LSAN
149149
run: |
150150
rm -rf build
151151
cmake -Bbuild -DCMAKE_BUILD_TYPE=LSAN -DMAYO_BUILD_TYPE=${{ matrix.mayo_build_type }} -DCMAKE_C_COMPILER=clang
152152
cmake --build build
153-
ctest -VV --test-dir build
153+
ctest -V --test-dir build
154154
155155
- name: Undefined Behavior Sanitizer UBSAN
156156
run: |
157157
rm -rf build
158158
cmake -Bbuild -DCMAKE_BUILD_TYPE=UBSAN -DMAYO_BUILD_TYPE=${{ matrix.mayo_build_type }} -DCMAKE_C_COMPILER=clang
159159
cmake --build build
160-
ctest -VV --test-dir build
160+
ctest -V --test-dir build

.github/workflows/macos_m1.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: CMake (macos-neon)
2+
3+
on:
4+
push:
5+
branches: [ '*' ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
11+
BUILD_TYPE: Debug
12+
13+
jobs:
14+
build_test:
15+
runs-on: macos-latest
16+
strategy:
17+
matrix:
18+
mayo_build_type: [neon]
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Set up Python 3.10
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.10"
26+
27+
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
28+
# You can convert this to a matrix build if you need cross-platform coverage.
29+
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
30+
31+
- name: Configure CMake
32+
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
33+
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
34+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DMAYO_BUILD_TYPE=${{ matrix.mayo_build_type }}
35+
36+
- name: Build
37+
# Build your program with the given configuration
38+
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
39+
40+
- name: Test
41+
working-directory: ${{github.workspace}}/build
42+
# Execute tests defined by the CMake configuration.
43+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
44+
run: ctest -C ${{env.BUILD_TYPE}}
45+
46+
- name: Examples (neon)
47+
working-directory: ${{github.workspace}}/build/apps
48+
run: |
49+
./PQCgenKAT_sign_mayo_1
50+
./PQCgenKAT_sign_mayo_2
51+
./PQCgenKAT_sign_mayo_3
52+
./PQCgenKAT_sign_mayo_5
53+
./example_mayo_1
54+
./example_mayo_2
55+
./example_mayo_3
56+
./example_mayo_5
57+
./example_nistapi_mayo_1
58+
./example_nistapi_mayo_2
59+
./example_nistapi_mayo_3
60+
./example_nistapi_mayo_5
61+
if: matrix.mayo_build_type == 'neon'
62+
63+
- name: Address Sanitizer ASAN
64+
run: |
65+
rm -rf build
66+
cmake -Bbuild -DCMAKE_BUILD_TYPE=ASAN -DMAYO_BUILD_TYPE=${{ matrix.mayo_build_type }} -DCMAKE_C_COMPILER=clang
67+
cmake --build build
68+
ctest -V --test-dir build

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
cmake_minimum_required(VERSION 3.5)
3+
cmake_minimum_required(VERSION 3.10)
44
project(MAYO VERSION 1.0 LANGUAGES C CXX ASM)
55

66
set(MAYO_SO_VERSION "0")
77
set(CMAKE_C_STANDARD 99)
88

9+
set(MEMORYCHECK_COMMAND_OPTIONS "--error-exitcode=1")
910
include(CTest)
1011

1112
option(ENABLE_STRICT "Build with strict compile options." ON)

0 commit comments

Comments
 (0)