cryptoModule
Lua interface to the Linux Crypto API.
Crypto objects are created in a process runtime alone: in a softirq or hardirq runtime a constructor raises “‘crypto.shash’: process-context class in interrupt-context runtime”, naming its class. Errors are raised as errno names: “ENOENT” for an unknown algorithm, “EINVAL” for a wrong IV, key or state length or a block cipher input that is not a multiple ofblocksize(),
“ENOMEM” when the kernel cannot allocate the transform, and
“not enough memory” when the binding cannot allocate its own state, its output or the copy of its
input. An AEAD message that does not authenticate is no error: decrypt answers nil and
“EBADMSG” for it.
Functions
| aead (algname) | Creates an AEAD cipher transform. |
| comp (algname) | Creates a compression transform. |
| rng ([algname="stdrng"]) | Creates a random number generator and seeds it as reset does without a seed. |
| shash (algname) | Creates a synchronous hash transform. |
| skcipher (algname) | Creates a symmetric-key cipher transform. |
Functions in detail
- aead (algname)
-
Creates an AEAD cipher transform.
Only a synchronous implementation is chosen: an asynchronous one, such as a hardware engine’s
or a
cryptd(...)instance, is passed over.Parameters
- algname string algorithm name (e.g., “gcm(aes)”, “ccm(aes)”)
Returns
-
crypto_aead
Raises
“ENOENT” for an unknown algorithm or one no synchronous implementation serves (“EEXIST” on 6.12 and later for a template whose instance is asynchronous, such ascryptd(...)), “ENOMEM” or “not enough memory” on allocation failureUsage
local aead = require("crypto").aead local cipher = aead("gcm(aes)")
- comp (algname)
-
Creates a compression transform. Absent on 6.15 and later, whose kernel has no synchronous
compression API.
Parameters
- algname string algorithm name (e.g., “lz4”, “deflate”)
Returns
-
crypto_comp
Raises
“ENOENT” for an unknown algorithm, “ENOMEM” or “not enough memory” on allocation failureUsage
local comp = require("crypto").comp local c = comp("lz4")
- rng ([algname="stdrng"])
-
Creates a random number generator and seeds it as
resetdoes without a seed.Parameters
- algname string algorithm name (default "stdrng")
Returns
-
crypto_rng
Raises
“ENOENT” for an unknown algorithm, “ENOMEM” or “not enough memory” on allocation failure, or the errno of the seeding it runs at creationUsage
local rng = require("crypto").rng local r = rng()
- shash (algname)
-
Creates a synchronous hash transform.
Parameters
- algname string algorithm name (e.g., “sha256”, “hmac(sha256)”)
Returns
-
crypto_shash
Raises
“ENOENT” for an unknown algorithm, “ENOMEM” or “not enough memory” on allocation failureUsage
local shash = require("crypto").shash local h = shash("sha256")
- skcipher (algname)
-
Creates a symmetric-key cipher transform.
Only a synchronous implementation is chosen: an asynchronous one, such as a hardware engine’s
or a
cryptd(...)instance, is passed over.Parameters
- algname string algorithm name (e.g., “cbc(aes)”, “ctr(aes)”)
Returns
-
crypto_skcipher
Raises
“ENOENT” for an unknown algorithm or one no synchronous implementation serves (“EEXIST” on 6.12 and later for a template whose instance is asynchronous, such ascryptd(...)), “ENOMEM” or “not enough memory” on allocation failureUsage
local skcipher = require("crypto").skcipher local cipher = skcipher("cbc(aes)")