# File lib/hmac.rb, line 42 def set_key(key) # If key is longer than the block size, apply hash function # to key and use the result as a real key. key = @algorithm.digest(key) if key.size > @block_size akey = key.unpack("C*") key_xor_ipad = ("\x36" * @block_size).unpack("C*") key_xor_opad = ("\x5C" * @block_size).unpack("C*") for i in 0 .. akey.size - 1 key_xor_ipad[i] ^= akey[i] key_xor_opad[i] ^= akey[i] end @key_xor_ipad = key_xor_ipad.pack("C*") @key_xor_opad = key_xor_opad.pack("C*") @md = @algorithm.new @initialized = true end