Skip to content

Commit e08609b

Browse files
committed
Specify Argon2 version on JRuby
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).
1 parent b690a51 commit e08609b

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

lib/argon2id/extension.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ def self.hash_encoded(t_cost, m_cost, parallelism, pwd, salt, hashlen)
1515
output = Java::byte[hashlen].new
1616
params = Java::OrgBouncycastleCryptoParams::Argon2Parameters::Builder
1717
.new(Java::OrgBouncycastleCryptoParams::Argon2Parameters::ARGON2_id)
18-
.with_salt(salt_bytes)
19-
.with_parallelism(parallelism)
20-
.with_memory_as_kb(m_cost)
18+
.with_version(Java::OrgBouncycastleCryptoParams::Argon2Parameters::ARGON2_VERSION_13)
2119
.with_iterations(t_cost)
20+
.with_memory_as_kb(m_cost)
21+
.with_parallelism(parallelism)
22+
.with_salt(salt_bytes)
2223
.build
2324
generator = Java::OrgBouncycastleCryptoGenerators::Argon2BytesGenerator.new
2425

@@ -43,11 +44,11 @@ def verify(pwd)
4344
other_output = Java::byte[output.bytesize].new
4445
params = Java::OrgBouncycastleCryptoParams::Argon2Parameters::Builder
4546
.new(Java::OrgBouncycastleCryptoParams::Argon2Parameters::ARGON2_id)
46-
.with_salt(salt.to_java_bytes)
47-
.with_parallelism(parallelism)
48-
.with_memory_as_kb(m_cost)
49-
.with_iterations(t_cost)
5047
.with_version(version)
48+
.with_iterations(t_cost)
49+
.with_memory_as_kb(m_cost)
50+
.with_parallelism(parallelism)
51+
.with_salt(salt.to_java_bytes)
5152
.build
5253
generator = Java::OrgBouncycastleCryptoGenerators::Argon2BytesGenerator.new
5354
generator.init(params)

test/argon2id/test_password.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,12 @@ def test_create_password_returns_password
386386
assert_instance_of Argon2id::Password, password
387387
end
388388

389+
def test_create_password_uses_version_13
390+
password = Argon2id::Password.create("password")
391+
392+
assert_equal 0x13, password.version
393+
end
394+
389395
def test_create_password_uses_default_t_cost
390396
password = Argon2id::Password.create("password")
391397

0 commit comments

Comments
 (0)