Skip to content

Commit

Permalink
Support short Blake2b keys (fixes #87)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Oct 24, 2013
1 parent 6ad700e commit 09ef8e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rbnacl/hash/blake2b.rb
Expand Up @@ -36,7 +36,7 @@ class Blake2b
def initialize(opts = {})
@key = opts.fetch(:key, nil)
@key_size = @key ? @key.bytesize : 0
raise LengthError, "Invalid key size" if (@key_size != 0) && (@key_size < KEYBYTES_MIN || @key_size > KEYBYTES_MAX)
raise LengthError, "Invalid key size" if @key_size > KEYBYTES_MAX

@digest_size = opts.fetch(:digest_size, BYTES_MAX)
raise LengthError, "Invalid digest size" if @digest_size < BYTES_MIN || @digest_size > BYTES_MAX
Expand Down
8 changes: 7 additions & 1 deletion spec/rbnacl/hash/blake2b_spec.rb
Expand Up @@ -20,7 +20,13 @@
let(:reference_string_hash) { vector :blake2b_keyed_digest }

it "calculates keyed hashes correctly" do
RbNaCl::Hash.blake2b(reference_string, :key => reference_key).should eq reference_string_hash
RbNaCl::Hash.blake2b(reference_string, key: reference_key).should eq reference_string_hash
end

it "supports short keys" do
expect do
RbNaCl::Hash.blake2b(reference_string, key: "X")
end.to_not raise_exception
end
end
end

0 comments on commit 09ef8e5

Please sign in to comment.