AwsEncryptionSdk.Crypto.AesGcm (AWS Encryption SDK v1.0.0)
View SourceAES-GCM encryption and decryption operations.
Wraps Erlang :crypto functions for AES-GCM with 128, 192, or 256-bit keys.
All operations use 12-byte IVs and 16-byte authentication tags as required
by the AWS Encryption SDK.
Summary
Functions
Decrypts ciphertext using AES-GCM.
Encrypts plaintext using AES-GCM.
Returns the IV length (always 12 bytes for AES-GCM).
Returns the required key length in bytes for a cipher.
Constructs an IV from a sequence number.
Returns the authentication tag length (always 16 bytes).
Returns a zero IV (12 zero bytes).
Types
Functions
@spec decrypt(cipher(), binary(), binary(), binary(), binary(), binary()) :: {:ok, binary()} | {:error, :authentication_failed}
Decrypts ciphertext using AES-GCM.
Parameters
cipher-:aes_128_gcm,:aes_192_gcm, or:aes_256_gcmkey- Decryption key (16, 24, or 32 bytes)iv- Initialization vector (12 bytes)ciphertext- Data to decryptaad- Additional authenticated dataauth_tag- Authentication tag (16 bytes)
Returns
{:ok, plaintext}on successful decryption and authentication{:error, :authentication_failed}if tag verification fails
Encrypts plaintext using AES-GCM.
Parameters
cipher-:aes_128_gcm,:aes_192_gcm, or:aes_256_gcmkey- Encryption key (16, 24, or 32 bytes)iv- Initialization vector (12 bytes)plaintext- Data to encryptaad- Additional authenticated data
Returns
{ciphertext, auth_tag} tuple where auth_tag is 16 bytes.
@spec iv_length() :: 12
Returns the IV length (always 12 bytes for AES-GCM).
@spec key_length(cipher()) :: 16 | 24 | 32
Returns the required key length in bytes for a cipher.
@spec sequence_number_to_iv(non_neg_integer()) :: binary()
Constructs an IV from a sequence number.
The IV is the sequence number padded to 12 bytes (big-endian). Used for frame encryption/decryption.
@spec tag_length() :: 16
Returns the authentication tag length (always 16 bytes).
@spec zero_iv() :: binary()
Returns a zero IV (12 zero bytes).
Used for header authentication tag computation.