pub trait KeyStore {
// Required methods
fn generate(
&mut self,
purpose: KeyPurpose,
random: &[u8; 32],
) -> Result<(KeyHandle, PublicKey)>;
fn import(
&mut self,
purpose: KeyPurpose,
secret: &[u8; 32],
) -> Result<KeyHandle>;
fn public_key(&self, handle: KeyHandle) -> Result<PublicKey>;
fn sign(&self, handle: KeyHandle, message: &[u8]) -> Result<Signature>;
fn ecdh(
&self,
handle: KeyHandle,
peer: &PublicKey,
) -> Result<Secret<GROUP_SIZE_BYTES>>;
fn remove(&mut self, handle: KeyHandle) -> Result<()>;
}Expand description
Custody of private keys.
Every operation that needs a private key goes through here, and none of them returns
one. A node whose keys are in an ATECC608, an nRF KMU, an ESP32 HMAC peripheral or a
TPM implements this over that; a node without one gets
SoftKeyStore, which keeps them in zeroising memory.
This is a trait — unlike the cryptosuite — because where the keys live really does differ between two nodes running the same binary.
Required Methods§
Sourcefn generate(
&mut self,
purpose: KeyPurpose,
random: &[u8; 32],
) -> Result<(KeyHandle, PublicKey)>
fn generate( &mut self, purpose: KeyPurpose, random: &[u8; 32], ) -> Result<(KeyHandle, PublicKey)>
Generates a key pair from 32 octets of randomness, returning its handle and public key.
The randomness is a parameter rather than something this crate fetches, for the
same reason every other source of entropy is: it comes from the one
Rng the integrator installed, so a platform with a
hardware generator uses it everywhere and a test can be deterministic.
Returns ErrorCode::InvalidArgument if the value is not a valid private key —
zero, or at or above the group order. A caller should draw again.
Sourcefn import(
&mut self,
purpose: KeyPurpose,
secret: &[u8; 32],
) -> Result<KeyHandle>
fn import( &mut self, purpose: KeyPurpose, secret: &[u8; 32], ) -> Result<KeyHandle>
Imports an existing private key. A store backed by hardware may refuse.
Sourcefn public_key(&self, handle: KeyHandle) -> Result<PublicKey>
fn public_key(&self, handle: KeyHandle) -> Result<PublicKey>
The public key for a handle.
Sourcefn sign(&self, handle: KeyHandle, message: &[u8]) -> Result<Signature>
fn sign(&self, handle: KeyHandle, message: &[u8]) -> Result<Signature>
Signs message — ECDSA over SHA-256 (§3.5.3.1).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl<const N: usize> KeyStore for SoftKeyStore<N>
rustcrypto only.