Class: Argon2::Engine
- Inherits:
-
Object
- Object
- Argon2::Engine
- Defined in:
- lib/argon2/engine.rb,
lib/argon2/ffi_engine.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
- .argon2i_verify(pwd, hash, secret) ⇒ Object
- .hash_argon2i(password, salt, t_cost, m_cost) ⇒ Object
- .hash_argon2i_encode(password, salt, t_cost, m_cost, secret) ⇒ Object
- .saltgen ⇒ Object
Class Method Details
.argon2i_verify(pwd, hash, secret) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/argon2/ffi_engine.rb', line 65 def self.argon2i_verify(pwd, hash, secret) secretlen = secret.nil? ? 0 : secret.bytesize passwordlen = pwd.nil? ? 0 : pwd.bytesize ret = Ext.wrap_argon2_verify(hash, pwd, passwordlen, secret, secretlen) return false if ERRORS[ret.abs] == 'ARGON2_DECODING_FAIL' raise ArgonHashFail, ERRORS[ret.abs] unless ret.zero? true end |
.hash_argon2i(password, salt, t_cost, m_cost) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/argon2/ffi_engine.rb', line 36 def self.hash_argon2i(password, salt, t_cost, m_cost) result = '' FFI::MemoryPointer.new(:char, Constants::OUT_LEN) do |buffer| ret = Ext.argon2i_hash_raw(t_cost, 1 << m_cost, 1, password, password.length, salt, salt.length, buffer, Constants::OUT_LEN) raise ArgonHashFail, ERRORS[ret.abs] unless ret.zero? result = buffer.read_string(Constants::OUT_LEN) end result.unpack('H*').join end |
.hash_argon2i_encode(password, salt, t_cost, m_cost, secret) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/argon2/ffi_engine.rb', line 48 def self.hash_argon2i_encode(password, salt, t_cost, m_cost, secret) result = '' secretlen = secret.nil? ? 0 : secret.bytesize passwordlen = password.nil? ? 0 : password.bytesize if salt.length != Constants::SALT_LEN raise ArgonHashFail, "Invalid salt size" end FFI::MemoryPointer.new(:char, Constants::ENCODE_LEN) do |buffer| ret = Ext.argon2_wrap(buffer, password, passwordlen, salt, salt.length, t_cost, (1 << m_cost), 1, secret, secretlen) raise ArgonHashFail, ERRORS[ret.abs] unless ret.zero? result = buffer.read_string(Constants::ENCODE_LEN) end result.delete "\0" end |
.saltgen ⇒ Object
7 8 9 |
# File 'lib/argon2/engine.rb', line 7 def self.saltgen SecureRandom.random_bytes(Argon2::Constants::SALT_LEN) end |