pub struct Key { /* private fields */ }Expand description
An AEAD key the profile admits. It seals under nonces the crate chooses, never the caller’s:
AES-GCM’s is drawn inside the module’s seal, ChaCha20-Poly1305’s from the module’s DRBG just
before its seal. It refuses its 2^32 + 1th seal with CryptoError::AeadLimit. It opens under
the nonce stored beside a ciphertext. It is not Clone, so its seal count cannot be copied.
Its key schedule is held in the module’s AEAD contexts, which the module clears on drop.
Implementations§
Source§impl Key
impl Key
Sourcepub fn new(
a: &Admitted,
algorithm: AeadAlgorithm,
key: &[u8],
) -> Result<Key, CryptoError>
pub fn new( a: &Admitted, algorithm: AeadAlgorithm, key: &[u8], ) -> Result<Key, CryptoError>
A key for algorithm. Refuses, in order: an algorithm a’s profile does not admit or its
module line lacks (Admitted::admit_aead); a key that is not algorithm.key_len() bytes
(CryptoError::AeadKeyLength); a key the module refuses (CryptoError::AeadKey).
Sourcepub fn algorithm(&self) -> AeadAlgorithm
pub fn algorithm(&self) -> AeadAlgorithm
The algorithm.
Sourcepub fn seal_in_place(
&self,
aad: &[u8],
buf: &mut [u8],
) -> Result<([u8; 12], [u8; 16]), CryptoError>
pub fn seal_in_place( &self, aad: &[u8], buf: &mut [u8], ) -> Result<([u8; 12], [u8; 16]), CryptoError>
Encrypts buf in place and returns the nonce and the tag, which the caller stores beside
the ciphertext. AES-GCM draws the nonce inside the module’s seal (FIPS 140-3 IG C.H
Scenario 2); ChaCha20-Poly1305 draws it from the module’s DRBG. Refuses, in order: a
plaintext longer than algorithm.max_plaintext_len() (CryptoError::AeadPlaintextLength);
a 2^32 + 1th seal (CryptoError::AeadLimit); a module failure (CryptoError::AeadSeal, or
CryptoError::Random). A seal the module refuses after reserving its invocation still
counts toward the limit; an AeadLimit refusal reserves nothing.
Sourcepub fn open_in_place<'b>(
&self,
nonce: &[u8; 12],
aad: &[u8],
buf: &'b mut [u8],
) -> Result<&'b mut [u8], CryptoError>
pub fn open_in_place<'b>( &self, nonce: &[u8; 12], aad: &[u8], buf: &'b mut [u8], ) -> Result<&'b mut [u8], CryptoError>
Authenticates and decrypts buf, the ciphertext followed by its tag, in place, and returns
the plaintext prefix. Refuses a buffer shorter than the tag, and anything that does not
authenticate under this key, nonce and aad, with CryptoError::AeadOpen. Opening does
not count toward the seal limit.