|
| 1 | +cmake_minimum_required(VERSION 3.10) |
| 2 | +project(libbitcoinpqc C) |
| 3 | + |
| 4 | +set(CMAKE_C_STANDARD 99) |
| 5 | +set(CMAKE_C_STANDARD_REQUIRED ON) |
| 6 | +set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 7 | + |
| 8 | +# Set version |
| 9 | +set(BITCOINPQC_VERSION_MAJOR 0) |
| 10 | +set(BITCOINPQC_VERSION_MINOR 1) |
| 11 | +set(BITCOINPQC_VERSION_PATCH 0) |
| 12 | + |
| 13 | +# Library output settings |
| 14 | +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 15 | +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 16 | +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 17 | + |
| 18 | +# Include directories |
| 19 | +include_directories( |
| 20 | + ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 21 | + ${CMAKE_CURRENT_SOURCE_DIR}/dilithium/ref |
| 22 | + ${CMAKE_CURRENT_SOURCE_DIR}/sphincsplus/ref |
| 23 | +) |
| 24 | + |
| 25 | +# Custom randombytes implementation |
| 26 | +set(CUSTOM_RANDOMBYTES |
| 27 | + dilithium/ref/randombytes_custom.c |
| 28 | + sphincsplus/ref/randombytes_custom.c |
| 29 | +) |
| 30 | + |
| 31 | +# ML-DSA-44 (Dilithium) source files |
| 32 | +set(ML_DSA_SOURCES |
| 33 | + dilithium/ref/sign.c |
| 34 | + dilithium/ref/packing.c |
| 35 | + dilithium/ref/polyvec.c |
| 36 | + dilithium/ref/poly.c |
| 37 | + dilithium/ref/ntt.c |
| 38 | + dilithium/ref/reduce.c |
| 39 | + dilithium/ref/rounding.c |
| 40 | + dilithium/ref/fips202.c |
| 41 | + dilithium/ref/symmetric-shake.c |
| 42 | +) |
| 43 | + |
| 44 | +# SLH-DSA-Shake-128s (SPHINCS+) source files |
| 45 | +set(SLH_DSA_SOURCES |
| 46 | + sphincsplus/ref/address.c |
| 47 | + sphincsplus/ref/fors.c |
| 48 | + sphincsplus/ref/hash_shake.c |
| 49 | + sphincsplus/ref/merkle.c |
| 50 | + sphincsplus/ref/sign.c |
| 51 | + sphincsplus/ref/thash_shake_simple.c |
| 52 | + sphincsplus/ref/utils.c |
| 53 | + sphincsplus/ref/utilsx1.c |
| 54 | + sphincsplus/ref/wots.c |
| 55 | + sphincsplus/ref/wotsx1.c |
| 56 | + sphincsplus/ref/fips202.c |
| 57 | +) |
| 58 | + |
| 59 | +# libbitcoinpqc source files |
| 60 | +set(BITCOINPQC_SOURCES |
| 61 | + src/bitcoinpqc.c |
| 62 | + src/ml_dsa/utils.c |
| 63 | + src/ml_dsa/keygen.c |
| 64 | + src/ml_dsa/sign.c |
| 65 | + src/ml_dsa/verify.c |
| 66 | + src/slh_dsa/utils.c |
| 67 | + src/slh_dsa/keygen.c |
| 68 | + src/slh_dsa/sign.c |
| 69 | + src/slh_dsa/verify.c |
| 70 | +) |
| 71 | + |
| 72 | +# Define the main library target |
| 73 | +add_library(bitcoinpqc STATIC |
| 74 | + ${BITCOINPQC_SOURCES} |
| 75 | + ${ML_DSA_SOURCES} |
| 76 | + ${SLH_DSA_SOURCES} |
| 77 | + ${CUSTOM_RANDOMBYTES} |
| 78 | +) |
| 79 | + |
| 80 | +# Set include directories for the library |
| 81 | +target_include_directories(bitcoinpqc PUBLIC |
| 82 | + ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 83 | +) |
| 84 | + |
| 85 | +# Set compile definitions for the library |
| 86 | +target_compile_definitions(bitcoinpqc PRIVATE |
| 87 | + DILITHIUM_MODE=2 # ML-DSA-44 (Dilithium2) |
| 88 | + PARAMS=sphincs-shake-128s |
| 89 | + CUSTOM_RANDOMBYTES=1 |
| 90 | +) |
| 91 | + |
| 92 | +# Configure install paths |
| 93 | +install(TARGETS bitcoinpqc |
| 94 | + ARCHIVE DESTINATION lib |
| 95 | + LIBRARY DESTINATION lib |
| 96 | + RUNTIME DESTINATION bin |
| 97 | +) |
| 98 | + |
| 99 | +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ |
| 100 | + DESTINATION include |
| 101 | + FILES_MATCHING PATTERN "*.h" |
| 102 | +) |
0 commit comments