Skip to content

Commit

Permalink
Specify Argon2 version on JRuby
Browse files Browse the repository at this point in the history
While the default version of Argon2's algorithm is currently version 13
(represented by the decimal 19 in the encoded hash), be explicit on
JRuby in case jruby-openssl ever changes so that it is consistent with
the C version.

While we're at it, re-order the parameters to match the order given to
the C API (though this doesn't actually match the order presented in the
encoded hash where memory cost precedes time cost).
  • Loading branch information
mudge committed Nov 11, 2024
1 parent b690a51 commit e08609b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/argon2id/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ def self.hash_encoded(t_cost, m_cost, parallelism, pwd, salt, hashlen)
output = Java::byte[hashlen].new
params = Java::OrgBouncycastleCryptoParams::Argon2Parameters::Builder
.new(Java::OrgBouncycastleCryptoParams::Argon2Parameters::ARGON2_id)
.with_salt(salt_bytes)
.with_parallelism(parallelism)
.with_memory_as_kb(m_cost)
.with_version(Java::OrgBouncycastleCryptoParams::Argon2Parameters::ARGON2_VERSION_13)
.with_iterations(t_cost)
.with_memory_as_kb(m_cost)
.with_parallelism(parallelism)
.with_salt(salt_bytes)
.build
generator = Java::OrgBouncycastleCryptoGenerators::Argon2BytesGenerator.new

Expand All @@ -43,11 +44,11 @@ def verify(pwd)
other_output = Java::byte[output.bytesize].new
params = Java::OrgBouncycastleCryptoParams::Argon2Parameters::Builder
.new(Java::OrgBouncycastleCryptoParams::Argon2Parameters::ARGON2_id)
.with_salt(salt.to_java_bytes)
.with_parallelism(parallelism)
.with_memory_as_kb(m_cost)
.with_iterations(t_cost)
.with_version(version)
.with_iterations(t_cost)
.with_memory_as_kb(m_cost)
.with_parallelism(parallelism)
.with_salt(salt.to_java_bytes)
.build
generator = Java::OrgBouncycastleCryptoGenerators::Argon2BytesGenerator.new
generator.init(params)
Expand Down
6 changes: 6 additions & 0 deletions test/argon2id/test_password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,12 @@ def test_create_password_returns_password
assert_instance_of Argon2id::Password, password
end

def test_create_password_uses_version_13
password = Argon2id::Password.create("password")

assert_equal 0x13, password.version
end

def test_create_password_uses_default_t_cost
password = Argon2id::Password.create("password")

Expand Down

0 comments on commit e08609b

Please sign in to comment.