cascade: bind the vetted layer through a provider slot
Built-in suites name a 'vetted' slot that AWS-LC, BoringSSL or wolfSSL can fill; the ciphertext does not depend on which one. Refs: R3
This commit is contained in:
parent
04643dbe97
commit
f8bca636b5
|
|
@ -26,7 +26,9 @@ pub const MAX_ROUNDS: u8 = 16;
|
|||
pub struct Layer {
|
||||
/// The AEAD.
|
||||
pub aead: AeadAlgorithm,
|
||||
/// The provider that runs it (`"wolfssl"`, `"rustcrypto"`, ...).
|
||||
/// The provider slot that runs it: a provider name (`"rustcrypto"`), or
|
||||
/// a slot such as [`crate::suites::VETTED`] that the build binds to one of
|
||||
/// several interchangeable providers with [`ProviderSet::bind`].
|
||||
pub provider: &'static str,
|
||||
}
|
||||
|
||||
|
|
@ -65,8 +67,9 @@ impl Policy {
|
|||
}
|
||||
}
|
||||
|
||||
/// Release builds (D-26): the vetted layer must come from wolfCrypt in
|
||||
/// FIPS mode. A build without the FIPS module cannot resolve any suite.
|
||||
/// Release builds (D-26): the vetted layer must come from a provider in
|
||||
/// FIPS mode (AWS-LC-FIPS by default). A build without a FIPS module
|
||||
/// cannot resolve any suite.
|
||||
pub fn release() -> Self {
|
||||
Self { require_fips_vetted_layer: true, ..Self::development() }
|
||||
}
|
||||
|
|
@ -91,6 +94,16 @@ impl ProviderSet {
|
|||
/// recorded and every suite using them refuses to resolve.
|
||||
pub fn add(&mut self, provider: Arc<dyn CryptoProvider>) -> &mut Self {
|
||||
let name = provider.provider_name();
|
||||
self.bind(name, provider)
|
||||
}
|
||||
|
||||
/// Add `provider` under the slot `slot` (for example
|
||||
/// [`crate::suites::VETTED`]) after running its self-test. Providers that
|
||||
/// implement an algorithm produce the same bytes, so the binding can change
|
||||
/// between builds without changing any ciphertext.
|
||||
pub fn bind(&mut self, slot: &'static str, provider: Arc<dyn CryptoProvider>) -> &mut Self {
|
||||
let name = slot;
|
||||
self.passed.retain(|(p, _)| *p != name);
|
||||
let report = provider.self_test();
|
||||
// Any failing vector for an algorithm disqualifies it, even if another
|
||||
// vector for it passed.
|
||||
|
|
@ -102,7 +115,7 @@ impl ProviderSet {
|
|||
self
|
||||
}
|
||||
|
||||
/// The provider called `name`.
|
||||
/// The provider bound to `name` (a provider name or a slot).
|
||||
pub fn get(&self, name: &str) -> Option<&Arc<dyn CryptoProvider>> {
|
||||
self.providers.get(name)
|
||||
}
|
||||
|
|
@ -159,7 +172,11 @@ impl ProviderSet {
|
|||
if self.failed_self_test(anchor.provider, KdfAlgorithm::Sha512 as u32) {
|
||||
return Err(CascadeError::SelfTestFailed(format!("HKDF-SHA-512 in {}", anchor.provider)));
|
||||
}
|
||||
if policy.require_distinct_adjacent_providers && suite.layers.windows(2).any(|w| w[0].provider == w[1].provider)
|
||||
// Distinct means distinct implementations, so compare what the slots
|
||||
// are bound to, not the slot names.
|
||||
let implementation = |slot: &str| self.providers[slot].provider_name();
|
||||
if policy.require_distinct_adjacent_providers
|
||||
&& suite.layers.windows(2).any(|w| implementation(w[0].provider) == implementation(w[1].provider))
|
||||
{
|
||||
return deny("adjacent layers share a provider".into());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,17 @@ use ccc_crypto_core::AeadAlgorithm::{AesGcm256, AesGcmSiv256, AsconAead128, XCha
|
|||
|
||||
use crate::suite::{Layer, Suite};
|
||||
|
||||
/// The slot for the vetted, FIPS-capable layer. Builds bind it to AWS-LC
|
||||
/// (default), BoringSSL or wolfSSL with [`crate::ProviderSet::bind`].
|
||||
pub const VETTED: &str = "vetted";
|
||||
|
||||
const fn layer(aead: ccc_crypto_core::AeadAlgorithm, provider: &'static str) -> Layer {
|
||||
Layer { aead, provider }
|
||||
}
|
||||
|
||||
/// Floor: one vetted layer (AES-256-GCM from wolfCrypt).
|
||||
/// Floor: one vetted layer (AES-256-GCM from the vetted provider).
|
||||
pub fn floor_aes() -> Suite {
|
||||
Suite { id: 1, name: "floor-aes", layers: vec![layer(AesGcm256, "wolfssl")] }
|
||||
Suite { id: 1, name: "floor-aes", layers: vec![layer(AesGcm256, VETTED)] }
|
||||
}
|
||||
|
||||
/// Standard+: two layers, two providers, two design families.
|
||||
|
|
@ -21,7 +25,7 @@ pub fn standard_2() -> Suite {
|
|||
Suite {
|
||||
id: 2,
|
||||
name: "standard-2",
|
||||
layers: vec![layer(AesGcm256, "wolfssl"), layer(XChaCha20Poly1305, "rustcrypto")],
|
||||
layers: vec![layer(AesGcm256, VETTED), layer(XChaCha20Poly1305, "rustcrypto")],
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -32,7 +36,7 @@ pub fn high_3() -> Suite {
|
|||
name: "high-3",
|
||||
layers: vec![
|
||||
layer(XChaCha20Poly1305, "rustcrypto"),
|
||||
layer(AesGcm256, "wolfssl"),
|
||||
layer(AesGcm256, VETTED),
|
||||
layer(AesGcmSiv256, "rustcrypto"),
|
||||
],
|
||||
}
|
||||
|
|
@ -46,7 +50,7 @@ pub fn ultra_3() -> Suite {
|
|||
name: "ultra-3",
|
||||
layers: vec![
|
||||
layer(XChaCha20Poly1305, "rustcrypto"),
|
||||
layer(AesGcm256, "wolfssl"),
|
||||
layer(AesGcm256, VETTED),
|
||||
layer(AsconAead128, "rustcrypto"),
|
||||
],
|
||||
}
|
||||
|
|
@ -54,7 +58,7 @@ pub fn ultra_3() -> Suite {
|
|||
|
||||
/// Storage at rest for Standard: two layers (design: storage cascade row).
|
||||
pub fn storage_2() -> Suite {
|
||||
Suite { id: 5, name: "storage-2", layers: vec![layer(AesGcm256, "wolfssl"), layer(AesGcmSiv256, "rustcrypto")] }
|
||||
Suite { id: 5, name: "storage-2", layers: vec![layer(AesGcm256, VETTED), layer(AesGcmSiv256, "rustcrypto")] }
|
||||
}
|
||||
|
||||
/// Every built-in suite.
|
||||
|
|
|
|||
|
|
@ -276,3 +276,24 @@ fn builtin_suites_have_unique_ids_and_a_vetted_layer() {
|
|||
assert_eq!(suites::by_id(s.id).as_ref(), Some(s));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slots_bind_providers_and_distinct_compares_implementations() {
|
||||
let mut p = providers();
|
||||
let wolf: Arc<dyn CryptoProvider> = Arc::new(WolfSslProvider::new());
|
||||
p.bind(crate::suites::VETTED, wolf.clone());
|
||||
let s = suite(1, &[(AesGcm256, crate::suites::VETTED), (XChaCha20Poly1305, "other")]);
|
||||
let dev = Policy::development();
|
||||
let r = p.resolve(&s, &dev).unwrap();
|
||||
assert_eq!(r.kdf.provider_name(), "wolfssl", "the slot runs the bound provider");
|
||||
// The same implementation behind two names is not two providers.
|
||||
let distinct = Policy { require_distinct_adjacent_providers: true, ..dev.clone() };
|
||||
let same = suite(1, &[(AesGcm256, crate::suites::VETTED), (ChaCha20Poly1305, "wolfssl")]);
|
||||
assert!(matches!(p.resolve(&same, &distinct), Err(CascadeError::Policy(_))));
|
||||
// Rebinding replaces the slot's self-test results.
|
||||
p.bind(crate::suites::VETTED, TestProvider::arc("broken2", false, Some(AesGcm256)));
|
||||
assert!(matches!(p.resolve(&s, &dev), Err(CascadeError::SelfTestFailed(_))));
|
||||
// An unbound slot is refused.
|
||||
let unbound = suite(1, &[(AesGcm256, "unbound-slot")]);
|
||||
assert!(matches!(ProviderSet::new().resolve(&unbound, &dev), Err(CascadeError::Policy(_))));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use ccc_crypto_wolfssl::WolfSslProvider;
|
|||
|
||||
fn providers() -> ProviderSet {
|
||||
let mut p = ProviderSet::new();
|
||||
p.add(Arc::new(WolfSslProvider::new()));
|
||||
p.bind(ccc_cascade::suites::VETTED, Arc::new(WolfSslProvider::new()));
|
||||
p.add(Arc::new(RustCryptoProvider::new()));
|
||||
p
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ const PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../vectors/cascade_v
|
|||
|
||||
fn providers() -> ProviderSet {
|
||||
let mut p = ProviderSet::new();
|
||||
p.add(Arc::new(ccc_crypto_wolfssl::WolfSslProvider::new()));
|
||||
let wolf = Arc::new(ccc_crypto_wolfssl::WolfSslProvider::new());
|
||||
p.add(wolf.clone());
|
||||
p.bind(ccc_cascade::suites::VETTED, wolf);
|
||||
p.add(Arc::new(ccc_crypto_rustcrypto::RustCryptoProvider::new()));
|
||||
p
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue