class GostHmac::Hmac
Public Class Methods
new(key, hmac_size)
click to toggle source
# File lib/gost_hmac/hmac.rb, line 8 def initialize(key, hmac_size) @dgst_size = hmac_size key_len = key.length if key_len <= 64 then standard_key = self.class.zeroBytes(64) standard_key[0...key_len] = key else standard_key = Gost3411.new(64).update(key).final end @ipad = standard_key.dup @opad = standard_key.dup (0...64).each do |i| @ipad[i] = (@ipad[i].ord ^ 0x36).chr @opad[i] = (@opad[i].ord ^ 0x5c).chr end @dgst_ctx = Gost3411.new(@dgst_size) @dgst_ctx.update(@ipad) end
Protected Class Methods
printBytes(bytes, line_size = 16)
click to toggle source
# File lib/gost_hmac/hmac.rb, line 46 def self.printBytes(bytes, line_size = 16) bytes.unpack('H*')[0].scan(/.{1,#{line_size}}/).each{|s| puts(s)} end
zeroBytes(n)
click to toggle source
# File lib/gost_hmac/hmac.rb, line 50 def self.zeroBytes(n) ("\x00"*n).force_encoding('BINARY') end
Public Instance Methods
final()
click to toggle source
# File lib/gost_hmac/hmac.rb, line 32 def final hmac_buf = @dgst_ctx.final hmac = Gost3411.new(@dgst_size).update(@opad).update(hmac_buf).final hmac end
reset()
click to toggle source
# File lib/gost_hmac/hmac.rb, line 38 def reset @dgst_ctx = Gost3411.new(@dgst_size) @dgst_ctx.update(@ipad) return self end
update(data)
click to toggle source
# File lib/gost_hmac/hmac.rb, line 27 def update(data) @dgst_ctx.update(data) return self end