diff --git a/src/asn1/certificate.rs b/src/asn1/certificate.rs index b312f53..34e673c 100644 --- a/src/asn1/certificate.rs +++ b/src/asn1/certificate.rs @@ -9,7 +9,6 @@ use crate::{ use chrono::{DateTime, Utc}; use cms::enveloped_data::RecipientIdentifier; use der::{Decode, DecodePem, Encode, EncodePem}; -use spki::ObjectIdentifier; use x509_cert::{ ext::pkix::{AuthorityKeyIdentifier, KeyUsage, SubjectKeyIdentifier}, name::RdnSequence, @@ -88,19 +87,9 @@ impl Certificate { /// /// `CertificateError::InvalidCertificate` will be returned if the certificate is invalid pub fn from_der(der: &[u8]) -> Result { - let mut cert = x509_cert::Certificate::from_der(der) + let cert = x509_cert::Certificate::from_der(der) .map_err(|_| QuantCryptError::InvalidCertificate)?; - // Map old OIDs to new OIDs - let original_oid = cert - .tbs_certificate - .subject_public_key_info - .algorithm - .oid - .to_string(); - let new_oid: ObjectIdentifier = original_oid - .parse() - .map_err(|_| QuantCryptError::InvalidCertificate)?; - cert.tbs_certificate.subject_public_key_info.algorithm.oid = new_oid; + Ok(Certificate::new(cert)) } diff --git a/src/kem/api/algorithm.rs b/src/kem/api/algorithm.rs index f425016..cc94e82 100644 --- a/src/kem/api/algorithm.rs +++ b/src/kem/api/algorithm.rs @@ -10,16 +10,6 @@ pub enum KemAlgorithm { MlKem768, MlKem1024, - // The composite algorithm list from the old version - MlKem512P256, - MlKem512BrainpoolP256r1, - MlKem512X25519, - MlKem512Rsa2048, - MlKem512Rsa3072, - MlKem768P256, - - // The compsite algorithm list is from the latest editor's draft: - //https://lamps-wg.github.io/draft-composite-kem/draft-ietf-lamps-pq-composite-kem.html MlKem768Rsa2048, MlKem768Rsa3072, MlKem768Rsa4096, @@ -45,16 +35,6 @@ impl KemAlgorithm { KemAlgorithm::MlKem768 => KemType::MlKem768, KemAlgorithm::MlKem1024 => KemType::MlKem1024, - // The composite algorithm list from the old version - KemAlgorithm::MlKem512P256 => KemType::MlKem512P256, - KemAlgorithm::MlKem512BrainpoolP256r1 => KemType::MlKem512BrainpoolP256r1, - KemAlgorithm::MlKem512X25519 => KemType::MlKem512X25519, - KemAlgorithm::MlKem512Rsa2048 => KemType::MlKem512Rsa2048, - KemAlgorithm::MlKem512Rsa3072 => KemType::MlKem512Rsa3072, - KemAlgorithm::MlKem768P256 => KemType::MlKem768P256, - - // The compsite algorithm list is from the latest editor's draft: - //https://lamps-wg.github.io/draft-composite-kem/draft-ietf-lamps-pq-composite-kem.html KemAlgorithm::MlKem768Rsa2048 => KemType::MlKem768Rsa2048, KemAlgorithm::MlKem768Rsa3072 => KemType::MlKem768Rsa3072, KemAlgorithm::MlKem768Rsa4096 => KemType::MlKem768Rsa4096, diff --git a/src/kem/common/config/ct_len.rs b/src/kem/common/config/ct_len.rs index 17a26c0..a81c4c4 100644 --- a/src/kem/common/config/ct_len.rs +++ b/src/kem/common/config/ct_len.rs @@ -27,31 +27,17 @@ impl CTLen for KemType { KemType::MlKem512 => Some(768), KemType::MlKem768 => Some(1088), KemType::MlKem1024 => Some(1568), - // Old version + // KEM CT + Trad CT + ASN.1 overhead - KemType::MlKem512P256 => Some(768 + 65 + 10), - KemType::MlKem512BrainpoolP256r1 => Some(768 + 65 + 10), - KemType::MlKem512X25519 => Some(768 + 32 + 10), - KemType::MlKem512Rsa2048 => Some(768 + 256 + 12), - KemType::MlKem512Rsa3072 => Some(768 + 384 + 12), - KemType::MlKem768P256 => Some(1088 + 65 + 10), KemType::MlKem768BrainpoolP256r1 => Some(1088 + 65 + 10), KemType::MlKem768X25519 => Some(1088 + 32 + 10), KemType::MlKem1024P384 => Some(1568 + 97 + 10), KemType::MlKem1024BrainpoolP384r1 => Some(1568 + 97 + 10), KemType::MlKem1024X448 => Some(1568 + 56 + 10), - - // Composite types from editor's draft. Skipped ones are also present in old version - // Editor's copy KemType::MlKem768Rsa2048 => Some(1088 + 256 + 12), KemType::MlKem768Rsa3072 => Some(1088 + 384 + 12), KemType::MlKem768Rsa4096 => Some(1088 + 512 + 12), - // KemType::MlKem768X25519 => Some(1088 + 32 + 10), KemType::MlKem768P384 => Some(1088 + 97 + 10), - // KemType::MlKem768BrainpoolP256r1 => Some(1088 + 65 + 10), - // KemType::MlKem1024P384 => Some(1568 + 97 + 10), - // KemType::MlKem1024BrainpoolP384r1 => Some(1568 + 97 + 10), - // KemType::MlKem1024X448 => Some(1568 + 56 + 10), KemType::XWing => Some(1120), } } diff --git a/src/kem/common/config/oids.rs b/src/kem/common/config/oids.rs index f8acba2..9c688f8 100644 --- a/src/kem/common/config/oids.rs +++ b/src/kem/common/config/oids.rs @@ -18,29 +18,15 @@ impl Oid for KemType { /// The OID for the KEM fn get_oid(&self) -> String { match self { - // Composite types from old version: - KemType::MlKem512P256 => "2.16.840.1.114027.80.5.2.1", - KemType::MlKem512BrainpoolP256r1 => "2.16.840.1.114027.80.5.2.2", - KemType::MlKem512X25519 => "2.16.840.1.114027.80.5.2.3", - KemType::MlKem512Rsa2048 => "2.16.840.1.114027.80.5.2.13", - KemType::MlKem512Rsa3072 => "2.16.840.1.114027.80.5.2.4", - KemType::MlKem768P256 => "2.16.840.1.114027.80.5.2.5", - KemType::MlKem768BrainpoolP256r1 => "2.16.840.1.114027.80.5.2.6", - KemType::MlKem768X25519 => "2.16.840.1.114027.80.5.2.7", - KemType::MlKem1024P384 => "2.16.840.1.114027.80.5.2.8", - KemType::MlKem1024BrainpoolP384r1 => "2.16.840.1.114027.80.5.2.9", - KemType::MlKem1024X448 => "2.16.840.1.114027.80.5.2.10", - - // Composite types from editor's copy, skipped ones are also in old version: KemType::MlKem768Rsa2048 => "2.16.840.1.114027.80.5.2.21", KemType::MlKem768Rsa3072 => "2.16.840.1.114027.80.5.2.22", KemType::MlKem768Rsa4096 => "2.16.840.1.114027.80.5.2.23", - // KemType::MlKem768X25519 => "2.16.840.1.114027.80.5.2.24", + KemType::MlKem768X25519 => "2.16.840.1.114027.80.5.2.24", KemType::MlKem768P384 => "2.16.840.1.114027.80.5.2.25", - // KemType::MlKem768BrainpoolP256r1 => "2.16.840.1.114027.80.5.2.26", - // KemType::MlKem1024P384 => "2.16.840.1.114027.80.5.2.27", - // KemType::MlKem1024BrainpoolP384r1 => "2.16.840.1.114027.80.5.2.28", - // KemType::MlKem1024X448 => "2.16.840.1.114027.80.5.2.29", + KemType::MlKem768BrainpoolP256r1 => "2.16.840.1.114027.80.5.2.26", + KemType::MlKem1024P384 => "2.16.840.1.114027.80.5.2.27", + KemType::MlKem1024BrainpoolP384r1 => "2.16.840.1.114027.80.5.2.28", + KemType::MlKem1024X448 => "2.16.840.1.114027.80.5.2.29", // EC Types: KemType::P256 => "1.2.840.10045.3.1.7", diff --git a/src/kem/common/config/pk_len.rs b/src/kem/common/config/pk_len.rs index 4219c03..7b0ea3d 100644 --- a/src/kem/common/config/pk_len.rs +++ b/src/kem/common/config/pk_len.rs @@ -29,30 +29,18 @@ impl PKLen for KemType { KemType::RsaOAEP2048 => Some(270), KemType::RsaOAEP3072 => Some(398), KemType::RsaOAEP4096 => Some(526), - // Composite types from old version + // KEM Pk + Trad Pk + ASN.1 overhead - KemType::MlKem512P256 => Some(800 + 65 + 12), - KemType::MlKem512BrainpoolP256r1 => Some(800 + 65 + 12), - KemType::MlKem512X25519 => Some(800 + 32 + 12), - KemType::MlKem512Rsa2048 => Some(800 + 270 + 14), - KemType::MlKem512Rsa3072 => Some(800 + 398 + 14), - KemType::MlKem768P256 => Some(1184 + 65 + 12), KemType::MlKem768BrainpoolP256r1 => Some(1184 + 65 + 12), KemType::MlKem768X25519 => Some(1184 + 32 + 12), KemType::MlKem1024P384 => Some(1568 + 97 + 12), KemType::MlKem1024BrainpoolP384r1 => Some(1568 + 97 + 12), KemType::MlKem1024X448 => Some(1568 + 56 + 12), - // Composite types from editor's draft. Skipped ones are also present in old version - // KEM Pk + Trad Pk + ASN.1 overhead KemType::MlKem768Rsa2048 => Some(1184 + 270 + 14), KemType::MlKem768Rsa3072 => Some(1184 + 398 + 14), KemType::MlKem768Rsa4096 => Some(1184 + 526 + 14), - // KemType::MlKem768X25519 => Some(1184 + 32 + 12), KemType::MlKem768P384 => Some(1184 + 97 + 12), - // KemType::MlKem768BrainpoolP256r1 => Some(1184 + 65 + 12), - // KemType::MlKem1024P384 => Some(1568 + 97 + 12), - // KemType::MlKem1024BrainpoolP384r1 => Some(1568 + 97 + 12), - // KemType::MlKem1024X448 => Some(1568 + 56 + 12), + KemType::XWing => Some(1216), } } diff --git a/src/kem/common/config/sk_len.rs b/src/kem/common/config/sk_len.rs index a0e7481..ffdc067 100644 --- a/src/kem/common/config/sk_len.rs +++ b/src/kem/common/config/sk_len.rs @@ -35,31 +35,19 @@ impl SKLen for KemType { KemType::RsaOAEP2048 => None, KemType::RsaOAEP3072 => None, KemType::RsaOAEP4096 => None, - // Composite types from old version + // In Kem composites, traditional public key is part of the private key // pq_sk + trad_sk + pq_overhead + trad_public_key_overhead + trad_overhead + sequence_overhead // trad_overhead = 9 + - KemType::MlKem512P256 => Some(1632 + 32 + 24 + (65 + 6) + 19 + 4), - KemType::MlKem512BrainpoolP256r1 => Some(1632 + 32 + 24 + (65 + 6) + 19 + 4), - KemType::MlKem512X25519 => Some(1632 + 32 + 24 + (32 + 11) + 14 + 4), - KemType::MlKem512Rsa2048 => None, - KemType::MlKem512Rsa3072 => None, - KemType::MlKem768P256 => Some(2400 + 32 + 24 + (65 + 6) + 19 + 4), KemType::MlKem768BrainpoolP256r1 => Some(2400 + 32 + 24 + (65 + 6) + 19 + 4), KemType::MlKem768X25519 => Some(2400 + 32 + 24 + (32 + 11) + 14 + 4), KemType::MlKem1024P384 => Some(3168 + 48 + 24 + (97 + 10) + 16 + 4), KemType::MlKem1024BrainpoolP384r1 => Some(3168 + 48 + 24 + (97 + 7) + 19 + 4), KemType::MlKem1024X448 => Some(3168 + 56 + 24 + (56 + 12) + 14 + 4), - // Composite types from editor's draft. Skipped ones are also present in old version KemType::MlKem768Rsa2048 => None, KemType::MlKem768Rsa3072 => None, KemType::MlKem768Rsa4096 => None, - // KemType::MlKem768X25519 => Some(2400 + 32 + 24 + (32 + 6) + 19 + 4), KemType::MlKem768P384 => Some(2400 + 48 + 24 + (97 + 10) + 16 + 4), - // KemType::MlKem768BrainpoolP256r1 => Some(2400 + 32 + 118), - // KemType::MlKem1024P384 => Some(3168 + 48 + 151), - // KemType::MlKem1024BrainpoolP384r1 => Some(3168 + 48 + 151), - // KemType::MlKem1024X448 => Some(3168 + 56 + 110), KemType::XWing => Some(32), } } diff --git a/src/kem/common/config/ss_len.rs b/src/kem/common/config/ss_len.rs index 759c4f2..f3eb7d7 100644 --- a/src/kem/common/config/ss_len.rs +++ b/src/kem/common/config/ss_len.rs @@ -37,32 +37,15 @@ impl SSLen for KemType { KemType::MlKem1024 => 32, // Composite types follow hash size - // Old version - KemType::MlKem512P256 => 32, - KemType::MlKem512BrainpoolP256r1 => 32, - KemType::MlKem512X25519 => 32, - KemType::MlKem512Rsa2048 => 32, - KemType::MlKem512Rsa3072 => 32, - KemType::MlKem768P256 => 48, - KemType::MlKem768BrainpoolP256r1 => 48, - // Should be 48 given SHA3-384 in the public version. In the editor's copy it's SHA-256 and thus 32. Follow the public version here. - // Public Copy Reference: https://datatracker.ietf.org/doc/draft-ietf-lamps-pq-composite-kem/ - KemType::MlKem768X25519 => 48, - KemType::MlKem1024P384 => 64, - KemType::MlKem1024BrainpoolP384r1 => 64, - KemType::MlKem1024X448 => 64, - - // Composite types from editor's draft. Skipped ones are also present in old version - // Editor's copy + KemType::MlKem768BrainpoolP256r1 => 32, + KemType::MlKem768X25519 => 32, + KemType::MlKem1024P384 => 32, + KemType::MlKem1024BrainpoolP384r1 => 32, + KemType::MlKem1024X448 => 32, KemType::MlKem768Rsa2048 => 32, KemType::MlKem768Rsa3072 => 32, KemType::MlKem768Rsa4096 => 32, - // KemType::MlKem768X25519 => 32, - KemType::MlKem768P384 => 48, - // KemType::MlKem768BrainpoolP256r1 => 48, - // KemType::MlKem1024P384 => 64, - // KemType::MlKem1024BrainpoolP384r1 => 64, - // KemType::MlKem1024X448 => 64, + KemType::MlKem768P384 => 32, KemType::XWing => 32, } } diff --git a/src/kem/common/kem_type.rs b/src/kem/common/kem_type.rs index 1c6bac7..cdac775 100644 --- a/src/kem/common/kem_type.rs +++ b/src/kem/common/kem_type.rs @@ -30,22 +30,7 @@ pub enum KemType { /// MlKem1024 key encapsulation mechanism MlKem1024, - // The composite algorithm list from the old version - /// id-MLKEM512-ECDH-P256 - MlKem512P256, - /// id-MLKEM512-ECDH-brainpoolP256r1 - MlKem512BrainpoolP256r1, - /// id-MLKEM512-X25519 - MlKem512X25519, - /// id-MLKEM512-RSA2048 - MlKem512Rsa2048, - /// id-MLKEM512-RSA3072 - MlKem512Rsa3072, - /// id-MLKEM768-ECDH-P256 - MlKem768P256, - // The compsite algorithm list is from the latest editor's draft: - //https://lamps-wg.github.io/draft-composite-kem/draft-ietf-lamps-pq-composite-kem.html /// id-MLKEM768-RSA2048 MlKem768Rsa2048, /// id-MLKEM768-RSA3072 @@ -64,6 +49,8 @@ pub enum KemType { MlKem1024BrainpoolP384r1, /// id-MLKEM1024-X448 MlKem1024X448, + + /// XWing XWing, } diff --git a/src/kem/composite_kem.rs b/src/kem/composite_kem.rs index e0bd329..e8d0d3f 100644 --- a/src/kem/composite_kem.rs +++ b/src/kem/composite_kem.rs @@ -151,45 +151,6 @@ impl Kem for CompositeKemManager { fn new(kem_type: KemType) -> Result { let kem_info = KemInfo::new(kem_type.clone()); let result = match kem_type { - // From old version - KemType::MlKem512P256 => Self { - kem_info, - trad_kem: Box::new(KemManager::new(KemType::P256)?), - pq_kem: Box::new(KemManager::new(KemType::MlKem512)?), - kdf: Kdf::new(KdfType::Sha3_256), - }, - KemType::MlKem512BrainpoolP256r1 => Self { - kem_info, - trad_kem: Box::new(KemManager::new(KemType::BrainpoolP256r1)?), - pq_kem: Box::new(KemManager::new(KemType::MlKem512)?), - kdf: Kdf::new(KdfType::Sha3_256), - }, - KemType::MlKem512X25519 => Self { - kem_info, - trad_kem: Box::new(KemManager::new(KemType::X25519)?), - pq_kem: Box::new(KemManager::new(KemType::MlKem512)?), - kdf: Kdf::new(KdfType::Sha3_256), - }, - KemType::MlKem512Rsa2048 => Self { - kem_info, - trad_kem: Box::new(KemManager::new(KemType::RsaOAEP2048)?), - pq_kem: Box::new(KemManager::new(KemType::MlKem512)?), - kdf: Kdf::new(KdfType::Sha3_256), - }, - KemType::MlKem512Rsa3072 => Self { - kem_info, - trad_kem: Box::new(KemManager::new(KemType::RsaOAEP3072)?), - pq_kem: Box::new(KemManager::new(KemType::MlKem512)?), - kdf: Kdf::new(KdfType::Sha3_256), - }, - KemType::MlKem768P256 => Self { - kem_info, - trad_kem: Box::new(KemManager::new(KemType::P256)?), - pq_kem: Box::new(KemManager::new(KemType::MlKem768)?), - kdf: Kdf::new(KdfType::Sha3_384), - }, - - // From Editor's draft KemType::MlKem768Rsa2048 => Self { kem_info, trad_kem: Box::new(KemManager::new(KemType::RsaOAEP2048)?), @@ -212,38 +173,37 @@ impl Kem for CompositeKemManager { kem_info, trad_kem: Box::new(KemManager::new(KemType::X25519)?), pq_kem: Box::new(KemManager::new(KemType::MlKem768)?), - kdf: Kdf::new(KdfType::Sha3_384), - // kdf: Kdf::new(KdfType::Sha3_256), //In editor's draft + kdf: Kdf::new(KdfType::Sha3_256), }, KemType::MlKem768P384 => Self { kem_info, trad_kem: Box::new(KemManager::new(KemType::P384)?), pq_kem: Box::new(KemManager::new(KemType::MlKem768)?), - kdf: Kdf::new(KdfType::HkdfSha384), + kdf: Kdf::new(KdfType::HkdfSha256), }, KemType::MlKem768BrainpoolP256r1 => Self { kem_info, trad_kem: Box::new(KemManager::new(KemType::BrainpoolP256r1)?), pq_kem: Box::new(KemManager::new(KemType::MlKem768)?), - kdf: Kdf::new(KdfType::HkdfSha384), + kdf: Kdf::new(KdfType::HkdfSha256), }, KemType::MlKem1024P384 => Self { kem_info, trad_kem: Box::new(KemManager::new(KemType::P384)?), pq_kem: Box::new(KemManager::new(KemType::MlKem1024)?), - kdf: Kdf::new(KdfType::Sha3_512), + kdf: Kdf::new(KdfType::Sha3_256), }, KemType::MlKem1024BrainpoolP384r1 => Self { kem_info, trad_kem: Box::new(KemManager::new(KemType::BrainpoolP384r1)?), pq_kem: Box::new(KemManager::new(KemType::MlKem1024)?), - kdf: Kdf::new(KdfType::Sha3_512), + kdf: Kdf::new(KdfType::Sha3_256), }, KemType::MlKem1024X448 => Self { kem_info, trad_kem: Box::new(KemManager::new(KemType::X448)?), pq_kem: Box::new(KemManager::new(KemType::MlKem1024)?), - kdf: Kdf::new(KdfType::Sha3_512), + kdf: Kdf::new(KdfType::Sha3_256), }, _ => { return Err(QuantCryptError::NotImplemented); @@ -391,44 +351,7 @@ impl Kem for CompositeKemManager { mod tests { use super::*; use crate::kem::common::macros::test_kem; - // Tests for old version - #[test] - fn test_mlkem_512_p256() { - let kem = CompositeKemManager::new(KemType::MlKem512P256); - test_kem!(kem); - } - - #[test] - fn test_mlkem_512_brainpool_p256_r1() { - let kem = CompositeKemManager::new(KemType::MlKem512BrainpoolP256r1); - test_kem!(kem); - } - - #[test] - fn test_mlkem_512_x25519() { - let kem = CompositeKemManager::new(KemType::MlKem512X25519); - test_kem!(kem); - } - - #[test] - fn test_mlkem_512_rsa2048() { - let kem = CompositeKemManager::new(KemType::MlKem512Rsa2048); - test_kem!(kem); - } - - #[test] - fn test_mlkem_512_rsa3072() { - let kem = CompositeKemManager::new(KemType::MlKem512Rsa3072); - test_kem!(kem); - } - - #[test] - fn test_mlkem_768_p256() { - let kem = CompositeKemManager::new(KemType::MlKem768P256); - test_kem!(kem); - } - // Tests for editor's copy #[test] fn test_mlkem_768_rsa2048() { let kem = CompositeKemManager::new(KemType::MlKem768Rsa2048);