macro_rules! impl_struct {
($name:ident, $doc:expr) => {
#[doc = $doc]
#[derive(Clone)]
pub struct $name<const SIZE: usize> {
pub(crate) value: [u8; SIZE],
}
impl<const SIZE: usize> $name<SIZE> {
pub fn zero() -> Self {
Self { value: [0u8; SIZE] }
}
pub fn new(value: [u8; SIZE]) -> Self {
Self { value }
}
pub fn as_slice(&self) -> &[u8] {
&self.value
}
pub fn as_ref(&self) -> &[u8; SIZE] {
&self.value
}
pub const fn len() -> usize {
SIZE
}
}
};
}
impl_struct!(MLDSASigningKey, "An ML-DSA signature key.");
impl_struct!(MLDSAVerificationKey, "An ML-DSA verification key.");
impl_struct!(MLDSASignature, "An ML-DSA signature.");
macro_rules! impl_non_hax_types {
($name:ident) => {
impl<const SIZE: usize> $name<SIZE> {
pub fn as_mut_slice(&mut self) -> &mut [u8] {
&mut self.value
}
pub fn as_ref_mut(&mut self) -> &mut [u8; SIZE] {
&mut self.value
}
}
};
}
mod non_hax_impls {
use super::*;
impl_non_hax_types!(MLDSASigningKey);
impl_non_hax_types!(MLDSAVerificationKey);
impl_non_hax_types!(MLDSASignature);
}
pub struct MLDSAKeyPair<const VERIFICATION_KEY_SIZE: usize, const SIGNING_KEY_SIZE: usize> {
pub signing_key: MLDSASigningKey<SIGNING_KEY_SIZE>,
pub verification_key: MLDSAVerificationKey<VERIFICATION_KEY_SIZE>,
}
#[cfg_attr(not(eurydice), derive(Debug))]
pub enum VerificationError {
MalformedHintError,
SignerResponseExceedsBoundError,
CommitmentHashesDontMatchError,
VerificationContextTooLongError,
}
#[cfg_attr(not(eurydice), derive(Debug))]
pub enum SigningError {
RejectionSamplingError,
ContextTooLongError,
}