-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #333 from cryspen/franziskus/mlkem-variants-features
Add features for ml-kem variants
- Loading branch information
Showing
28 changed files
with
18,716 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
files: | ||
# INTRINSICS | ||
|
||
- name: libcrux_intrinsics_avx2 | ||
library: true | ||
inline_static: true | ||
api: | ||
- [libcrux_intrinsics, avx2] | ||
|
||
# SHA3 (no mention of libcrux_mlkem in this section, please) | ||
|
||
- name: libcrux_sha3_avx2 | ||
inline_static: true | ||
# This is needed solely for the benchmarking test -- otherwise these would | ||
# all be private. Note that the order matters! So we put these first so that | ||
# they match immediately (and get promoted to internal), then the rest of | ||
# the behavior applies. | ||
api: | ||
patterns: | ||
- [libcrux_sha3, avx2, "*"] | ||
- [libcrux_sha3, simd, avx2, "*"] | ||
exact: | ||
- [libcrux_sha3, avx2, x4, incremental, KeccakState4] | ||
monomorphizations_exact: | ||
- [libcrux_sha3, avx2, x4, incremental, KeccakState4] | ||
- [libcrux_sha3, generic_keccak, absorb_final__core_core_arch_x86___m256i_4size_t_168size_t_31uint8_t ] | ||
- [libcrux_sha3, generic_keccak, squeeze_first_three_blocks__core_core_arch_x86___m256i_4size_t_168size_t ] | ||
- [libcrux_sha3, generic_keccak, "KeccakState__core_core_arch_x86___m256i_$4size_t"] | ||
monomorphizations_of: | ||
- [libcrux_sha3, avx2, "*"] | ||
- [libcrux_sha3, simd, avx2, "*"] | ||
monomorphizations_using: | ||
# Should this also include the monomorphizations using | ||
# core.arch.x86.__m256i? | ||
- [libcrux_sha3, avx2, "*"] | ||
- [libcrux_sha3, simd, avx2, "*"] | ||
include_in_h: | ||
- '"intrinsics/libcrux_intrinsics_avx2.h"' | ||
|
||
# Portable SHA3 | ||
- name: libcrux_sha3_portable | ||
inline_static: true | ||
api: | ||
patterns: | ||
- [libcrux_sha3, "*"] | ||
monomorphizations_of: | ||
- [libcrux_sha3, "*"] | ||
monomorphizations_using: | ||
- [libcrux_sha3, "*"] | ||
|
||
# Common parts of SHA3 (this catches stuff that hasn't matched above). Must | ||
# # come after the (more precise) patterns above concerning platform-specific hash_functions | ||
# - name: libcrux_sha3_internal | ||
# api: | ||
# patterns: | ||
# - [libcrux_sha3, "*"] | ||
# monomorphizations_of: | ||
# - [libcrux_sha3, "*"] | ||
# monomorphizations_using: | ||
# - [libcrux_sha3, "*"] | ||
# inline_static: true | ||
|
||
# MLKEM: HASH FUNCTIONS (as used by mlkem) | ||
|
||
# - name: libcrux_mlkem_avx2 | ||
# api: | ||
# - [libcrux_ml_kem, vector, avx2, "*"] | ||
# - [libcrux_ml_kem, hash_functions, avx2, "*"] | ||
# private: | ||
# monomorphizations_using: | ||
# - [libcrux_ml_kem, vector, avx2, "*"] | ||
# - [libcrux_ml_kem, hash_functions, avx2, "*"] | ||
# monomorphizations_of: | ||
# - [libcrux_ml_kem, vector, avx2, "*"] | ||
# - [libcrux_ml_kem, hash_functions, avx2, "*"] | ||
|
||
# # This covers slightly more than the two bundles above, but this greatly | ||
# # simplifies our lives. | ||
# - name: libcrux_mlkem_portable | ||
# inline_static: true | ||
# api: | ||
# patterns: | ||
# - [libcrux_ml_kem, vector, "*"] | ||
# - [libcrux_ml_kem, hash_functions, portable, "*"] | ||
# - [ libcrux_ml_kem, polynomial, "*" ] | ||
# monomorphizations_using: | ||
# - [ libcrux_ml_kem, polynomial, "*" ] | ||
# - [libcrux_ml_kem, vector, "*"] | ||
# - [libcrux_ml_kem, hash_functions, portable, "*"] | ||
# monomorphizations_of: | ||
# - [ libcrux_ml_kem, polynomial, "*" ] | ||
# - [libcrux_ml_kem, vector, "*"] | ||
# - [libcrux_ml_kem, hash_functions, portable, "*"] | ||
|
||
# MLKEM: MISC NON-ARCHITECTURE SPECIFIC HEADERS | ||
- name: libcrux_core | ||
inline_static: true | ||
private: | ||
monomorphizations_of: | ||
- [core, "*"] | ||
- [libcrux_ml_kem, types, "*"] | ||
- [libcrux_ml_kem, constant_time_ops, "*"] | ||
- [libcrux_ml_kem, utils, "*" ] | ||
monomorphizations_using: | ||
- [Eurydice, "*" ] | ||
- [libcrux_ml_kem, types, "*"] | ||
patterns: | ||
- [core, "*"] | ||
- [libcrux_ml_kem, types ] | ||
- [libcrux_ml_kem, constants ] | ||
- [libcrux_ml_kem, constant_time_ops, "*"] | ||
- [libcrux_ml_kem, utils, "*" ] | ||
api: | ||
- [Eurydice, "*"] | ||
|
||
# MLKEM-768 | ||
|
||
- name: libcrux_mlkem768_avx2 | ||
inline_static: true | ||
api: | ||
patterns: | ||
- [libcrux_ml_kem, vector, avx2, "*"] | ||
- [libcrux_ml_kem, hash_functions, avx2, "*"] | ||
- [libcrux_ml_kem, mlkem768, avx2] | ||
- [libcrux_ml_kem, ind_cca, instantiations, avx2] | ||
monomorphizations_of: | ||
- [libcrux_ml_kem, vector, avx2, "*"] | ||
- [libcrux_ml_kem, hash_functions, avx2, "*"] | ||
- [libcrux_ml_kem, mlkem768, avx2] | ||
- [libcrux_ml_kem, ind_cca, instantiations, avx2] | ||
monomorphizations_using: | ||
- [libcrux_ml_kem, vector, avx2, "*"] | ||
- [libcrux_ml_kem, hash_functions, avx2, "*"] | ||
|
||
- name: libcrux_mlkem768_portable | ||
inline_static: true | ||
api: | ||
patterns: | ||
- [libcrux_ml_kem, "*"] | ||
- [libcrux_ml_kem, vector, "*"] | ||
- [libcrux_ml_kem, hash_functions, portable, "*"] | ||
# - [libcrux_ml_kem, polynomial, "*" ] | ||
- [libcrux_ml_kem, mlkem768, portable, "*"] | ||
- [libcrux_ml_kem, ind_cca, instantiations, portable, "*"] | ||
monomorphizations_of: | ||
- [libcrux_ml_kem, polynomial, "*" ] | ||
- [libcrux_ml_kem, vector, "*"] | ||
- [libcrux_ml_kem, hash_functions, portable, "*"] | ||
- [libcrux_ml_kem, mlkem768, portable] | ||
- [libcrux_ml_kem, ind_cca, instantiations, portable, "*"] | ||
monomorphizations_using: | ||
- [libcrux_ml_kem, polynomial, "*" ] | ||
- [libcrux_ml_kem, vector, "*"] | ||
- [libcrux_ml_kem, hash_functions, portable, "*"] | ||
- [libcrux_ml_kem, ind_cca, instantiations, portable, "*"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# cmake -B build -G "Ninja Multi-Config" | ||
# cmake --build build | ||
# # For release (benchmarks) | ||
# cmake --build build --config Release | ||
|
||
cmake_minimum_required(VERSION 3.10) | ||
|
||
project(libcrux-ml-kem | ||
VERSION 0.1.0 | ||
LANGUAGES C CXX | ||
) | ||
|
||
set(CMAKE_C_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD 20) | ||
|
||
if(NOT MSVC) | ||
# TODO: Clean up | ||
add_compile_options( | ||
-Wall | ||
# -Wextra | ||
# -pedantic | ||
# -Wconversion | ||
# -Wsign-conversion | ||
$<$<CONFIG:DEBUG>:-g> | ||
$<$<CONFIG:DEBUG>:-Og> | ||
$<$<CONFIG:RELEASE>:-g> | ||
$<$<CONFIG:RELEASE>:-O3> | ||
) | ||
endif(NOT MSVC) | ||
|
||
set(CMAKE_COLOR_DIAGNOSTICS "ON") | ||
include_directories( | ||
${PROJECT_SOURCE_DIR} | ||
${PROJECT_SOURCE_DIR}/internal | ||
${PROJECT_SOURCE_DIR}/karamel/include | ||
) | ||
|
||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64") | ||
message(STATUS "Detected an x64 architecture") | ||
add_compile_definitions(LIBCRUX_X64) | ||
endif() | ||
|
||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|arm64v8" AND DEFINED ENV{LIBCRUX_NEON}) | ||
message(STATUS "Detected an arm64 architecture") | ||
add_compile_definitions(LIBCRUX_AARCH64) | ||
endif() | ||
|
||
# --- Tests | ||
|
||
# Get gtests | ||
include(FetchContent) | ||
FetchContent_Declare(googletest | ||
DOWNLOAD_EXTRACT_TIMESTAMP TRUE | ||
URL https://github.com/google/googletest/archive/refs/tags/release-1.11.0.zip | ||
) | ||
|
||
# For Windows: Prevent overriding the parent project's compiler/linker settings | ||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
FetchContent_MakeAvailable(googletest) | ||
|
||
# Get nlohmann json | ||
FetchContent_Declare(json | ||
DOWNLOAD_EXTRACT_TIMESTAMP TRUE | ||
URL https://github.com/nlohmann/json/archive/refs/tags/v3.10.3.zip | ||
) | ||
FetchContent_MakeAvailable(json) | ||
|
||
add_executable(ml_kem_test | ||
${PROJECT_SOURCE_DIR}/tests/mlkem768.cc | ||
) | ||
target_link_libraries(ml_kem_test PRIVATE | ||
gtest_main | ||
nlohmann_json::nlohmann_json | ||
) | ||
|
||
add_executable(sha3_test | ||
${PROJECT_SOURCE_DIR}/tests/sha3.cc | ||
) | ||
target_link_libraries(sha3_test PRIVATE | ||
gtest_main | ||
nlohmann_json::nlohmann_json | ||
) | ||
|
||
# --- Benchmarks | ||
FetchContent_Declare(benchmark | ||
GIT_REPOSITORY https://github.com/google/benchmark.git | ||
GIT_TAG v1.8.4 | ||
) | ||
FetchContent_MakeAvailable(benchmark) | ||
|
||
add_executable(ml_kem_bench | ||
${PROJECT_SOURCE_DIR}/benches/mlkem768.cc | ||
) | ||
target_link_libraries(ml_kem_bench PRIVATE | ||
benchmark::benchmark | ||
) | ||
|
||
if(DEFINED ENV{SYMCRYPT_PATH}) | ||
message("Symcrypt path: $ENV{SYMCRYPT_PATH}") | ||
add_compile_definitions(LIBCRUX_SYMCRYPT) | ||
target_include_directories(ml_kem_bench PRIVATE $ENV{SYMCRYPT_PATH}) | ||
target_link_directories(ml_kem_bench PRIVATE $ENV{SYMCRYPT_PATH}/bin/lib) | ||
target_link_libraries(ml_kem_bench PRIVATE symcrypt) | ||
endif(DEFINED ENV{SYMCRYPT_PATH}) | ||
|
||
add_executable(ml_kem_keygen | ||
${PROJECT_SOURCE_DIR}/benches/mlkem768_keygen.cc | ||
) | ||
target_link_libraries(ml_kem_keygen PRIVATE | ||
benchmark::benchmark | ||
) | ||
|
||
add_executable(ml_kem_encaps | ||
${PROJECT_SOURCE_DIR}/benches/mlkem768_encaps.cc | ||
) | ||
target_link_libraries(ml_kem_encaps PRIVATE | ||
benchmark::benchmark | ||
) | ||
|
||
if(NOT MSVC) | ||
# We benchmark internal functions here that are inlined and thus not available | ||
# in MSVC. | ||
add_executable(sha3_bench | ||
${PROJECT_SOURCE_DIR}/benches/sha3.cc | ||
) | ||
target_link_libraries(sha3_bench PRIVATE | ||
benchmark::benchmark | ||
) | ||
endif(NOT MSVC) |
Oops, something went wrong.