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.
Fields§
§cipher: Aes
Encryption cipher.
ghash: GHash
GHASH 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: BlockCipher + BlockSizeUser<BlockSize = U16> + BlockEncrypt,
NonceSize: ArrayLength<u8>,
TagSize: TagSize,
impl<Aes, NonceSize, TagSize> AesGcm<Aes, NonceSize, TagSize>where
Aes: BlockCipher + BlockSizeUser<BlockSize = U16> + BlockEncrypt,
NonceSize: ArrayLength<u8>,
TagSize: TagSize,
sourcepub(crate) fn init_ctr(
&self,
nonce: &Nonce<NonceSize>,
) -> (CtrCore<&Aes, Ctr32BE>, GenericArray<u8, U16>)
pub(crate) fn init_ctr( &self, nonce: &Nonce<NonceSize>, ) -> (CtrCore<&Aes, Ctr32BE>, GenericArray<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).
sourcepub(crate) fn compute_tag(
&self,
mask: GenericArray<u8, U16>,
associated_data: &[u8],
buffer: &[u8],
) -> Tag
pub(crate) fn compute_tag( &self, mask: GenericArray<u8, U16>, associated_data: &[u8], buffer: &[u8], ) -> Tag
Authenticate the given plaintext and associated data using GHASH.
Trait Implementations§
source§impl<Aes, NonceSize, TagSize> AeadCore for AesGcm<Aes, NonceSize, TagSize>
impl<Aes, NonceSize, TagSize> AeadCore for AesGcm<Aes, NonceSize, TagSize>
§type CiphertextOverhead = UTerm
type CiphertextOverhead = UTerm
source§fn generate_nonce(
rng: impl CryptoRng + RngCore,
) -> GenericArray<u8, Self::NonceSize>
fn generate_nonce( rng: impl CryptoRng + RngCore, ) -> GenericArray<u8, Self::NonceSize>
source§impl<Aes, NonceSize, TagSize> AeadInPlace for AesGcm<Aes, NonceSize, TagSize>where
Aes: BlockCipher + BlockSizeUser<BlockSize = U16> + BlockEncrypt,
NonceSize: ArrayLength<u8>,
TagSize: TagSize,
impl<Aes, NonceSize, TagSize> AeadInPlace for AesGcm<Aes, NonceSize, TagSize>where
Aes: BlockCipher + BlockSizeUser<BlockSize = U16> + BlockEncrypt,
NonceSize: ArrayLength<u8>,
TagSize: TagSize,
source§fn encrypt_in_place_detached(
&self,
nonce: &Nonce<NonceSize>,
associated_data: &[u8],
buffer: &mut [u8],
) -> Result<Tag<TagSize>, Error>
fn encrypt_in_place_detached( &self, nonce: &Nonce<NonceSize>, associated_data: &[u8], buffer: &mut [u8], ) -> Result<Tag<TagSize>, Error>
source§fn decrypt_in_place_detached(
&self,
nonce: &Nonce<NonceSize>,
associated_data: &[u8],
buffer: &mut [u8],
tag: &Tag<TagSize>,
) -> Result<(), Error>
fn decrypt_in_place_detached( &self, nonce: &Nonce<NonceSize>, associated_data: &[u8], buffer: &mut [u8], tag: &Tag<TagSize>, ) -> Result<(), Error>
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§fn generate_key(
rng: impl CryptoRng + RngCore,
) -> GenericArray<u8, Self::KeySize>
fn generate_key( rng: impl CryptoRng + RngCore, ) -> GenericArray<u8, Self::KeySize>
CryptoRng
.