Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ext/mri/bcrypt_pbkdf_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ static VALUE cBCryptPbkdfEngine;
*/
static VALUE bc_crypt_pbkdf(VALUE self, VALUE pass, VALUE salt, VALUE keylen, VALUE rounds) {
size_t okeylen = NUM2ULONG(keylen);
unsigned int rounds_value = NUM2UINT(rounds);
if (okeylen == 0 || okeylen > 1024)
return Qnil;
u_int8_t* okey = xmalloc(okeylen);
Expand All @@ -17,7 +18,7 @@ static VALUE bc_crypt_pbkdf(VALUE self, VALUE pass, VALUE salt, VALUE keylen, VA
StringValuePtr(pass), RSTRING_LEN(pass),
(const u_int8_t*)StringValuePtr(salt), RSTRING_LEN(salt),
okey, okeylen,
NUM2ULONG(rounds));
rounds_value);
if (ret < 0) {
xfree(okey);
return Qnil;
Expand Down
9 changes: 9 additions & 0 deletions test/bcrypt_pnkdf/engine_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ def test_invalid_pbkdf_arguments_return_nil
assert_nil BCryptPbkdf::Engine.__bc_crypt_pbkdf('pass', 'salt', 1025, 1)
end

def test_rounds_must_fit_the_native_range
assert_raises(RangeError) do
BCryptPbkdf::Engine.__bc_crypt_pbkdf('pass', 'salt', 32, (1 << 32) + 1)
end
assert_raises(TypeError) do
BCryptPbkdf::Engine.__bc_crypt_pbkdf('pass', 'salt', 32, Object.new)
end
end

def test_hash_argument_lengths
sha2pass = OpenSSL::Digest.digest('SHA512', 'pass')
sha2salt = OpenSSL::Digest.digest('SHA512', 'salt')
Expand Down