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
This commit is contained in:
parent
110d33443f
commit
7a10b28f2d
|
|
@ -1,8 +1,9 @@
|
||||||
//! Algorithm enumerations for the CCC crypto system.
|
//! Algorithm enumerations for the CCC crypto system.
|
||||||
//!
|
//!
|
||||||
//! **Important**: every discriminant value matches the corresponding integer
|
//! This registry is the single source of truth for algorithm IDs (G-8, R3-1).
|
||||||
//! constant in `cipher_constants.dart`. Do NOT change them without making a
|
//! The IDs that existed before CCC v2 still match `cipher_constants.dart`,
|
||||||
//! matching change in 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};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
|
@ -25,6 +26,21 @@ pub enum AeadAlgorithm {
|
||||||
XChaCha20Poly1305 = 14,
|
XChaCha20Poly1305 = 14,
|
||||||
/// Ascon-AEAD-128a (lightweight AEAD). Dart constant `15`.
|
/// Ascon-AEAD-128a (lightweight AEAD). Dart constant `15`.
|
||||||
Ascon128a = 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 {
|
impl AeadAlgorithm {
|
||||||
|
|
@ -35,6 +51,8 @@ impl AeadAlgorithm {
|
||||||
13 => Some(Self::ChaCha20Poly1305),
|
13 => Some(Self::ChaCha20Poly1305),
|
||||||
14 => Some(Self::XChaCha20Poly1305),
|
14 => Some(Self::XChaCha20Poly1305),
|
||||||
15 => Some(Self::Ascon128a),
|
15 => Some(Self::Ascon128a),
|
||||||
|
16 => Some(Self::AesGcmSiv256),
|
||||||
|
17 => Some(Self::AsconAead128),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -46,6 +64,8 @@ impl AeadAlgorithm {
|
||||||
Self::ChaCha20Poly1305 => "ChaCha20-Poly1305",
|
Self::ChaCha20Poly1305 => "ChaCha20-Poly1305",
|
||||||
Self::XChaCha20Poly1305 => "XChaCha20-Poly1305",
|
Self::XChaCha20Poly1305 => "XChaCha20-Poly1305",
|
||||||
Self::Ascon128a => "Ascon-AEAD-128a",
|
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::ChaCha20Poly1305 => 12,
|
||||||
Self::XChaCha20Poly1305 => 24,
|
Self::XChaCha20Poly1305 => 24,
|
||||||
Self::Ascon128a => 16,
|
Self::Ascon128a => 16,
|
||||||
|
Self::AesGcmSiv256 => 12,
|
||||||
|
Self::AsconAead128 => 16,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,8 +88,36 @@ impl AeadAlgorithm {
|
||||||
Self::ChaCha20Poly1305 => 32,
|
Self::ChaCha20Poly1305 => 32,
|
||||||
Self::XChaCha20Poly1305 => 32,
|
Self::XChaCha20Poly1305 => 32,
|
||||||
Self::Ascon128a => 16,
|
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,
|
MlKem1024 = 53,
|
||||||
/// Classic McEliece 460896. Dart constant `54`.
|
/// Classic McEliece 460896. Dart constant `54`.
|
||||||
ClassicMcEliece460896 = 54,
|
ClassicMcEliece460896 = 54,
|
||||||
|
/// X-Wing hybrid KEM (ML-KEM-768 + X25519), the LGP receive and ingest key.
|
||||||
|
XWing = 55,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KemAlgorithm {
|
impl KemAlgorithm {
|
||||||
|
|
@ -278,6 +330,7 @@ impl KemAlgorithm {
|
||||||
52 => Some(Self::MlKem768),
|
52 => Some(Self::MlKem768),
|
||||||
53 => Some(Self::MlKem1024),
|
53 => Some(Self::MlKem1024),
|
||||||
54 => Some(Self::ClassicMcEliece460896),
|
54 => Some(Self::ClassicMcEliece460896),
|
||||||
|
55 => Some(Self::XWing),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -290,6 +343,7 @@ impl KemAlgorithm {
|
||||||
Self::MlKem768 => "ML-KEM-768",
|
Self::MlKem768 => "ML-KEM-768",
|
||||||
Self::MlKem1024 => "ML-KEM-1024",
|
Self::MlKem1024 => "ML-KEM-1024",
|
||||||
Self::ClassicMcEliece460896 => "Classic-McEliece-460896",
|
Self::ClassicMcEliece460896 => "Classic-McEliece-460896",
|
||||||
|
Self::XWing => "X-Wing",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ pub mod registry;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
// Re-export everything a provider crate or the bridge crate needs.
|
// 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 capabilities::{AlgorithmCapability, ProviderCapabilities};
|
||||||
pub use error::CryptoError;
|
pub use error::CryptoError;
|
||||||
pub use provider::{AeadProvider, CryptoProvider, HashProvider, KdfProvider, KemProvider, MacProvider};
|
pub use provider::{AeadProvider, CryptoProvider, HashProvider, KdfProvider, KemProvider, MacProvider};
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,13 @@ pub trait CryptoProvider:
|
||||||
/// in `ccc_provider_spec.dart`.
|
/// in `ccc_provider_spec.dart`.
|
||||||
fn provider_name(&self) -> &'static str;
|
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.
|
/// Return the full runtime capability matrix for this provider.
|
||||||
///
|
///
|
||||||
/// Called once at startup after [`CryptoProvider::self_test`] and
|
/// Called once at startup after [`CryptoProvider::self_test`] and
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,9 @@ pub fn encrypt(
|
||||||
AeadAlgorithm::AesGcm256 => aes_gcm_256_encrypt(key, nonce, plaintext, aad),
|
AeadAlgorithm::AesGcm256 => aes_gcm_256_encrypt(key, nonce, plaintext, aad),
|
||||||
AeadAlgorithm::ChaCha20Poly1305 => chacha20_poly1305_encrypt(key, nonce, plaintext, aad),
|
AeadAlgorithm::ChaCha20Poly1305 => chacha20_poly1305_encrypt(key, nonce, plaintext, aad),
|
||||||
AeadAlgorithm::XChaCha20Poly1305 => xchacha20_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 => {
|
AeadAlgorithm::XChaCha20Poly1305 => {
|
||||||
xchacha20_poly1305_decrypt(key, nonce, ciphertext_and_tag, aad)
|
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()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,13 @@ pub fn probe_capabilities(benchmarks: Option<&BenchmarkReport>) -> ProviderCapab
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ascon-128a is not in this wolfSSL build.
|
// 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 ──────────────────────────────────────────────────────────────────
|
// ── KDF ──────────────────────────────────────────────────────────────────
|
||||||
for algo in [
|
for algo in [
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ pub fn generate_keypair(algo: KemAlgorithm) -> Result<KemKeyPair, CryptoError> {
|
||||||
KemAlgorithm::MlKem768 | KemAlgorithm::MlKem1024 => Err(CryptoError::FeatureNotCompiled(
|
KemAlgorithm::MlKem768 | KemAlgorithm::MlKem1024 => Err(CryptoError::FeatureNotCompiled(
|
||||||
"ML-KEM is deferred to Phase 5 (requires wolfSSL PQ build)".into(),
|
"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(),
|
"Classic-McEliece is deferred to Phase 5".into(),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
|
|
@ -46,7 +46,7 @@ pub fn encapsulate(
|
||||||
KemAlgorithm::MlKem768 | KemAlgorithm::MlKem1024 => Err(CryptoError::FeatureNotCompiled(
|
KemAlgorithm::MlKem768 | KemAlgorithm::MlKem1024 => Err(CryptoError::FeatureNotCompiled(
|
||||||
"ML-KEM is deferred to Phase 5".into(),
|
"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(),
|
"Classic-McEliece is deferred to Phase 5".into(),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
|
|
@ -65,7 +65,7 @@ pub fn decapsulate(
|
||||||
KemAlgorithm::MlKem768 | KemAlgorithm::MlKem1024 => Err(CryptoError::FeatureNotCompiled(
|
KemAlgorithm::MlKem768 | KemAlgorithm::MlKem1024 => Err(CryptoError::FeatureNotCompiled(
|
||||||
"ML-KEM is deferred to Phase 5".into(),
|
"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(),
|
"Classic-McEliece is deferred to Phase 5".into(),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue