interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / omega / allen / vendor / sha256-core.om

179 lines · 3345 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-or-later
2note SHA256 core reused byte-for-byte from native Omega TRN1 at 12251e3403d42931ada27dc1c54b3b610954be5d.
3note Reads stdin up to 8 MiB and emits lowercase hex plus LF only after successful EOF.
4global Buf uchar 8192
5global H uint 8
6global Vv uint 8
7global W uint 64
8global K uint 64
9global Hb uchar 64
10global Hs ulong 2
11global Hash uchar 32
12global Out uchar 65
13text Hex "0123456789abcdef"
14
15fn rotate x uint n uint to uint
16ret or shr x n shl x sub 32 n
17end
18
19fn round i ulong to void
20e = get Vv 4
21a = get Vv 0
22s = xor xor rotate e 6 rotate e 11 rotate e 25
23c = xor and e get Vv 5 and not e get Vv 6
24t = add add get Vv 7 s add c add get K i get W i
25s = xor xor rotate a 2 rotate a 13 rotate a 22
26c = and a get Vv 1
27c = xor c and a get Vv 2
28c = xor c and get Vv 1 get Vv 2
29u = add s c
30put Vv 7 get Vv 6
31put Vv 6 get Vv 5
32put Vv 5 e
33put Vv 4 add get Vv 3 t
34put Vv 3 get Vv 2
35put Vv 2 get Vv 1
36put Vv 1 a
37put Vv 0 add t u
38end
39
40fn block to void
41for i ulong 16
42x = uint 0
43for j ulong 4
44x = or shl x 8 uint get Hb add mul i 4 j
45end
46put W i x
47end
48for j ulong 48
49i = add j 16
50x = get W sub i 15
51y = get W sub i 2
52s = xor xor rotate x 7 rotate x 18 shr x 3
53t = xor xor rotate y 17 rotate y 19 shr y 10
54put W i add add get W sub i 16 s add get W sub i 7 t
55end
56for i ulong 8
57put Vv i get H i
58end
59for i ulong 64
60round i
61end
62for i ulong 8
63put H i add get H i get Vv i
64end
65end
66
67fn hinit to void
68put H 0 1779033703
69put H 1 3144134277
70put H 2 1013904242
71put H 3 2773480762
72put H 4 1359893119
73put H 5 2600822924
74put H 6 528734635
75put H 7 1541459225
76put Hs 0 0
77put Hs 1 0
78end
79
80fn hbyte c uchar to void
81p = get Hs 0
82put Hb p c
83p = add p 1
84put Hs 1 add get Hs 1 1
85if eq p 64
86block
87p = 0
88end
89put Hs 0 p
90end
91
92fn update off ulong count ulong to void
93for i ulong count
94hbyte get Buf add off i
95end
96end
97
98fn finish to void
99bits = mul get Hs 1 8
100hbyte 128
101while ne get Hs 0 56
102hbyte 0
103end
104for i ulong 8
105hbyte uchar and shr bits mul sub 7 i 8 255
106end
107for i ulong 32
108x = get H div i 4
109put Hash i uchar and shr x uint mul sub 3 rem i 4 8 255
110end
111end
112
113fn constants to void
114put K 0 1116352408
115put K 1 1899447441
116put K 2 3049323471
117put K 3 3921009573
118put K 4 961987163
119put K 5 1508970993
120put K 6 2453635748
121put K 7 2870763221
122put K 8 3624381080
123put K 9 310598401
124put K 10 607225278
125put K 11 1426881987
126put K 12 1925078388
127put K 13 2162078206
128put K 14 2614888103
129put K 15 3248222580
130put K 16 3835390401
131put K 17 4022224774
132put K 18 264347078
133put K 19 604807628
134put K 20 770255983
135put K 21 1249150122
136put K 22 1555081692
137put K 23 1996064986
138put K 24 2554220882
139put K 25 2821834349
140put K 26 2952996808
141put K 27 3210313671
142put K 28 3336571891
143put K 29 3584528711
144put K 30 113926993
145put K 31 338241895
146put K 32 666307205
147put K 33 773529912
148put K 34 1294757372
149put K 35 1396182291
150put K 36 1695183700
151put K 37 1986661051
152put K 38 2177026350
153put K 39 2456956037
154put K 40 2730485921
155put K 41 2820302411
156put K 42 3259730800
157put K 43 3345764771
158put K 44 3516065817
159put K 45 3600352804
160put K 46 4094571909
161put K 47 275423344
162put K 48 430227734
163put K 49 506948616
164put K 50 659060556
165put K 51 883997877
166put K 52 958139571
167put K 53 1322822218
168put K 54 1537002063
169put K 55 1747873779
170put K 56 1955562222
171put K 57 2024104815
172put K 58 2227730452
173put K 59 2361852424
174put K 60 2428436474
175put K 61 2756734187
176put K 62 3204031479
177put K 63 3329325298
178end
179