interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / gpu / nvidia / om / components / cm_digest.om

61 lines · 1225 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note Reuses om/cache/digest.om's SHA-256 schedule, constants, rounds and padding.
3note Mode 0 initializes; mode 1 consumes 64 bytes; mode 2 finishes tail state[9] and writes data[0:32].
4note State[0:8] is the chaining value and state[8] is consumed bytes. Mode 3 compares data[0:32] and [32:64].
5fn cm_sha_output s view uint 8 data edit uchar 128 to void
6for i ulong 8
7for j ulong 4
8q = add mul i 4 j
9v = shr get s i mul sub ulong 3 j 8
10put data q uchar and v 255
11end
12end
13end
14fn cm_digest mode ulong state edit ulong 16 data edit uchar 128 to ulong
15if eq mode 3
16for i ulong 32
17if ne get data i get data add 32 i
18ret 0
19end
20end
21ret 1
22end
23s = new uint 8 0
24if eq mode 0
25kc_iv s
26for i ulong 8
27put state i ulong get s i
28end
29put state 8 ulong 0
30ret 0
31end
32for i ulong 8
33put s i uint get state i
34end
35w = new uint 64 0
36kt = new uint 64 0
37kc_k kt
38if eq mode 1
39kc_padsched w data 0
40kc_rounds s w kt
41put state 8 add get state 8 64
42else
43used = get state 9
44if ge used 64
45ret 1
46end
47n = add get state 8 used
48for i ulong 128
49if ge i used
50put data i uchar 0
51end
52end
53kc_finish s w kt data n
54cm_sha_output s data
55put state 8 n
56end
57for i ulong 8
58put state i ulong get s i
59end
60ret 0
61end