Skip to main content

EphemeralKeypair

Struct EphemeralKeypair 

Source
pub struct EphemeralKeypair { /* private fields */ }
Expand description

An ephemeral X25519 keypair for a single Pair Verify exchange.

“Ephemeral” here means per session: a new keypair is generated with EphemeralKeypair::generate for each Pair Verify run and discarded once the session keys are derived. EphemeralKeypair::from_secret reconstructs a keypair from a fixed scalar for deterministic tests and trace replay.

The underlying secret is held as a StaticSecret (which zeroizes on drop) rather than exposed as raw bytes; only the public key and the computed shared secret leave this type.

Implementations§

Source§

impl EphemeralKeypair

Source

pub fn generate() -> Self

Generate a fresh random ephemeral keypair using the operating system CSPRNG.

This is the constructor production code uses; every Pair Verify session gets its own keypair.

Source

pub fn from_secret(scalar: [u8; 32]) -> Self

Reconstruct a keypair from a fixed 32-byte secret scalar.

The scalar is clamped internally by X25519, so any 32-byte value is accepted and the resulting public key matches the X25519 definition. This is the deterministic path used to replay captured traces and to assert the RFC 7748 known-answer vector; production code calls EphemeralKeypair::generate instead.

Source

pub fn public(&self) -> [u8; 32]

This keypair’s X25519 public key — the 32 bytes sent on the wire.

Source

pub fn diffie_hellman(&self, peer_public: &[u8; 32]) -> [u8; 32]

Compute the X25519 shared secret against the peer’s 32-byte public key.

Both sides of a Pair Verify exchange derive the same value: DH(self_secret, peer_public) == DH(peer_secret, self_public).

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.