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 / cert-sha384.om

333 lines · 9177 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Modified 2026-10-25: SHA384 from aien-dev/omnet om/sha512/sha512.om.
3note Source a14ff7efc94ea56530a61e0d91675dc970e7d806; file SHA256
4note 069a54b75484221bc7dbacfbea744ca9002c295f4f34f2c3905b0776450e3ce2.
5note SHA384 IV per FIPS180-4 section 5.3.4; only first48 output bytes are SHA384.
6note Compression/padding reused; names cs384, no signing. CERT-APACHE-LICENSE applies.
7note SPDX-License-Identifier: Apache-2.0
8note sha512.om: SHA-512 (FIPS 180-4 section 6.4) as a library unit: functions only, no main, no
9note globals. Every function name starts with cs384.
10note
11note API (one shot):
12note fn cs384hash m view uchar 65536 n ulong o edit uchar 64 to void
13note writes SHA-512(m[0..n)) as 64 bytes to o[0..64); n > 65536 traps 3.
14note fn cs384pre p view uchar 64 m view uchar 65536 n ulong o edit uchar 64 to void
15note writes SHA-512(p[0..64) || m[0..n)) to o[0..64); n > 65536 traps 3.
16note
17note Words are ulong (64-bit unsigned, wrapping add is the mod 2^64 addition of FIPS 180-4 section 3.2).
18note Omega has no rotate word, so ROTR^r(x) = (x >> r) | (x << (64 - r)) (FIPS 180-4 section 3.2 item 4).
19note Not constant-time audited.
20
21note K{512}[0..80): first 64 bits of the fractional parts of the cube roots of the first 80 primes
22note (FIPS 180-4 section 4.2.3)
23fn cs384k k edit ulong 80 to void
24put k 0 4794697086780616226
25put k 1 8158064640168781261
26put k 2 13096744586834688815
27put k 3 16840607885511220156
28put k 4 4131703408338449720
29put k 5 6480981068601479193
30put k 6 10538285296894168987
31put k 7 12329834152419229976
32put k 8 15566598209576043074
33put k 9 1334009975649890238
34put k 10 2608012711638119052
35put k 11 6128411473006802146
36put k 12 8268148722764581231
37put k 13 9286055187155687089
38put k 14 11230858885718282805
39put k 15 13951009754708518548
40put k 16 16472876342353939154
41put k 17 17275323862435702243
42put k 18 1135362057144423861
43put k 19 2597628984639134821
44put k 20 3308224258029322869
45put k 21 5365058923640841347
46put k 22 6679025012923562964
47put k 23 8573033837759648693
48put k 24 10970295158949994411
49put k 25 12119686244451234320
50put k 26 12683024718118986047
51put k 27 13788192230050041572
52put k 28 14330467153632333762
53put k 29 15395433587784984357
54put k 30 489312712824947311
55put k 31 1452737877330783856
56put k 32 2861767655752347644
57put k 33 3322285676063803686
58put k 34 5560940570517711597
59put k 35 5996557281743188959
60put k 36 7280758554555802590
61put k 37 8532644243296465576
62put k 38 9350256976987008742
63put k 39 10552545826968843579
64put k 40 11727347734174303076
65put k 41 12113106623233404929
66put k 42 14000437183269869457
67put k 43 14369950271660146224
68put k 44 15101387698204529176
69put k 45 15463397548674623760
70put k 46 17586052441742319658
71put k 47 1182934255886127544
72put k 48 1847814050463011016
73put k 49 2177327727835720531
74put k 50 2830643537854262169
75put k 51 3796741975233480872
76put k 52 4115178125766777443
77put k 53 5681478168544905931
78put k 54 6601373596472566643
79put k 55 7507060721942968483
80put k 56 8399075790359081724
81put k 57 8693463985226723168
82put k 58 9568029438360202098
83put k 59 10144078919501101548
84put k 60 10430055236837252648
85put k 61 11840083180663258601
86put k 62 13761210420658862357
87put k 63 14299343276471374635
88put k 64 14566680578165727644
89put k 65 15097957966210449927
90put k 66 16922976911328602910
91put k 67 17689382322260857208
92put k 68 500013540394364858
93put k 69 748580250866718886
94put k 70 1242879168328830382
95put k 71 1977374033974150939
96put k 72 2944078676154940804
97put k 73 3659926193048069267
98put k 74 4368137639120453308
99put k 75 4836135668995329356
100put k 76 5532061633213252278
101put k 77 6448918945643986474
102put k 78 6902733635092675308
103put k 79 7801388544844847127
104end
105
106note H(0) for SHA-512: first 64 bits of the fractional parts of the square roots of the first 8 primes
107note (FIPS 180-4 section 5.3.5)
108fn cs384iv h edit ulong 8 to void
109put h 0 14680500436340154072
110put h 1 7105036623409894663
111put h 2 10473403895298186519
112put h 3 1526699215303891257
113put h 4 7436329637833083697
114put h 5 10282925794625328401
115put h 6 15784041429090275239
116put h 7 5167115440072839076
117end
118
119note upper-case Sigma0{512}(x) = ROTR^28 ^ ROTR^34 ^ ROTR^39 (FIPS 180-4 section 4.1.3, (4.10))
120fn cs384bs0 x ulong to ulong
121r = or shr x 28 shl x 36
122r = xor r or shr x 34 shl x 30
123r = xor r or shr x 39 shl x 25
124ret r
125end
126
127note upper-case Sigma1{512}(x) = ROTR^14 ^ ROTR^18 ^ ROTR^41 (section 4.1.3, (4.11))
128fn cs384bs1 x ulong to ulong
129r = or shr x 14 shl x 50
130r = xor r or shr x 18 shl x 46
131r = xor r or shr x 41 shl x 23
132ret r
133end
134
135note lower-case sigma0{512}(x) = ROTR^1 ^ ROTR^8 ^ SHR^7 (section 4.1.3, (4.12))
136fn cs384ss0 x ulong to ulong
137r = or shr x 1 shl x 63
138r = xor r or shr x 8 shl x 56
139r = xor r shr x 7
140ret r
141end
142
143note lower-case sigma1{512}(x) = ROTR^19 ^ ROTR^61 ^ SHR^6 (section 4.1.3, (4.13))
144fn cs384ss1 x ulong to ulong
145r = or shr x 19 shl x 45
146r = xor r or shr x 61 shl x 3
147r = xor r shr x 6
148ret r
149end
150
151note Ch(x,y,z) = (x and y) xor (not x and z), written as z xor (x and (y xor z)) (section 4.1.3, (4.8))
152fn cs384ch x ulong y ulong z ulong to ulong
153ret xor z and x xor y z
154end
155
156note Maj(x,y,z) = (x and y) xor (x and z) xor (y and z), written as (x and y) or (z and (x or y))
157note (section 4.1.3, (4.9))
158fn cs384mj x ulong y ulong z ulong to ulong
159ret or and x y and z or x y
160end
161
162note big-endian 64-bit word of the 8 bytes at m[q..q+8) (section 3.1 item 3)
163fn cs384bem m view uchar 65536 q ulong to ulong
164v = ulong 0
165for j ulong 8
166v = or shl v 8 ulong get m add q j
167end
168ret v
169end
170
171note the same for the 256-byte padding buffer
172fn cs384bep p view uchar 256 q ulong to ulong
173v = ulong 0
174for j ulong 8
175v = or shl v 8 ulong get p add q j
176end
177ret v
178end
179
180note the same for the 64-byte prefix
181fn cs384bex p view uchar 64 q ulong to ulong
182v = ulong 0
183for j ulong 8
184v = or shl v 8 ulong get p add q j
185end
186ret v
187end
188
189note message block M(i) at byte o of the stream p[0..pl) || m into w[0..16) (section 6.4.2 step 1,
190note t = 0..15). pl is 0 or 64 and o is a multiple of 128, so every word lies wholly in p or in m.
191fn cs384ldm p view uchar 64 pl ulong m view uchar 65536 o ulong w edit ulong 80 to void
192for i ulong 16
193q = add o mul i 8
194if lt q pl
195put w i cs384bex p q
196else
197put w i cs384bem m sub q pl
198end
199end
200end
201
202note the block at byte o of the padding buffer pb into w[0..16)
203fn cs384ldp pb view uchar 256 o ulong w edit ulong 80 to void
204for i ulong 16
205put w i cs384bep pb add o mul i 8
206end
207end
208
209note one SHA-512 compression (section 6.4.2 steps 1-4); w[0..16) holds the block on entry
210fn cs384blk h edit ulong 8 w edit ulong 80 k view ulong 80 to void
211for i ulong 64
212t = add i 16
213v = cs384ss1 get w sub t 2
214v = add v get w sub t 7
215v = add v cs384ss0 get w sub t 15
216v = add v get w i
217put w t v
218end
219a = get h 0
220b = get h 1
221c = get h 2
222d = get h 3
223e = get h 4
224f = get h 5
225g = get h 6
226x = get h 7
227for i ulong 80
228t = add x cs384bs1 e
229t = add t cs384ch e f g
230t = add t get k i
231t = add t get w i
232u = add cs384bs0 a cs384mj a b c
233x = g
234g = f
235f = e
236e = add d t
237d = c
238c = b
239b = a
240a = add t u
241end
242put h 0 add get h 0 a
243put h 1 add get h 1 b
244put h 2 add get h 2 c
245put h 3 add get h 3 d
246put h 4 add get h 4 e
247put h 5 add get h 5 f
248put h 6 add get h 6 g
249put h 7 add get h 7 x
250end
251
252note Padding (section 5.1.2) of the stream p[0..pl) || m, tot bytes long, whose bytes from off on
253note (fewer than 128) are not yet compressed: they go to pb[0..r), then one 1 bit (byte 128), zero bytes
254note up to 112 mod 128, then l = 8 * tot as a 128-bit big-endian integer. pb must be all zero on entry.
255note Returns the padded length, 128 when r < 112, else 256. The upper 64 bits of l are always 0 here
256note because tot <= 65600.
257fn cs384pad p view uchar 64 pl ulong m view uchar 65536 off ulong tot ulong pb edit uchar 256 to ulong
258r = sub tot off
259for i ulong r
260q = add off i
261if lt q pl
262put pb i get p q
263else
264put pb i get m sub q pl
265end
266end
267put pb r 128
268e = ulong 128
269if ge r 112
270e = 256
271end
272cs384len pb e mul tot 8
273ret e
274end
275
276note the low 64 bits of the 128-bit big-endian length field ending at pb[e-1]
277fn cs384len pb edit uchar 256 e ulong bits ulong to void
278for i ulong 8
279y = sub sub e 1 i
280put pb y uchar and shr bits mul i 8 255
281end
282end
283
284note H(N) as the 64-byte big-endian digest (section 6.4.2, final hash value)
285fn cs384out h view ulong 8 o edit uchar 64 to void
286for i ulong 8
287v = get h i
288for j ulong 8
289put o add mul i 8 j uchar and shr v mul sub 7 j 8 255
290end
291end
292end
293
294note SHA-512 of the stream p[0..pl) || m[0..n), pl 0 or 64 (else trap 3), n <= 65536 (else trap 3),
295note digest to o[0..64).
296fn cs384core p view uchar 64 pl ulong m view uchar 65536 n ulong o edit uchar 64 to void
297if gt n 65536
298trap 3
299end
300if ne pl 0
301if ne pl 64
302trap 3
303end
304end
305h = new ulong 8 0
306w = new ulong 80 0
307k = new ulong 80 0
308pb = new uchar 256 0
309cs384k k
310cs384iv h
311tot = add pl n
312off = ulong 0
313while le add off 128 tot bound 514
314cs384ldm p pl m off w
315cs384blk h w k
316off = add off 128
317end
318e = cs384pad p pl m off tot pb
319cs384ldp pb 0 w
320cs384blk h w k
321if eq e 256
322cs384ldp pb 128 w
323cs384blk h w k
324end
325cs384out h o
326end
327
328note SHA-512(m[0..n)), n <= 65536 (else trap 3), digest to o[0..64)
329fn cs384hash m view uchar 65536 n ulong o edit uchar 64 to void
330z = new uchar 64 0
331cs384core z 0 m n o
332end
333