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

C extraction for ML-DSA #710

Merged
merged 29 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5642422
wip; started cleanup hashing
franziskuskiefer Dec 5, 2024
bf2b900
added shake256 xof
franziskuskiefer Dec 5, 2024
7bf825a
F* extraction
franziskuskiefer Dec 5, 2024
38bf469
wip
franziskuskiefer Dec 5, 2024
5a0f22f
more wip eurydice changes
franziskuskiefer Dec 5, 2024
76e8015
update for C extraction
franziskuskiefer Dec 6, 2024
11a2dcf
first C extraction
franziskuskiefer Dec 6, 2024
0273d4a
more fixes for C (extracting but broken)
franziskuskiefer Dec 6, 2024
234b7d2
wip cg boilerplate
franziskuskiefer Dec 6, 2024
8723dfe
update serialize
franziskuskiefer Dec 6, 2024
b7df319
more loop cleanups
franziskuskiefer Dec 6, 2024
ce52b83
more loop cleanups
franziskuskiefer Dec 6, 2024
05d9103
more loop cleanups
franziskuskiefer Dec 6, 2024
3485de7
more loop cleanups
franziskuskiefer Dec 7, 2024
5686e51
more cleanup for hax/eurydice
franziskuskiefer Dec 7, 2024
d0dff30
extracting portable without eurydice failures
franziskuskiefer Dec 7, 2024
d4b51bc
fixes for hax
franziskuskiefer Dec 7, 2024
523b631
C and F* extraction
franziskuskiefer Dec 7, 2024
776fe1b
C extraction; not working
franziskuskiefer Dec 7, 2024
8749729
fix eurydice iterators
franziskuskiefer Dec 9, 2024
02f1009
mldsa: feature guard sampling
franziskuskiefer Dec 9, 2024
a93d7ea
mldsa C code (portable working)
franziskuskiefer Dec 9, 2024
60ac469
mldsa: updated F* code
franziskuskiefer Dec 9, 2024
6fef4d9
Merge branch 'franziskus/mldsa-c1' into franziskus/mldsa-c2
franziskuskiefer Dec 9, 2024
8836f78
Merge branch 'main' into franziskus/mldsa-c2
franziskuskiefer Dec 11, 2024
9f92306
address review comments
franziskuskiefer Dec 11, 2024
c51c2dd
update C extraction
franziskuskiefer Dec 11, 2024
23f6723
update DsaXof comment
franziskuskiefer Dec 11, 2024
f2e76e9
mldsa: update F* extraction
franziskuskiefer Dec 11, 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
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
Loading