inst_lc.bend
bend-osdev-crypto@0.1.0.0 · 39 lines · 4 definitions
1
2
3
4
5
6
7
8
9
10
11
12
13import Base
14import bend-osdev-bytes@0.1.0.0/bytes.bend as B
15import bend-osdev-legacy-ciphers@0.1.0.0/legacy_ciphers.bend as L
16import bend-osdev-crypto@0.1.0.0/crypto.bend as Cr
17
18def CrLc.err(e: L.LcError) -> Cr.CrError:
19 match e:
20 case L.LcBadKeyLength{n}:
21 Cr.CrBadKeyLength{n}
22 case L.LcBadIvLength{n}:
23 Cr.CrBadIvLength{n}
24 case L.LcNotBlockMultiple{n}:
25 Cr.CrNotBlockMultiple{n}
26
27
28def CrLc.lift(~A: Data, r: Result<&2, &2, L.LcError, A>) -> Result<&2, &2, Cr.CrError, A>:
29 Cr.CrError.lift(~L.LcError, ~A, ~CrLc.err, r)
30
31
32def CrLc.key(~K: Data, ~key: B.Octets -> Result<&2, &2, L.LcError, K>, o: B.Octets) -> Result<&2, &2, Cr.CrError, K>:
33 CrLc.lift(~K, key(o))
34
35
36def CrBlk64.xor(a: L.LcBlock64, b: L.LcBlock64) -> L.LcBlock64:
37 match a b:
38 case L.LcBlock64{a0, a1} L.LcBlock64{b0, b1}:
39 L.LcBlock64{U32.xor(a0, b0), U32.xor(a1, b1)}