interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / om / cache / digest.om

252 lines · 5603 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note OM-1 bounded SHA256 adaptation of omega-mv 6999fa9e om/sha256.
3note Constants copied from filed sha256-k.dec and sha256-iv.dec; no generated constants.
4note Exact used bytes only; no identity schema and no implicit padding.
5fn kc_rotr x uint n uint to uint
6ret or shr x n shl x sub uint 32 n
7end
8fn kc_k k edit uint 64 to void
9put k 0 1116352408
10put k 1 1899447441
11put k 2 3049323471
12put k 3 3921009573
13put k 4 961987163
14put k 5 1508970993
15put k 6 2453635748
16put k 7 2870763221
17put k 8 3624381080
18put k 9 310598401
19put k 10 607225278
20put k 11 1426881987
21put k 12 1925078388
22put k 13 2162078206
23put k 14 2614888103
24put k 15 3248222580
25put k 16 3835390401
26put k 17 4022224774
27put k 18 264347078
28put k 19 604807628
29put k 20 770255983
30put k 21 1249150122
31put k 22 1555081692
32put k 23 1996064986
33put k 24 2554220882
34put k 25 2821834349
35put k 26 2952996808
36put k 27 3210313671
37put k 28 3336571891
38put k 29 3584528711
39put k 30 113926993
40put k 31 338241895
41put k 32 666307205
42put k 33 773529912
43put k 34 1294757372
44put k 35 1396182291
45put k 36 1695183700
46put k 37 1986661051
47put k 38 2177026350
48put k 39 2456956037
49put k 40 2730485921
50put k 41 2820302411
51put k 42 3259730800
52put k 43 3345764771
53put k 44 3516065817
54put k 45 3600352804
55put k 46 4094571909
56put k 47 275423344
57put k 48 430227734
58put k 49 506948616
59put k 50 659060556
60put k 51 883997877
61put k 52 958139571
62put k 53 1322822218
63put k 54 1537002063
64put k 55 1747873779
65put k 56 1955562222
66put k 57 2024104815
67put k 58 2227730452
68put k 59 2361852424
69put k 60 2428436474
70put k 61 2756734187
71put k 62 3204031479
72put k 63 3329325298
73end
74fn kc_iv s edit uint 8 to void
75put s 0 1779033703
76put s 1 3144134277
77put s 2 1013904242
78put s 3 2773480762
79put s 4 1359893119
80put s 5 2600822924
81put s 6 528734635
82put s 7 1541459225
83end
84note Full blocks are read directly, not copied or zero-filled into an artifact-sized temporary.
85fn kc_sched w edit uint 64 m view uchar 4096 o ulong to void
86q = ulong 0
87x = uint 0
88for i ulong 16
89q = add o mul i 4
90x = uint get m q
91x = or shl x 8 uint get m add q 1
92x = or shl x 8 uint get m add q 2
93put w i or shl x 8 uint get m add q 3
94end
95kc_expand w
96end
97note Fixed-array signatures require separate readers at the OM-1 production pin.
98fn kc_codesched w edit uint 64 m view uchar 16384 o ulong to void
99q = ulong 0
100x = uint 0
101for i ulong 16
102q = add o mul i 4
103x = uint get m q
104x = or shl x 8 uint get m add q 1
105x = or shl x 8 uint get m add q 2
106put w i or shl x 8 uint get m add q 3
107end
108kc_expand w
109end
110fn kc_padsched w edit uint 64 m view uchar 128 o ulong to void
111q = ulong 0
112x = uint 0
113for i ulong 16
114q = add o mul i 4
115x = uint get m q
116x = or shl x 8 uint get m add q 1
117x = or shl x 8 uint get m add q 2
118put w i or shl x 8 uint get m add q 3
119end
120kc_expand w
121end
122fn kc_expand w edit uint 64 to void
123x = uint 0
124y = uint 0
125for i ulong 48
126x = get w add i 1
127y = get w add i 14
128x = add add get w i get w add i 9 xor xor kc_rotr x 7 kc_rotr x 18 shr x 3
129put w add i 16 add x xor xor kc_rotr y 17 kc_rotr y 19 shr y 10
130end
131end
132
133note The 64 rounds on the chaining value s. uint arithmetic wraps mod 2^32.
134note Ch(e,f,g) = (e and f) xor (not e and g) is written g xor (e and (f xor g)); Maj(a,b,c) =
135note (a and b) xor (a and c) xor (b and c) is written (a and b) or (c and (a or b)). Both are bitwise
136note identities. h first becomes T1, then T1 + T2, which is the next a; the names then shift by one.
137note The sums are built a term per line and each Sigma in two lines through t: 12 names are live, and
138note omc hands out 16 registers with no spilling (error 12 under compiler-s1/s2 for longer lines).
139fn kc_rounds s edit uint 8 w view uint 64 kt view uint 64 to void
140a = get s 0
141b = get s 1
142c = get s 2
143d = get s 3
144e = get s 4
145f = get s 5
146g = get s 6
147h = get s 7
148t = uint 0
149for i ulong 64
150h = add h get kt i
151h = add h get w i
152t = xor kc_rotr e 6 kc_rotr e 11
153t = xor t kc_rotr e 25
154h = add h t
155h = add h xor g and e xor f g
156d = add d h
157t = xor kc_rotr a 2 kc_rotr a 13
158t = xor t kc_rotr a 22
159h = add h t
160t = and c or a b
161h = add h or and a b t
162t = h
163h = g
164g = f
165f = e
166e = d
167d = c
168c = b
169b = a
170a = t
171end
172put s 0 add get s 0 a
173put s 1 add get s 1 b
174put s 2 add get s 2 c
175put s 3 add get s 3 d
176put s 4 add get s 4 e
177put s 5 add get s 5 f
178put s 6 add get s 6 g
179put s 7 add get s 7 h
180end
181fn kc_output s view uint 8 dst edit uchar 32 to void
182for i ulong 8
183for j ulong 4
184q = add mul i 4 j
185v = shr get s i mul sub ulong 3 j 8
186put dst q uchar and v 255
187end
188end
189end
190fn kc_finish s edit uint 8 w edit uint 64 kt view uint 64 buf edit uchar 128 n ulong to void
191used = rem n 64
192put buf used 128
193nb = ulong 64
194if ge used 56
195nb = 128
196end
197for i ulong 8
198q = sub nb add i 1
199v = shr shl n 3 mul i 8
200put buf q uchar and v 255
201end
202kc_padsched w buf 0
203kc_rounds s w kt
204if eq nb 128
205kc_padsched w buf 64
206kc_rounds s w kt
207end
208end
209fn kc_sha data view uchar 4096 n ulong dst edit uchar 32 to int
210buf = new uchar 128 0
211s = new uint 8 0
212w = new uint 64 0
213kt = new uint 64 0
214if gt n 4096
215ret -1
216end
217kc_k kt
218kc_iv s
219for off ulong div n 64
220kc_sched w data mul off 64
221kc_rounds s w kt
222end
223base = mul div n 64 64
224for i ulong rem n 64
225put buf i get data add base i
226end
227kc_finish s w kt buf n
228kc_output s dst
229ret 0
230end
231fn kc_codesha data view uchar 16384 n ulong dst edit uchar 32 to int
232buf = new uchar 128 0
233s = new uint 8 0
234w = new uint 64 0
235kt = new uint 64 0
236if gt n 16384
237ret -1
238end
239kc_k kt
240kc_iv s
241for off ulong div n 64
242kc_codesched w data mul off 64
243kc_rounds s w kt
244end
245base = mul div n 64 64
246for i ulong rem n 64
247put buf i get data add base i
248end
249kc_finish s w kt buf n
250kc_output s dst
251ret 0
252end