def ccm

bend-osdev-crypto@0.1.0.0 · check.bend:233

import bend-osdev-crypto@0.1.0.0/check.bend as Check
import Base
import bend-osdev-bytes@0.1.0.0/bytes.bend as B
import bend-osdev-cipher-modes@0.1.0.0/aes.bend as X
import bend-osdev-crypto@0.1.0.0/crypto.bend as Cr
import bend-osdev-crypto@0.1.0.0/aead.bend as Ae
import bend-osdev-crypto@0.1.0.0/inst_aes.bend as A
import bend-osdev-crypto@0.1.0.0/inst_ccm.bend as CC

233# CCM-AES through the AEAD interface, an m-byte tag: the sealed message, the
234# plaintext opened again, and the result of opening it with the tag's last
235# byte changed
236def ccm(~tlen: Nat, +k: B.Octets, +n: B.Octets, +a: B.Octets, +p: B.Octets) -> String:
237  +c = Ae.CrAead.seal_with(~X.CmAesKey, ~A.CrAes.key_enc, ~CC.CrCcm.seal(~X.CmAesKey, ~X.CmAes.encrypt, ~tlen), k, n, a, p)
238  +o = Result.bind(&2, &2, Cr.CrError, B.Octets, B.Octets, c, x => Ae.CrAead.open_with(~X.CmAesKey, ~A.CrAes.key_enc, ~CC.CrCcm.open(~X.CmAesKey, ~X.CmAes.encrypt, ~tlen), k, n, a, x))
239  +bad = Result.bind(&2, &2, Cr.CrError, B.Octets, B.Octets, c, x => Ae.CrAead.open_with(~X.CmAesKey, ~A.CrAes.key_enc, ~CC.CrCcm.open(~X.CmAesKey, ~X.CmAes.encrypt, ~tlen), k, n, a, flip_last(x)))
240  cat(show(c), cat(" ", cat(show(o), cat(" ", show(bad)))))

Uses (15)

Used by (1)