buffer.bend
0x3bdc0c9f5265bb49f7fc76b61f529f24 · 17 lines · 0 definitions
1import Base
2import 0x3bdc0c9f5265bb49f7fc76b61f529f24/state.bend as S
3import 0x3bdc0c9f5265bb49f7fc76b61f529f24/packed.bend as P
4
5# Exactly eight big-endian U32 words (32 bytes), with no list allocation.
6def digest(s: S.State) -> Array<U32>:
7 match s:
8 case S.H{a,b,c,d,e,f,g,h}:
9 ANode{ANode{ANode{ALeaf{a},ALeaf{b}},ANode{ALeaf{c},ALeaf{d}}},ANode{ANode{ALeaf{e},ALeaf{f}},ANode{ALeaf{g},ALeaf{h}}}}
10
11def result(r: Maybe<&2,S.State>) -> Maybe<&1,Array<U32>>:
12 match r:
13 case None{}: None{}
14 case Some{s}: Some{digest(s)}
15
16def sha256(input: Array<U32>, length: Nat) -> Maybe<&1,Array<U32>>:
17 result(P.hash(input,length))