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 1d4272e). 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.
31 lines
1.2 KiB
Rust
31 lines
1.2 KiB
Rust
// Copyright (c) 2024-2026 Lux Industries Inc.
|
|
// SPDX-License-Identifier: BSD-3-Clause-Eco
|
|
//
|
|
// BLS12-381 binding smoke test. The canonical luxcpp body currently returns
|
|
// CRYPTO_ERR_NOTIMPL (-5) until the blst integration is wired. This test
|
|
// asserts the C-ABI is reachable through Rust and reports a coherent status.
|
|
|
|
use lux_crypto_bls::{keygen, sk_to_pk, sign, verify, Error, PK_LEN, SEED_LEN, SIG_LEN, SK_LEN};
|
|
|
|
#[test]
|
|
fn keygen_sign_verify_roundtrip_or_notimpl() {
|
|
let seed = [0x11u8; SEED_LEN];
|
|
let mut sk = [0u8; SK_LEN];
|
|
|
|
match keygen(&seed, &mut sk) {
|
|
Ok(()) => {
|
|
let mut pk = [0u8; PK_LEN];
|
|
sk_to_pk(&sk, &mut pk).expect("sk_to_pk after successful keygen");
|
|
let mut sig = [0u8; SIG_LEN];
|
|
sign(&sk, b"lux-bls-binding-kat", &mut sig).expect("sign after keygen");
|
|
verify(&pk, b"lux-bls-binding-kat", &sig).expect("verify accepts honest sig");
|
|
}
|
|
Err(Error::Internal(-5)) => {
|
|
// CRYPTO_ERR_NOTIMPL: BLS C-ABI surface published, body in flight.
|
|
let mut pk = [0u8; PK_LEN];
|
|
assert!(matches!(sk_to_pk(&sk, &mut pk), Err(Error::Internal(-5))));
|
|
}
|
|
Err(other) => panic!("unexpected keygen error: {:?}", other),
|
|
}
|
|
}
|