-
Notifications
You must be signed in to change notification settings - Fork 0
crypto_generichash
Wrapper for the crypto_generichash
functions.
https://libsodium.gitbook.io/doc/hashing/generic_hashing
local luasodium = require'luasodium'
local state = luasodium.crypto_generichash()
state:update('a')
state:update('message')
local hash = state:final()
luasodium.crypto_generichash_BYTES
luasodium.crypto_generichash_BYTES_MIN
luasodium.crypto_generichash_BYTES_MAX
luasodium.crypto_generichash_KEYBYTES
luasodium.crypto_generichash_KEYBYTES_MIN
luasodium.crypto_generichash_KEYBYTES_MAX
syntax: string hash = luasodium.crypto_generichash(string message [, string key, number size])
Generates a hash for a given message
.
Accepts an optional key
with a
length between
crypto_generichash_KEYBYTES_MIN
and
crypto_generichash_KEYBYTES_MAX
.
Accepts an optional size
with a value
between
luasodium.crypto_generichash_BYTES_MIN
and
luasodium.crypto_generichash_BYTES_MAX
.
If no size is given, defaults to luasodium.crypto_generichahs_BYTES
.
syntax: userdata state = luasodium.crypto_generichash_init([string key, number size])
Generates an object for computing a hash with multiple chunks.
Accepts an optional key
with a
length between
crypto_generichash_KEYBYTES_MIN
and
crypto_generichash_KEYBYTES_MAX
.
Accepts an optional size
with a value
between
luasodium.crypto_generichash_BYTES_MIN
and
luasodium.crypto_generichash_BYTES_MAX
.
If no size is given, defaults to luasodium.crypto_generichahs_BYTES
.
Returned userdata has a metatable allowing object-oriented message:
-
state:update(string message)
- equivalent toluasodium.crypto_generichash_update(userdata state, string message)
-
state:final([number size])
- equivalent toluasodium.crypto_generichash_final(userdata state [, number size])
syntax: boolean success = luasodium.crypto_generichash_update(userdata state, string message)
Updates userdata state
with the contents of message
.
syntax: string hash = luasodium.crypto_generichash_final(userdata state [, number size])
Computes and returns the final hash
for a given state
.
Accepts an optional size
value, between crypto_generichash_BYTES_MIN
and
crypto_generichash_BYTES_MAX
.
syntax: string key = luasodium.crypto_generichash_keygen()
Generates a random key
with length crypto_generichash_KEYBYTES
.