Skip to main content

EphemeralKey

Struct EphemeralKey 

Source
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

Source

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).

Source

pub fn algorithm(&self) -> KeyAgreementAlgorithm

The key’s curve.

Source

pub fn public_key(&self) -> &[u8] ⓘ

The public key to send the peer: an uncompressed SEC 1 point, or 32 bytes for X25519.

Source

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).

Trait Implementations§

Source§

impl Debug for EphemeralKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.