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 / tls-p384.om

471 lines · 10324 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Modified 2026-10-25: public verification subset of aien-dev/spark-rsi-mv om/p256/p256.om (P256 arithmetic adapted to P384).
3note Source commit bba3877510daeb8a0e070a781a689bcf1952b6f6, SHA256
4note 92da68007af091ccfbe01aa845be779502130e02bf57e9550332d669905db958.
5note Adapted to P384, names prefixed cp3/C3, digest supplied by caller; signing, HMAC, nonce and private-key APIs removed.
6note Public ECDSA inputs only. 32-bit-limb Montgomery arithmetic and complete a=-3 point addition.
7note Renes-Costello-Batina 2015 algorithm 4; SEC2 v2 section 2.5.1 parameters.
8note Byte buffer: key3072 (97 bytes), raw signature3200 (96), prehash3296 (48).
9note No secret-key or constant-time compiler claim. Apache license in CERT-APACHE-LICENSE.
10
11const C3MP ulong 0
12const C3MN ulong 72
13const C3ONE1 ulong 144
14const C3BM ulong 156
15const C3GX ulong 180
16const C3W1 ulong 240
17const C3W2 ulong 252
18const C3XX ulong 264
19const C3YY ulong 276
20const C3ZZ ulong 288
21const C3XY ulong 300
22const C3YZ ulong 312
23const C3XZ ulong 324
24const C3U ulong 336
25const C3V ulong 348
26const C3YM ulong 360
27const C3YP ulong 372
28const C3BX3 ulong 384
29const C3XX3 ulong 396
30const C3ZZ3 ulong 408
31const C3RX ulong 420
32const C3ACC ulong 456
33const C3TMP ulong 492
34const C3BASE ulong 528
35const C3ZI ulong 564
36const C3Z ulong 792
37const C3R ulong 804
38const C3S ulong 816
39const C3U1 ulong 828
40const C3U2 ulong 840
41const C3T1 ulong 864
42const C3T2 ulong 876
43const C3T3 ulong 888
44const C3X ulong 912
45const C3Y ulong 924
46const C3Q ulong 960
47const C3P1 ulong 996
48const C3P2 ulong 1032
49const C3BPUB ulong 3072
50const C3BSIG ulong 3200
51const C3BDIG ulong 3296
52
53fn cp3cpy w edit ulong 1536 o ulong a ulong to void
54for i ulong 12
55put w add o i get w add a i
56end
57end
58
59fn cp3pcpy w edit ulong 1536 o ulong a ulong to void
60for i ulong 36
61put w add o i get w add a i
62end
63end
64
65fn cp3set w edit ulong 1536 o ulong v ulong to void
66put w o v
67for i ulong 11
68put w add o add i 1 0
69end
70end
71
72fn cp3red w edit ulong 1536 o ulong t view ulong 14 m ulong to void
73u = new ulong 12 0
74bw = ulong 0
75x = ulong 0
76for i ulong 12
77x = sub sub get t i get w add m i bw
78put u i and x 4294967295
79bw = shr x 63
80end
81sel = or get t 12 xor bw 1
82mk = sub 0 sel
83for j ulong 12
84y = and get u j mk
85put w add o j or y and get t j not mk
86end
87end
88
89fn cp3mrow t edit ulong 14 w edit ulong 1536 a ulong bi ulong to void
90c = ulong 0
91x = ulong 0
92for j ulong 12
93x = add add get t j mul get w add a j bi c
94put t j and x 4294967295
95c = shr x 32
96end
97x = add get t 12 c
98put t 12 and x 4294967295
99put t 13 shr x 32
100end
101
102fn cp3mred t edit ulong 14 w edit ulong 1536 m ulong to void
103q = and mul get t 0 get w add m 12 4294967295
104x = add get t 0 mul q get w m
105c = shr x 32
106j1 = ulong 0
107for k ulong 11
108j1 = add k 1
109x = add add get t j1 mul q get w add m j1 c
110put t k and x 4294967295
111c = shr x 32
112end
113x = add get t 12 c
114put t 11 and x 4294967295
115put t 12 add get t 13 shr x 32
116end
117
118fn cp3mul w edit ulong 1536 o ulong a ulong b ulong m ulong to void
119t = new ulong 14 0
120for i ulong 12
121cp3mrow t w a get w add b i
122cp3mred t w m
123end
124cp3red w o t m
125end
126
127fn cp3add w edit ulong 1536 o ulong a ulong b ulong m ulong to void
128t = new ulong 14 0
129c = ulong 0
130x = ulong 0
131for i ulong 12
132x = add add get w add a i get w add b i c
133put t i and x 4294967295
134c = shr x 32
135end
136put t 12 c
137cp3red w o t m
138end
139
140fn cp3sub w edit ulong 1536 o ulong a ulong b ulong m ulong to void
141t = new ulong 12 0
142bw = ulong 0
143x = ulong 0
144for i ulong 12
145x = sub sub get w add a i get w add b i bw
146put t i and x 4294967295
147bw = shr x 63
148end
149mk = sub 0 bw
150c = ulong 0
151for j ulong 12
152x = add add get t j and get w add m j mk c
153put w add o j and x 4294967295
154c = shr x 32
155end
156end
157
158fn cp3modr w edit ulong 1536 o ulong m ulong to void
159t = new ulong 14 0
160for i ulong 12
161put t i get w add o i
162end
163cp3red w o t m
164end
165
166fn cp3lt w edit ulong 1536 a ulong m ulong to bool
167bw = ulong 0
168x = ulong 0
169for i ulong 12
170x = sub sub get w add a i get w add m i bw
171bw = shr x 63
172end
173ret eq bw 1
174end
175
176fn cp3isz w edit ulong 1536 a ulong to bool
177v = ulong 0
178for i ulong 12
179v = or v get w add a i
180end
181ret eq v 0
182end
183
184fn cp3eqv w edit ulong 1536 a ulong b ulong to bool
185v = ulong 0
186for i ulong 12
187v = or v xor get w add a i get w add b i
188end
189ret eq v 0
190end
191
192fn cp3rng w edit ulong 1536 a ulong to bool
193ret and not cp3isz w a cp3lt w a C3MN
194end
195
196fn cp3pow w edit ulong 1536 o ulong a ulong e ulong m ulong to void
197cp3cpy w C3W2 a
198cp3cpy w C3W1 add m 36
199i = ulong 0
200bit = ulong 0
201for j ulong 384
202i = sub 383 j
203cp3mul w C3W1 C3W1 C3W1 m
204bit = and shr get w add e shr i 5 and i 31 1
205if eq bit 1
206cp3mul w C3W1 C3W1 C3W2 m
207end
208end
209cp3cpy w o C3W1
210end
211
212fn cp3inv w edit ulong 1536 o ulong a ulong m ulong to void
213cp3pow w o a add m 48 m
214end
215
216fn cp3tom w edit ulong 1536 o ulong a ulong m ulong to void
217cp3mul w o a add m 24 m
218end
219
220fn cp3frm w edit ulong 1536 o ulong a ulong m ulong to void
221cp3mul w o a C3ONE1 m
222end
223
224fn cp3mod w edit ulong 1536 m ulong to void
225m0 = get w m
226x = m0
227for i ulong 5
228x = mul x sub 2 mul m0 x
229end
230put w add m 12 and sub 0 x 4294967295
231cp3set w add m 24 1
232for j ulong 768
233cp3add w add m 24 add m 24 add m 24 m
234end
235cp3mul w add m 36 C3ONE1 add m 24 m
236cp3cpy w add m 48 m
237put w add m 48 sub get w add m 48 2
238end
239
240fn cp3init w edit ulong 1536 to void
241for i ulong 1536
242put w i 0
243end
244put w 0 4294967295
245put w 1 0
246put w 2 0
247put w 3 4294967295
248put w 4 4294967294
249put w 5 4294967295
250put w 6 4294967295
251put w 7 4294967295
252put w 8 4294967295
253put w 9 4294967295
254put w 10 4294967295
255put w 11 4294967295
256put w 72 3435473267
257put w 73 3974895978
258put w 74 1219536762
259put w 75 1478102450
260put w 76 4097256927
261put w 77 3345173889
262put w 78 4294967295
263put w 79 4294967295
264put w 80 4294967295
265put w 81 4294967295
266put w 82 4294967295
267put w 83 4294967295
268put w C3ONE1 1
269cp3mod w C3MP
270cp3mod w C3MN
271put w 864 3555470063
272put w 865 713410797
273put w 866 2318324125
274put w 867 3327539597
275put w 868 1343457114
276put w 869 51644559
277put w 870 4269883666
278put w 871 404593774
279put w 872 3824692505
280put w 873 2559444331
281put w 874 3795773412
282put w 875 3006345127
283cp3tom w C3BM C3T1 C3MP
284put w 864 1920338615
285put w 865 978607672
286put w 866 3210029420
287put w 867 1426256477
288put w 868 2186553912
289put w 869 1509376480
290put w 870 2343017368
291put w 871 1847409506
292put w 872 4079005044
293put w 873 2394015518
294put w 874 3196781879
295put w 875 2861025826
296cp3tom w C3GX C3T1 C3MP
297put w 864 2431258207
298put w 865 2051218812
299put w 866 494829981
300put w 867 174109134
301put w 868 3052452032
302put w 869 3923390739
303put w 870 681186428
304put w 871 4176747965
305put w 872 2459098153
306put w 873 1570674879
307put w 874 2519084143
308put w 875 907533898
309cp3tom w add C3GX 12 C3T1 C3MP
310cp3cpy w add C3GX 24 add C3MP 36
311cp3set w C3T1 0
312end
313
314fn cp3padd w edit ulong 1536 o ulong a ulong q ulong to void
315cp3mul w C3XX a q C3MP
316cp3mul w C3YY add a 12 add q 12 C3MP
317cp3mul w C3ZZ add a 24 add q 24 C3MP
318cp3add w C3U a add a 12 C3MP
319cp3add w C3V q add q 12 C3MP
320cp3mul w C3XY C3U C3V C3MP
321cp3add w C3U C3XX C3YY C3MP
322cp3sub w C3XY C3XY C3U C3MP
323cp3add w C3U add a 12 add a 24 C3MP
324cp3add w C3V add q 12 add q 24 C3MP
325cp3mul w C3YZ C3U C3V C3MP
326cp3add w C3U C3YY C3ZZ C3MP
327cp3sub w C3YZ C3YZ C3U C3MP
328cp3add w C3U a add a 24 C3MP
329cp3add w C3V q add q 24 C3MP
330cp3mul w C3XZ C3U C3V C3MP
331cp3add w C3U C3XX C3ZZ C3MP
332cp3sub w C3XZ C3XZ C3U C3MP
333note bzz3 = 3 (xz - b zz); ym = yy - bzz3; yp = yy + bzz3
334cp3mul w C3U C3BM C3ZZ C3MP
335cp3sub w C3U C3XZ C3U C3MP
336cp3add w C3V C3U C3U C3MP
337cp3add w C3U C3V C3U C3MP
338cp3sub w C3YM C3YY C3U C3MP
339cp3add w C3YP C3YY C3U C3MP
340note zz3 = 3 zz; bxz3 = 3 (b xz - (zz3 + xx)); xx3 = 3 xx - zz3
341cp3add w C3ZZ3 C3ZZ C3ZZ C3MP
342cp3add w C3ZZ3 C3ZZ3 C3ZZ C3MP
343cp3mul w C3U C3BM C3XZ C3MP
344cp3add w C3V C3ZZ3 C3XX C3MP
345cp3sub w C3U C3U C3V C3MP
346cp3add w C3V C3U C3U C3MP
347cp3add w C3BX3 C3V C3U C3MP
348cp3add w C3V C3XX C3XX C3MP
349cp3add w C3V C3V C3XX C3MP
350cp3sub w C3XX3 C3V C3ZZ3 C3MP
351note X3 = yp xy - yz bxz3; Y3 = yp ym + xx3 bxz3; Z3 = ym yz + xy xx3
352cp3mul w C3U C3YP C3XY C3MP
353cp3mul w C3V C3YZ C3BX3 C3MP
354cp3sub w C3RX C3U C3V C3MP
355cp3mul w C3U C3YP C3YM C3MP
356cp3mul w C3V C3XX3 C3BX3 C3MP
357cp3add w add C3RX 12 C3U C3V C3MP
358cp3mul w C3U C3YM C3YZ C3MP
359cp3mul w C3V C3XY C3XX3 C3MP
360cp3add w add C3RX 24 C3U C3V C3MP
361cp3pcpy w o C3RX
362end
363
364fn cp3psel w edit ulong 1536 bit ulong to void
365mk = sub 0 bit
366nm = not mk
367for c ulong 36
368y = and get w add C3TMP c mk
369put w add C3ACC c or y and get w add C3ACC c nm
370end
371end
372
373fn cp3smul w edit ulong 1536 o ulong k ulong p ulong to void
374cp3pcpy w C3BASE p
375cp3set w C3ACC 0
376cp3cpy w add C3ACC 12 add C3MP 36
377cp3set w add C3ACC 24 0
378i = ulong 0
379for j ulong 384
380i = sub 383 j
381cp3padd w C3ACC C3ACC C3ACC
382cp3padd w C3TMP C3ACC C3BASE
383cp3psel w and shr get w add k shr i 5 and i 31 1
384end
385cp3pcpy w o C3ACC
386end
387
388fn cp3aff w edit ulong 1536 x ulong y ulong p ulong to void
389cp3inv w C3ZI add p 24 C3MP
390cp3mul w x p C3ZI C3MP
391cp3frm w x x C3MP
392cp3mul w y add p 12 C3ZI C3MP
393cp3frm w y y C3MP
394end
395
396fn cp3ld w edit ulong 1536 o ulong b edit uchar 4096 off ulong to void
397q = ulong 0
398v = ulong 0
399for i ulong 12
400q = add off sub 44 mul i 4
401v = ulong get b q
402v = or shl v 8 ulong get b add q 1
403v = or shl v 8 ulong get b add q 2
404v = or shl v 8 ulong get b add q 3
405put w add o i v
406end
407end
408
409fn cp3oncv w edit ulong 1536 to bool
410if not cp3lt w C3X C3MP
411ret false
412end
413if not cp3lt w C3Y C3MP
414ret false
415end
416cp3tom w C3T1 C3X C3MP
417cp3tom w C3T2 C3Y C3MP
418cp3mul w C3T3 C3T2 C3T2 C3MP
419cp3mul w C3T2 C3T1 C3T1 C3MP
420cp3mul w C3T2 C3T2 C3T1 C3MP
421cp3sub w C3T2 C3T2 C3T1 C3MP
422cp3sub w C3T2 C3T2 C3T1 C3MP
423cp3sub w C3T2 C3T2 C3T1 C3MP
424cp3add w C3T2 C3T2 C3BM C3MP
425ret cp3eqv w C3T2 C3T3
426end
427
428fn cp3vrfy w edit ulong 1536 b edit uchar 4096 to ulong
429if ne get b C3BPUB 4
430ret 0
431end
432cp3ld w C3X b add C3BPUB 1
433cp3ld w C3Y b add C3BPUB 49
434if not cp3oncv w
435ret 0
436end
437cp3ld w C3R b C3BSIG
438cp3ld w C3S b add C3BSIG 48
439if not cp3rng w C3R
440ret 0
441end
442if not cp3rng w C3S
443ret 0
444end
445cp3ld w C3Z b C3BDIG
446cp3modr w C3Z C3MN
447cp3tom w C3T1 C3S C3MN
448cp3inv w C3T1 C3T1 C3MN
449cp3tom w C3T2 C3Z C3MN
450cp3mul w C3U1 C3T2 C3T1 C3MN
451cp3frm w C3U1 C3U1 C3MN
452cp3tom w C3T2 C3R C3MN
453cp3mul w C3U2 C3T2 C3T1 C3MN
454cp3frm w C3U2 C3U2 C3MN
455cp3tom w C3Q C3X C3MP
456cp3tom w add C3Q 12 C3Y C3MP
457cp3cpy w add C3Q 24 add C3MP 36
458cp3smul w C3P1 C3U1 C3GX
459cp3smul w C3P2 C3U2 C3Q
460cp3padd w C3P1 C3P1 C3P2
461if cp3isz w add C3P1 24
462ret 0
463end
464cp3aff w C3X C3Y C3P1
465cp3modr w C3X C3MN
466if cp3eqv w C3X C3R
467ret 1
468end
469ret 0
470end
471