Skip to content

Commit 8f92606

Browse files
mdcornutkanteckerdincoz
authored
Add AVX512VL-Optimized SHA3/SHAKE Implementations (#2167)
* Add SHA3-256/384/512 and SHAKE128/256 AVX512VL implementations Co-authored-by: Tomasz Kantecki <[email protected]> Co-authored-by: Erdinc Ozturk <[email protected]> Signed-off-by: Marcel Cornu <[email protected]> Signed-off-by: Tomasz Kantecki <[email protected]> * AVX512VL SHA3 is added as an extension of XKCP implementation Co-authored-by: Marcel Cornu <[email protected]> Signed-off-by: Tomasz Kantecki <[email protected]> Signed-off-by: Marcel Cornu <[email protected]> * Add SHA3-384 tests Signed-off-by: Marcel Cornu <[email protected]> * Update namespace test to include SHA3 Signed-off-by: Marcel Cornu <[email protected]> * Release SHA3 context after triggering dispatcher Signed-off-by: Marcel Cornu <[email protected]> * Add linux CI for OQS_USE_SHA3_AVX512VL=OFF config Signed-off-by: Marcel Cornu <[email protected]> * Add AVX512 emulation to linux CI Signed-off-by: Marcel Cornu <[email protected]> --------- Signed-off-by: Marcel Cornu <[email protected]> Signed-off-by: Tomasz Kantecki <[email protected]> Co-authored-by: Tomasz Kantecki <[email protected]> Co-authored-by: Erdinc Ozturk <[email protected]>
1 parent 47b8fdd commit 8f92606

16 files changed

+3989
-8
lines changed

.CMake/alg_support.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ if(OQS_DIST_X86_64_BUILD OR OQS_USE_AVX2_INSTRUCTIONS)
7878
endif()
7979
endif()
8080

81+
# SHA3 AVX512VL only supported on Linux x86_64
82+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND (OQS_DIST_X86_64_BUILD OR OQS_USE_AVX512_INSTRUCTIONS))
83+
cmake_dependent_option(OQS_USE_SHA3_AVX512VL "Enable SHA3 AVX512VL usage" ON "NOT OQS_USE_SHA3_OPENSSL" OFF)
84+
else()
85+
option(OQS_USE_SHA3_AVX512VL "Enable SHA3 AVX512VL usage" OFF)
86+
endif()
87+
8188
# BIKE is not supported on Windows, 32-bit ARM, X86, S390X (big endian) and PPC64 (big endian)
8289
cmake_dependent_option(OQS_ENABLE_KEM_BIKE "Enable BIKE algorithm family" ON "NOT WIN32; NOT ARCH_ARM32v7; NOT ARCH_X86; NOT ARCH_S390X; NOT ARCH_PPC64" OFF)
8390
# BIKE doesn't work on any 32-bit platform

.github/workflows/linux.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ jobs:
112112
container: openquantumsafe/ci-ubuntu-latest:latest
113113
CMAKE_ARGS: -DCMAKE_C_COMPILER=clang -DCMAKE_BUILD_TYPE=Debug -DUSE_SANITIZER=Address -DOQS_LIBJADE_BUILD=ON -DOQS_MINIMAL_BUILD="${{ vars.LIBJADE_ALG_LIST }}"
114114
PYTEST_ARGS: --ignore=tests/test_distbuild.py --ignore=tests/test_leaks.py --ignore=tests/test_kat_all.py --maxprocesses=10
115+
- name: noble-no-sha3-avx512vl
116+
runner: ubuntu-latest
117+
container: openquantumsafe/ci-ubuntu-latest:latest
118+
CMAKE_ARGS: -DOQS_USE_SHA3_AVX512VL=OFF
119+
PYTEST_ARGS: --ignore=tests/test_leaks.py --ignore=tests/test_kat_all.py
115120
runs-on: ${{ matrix.runner }}
116121
container:
117122
image: ${{ matrix.container }}
@@ -271,3 +276,36 @@ jobs:
271276
- name: Build
272277
run: scan-build --status-bugs ninja
273278
working-directory: build
279+
280+
linux_x86_emulated:
281+
runs-on: ubuntu-latest
282+
container:
283+
image: openquantumsafe/ci-ubuntu-latest:latest
284+
strategy:
285+
fail-fast: false
286+
matrix:
287+
include:
288+
- name: avx512-ml-kem_ml-dsa
289+
SDE_ARCH: -skx
290+
CMAKE_ARGS: -DOQS_MINIMAL_BUILD="KEM_ml_kem_512;KEM_ml_kem_768;KEM_ml_kem_1024;SIG_ml_dsa_44;SIG_ml_dsa_65;SIG_ml_dsa_87"
291+
PYTEST_ARGS: tests/test_hash.py::test_sha3 tests/test_kat.py tests/test_acvp_vectors.py
292+
env:
293+
SDE_URL: https://downloadmirror.intel.com/850782/sde-external-9.53.0-2025-03-16-lin.tar.xz
294+
steps:
295+
- name: Checkout code
296+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v4
297+
- name: Setup Intel SDE
298+
run: |
299+
wget -O sde.tar.xz "$SDE_URL" && \
300+
mkdir sde && tar -xf sde.tar.xz -C sde --strip-components=1 && \
301+
echo "$(pwd)/sde" >> $GITHUB_PATH
302+
- name: Configure
303+
run: mkdir build && cd build && cmake -GNinja ${{ matrix.CMAKE_ARGS }} .. && cmake -LA -N ..
304+
- name: Build
305+
run: ninja
306+
working-directory: build
307+
- name: Run tests
308+
timeout-minutes: 60
309+
run: |
310+
mkdir -p tmp && sde64 ${{ matrix.SDE_ARCH }} -- \
311+
python3 -m pytest --verbose --numprocesses=auto ${{ matrix.PYTEST_ARGS }}

src/common/CMakeLists.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,19 @@ else()
6161
endif()
6262

6363
if(${OQS_USE_SHA3_OPENSSL})
64-
if (${OQS_ENABLE_SHA3_xkcp_low})
65-
add_subdirectory(sha3/xkcp_low)
66-
endif()
64+
if (${OQS_ENABLE_SHA3_xkcp_low})
65+
add_subdirectory(sha3/xkcp_low)
66+
endif()
6767
set(SHA3_IMPL sha3/ossl_sha3.c sha3/ossl_sha3x4.c)
6868
set(OSSL_HELPERS ossl_helpers.c)
6969
else() # using XKCP
7070
add_subdirectory(sha3/xkcp_low)
7171
set(SHA3_IMPL sha3/xkcp_sha3.c sha3/xkcp_sha3x4.c)
72+
if(OQS_USE_SHA3_AVX512VL)
73+
# also build avx512vl modules
74+
add_subdirectory(sha3/avx512vl_low)
75+
list(APPEND SHA3_IMPL sha3/avx512vl_sha3.c sha3/avx512vl_sha3x4.c)
76+
endif()
7277
endif()
7378

7479
if ((OQS_LIBJADE_BUILD STREQUAL "ON"))
@@ -157,6 +162,11 @@ if(${OQS_ENABLE_SHA3_xkcp_low}) # using XKCP
157162
set(_INTERNAL_OBJS ${_INTERNAL_OBJS} ${XKCP_LOW_OBJS})
158163
endif()
159164

165+
if(${OQS_USE_SHA3_AVX512VL})
166+
set(_COMMON_OBJS ${_COMMON_OBJS} ${SHA3_AVX512VL_LOW_OBJS})
167+
set(_INTERNAL_OBJS ${_INTERNAL_OBJS} ${SHA3_AVX512VL_LOW_OBJS})
168+
endif()
169+
160170
set(_COMMON_OBJS ${_COMMON_OBJS} $<TARGET_OBJECTS:common>)
161171
set(COMMON_OBJS ${_COMMON_OBJS} PARENT_SCOPE)
162172
set(_INTERNAL_OBJS ${_INTERNAL_OBJS} $<TARGET_OBJECTS:internal>)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2025 Intel Corporation
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
set(_SHA3_AVX512VL_LOW_OBJS "")
6+
7+
if(OQS_USE_SHA3_AVX512VL)
8+
add_library(sha3_avx512vl_low OBJECT
9+
KeccakP-1600-AVX512VL.S SHA3-AVX512VL.S KeccakP-1600-times4-AVX512VL.S SHA3-times4-AVX512VL.S)
10+
set(_SHA3_AVX512VL_LOW_OBJS ${_SHA3_AVX512VL_LOW_OBJS} $<TARGET_OBJECTS:sha3_avx512vl_low>)
11+
endif()
12+
13+
set(SHA3_AVX512VL_LOW_OBJS ${_SHA3_AVX512VL_LOW_OBJS} PARENT_SCOPE)
14+

0 commit comments

Comments
 (0)