Class: PasswordPing::Argon2Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/passwordping/argon2_wrapper.rb

Class Method Summary collapse

Class Method Details

.hash_argon2d(password, salt, t_cost, m_cost, lanes, hash_length) ⇒ Object

Raises:



29
30
31
32
33
34
35
# File 'lib/passwordping/argon2_wrapper.rb', line 29

def self.hash_argon2d(password, salt, t_cost, m_cost, lanes, hash_length)
  result = "\0" * hash_length;
  ret = (Argon2::Argon2.new()).argon2_raw(t_cost, 1 << m_cost, lanes, hash_length,
    password, salt, result, 0, 19);
  raise ArgonHashFail, ERRORS[ret.abs] unless ret.zero?
  result.unpack('H*').join
end

.hash_argon2d_encode(password, salt, t_cost, m_cost, lanes, hash_length) ⇒ Object

Raises:



13
14
15
16
17
18
19
# File 'lib/passwordping/argon2_wrapper.rb', line 13

def self.hash_argon2d_encode(password, salt, t_cost, m_cost, lanes, hash_length)
  result = "\0" * (96 + salt.length);
  ret = (Argon2::Argon2.new()).argon2_encoded(t_cost, 1 << m_cost, lanes, hash_length,
    password, salt, result, 0, 19);
  raise ArgonHashFail, ERRORS[ret.abs] unless ret.zero?
  result.delete "\0"
end

.hash_argon2i(password, salt, t_cost, m_cost, lanes, hash_length) ⇒ Object

Raises:



21
22
23
24
25
26
27
# File 'lib/passwordping/argon2_wrapper.rb', line 21

def self.hash_argon2i(password, salt, t_cost, m_cost, lanes, hash_length)
  result = "\0" * hash_length;
  ret = (Argon2::Argon2.new()).argon2_raw(t_cost, 1 << m_cost, lanes, hash_length,
    password, salt, result, 1, 19);
  raise ArgonHashFail, ERRORS[ret.abs] unless ret.zero?
  result.unpack('H*').join
end

.hash_argon2i_encode(password, salt, t_cost, m_cost, lanes, hash_length) ⇒ Object

Raises:



5
6
7
8
9
10
11
# File 'lib/passwordping/argon2_wrapper.rb', line 5

def self.hash_argon2i_encode(password, salt, t_cost, m_cost, lanes, hash_length)
  result = "\0" * (96 + salt.length);
  ret = (Argon2::Argon2.new()).argon2_encoded(t_cost, 1 << m_cost, lanes, hash_length,
    password, salt, result, 1, 19);
  raise ArgonHashFail, ERRORS[ret.abs] unless ret.zero?
  result.delete "\0"
end