Module tch.crypto.digest
Lua C module exposing digest functions.
Usage:
local digest = require("tch.crypto.digest") local hmac = digest.hmac(digest.SHA256, "key", "data") local sig_OK = digest.verify(digest.SHA256, "pubkey.pem", "signature.sig", "checksums")
Functions
hmac(digest, key, data) | Calculate a message authentication code (MAC) for the given data using a keyed hash function. |
verify(digest, pubkey_file, signature_file, data_file) | Verify the signature for the given algorithm, public key and data using the given digest algorithm. |
Tables
tch.crypto.digest | Supported digest (hash) algorithms. |
Functions
- hmac(digest, key, data)
-
Calculate a message authentication code (MAC) for the given data using a keyed hash function.
Parameters:
- digest
int
One of the
TCH_DIGEST_*
constants indicating the digest (hash) algorithm to use. - key string The key to use.
- data string The data over which to calculate the MAC.
Returns:
-
string
The calculated MAC in hexstring format.
Or
- nil
- string Error message.
- digest
int
One of the
- verify(digest, pubkey_file, signature_file, data_file)
-
Verify the signature for the given algorithm, public key and
data using the given digest algorithm.
Parameters:
- digest
int
One of the
TCH_DIGEST_*
constants indicating the digest (hash) algorithm to use. - pubkey_file string Location of the file containing the public key in PEM format.
- signature_file string Location of the file containing the signature.
- data_file string Location of the file containing the data to verify.
Returns:
-
boolean
True if verification succeeded.
Or
- nil
- string Error message.
- digest
int
One of the