Skip to content

Commit b97bfaa

Browse files
authored
Use libsodium constants for scrypt params (#231)
1 parent 3e8d8f8 commit b97bfaa

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

lib/rbnacl/password_hash.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ module PasswordHash
3232
# @raise [CryptoError] If calculating the digest fails for some reason.
3333
#
3434
# @return [String] The scrypt digest as raw bytes
35-
def self.scrypt(password, salt, opslimit, memlimit, digest_size = 64)
35+
def self.scrypt(password, salt, opslimit = SCrypt::OPSLIMIT_SENSITIVE, memlimit = SCrypt::MEMLIMIT_SENSITIVE,
36+
digest_size = 64)
3637
SCrypt.new(opslimit, memlimit, digest_size).digest(password, salt)
3738
end
3839

lib/rbnacl/password_hash/scrypt.rb

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class SCrypt
2323
sodium_primitive :scryptsalsa208sha256
2424

2525
sodium_constant :SALTBYTES
26+
sodium_constant :OPSLIMIT_SENSITIVE
27+
sodium_constant :MEMLIMIT_SENSITIVE
2628

2729
sodium_function :scrypt,
2830
:crypto_pwhash_scryptsalsa208sha256,

lib/rbnacl/test_vectors.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ module RbNaCl
120120
"82ad86b83c8f20a23dbb74f6da60b0b6ecffd67134d45946ac8ebfb3064294bc" \
121121
"097d43ced68642bfb8bbbdd0f50b30118f5e",
122122
scrypt_salt: "39d82eef32010b8b79cc5ba88ed539fbaba741100f2edbeca7cc171ffeabf258",
123-
scrypt_opslimit: 758_010,
124-
scrypt_memlimit: 5_432_947,
125-
scrypt_digest: "bcc5c2fd785e4781d1201ed43d84925537e2a540d3de55f5812f29e9dd0a4a00" \
126-
"451a5c8ddbb4862c03d45c75bf91b7fb49265feb667ad5c899fdbf2ca19eac67",
123+
scrypt_opslimit: 33_554_432,
124+
scrypt_memlimit: 1_073_741_824,
125+
scrypt_digest: "11a4c60b98411758ba9e89a28587c074ae674c367326c79a999e415110b14460" \
126+
"5921bd3c897098a837fa40d9eef5338268754ea5e243f630a58fa698df95d1ed",
127127

128128
# argon2 vectors
129129
# from libsodium/test/default/pwhash_argon2i.c

spec/rbnacl/password_hash/scrypt_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,13 @@
1818

1919
expect(digest).to eq reference_digest
2020
end
21+
22+
it "calculates the correct digest using libsodium primitives" do
23+
digest = RbNaCl::PasswordHash.scrypt(
24+
reference_password,
25+
reference_salt
26+
)
27+
28+
expect(digest).to eq reference_digest
29+
end
2130
end

0 commit comments

Comments
 (0)