Module: Crypto::PwHash::ScryptSalsa208SHA256

Extended by:
FFI::Library, Sodium::Utils
Defined in:
lib/crypto/pw_hash/scrypt_salsa208_sha256.rb

Constant Summary collapse

PRIMITIVE =
'scryptsalsa208sha256'.freeze
SALTBYTES =
saltbytes.freeze
STRBYTES =
strbytes.freeze
STRPREFIX =
strprefix.freeze
OPSLIMIT_INTERACTIVE =
opslimit_interactive.freeze
MEMLIMIT_INTERACTIVE =
memlimit_interactive.freeze
OPSLIMIT_SENSITIVE =
opslimit_sensitive.freeze
MEMLIMIT_SENSITIVE =
memlimit_sensitive.freeze

Constants included from Sodium::Utils

Sodium::Utils::HEXY, Sodium::Utils::ZERO

Class Method Summary collapse

Methods included from Sodium::Utils

bin2hex, check_length, get_size, hex2bin, zeros

Class Method Details

.crypto_pwhash_scryptsalsa208sha256_primitiveObject Also known as: primitive



18
19
20
# File 'lib/crypto/pw_hash/scrypt_salsa208_sha256.rb', line 18

def crypto_pwhash_scryptsalsa208sha256_primitive
  PRIMITIVE
end

.saltObject



47
48
49
# File 'lib/crypto/pw_hash/scrypt_salsa208_sha256.rb', line 47

def salt
  RandomBytes.buf(SALTBYTES)
end

.scryptsalsa208sha256(outlen, passwd, salt, opslimit = OPSLIMIT_INTERACTIVE, memlimit = MEMLIMIT_INTERACTIVE) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/crypto/pw_hash/scrypt_salsa208_sha256.rb', line 51

def scryptsalsa208sha256(outlen, passwd, salt, opslimit = OPSLIMIT_INTERACTIVE, memlimit = MEMLIMIT_INTERACTIVE)
  check_length(salt, SALTBYTES, :Salt)

  out = Sodium::SecretBuffer.new(outlen)
  if crypto_pwhash_scryptsalsa208sha256(out, outlen, passwd, passwd.bytesize, salt, opslimit, memlimit) == 0
    out.noaccess
    out
  else
    raise NoMemoryError, "Failed to allocate memory max size=#{memlimit} bytes", caller
  end
end

.str(passwd, opslimit = OPSLIMIT_INTERACTIVE, memlimit = MEMLIMIT_INTERACTIVE) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/crypto/pw_hash/scrypt_salsa208_sha256.rb', line 63

def str(passwd, opslimit = OPSLIMIT_INTERACTIVE, memlimit = MEMLIMIT_INTERACTIVE)
  hashed_password = zeros(STRBYTES - 1)
  if crypto_pwhash_scryptsalsa208sha256_str(hashed_password, passwd, passwd.bytesize, opslimit, memlimit) == 0
    hashed_password
  else
    raise NoMemoryError, "Failed to allocate memory max size=#{memlimit} bytes", caller
  end
end

.str_verify(str, passwd) ⇒ Object



72
73
74
75
# File 'lib/crypto/pw_hash/scrypt_salsa208_sha256.rb', line 72

def str_verify(str, passwd)
  check_length(str, STRBYTES - 1, :Str)
  crypto_pwhash_scryptsalsa208sha256_str_verify(str, passwd, passwd.bytesize) == 0
end