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 / core / sha256.om

1534 lines · 35919 bytes Raw Blame History
1note Vendored from aien-dev/omega-mv@acb3f15cdc691b1b046b48b0dad0f9255a12ba4b om/sha256/sha256.om.
2note Copyright 2026 Drake Stapleton. Local source; no cross-repository build import.
3note SPDX-License-Identifier: Apache-2.0
4note sha256.om: FIPS 180-4 SHA-256 as one function-mode unit, bound through the omega-bridge native
5note call ABI (docs/NATIVE-ABI.md) and exported as omega_omsha. It replaces the algorithm of
6note src/sha256.c: the C file keeps only the sha256_* entry points that cut caller data into
7note pieces of at most 4096 bytes.
8note
9note The whole hash state lives in the caller's sha256_ctx (104 bytes, src/sha256.h):
10note bytes 0..31 state[8], uint32 little endian
11note bytes 32..39 count, uint64 little endian (bytes absorbed so far)
12note bytes 40..103 buffer, the pending partial block
13note omsha c b n op w b8:
14note op 0 init: count 0, FIPS initial hash value
15note op 1 absorb b[0..n), n <= 4096, with src/sha256.c's buffering rules
16note op 2 final: pad, absorb the bit length, the 32-byte digest packed into w[0..4)
17note op 3 one shot: the digest of the n < 4096 bytes of b8 packed into w[0..4); c is not used
18note w is the caller's scratch for the message schedule (64 words, contents ignored and overwritten):
19note Omega writes every word before reading it, so the caller need not clear it.
20note Entry refuses n > 4096 with result 3, invalid op with result 9, before state mutation.
21note The original explicit traps are represented as refusal results for the pinned bridge-seeded subset.
22
23note little-endian word of nb bytes at byte offset p of the context
24fn getle c edit uchar 104 p ulong nb ulong to ulong
25v = ulong 0
26i = nb
27while gt i 0 bound 8
28i = sub i 1
29v = or shl v 8 ulong get c add p i
30end
31ret v
32end
33
34fn putle c edit uchar 104 p ulong nb ulong v ulong to void
35x = v
36for i ulong nb
37put c add p i uchar and x 255
38x = shr x 8
39end
40end
41
42note the hash words of the context into h, and back
43fn loadh c edit uchar 104 h edit uint 8 to void
44for i ulong 8
45put h i uint getle c mul i 4 4
46end
47end
48
49fn storeh c edit uchar 104 h edit uint 8 to void
50for i ulong 8
51putle c mul i 4 4 ulong get h i
52end
53end
54
55note big-endian words of the block at byte o of b into w[0..16), then the schedule
56fn schedb b view uchar 4096 o ulong w edit ulong 64 to void
57for i ulong 16
58q = add o mul i 4
59v = ulong get b q
60v = or shl v 8 ulong get b add q 1
61v = or shl v 8 ulong get b add q 2
62v = or shl v 8 ulong get b add q 3
63put w i or v shl v 32
64end
65expand w
66end
67
68note big-endian words of the block at byte 40 of b into w[0..16), then the schedule
69fn schedc b edit uchar 104 w edit ulong 64 to void
70for i ulong 16
71q = add 40 mul i 4
72v = ulong get b q
73v = or shl v 8 ulong get b add q 1
74v = or shl v 8 ulong get b add q 2
75v = or shl v 8 ulong get b add q 3
76put w i or v shl v 32
77end
78expand w
79end
80
81note the 64 rounds, unrolled with the working words in locals (names rotate instead of moving).
82note Same lazy low-32-bit cells and rotate trick as expand; K is an immediate; the eight words are
83note reduced to 32 bits only when they are added back into h.
84fn rounds h edit uint 8 w view ulong 64 to void
85a = ulong get h 0
86b = ulong get h 1
87c = ulong get h 2
88d = ulong get h 3
89e = ulong get h 4
90f = ulong get h 5
91g = ulong get h 6
92x = ulong get h 7
93t = ulong 0
94u = ulong 0
95t = add x add get w 0 1116352408
96u = shl e 32
97u = or u shr u 32
98u = xor xor shr u 6 shr u 11 shr u 25
99t = add t u
100t = add t xor g and e xor f g
101u = shl a 32
102u = or u shr u 32
103u = xor xor shr u 2 shr u 13 shr u 22
104u = add u xor b and xor a b xor b c
105d = add d t
106x = add t u
107t = add g add get w 1 1899447441
108u = shl d 32
109u = or u shr u 32
110u = xor xor shr u 6 shr u 11 shr u 25
111t = add t u
112t = add t xor f and d xor e f
113u = shl x 32
114u = or u shr u 32
115u = xor xor shr u 2 shr u 13 shr u 22
116u = add u xor a and xor x a xor a b
117c = add c t
118g = add t u
119t = add f add get w 2 3049323471
120u = shl c 32
121u = or u shr u 32
122u = xor xor shr u 6 shr u 11 shr u 25
123t = add t u
124t = add t xor e and c xor d e
125u = shl g 32
126u = or u shr u 32
127u = xor xor shr u 2 shr u 13 shr u 22
128u = add u xor x and xor g x xor x a
129b = add b t
130f = add t u
131t = add e add get w 3 3921009573
132u = shl b 32
133u = or u shr u 32
134u = xor xor shr u 6 shr u 11 shr u 25
135t = add t u
136t = add t xor d and b xor c d
137u = shl f 32
138u = or u shr u 32
139u = xor xor shr u 2 shr u 13 shr u 22
140u = add u xor g and xor f g xor g x
141a = add a t
142e = add t u
143t = add d add get w 4 961987163
144u = shl a 32
145u = or u shr u 32
146u = xor xor shr u 6 shr u 11 shr u 25
147t = add t u
148t = add t xor c and a xor b c
149u = shl e 32
150u = or u shr u 32
151u = xor xor shr u 2 shr u 13 shr u 22
152u = add u xor f and xor e f xor f g
153x = add x t
154d = add t u
155t = add c add get w 5 1508970993
156u = shl x 32
157u = or u shr u 32
158u = xor xor shr u 6 shr u 11 shr u 25
159t = add t u
160t = add t xor b and x xor a b
161u = shl d 32
162u = or u shr u 32
163u = xor xor shr u 2 shr u 13 shr u 22
164u = add u xor e and xor d e xor e f
165g = add g t
166c = add t u
167t = add b add get w 6 2453635748
168u = shl g 32
169u = or u shr u 32
170u = xor xor shr u 6 shr u 11 shr u 25
171t = add t u
172t = add t xor a and g xor x a
173u = shl c 32
174u = or u shr u 32
175u = xor xor shr u 2 shr u 13 shr u 22
176u = add u xor d and xor c d xor d e
177f = add f t
178b = add t u
179t = add a add get w 7 2870763221
180u = shl f 32
181u = or u shr u 32
182u = xor xor shr u 6 shr u 11 shr u 25
183t = add t u
184t = add t xor x and f xor g x
185u = shl b 32
186u = or u shr u 32
187u = xor xor shr u 2 shr u 13 shr u 22
188u = add u xor c and xor b c xor c d
189e = add e t
190a = add t u
191t = add x add get w 8 3624381080
192u = shl e 32
193u = or u shr u 32
194u = xor xor shr u 6 shr u 11 shr u 25
195t = add t u
196t = add t xor g and e xor f g
197u = shl a 32
198u = or u shr u 32
199u = xor xor shr u 2 shr u 13 shr u 22
200u = add u xor b and xor a b xor b c
201d = add d t
202x = add t u
203t = add g add get w 9 310598401
204u = shl d 32
205u = or u shr u 32
206u = xor xor shr u 6 shr u 11 shr u 25
207t = add t u
208t = add t xor f and d xor e f
209u = shl x 32
210u = or u shr u 32
211u = xor xor shr u 2 shr u 13 shr u 22
212u = add u xor a and xor x a xor a b
213c = add c t
214g = add t u
215t = add f add get w 10 607225278
216u = shl c 32
217u = or u shr u 32
218u = xor xor shr u 6 shr u 11 shr u 25
219t = add t u
220t = add t xor e and c xor d e
221u = shl g 32
222u = or u shr u 32
223u = xor xor shr u 2 shr u 13 shr u 22
224u = add u xor x and xor g x xor x a
225b = add b t
226f = add t u
227t = add e add get w 11 1426881987
228u = shl b 32
229u = or u shr u 32
230u = xor xor shr u 6 shr u 11 shr u 25
231t = add t u
232t = add t xor d and b xor c d
233u = shl f 32
234u = or u shr u 32
235u = xor xor shr u 2 shr u 13 shr u 22
236u = add u xor g and xor f g xor g x
237a = add a t
238e = add t u
239t = add d add get w 12 1925078388
240u = shl a 32
241u = or u shr u 32
242u = xor xor shr u 6 shr u 11 shr u 25
243t = add t u
244t = add t xor c and a xor b c
245u = shl e 32
246u = or u shr u 32
247u = xor xor shr u 2 shr u 13 shr u 22
248u = add u xor f and xor e f xor f g
249x = add x t
250d = add t u
251t = add c add get w 13 2162078206
252u = shl x 32
253u = or u shr u 32
254u = xor xor shr u 6 shr u 11 shr u 25
255t = add t u
256t = add t xor b and x xor a b
257u = shl d 32
258u = or u shr u 32
259u = xor xor shr u 2 shr u 13 shr u 22
260u = add u xor e and xor d e xor e f
261g = add g t
262c = add t u
263t = add b add get w 14 2614888103
264u = shl g 32
265u = or u shr u 32
266u = xor xor shr u 6 shr u 11 shr u 25
267t = add t u
268t = add t xor a and g xor x a
269u = shl c 32
270u = or u shr u 32
271u = xor xor shr u 2 shr u 13 shr u 22
272u = add u xor d and xor c d xor d e
273f = add f t
274b = add t u
275t = add a add get w 15 3248222580
276u = shl f 32
277u = or u shr u 32
278u = xor xor shr u 6 shr u 11 shr u 25
279t = add t u
280t = add t xor x and f xor g x
281u = shl b 32
282u = or u shr u 32
283u = xor xor shr u 2 shr u 13 shr u 22
284u = add u xor c and xor b c xor c d
285e = add e t
286a = add t u
287t = add x add get w 16 3835390401
288u = shl e 32
289u = or u shr u 32
290u = xor xor shr u 6 shr u 11 shr u 25
291t = add t u
292t = add t xor g and e xor f g
293u = shl a 32
294u = or u shr u 32
295u = xor xor shr u 2 shr u 13 shr u 22
296u = add u xor b and xor a b xor b c
297d = add d t
298x = add t u
299t = add g add get w 17 4022224774
300u = shl d 32
301u = or u shr u 32
302u = xor xor shr u 6 shr u 11 shr u 25
303t = add t u
304t = add t xor f and d xor e f
305u = shl x 32
306u = or u shr u 32
307u = xor xor shr u 2 shr u 13 shr u 22
308u = add u xor a and xor x a xor a b
309c = add c t
310g = add t u
311t = add f add get w 18 264347078
312u = shl c 32
313u = or u shr u 32
314u = xor xor shr u 6 shr u 11 shr u 25
315t = add t u
316t = add t xor e and c xor d e
317u = shl g 32
318u = or u shr u 32
319u = xor xor shr u 2 shr u 13 shr u 22
320u = add u xor x and xor g x xor x a
321b = add b t
322f = add t u
323t = add e add get w 19 604807628
324u = shl b 32
325u = or u shr u 32
326u = xor xor shr u 6 shr u 11 shr u 25
327t = add t u
328t = add t xor d and b xor c d
329u = shl f 32
330u = or u shr u 32
331u = xor xor shr u 2 shr u 13 shr u 22
332u = add u xor g and xor f g xor g x
333a = add a t
334e = add t u
335t = add d add get w 20 770255983
336u = shl a 32
337u = or u shr u 32
338u = xor xor shr u 6 shr u 11 shr u 25
339t = add t u
340t = add t xor c and a xor b c
341u = shl e 32
342u = or u shr u 32
343u = xor xor shr u 2 shr u 13 shr u 22
344u = add u xor f and xor e f xor f g
345x = add x t
346d = add t u
347t = add c add get w 21 1249150122
348u = shl x 32
349u = or u shr u 32
350u = xor xor shr u 6 shr u 11 shr u 25
351t = add t u
352t = add t xor b and x xor a b
353u = shl d 32
354u = or u shr u 32
355u = xor xor shr u 2 shr u 13 shr u 22
356u = add u xor e and xor d e xor e f
357g = add g t
358c = add t u
359t = add b add get w 22 1555081692
360u = shl g 32
361u = or u shr u 32
362u = xor xor shr u 6 shr u 11 shr u 25
363t = add t u
364t = add t xor a and g xor x a
365u = shl c 32
366u = or u shr u 32
367u = xor xor shr u 2 shr u 13 shr u 22
368u = add u xor d and xor c d xor d e
369f = add f t
370b = add t u
371t = add a add get w 23 1996064986
372u = shl f 32
373u = or u shr u 32
374u = xor xor shr u 6 shr u 11 shr u 25
375t = add t u
376t = add t xor x and f xor g x
377u = shl b 32
378u = or u shr u 32
379u = xor xor shr u 2 shr u 13 shr u 22
380u = add u xor c and xor b c xor c d
381e = add e t
382a = add t u
383t = add x add get w 24 2554220882
384u = shl e 32
385u = or u shr u 32
386u = xor xor shr u 6 shr u 11 shr u 25
387t = add t u
388t = add t xor g and e xor f g
389u = shl a 32
390u = or u shr u 32
391u = xor xor shr u 2 shr u 13 shr u 22
392u = add u xor b and xor a b xor b c
393d = add d t
394x = add t u
395t = add g add get w 25 2821834349
396u = shl d 32
397u = or u shr u 32
398u = xor xor shr u 6 shr u 11 shr u 25
399t = add t u
400t = add t xor f and d xor e f
401u = shl x 32
402u = or u shr u 32
403u = xor xor shr u 2 shr u 13 shr u 22
404u = add u xor a and xor x a xor a b
405c = add c t
406g = add t u
407t = add f add get w 26 2952996808
408u = shl c 32
409u = or u shr u 32
410u = xor xor shr u 6 shr u 11 shr u 25
411t = add t u
412t = add t xor e and c xor d e
413u = shl g 32
414u = or u shr u 32
415u = xor xor shr u 2 shr u 13 shr u 22
416u = add u xor x and xor g x xor x a
417b = add b t
418f = add t u
419t = add e add get w 27 3210313671
420u = shl b 32
421u = or u shr u 32
422u = xor xor shr u 6 shr u 11 shr u 25
423t = add t u
424t = add t xor d and b xor c d
425u = shl f 32
426u = or u shr u 32
427u = xor xor shr u 2 shr u 13 shr u 22
428u = add u xor g and xor f g xor g x
429a = add a t
430e = add t u
431t = add d add get w 28 3336571891
432u = shl a 32
433u = or u shr u 32
434u = xor xor shr u 6 shr u 11 shr u 25
435t = add t u
436t = add t xor c and a xor b c
437u = shl e 32
438u = or u shr u 32
439u = xor xor shr u 2 shr u 13 shr u 22
440u = add u xor f and xor e f xor f g
441x = add x t
442d = add t u
443t = add c add get w 29 3584528711
444u = shl x 32
445u = or u shr u 32
446u = xor xor shr u 6 shr u 11 shr u 25
447t = add t u
448t = add t xor b and x xor a b
449u = shl d 32
450u = or u shr u 32
451u = xor xor shr u 2 shr u 13 shr u 22
452u = add u xor e and xor d e xor e f
453g = add g t
454c = add t u
455t = add b add get w 30 113926993
456u = shl g 32
457u = or u shr u 32
458u = xor xor shr u 6 shr u 11 shr u 25
459t = add t u
460t = add t xor a and g xor x a
461u = shl c 32
462u = or u shr u 32
463u = xor xor shr u 2 shr u 13 shr u 22
464u = add u xor d and xor c d xor d e
465f = add f t
466b = add t u
467t = add a add get w 31 338241895
468u = shl f 32
469u = or u shr u 32
470u = xor xor shr u 6 shr u 11 shr u 25
471t = add t u
472t = add t xor x and f xor g x
473u = shl b 32
474u = or u shr u 32
475u = xor xor shr u 2 shr u 13 shr u 22
476u = add u xor c and xor b c xor c d
477e = add e t
478a = add t u
479t = add x add get w 32 666307205
480u = shl e 32
481u = or u shr u 32
482u = xor xor shr u 6 shr u 11 shr u 25
483t = add t u
484t = add t xor g and e xor f g
485u = shl a 32
486u = or u shr u 32
487u = xor xor shr u 2 shr u 13 shr u 22
488u = add u xor b and xor a b xor b c
489d = add d t
490x = add t u
491t = add g add get w 33 773529912
492u = shl d 32
493u = or u shr u 32
494u = xor xor shr u 6 shr u 11 shr u 25
495t = add t u
496t = add t xor f and d xor e f
497u = shl x 32
498u = or u shr u 32
499u = xor xor shr u 2 shr u 13 shr u 22
500u = add u xor a and xor x a xor a b
501c = add c t
502g = add t u
503t = add f add get w 34 1294757372
504u = shl c 32
505u = or u shr u 32
506u = xor xor shr u 6 shr u 11 shr u 25
507t = add t u
508t = add t xor e and c xor d e
509u = shl g 32
510u = or u shr u 32
511u = xor xor shr u 2 shr u 13 shr u 22
512u = add u xor x and xor g x xor x a
513b = add b t
514f = add t u
515t = add e add get w 35 1396182291
516u = shl b 32
517u = or u shr u 32
518u = xor xor shr u 6 shr u 11 shr u 25
519t = add t u
520t = add t xor d and b xor c d
521u = shl f 32
522u = or u shr u 32
523u = xor xor shr u 2 shr u 13 shr u 22
524u = add u xor g and xor f g xor g x
525a = add a t
526e = add t u
527t = add d add get w 36 1695183700
528u = shl a 32
529u = or u shr u 32
530u = xor xor shr u 6 shr u 11 shr u 25
531t = add t u
532t = add t xor c and a xor b c
533u = shl e 32
534u = or u shr u 32
535u = xor xor shr u 2 shr u 13 shr u 22
536u = add u xor f and xor e f xor f g
537x = add x t
538d = add t u
539t = add c add get w 37 1986661051
540u = shl x 32
541u = or u shr u 32
542u = xor xor shr u 6 shr u 11 shr u 25
543t = add t u
544t = add t xor b and x xor a b
545u = shl d 32
546u = or u shr u 32
547u = xor xor shr u 2 shr u 13 shr u 22
548u = add u xor e and xor d e xor e f
549g = add g t
550c = add t u
551t = add b add get w 38 2177026350
552u = shl g 32
553u = or u shr u 32
554u = xor xor shr u 6 shr u 11 shr u 25
555t = add t u
556t = add t xor a and g xor x a
557u = shl c 32
558u = or u shr u 32
559u = xor xor shr u 2 shr u 13 shr u 22
560u = add u xor d and xor c d xor d e
561f = add f t
562b = add t u
563t = add a add get w 39 2456956037
564u = shl f 32
565u = or u shr u 32
566u = xor xor shr u 6 shr u 11 shr u 25
567t = add t u
568t = add t xor x and f xor g x
569u = shl b 32
570u = or u shr u 32
571u = xor xor shr u 2 shr u 13 shr u 22
572u = add u xor c and xor b c xor c d
573e = add e t
574a = add t u
575t = add x add get w 40 2730485921
576u = shl e 32
577u = or u shr u 32
578u = xor xor shr u 6 shr u 11 shr u 25
579t = add t u
580t = add t xor g and e xor f g
581u = shl a 32
582u = or u shr u 32
583u = xor xor shr u 2 shr u 13 shr u 22
584u = add u xor b and xor a b xor b c
585d = add d t
586x = add t u
587t = add g add get w 41 2820302411
588u = shl d 32
589u = or u shr u 32
590u = xor xor shr u 6 shr u 11 shr u 25
591t = add t u
592t = add t xor f and d xor e f
593u = shl x 32
594u = or u shr u 32
595u = xor xor shr u 2 shr u 13 shr u 22
596u = add u xor a and xor x a xor a b
597c = add c t
598g = add t u
599t = add f add get w 42 3259730800
600u = shl c 32
601u = or u shr u 32
602u = xor xor shr u 6 shr u 11 shr u 25
603t = add t u
604t = add t xor e and c xor d e
605u = shl g 32
606u = or u shr u 32
607u = xor xor shr u 2 shr u 13 shr u 22
608u = add u xor x and xor g x xor x a
609b = add b t
610f = add t u
611t = add e add get w 43 3345764771
612u = shl b 32
613u = or u shr u 32
614u = xor xor shr u 6 shr u 11 shr u 25
615t = add t u
616t = add t xor d and b xor c d
617u = shl f 32
618u = or u shr u 32
619u = xor xor shr u 2 shr u 13 shr u 22
620u = add u xor g and xor f g xor g x
621a = add a t
622e = add t u
623t = add d add get w 44 3516065817
624u = shl a 32
625u = or u shr u 32
626u = xor xor shr u 6 shr u 11 shr u 25
627t = add t u
628t = add t xor c and a xor b c
629u = shl e 32
630u = or u shr u 32
631u = xor xor shr u 2 shr u 13 shr u 22
632u = add u xor f and xor e f xor f g
633x = add x t
634d = add t u
635t = add c add get w 45 3600352804
636u = shl x 32
637u = or u shr u 32
638u = xor xor shr u 6 shr u 11 shr u 25
639t = add t u
640t = add t xor b and x xor a b
641u = shl d 32
642u = or u shr u 32
643u = xor xor shr u 2 shr u 13 shr u 22
644u = add u xor e and xor d e xor e f
645g = add g t
646c = add t u
647t = add b add get w 46 4094571909
648u = shl g 32
649u = or u shr u 32
650u = xor xor shr u 6 shr u 11 shr u 25
651t = add t u
652t = add t xor a and g xor x a
653u = shl c 32
654u = or u shr u 32
655u = xor xor shr u 2 shr u 13 shr u 22
656u = add u xor d and xor c d xor d e
657f = add f t
658b = add t u
659t = add a add get w 47 275423344
660u = shl f 32
661u = or u shr u 32
662u = xor xor shr u 6 shr u 11 shr u 25
663t = add t u
664t = add t xor x and f xor g x
665u = shl b 32
666u = or u shr u 32
667u = xor xor shr u 2 shr u 13 shr u 22
668u = add u xor c and xor b c xor c d
669e = add e t
670a = add t u
671t = add x add get w 48 430227734
672u = shl e 32
673u = or u shr u 32
674u = xor xor shr u 6 shr u 11 shr u 25
675t = add t u
676t = add t xor g and e xor f g
677u = shl a 32
678u = or u shr u 32
679u = xor xor shr u 2 shr u 13 shr u 22
680u = add u xor b and xor a b xor b c
681d = add d t
682x = add t u
683t = add g add get w 49 506948616
684u = shl d 32
685u = or u shr u 32
686u = xor xor shr u 6 shr u 11 shr u 25
687t = add t u
688t = add t xor f and d xor e f
689u = shl x 32
690u = or u shr u 32
691u = xor xor shr u 2 shr u 13 shr u 22
692u = add u xor a and xor x a xor a b
693c = add c t
694g = add t u
695t = add f add get w 50 659060556
696u = shl c 32
697u = or u shr u 32
698u = xor xor shr u 6 shr u 11 shr u 25
699t = add t u
700t = add t xor e and c xor d e
701u = shl g 32
702u = or u shr u 32
703u = xor xor shr u 2 shr u 13 shr u 22
704u = add u xor x and xor g x xor x a
705b = add b t
706f = add t u
707t = add e add get w 51 883997877
708u = shl b 32
709u = or u shr u 32
710u = xor xor shr u 6 shr u 11 shr u 25
711t = add t u
712t = add t xor d and b xor c d
713u = shl f 32
714u = or u shr u 32
715u = xor xor shr u 2 shr u 13 shr u 22
716u = add u xor g and xor f g xor g x
717a = add a t
718e = add t u
719t = add d add get w 52 958139571
720u = shl a 32
721u = or u shr u 32
722u = xor xor shr u 6 shr u 11 shr u 25
723t = add t u
724t = add t xor c and a xor b c
725u = shl e 32
726u = or u shr u 32
727u = xor xor shr u 2 shr u 13 shr u 22
728u = add u xor f and xor e f xor f g
729x = add x t
730d = add t u
731t = add c add get w 53 1322822218
732u = shl x 32
733u = or u shr u 32
734u = xor xor shr u 6 shr u 11 shr u 25
735t = add t u
736t = add t xor b and x xor a b
737u = shl d 32
738u = or u shr u 32
739u = xor xor shr u 2 shr u 13 shr u 22
740u = add u xor e and xor d e xor e f
741g = add g t
742c = add t u
743t = add b add get w 54 1537002063
744u = shl g 32
745u = or u shr u 32
746u = xor xor shr u 6 shr u 11 shr u 25
747t = add t u
748t = add t xor a and g xor x a
749u = shl c 32
750u = or u shr u 32
751u = xor xor shr u 2 shr u 13 shr u 22
752u = add u xor d and xor c d xor d e
753f = add f t
754b = add t u
755t = add a add get w 55 1747873779
756u = shl f 32
757u = or u shr u 32
758u = xor xor shr u 6 shr u 11 shr u 25
759t = add t u
760t = add t xor x and f xor g x
761u = shl b 32
762u = or u shr u 32
763u = xor xor shr u 2 shr u 13 shr u 22
764u = add u xor c and xor b c xor c d
765e = add e t
766a = add t u
767t = add x add get w 56 1955562222
768u = shl e 32
769u = or u shr u 32
770u = xor xor shr u 6 shr u 11 shr u 25
771t = add t u
772t = add t xor g and e xor f g
773u = shl a 32
774u = or u shr u 32
775u = xor xor shr u 2 shr u 13 shr u 22
776u = add u xor b and xor a b xor b c
777d = add d t
778x = add t u
779t = add g add get w 57 2024104815
780u = shl d 32
781u = or u shr u 32
782u = xor xor shr u 6 shr u 11 shr u 25
783t = add t u
784t = add t xor f and d xor e f
785u = shl x 32
786u = or u shr u 32
787u = xor xor shr u 2 shr u 13 shr u 22
788u = add u xor a and xor x a xor a b
789c = add c t
790g = add t u
791t = add f add get w 58 2227730452
792u = shl c 32
793u = or u shr u 32
794u = xor xor shr u 6 shr u 11 shr u 25
795t = add t u
796t = add t xor e and c xor d e
797u = shl g 32
798u = or u shr u 32
799u = xor xor shr u 2 shr u 13 shr u 22
800u = add u xor x and xor g x xor x a
801b = add b t
802f = add t u
803t = add e add get w 59 2361852424
804u = shl b 32
805u = or u shr u 32
806u = xor xor shr u 6 shr u 11 shr u 25
807t = add t u
808t = add t xor d and b xor c d
809u = shl f 32
810u = or u shr u 32
811u = xor xor shr u 2 shr u 13 shr u 22
812u = add u xor g and xor f g xor g x
813a = add a t
814e = add t u
815t = add d add get w 60 2428436474
816u = shl a 32
817u = or u shr u 32
818u = xor xor shr u 6 shr u 11 shr u 25
819t = add t u
820t = add t xor c and a xor b c
821u = shl e 32
822u = or u shr u 32
823u = xor xor shr u 2 shr u 13 shr u 22
824u = add u xor f and xor e f xor f g
825x = add x t
826d = add t u
827t = add c add get w 61 2756734187
828u = shl x 32
829u = or u shr u 32
830u = xor xor shr u 6 shr u 11 shr u 25
831t = add t u
832t = add t xor b and x xor a b
833u = shl d 32
834u = or u shr u 32
835u = xor xor shr u 2 shr u 13 shr u 22
836u = add u xor e and xor d e xor e f
837g = add g t
838c = add t u
839t = add b add get w 62 3204031479
840u = shl g 32
841u = or u shr u 32
842u = xor xor shr u 6 shr u 11 shr u 25
843t = add t u
844t = add t xor a and g xor x a
845u = shl c 32
846u = or u shr u 32
847u = xor xor shr u 2 shr u 13 shr u 22
848u = add u xor d and xor c d xor d e
849f = add f t
850b = add t u
851t = add a add get w 63 3329325298
852u = shl f 32
853u = or u shr u 32
854u = xor xor shr u 6 shr u 11 shr u 25
855t = add t u
856t = add t xor x and f xor g x
857u = shl b 32
858u = or u shr u 32
859u = xor xor shr u 2 shr u 13 shr u 22
860u = add u xor c and xor b c xor c d
861e = add e t
862a = add t u
863t = add ulong get h 0 a
864put h 0 uint and t 4294967295
865t = add ulong get h 1 b
866put h 1 uint and t 4294967295
867t = add ulong get h 2 c
868put h 2 uint and t 4294967295
869t = add ulong get h 3 d
870put h 3 uint and t 4294967295
871t = add ulong get h 4 e
872put h 4 uint and t 4294967295
873t = add ulong get h 5 f
874put h 5 uint and t 4294967295
875t = add ulong get h 6 g
876put h 6 uint and t 4294967295
877t = add ulong get h 7 x
878put h 7 uint and t 4294967295
879end
880
881fn tobuf c edit uchar 104 bi ulong b view uchar 4096 bo ulong n ulong to void
882for i ulong n
883put c add 40 add bi i get b add bo i
884end
885end
886
887note absorb b[0..n), n <= 4096, exactly as src/sha256.c sha256_update does for that piece
888fn absorb c edit uchar 104 b view uchar 4096 n ulong w edit ulong 64 to void
889h = new uint 8 0
890cnt = getle c 32 8
891bi = and cnt 63
892putle c 32 8 add cnt n
893off = ulong 0
894if gt bi 0
895lf = sub 64 bi
896if lt n lf
897tobuf c bi b 0 n
898ret
899end
900tobuf c bi b 0 lf
901loadh c h
902schedc c w
903rounds h w
904storeh c h
905off = lf
906end
907if le add off 64 n
908loadh c h
909while le add off 64 n bound 65
910schedb b off w
911rounds h w
912off = add off 64
913end
914storeh c h
915end
916tobuf c 0 b off sub n off
917end
918
919fn init c edit uchar 104 to void
920putle c 32 8 0
921putle c 0 4 1779033703
922putle c 4 4 3144134277
923putle c 8 4 1013904242
924putle c 12 4 2773480762
925putle c 16 4 1359893119
926putle c 20 4 2600822924
927putle c 24 4 528734635
928putle c 28 4 1541459225
929end
930
931note compress the context's own block buffer (bytes 40..103) into its hash words
932fn compbuf c edit uchar 104 w edit ulong 64 to void
933h = new uint 8 0
934loadh c h
935schedc c w
936rounds h w
937storeh c h
938end
939
940note zero buffer bytes s..e-1 (indices into the 64-byte block)
941fn zbuf c edit uchar 104 s ulong e ulong to void
942i = s
943while lt i e bound 64
944put c add 40 i 0
945i = add i 1
946end
947end
948
949note sha256_final of src/sha256.c, padding in place: 0x80, zeros to 56 mod 64 (one more block
950note when the pending part is 56 bytes or more), the 64-bit big-endian bit count, then the digest.
951note Preserve the public context's count and buffer state, including repeated finalization.
952fn final c edit uchar 104 w edit ulong 64 to void
953cnt = getle c 32 8
954bi = and cnt 63
955put c add 40 bi 128
956zbuf c add bi 1 64
957if ge bi 56
958compbuf c w
959zbuf c 0 56
960end
961bits = mul cnt 8
962for i ulong 8
963sh = mul sub 7 i 8
964put c add 96 i uchar and shr bits sh 255
965end
966compbuf c w
967h = new uint 8 0
968loadh c h
969digest8 h w
970total = add cnt sub 64 bi
971if ge bi 56
972total = add total 64
973end
974putle c 32 8 total
975end
976
977note IV into h
978fn initiv h edit uint 8 to void
979put h 0 uint 1779033703
980put h 1 uint 3144134277
981put h 2 uint 1013904242
982put h 3 uint 2773480762
983put h 4 uint 1359893119
984put h 5 uint 2600822924
985put h 6 uint 528734635
986put h 7 uint 1541459225
987end
988
989note expand w[0..16) into the full 64-word schedule, unrolled (constant indices need no bounds checks).
990note Every schedule word is stored duplicated, the 32-bit value in both halves (d = (x << 32) | x), so
991note a rotate right by r is the low half of d >> r and a plain shift right by n is d >> (32 + n); sums
992note are formed in the low 32 bits (add, and, xor, or need no masks) and duplicated once on store.
993fn expand w edit ulong 64 to void
994u = ulong 0
995v = ulong 0
996x = ulong 0
997x = get w 14
998u = xor xor shr x 17 shr x 19 shr x 42
999x = get w 1
1000v = xor xor shr x 7 shr x 18 shr x 35
1001u = add u v
1002u = add u get w 9
1003u = add u get w 0
1004u = shl u 32
1005put w 16 or u shr u 32
1006x = get w 15
1007u = xor xor shr x 17 shr x 19 shr x 42
1008x = get w 2
1009v = xor xor shr x 7 shr x 18 shr x 35
1010u = add u v
1011u = add u get w 10
1012u = add u get w 1
1013u = shl u 32
1014put w 17 or u shr u 32
1015x = get w 16
1016u = xor xor shr x 17 shr x 19 shr x 42
1017x = get w 3
1018v = xor xor shr x 7 shr x 18 shr x 35
1019u = add u v
1020u = add u get w 11
1021u = add u get w 2
1022u = shl u 32
1023put w 18 or u shr u 32
1024x = get w 17
1025u = xor xor shr x 17 shr x 19 shr x 42
1026x = get w 4
1027v = xor xor shr x 7 shr x 18 shr x 35
1028u = add u v
1029u = add u get w 12
1030u = add u get w 3
1031u = shl u 32
1032put w 19 or u shr u 32
1033x = get w 18
1034u = xor xor shr x 17 shr x 19 shr x 42
1035x = get w 5
1036v = xor xor shr x 7 shr x 18 shr x 35
1037u = add u v
1038u = add u get w 13
1039u = add u get w 4
1040u = shl u 32
1041put w 20 or u shr u 32
1042x = get w 19
1043u = xor xor shr x 17 shr x 19 shr x 42
1044x = get w 6
1045v = xor xor shr x 7 shr x 18 shr x 35
1046u = add u v
1047u = add u get w 14
1048u = add u get w 5
1049u = shl u 32
1050put w 21 or u shr u 32
1051x = get w 20
1052u = xor xor shr x 17 shr x 19 shr x 42
1053x = get w 7
1054v = xor xor shr x 7 shr x 18 shr x 35
1055u = add u v
1056u = add u get w 15
1057u = add u get w 6
1058u = shl u 32
1059put w 22 or u shr u 32
1060x = get w 21
1061u = xor xor shr x 17 shr x 19 shr x 42
1062x = get w 8
1063v = xor xor shr x 7 shr x 18 shr x 35
1064u = add u v
1065u = add u get w 16
1066u = add u get w 7
1067u = shl u 32
1068put w 23 or u shr u 32
1069x = get w 22
1070u = xor xor shr x 17 shr x 19 shr x 42
1071x = get w 9
1072v = xor xor shr x 7 shr x 18 shr x 35
1073u = add u v
1074u = add u get w 17
1075u = add u get w 8
1076u = shl u 32
1077put w 24 or u shr u 32
1078x = get w 23
1079u = xor xor shr x 17 shr x 19 shr x 42
1080x = get w 10
1081v = xor xor shr x 7 shr x 18 shr x 35
1082u = add u v
1083u = add u get w 18
1084u = add u get w 9
1085u = shl u 32
1086put w 25 or u shr u 32
1087x = get w 24
1088u = xor xor shr x 17 shr x 19 shr x 42
1089x = get w 11
1090v = xor xor shr x 7 shr x 18 shr x 35
1091u = add u v
1092u = add u get w 19
1093u = add u get w 10
1094u = shl u 32
1095put w 26 or u shr u 32
1096x = get w 25
1097u = xor xor shr x 17 shr x 19 shr x 42
1098x = get w 12
1099v = xor xor shr x 7 shr x 18 shr x 35
1100u = add u v
1101u = add u get w 20
1102u = add u get w 11
1103u = shl u 32
1104put w 27 or u shr u 32
1105x = get w 26
1106u = xor xor shr x 17 shr x 19 shr x 42
1107x = get w 13
1108v = xor xor shr x 7 shr x 18 shr x 35
1109u = add u v
1110u = add u get w 21
1111u = add u get w 12
1112u = shl u 32
1113put w 28 or u shr u 32
1114x = get w 27
1115u = xor xor shr x 17 shr x 19 shr x 42
1116x = get w 14
1117v = xor xor shr x 7 shr x 18 shr x 35
1118u = add u v
1119u = add u get w 22
1120u = add u get w 13
1121u = shl u 32
1122put w 29 or u shr u 32
1123x = get w 28
1124u = xor xor shr x 17 shr x 19 shr x 42
1125x = get w 15
1126v = xor xor shr x 7 shr x 18 shr x 35
1127u = add u v
1128u = add u get w 23
1129u = add u get w 14
1130u = shl u 32
1131put w 30 or u shr u 32
1132x = get w 29
1133u = xor xor shr x 17 shr x 19 shr x 42
1134x = get w 16
1135v = xor xor shr x 7 shr x 18 shr x 35
1136u = add u v
1137u = add u get w 24
1138u = add u get w 15
1139u = shl u 32
1140put w 31 or u shr u 32
1141x = get w 30
1142u = xor xor shr x 17 shr x 19 shr x 42
1143x = get w 17
1144v = xor xor shr x 7 shr x 18 shr x 35
1145u = add u v
1146u = add u get w 25
1147u = add u get w 16
1148u = shl u 32
1149put w 32 or u shr u 32
1150x = get w 31
1151u = xor xor shr x 17 shr x 19 shr x 42
1152x = get w 18
1153v = xor xor shr x 7 shr x 18 shr x 35
1154u = add u v
1155u = add u get w 26
1156u = add u get w 17
1157u = shl u 32
1158put w 33 or u shr u 32
1159x = get w 32
1160u = xor xor shr x 17 shr x 19 shr x 42
1161x = get w 19
1162v = xor xor shr x 7 shr x 18 shr x 35
1163u = add u v
1164u = add u get w 27
1165u = add u get w 18
1166u = shl u 32
1167put w 34 or u shr u 32
1168x = get w 33
1169u = xor xor shr x 17 shr x 19 shr x 42
1170x = get w 20
1171v = xor xor shr x 7 shr x 18 shr x 35
1172u = add u v
1173u = add u get w 28
1174u = add u get w 19
1175u = shl u 32
1176put w 35 or u shr u 32
1177x = get w 34
1178u = xor xor shr x 17 shr x 19 shr x 42
1179x = get w 21
1180v = xor xor shr x 7 shr x 18 shr x 35
1181u = add u v
1182u = add u get w 29
1183u = add u get w 20
1184u = shl u 32
1185put w 36 or u shr u 32
1186x = get w 35
1187u = xor xor shr x 17 shr x 19 shr x 42
1188x = get w 22
1189v = xor xor shr x 7 shr x 18 shr x 35
1190u = add u v
1191u = add u get w 30
1192u = add u get w 21
1193u = shl u 32
1194put w 37 or u shr u 32
1195x = get w 36
1196u = xor xor shr x 17 shr x 19 shr x 42
1197x = get w 23
1198v = xor xor shr x 7 shr x 18 shr x 35
1199u = add u v
1200u = add u get w 31
1201u = add u get w 22
1202u = shl u 32
1203put w 38 or u shr u 32
1204x = get w 37
1205u = xor xor shr x 17 shr x 19 shr x 42
1206x = get w 24
1207v = xor xor shr x 7 shr x 18 shr x 35
1208u = add u v
1209u = add u get w 32
1210u = add u get w 23
1211u = shl u 32
1212put w 39 or u shr u 32
1213x = get w 38
1214u = xor xor shr x 17 shr x 19 shr x 42
1215x = get w 25
1216v = xor xor shr x 7 shr x 18 shr x 35
1217u = add u v
1218u = add u get w 33
1219u = add u get w 24
1220u = shl u 32
1221put w 40 or u shr u 32
1222x = get w 39
1223u = xor xor shr x 17 shr x 19 shr x 42
1224x = get w 26
1225v = xor xor shr x 7 shr x 18 shr x 35
1226u = add u v
1227u = add u get w 34
1228u = add u get w 25
1229u = shl u 32
1230put w 41 or u shr u 32
1231x = get w 40
1232u = xor xor shr x 17 shr x 19 shr x 42
1233x = get w 27
1234v = xor xor shr x 7 shr x 18 shr x 35
1235u = add u v
1236u = add u get w 35
1237u = add u get w 26
1238u = shl u 32
1239put w 42 or u shr u 32
1240x = get w 41
1241u = xor xor shr x 17 shr x 19 shr x 42
1242x = get w 28
1243v = xor xor shr x 7 shr x 18 shr x 35
1244u = add u v
1245u = add u get w 36
1246u = add u get w 27
1247u = shl u 32
1248put w 43 or u shr u 32
1249x = get w 42
1250u = xor xor shr x 17 shr x 19 shr x 42
1251x = get w 29
1252v = xor xor shr x 7 shr x 18 shr x 35
1253u = add u v
1254u = add u get w 37
1255u = add u get w 28
1256u = shl u 32
1257put w 44 or u shr u 32
1258x = get w 43
1259u = xor xor shr x 17 shr x 19 shr x 42
1260x = get w 30
1261v = xor xor shr x 7 shr x 18 shr x 35
1262u = add u v
1263u = add u get w 38
1264u = add u get w 29
1265u = shl u 32
1266put w 45 or u shr u 32
1267x = get w 44
1268u = xor xor shr x 17 shr x 19 shr x 42
1269x = get w 31
1270v = xor xor shr x 7 shr x 18 shr x 35
1271u = add u v
1272u = add u get w 39
1273u = add u get w 30
1274u = shl u 32
1275put w 46 or u shr u 32
1276x = get w 45
1277u = xor xor shr x 17 shr x 19 shr x 42
1278x = get w 32
1279v = xor xor shr x 7 shr x 18 shr x 35
1280u = add u v
1281u = add u get w 40
1282u = add u get w 31
1283u = shl u 32
1284put w 47 or u shr u 32
1285x = get w 46
1286u = xor xor shr x 17 shr x 19 shr x 42
1287x = get w 33
1288v = xor xor shr x 7 shr x 18 shr x 35
1289u = add u v
1290u = add u get w 41
1291u = add u get w 32
1292u = shl u 32
1293put w 48 or u shr u 32
1294x = get w 47
1295u = xor xor shr x 17 shr x 19 shr x 42
1296x = get w 34
1297v = xor xor shr x 7 shr x 18 shr x 35
1298u = add u v
1299u = add u get w 42
1300u = add u get w 33
1301u = shl u 32
1302put w 49 or u shr u 32
1303x = get w 48
1304u = xor xor shr x 17 shr x 19 shr x 42
1305x = get w 35
1306v = xor xor shr x 7 shr x 18 shr x 35
1307u = add u v
1308u = add u get w 43
1309u = add u get w 34
1310u = shl u 32
1311put w 50 or u shr u 32
1312x = get w 49
1313u = xor xor shr x 17 shr x 19 shr x 42
1314x = get w 36
1315v = xor xor shr x 7 shr x 18 shr x 35
1316u = add u v
1317u = add u get w 44
1318u = add u get w 35
1319u = shl u 32
1320put w 51 or u shr u 32
1321x = get w 50
1322u = xor xor shr x 17 shr x 19 shr x 42
1323x = get w 37
1324v = xor xor shr x 7 shr x 18 shr x 35
1325u = add u v
1326u = add u get w 45
1327u = add u get w 36
1328u = shl u 32
1329put w 52 or u shr u 32
1330x = get w 51
1331u = xor xor shr x 17 shr x 19 shr x 42
1332x = get w 38
1333v = xor xor shr x 7 shr x 18 shr x 35
1334u = add u v
1335u = add u get w 46
1336u = add u get w 37
1337u = shl u 32
1338put w 53 or u shr u 32
1339x = get w 52
1340u = xor xor shr x 17 shr x 19 shr x 42
1341x = get w 39
1342v = xor xor shr x 7 shr x 18 shr x 35
1343u = add u v
1344u = add u get w 47
1345u = add u get w 38
1346u = shl u 32
1347put w 54 or u shr u 32
1348x = get w 53
1349u = xor xor shr x 17 shr x 19 shr x 42
1350x = get w 40
1351v = xor xor shr x 7 shr x 18 shr x 35
1352u = add u v
1353u = add u get w 48
1354u = add u get w 39
1355u = shl u 32
1356put w 55 or u shr u 32
1357x = get w 54
1358u = xor xor shr x 17 shr x 19 shr x 42
1359x = get w 41
1360v = xor xor shr x 7 shr x 18 shr x 35
1361u = add u v
1362u = add u get w 49
1363u = add u get w 40
1364u = shl u 32
1365put w 56 or u shr u 32
1366x = get w 55
1367u = xor xor shr x 17 shr x 19 shr x 42
1368x = get w 42
1369v = xor xor shr x 7 shr x 18 shr x 35
1370u = add u v
1371u = add u get w 50
1372u = add u get w 41
1373u = shl u 32
1374put w 57 or u shr u 32
1375x = get w 56
1376u = xor xor shr x 17 shr x 19 shr x 42
1377x = get w 43
1378v = xor xor shr x 7 shr x 18 shr x 35
1379u = add u v
1380u = add u get w 51
1381u = add u get w 42
1382u = shl u 32
1383put w 58 or u shr u 32
1384x = get w 57
1385u = xor xor shr x 17 shr x 19 shr x 42
1386x = get w 44
1387v = xor xor shr x 7 shr x 18 shr x 35
1388u = add u v
1389u = add u get w 52
1390u = add u get w 43
1391u = shl u 32
1392put w 59 or u shr u 32
1393x = get w 58
1394u = xor xor shr x 17 shr x 19 shr x 42
1395x = get w 45
1396v = xor xor shr x 7 shr x 18 shr x 35
1397u = add u v
1398u = add u get w 53
1399u = add u get w 44
1400u = shl u 32
1401put w 60 or u shr u 32
1402x = get w 59
1403u = xor xor shr x 17 shr x 19 shr x 42
1404x = get w 46
1405v = xor xor shr x 7 shr x 18 shr x 35
1406u = add u v
1407u = add u get w 54
1408u = add u get w 45
1409u = shl u 32
1410put w 61 or u shr u 32
1411x = get w 60
1412u = xor xor shr x 17 shr x 19 shr x 42
1413x = get w 47
1414v = xor xor shr x 7 shr x 18 shr x 35
1415u = add u v
1416u = add u get w 55
1417u = add u get w 46
1418u = shl u 32
1419put w 62 or u shr u 32
1420x = get w 61
1421u = xor xor shr x 17 shr x 19 shr x 42
1422x = get w 48
1423v = xor xor shr x 7 shr x 18 shr x 35
1424u = add u v
1425u = add u get w 56
1426u = add u get w 47
1427u = shl u 32
1428put w 63 or u shr u 32
1429end
1430
1431note Word access for the aligned paths. b8 is the caller's 8-byte-aligned copy of the input lent a
1432note second time as ulong cells (b views the same bytes), so one load brings 8 bytes. Swapping the
1433note bytes inside each 32-bit half (two mask-and-shift steps; the constants stay in registers) turns
1434note little-endian bytes b0..b7 into the big-endian words b0..b3 (low half) and b4..b7 (high half).
1435note Each word is stored duplicated, as expand requires.
1436fn blk8 b8 view ulong 512 q ulong w edit ulong 64 to void
1437for i ulong 8
1438x = get b8 add q i
1439y = or shl and x 71777214294589695 8 and shr x 8 71777214294589695
1440y = or shl and y 281470681808895 16 and shr y 16 281470681808895
1441j = mul i 2
1442t = shl y 32
1443put w j or t shr t 32
1444put w add j 1 or and y 18446744069414584320 shr y 32
1445end
1446end
1447
1448note the padded tail b[off..n) (less than 64 bytes), read as words through b8 (the bytes past n
1449note are inside the caller's 4096-byte copy and are masked off here): the word holding byte n keeps
1450note its k valid bytes and gets 0x80 after them, later words are zero, the 64-bit bit count goes in
1451note words 14 and 15; a second block when the tail is 56 bytes or more
1452fn tail8 h edit uint 8 b8 view ulong 512 off ulong n ulong w edit ulong 64 to void
1453blk8 b8 shr off 3 w
1454r = sub n off
1455fw = shr r 2
1456k = and r 3
1457sh = mul k 8
1458v = get w fw
1459v = and v shl 4294967295 sub 32 sh
1460v = and v 4294967295
1461v = or v shl 128 sub 24 sh
1462put w fw or v shl v 32
1463i = add fw 1
1464while lt i 16 bound 16
1465put w i 0
1466i = add i 1
1467end
1468if ge r 56
1469expand w
1470rounds h w
1471for j ulong 14
1472put w j 0
1473end
1474end
1475bits = mul n 8
1476v = shr bits 32
1477put w 14 or v shl v 32
1478v = and bits 4294967295
1479put w 15 or v shl v 32
1480expand w
1481rounds h w
1482end
1483
1484note the digest of h as 32 bytes packed little endian into w[0..4): word i holds the big-endian
1485note bytes of h[2i] then h[2i+1], so the caller copies the digest out of w with memcpy
1486fn digest8 h edit uint 8 w edit ulong 64 to void
1487for i ulong 4
1488j = mul i 2
1489x = or ulong get h j shl ulong get h add j 1 32
1490y = or shl and x 71777214294589695 8 and shr x 8 71777214294589695
1491y = or shl and y 281470681808895 16 and shr y 16 281470681808895
1492put w i y
1493end
1494end
1495
1496note SHA-256 of the n < 4096 bytes in b8, state in locals only (sha256_hash's short path)
1497fn oneshot b8 view ulong 512 n ulong w edit ulong 64 to void
1498h = new uint 8 0
1499initiv h
1500off = ulong 0
1501while le add off 64 n bound 64
1502blk8 b8 shr off 3 w
1503expand w
1504rounds h w
1505off = add off 64
1506end
1507tail8 h b8 off n w
1508digest8 h w
1509end
1510
1511note Local adaptation: bridge-seeded does not lower explicit trap statements.
1512note Return refusal codes before mutation; internal helpers are reached only through omsha.
1513fn omsha c edit uchar 104 b view uchar 4096 n ulong op ulong w edit ulong 64 b8 view ulong 512 to ulong
1514if or gt n 4096 and eq op 3 eq n 4096
1515ret 3
1516end
1517if eq op 0
1518init c
1519ret 0
1520end
1521if eq op 1
1522absorb c b n w
1523ret 0
1524end
1525if eq op 2
1526final c w
1527ret 0
1528end
1529if eq op 3
1530oneshot b8 n w
1531ret 0
1532end
1533ret 9
1534end