Skip to content

crypto_pwhash

John Regan edited this page Mar 8, 2022 · 2 revisions

Wrapper for the crypto_pwhash functions.

https://libsodium.gitbook.io/doc/password_hashing/default_phf

Synopsis

local luasodium = require'luasodium'

local passwd = 'Correct horse battery staple'

local str = luasodium.crypto_pwhash_str(
  passwd,
  luasodium.crypto_pwhash_OPSLIMIT_SENSITIVE,
  luasodium.crypto_pwhash_MEMLIMIT_SENSITIVE)

assert(luasodium.crypto_pwhash_str_verify(str, passwd) == true)

Constants

  • luasodium.crypto_pwhash_ALG_ARGON2I13
  • luasodium.crypto_pwhash_ALG_ARGON2ID13
  • luasodium.crypto_pwhash_ALG_DEFAULT
  • luasodium.crypto_pwhash_BYTES_MAX
  • luasodium.crypto_pwhash_BYTES_MIN
  • luasodium.crypto_pwhash_MEMLIMIT_INTERACTIVE
  • luasodium.crypto_pwhash_MEMLIMIT_MAX
  • luasodium.crypto_pwhash_MEMLIMIT_MIN
  • luasodium.crypto_pwhash_MEMLIMIT_MODERATE
  • luasodium.crypto_pwhash_MEMLIMIT_SENSITIVE
  • luasodium.crypto_pwhash_OPSLIMIT_INTERACTIVE
  • luasodium.crypto_pwhash_OPSLIMIT_MAX
  • luasodium.crypto_pwhash_OPSLIMIT_MIN
  • luasodium.crypto_pwhash_OPSLIMIT_MODERATE
  • luasodium.crypto_pwhash_OPSLIMIT_SENSITIVE
  • luasodium.crypto_pwhash_PASSWD_MAX
  • luasodium.crypto_pwhash_PASSWD_MIN
  • luasodium.crypto_pwhash_SALTBYTES
  • luasodium.crypto_pwhash_STRBYTES
  • luasodium.crypto_pwhash_STRPREFIX

Functions

crypto_pwhash

syntax: string key = luasodium.crypto_pwhash(number length, string password, string salt, number opslimit, number memlimit [, number algorithm])

Derives a key that's length bytes long, from a given password and salt, with the given limit of CPU opslimit to perform and maximum memory memlimit (in bytes). An algorithm can be specified with algorithm (see the above constants for available choices).

crypto_pwhash_str

syntax: string hash = luasodium.crypto_pwhash_str(string password, number opslimit, number memlimit)

Computes an ASCII-encoded hash and returns it as hash for a given password, opslimit, and memlimit combination.

crypto_pwhash_str_verify

syntax: boolean success = luasodium.crypto_pwhash_str_verify(string hash, string password)

Verifies if hash is valid for a given password. Returns true on success.

crypto_pwhash_str_needs_rehash

syntax: boolean rehash_needed = luasodium_crypto_pwhash_str_needs_rehash(string hash, number opslimit, number memlimit)

Returns true if a given hash needs to be rehashed for a new opslimit and memlimit.

crypto_pwhash_scryptsalsa208sha256

syntax: string key = luasodium.crypto_pwhash_scryptsalsa208sha256(number length, string password, string salt, number opslimit, number memlimit)

Derives a key that's length bytes long, from a given password and salt, with the given limit of CPU opslimit to perform and maximum memory memlimit (in bytes).

crypto_pwhash_scryptsalsa208sha256_str

syntax: string hash = luasodium.crypto_pwhash_scryptsalsa208sha256_str(string password, number opslimit, number memlimit)

Computes an ASCII-encoded hash and returns it as hash for a given password, opslimit, and memlimit combination.

crypto_pwhash_scryptsalsa208sha256_str_verify

syntax: boolean success = luasodium.crypto_pwhash_scryptsalsa208sha256_str_verify(string hash, string password)

Verifies if hash is valid for a given password. Returns true on success.

crypto_pwhash_scryptsalsa208sha256_str_needs_rehash

syntax: boolean rehash_needed = luasodium_crypto_pwhash_scryptsalsa208sha256_str_needs_rehash(string hash, number opslimit, number memlimit)

Returns true if a given hash needs to be rehashed for a new opslimit and memlimit.