AwsEncryptionSdk.Format.BodyAad (AWS Encryption SDK v1.0.0)

View Source

Message Body AAD (Additional Authenticated Data) serialization.

Used as AAD input to AES-GCM when encrypting/decrypting message body content.

Format

Per message-body-aad.md:

| Field           | Size           | Type   |
|-----------------|----------------|--------|
| Message ID      | 16 (v1) or 32 (v2) bytes | Binary |
| Body AAD Content| Variable       | UTF-8  |
| Sequence Number | 4 bytes        | Uint32 |
| Content Length  | 8 bytes        | Uint64 |

The Body AAD Content string varies by content type:

  • Non-framed: "AWSKMSEncryptionClient Single Block"
  • Regular frame: "AWSKMSEncryptionClient Frame"
  • Final frame: "AWSKMSEncryptionClient Final Frame"

Summary

Types

Content type for Body AAD

Functions

Returns the Body AAD Content string for a given content type.

Serializes Message Body AAD for use in AES-GCM encryption/decryption.

Types

content_type()

@type content_type() :: :non_framed | :regular_frame | :final_frame

Content type for Body AAD

Functions

content_string(atom)

@spec content_string(content_type()) :: String.t()

Returns the Body AAD Content string for a given content type.

serialize(message_id, content_type, sequence_number, content_length)

@spec serialize(binary(), content_type(), pos_integer(), non_neg_integer()) ::
  binary()

Serializes Message Body AAD for use in AES-GCM encryption/decryption.

Parameters

  • message_id - 16 bytes (v1) or 32 bytes (v2)
  • content_type - :non_framed, :regular_frame, or :final_frame
  • sequence_number - Frame sequence number (1 for non-framed)
  • content_length - Plaintext length being encrypted

Examples

iex> message_id = :crypto.strong_rand_bytes(32)
iex> aad = AwsEncryptionSdk.Format.BodyAad.serialize(message_id, :non_framed, 1, 1024)
iex> byte_size(aad)
79  # 32 + 35 + 4 + 8