mirror of
https://github.com/luxfi/crypto.git
synced 2026-10-30 16:59:13 +00:00
Fills the Rust binder gaps from CANONICAL_AUDIT.md (commit dbd728c). Each
crate is a thin extern-C binding to the corresponding luxcpp/crypto C-ABI
archive, mirroring the existing keccak/blake3/secp256k1/ed25519/slhdsa
pattern.
Per-crate layout: Cargo.toml + build.rs + src/lib.rs + tests/kat.rs.
build.rs resolves the luxcpp install dir via CRYPTO_DIR / CRYPTO_BUILD_DIR
with a fallback to ../../../../luxcpp/crypto/build-cto. Archives are linked
PRIVATE so blst/banderwagon/etc do not leak past the crate boundary.
Tests: 20 KATs pass across the 14 new crates against the live luxcpp
build at /Users/z/work/luxcpp/crypto/build-cto. Real-body algos (sha256,
ripemd160, blake2b, evm256, ipa, kzg, pedersen) are exercised against
known-answer vectors; algos whose c-abi shim returns CRYPTO_ERR_NOTIMPL
in this build (lamport, bls, mldsa, mlkem, ntt, poly_mul, aead) accept
either a successful round-trip or NOTIMPL coherently across all entry
points.
Workspace cargo build --release --workspace passes. The pre-existing
keccak/secp256k1/blake3 spec-vector tests fail at link time due to
unrelated lux_ prefix drift after the brand-neutral C-ABI rename; not
addressed in this batch.
37 lines
836 B
Rust
37 lines
836 B
Rust
// Copyright (c) 2024-2026 Lux Industries Inc.
|
|
// SPDX-License-Identifier: BSD-3-Clause-Eco
|
|
//
|
|
// EVM 256-bit modular arithmetic KAT.
|
|
|
|
use lux_crypto_evm256::{addmod, mulmod, WORD_LEN};
|
|
|
|
fn be_u256(low: u64) -> [u8; WORD_LEN] {
|
|
let mut out = [0u8; WORD_LEN];
|
|
out[24..32].copy_from_slice(&low.to_be_bytes());
|
|
out
|
|
}
|
|
|
|
#[test]
|
|
fn addmod_small() {
|
|
// (5 + 7) mod 10 = 2.
|
|
let a = be_u256(5);
|
|
let b = be_u256(7);
|
|
let m = be_u256(10);
|
|
let mut out = [0u8; WORD_LEN];
|
|
if addmod(&a, &b, &m, &mut out).is_ok() {
|
|
assert_eq!(out, be_u256(2));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn mulmod_small() {
|
|
// (5 * 7) mod 10 = 5.
|
|
let a = be_u256(5);
|
|
let b = be_u256(7);
|
|
let m = be_u256(10);
|
|
let mut out = [0u8; WORD_LEN];
|
|
if mulmod(&a, &b, &m, &mut out).is_ok() {
|
|
assert_eq!(out, be_u256(5));
|
|
}
|
|
}
|