~/bend-docscommunity

inst_cmac.bend source

inst_cmac.bend on the hub · documented module

# CMAC as a MAC: cipher-modes' CMAC (NIST SP 800-38B, RFC 4493) over any# 128-bit block cipher (~K, ~key, ~enc). The instance:#   ~K, ~key, ~CrCmac.mac(~K, ~enc), ~CrCmac.verify(~K, ~enc)# for example AES-CMAC:#   ~X.CmAesKey, ~CrAes.key, ~CrCmac.mac(~X.CmAesKey, ~X.CmAes.encrypt),#   ~CrCmac.verify(~X.CmAesKey, ~X.CmAes.encrypt)# verify is the interface's named default (mac.bend: CrMac.verify_tag), so# its laws hold for CMAC by the generic proof; cipher-modes' own# Cmac.verify does the same comparison, but no law of cipher-modes ties it# to Cmac.mac.import Baseimport bend-osdev-bytes@0.1.0.0/bytes.bend as Bimport bend-osdev-cipher-modes@0.1.0.0/cipher_modes.bend as Mimport bend-osdev-cipher-modes@0.1.0.0/cmac.bend as CMcimport ./mac.bend as Mc# the 16-byte tag of mdef CrCmac.mac(~K: Data, ~enc: K -> M.CmBlock -> M.CmBlock, k: K, m: B.Octets) -> B.Octets:  CMc.Cmac.mac(~K, ~enc, k, m)# whether t is m's tag (every byte compared)def CrCmac.verify(~K: Data, ~enc: K -> M.CmBlock -> M.CmBlock, k: K, m: B.Octets, t: B.Octets) -> Bool:  Mc.CrMac.verify_tag(~K, ~CrCmac.mac(~K, ~enc), k, m, t)