Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
codespree committed Nov 2, 2024
1 parent 664544e commit 015415d
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 215 deletions.
15 changes: 2 additions & 13 deletions src/asn1/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -88,19 +87,9 @@ impl Certificate {
///
/// `CertificateError::InvalidCertificate` will be returned if the certificate is invalid
pub fn from_der(der: &[u8]) -> Result<Certificate> {
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))
}

Expand Down
20 changes: 0 additions & 20 deletions src/kem/api/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
16 changes: 1 addition & 15 deletions src/kem/common/config/ct_len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand Down
24 changes: 5 additions & 19 deletions src/kem/common/config/oids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 2 additions & 14 deletions src/kem/common/config/pk_len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand Down
14 changes: 1 addition & 13 deletions src/kem/common/config/sk_len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 + <oid_byte>
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),
}
}
Expand Down
29 changes: 6 additions & 23 deletions src/kem/common/config/ss_len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
17 changes: 2 additions & 15 deletions src/kem/common/kem_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -64,6 +49,8 @@ pub enum KemType {
MlKem1024BrainpoolP384r1,
/// id-MLKEM1024-X448
MlKem1024X448,

/// XWing
XWing,
}

Expand Down
Loading

0 comments on commit 015415d

Please sign in to comment.