Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ QWEN.md
build-local/
docs-site/.next/
docs-site/node_modules/

# Symlinks created at configure-time by the lux-gpu-kernels discovery hook
# (top-level CMakeLists.txt). Each <scheme>/gpu/<backend> is a symlink into
# the lux-gpu-kernels install prefix when the private repo is found;
# absent on CPU-only builds. Never committed.
*/gpu/cuda
*/gpu/metal
*/gpu/wgsl
math/ntt/cuda
630 changes: 339 additions & 291 deletions CMakeLists.txt

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# luxcpp/crypto

Canonical native cryptographic primitives for the Lux / Hanzo / Zoo
ecosystem. CPU + GPU implementations live here and only here.

* CPU: portable C++17 / C++20, no third-party crypto libraries
* GPU: CUDA, Metal, WGSL kernels with byte-equal CPU↔GPU output
ecosystem. Public surface ships CPU implementations only.

* CPU: portable C++17 / C++20, no third-party crypto libraries (this repo)
* GPU: CUDA, Metal, WGSL kernels — **proprietary**, distributed via
`lux-private/gpu-kernels`. Public CMake build auto-detects via
`find_package(lux-gpu-kernels CONFIG QUIET)` and disables Metal/CUDA/WGSL
drivers when absent (CPU-only fallback). Commercial license:
licensing@lux.network
* C ABI: `include/lux/crypto/<alg>.h`, callable from Go (cgo) and
Rust (bindgen / lux-crypto-sys)
Rust (bindgen / lux-crypto-sys) — identical surface whether the GPU
kernels are linked or not

The Go entry point is `github.com/luxfi/crypto`; the GPU device router
is `github.com/luxfi/accel`.
Expand Down
124 changes: 55 additions & 69 deletions aead/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,21 @@ endif()
# =============================================================================
# CUDA drivers + determinism test.
#
# The .cu files compile only when CRYPTO_ENABLE_CUDA is ON (NVCC required).
# The host driver compiles on every host: with LUX_AEAD_HAVE_CUDA defined it
# launches the kernels; without, it returns -1 from every entry point so the
# determinism test prints a "build-only" banner on Apple.
# Built only when CRYPTO_ENABLE_CUDA=ON (lux-gpu-kernels found + NVCC). The
# host driver and .cu kernels live in lux-private/gpu-kernels; consumer tests
# at the top-level CMakeLists are gated on the same flag.
# =============================================================================

# Always build the host driver (stub or real). On Apple this gives us the
# build-only path (compiles, links, returns -1). On Linux+CUDA CI we set
# CRYPTO_ENABLE_CUDA=ON which flips the driver into real-dispatch mode
# and additionally compiles the .cu kernels.

add_library(aead_cuda_driver STATIC gpu/cuda/aead_driver_cuda.cpp)
target_include_directories(aead_cuda_driver
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/gpu/cuda>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp>
)
target_compile_features(aead_cuda_driver PUBLIC cxx_std_20)
set_target_properties(aead_cuda_driver PROPERTIES POSITION_INDEPENDENT_CODE ON)

if(CRYPTO_ENABLE_CUDA)
enable_language(CUDA)
add_library(aead_cuda_driver STATIC gpu/cuda/aead_driver_cuda.cpp)
target_include_directories(aead_cuda_driver
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/gpu/cuda>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp>
)
target_compile_features(aead_cuda_driver PUBLIC cxx_std_20)
set_target_properties(aead_cuda_driver PROPERTIES POSITION_INDEPENDENT_CODE ON)

add_library(aead_cuda_kernels STATIC
gpu/cuda/chacha20_poly1305.cu
gpu/cuda/aes_gcm.cu)
Expand All @@ -76,60 +69,53 @@ if(CRYPTO_ENABLE_CUDA)
target_link_libraries(aead_cuda_driver PUBLIC CUDA::cudart)
endif()

# Test executables are added at the top-level CMakeLists.txt where
# enable_testing() has been called before us. The library targets above
# are sufficient for the parent to wire test binaries.

# =============================================================================
# WGSL driver (compiles WGSL via wgpu-native or Dawn; outputs bound through
# C ABI). On Apple, byte-equality is enforced if wgpu-native is on the system;
# otherwise the test self-skips. On Linux/CI, same behavior with Dawn.
# C ABI). Built only when CRYPTO_ENABLE_WGSL=ON.
# =============================================================================
if(CRYPTO_ENABLE_WGSL)
# Concatenate WGSL sources into a header that the host driver embeds.
set(AEAD_WGSL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gpu/wgsl")
set(AEAD_WGSL_HEADER "${CMAKE_CURRENT_BINARY_DIR}/aead_wgsl_sources.h")
file(WRITE "${AEAD_WGSL_HEADER}" "// Auto-generated. Do not edit.\n#pragma once\n\n")
foreach(_SRC chacha20_poly1305.wgsl aes_gcm.wgsl)
get_filename_component(_NAME ${_SRC} NAME_WE)
string(REGEX REPLACE "^chacha20_poly1305$" "ChaCha20Poly1305" _SHORT "${_NAME}")
string(REGEX REPLACE "^aes_gcm$" "AesGcm" _SHORT "${_SHORT}")
file(READ "${AEAD_WGSL_DIR}/${_SRC}" _CONTENT)
file(APPEND "${AEAD_WGSL_HEADER}"
"// ---- ${_SRC} ----\n"
"static constexpr char kAEAD_WGSL_${_SHORT}[] = R\"AEADWGSL(\n${_CONTENT}\n)AEADWGSL\";\n\n")
endforeach()

# Concatenate WGSL sources into a header that the host driver embeds.
set(AEAD_WGSL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gpu/wgsl")
set(AEAD_WGSL_HEADER "${CMAKE_CURRENT_BINARY_DIR}/aead_wgsl_sources.h")
file(WRITE "${AEAD_WGSL_HEADER}" "// Auto-generated. Do not edit.\n#pragma once\n\n")
foreach(_SRC chacha20_poly1305.wgsl aes_gcm.wgsl)
get_filename_component(_NAME ${_SRC} NAME_WE)
string(REGEX REPLACE "^chacha20_poly1305$" "ChaCha20Poly1305" _SHORT "${_NAME}")
string(REGEX REPLACE "^aes_gcm$" "AesGcm" _SHORT "${_SHORT}")
file(READ "${AEAD_WGSL_DIR}/${_SRC}" _CONTENT)
file(APPEND "${AEAD_WGSL_HEADER}"
"// ---- ${_SRC} ----\n"
"static constexpr char kAEAD_WGSL_${_SHORT}[] = R\"AEADWGSL(\n${_CONTENT}\n)AEADWGSL\";\n\n")
endforeach()

# Locate wgpu-native (Homebrew) or Dawn.
set(_AEAD_WGPU_FOUND FALSE)
find_path(_AEAD_WGPU_INCLUDE webgpu.h
HINTS /opt/homebrew/include /usr/local/include /usr/include)
find_library(_AEAD_WGPU_LIB NAMES wgpu_native wgpu
HINTS /opt/homebrew/lib /usr/local/lib /usr/lib)
if(_AEAD_WGPU_INCLUDE AND _AEAD_WGPU_LIB)
set(_AEAD_WGPU_FOUND TRUE)
endif()
# Locate wgpu-native (Homebrew) or Dawn.
set(_AEAD_WGPU_FOUND FALSE)
find_path(_AEAD_WGPU_INCLUDE webgpu.h
HINTS /opt/homebrew/include /usr/local/include /usr/include)
find_library(_AEAD_WGPU_LIB NAMES wgpu_native wgpu
HINTS /opt/homebrew/lib /usr/local/lib /usr/lib)
if(_AEAD_WGPU_INCLUDE AND _AEAD_WGPU_LIB)
set(_AEAD_WGPU_FOUND TRUE)
endif()

add_library(aead_wgpu_driver STATIC gpu/wgsl/aead_driver_wgpu.cpp)
target_include_directories(aead_wgpu_driver
PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/gpu/wgsl"
"${CMAKE_CURRENT_SOURCE_DIR}/cpp"
)
target_compile_features(aead_wgpu_driver PUBLIC cxx_std_20)
set_target_properties(aead_wgpu_driver PROPERTIES POSITION_INDEPENDENT_CODE ON)
add_library(aead_wgpu_driver STATIC gpu/wgsl/aead_driver_wgpu.cpp)
target_include_directories(aead_wgpu_driver
PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/gpu/wgsl"
"${CMAKE_CURRENT_SOURCE_DIR}/cpp"
)
target_compile_features(aead_wgpu_driver PUBLIC cxx_std_20)
set_target_properties(aead_wgpu_driver PROPERTIES POSITION_INDEPENDENT_CODE ON)

if(_AEAD_WGPU_FOUND)
target_include_directories(aead_wgpu_driver PRIVATE ${_AEAD_WGPU_INCLUDE})
target_link_libraries(aead_wgpu_driver PUBLIC ${_AEAD_WGPU_LIB})
target_compile_definitions(aead_wgpu_driver PRIVATE
LUX_AEAD_HAS_WEBGPU=1
LUX_AEAD_HAS_WGPU_NATIVE=1)
message(STATUS "[aead-wgsl] wgpu-native: ${_AEAD_WGPU_LIB}")
else()
message(STATUS "[aead-wgsl] wgpu-native: NOT FOUND (driver compiles to stub)")
if(_AEAD_WGPU_FOUND)
target_include_directories(aead_wgpu_driver PRIVATE ${_AEAD_WGPU_INCLUDE})
target_link_libraries(aead_wgpu_driver PUBLIC ${_AEAD_WGPU_LIB})
target_compile_definitions(aead_wgpu_driver PRIVATE
LUX_AEAD_HAS_WEBGPU=1
LUX_AEAD_HAS_WGPU_NATIVE=1)
message(STATUS "[aead-wgsl] wgpu-native: ${_AEAD_WGPU_LIB}")
else()
message(STATUS "[aead-wgsl] wgpu-native: NOT FOUND (driver compiles to stub)")
endif()
endif()

# See note above: aead_wgsl_determinism_test is added at the top-level
# CMakeLists.txt after enable_testing() has run.
205 changes: 0 additions & 205 deletions aead/gpu/cuda/aead_driver_cuda.cpp

This file was deleted.

Loading
Loading