pub trait Aead: Sized + Aead {
const HPKE_AEAD_ID: u16;
const MAX_PLAINTEXT_SIZE: u64;
const MAX_CIPHERTEXT_SIZE: u64;
// Required method
fn new(key: &[u8]) -> Result<Self, HpkeError>;
// Provided methods
fn seal(
&self,
in_out: &mut [u8],
nonce: &[u8],
associated_data: &[u8],
) -> Result<Hash, HpkeError> { ... }
fn open(
&self,
in_out: &mut [u8],
nonce: &[u8],
associated_data: &[u8],
tag: &[u8],
) -> Result<(), HpkeError> { ... }
}Expand description
HPKE ciphersuite binding for an AEAD algorithm.
An AEAD is the symmetric cipher used to seal and open messages. This trait
only adds what HPKE itself needs on top of [crypto::Aead] (from which the
nonce size, tag size, and the underlying cipher operations are inherited):
Aead::HPKE_AEAD_ID, the IANA “HPKE AEAD Identifiers” value used to build the ciphersuitesuite_id,Aead::MAX_PLAINTEXT_SIZEandAead::MAX_CIPHERTEXT_SIZE, the message length limitsP_MAXandC_MAXdefined by [RFC 5116],Aead::new, the construction of a ready-to-use cipher from the raw key schedule output.
§Example
use hpke::aead::{Aead, Aes256Gcm, ExportOnly};
let cipher = <Aes256Gcm as Aead>::new(&[0x42u8; 32]).unwrap();
assert_eq!(Aes256Gcm::HPKE_AEAD_ID, 0x0002);
assert_eq!(ExportOnly::HPKE_AEAD_ID, 0xffff);§Custom AEADs
Implement [crypto::Aead] for the cipher’s operations, then implement this
trait to give it an HPKE identifier, key size, and message length limits. Any
nonce and tag size is supported as long as KEY_SIZE is at most 64 bytes and
NONCE_SIZE is between 8 and 64 bytes; larger values fail to compile when
the cipher is used with new_sender or
new_recipient.
Required Associated Constants§
Sourceconst HPKE_AEAD_ID: u16
const HPKE_AEAD_ID: u16
The HPKE AEAD identifier (draft-ietf-hpke-hpke-05 Section 7.3, IANA
“HPKE AEAD Identifiers”), used to build the ciphersuite suite_id.
Sourceconst MAX_PLAINTEXT_SIZE: u64
const MAX_PLAINTEXT_SIZE: u64
Maximum length, in bytes, of a plaintext passed to Aead::seal, i.e.
P_MAX ([RFC 5116]).
HPKE refuses to encrypt longer plaintexts with
HpkeError::MessageLimitReached: exceeding P_MAX would void the
confidentiality and integrity guarantees of the AEAD
(draft-ietf-hpke-hpke-05 Section 5.2). There is no default; every AEAD
must state its limit.
Sourceconst MAX_CIPHERTEXT_SIZE: u64
const MAX_CIPHERTEXT_SIZE: u64
Maximum length, in bytes, of a ciphertext passed to
Aead::open, i.e. C_MAX ([RFC 5116]).
HPKE refuses to open longer ciphertexts with
HpkeError::MessageLimitReached (draft-ietf-hpke-hpke-05
Section 5.2). There is no default; every AEAD must state its limit.
Required Methods§
Provided Methods§
Sourcefn seal(
&self,
in_out: &mut [u8],
nonce: &[u8],
associated_data: &[u8],
) -> Result<Hash, HpkeError>
fn seal( &self, in_out: &mut [u8], nonce: &[u8], associated_data: &[u8], ) -> Result<Hash, HpkeError>
Encrypts in_out in place and returns the detached authentication tag,
forwarding to [crypto::Aead::encrypt_in_place].
§Errors
Returns HpkeError::NotSupported when the cipher is the
ExportOnly pseudo-AEAD.
Sourcefn open(
&self,
in_out: &mut [u8],
nonce: &[u8],
associated_data: &[u8],
tag: &[u8],
) -> Result<(), HpkeError>
fn open( &self, in_out: &mut [u8], nonce: &[u8], associated_data: &[u8], tag: &[u8], ) -> Result<(), HpkeError>
Decrypts in_out in place using the detached authentication tag,
forwarding to [crypto::Aead::decrypt_in_place].
§Errors
Returns HpkeError::OpenError when authentication fails, or
HpkeError::NotSupported when the cipher is the ExportOnly
pseudo-AEAD.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
Source§impl Aead for Aes256Gcm
AES-256-GCM (AEAD id 0x0002).
impl Aead for Aes256Gcm
AES-256-GCM (AEAD id 0x0002).
const HPKE_AEAD_ID: u16 = 0x0002
const MAX_PLAINTEXT_SIZE: u64 = AES_GCM_MAX_PLAINTEXT_SIZE
const MAX_CIPHERTEXT_SIZE: u64 = AES_GCM_MAX_CIPHERTEXT_SIZE
Source§impl Aead for ChaCha20Poly1305
ChaCha20-Poly1305 (AEAD id 0x0003).
impl Aead for ChaCha20Poly1305
ChaCha20-Poly1305 (AEAD id 0x0003).