interplane.Get Omega
Read in your language

omega-mv

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

Brought by drakestapleton

branch main Branches Tags History

omega-mv / aienux / disk / sha256_bare.om

216 lines · 4307 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/disk/sha256_bare.om: Pure-Omega FIPS 180-4 SHA-256 with zero host words.
3note Compiles identically under target a64efi, target a64macos, and default Linux AArch64.
4note Constants match gpu/driver/gsp/sha2.om.
5
6global s2_ok ulong 1
7global s2_k uint 64
8global s2_h uint 8
9global s2_w uint 64
10global s2_buf uchar 64
11global s2_n ulong 1
12global s2_tot ulong 1
13global s2_out uchar 32
14
15fn s2_setup to void
16if eq get s2_ok 0 1
17ret
18end
19put s2_k 0 1116352408
20put s2_k 1 1899447441
21put s2_k 2 3049323471
22put s2_k 3 3921009573
23put s2_k 4 961987163
24put s2_k 5 1508970993
25put s2_k 6 2453635748
26put s2_k 7 2870763221
27put s2_k 8 3624381080
28put s2_k 9 310598401
29put s2_k 10 607225278
30put s2_k 11 1426881987
31put s2_k 12 1925078388
32put s2_k 13 2162078206
33put s2_k 14 2614888103
34put s2_k 15 3248222580
35put s2_k 16 3835390401
36put s2_k 17 4022224774
37put s2_k 18 264347078
38put s2_k 19 604807628
39put s2_k 20 770255983
40put s2_k 21 1249150122
41put s2_k 22 1555081692
42put s2_k 23 1996064986
43put s2_k 24 2554220882
44put s2_k 25 2821834349
45put s2_k 26 2952996808
46put s2_k 27 3210313671
47put s2_k 28 3336571891
48put s2_k 29 3584528711
49put s2_k 30 113926993
50put s2_k 31 338241895
51put s2_k 32 666307205
52put s2_k 33 773529912
53put s2_k 34 1294757372
54put s2_k 35 1396182291
55put s2_k 36 1695183700
56put s2_k 37 1986661051
57put s2_k 38 2177026350
58put s2_k 39 2456956037
59put s2_k 40 2730485921
60put s2_k 41 2820302411
61put s2_k 42 3259730800
62put s2_k 43 3345764771
63put s2_k 44 3516065817
64put s2_k 45 3600352804
65put s2_k 46 4094571909
66put s2_k 47 275423344
67put s2_k 48 430227734
68put s2_k 49 506948616
69put s2_k 50 659060556
70put s2_k 51 883997877
71put s2_k 52 958139571
72put s2_k 53 1322822218
73put s2_k 54 1537002063
74put s2_k 55 1747873779
75put s2_k 56 1955562222
76put s2_k 57 2024104815
77put s2_k 58 2227730452
78put s2_k 59 2361852424
79put s2_k 60 2428436474
80put s2_k 61 2756734187
81put s2_k 62 3204031479
82put s2_k 63 3329325298
83put s2_ok 0 1
84end
85
86fn s256_init to void
87s2_setup
88put s2_h 0 1779033703
89put s2_h 1 3144134277
90put s2_h 2 1013904242
91put s2_h 3 2773480762
92put s2_h 4 1359893119
93put s2_h 5 2600822924
94put s2_h 6 528734635
95put s2_h 7 1541459225
96put s2_n 0 0
97put s2_tot 0 0
98end
99
100fn s2_rounds to void
101a = get s2_h 0
102b = get s2_h 1
103c = get s2_h 2
104d = get s2_h 3
105e = get s2_h 4
106f = get s2_h 5
107g = get s2_h 6
108h = get s2_h 7
109for r2 ulong 64
110x2 = or shr e 6 shl e 26
111x2 = xor x2 or shr e 11 shl e 21
112x2 = xor x2 or shr e 25 shl e 7
113x2 = add x2 h
114x2 = add x2 xor and e f and not e g
115x2 = add x2 get s2_k r2
116x2 = add x2 get s2_w r2
117h = g
118g = f
119f = e
120e = add d x2
121d = c
122c = b
123b = a
124y2 = or shr b 2 shl b 30
125y2 = xor y2 or shr b 13 shl b 19
126y2 = xor y2 or shr b 22 shl b 10
127x2 = add x2 y2
128y2 = xor and b c and b d
129y2 = xor y2 and c d
130a = add x2 y2
131end
132put s2_h 0 add get s2_h 0 a
133put s2_h 1 add get s2_h 1 b
134put s2_h 2 add get s2_h 2 c
135put s2_h 3 add get s2_h 3 d
136put s2_h 4 add get s2_h 4 e
137put s2_h 5 add get s2_h 5 f
138put s2_h 6 add get s2_h 6 g
139put s2_h 7 add get s2_h 7 h
140end
141
142fn s2_compress to void
143for t ulong 16
144p = mul t 4
145v = or shl uint get s2_buf p 24 shl uint get s2_buf add p 1 16
146v = or v or shl uint get s2_buf add p 2 8 uint get s2_buf add p 3
147put s2_w t v
148end
149for u ulong 48
150i = add u 16
151x = get s2_w sub i 2
152s = or shr x 17 shl x 15
153s = xor s or shr x 19 shl x 13
154s = xor s shr x 10
155y = get s2_w sub i 15
156r = or shr y 7 shl y 25
157r = xor r or shr y 18 shl y 14
158r = xor r shr y 3
159s = add s get s2_w sub i 7
160r = add r get s2_w sub i 16
161put s2_w i add s r
162end
163s2_rounds
164end
165
166fn s256_byte b uchar to void
167n = get s2_n 0
168put s2_buf n b
169n = add n 1
170if eq n 64
171s2_compress
172n = ulong 0
173end
174put s2_n 0 n
175put s2_tot 0 add get s2_tot 0 1
176end
177
178fn s256_zeros cnt ulong to void
179i = ulong 0
180while lt i cnt bound 9223372036854775807
181s256_byte 0
182i = add i 1
183end
184end
185
186fn s256_fin to void
187bits = mul get s2_tot 0 8
188n = get s2_n 0
189put s2_buf n 128
190n = add n 1
191if gt n 56
192while lt n 64 bound 64
193put s2_buf n 0
194n = add n 1
195end
196s2_compress
197n = ulong 0
198end
199while lt n 56 bound 64
200put s2_buf n 0
201n = add n 1
202end
203for k ulong 8
204put s2_buf add 56 k uchar and shr bits mul sub 7 k 8 255
205end
206s2_compress
207put s2_n 0 0
208for j ulong 8
209w = ulong get s2_h j
210o = mul j 4
211put s2_out o uchar and shr w 24 255
212put s2_out add o 1 uchar and shr w 16 255
213put s2_out add o 2 uchar and shr w 8 255
214put s2_out add o 3 uchar and w 255
215end
216end