pub struct EphemeralKey { /* private fields */ }Expand description
An ephemeral key, generated in the module for one agreement and never exported. agree
consumes it (SP 800-56A Rev. 3 §5.6.3.3).
Implementations§
Source§impl EphemeralKey
impl EphemeralKey
Sourcepub fn generate(
a: &Admitted,
algorithm: KeyAgreementAlgorithm,
) -> Result<Self, CryptoError>
pub fn generate( a: &Admitted, algorithm: KeyAgreementAlgorithm, ) -> Result<Self, CryptoError>
A fresh key on algorithm’s curve. Refuses a curve a’s profile does not admit, or its
module line lacks (Admitted::admit_key_agreement).
Sourcepub fn algorithm(&self) -> KeyAgreementAlgorithm
pub fn algorithm(&self) -> KeyAgreementAlgorithm
The key’s curve.
Sourcepub fn public_key(&self) -> &[u8] ⓘ
pub fn public_key(&self) -> &[u8] ⓘ
The public key to send the peer: an uncompressed SEC 1 point, or 32 bytes for X25519.
Sourcepub fn agree(
self,
peer_static: &[u8],
spec: &Spec<'_>,
len: usize,
) -> Result<DerivedKey, CryptoError>
pub fn agree( self, peer_static: &[u8], spec: &Spec<'_>, len: usize, ) -> Result<DerivedKey, CryptoError>
Agrees with the peer’s static public key and derives len bytes from the shared secret as
spec says, under the profile the key was generated under, which admitted its curve. With
kdf::Spec::Dhkem this is RFC 9180 §4.1 Encap’s shared secret, enc being this key’s
public key. Refuses, in this order: a spec whose algorithm is not of its kind, or a DHKEM
HKDF RFC 9180 Table 2 does not pair with the curve (CryptoError::KdfSpecMismatch); a KDF
the profile does not admit; an empty info or fixed_info unless kdf_info_may_be_empty;
an output length outside the KDF’s bounds, or other than Nsecret for DHKEM; a peer key
that is not an uncompressed point (or 32 bytes for X25519) of the key’s length; and a peer
key the module’s validation refuses, or an X25519 agreement whose shared secret is all
zeros (CryptoError::KeyAgreementPeerKey).