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
234
235
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)))))