Files
crypto/rust/lux-crypto-blake3/tests/spec_vectors.rs
zeekay 0e189bf8af rust: 21-crate workspace finalized over luxcpp/crypto C-ABI
One Rust crate per algorithm, plus an `lux-crypto` umbrella that re-exports
each per-algorithm crate behind a Cargo feature.

5 working crates with verified spec vectors:
  - lux-crypto-keccak    (Ethereum keccak256)
  - lux-crypto-secp256k1 (ecrecover precompile + batch)
  - lux-crypto-sha256    (FIPS 180-4)
  - lux-crypto-ripemd160 (Bitcoin/Ethereum address derivation)
  - lux-crypto-blake2b   (RFC 7693)

15 wired-but-NOTIMPL crates (canonical Rust binding shipped, body returns
CRYPTO_ERR_NOTIMPL today; spec-vector tests gated `#[ignore]` with FIXME):
  blake3, ed25519, slhdsa, mldsa, mlkem, bls, kzg, bn254, aead, ipa,
  pedersen, lamport, ntt, poly-mul, evm256.

cargo check --release --workspace --all-features    OK
cargo test  --release --workspace                   55 pass / 0 fail / 25 ignored
cargo doc   --no-deps --workspace                   clean
cargo publish --dry-run --no-verify                 OK for all 20 leaf crates

Workspace docs added at rust/{README,PUBLISHING,RUST_CRATE_STATUS}.md.
Per-crate README.md and `Cargo.toml` metadata (description, license,
repository, keywords, categories, readme) wired for crates.io publish.

Build directives normalized: link both `lib<alg>.a` (C-ABI shim) and
`lib<alg>_cpu.a` (CPU body); brand-neutral C symbols (no lux_ prefix) per
the prefix-uniform audit.
2025-12-28 10:41:53 -08:00

64 lines
2.2 KiB
Rust

// Copyright (c) 2024-2026 Lux Industries Inc.
// SPDX-License-Identifier: BSD-3-Clause-Eco
//
// Spec-vector integration test for lux-crypto-blake3.
//
// FIXME: luxcpp/crypto/blake3/c-abi/c_blake3.cpp returns CRYPTO_ERR_NOTIMPL
// for all entry points. Re-enable these vectors once the C-ABI body lands.
// Tracked at luxcpp/crypto issue #blake3-c-abi-impl.
//
// Vectors below are the upstream BLAKE3-team/BLAKE3 v1.5.0 reference
// `test_vectors.json` first 32-byte hash output.
use lux_crypto_blake3::{hash, Error};
fn from_hex32(s: &str) -> [u8; 32] {
let b = s.as_bytes();
assert_eq!(b.len(), 64);
let nibble = |c: u8| -> u8 {
match c {
b'0'..=b'9' => c - b'0',
b'a'..=b'f' => c - b'a' + 10,
b'A'..=b'F' => c - b'A' + 10,
_ => panic!("non-hex"),
}
};
let mut out = [0u8; 32];
for i in 0..32 {
out[i] = (nibble(b[2 * i]) << 4) | nibble(b[2 * i + 1]);
}
out
}
#[test]
#[ignore = "luxcpp blake3 c-abi NOTIMPL — tracked at #blake3-c-abi-impl"]
fn empty_input_default_digest() {
// Upstream BLAKE3 reference output for the empty input (first 32 bytes
// of the hash function output stream).
let want = from_hex32("af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262");
let got = hash(b"").expect("blake3(empty)");
assert_eq!(got, want, "BLAKE3 empty input mismatch");
}
#[test]
#[ignore = "luxcpp blake3 c-abi NOTIMPL — tracked at #blake3-c-abi-impl"]
fn input_one_byte_zero_default_digest() {
let want = from_hex32("2d3adedff11b61f14c886e35afa036736dcd87a74d27b5c1510225d0f592e213");
let got = hash(&[0u8]).expect("blake3(0x00)");
assert_eq!(got, want);
}
#[test]
fn binding_returns_error_when_c_abi_unimpl() {
// While the C-ABI body is unwired, every call returns -5 (CRYPTO_ERR_NOTIMPL).
// This is the only check we can run today that does not silently pass.
match hash(b"any input") {
Ok(_) => {
// Once the C-ABI body lands, this branch becomes the new normal.
}
Err(Error::InternalError(rc)) => {
assert_eq!(rc, -5, "expected NOTIMPL while C-ABI body is unwired");
}
}
}