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

  1. nil
  2. string Error message.
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

  1. nil
  2. string Error message.

Tables

tch.crypto.digest
Supported digest (hash) algorithms.

Fields:

  • SHA256 The SHA256 hash algorithm.
  • SHA1 The SHA1 hash algorithm.
  • MD5 The MD5 hash algorithm.
generated by LDoc 1.4.5 Last updated 2017-05-04 22:24:31