pub struct Context<C, Role> { /* private fields */ }Expand description
The HPKE cryptographic context.
HPKE allows multiple encryption operations to be done based on a given setup transaction. Since the public key operations involved in setup are typically more expensive than symmetric encryption or decryption, this allows applications to amortize the cost of the public key operations, reducing the overall overhead.
In order to avoid nonce reuse, however, this encryption must be stateful. Each of the setup procedures above produces a role-specific context object that stores the AEAD and secret export parameters. The AEAD parameters consist of:
- The AEAD algorithm in use
- A secret
key - A base nonce
base_nonce - A sequence number (initially 0)
The secret export parameters consist of:
- The HPKE ciphersuite in use and
- An
exporter_secretused for the secret export interface (see RFC 9180, Section 5.3)
Note that the RFC currently doesn’t define this. Also see https://github.com/cfrg/draft-irtf-cfrg-hpke/issues/161.
TODO: need pub?
Implementations§
Source§impl<C: Crypto> Context<C, Sender>
impl<C: Crypto> Context<C, Sender>
Sourcepub fn seal_in_place(
&mut self,
aad: &[u8],
in_out: &mut Vec<u8>,
) -> Result<(), Error>
pub fn seal_in_place( &mut self, aad: &[u8], in_out: &mut Vec<u8>, ) -> Result<(), Error>
5.2. Encryption and Decryption
Encryption is unidirectional from sender to recipient. The sender’s
context can encrypt a plaintext pt with associated data aad as
follows:
def Context.Seal(aad, pt):
ct = Seal(self.key, self.ComputeNonce(self.seq), aad, pt)
self.IncrementSeq()
return ctSee RFC 9180, Section 5.2 for details.
§Errors
CryptoError, or message limit reached.
Source§impl<C: Crypto> Context<C, Recipient>
impl<C: Crypto> Context<C, Recipient>
Sourcepub fn open_in_place(
&mut self,
aad: &[u8],
in_out: &mut Vec<u8>,
) -> Result<(), Error>
pub fn open_in_place( &mut self, aad: &[u8], in_out: &mut Vec<u8>, ) -> Result<(), Error>
5.2. Encryption and Decryption
The recipient’s context can decrypt a ciphertext ct with associated
data aad as follows:
def Context.Open(aad, ct):
pt = Open(self.key, self.ComputeNonce(self.seq), aad, ct)
if pt == OpenError:
raise OpenError
self.IncrementSeq()
return ptSee RFC 9180, Section 5.2 for details.
§Errors
CryptoError, or message limit reached.
Source§impl<C: Crypto, Role> Context<C, Role>
impl<C: Crypto, Role> Context<C, Role>
Sourcepub fn export(
&self,
exporter_context: &[u8],
length: usize,
) -> Result<Okm, Error>
pub fn export( &self, exporter_context: &[u8], length: usize, ) -> Result<Okm, Error>
5.3. Secret Export
Takes a serialised exporter context as byte slice and a length for the output secret and returns an exporter secret as byte vector.
def Context.Export(exporter_context, L):
return LabeledExpand(self.exporter_secret, "sec", exporter_context, L)See RFC 9180, Section 5.3 for details.
§Errors
See kdf::labeled_expand.