interplane.Get Omega
Read in your language

spark-rsi-mv

Native Rust recursive self-improvement engine with paired bootstrap evaluation and cryptographic ledger

Brought by drakestapleton

branch main Branches Tags History

spark-rsi-mv / om / p256 / sha256.om

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