Skip to main content

SenderContext

Struct SenderContext 

Source
pub struct SenderContext<A: Aead, D: Kdf>(/* private fields */);
Expand description

The sender’s encryption context, returned by new_sender.

A context tracks a monotonically increasing sequence number; messages MUST be sealed in order, and the matching RecipientContext MUST open them in the same order. Sealing more than 2^64 - 1 messages with a single context is not possible.

Implementations§

Source§

impl<A: Aead, D: Kdf> SenderContext<A, D>

Source

pub fn seal_in_place( &mut self, in_out: &mut [u8], associated_data: &[u8], ) -> Result<Hash, HpkeError>

Encrypts in_out in place and returns the detached authentication tag.

The ciphertext is in_out itself; combine it with the returned tag as ciphertext || tag for transmission.

§Errors

Returns HpkeError::MessageLimitReached when in_out is longer than the AEAD’s maximum plaintext size (P_MAX) or the context’s sequence number is exhausted, or HpkeError::NotSupported when the ciphersuite uses the ExportOnly pseudo-AEAD.

Source

pub fn seal( &mut self, plaintext: &[u8], associated_data: &[u8], ) -> Result<Vec<u8>, HpkeError>

Encrypts plaintext and returns ciphertext || tag.

§Errors

Returns HpkeError::MessageLimitReached when plaintext is longer than the AEAD’s maximum plaintext size (P_MAX) or the context’s sequence number is exhausted, or HpkeError::NotSupported when the ciphersuite uses the ExportOnly pseudo-AEAD.

Source

pub fn export( &self, out: &mut [u8], exporter_context: &[u8], ) -> Result<(), HpkeError>

Derives out.len() bytes of exported key material, bound to exporter_context (draft-ietf-hpke-hpke-05 Section 5.3).

§Replay

HPKE does not provide replay protection: replaying the encapsulated key enc produces an identical context and therefore identical exported secrets. Applications MUST NOT use an exported secret unless it is safe for the same value to be produced more than once, and MUST NOT derive an AEAD (key, nonce) pair from it (as the example in RFC 9180 Section 9.8 did). When an exported secret feeds encryption, mix in fresh recipient-provided randomness, as in draft-ietf-hpke-hpke-05 Section 9.8.

§Errors

Returns HpkeError::KdfOutputTooLong when out is longer than the KDF can produce (255 * OUTPUT_SIZE for two-stage KDFs, 2^16 - 1 bytes for single-stage KDFs).

Auto Trait Implementations§

§

impl<A, D> Freeze for SenderContext<A, D>
where Context<A, D>: Freeze,

§

impl<A, D> RefUnwindSafe for SenderContext<A, D>
where Context<A, D>: RefUnwindSafe,

§

impl<A, D> Send for SenderContext<A, D>
where Context<A, D>: Send,

§

impl<A, D> Sync for SenderContext<A, D>
where Context<A, D>: Sync,

§

impl<A, D> Unpin for SenderContext<A, D>
where Context<A, D>: Unpin,

§

impl<A, D> UnsafeUnpin for SenderContext<A, D>
where Context<A, D>: UnsafeUnpin,

§

impl<A, D> UnwindSafe for SenderContext<A, D>
where Context<A, D>: UnwindSafe,

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.