Context
HPKE encryption contexts (RFC 9180 §5.2). Sender and recipient contexts for seal/open and export.
- class rfc9180.context.Context(role, aead, kdf, key, base_nonce, exporter_secret, suite_id)[source]
Bases:
objectHPKE Encryption Context (RFC 9180 §5.2).
Manages the encryption/decryption state for HPKE operations, including sequence number tracking and key export functionality.
- Parameters:
role (Role) – Context role (‘S’ for sender, ‘R’ for recipient).
aead (AEADBase) – AEAD algorithm instance.
kdf (KDFBase) – KDF algorithm instance.
key (bytes) – AEAD encryption key.
base_nonce (bytes) – Base nonce for nonce generation.
exporter_secret (bytes) – Secret for key export operations.
suite_id (bytes) – HPKE suite identifier.
- role
Context role.
- Type:
Role
- increment_seq()[source]
Increment the sequence number.
- Raises:
MessageLimitReachedError – If sequence number would overflow.
- Return type:
- seal(aad, pt)[source]
Seal (encrypt) a message.
- Parameters:
- Returns:
Ciphertext.
- Return type:
- Raises:
ValueError – If context is not a sender context.
MessageLimitReachedError – If sequence number would overflow.
- open(aad, ct)[source]
Open (decrypt) a message.
- Parameters:
- Returns:
Decrypted plaintext.
- Return type:
- Raises:
ValueError – If context is not a recipient context.
OpenError – If decryption fails.
MessageLimitReachedError – If sequence number would overflow.