Skip to main content

capsule_core/crypto/keys/
signer.rs

1//! The signing seam (SSoT: [Cryptography — Keys § Device Keys]).
2//!
3//! Every data-plane signature flows through [`Signer`] rather than a concrete
4//! [`HybridSigningKey`], so a **hardware-bound** device signing key can be dropped in without
5//! touching the call sites that build manifests and backup artifacts. The design binds only
6//! the *device* signing key (DSK) to hardware; the user IK and per-epoch write-tier keys are
7//! software, and [`HybridSigningKey`] is their [`Signer`] implementation here.
8//!
9//! Signing is **fallible** because a hardware element can refuse (the user cancels a
10//! biometric, the element is unavailable). The software implementation never returns `Err`.
11//! The hardware-backed implementation lands with [hardware-bound key storage] (`SLICES.md`).
12//!
13//! [Cryptography — Keys § Device Keys]: https://docs/design/cryptography/keys/#device-keys
14//! [hardware-bound key storage]: https://docs/design/cryptography/keys/
15
16use super::hybrid_sig::{HybridSignature, HybridSigningKey, HybridVerifyingKey};
17use crate::crypto::CryptoError;
18
19/// Produces hybrid signatures over arbitrary bytes and exposes the matching public key.
20///
21/// This is the abstraction the device signing key (DSK) is consumed through. Keeping it
22/// object-safe (`&dyn Signer`) lets a software key and a Secure Enclave / StrongBox / TPM
23/// backend be used interchangeably at every signing site. `Send + Sync` so a `Box<dyn Signer>`
24/// can live inside the (`Mutex`-shared) `Workspace`.
25pub trait Signer: Send + Sync {
26    /// Sign `msg`, producing both signature halves (Ed25519 ‖ ML-DSA-65).
27    ///
28    /// Returns [`CryptoError`] only for a backend that can fail (hardware); the software
29    /// [`HybridSigningKey`] implementation is infallible.
30    fn sign(&self, msg: &[u8]) -> Result<HybridSignature, CryptoError>;
31
32    /// The hybrid public key both halves of [`sign`](Self::sign) verify against.
33    fn verifying_key(&self) -> HybridVerifyingKey;
34}
35
36/// The software signer: an in-memory hybrid key. Its `sign` never fails.
37impl Signer for HybridSigningKey {
38    fn sign(&self, msg: &[u8]) -> Result<HybridSignature, CryptoError> {
39        Ok(HybridSigningKey::sign(self, msg))
40    }
41
42    fn verifying_key(&self) -> HybridVerifyingKey {
43        HybridSigningKey::verifying_key(self)
44    }
45}
46
47#[cfg(test)]
48mod tests;