Skip to content

Commit

Permalink
Merge pull request #710 from cryspen/franziskus/mldsa-c2
Browse files Browse the repository at this point in the history
C extraction for ML-DSA
  • Loading branch information
franziskuskiefer authored Dec 16, 2024
2 parents fc934b3 + f2e76e9 commit 5d76f68
Show file tree
Hide file tree
Showing 145 changed files with 29,598 additions and 2,656 deletions.
53 changes: 33 additions & 20 deletions libcrux-ml-dsa/cg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,6 @@ files:
monomorphizations_using:
- [libcrux_sha3, "*"]

# MLKEM: MISC NON-ARCHITECTURE SPECIFIC HEADERS
- name: libcrux_core
inline_static: true
private:
monomorphizations_of:
- [core, "*"]
- [libcrux_ml_dsa, types, "*"]
- [libcrux_ml_dsa, utils, "*" ]
monomorphizations_using:
- [Eurydice, "*" ]
- [libcrux_ml_dsa, types, "*"]
patterns:
- [core, "*"]
- [libcrux_ml_dsa, types, "*" ]
- [libcrux_ml_dsa, constants ]
- [libcrux_ml_dsa, utils, "*" ]
- [libcrux_ml_dsa, simd, traits ]
api:
- [Eurydice, "*"]

# MLDSA-65

- name: libcrux_mldsa65_avx2
Expand All @@ -78,6 +58,7 @@ files:
- [libcrux_ml_dsa, hash_functions, simd256, "*"]
- [libcrux_ml_dsa, ml_dsa_65, avx2, "*"]
- [libcrux_ml_dsa, ml_dsa_generic, instantiations, avx2, "*"]
# - [core, option, Option_c4]
# - [libcrux_ml_dsa, polynomial, "*" ]
monomorphizations_of:
- [libcrux_ml_dsa, simd, avx2, "*"]
Expand All @@ -87,6 +68,8 @@ files:
monomorphizations_using:
- [libcrux_ml_dsa, simd, avx2, "*"]
- [libcrux_ml_dsa, hash_functions, simd256, "*"]
# monomorphizations_exact:
# - [core, option, Option_c4]

- name: libcrux_mldsa65_portable
inline_static: true
Expand All @@ -97,17 +80,47 @@ files:
- [libcrux_ml_dsa, hash_functions, portable, "*"]
- [libcrux_ml_dsa, ml_dsa_65, portable, "*"]
- [libcrux_ml_dsa, ml_dsa_generic, instantiations, portable, "*"]
# - [libcrux_ml_dsa, pre_hash, PreHashResult]
# - [core, option, Option_84]
monomorphizations_of:
- [libcrux_ml_dsa, polynomial, "*" ]
- [libcrux_ml_dsa, simd, "*"]
- [libcrux_ml_dsa, hash_functions, portable, "*"]
- [libcrux_ml_dsa, ml_dsa_65, portable]
- [libcrux_ml_dsa, ml_dsa_generic, instantiations, portable, "*"]
# - [libcrux_ml_dsa, pre_hash, PreHashResult]
# - [core, option, Option_84]
monomorphizations_using:
- [libcrux_ml_dsa, polynomial, "*" ]
- [libcrux_ml_dsa, simd, "*"]
- [libcrux_ml_dsa, hash_functions, portable, "*"]
- [libcrux_ml_dsa, ml_dsa_generic, instantiations, portable, "*"]
# - [libcrux_ml_dsa, pre_hash, PreHashResult]
monomorphizations_exact:
- [libcrux_ml_dsa, pre_hash, PreHashResult]
- [core, result, Result_a8]
- [core, option, Option_84]


# MLKEM: MISC NON-ARCHITECTURE SPECIFIC HEADERS
- name: libcrux_core
inline_static: true
private:
monomorphizations_of:
- [core, "*"]
- [libcrux_ml_dsa, types, "*"]
- [libcrux_ml_dsa, utils, "*" ]
monomorphizations_using:
- [Eurydice, "*" ]
- [libcrux_ml_dsa, types, "*"]
patterns:
- [core, "*"]
- [libcrux_ml_dsa, types ]
- [libcrux_ml_dsa, constants ]
- [libcrux_ml_dsa, utils, "*" ]
# - [libcrux_ml_dsa, simd, traits ]
api:
- [Eurydice, "*"]

naming:
skip_prefix:
Expand Down
1 change: 1 addition & 0 deletions libcrux-ml-dsa/cg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
143 changes: 143 additions & 0 deletions libcrux-ml-dsa/cg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# 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-dsa
VERSION 0.1.0
LANGUAGES C CXX
)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)

if(NOT MSVC)
add_compile_options(
-Wall
-fstack-usage
-Wunused-function
$<$<CONFIG:DEBUG>:-g>
$<$<CONFIG:DEBUG>:-Og>
$<$<CONFIG:RELEASE>:-g>
$<$<CONFIG:RELEASE>:-O3>
)
endif(NOT MSVC)

if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "13.0.0") OR
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND
CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "13.1.6"))
# add_compile_options(-Werror -Wframe-larger-than=25344)
endif()

set(CMAKE_COLOR_DIAGNOSTICS "ON")
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/karamel
)

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_dsa_test
${PROJECT_SOURCE_DIR}/tests/mldsa65.cc
)
target_link_libraries(ml_dsa_test PRIVATE
gtest_main
nlohmann_json::nlohmann_json
)

# add_executable(kyber_test
# ${PROJECT_SOURCE_DIR}/tests/kyber768.cc
# )
# target_link_libraries(kyber_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
# if(DEFINED ENV{LIBCRUX_BENCHMARKS})
# FetchContent_Declare(benchmark
# GIT_REPOSITORY https://github.com/google/benchmark.git
# GIT_TAG v1.8.4
# )
# FetchContent_MakeAvailable(benchmark)

# add_executable(ml_dsa_bench
# ${PROJECT_SOURCE_DIR}/benches/mldsa768.cc
# )
# target_link_libraries(ml_dsa_bench PRIVATE
# benchmark::benchmark
# )

# if(DEFINED ENV{SYMCRYPT_PATH})
# message("Symcrypt path: $ENV{SYMCRYPT_PATH}")
# add_compile_definitions(LIBCRUX_SYMCRYPT)
# target_include_directories(ml_dsa_bench PRIVATE $ENV{SYMCRYPT_PATH})
# target_link_directories(ml_dsa_bench PRIVATE $ENV{SYMCRYPT_PATH}/bin/lib)
# target_link_libraries(ml_dsa_bench PRIVATE symcrypt)
# endif(DEFINED ENV{SYMCRYPT_PATH})

# add_executable(ml_dsa_keygen
# ${PROJECT_SOURCE_DIR}/benches/mldsa768_keygen.cc
# )
# target_link_libraries(ml_dsa_keygen PRIVATE
# benchmark::benchmark
# )

# add_executable(ml_dsa_encaps
# ${PROJECT_SOURCE_DIR}/benches/mldsa768_encaps.cc
# )
# target_link_libraries(ml_dsa_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)
# endif(DEFINED ENV{LIBCRUX_BENCHMARKS})
10 changes: 5 additions & 5 deletions libcrux-ml-dsa/cg/code_gen.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This code was generated with the following revisions:
Charon: 45f5a34f336e35c6cc2253bc90cbdb8d812cefa9
Eurydice: e2db6e88adc9995ca9d3dedf7fa9bc4095e9ca20
Karamel: 8c3612018c25889288da6857771be3ad03b75bcd
F*: 5643e656b989aca7629723653a2570c7df6252b9-dirty
Libcrux: ef3ee2539580595003c62a749034ae0c76d22a0d
Charon: a68994d00017b76a805d0115ca06c1f2c1805e79
Eurydice: b665364a6d86749566ce2d650d13fa12c8fab2c5
Karamel: 96572bc631fde691a2aea7bce5a5a3838b3a5968
F*: b0961063393215ca65927f017720cb365a193833-dirty
Libcrux: d4b51bcb3af12fb1358ed37830e33cbd72d31590
Loading

0 comments on commit 5d76f68

Please sign in to comment.