Module mac

mac module perform Message Authentication Code operations.

It base on EVP_MAC in OpenSSL v3.

Usage:

    hamc = require('openssl').mac
    

Info:

  • Author: george zhao <zhaozg(at)gmail.com>

Functions

new (algorithm[, properties]) create new MAC object
is_a (name) check if MAC algorithm supports a specific name
names () get all names supported by this MAC algorithm
provider () get provider name for this MAC algorithm
dup () duplicate MAC context
mac () get MAC object from MAC context
params () get or set MAC context parameters (not yet implemented)
new (alg, key[, engine]) get mac_ctx object
free () free MAC context resources
mac (digest, message, key) compute mac one step, in module openssl.hamc
update (msg) feed data to do digest
final ([last[, raw]]) get result of mac
size (msg) return size of mac value


Functions

new (algorithm[, properties])
create new MAC object

Parameters:

  • algorithm string MAC algorithm name (e.g., “HMAC”, “CMAC”, “GMAC”)
  • properties string optional properties string (optional)

Returns:

    mac or nil new MAC object or nil on failure
is_a (name)
check if MAC algorithm supports a specific name

Parameters:

  • name string algorithm name to check

Returns:

    boolean true if MAC supports the given name
names ()
get all names supported by this MAC algorithm

Returns:

    table array of supported algorithm names
provider ()
get provider name for this MAC algorithm

Returns:

    string name of the provider implementing this MAC
dup ()
duplicate MAC context

Returns:

    mac_ctx duplicated MAC context
mac ()
get MAC object from MAC context

Returns:

    mac the MAC object associated with this context
params ()
get or set MAC context parameters (not yet implemented)

Returns:

  1. nil always returns nil (NYI – Not Yet Implemented)
  2. string error message “NYI”
new (alg, key[, engine])
get mac_ctx object

Parameters:

  • alg string, integer or asn1_object name, nid or object identity
  • key string secret key
  • engine engine , nothing with default engine (optional)

Returns:

    mac_ctx object mapping MAC_CTX in openssl
free ()
free MAC context resources

Returns:

    number always returns 0
mac (digest, message, key)
compute mac one step, in module openssl.hamc

Parameters:

Returns:

    string result binary string
update (msg)
feed data to do digest

Parameters:

Returns:

    boolean result true for success
final ([last[, raw]])
get result of mac

Parameters:

  • last string last part of data (optional)
  • raw boolean binary or hex encoded result, default true for binary result (optional)

Returns:

    string val hash result
size (msg)
return size of mac value

Parameters:

Returns:

    number size of MAC value in bytes
generated by LDoc 1.5.0 Last updated 2025-09-22 19:55:54