use arcanum_core::error::Result;
pub trait KeyEncapsulation {
type DecapsulationKey;
type EncapsulationKey;
type Ciphertext;
type SharedSecret;
const ALGORITHM: &'static str;
const SECURITY_LEVEL: usize;
fn generate_keypair() -> (Self::DecapsulationKey, Self::EncapsulationKey);
fn encapsulate(ek: &Self::EncapsulationKey) -> (Self::Ciphertext, Self::SharedSecret);
fn decapsulate(
dk: &Self::DecapsulationKey,
ciphertext: &Self::Ciphertext,
) -> Result<Self::SharedSecret>;
}
pub trait PostQuantumSignature {
type SigningKey;
type VerifyingKey;
type Signature;
const ALGORITHM: &'static str;
const SECURITY_LEVEL: usize;
fn generate_keypair() -> (Self::SigningKey, Self::VerifyingKey);
fn sign(sk: &Self::SigningKey, message: &[u8]) -> Self::Signature;
fn verify(vk: &Self::VerifyingKey, message: &[u8], signature: &Self::Signature) -> Result<()>;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SecurityLevel {
Level1 = 128,
Level3 = 192,
Level5 = 256,
}
impl SecurityLevel {
pub fn bits(&self) -> usize {
*self as usize
}
pub fn ml_kem_variant(&self) -> &'static str {
match self {
SecurityLevel::Level1 => "ML-KEM-512",
SecurityLevel::Level3 => "ML-KEM-768",
SecurityLevel::Level5 => "ML-KEM-1024",
}
}
pub fn ml_dsa_variant(&self) -> &'static str {
match self {
SecurityLevel::Level1 => "ML-DSA-44",
SecurityLevel::Level3 => "ML-DSA-65",
SecurityLevel::Level5 => "ML-DSA-87",
}
}
}