src/crypto/blake/blake2b/lane.bend
bend-collections-laws-crypto@1.0.0.0 · 34 lines · 6 definitions
1
2import Base
3import bend-collections-laws-crypto@1.0.0.0/src/crypto/blake/blake2b/types.bend as T
4
5
6def add(a: T.Lane, b: T.Lane) -> T.Lane:
7 match a b:
8 case T.W{+al,ah} T.W{bl,bh}:
9 +lo = U32.add(al,bl)
10 T.W{lo,U32.add(U32.add(ah,bh),Bool.to_u32(U32.is_lt(lo,al)))}
11
12def xor(a: T.Lane, b: T.Lane) -> T.Lane:
13 match a b:
14 case T.W{al,ah} T.W{bl,bh}: T.W{U32.xor(al,bl),U32.xor(ah,bh)}
15
16
17def rot32(a: T.Lane) -> T.Lane:
18 match a:
19 case T.W{lo,hi}: T.W{hi,lo}
20
21def rot24(a: T.Lane) -> T.Lane:
22 match a:
23 case T.W{+lo,+hi}:
24 T.W{U32.or(U32.shrn(lo,24n),U32.shln(hi,8n)),U32.or(U32.shrn(hi,24n),U32.shln(lo,8n))}
25
26def rot16(a: T.Lane) -> T.Lane:
27 match a:
28 case T.W{+lo,+hi}:
29 T.W{U32.or(U32.shrn(lo,16n),U32.shln(hi,16n)),U32.or(U32.shrn(hi,16n),U32.shln(lo,16n))}
30
31def rot63(a: T.Lane) -> T.Lane:
32 match a:
33 case T.W{+lo,+hi}:
34 T.W{U32.or(U32.shrn(hi,31n),U32.shln(lo,1n)),U32.or(U32.shrn(lo,31n),U32.shln(hi,1n))}