Files
crypto/rust/lux-crypto-blake2b/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

53 lines
1.5 KiB
Rust

// Copyright (c) 2024-2026 Lux Industries Inc.
// SPDX-License-Identifier: BSD-3-Clause-Eco
//
// RFC 7693 BLAKE2b-512 known-answer tests.
use lux_crypto_blake2b::{hash, DIGEST_LEN};
fn from_hex(s: &str) -> [u8; DIGEST_LEN] {
let b = s.as_bytes();
assert_eq!(b.len(), 2 * DIGEST_LEN);
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; DIGEST_LEN];
for i in 0..DIGEST_LEN {
out[i] = (nibble(b[2 * i]) << 4) | nibble(b[2 * i + 1]);
}
out
}
#[test]
fn empty_string() {
let want = from_hex(
"786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419\
d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce",
);
assert_eq!(hash(b""), want);
}
#[test]
fn abc() {
// RFC 7693 §F.4 reference vector for "abc".
let want = from_hex(
"ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d1\
7d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923",
);
assert_eq!(hash(b"abc"), want);
}
#[test]
fn quick_brown_fox() {
let want = from_hex(
"a8add4bdddfd93e4877d2746e62817b116364a1fa7bc148d95090bc7333b3673\
f82401cf7aa2e4cb1ecd90296e3f14cb5413f8ed77be73045b13914cdcd6a918",
);
assert_eq!(hash(b"The quick brown fox jumps over the lazy dog"), want);
}