Class crypto_aead

Lua interface to AEAD (Authenticated Encryption with Associated Data) ciphers.

Methods

crypto_aead:authsize () Returns the authentication tag size in bytes.
crypto_aead:decrypt (iv, ciphertext_with_tag[, aad]) Decrypts and authenticates ciphertext.
crypto_aead:encrypt (iv, plaintext[, aad]) Encrypts plaintext with authentication.
crypto_aead:ivsize () Returns the required IV size in bytes.
crypto_aead:new (algname) Creates a new AEAD transform object.
crypto_aead:setauthsize (tagsize) Sets the authentication tag size.
crypto_aead:setkey (key) Sets the cipher key.


Methods

crypto_aead:authsize ()
Returns the authentication tag size in bytes.

Returns:

    integer
crypto_aead:decrypt (iv, ciphertext_with_tag[, aad])
Decrypts and authenticates ciphertext. IV length must match ivsize(). Raises EBADMSG on authentication failure.

Parameters:

  • iv string initialization vector
  • ciphertext_with_tag string ciphertext concatenated with authentication tag
  • aad string additional authenticated data (default: empty string) (optional)

Returns:

    string decrypted plaintext

Raises:

on authentication failure (EBADMSG), incorrect IV length, or input too short
crypto_aead:encrypt (iv, plaintext[, aad])
Encrypts plaintext with authentication. IV length must match ivsize().

Parameters:

  • iv string initialization vector
  • plaintext string data to encrypt
  • aad string additional authenticated data (default: empty string) (optional)

Returns:

    string ciphertext concatenated with authentication tag

Raises:

on encryption failure or incorrect IV length
crypto_aead:ivsize ()
Returns the required IV size in bytes.

Returns:

    integer
crypto_aead:new (algname)
Creates a new AEAD transform object.

Parameters:

  • algname string algorithm name (e.g., "gcm(aes)", "ccm(aes)")

Returns:

    crypto_aead

Raises:

on allocation failure

Usage:

    local aead = require("crypto").aead
    local cipher = aead("gcm(aes)")
crypto_aead:setauthsize (tagsize)
Sets the authentication tag size.

Parameters:

  • tagsize integer tag size in bytes

Raises:

on unsupported size
crypto_aead:setkey (key)
Sets the cipher key.

Parameters:

Raises:

on invalid key length or algorithm error
generated by LDoc 1.5.0 Last updated 2026-03-31 12:21:45