Sha256: ce0892871d440975a3685ab6a77a5eeb49cfb52ed623c9849d8815a88d9ae660

Contents?: true

Size: 754 Bytes

Versions: 1

Compression:

Stored size: 754 Bytes

Contents

module GostMagma
  class MagmaKeyExpImp < Magma
    def self.export(key, key_mac, key_enc, iv)
      mac = MagmaOmac.new(key_mac, BlockLengthInBytes).update(iv+key).final
      ctr = MagmaCtr.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 = MagmaCtr.new(key_enc, iv, BlockLengthInBytes).decrypt(encr_key)
      decr_key = buf[0...-BlockLengthInBytes]
      decr_mac = buf[decr_key.length..-1]
      mac = MagmaOmac.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_magma-0.1.1 lib/gost_magma/magma_key_exp_imp.rb