quantcrypt/kem/api/
algorithm.rsuse crate::kem::common::{config::oids::Oid, kem_type::KemType};
use strum::IntoEnumIterator;
use strum_macros::{Display, EnumIter};
#[derive(Clone, Debug, PartialEq, EnumIter, Display, Copy)]
pub enum KemAlgorithm {
MlKem512,
MlKem768,
MlKem1024,
MlKem512P256,
MlKem512BrainpoolP256r1,
MlKem512X25519,
MlKem512Rsa2048,
MlKem512Rsa3072,
MlKem768P256,
MlKem768Rsa2048,
MlKem768Rsa3072,
MlKem768Rsa4096,
MlKem768X25519,
MlKem768P384,
MlKem768BrainpoolP256r1,
MlKem1024P384,
MlKem1024BrainpoolP384r1,
MlKem1024X448,
}
impl KemAlgorithm {
pub(crate) fn all() -> Vec<KemAlgorithm> {
KemAlgorithm::iter().collect()
}
pub(crate) fn get_kem_type(&self) -> KemType {
match self {
KemAlgorithm::MlKem512 => KemType::MlKem512,
KemAlgorithm::MlKem768 => KemType::MlKem768,
KemAlgorithm::MlKem1024 => KemType::MlKem1024,
KemAlgorithm::MlKem512P256 => KemType::MlKem512P256,
KemAlgorithm::MlKem512BrainpoolP256r1 => KemType::MlKem512BrainpoolP256r1,
KemAlgorithm::MlKem512X25519 => KemType::MlKem512X25519,
KemAlgorithm::MlKem512Rsa2048 => KemType::MlKem512Rsa2048,
KemAlgorithm::MlKem512Rsa3072 => KemType::MlKem512Rsa3072,
KemAlgorithm::MlKem768P256 => KemType::MlKem768P256,
KemAlgorithm::MlKem768Rsa2048 => KemType::MlKem768Rsa2048,
KemAlgorithm::MlKem768Rsa3072 => KemType::MlKem768Rsa3072,
KemAlgorithm::MlKem768Rsa4096 => KemType::MlKem768Rsa4096,
KemAlgorithm::MlKem768X25519 => KemType::MlKem768X25519,
KemAlgorithm::MlKem768P384 => KemType::MlKem768P384,
KemAlgorithm::MlKem768BrainpoolP256r1 => KemType::MlKem768BrainpoolP256r1,
KemAlgorithm::MlKem1024P384 => KemType::MlKem1024P384,
KemAlgorithm::MlKem1024BrainpoolP384r1 => KemType::MlKem1024BrainpoolP384r1,
KemAlgorithm::MlKem1024X448 => KemType::MlKem1024X448,
}
}
pub fn is_composite(&self) -> bool {
!matches!(
self,
KemAlgorithm::MlKem512 | KemAlgorithm::MlKem768 | KemAlgorithm::MlKem1024
)
}
pub fn get_oid(&self) -> String {
self.get_kem_type().get_oid()
}
pub fn from_oid(oid: &str) -> Option<KemAlgorithm> {
KemAlgorithm::all()
.iter()
.find(|x| x.get_oid() == oid)
.cloned()
}
}