aes_gcm

Type Alias Aes128Gcm

Source
pub type Aes128Gcm = AesGcm<Aes128, U12>;
Expand description

AES-GCM with a 128-bit key and 96-bit nonce.

Aliased Type§

struct Aes128Gcm {
    pub(crate) cipher: Aes128,
    pub(crate) ghash: GHash,
    pub(crate) nonce_size: PhantomData<UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>>,
    pub(crate) tag_size: PhantomData<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>>,
}

Fields§

§cipher: Aes128

Encryption cipher.

§ghash: GHash

GHASH authenticator.

§nonce_size: PhantomData<UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>>

Length of the nonce.

§tag_size: PhantomData<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>>

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,

Source

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).

Source

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>
where NonceSize: ArrayLength<u8>, TagSize: TagSize,

Source§

type NonceSize = NonceSize

The length of a nonce.
Source§

type TagSize = TagSize

The maximum length of the nonce.
Source§

type CiphertextOverhead = UTerm

The upper bound amount of additional space required to support a ciphertext vs. a plaintext.
Source§

fn generate_nonce( rng: impl CryptoRng + RngCore, ) -> GenericArray<u8, Self::NonceSize>

Generate a random nonce for this AEAD algorithm. Read more
Source§

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>

Encrypt the data in-place, returning the authentication tag
Source§

fn decrypt_in_place_detached( &self, nonce: &Nonce<NonceSize>, associated_data: &[u8], buffer: &mut [u8], tag: &Tag<TagSize>, ) -> Result<(), Error>

Decrypt the message in-place, returning an error in the event the provided authentication tag does not match the given ciphertext (i.e. ciphertext is modified/unauthentic)
Source§

fn encrypt_in_place( &self, nonce: &GenericArray<u8, Self::NonceSize>, associated_data: &[u8], buffer: &mut dyn Buffer, ) -> Result<(), Error>

Encrypt the given buffer containing a plaintext message in-place. Read more
Source§

fn decrypt_in_place( &self, nonce: &GenericArray<u8, Self::NonceSize>, associated_data: &[u8], buffer: &mut dyn Buffer, ) -> Result<(), Error>

Decrypt the message in-place, returning an error in the event the provided authentication tag does not match the given ciphertext. Read more
Source§

impl<Aes: Clone, NonceSize: Clone, TagSize> Clone for AesGcm<Aes, NonceSize, TagSize>
where TagSize: TagSize + Clone,

Source§

fn clone(&self) -> AesGcm<Aes, NonceSize, TagSize>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Aes, NonceSize, TagSize> From<Aes> for AesGcm<Aes, NonceSize, TagSize>
where Aes: BlockSizeUser<BlockSize = U16> + BlockEncrypt, TagSize: TagSize,

Source§

fn from(cipher: Aes) -> Self

Converts to this type from the input type.
Source§

impl<Aes, NonceSize, TagSize> KeyInit for AesGcm<Aes, NonceSize, TagSize>
where Aes: BlockSizeUser<BlockSize = U16> + BlockEncrypt + KeyInit, TagSize: TagSize,

Source§

fn new(key: &Key<Self>) -> Self

Create new value from fixed size key.
Source§

fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength>

Create new value from variable size key.
Source§

fn generate_key( rng: impl CryptoRng + RngCore, ) -> GenericArray<u8, Self::KeySize>

Generate random key using the provided CryptoRng.
Source§

impl<Aes, NonceSize, TagSize> KeySizeUser for AesGcm<Aes, NonceSize, TagSize>
where Aes: KeySizeUser, TagSize: TagSize,

Source§

type KeySize = <Aes as KeySizeUser>::KeySize

Key size in bytes.
Source§

fn key_size() -> usize

Return key size in bytes.