baml.crypto.Aes128GcmSiv

AES-128-GCM-SIV: nonce-misuse-resistant authenticated encryption (RFC 8452) under a 128-bit key.

Reference version

Signature

class baml.crypto.Aes128GcmSiv

AES-128-GCM-SIV: nonce-misuse-resistant authenticated encryption (RFC 8452) under a 128-bit key.

Identical in construction and guarantees to [Aes256GcmSiv], with a shorter key. Prefer Aes256GcmSiv unless a 128-bit key is dictated by an existing format or peer.

Source:<builtin>/baml/ns_crypto/aes_gcm_siv.bamlbytes 4104–6617

Fields

_cipher

$rust_type

Opaque, runtime-owned cipher state: the expanded AES key schedule.

The key lives here rather than in a uint8array field so that a cipher carrying a wrong-length key cannot be constructed, and so key material stays unreachable from BAML. It cannot be read back, rendered by string.from, or serialized by baml.json.from.

Static methods

function

new

(key: uint8array) -> baml.crypto.Aes128GcmSiv throws baml.errors.InvalidArgument

Creates a cipher from a 16-byte (128-bit) key.

Throws
  • baml.errors.InvalidArgument if key is not exactly 16 bytes.

Implementations

baml.Concrete for T

Source:<builtin>/baml/core.bamlbytes 763–795

baml.crypto.Aead for baml.crypto.Aes128GcmSiv

Instance methods

function

decrypt

(
self,
nonce: uint8array,
ciphertext: uint8array,
aad: uint8array

Authenticates and decrypts ciphertext, which must have been produced by encrypt under the same key, nonce, and aad.

Throws
  • baml.errors.InvalidArgument if nonce is not exactly 12 bytes, or ciphertext / aad exceed the RFC 8452 limits.
  • DecryptionFailure if the ciphertext does not authenticate.
function

encrypt

(
self,
nonce: uint8array,
plaintext: uint8array,
aad: uint8array
) -> uint8array throws baml.errors.InvalidArgument

Encrypts plaintext under nonce, authenticating aad alongside it. The ciphertext is 16 bytes longer than plaintext, which is the appended authentication tag.

Throws
  • baml.errors.InvalidArgument if nonce is not exactly 12 bytes, or plaintext / aad exceed the RFC 8452 limit of 2^36 bytes.

Source:<builtin>/baml/ns_crypto/aes_gcm_siv.bamlbytes 4826–6205

baml.crypto.GenerateKey for baml.crypto.Aes128GcmSiv

Key = uint8array

Static methods

function

random_key

(rng: baml.random.Rng) -> uint8array throws never

Draws a fresh 16-byte key from rng. Pass the result to Aes128GcmSiv.new. BUG: see Aes256GcmSiv.random_key. Self.Key lowers to an error type at a concrete impl site, so the concrete type is spelled out.

Source:<builtin>/baml/ns_crypto/aes_gcm_siv.bamlbytes 6211–6615