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>
impl<A: Aead, D: Kdf> SenderContext<A, D>
Sourcepub fn seal_in_place(
&mut self,
in_out: &mut [u8],
associated_data: &[u8],
) -> Result<Hash, HpkeError>
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.
Sourcepub fn seal(
&mut self,
plaintext: &[u8],
associated_data: &[u8],
) -> Result<Vec<u8>, HpkeError>
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.
Sourcepub fn export(
&self,
out: &mut [u8],
exporter_context: &[u8],
) -> Result<(), HpkeError>
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).