pub struct AesGcm<Aes, NonceSize, TagSize = U16>where
TagSize: TagSize,{
pub(crate) cipher: Aes,
pub(crate) ghash: GHash,
pub(crate) nonce_size: PhantomData<NonceSize>,
pub(crate) tag_size: PhantomData<TagSize>,
}Expand description
AES-GCM: generic over an underlying AES implementation and nonce size.
This type is generic to support substituting alternative AES implementations (e.g. embedded hardware implementations)
It is NOT intended to be instantiated with any block cipher besides AES! Doing so runs the risk of unintended cryptographic properties!
The NonceSize generic parameter can be used to instantiate AES-GCM with other
nonce sizes, however it’s recommended to use it with typenum::U12,
the default of 96-bits.
The TagSize generic parameter can be used to instantiate AES-GCM with other
authorization tag sizes, however it’s recommended to use it with typenum::U16,
the default of 128-bits.
If in doubt, use the built-in Aes128Gcm and Aes256Gcm type aliases.
§⚠️ WARNING: Hazmat!
When using short authentication tags, namely 32-bit tags with typenum::U4 or
64-bit tags with typenum::U8 (which require the crate feature hazmat), it is
RECOMMENDED that a key not be used for more than the maximum invocations of
authenticated decryption specified in Table 1 or Table 2 of NIST SP 800-38D,
respectively.
Fields§
§cipher: AesEncryption cipher.
ghash: GHashGHASH authenticator.
nonce_size: PhantomData<NonceSize>Length of the nonce.
tag_size: PhantomData<TagSize>Length of the tag.
Implementations§
Source§impl<Aes, NonceSize, TagSize> AesGcm<Aes, NonceSize, TagSize>where
Aes: BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt,
NonceSize: ArraySize,
TagSize: TagSize,
impl<Aes, NonceSize, TagSize> AesGcm<Aes, NonceSize, TagSize>where
Aes: BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt,
NonceSize: ArraySize,
TagSize: TagSize,
Sourcepub(crate) fn init_ctr(
&self,
nonce: &Nonce<NonceSize>,
) -> (CtrCore<&Aes, Ctr32BE>, Array<u8, U16>)
pub(crate) fn init_ctr( &self, nonce: &Nonce<NonceSize>, ) -> (CtrCore<&Aes, Ctr32BE>, Array<u8, U16>)
Initialize counter mode.
See algorithm described in Section 7.2 of NIST SP800-38D: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
Define a block, J0, as follows: If len(IV)=96, then J0 = IV || 0{31} || 1. If len(IV) ≠ 96, then let s = 128 ⎡len(IV)/128⎤-len(IV), and J0=GHASH(IV||0s+64||[len(IV)]64).
Trait Implementations§
Source§impl<Aes, NonceSize, TagSize> AeadCore for AesGcm<Aes, NonceSize, TagSize>
impl<Aes, NonceSize, TagSize> AeadCore for AesGcm<Aes, NonceSize, TagSize>
Source§const TAG_POSITION: TagPosition = TagPosition::Postfix
const TAG_POSITION: TagPosition = TagPosition::Postfix
Source§impl<Aes, NonceSize, TagSize> AeadInOut for AesGcm<Aes, NonceSize, TagSize>where
Aes: BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt,
NonceSize: ArraySize,
TagSize: TagSize,
impl<Aes, NonceSize, TagSize> AeadInOut for AesGcm<Aes, NonceSize, TagSize>where
Aes: BlockSizeUser<BlockSize = U16> + BlockCipherEncrypt,
NonceSize: ArraySize,
TagSize: TagSize,
Source§fn encrypt_inout_detached(
&self,
nonce: &Nonce<NonceSize>,
associated_data: &[u8],
buffer: InOutBuf<'_, '_, u8>,
) -> Result<Tag<TagSize>, Error>
fn encrypt_inout_detached( &self, nonce: &Nonce<NonceSize>, associated_data: &[u8], buffer: InOutBuf<'_, '_, u8>, ) -> Result<Tag<TagSize>, Error>
Source§fn decrypt_inout_detached(
&self,
nonce: &Nonce<NonceSize>,
associated_data: &[u8],
buffer: InOutBuf<'_, '_, u8>,
tag: &Tag<TagSize>,
) -> Result<(), Error>
fn decrypt_inout_detached( &self, nonce: &Nonce<NonceSize>, associated_data: &[u8], buffer: InOutBuf<'_, '_, u8>, tag: &Tag<TagSize>, ) -> Result<(), Error>
Source§impl<Aes, NonceSize, TagSize> Debug for AesGcm<Aes, NonceSize, TagSize>where
TagSize: TagSize,
impl<Aes, NonceSize, TagSize> Debug for AesGcm<Aes, NonceSize, TagSize>where
TagSize: TagSize,
Source§impl<Aes, NonceSize, TagSize> KeyInit for AesGcm<Aes, NonceSize, TagSize>
impl<Aes, NonceSize, TagSize> KeyInit for AesGcm<Aes, NonceSize, TagSize>
Source§fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength>
fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength>
Source§impl<Aes, NonceSize, TagSize> KeySizeUser for AesGcm<Aes, NonceSize, TagSize>where
Aes: KeySizeUser,
TagSize: TagSize,
impl<Aes, NonceSize, TagSize> KeySizeUser for AesGcm<Aes, NonceSize, TagSize>where
Aes: KeySizeUser,
TagSize: TagSize,
Auto Trait Implementations§
impl<Aes, NonceSize, TagSize> Freeze for AesGcm<Aes, NonceSize, TagSize>where
Aes: Freeze,
impl<Aes, NonceSize, TagSize> RefUnwindSafe for AesGcm<Aes, NonceSize, TagSize>
impl<Aes, NonceSize, TagSize> Send for AesGcm<Aes, NonceSize, TagSize>
impl<Aes, NonceSize, TagSize> Sync for AesGcm<Aes, NonceSize, TagSize>
impl<Aes, NonceSize, TagSize> Unpin for AesGcm<Aes, NonceSize, TagSize>
impl<Aes, NonceSize, TagSize> UnsafeUnpin for AesGcm<Aes, NonceSize, TagSize>where
Aes: UnsafeUnpin,
impl<Aes, NonceSize, TagSize> UnwindSafe for AesGcm<Aes, NonceSize, TagSize>
Blanket Implementations§
Source§impl<T> AeadInPlace for Twhere
T: AeadInOut,
impl<T> AeadInPlace for Twhere
T: AeadInOut,
Source§fn encrypt_in_place(
&self,
nonce: &Array<u8, <T as AeadCore>::NonceSize>,
associated_data: &[u8],
buffer: &mut dyn Buffer,
) -> Result<(), Error>
fn encrypt_in_place( &self, nonce: &Array<u8, <T as AeadCore>::NonceSize>, associated_data: &[u8], buffer: &mut dyn Buffer, ) -> Result<(), Error>
AeadInOut::encrypt_in_place insteadSource§fn encrypt_in_place_detached(
&self,
nonce: &Array<u8, <T as AeadCore>::NonceSize>,
associated_data: &[u8],
buffer: &mut [u8],
) -> Result<Array<u8, <T as AeadCore>::TagSize>, Error>
fn encrypt_in_place_detached( &self, nonce: &Array<u8, <T as AeadCore>::NonceSize>, associated_data: &[u8], buffer: &mut [u8], ) -> Result<Array<u8, <T as AeadCore>::TagSize>, Error>
AeadInOut::encrypt_inout_detached insteadSource§fn decrypt_in_place(
&self,
nonce: &Array<u8, <T as AeadCore>::NonceSize>,
associated_data: &[u8],
buffer: &mut dyn Buffer,
) -> Result<(), Error>
fn decrypt_in_place( &self, nonce: &Array<u8, <T as AeadCore>::NonceSize>, associated_data: &[u8], buffer: &mut dyn Buffer, ) -> Result<(), Error>
AeadInOut::decrypt_in_place insteadSource§fn decrypt_in_place_detached(
&self,
nonce: &Array<u8, <T as AeadCore>::NonceSize>,
associated_data: &[u8],
buffer: &mut [u8],
tag: &Array<u8, <T as AeadCore>::TagSize>,
) -> Result<(), Error>
fn decrypt_in_place_detached( &self, nonce: &Array<u8, <T as AeadCore>::NonceSize>, associated_data: &[u8], buffer: &mut [u8], tag: &Array<u8, <T as AeadCore>::TagSize>, ) -> Result<(), Error>
AeadInOut::decrypt_inout_detached instead