wolfssl: add SHA-256 and SHA-512 known-answer tests
The engine now refuses any directly used algorithm without a passing KAT, and wolfSSL had none for its hashes. Refs: R3
This commit is contained in:
parent
4b79e83063
commit
424f7607bd
|
|
@ -4,11 +4,11 @@
|
||||||
//! gate the provider from being marked `available` in the capability catalog.
|
//! gate the provider from being marked `available` in the capability catalog.
|
||||||
|
|
||||||
use ccc_crypto_core::{
|
use ccc_crypto_core::{
|
||||||
algorithms::{AeadAlgorithm, KdfAlgorithm, MacAlgorithm},
|
algorithms::{AeadAlgorithm, HashAlgorithm, KdfAlgorithm, MacAlgorithm},
|
||||||
types::{AlgoTestResult, SelfTestReport},
|
types::{AlgoTestResult, SelfTestReport},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{aead, kdf, mac};
|
use crate::{aead, hash, kdf, mac};
|
||||||
|
|
||||||
// ──────────────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────────────
|
||||||
// AEAD vectors
|
// AEAD vectors
|
||||||
|
|
@ -94,6 +94,15 @@ static MAC_VECTORS: &[(MacAlgorithm, &str)] = &[
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/// FIPS 180-4 examples: the digest of "abc".
|
||||||
|
static HASH_VECTORS: &[(HashAlgorithm, &str)] = &[
|
||||||
|
(HashAlgorithm::Sha256, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"),
|
||||||
|
(
|
||||||
|
HashAlgorithm::Sha512,
|
||||||
|
"ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f",
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
fn hex(bytes: &[u8]) -> String {
|
fn hex(bytes: &[u8]) -> String {
|
||||||
bytes.iter().map(|b| format!("{b:02x}")).collect()
|
bytes.iter().map(|b| format!("{b:02x}")).collect()
|
||||||
}
|
}
|
||||||
|
|
@ -130,6 +139,13 @@ fn run_mac_vectors(results: &mut Vec<AlgoTestResult>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn run_hash_vectors(results: &mut Vec<AlgoTestResult>) {
|
||||||
|
for (algo, expected) in HASH_VECTORS {
|
||||||
|
let out = hash::hash(*algo, b"abc").map(|d| hex(&d)).map_err(|e| e.to_string());
|
||||||
|
results.push(result(*algo as u32, format!("{} FIPS 180-4 \"abc\"", algo.name()), out, expected));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ──────────────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────────────
|
||||||
// Runner
|
// Runner
|
||||||
// ──────────────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────────────
|
||||||
|
|
@ -142,6 +158,7 @@ pub(crate) fn run() -> SelfTestReport {
|
||||||
}
|
}
|
||||||
run_kdf_vectors(&mut results);
|
run_kdf_vectors(&mut results);
|
||||||
run_mac_vectors(&mut results);
|
run_mac_vectors(&mut results);
|
||||||
|
run_hash_vectors(&mut results);
|
||||||
SelfTestReport::finalise("wolfssl", results)
|
SelfTestReport::finalise("wolfssl", results)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,6 +211,6 @@ mod tests {
|
||||||
let r = super::run();
|
let r = super::run();
|
||||||
let failed: Vec<_> = r.results.iter().filter(|t| !t.passed).map(|t| t.algo_name.clone()).collect();
|
let failed: Vec<_> = r.results.iter().filter(|t| !t.passed).map(|t| t.algo_name.clone()).collect();
|
||||||
assert!(failed.is_empty(), "failed: {failed:?}");
|
assert!(failed.is_empty(), "failed: {failed:?}");
|
||||||
assert_eq!(r.results.len(), 7);
|
assert_eq!(r.results.len(), 9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue