lib/noise/functions/hash.rb in noise-ruby-0.1.0 vs lib/noise/functions/hash.rb in noise-ruby-0.2.0
- old
+ new
@@ -8,16 +8,20 @@
autoload :Sha256, 'noise/functions/hash/sha256'
autoload :Sha512, 'noise/functions/hash/sha512'
def self.hmac_hash(key, data, digest)
# TODO: support for blake2b, blake2s
- OpenSSL::HMAC.digest(OpenSSL::Digest.new(digest), key, data)
+ if digest.include?('SHA')
+ OpenSSL::HMAC.digest(OpenSSL::Digest.new(digest), key, data)
+ elsif digest.include?('BLAKE2b')
+ Noise::Functions::Hash::Blake2bHMAC.new(key).update(data).digest
+ end
end
def self.create_hkdf_fn(digest)
- ->(chaining_key, input_key_material, num_output) {
+ lambda do |chaining_key, input_key_material, num_output|
hkdf(chaining_key, input_key_material, num_output, digest)
- }
+ end
end
def self.hkdf(chaining_key, input_key_material, num_outputs, digest)
temp_key = hmac_hash(chaining_key, input_key_material, digest)
output1 = hmac_hash(temp_key, "\x01", digest)