Skip to content

Commit

Permalink
Moves SLH to prehash dsa types
Browse files Browse the repository at this point in the history
  • Loading branch information
codespree committed Nov 4, 2024
1 parent 80dcd5c commit d473b19
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 193 deletions.
30 changes: 14 additions & 16 deletions src/dsa/api/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,7 @@ impl DsaAlgorithm {

/// Get the corresponding `DsaType` for the algorithm
pub(crate) fn get_dsa_type(&self) -> Option<DsaType> {
match self {
DsaAlgorithm::SlhDsaSha2_128s => Some(DsaType::SlhDsaSha2_128s),
DsaAlgorithm::SlhDsaSha2_128f => Some(DsaType::SlhDsaSha2_128f),
DsaAlgorithm::SlhDsaSha2_192s => Some(DsaType::SlhDsaSha2_192s),
DsaAlgorithm::SlhDsaSha2_192f => Some(DsaType::SlhDsaSha2_192f),
DsaAlgorithm::SlhDsaSha2_256s => Some(DsaType::SlhDsaSha2_256s),
DsaAlgorithm::SlhDsaSha2_256f => Some(DsaType::SlhDsaSha2_256f),
DsaAlgorithm::SlhDsaShake128s => Some(DsaType::SlhDsaShake128s),
DsaAlgorithm::SlhDsaShake128f => Some(DsaType::SlhDsaShake128f),
DsaAlgorithm::SlhDsaShake192s => Some(DsaType::SlhDsaShake192s),
DsaAlgorithm::SlhDsaShake192f => Some(DsaType::SlhDsaShake192f),
DsaAlgorithm::SlhDsaShake256s => Some(DsaType::SlhDsaShake256s),
DsaAlgorithm::SlhDsaShake256f => Some(DsaType::SlhDsaShake256f),
_ => None,
}
None
}

/// Get the corresponding `PrehashDsaType` for the algorithm
Expand Down Expand Up @@ -162,7 +148,19 @@ impl DsaAlgorithm {
Some(PrehashDsaType::HashMlDsa87EcdsaBrainpoolP384r1Sha512)
}
DsaAlgorithm::HashMlDsa87Ed448Sha512 => Some(PrehashDsaType::HashMlDsa87Ed448Sha512),
_ => None,

DsaAlgorithm::SlhDsaSha2_128s => Some(PrehashDsaType::SlhDsaSha2_128s),
DsaAlgorithm::SlhDsaSha2_128f => Some(PrehashDsaType::SlhDsaSha2_128f),
DsaAlgorithm::SlhDsaSha2_192s => Some(PrehashDsaType::SlhDsaSha2_192s),
DsaAlgorithm::SlhDsaSha2_192f => Some(PrehashDsaType::SlhDsaSha2_192f),
DsaAlgorithm::SlhDsaSha2_256s => Some(PrehashDsaType::SlhDsaSha2_256s),
DsaAlgorithm::SlhDsaSha2_256f => Some(PrehashDsaType::SlhDsaSha2_256f),
DsaAlgorithm::SlhDsaShake128s => Some(PrehashDsaType::SlhDsaShake128s),
DsaAlgorithm::SlhDsaShake128f => Some(PrehashDsaType::SlhDsaShake128f),
DsaAlgorithm::SlhDsaShake192s => Some(PrehashDsaType::SlhDsaShake192s),
DsaAlgorithm::SlhDsaShake192f => Some(PrehashDsaType::SlhDsaShake192f),
DsaAlgorithm::SlhDsaShake256s => Some(PrehashDsaType::SlhDsaShake256s),
DsaAlgorithm::SlhDsaShake256f => Some(PrehashDsaType::SlhDsaShake256f),
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/dsa/common/config/hash_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ impl HashTypeConfig for PrehashDsaType {
PrehashDsaType::HashMlDsa87EcdsaP384Sha512 => Some(HashType::Sha512),
PrehashDsaType::HashMlDsa87EcdsaBrainpoolP384r1Sha512 => Some(HashType::Sha512),
PrehashDsaType::HashMlDsa87Ed448Sha512 => Some(HashType::Sha512),

PrehashDsaType::SlhDsaSha2_128s => None,
PrehashDsaType::SlhDsaSha2_128f => None,
PrehashDsaType::SlhDsaSha2_192s => None,
PrehashDsaType::SlhDsaSha2_192f => None,
PrehashDsaType::SlhDsaSha2_256s => None,
PrehashDsaType::SlhDsaSha2_256f => None,
PrehashDsaType::SlhDsaShake128s => None,
PrehashDsaType::SlhDsaShake128f => None,
PrehashDsaType::SlhDsaShake192s => None,
PrehashDsaType::SlhDsaShake192f => None,
PrehashDsaType::SlhDsaShake256s => None,
PrehashDsaType::SlhDsaShake256f => None,
}
}
}
26 changes: 13 additions & 13 deletions src/dsa/common/config/oids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@ impl Oid for DsaType {
DsaType::EcdsaP384SHA384 | DsaType::EcdsaBrainpoolP384r1SHA384 => "1.2.840.10045.4.3.3",
DsaType::Ed25519 => "1.3.101.112",
DsaType::Ed448 => "1.3.101.113",

DsaType::SlhDsaSha2_128s => "2.16.840.1.101.3.4.3.20",
DsaType::SlhDsaSha2_128f => "2.16.840.1.101.3.4.3.21",
DsaType::SlhDsaSha2_192s => "2.16.840.1.101.3.4.3.22",
DsaType::SlhDsaSha2_192f => "2.16.840.1.101.3.4.3.23",
DsaType::SlhDsaSha2_256s => "2.16.840.1.101.3.4.3.24",
DsaType::SlhDsaSha2_256f => "2.16.840.1.101.3.4.3.25",
DsaType::SlhDsaShake128s => "2.16.840.1.101.3.4.3.26",
DsaType::SlhDsaShake128f => "2.16.840.1.101.3.4.3.27",
DsaType::SlhDsaShake192s => "2.16.840.1.101.3.4.3.28",
DsaType::SlhDsaShake192f => "2.16.840.1.101.3.4.3.29",
DsaType::SlhDsaShake256s => "2.16.840.1.101.3.4.3.30",
DsaType::SlhDsaShake256f => "2.16.840.1.101.3.4.3.31",
}
.to_string()
}
Expand Down Expand Up @@ -100,6 +87,19 @@ impl Oid for PrehashDsaType {
PrehashDsaType::HashMlDsa87EcdsaP384Sha512 => "2.16.840.1.114027.80.8.1.51",
PrehashDsaType::HashMlDsa87EcdsaBrainpoolP384r1Sha512 => "2.16.840.1.114027.80.8.1.52",
PrehashDsaType::HashMlDsa87Ed448Sha512 => "2.16.840.1.114027.80.8.1.53",

PrehashDsaType::SlhDsaSha2_128s => "2.16.840.1.101.3.4.3.20",
PrehashDsaType::SlhDsaSha2_128f => "2.16.840.1.101.3.4.3.21",
PrehashDsaType::SlhDsaSha2_192s => "2.16.840.1.101.3.4.3.22",
PrehashDsaType::SlhDsaSha2_192f => "2.16.840.1.101.3.4.3.23",
PrehashDsaType::SlhDsaSha2_256s => "2.16.840.1.101.3.4.3.24",
PrehashDsaType::SlhDsaSha2_256f => "2.16.840.1.101.3.4.3.25",
PrehashDsaType::SlhDsaShake128s => "2.16.840.1.101.3.4.3.26",
PrehashDsaType::SlhDsaShake128f => "2.16.840.1.101.3.4.3.27",
PrehashDsaType::SlhDsaShake192s => "2.16.840.1.101.3.4.3.28",
PrehashDsaType::SlhDsaShake192f => "2.16.840.1.101.3.4.3.29",
PrehashDsaType::SlhDsaShake256s => "2.16.840.1.101.3.4.3.30",
PrehashDsaType::SlhDsaShake256f => "2.16.840.1.101.3.4.3.31",
}
.to_string()
}
Expand Down
26 changes: 13 additions & 13 deletions src/dsa/common/config/pk_len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,6 @@ impl PKLen for DsaType {
DsaType::EcdsaP256SHA256 => Some(65),
DsaType::EcdsaBrainpoolP256r1SHA256 => Some(65),

DsaType::SlhDsaSha2_128s => Some(32),
DsaType::SlhDsaSha2_128f => Some(32),
DsaType::SlhDsaSha2_192s => Some(48),
DsaType::SlhDsaSha2_192f => Some(48),
DsaType::SlhDsaSha2_256s => Some(64),
DsaType::SlhDsaSha2_256f => Some(64),
DsaType::SlhDsaShake128s => Some(32),
DsaType::SlhDsaShake128f => Some(32),
DsaType::SlhDsaShake192s => Some(48),
DsaType::SlhDsaShake192f => Some(48),
DsaType::SlhDsaShake256s => Some(64),
DsaType::SlhDsaShake256f => Some(64),

DsaType::EcdsaP384SHA384 => Some(97),
DsaType::EcdsaBrainpoolP384r1SHA384 => Some(97),
DsaType::Ed25519 => Some(32),
Expand Down Expand Up @@ -91,6 +78,19 @@ impl PKLen for PrehashDsaType {
PrehashDsaType::HashMlDsa87EcdsaP384Sha512 => Some(2592 + 97 + 12), // 2701
PrehashDsaType::HashMlDsa87EcdsaBrainpoolP384r1Sha512 => Some(2592 + 97 + 12), // 2701
PrehashDsaType::HashMlDsa87Ed448Sha512 => Some(2592 + 57 + 12), // 2523

PrehashDsaType::SlhDsaSha2_128s => Some(32),
PrehashDsaType::SlhDsaSha2_128f => Some(32),
PrehashDsaType::SlhDsaSha2_192s => Some(48),
PrehashDsaType::SlhDsaSha2_192f => Some(48),
PrehashDsaType::SlhDsaSha2_256s => Some(64),
PrehashDsaType::SlhDsaSha2_256f => Some(64),
PrehashDsaType::SlhDsaShake128s => Some(32),
PrehashDsaType::SlhDsaShake128f => Some(32),
PrehashDsaType::SlhDsaShake192s => Some(48),
PrehashDsaType::SlhDsaShake192f => Some(48),
PrehashDsaType::SlhDsaShake256s => Some(64),
PrehashDsaType::SlhDsaShake256f => Some(64),
}
}
}
26 changes: 13 additions & 13 deletions src/dsa/common/config/sig_len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,6 @@ impl SigLen for DsaType {
DsaType::EcdsaP256SHA256 => None,
DsaType::EcdsaBrainpoolP256r1SHA256 => None,

DsaType::SlhDsaSha2_128s => Some(7856),
DsaType::SlhDsaSha2_128f => Some(17088),
DsaType::SlhDsaSha2_192s => Some(16224),
DsaType::SlhDsaSha2_192f => Some(35664),
DsaType::SlhDsaSha2_256s => Some(29792),
DsaType::SlhDsaSha2_256f => Some(49856),
DsaType::SlhDsaShake128s => Some(7856),
DsaType::SlhDsaShake128f => Some(17088),
DsaType::SlhDsaShake192s => Some(16224),
DsaType::SlhDsaShake192f => Some(35664),
DsaType::SlhDsaShake256s => Some(29792),
DsaType::SlhDsaShake256f => Some(49856),

// P256 and P384 variations do not have a fixed sig_len
DsaType::EcdsaP384SHA384 => None,
DsaType::EcdsaBrainpoolP384r1SHA384 => None,
Expand Down Expand Up @@ -94,6 +81,19 @@ impl SigLen for PrehashDsaType {
PrehashDsaType::HashMlDsa87EcdsaP384Sha512 => None, // None
PrehashDsaType::HashMlDsa87EcdsaBrainpoolP384r1Sha512 => None, // None
PrehashDsaType::HashMlDsa87Ed448Sha512 => Some(4627 + 114 + 12), // 4753

PrehashDsaType::SlhDsaSha2_128s => Some(7856),
PrehashDsaType::SlhDsaSha2_128f => Some(17088),
PrehashDsaType::SlhDsaSha2_192s => Some(16224),
PrehashDsaType::SlhDsaSha2_192f => Some(35664),
PrehashDsaType::SlhDsaSha2_256s => Some(29792),
PrehashDsaType::SlhDsaSha2_256f => Some(49856),
PrehashDsaType::SlhDsaShake128s => Some(7856),
PrehashDsaType::SlhDsaShake128f => Some(17088),
PrehashDsaType::SlhDsaShake192s => Some(16224),
PrehashDsaType::SlhDsaShake192f => Some(35664),
PrehashDsaType::SlhDsaShake256s => Some(29792),
PrehashDsaType::SlhDsaShake256f => Some(49856),
}
}
}
26 changes: 13 additions & 13 deletions src/dsa/common/config/sk_len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,6 @@ impl SKLen for DsaType {
DsaType::EcdsaP256SHA256 => Some(32),
DsaType::EcdsaBrainpoolP256r1SHA256 => Some(32),

DsaType::SlhDsaSha2_128s => Some(32 * 2),
DsaType::SlhDsaSha2_128f => Some(32 * 2),
DsaType::SlhDsaSha2_192s => Some(48 * 2),
DsaType::SlhDsaSha2_192f => Some(48 * 2),
DsaType::SlhDsaSha2_256s => Some(64 * 2),
DsaType::SlhDsaSha2_256f => Some(64 * 2),
DsaType::SlhDsaShake128s => Some(32 * 2),
DsaType::SlhDsaShake128f => Some(32 * 2),
DsaType::SlhDsaShake192s => Some(48 * 2),
DsaType::SlhDsaShake192f => Some(48 * 2),
DsaType::SlhDsaShake256s => Some(64 * 2),
DsaType::SlhDsaShake256f => Some(64 * 2),

DsaType::EcdsaP384SHA384 => Some(48),
DsaType::EcdsaBrainpoolP384r1SHA384 => Some(48),
DsaType::Ed25519 => Some(32),
Expand Down Expand Up @@ -92,6 +79,19 @@ impl SKLen for PrehashDsaType {
PrehashDsaType::HashMlDsa87EcdsaP384Sha512 => Some(4896 + 48 + 10), // 4954
PrehashDsaType::HashMlDsa87EcdsaBrainpoolP384r1Sha512 => Some(4896 + 48 + 10), // 4954
PrehashDsaType::HashMlDsa87Ed448Sha512 => Some(4896 + 57 + 10), // 4963

PrehashDsaType::SlhDsaSha2_128s => Some(32 * 2),
PrehashDsaType::SlhDsaSha2_128f => Some(32 * 2),
PrehashDsaType::SlhDsaSha2_192s => Some(48 * 2),
PrehashDsaType::SlhDsaSha2_192f => Some(48 * 2),
PrehashDsaType::SlhDsaSha2_256s => Some(64 * 2),
PrehashDsaType::SlhDsaSha2_256f => Some(64 * 2),
PrehashDsaType::SlhDsaShake128s => Some(32 * 2),
PrehashDsaType::SlhDsaShake128f => Some(32 * 2),
PrehashDsaType::SlhDsaShake192s => Some(48 * 2),
PrehashDsaType::SlhDsaShake192f => Some(48 * 2),
PrehashDsaType::SlhDsaShake256s => Some(64 * 2),
PrehashDsaType::SlhDsaShake256f => Some(64 * 2),
}
}
}
14 changes: 0 additions & 14 deletions src/dsa/common/dsa_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ pub enum DsaType {
Ed25519,
Ed448,
EcdsaBrainpoolP384r1SHA384,

// SLH DSA
SlhDsaSha2_128s,
SlhDsaSha2_128f,
SlhDsaSha2_192s,
SlhDsaSha2_192f,
SlhDsaSha2_256s,
SlhDsaSha2_256f,
SlhDsaShake128s,
SlhDsaShake128f,
SlhDsaShake192s,
SlhDsaShake192f,
SlhDsaShake256s,
SlhDsaShake256f,
}

impl DsaType {
Expand Down
15 changes: 15 additions & 0 deletions src/dsa/common/prehash_dsa_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ pub enum PrehashDsaType {
HashMlDsa87EcdsaP384Sha512,
HashMlDsa87EcdsaBrainpoolP384r1Sha512,
HashMlDsa87Ed448Sha512,

// Pure SLH-DSA
// SLH DSA
SlhDsaSha2_128s,
SlhDsaSha2_128f,
SlhDsaSha2_192s,
SlhDsaSha2_192f,
SlhDsaSha2_256s,
SlhDsaSha2_256f,
SlhDsaShake128s,
SlhDsaShake128f,
SlhDsaShake192s,
SlhDsaShake192f,
SlhDsaShake256s,
SlhDsaShake256f,
}

impl PrehashDsaType {
Expand Down
Loading

0 comments on commit d473b19

Please sign in to comment.