Class: PasswordPing::Argon2Wrapper

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

Overview

The engine class shields users from the FFI interface. It is generally not advised to directly use this class.

Class Method Summary collapse

Class Method Details

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



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/passwordping/argon2_wrapper_ffi.rb', line 65

def self.hash_argon2d(password, salt, t_cost, m_cost, lanes, hash_length)
  result = ''
  FFI::MemoryPointer.new(:char, hash_length) do |buffer|
    ret = Ext.argon2d_hash_raw(t_cost, 1 << m_cost, lanes, password,
       password.length, salt, salt.length,
        buffer, hash_length)
    raise ArgonHashFail, ERRORS[ret.abs] unless ret.zero?
    result = buffer.read_string(hash_length)
  end
  result.unpack('H*').join
end

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



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/passwordping/argon2_wrapper_ffi.rb', line 77

def self.hash_argon2d_encode(password, salt, t_cost, m_cost, lanes, hash_length)
  result = ''
  FFI::MemoryPointer.new(:char, 96 + salt.length) do |buffer|
    ret = Ext.argon2d_hash_encoded(t_cost, 1 << m_cost, lanes, password,
       password.length, salt, salt.length,
        hash_length, buffer, 96 + salt.length)
    raise ArgonHashFail, ERRORS[ret.abs] unless ret.zero?
    result = buffer.read_string(96 + salt.length)
  end
  result.delete "\0"
end

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



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/passwordping/argon2_wrapper_ffi.rb', line 41

def self.hash_argon2i(password, salt, t_cost, m_cost, lanes, hash_length)
  result = ''
  FFI::MemoryPointer.new(:char, hash_length) do |buffer|
    ret = Ext.argon2i_hash_raw(t_cost, 1 << m_cost, lanes, password,
       password.length, salt, salt.length,
        buffer, hash_length)
    raise ArgonHashFail, ERRORS[ret.abs] unless ret.zero?
    result = buffer.read_string(hash_length)
  end
  result.unpack('H*').join
end

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



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/passwordping/argon2_wrapper_ffi.rb', line 53

def self.hash_argon2i_encode(password, salt, t_cost, m_cost, lanes, hash_length)
  result = ''
  FFI::MemoryPointer.new(:char, 96 + salt.length) do |buffer|
    ret = Ext.argon2i_hash_encoded(t_cost, 1 << m_cost, lanes, password,
       password.length, salt, salt.length,
        hash_length, buffer, 96 + salt.length)
    raise ArgonHashFail, ERRORS[ret.abs] unless ret.zero?
    result = buffer.read_string(96 + salt.length)
  end
  result.delete "\0"
end