Lunatik

crypto_aeadClass

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

Methods

crypto_aead:algname () Returns the driver-independent name of the algorithm the transform was allocated with.
crypto_aead:authsize () Returns the authentication tag size in bytes.
crypto_aead:close () Releases the transform.
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:setauthsize (tagsize) Sets the authentication tag size.
crypto_aead:setkey (key) Sets the cipher key.

Methods in detail

crypto_aead:algname ()
Returns the driver-independent name of the algorithm the transform was allocated with.

Returns

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

Returns

    integer
crypto_aead:close ()
Releases the transform. A to-be-closed variable holding the object releases it the same way. Calling it again does nothing, and every other method raises “closed object” afterwards.

Returns

    nil
crypto_aead:decrypt (iv, ciphertext_with_tag[, aad])
Decrypts and authenticates ciphertext. IV length must match ivsize(). A message that does not authenticate, a forged or corrupted one, is the outcome the call reports, as nil and “EBADMSG”.

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, or nil and “EBADMSG” when the tag does not authenticate the message or the input is shorter than the tag

Raises

on incorrect IV length, “not enough memory” when one kmalloc block cannot be allocated for the associated data and the ciphertext, always past KMALLOC_MAX_SIZE
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, “not enough memory” when one kmalloc block cannot be allocated for the associated data, the plaintext and the tag, always past KMALLOC_MAX_SIZE
crypto_aead:ivsize ()
Returns the required IV size in bytes.

Returns

    integer
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