def CrLrw.key

bend-osdev-crypto@0.1.0.0 · lrw.bend:115

import bend-osdev-crypto@0.1.0.0/lrw.bend as Lrw
import Base
import bend-osdev-bytes@0.1.0.0/bytes.bend as B
import bend-osdev-gf@0.1.0.0/gf128.bend as G
import bend-osdev-crypto@0.1.0.0/crypto.bend as Cr

115# a raw key: the cipher's key followed by the 16-byte tweak key
116# (CrBadKeyLength for a key of 16 bytes or fewer, or one the cipher refuses)
117def CrLrw.key(~K: Data, ~key: B.Octets -> Result<&2, &2, Cr.CrError, K>, +o: B.Octets) -> Result<&2, &2, Cr.CrError, CrLrwKey<K>>:
118  +n = B.Octets.len(o)
119  do Result<&2, &2, Cr.CrError, CrLrwKey<K>>:
120    Cr.CrError.check(Nat.is_lt(16n, n), Cr.CrBadKeyLength{n})
121    k : K <- key(B.Octets.take(Nat.sub(n, 16n), o))
122    t : G.Gf128 <- cr.lrw.gf(n, G.Gf128.of_octets(B.Octets.drop(Nat.sub(n, 16n), o)))
123    return CrLrwKey{k, t}

Uses (16)

Used by (1)