Class: IOTA::Crypto::Hmac

Inherits:
Object
  • Object
show all
Defined in:
lib/iota/crypto/hmac.rb

Constant Summary collapse

ROUNDS =
27

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Hmac

Returns a new instance of Hmac.



6
7
8
# File 'lib/iota/crypto/hmac.rb', line 6

def initialize(key)
  @key = Converter.trits(key)
end

Instance Method Details

#addHMAC(bundle) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/iota/crypto/hmac.rb', line 10

def addHMAC(bundle)
  curl = Curl.new(ROUNDS)
  (0...bundle.bundle.length).step(1) do |i|
    if bundle.bundle[i].value > 0
      bundleHashTrits = Converter.trits(bundle.bundle[i].bundle)
      hmac = Array.new(243, 0)
      curl.reset
      curl.absorb(@key)
      curl.absorb(bundleHashTrits)
      curl.squeeze(hmac)
      hmacTrytes = Converter.trytes(hmac)
      bundle.bundle[i].signatureMessageFragment = hmacTrytes + bundle.bundle[i].signatureMessageFragment[81...2187]
    end
  end
end