From 7a10b28f2dfe43ee1e974dfedcb77ee6d51dab34 Mon Sep 17 00:00:00 2001 From: JohnE Date: Mon, 16 Nov 2026 03:12:36 -0500 Subject: [PATCH] core: add GCM-SIV, Ascon-AEAD128, X-Wing and tiers The Rust registry becomes the single source of algorithm IDs and tiers for CCC v2 (G-8); existing IDs keep their Dart values until R10. Refs: R3-1 --- crates/ccc-crypto-core/src/algorithms.rs | 60 ++++++++++++++++++- crates/ccc-crypto-core/src/lib.rs | 2 +- crates/ccc-crypto-core/src/provider.rs | 7 +++ crates/ccc-crypto-wolfssl/src/aead.rs | 8 ++- crates/ccc-crypto-wolfssl/src/capabilities.rs | 8 ++- crates/ccc-crypto-wolfssl/src/kem.rs | 6 +- 6 files changed, 81 insertions(+), 10 deletions(-) diff --git a/crates/ccc-crypto-core/src/algorithms.rs b/crates/ccc-crypto-core/src/algorithms.rs index bc3b580..e645198 100644 --- a/crates/ccc-crypto-core/src/algorithms.rs +++ b/crates/ccc-crypto-core/src/algorithms.rs @@ -1,8 +1,9 @@ //! Algorithm enumerations for the CCC crypto system. //! -//! **Important**: every discriminant value matches the corresponding integer -//! constant in `cipher_constants.dart`. Do NOT change them without making a -//! matching change in Dart. +//! This registry is the single source of truth for algorithm IDs (G-8, R3-1). +//! The IDs that existed before CCC v2 still match `cipher_constants.dart`, +//! which today's Dart engine uses until the cutover (R10); never renumber them. +//! New IDs are added at the end of each range. use serde::{Deserialize, Serialize}; @@ -25,6 +26,21 @@ pub enum AeadAlgorithm { XChaCha20Poly1305 = 14, /// Ascon-AEAD-128a (lightweight AEAD). Dart constant `15`. Ascon128a = 15, + /// AES-256-GCM-SIV (RFC 8452), nonce-misuse resistant. + AesGcmSiv256 = 16, + /// Ascon-AEAD128 (NIST SP 800-232). + AsconAead128 = 17, +} + +/// How much an algorithm is trusted (design: "Algorithm tiers", S4). +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub enum Tier { + /// A standard AEAD from a mature implementation. Every suite needs one. + Vetted, + /// A well-studied alternative design family; allowed in any position. + Conservative, + /// Research algorithms: additive only, behind a feature, badged in the UI. + Experimental, } impl AeadAlgorithm { @@ -35,6 +51,8 @@ impl AeadAlgorithm { 13 => Some(Self::ChaCha20Poly1305), 14 => Some(Self::XChaCha20Poly1305), 15 => Some(Self::Ascon128a), + 16 => Some(Self::AesGcmSiv256), + 17 => Some(Self::AsconAead128), _ => None, } } @@ -46,6 +64,8 @@ impl AeadAlgorithm { Self::ChaCha20Poly1305 => "ChaCha20-Poly1305", Self::XChaCha20Poly1305 => "XChaCha20-Poly1305", Self::Ascon128a => "Ascon-AEAD-128a", + Self::AesGcmSiv256 => "AES-256-GCM-SIV", + Self::AsconAead128 => "Ascon-AEAD128", } } @@ -56,6 +76,8 @@ impl AeadAlgorithm { Self::ChaCha20Poly1305 => 12, Self::XChaCha20Poly1305 => 24, Self::Ascon128a => 16, + Self::AesGcmSiv256 => 12, + Self::AsconAead128 => 16, } } @@ -66,8 +88,36 @@ impl AeadAlgorithm { Self::ChaCha20Poly1305 => 32, Self::XChaCha20Poly1305 => 32, Self::Ascon128a => 16, + Self::AesGcmSiv256 => 32, + Self::AsconAead128 => 16, } } + + /// Authentication tag length in bytes (every supported AEAD uses 16). + pub fn tag_len(self) -> usize { + 16 + } + + /// The algorithm's tier. + pub fn tier(self) -> Tier { + match self { + Self::AesGcm256 + | Self::ChaCha20Poly1305 + | Self::XChaCha20Poly1305 + | Self::AesGcmSiv256 => Tier::Vetted, + Self::AsconAead128 | Self::Ascon128a => Tier::Conservative, + } + } + + /// Every AEAD ID, for capability probes and conformance tests. + pub const ALL: [AeadAlgorithm; 6] = [ + Self::AesGcm256, + Self::ChaCha20Poly1305, + Self::XChaCha20Poly1305, + Self::Ascon128a, + Self::AesGcmSiv256, + Self::AsconAead128, + ]; } // ────────────────────────────────────────────────────────────────────────────── @@ -267,6 +317,8 @@ pub enum KemAlgorithm { MlKem1024 = 53, /// Classic McEliece 460896. Dart constant `54`. ClassicMcEliece460896 = 54, + /// X-Wing hybrid KEM (ML-KEM-768 + X25519), the LGP receive and ingest key. + XWing = 55, } impl KemAlgorithm { @@ -278,6 +330,7 @@ impl KemAlgorithm { 52 => Some(Self::MlKem768), 53 => Some(Self::MlKem1024), 54 => Some(Self::ClassicMcEliece460896), + 55 => Some(Self::XWing), _ => None, } } @@ -290,6 +343,7 @@ impl KemAlgorithm { Self::MlKem768 => "ML-KEM-768", Self::MlKem1024 => "ML-KEM-1024", Self::ClassicMcEliece460896 => "Classic-McEliece-460896", + Self::XWing => "X-Wing", } } } diff --git a/crates/ccc-crypto-core/src/lib.rs b/crates/ccc-crypto-core/src/lib.rs index 6c5233c..3398858 100644 --- a/crates/ccc-crypto-core/src/lib.rs +++ b/crates/ccc-crypto-core/src/lib.rs @@ -16,7 +16,7 @@ pub mod registry; pub mod types; // Re-export everything a provider crate or the bridge crate needs. -pub use algorithms::{AeadAlgorithm, HashAlgorithm, KdfAlgorithm, KemAlgorithm, MacAlgorithm}; +pub use algorithms::{AeadAlgorithm, HashAlgorithm, KdfAlgorithm, KemAlgorithm, MacAlgorithm, Tier}; pub use capabilities::{AlgorithmCapability, ProviderCapabilities}; pub use error::CryptoError; pub use provider::{AeadProvider, CryptoProvider, HashProvider, KdfProvider, KemProvider, MacProvider}; diff --git a/crates/ccc-crypto-core/src/provider.rs b/crates/ccc-crypto-core/src/provider.rs index f475d42..ff7c9da 100644 --- a/crates/ccc-crypto-core/src/provider.rs +++ b/crates/ccc-crypto-core/src/provider.rs @@ -172,6 +172,13 @@ pub trait CryptoProvider: /// in `ccc_provider_spec.dart`. fn provider_name(&self) -> &'static str; + /// Whether this provider runs as a FIPS 140-3 validated module in FIPS + /// mode. Release policy requires the vetted layer of every suite to come + /// from such a provider (D-26). Defaults to `false`. + fn fips_mode(&self) -> bool { + false + } + /// Return the full runtime capability matrix for this provider. /// /// Called once at startup after [`CryptoProvider::self_test`] and diff --git a/crates/ccc-crypto-wolfssl/src/aead.rs b/crates/ccc-crypto-wolfssl/src/aead.rs index c4c2c25..b20881f 100644 --- a/crates/ccc-crypto-wolfssl/src/aead.rs +++ b/crates/ccc-crypto-wolfssl/src/aead.rs @@ -29,7 +29,9 @@ pub fn encrypt( AeadAlgorithm::AesGcm256 => aes_gcm_256_encrypt(key, nonce, plaintext, aad), AeadAlgorithm::ChaCha20Poly1305 => chacha20_poly1305_encrypt(key, nonce, plaintext, aad), AeadAlgorithm::XChaCha20Poly1305 => xchacha20_poly1305_encrypt(key, nonce, plaintext, aad), - AeadAlgorithm::Ascon128a => Err(CryptoError::FeatureNotCompiled("Ascon-128a".into())), + AeadAlgorithm::Ascon128a | AeadAlgorithm::AesGcmSiv256 | AeadAlgorithm::AsconAead128 => { + Err(CryptoError::FeatureNotCompiled(algo.name().into())) + } } } @@ -53,7 +55,9 @@ pub fn decrypt( AeadAlgorithm::XChaCha20Poly1305 => { xchacha20_poly1305_decrypt(key, nonce, ciphertext_and_tag, aad) } - AeadAlgorithm::Ascon128a => Err(CryptoError::FeatureNotCompiled("Ascon-128a".into())), + AeadAlgorithm::Ascon128a | AeadAlgorithm::AesGcmSiv256 | AeadAlgorithm::AsconAead128 => { + Err(CryptoError::FeatureNotCompiled(algo.name().into())) + } } } diff --git a/crates/ccc-crypto-wolfssl/src/capabilities.rs b/crates/ccc-crypto-wolfssl/src/capabilities.rs index 2b62e4e..2fb4f5b 100644 --- a/crates/ccc-crypto-wolfssl/src/capabilities.rs +++ b/crates/ccc-crypto-wolfssl/src/capabilities.rs @@ -55,7 +55,13 @@ pub fn probe_capabilities(benchmarks: Option<&BenchmarkReport>) -> ProviderCapab } // Ascon-128a is not in this wolfSSL build. - caps = caps.with_aead(AeadAlgorithm::Ascon128a, AlgorithmCapability::unavailable()); + for unavailable in [ + AeadAlgorithm::Ascon128a, + AeadAlgorithm::AesGcmSiv256, + AeadAlgorithm::AsconAead128, + ] { + caps = caps.with_aead(unavailable, AlgorithmCapability::unavailable()); + } // ── KDF ────────────────────────────────────────────────────────────────── for algo in [ diff --git a/crates/ccc-crypto-wolfssl/src/kem.rs b/crates/ccc-crypto-wolfssl/src/kem.rs index c544cef..ea4ddda 100644 --- a/crates/ccc-crypto-wolfssl/src/kem.rs +++ b/crates/ccc-crypto-wolfssl/src/kem.rs @@ -24,7 +24,7 @@ pub fn generate_keypair(algo: KemAlgorithm) -> Result { KemAlgorithm::MlKem768 | KemAlgorithm::MlKem1024 => Err(CryptoError::FeatureNotCompiled( "ML-KEM is deferred to Phase 5 (requires wolfSSL PQ build)".into(), )), - KemAlgorithm::ClassicMcEliece460896 => Err(CryptoError::FeatureNotCompiled( + KemAlgorithm::ClassicMcEliece460896 | KemAlgorithm::XWing => Err(CryptoError::FeatureNotCompiled( "Classic-McEliece is deferred to Phase 5".into(), )), } @@ -46,7 +46,7 @@ pub fn encapsulate( KemAlgorithm::MlKem768 | KemAlgorithm::MlKem1024 => Err(CryptoError::FeatureNotCompiled( "ML-KEM is deferred to Phase 5".into(), )), - KemAlgorithm::ClassicMcEliece460896 => Err(CryptoError::FeatureNotCompiled( + KemAlgorithm::ClassicMcEliece460896 | KemAlgorithm::XWing => Err(CryptoError::FeatureNotCompiled( "Classic-McEliece is deferred to Phase 5".into(), )), } @@ -65,7 +65,7 @@ pub fn decapsulate( KemAlgorithm::MlKem768 | KemAlgorithm::MlKem1024 => Err(CryptoError::FeatureNotCompiled( "ML-KEM is deferred to Phase 5".into(), )), - KemAlgorithm::ClassicMcEliece460896 => Err(CryptoError::FeatureNotCompiled( + KemAlgorithm::ClassicMcEliece460896 | KemAlgorithm::XWing => Err(CryptoError::FeatureNotCompiled( "Classic-McEliece is deferred to Phase 5".into(), )), }