Skip to content

crypto_generichash

John Regan edited this page Jan 16, 2021 · 1 revision

Wrapper for the crypto_generichash functions.

https://libsodium.gitbook.io/doc/hashing/generic_hashing

Synopsis

local luasodium = require'luasodium'

local state = luasodium.crypto_generichash()

state:update('a')
state:update('message')

local hash = state:final()

Constants

  • 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

Functions

crypto_generichash

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.

crypto_generichash_init

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 to luasodium.crypto_generichash_update(userdata state, string message)
  • state:final([number size]) - equivalent to luasodium.crypto_generichash_final(userdata state [, number size])

crypto_generichash_update

syntax: boolean success = luasodium.crypto_generichash_update(userdata state, string message)

Updates userdata state with the contents of message.

crypto_generichash_final

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.

crypto_generichash_keygen

syntax: string key = luasodium.crypto_generichash_keygen()

Generates a random key with length crypto_generichash_KEYBYTES.

Clone this wiki locally