Class: SequelAuth::Providers::Scrypt

Inherits:
Object
  • Object
show all
Defined in:
lib/providers/scrypt.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.key_lenObject

Key length - length in bytes of generated key, from 16 to 512.



12
13
14
# File 'lib/providers/scrypt.rb', line 12

def key_len
  @key_len ||= defaults[:key_len]
end

.max_memObject

Max memory - maximum memory usage. The minimum is always 1MB



27
28
29
# File 'lib/providers/scrypt.rb', line 27

def max_mem
  @max_mem ||= defaults[:max_mem]
end

.max_memfracObject

Max memory fraction - maximum memory out of all available. Always greater than zero and <= 0.5.



33
34
35
# File 'lib/providers/scrypt.rb', line 33

def max_memfrac
  @max_memfrac ||= defaults[:max_memfrac]
end

.max_timeObject

Max time - maximum time spent in computation



22
23
24
# File 'lib/providers/scrypt.rb', line 22

def max_time
  @max_time ||= defaults[:max_time]
end

.salt_sizeObject

Salt size - size in bytes of random salt, from 8 to 32



17
18
19
# File 'lib/providers/scrypt.rb', line 17

def salt_size
  @salt_size ||= defaults[:salt_size]
end

Class Method Details

.defaultsObject



54
55
56
57
58
59
60
61
62
# File 'lib/providers/scrypt.rb', line 54

def defaults
  {
    key_len: 32,
    salt_size: 8,
    max_time: 0.2,
    max_mem: 1024 * 1024,
    max_memfrac: 0.5
  }.freeze
end

.encrypt(password) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/providers/scrypt.rb', line 37

def encrypt(password)
  ::SCrypt::Password.create(
    password,
    key_len: key_len,
    salt_size: salt_size,
    max_mem: max_mem,
    max_memfrac: max_memfrac,
    max_time: max_time
  )
end

.matches?(hash, password) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/providers/scrypt.rb', line 48

def matches?(hash, password)
  ::SCrypt::Password.new(hash)==password
rescue ::SCrypt::Errors::InvalidHash
  false
end