Sha256: fd6f71a428f2b916e9af7c4952e2a86a37bfd367e28b6e89b7d05a0709290f30

Contents?: true

Size: 789 Bytes

Versions: 1

Compression:

Stored size: 789 Bytes

Contents

module GostKuznyechik
  class KuznyechikKeyExpImp < Kuznyechik
    def self.export(key, key_mac, key_enc, iv)
      mac = KuznyechikOmac.new(key_mac, BlockLengthInBytes).update(iv+key).final
      ctr = KuznyechikCtr.new(key_enc, iv, BlockLengthInBytes)
      encr_key = ctr.encrypt(key)
      encr_mac = ctr.encrypt(mac)
      encr_key += encr_mac
    end
    
    def self.import(encr_key, key_mac, key_enc, iv)
      buf = KuznyechikCtr.new(key_enc, iv, BlockLengthInBytes).decrypt(encr_key)
      decr_key = buf[0...-BlockLengthInBytes]
      decr_mac = buf[decr_key.length..-1]
      mac = KuznyechikOmac.new(key_mac, BlockLengthInBytes).update(iv+decr_key).final
      if mac != decr_mac then
        decr_key = nil
      end
      decr_key
    end
  end
end  

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gost_kuznyechik-0.1.1 lib/gost_kuznyechik/kuznyechik_key_exp_imp.rb