Skip to main content

quantaegis_core/
signature.rs

1//! Digital Signature trait abstraction.
2//!
3//! Designed to support pure post-quantum signatures (e.g., FIPS 204 ML-DSA, FIPS 205 SLH-DSA)
4//! and composite/hybrid signatures behind a uniform, context-aware interface.
5
6use crate::error::Result;
7use crate::rng::CryptoRng;
8
9/// Uniform interface for post-quantum Digital Signature Schemes.
10///
11/// # Secret-Output Staging Note
12/// Returning secret signing keys by value (`-> Result<...>`) in safe Rust can leave an unzeroized
13/// copy in a callee's return staging slot when moved into the caller's return place.
14/// Zeroization-critical callers (including `quantaegis-fips`) should prefer concrete in-place
15/// `keygen_into` (and `sign_into` for direct buffer output) methods where provided by the
16/// parameter set.
17pub trait Signature {
18    /// Public verifying key type.
19    type VerifyingKey;
20    /// Private signing key type (must zeroize on drop).
21    type SigningKey;
22    /// Signature type.
23    type Sig;
24
25    /// Generates a fresh `(VerifyingKey, SigningKey)` key pair using `rng`.
26    ///
27    /// For zeroization-critical callers avoiding safe-Rust return-slot staging copies of the
28    /// signing key, prefer the concrete parameter set's `keygen_into` method.
29    fn keygen<R: CryptoRng + ?Sized>(rng: &mut R)
30    -> Result<(Self::VerifyingKey, Self::SigningKey)>;
31
32    /// Signs `msg` with optional domain-separation context string `ctx` (at most 255 bytes in
33    /// FIPS 204/205) using fresh randomness from `rng` (hedged mode).
34    ///
35    /// Callers writing directly into a caller-owned byte buffer can prefer the concrete signing
36    /// key's `sign_into` method where available.
37    fn sign<R: CryptoRng + ?Sized>(
38        sk: &Self::SigningKey,
39        msg: &[u8],
40        ctx: &[u8],
41        rng: &mut R,
42    ) -> Result<Self::Sig>;
43
44    /// Verifies `sig` over `msg` and `ctx` using `vk`.
45    fn verify(vk: &Self::VerifyingKey, msg: &[u8], ctx: &[u8], sig: &Self::Sig) -> Result<()>;
46}