pub struct AesGcmContext { /* private fields */ }unstable only.Expand description
An AES-GCM work queue user.
Operations run on AesDmaBackend, which must be started. On
AesBackend, every operation ends with GcmError::Unsupported. A
nonce must never repeat under one key, because a repeated nonce breaks the authentication.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Implementations§
Source§impl AesGcmContext
impl AesGcmContext
Sourcepub fn new(key: impl Into<Key>) -> Self
pub fn new(key: impl Into<Key>) -> Self
Creates a new context that encrypts and decrypts with key.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn encrypt<'t>(
&'t mut self,
nonce: &[u8; 12],
aad: &'t [u8],
input: &'t [u8],
output: &'t mut [u8],
tag: &'t mut [u8; 16],
) -> Result<AesGcmHandle<'t>, Error>
pub fn encrypt<'t>( &'t mut self, nonce: &[u8; 12], aad: &'t [u8], input: &'t [u8], output: &'t mut [u8], tag: &'t mut [u8; 16], ) -> Result<AesGcmHandle<'t>, Error>
Starts encrypting input into output, and computing the tag over aad and the
ciphertext.
The tag is written to tag when the operation completes. The nonce must never repeat
under this context’s key.
Dropping the returned handle before the operation completes cancels the operation.
§Errors
Error::IncorrectBufferLengthwheninputis empty or longer than 20,400 bytes, oraadis longer than 4,080 bytes.Error::AadNotInRamwhen the DMA cannot readaad, for example from flash.Error::BuffersNotEqualwheninputandoutputdiffer in length.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn encrypt_in_place<'t>(
&'t mut self,
nonce: &[u8; 12],
aad: &'t [u8],
buffer: &'t mut [u8],
tag: &'t mut [u8; 16],
) -> Result<AesGcmHandle<'t>, Error>
pub fn encrypt_in_place<'t>( &'t mut self, nonce: &[u8; 12], aad: &'t [u8], buffer: &'t mut [u8], tag: &'t mut [u8; 16], ) -> Result<AesGcmHandle<'t>, Error>
Starts encrypting buffer in place, and computing the tag over aad and the
ciphertext.
Operates as Self::encrypt does.
§Errors
As Self::encrypt.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn decrypt<'t>(
&'t mut self,
nonce: &[u8; 12],
aad: &'t [u8],
input: &'t [u8],
output: &'t mut [u8],
tag: &'t [u8; 16],
) -> Result<AesGcmHandle<'t>, Error>
pub fn decrypt<'t>( &'t mut self, nonce: &[u8; 12], aad: &'t [u8], input: &'t [u8], output: &'t mut [u8], tag: &'t [u8; 16], ) -> Result<AesGcmHandle<'t>, Error>
Starts decrypting input into output, and checking tag over aad and input.
When the tag does not match, the operation ends with GcmError::TagMismatch and
output is zeroed.
§Errors
As Self::encrypt.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn decrypt_in_place<'t>(
&'t mut self,
nonce: &[u8; 12],
aad: &'t [u8],
buffer: &'t mut [u8],
tag: &'t [u8; 16],
) -> Result<AesGcmHandle<'t>, Error>
pub fn decrypt_in_place<'t>( &'t mut self, nonce: &[u8; 12], aad: &'t [u8], buffer: &'t mut [u8], tag: &'t [u8; 16], ) -> Result<AesGcmHandle<'t>, Error>
Starts decrypting buffer in place, and checking tag over aad and buffer.
Operates as Self::decrypt does.
§Errors
As Self::encrypt.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.