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 / allen / vendor / cert-p256.om

447 lines · 9762 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.
3note Source commit bba3877510daeb8a0e070a781a689bcf1952b6f6, SHA256
4note 92da68007af091ccfbe01aa845be779502130e02bf57e9550332d669905db958.
5note Names prefixed cp2/C2, 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.4.2 parameters.
8note Byte buffer: key3072 (65 bytes), raw signature3200 (64), prehash3296 (32).
9note No secret-key or constant-time compiler claim. Apache license in CERT-APACHE-LICENSE.
10
11const C2MP ulong 0
12const C2MN ulong 48
13const C2ONE1 ulong 96
14const C2BM ulong 104
15const C2GX ulong 120
16const C2W1 ulong 160
17const C2W2 ulong 168
18const C2XX ulong 176
19const C2YY ulong 184
20const C2ZZ ulong 192
21const C2XY ulong 200
22const C2YZ ulong 208
23const C2XZ ulong 216
24const C2U ulong 224
25const C2V ulong 232
26const C2YM ulong 240
27const C2YP ulong 248
28const C2BX3 ulong 256
29const C2XX3 ulong 264
30const C2ZZ3 ulong 272
31const C2RX ulong 280
32const C2ACC ulong 304
33const C2TMP ulong 328
34const C2BASE ulong 352
35const C2ZI ulong 376
36const C2Z ulong 528
37const C2R ulong 536
38const C2S ulong 544
39const C2U1 ulong 552
40const C2U2 ulong 560
41const C2T1 ulong 576
42const C2T2 ulong 584
43const C2T3 ulong 592
44const C2X ulong 608
45const C2Y ulong 616
46const C2Q ulong 640
47const C2P1 ulong 664
48const C2P2 ulong 688
49const C2BPUB ulong 3072
50const C2BSIG ulong 3200
51const C2BDIG ulong 3296
52
53fn cp2cpy w edit ulong 1024 o ulong a ulong to void
54for i ulong 8
55put w add o i get w add a i
56end
57end
58
59fn cp2pcpy w edit ulong 1024 o ulong a ulong to void
60for i ulong 24
61put w add o i get w add a i
62end
63end
64
65fn cp2set w edit ulong 1024 o ulong v ulong to void
66put w o v
67for i ulong 7
68put w add o add i 1 0
69end
70end
71
72fn cp2red w edit ulong 1024 o ulong t view ulong 10 m ulong to void
73u = new ulong 8 0
74bw = ulong 0
75x = ulong 0
76for i ulong 8
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 8 xor bw 1
82mk = sub 0 sel
83for j ulong 8
84y = and get u j mk
85put w add o j or y and get t j not mk
86end
87end
88
89fn cp2mrow t edit ulong 10 w edit ulong 1024 a ulong bi ulong to void
90c = ulong 0
91x = ulong 0
92for j ulong 8
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 8 c
98put t 8 and x 4294967295
99put t 9 shr x 32
100end
101
102fn cp2mred t edit ulong 10 w edit ulong 1024 m ulong to void
103q = and mul get t 0 get w add m 8 4294967295
104x = add get t 0 mul q get w m
105c = shr x 32
106j1 = ulong 0
107for k ulong 7
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 8 c
114put t 7 and x 4294967295
115put t 8 add get t 9 shr x 32
116end
117
118fn cp2mul w edit ulong 1024 o ulong a ulong b ulong m ulong to void
119t = new ulong 10 0
120for i ulong 8
121cp2mrow t w a get w add b i
122cp2mred t w m
123end
124cp2red w o t m
125end
126
127fn cp2add w edit ulong 1024 o ulong a ulong b ulong m ulong to void
128t = new ulong 10 0
129c = ulong 0
130x = ulong 0
131for i ulong 8
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 8 c
137cp2red w o t m
138end
139
140fn cp2sub w edit ulong 1024 o ulong a ulong b ulong m ulong to void
141t = new ulong 8 0
142bw = ulong 0
143x = ulong 0
144for i ulong 8
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 8
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 cp2modr w edit ulong 1024 o ulong m ulong to void
159t = new ulong 10 0
160for i ulong 8
161put t i get w add o i
162end
163cp2red w o t m
164end
165
166fn cp2lt w edit ulong 1024 a ulong m ulong to bool
167bw = ulong 0
168x = ulong 0
169for i ulong 8
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 cp2isz w edit ulong 1024 a ulong to bool
177v = ulong 0
178for i ulong 8
179v = or v get w add a i
180end
181ret eq v 0
182end
183
184fn cp2eqv w edit ulong 1024 a ulong b ulong to bool
185v = ulong 0
186for i ulong 8
187v = or v xor get w add a i get w add b i
188end
189ret eq v 0
190end
191
192fn cp2rng w edit ulong 1024 a ulong to bool
193ret and not cp2isz w a cp2lt w a C2MN
194end
195
196fn cp2pow w edit ulong 1024 o ulong a ulong e ulong m ulong to void
197cp2cpy w C2W2 a
198cp2cpy w C2W1 add m 24
199i = ulong 0
200bit = ulong 0
201for j ulong 256
202i = sub 255 j
203cp2mul w C2W1 C2W1 C2W1 m
204bit = and shr get w add e shr i 5 and i 31 1
205if eq bit 1
206cp2mul w C2W1 C2W1 C2W2 m
207end
208end
209cp2cpy w o C2W1
210end
211
212fn cp2inv w edit ulong 1024 o ulong a ulong m ulong to void
213cp2pow w o a add m 32 m
214end
215
216fn cp2tom w edit ulong 1024 o ulong a ulong m ulong to void
217cp2mul w o a add m 16 m
218end
219
220fn cp2frm w edit ulong 1024 o ulong a ulong m ulong to void
221cp2mul w o a C2ONE1 m
222end
223
224fn cp2mod w edit ulong 1024 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 8 and sub 0 x 4294967295
231cp2set w add m 16 1
232for j ulong 512
233cp2add w add m 16 add m 16 add m 16 m
234end
235cp2mul w add m 24 C2ONE1 add m 16 m
236cp2cpy w add m 32 m
237put w add m 32 sub get w add m 32 2
238end
239
240fn cp2init w edit ulong 1024 to void
241for i ulong 1024
242put w i 0
243end
244put w 0 4294967295
245put w 1 4294967295
246put w 2 4294967295
247put w 6 1
248put w 7 4294967295
249put w 48 4234356049
250put w 49 4089039554
251put w 50 2803342980
252put w 51 3169254061
253put w 52 4294967295
254put w 53 4294967295
255put w 55 4294967295
256put w C2ONE1 1
257cp2mod w C2MP
258cp2mod w C2MN
259put w C2T1 668098635
260put w 577 1003371582
261put w 578 3428036854
262put w 579 1696401072
263put w 580 1989707452
264put w 581 3018571093
265put w 582 2855965671
266put w 583 1522939352
267cp2tom w C2BM C2T1 C2MP
268put w C2T1 3633889942
269put w 577 4104206661
270put w 578 770388896
271put w 579 1996717441
272put w 580 1671708914
273put w 581 4173129445
274put w 582 3777774151
275put w 583 1796723186
276cp2tom w C2GX C2T1 C2MP
277put w C2T1 935285237
278put w 577 3417718888
279put w 578 1798397646
280put w 579 734933847
281put w 580 2081398294
282put w 581 2397563722
283put w 582 4263149467
284put w 583 1340293858
285cp2tom w add C2GX 8 C2T1 C2MP
286cp2cpy w add C2GX 16 add C2MP 24
287cp2set w C2T1 0
288end
289
290fn cp2padd w edit ulong 1024 o ulong a ulong q ulong to void
291cp2mul w C2XX a q C2MP
292cp2mul w C2YY add a 8 add q 8 C2MP
293cp2mul w C2ZZ add a 16 add q 16 C2MP
294cp2add w C2U a add a 8 C2MP
295cp2add w C2V q add q 8 C2MP
296cp2mul w C2XY C2U C2V C2MP
297cp2add w C2U C2XX C2YY C2MP
298cp2sub w C2XY C2XY C2U C2MP
299cp2add w C2U add a 8 add a 16 C2MP
300cp2add w C2V add q 8 add q 16 C2MP
301cp2mul w C2YZ C2U C2V C2MP
302cp2add w C2U C2YY C2ZZ C2MP
303cp2sub w C2YZ C2YZ C2U C2MP
304cp2add w C2U a add a 16 C2MP
305cp2add w C2V q add q 16 C2MP
306cp2mul w C2XZ C2U C2V C2MP
307cp2add w C2U C2XX C2ZZ C2MP
308cp2sub w C2XZ C2XZ C2U C2MP
309note bzz3 = 3 (xz - b zz); ym = yy - bzz3; yp = yy + bzz3
310cp2mul w C2U C2BM C2ZZ C2MP
311cp2sub w C2U C2XZ C2U C2MP
312cp2add w C2V C2U C2U C2MP
313cp2add w C2U C2V C2U C2MP
314cp2sub w C2YM C2YY C2U C2MP
315cp2add w C2YP C2YY C2U C2MP
316note zz3 = 3 zz; bxz3 = 3 (b xz - (zz3 + xx)); xx3 = 3 xx - zz3
317cp2add w C2ZZ3 C2ZZ C2ZZ C2MP
318cp2add w C2ZZ3 C2ZZ3 C2ZZ C2MP
319cp2mul w C2U C2BM C2XZ C2MP
320cp2add w C2V C2ZZ3 C2XX C2MP
321cp2sub w C2U C2U C2V C2MP
322cp2add w C2V C2U C2U C2MP
323cp2add w C2BX3 C2V C2U C2MP
324cp2add w C2V C2XX C2XX C2MP
325cp2add w C2V C2V C2XX C2MP
326cp2sub w C2XX3 C2V C2ZZ3 C2MP
327note X3 = yp xy - yz bxz3; Y3 = yp ym + xx3 bxz3; Z3 = ym yz + xy xx3
328cp2mul w C2U C2YP C2XY C2MP
329cp2mul w C2V C2YZ C2BX3 C2MP
330cp2sub w C2RX C2U C2V C2MP
331cp2mul w C2U C2YP C2YM C2MP
332cp2mul w C2V C2XX3 C2BX3 C2MP
333cp2add w add C2RX 8 C2U C2V C2MP
334cp2mul w C2U C2YM C2YZ C2MP
335cp2mul w C2V C2XY C2XX3 C2MP
336cp2add w add C2RX 16 C2U C2V C2MP
337cp2pcpy w o C2RX
338end
339
340fn cp2psel w edit ulong 1024 bit ulong to void
341mk = sub 0 bit
342nm = not mk
343for c ulong 24
344y = and get w add C2TMP c mk
345put w add C2ACC c or y and get w add C2ACC c nm
346end
347end
348
349fn cp2smul w edit ulong 1024 o ulong k ulong p ulong to void
350cp2pcpy w C2BASE p
351cp2set w C2ACC 0
352cp2cpy w add C2ACC 8 add C2MP 24
353cp2set w add C2ACC 16 0
354i = ulong 0
355for j ulong 256
356i = sub 255 j
357cp2padd w C2ACC C2ACC C2ACC
358cp2padd w C2TMP C2ACC C2BASE
359cp2psel w and shr get w add k shr i 5 and i 31 1
360end
361cp2pcpy w o C2ACC
362end
363
364fn cp2aff w edit ulong 1024 x ulong y ulong p ulong to void
365cp2inv w C2ZI add p 16 C2MP
366cp2mul w x p C2ZI C2MP
367cp2frm w x x C2MP
368cp2mul w y add p 8 C2ZI C2MP
369cp2frm w y y C2MP
370end
371
372fn cp2ld w edit ulong 1024 o ulong b edit uchar 4096 off ulong to void
373q = ulong 0
374v = ulong 0
375for i ulong 8
376q = add off sub 28 mul i 4
377v = ulong get b q
378v = or shl v 8 ulong get b add q 1
379v = or shl v 8 ulong get b add q 2
380v = or shl v 8 ulong get b add q 3
381put w add o i v
382end
383end
384
385fn cp2oncv w edit ulong 1024 to bool
386if not cp2lt w C2X C2MP
387ret false
388end
389if not cp2lt w C2Y C2MP
390ret false
391end
392cp2tom w C2T1 C2X C2MP
393cp2tom w C2T2 C2Y C2MP
394cp2mul w C2T3 C2T2 C2T2 C2MP
395cp2mul w C2T2 C2T1 C2T1 C2MP
396cp2mul w C2T2 C2T2 C2T1 C2MP
397cp2sub w C2T2 C2T2 C2T1 C2MP
398cp2sub w C2T2 C2T2 C2T1 C2MP
399cp2sub w C2T2 C2T2 C2T1 C2MP
400cp2add w C2T2 C2T2 C2BM C2MP
401ret cp2eqv w C2T2 C2T3
402end
403
404fn cp2vrfy w edit ulong 1024 b edit uchar 4096 to ulong
405if ne get b C2BPUB 4
406ret 0
407end
408cp2ld w C2X b add C2BPUB 1
409cp2ld w C2Y b add C2BPUB 33
410if not cp2oncv w
411ret 0
412end
413cp2ld w C2R b C2BSIG
414cp2ld w C2S b add C2BSIG 32
415if not cp2rng w C2R
416ret 0
417end
418if not cp2rng w C2S
419ret 0
420end
421cp2ld w C2Z b C2BDIG
422cp2modr w C2Z C2MN
423cp2tom w C2T1 C2S C2MN
424cp2inv w C2T1 C2T1 C2MN
425cp2tom w C2T2 C2Z C2MN
426cp2mul w C2U1 C2T2 C2T1 C2MN
427cp2frm w C2U1 C2U1 C2MN
428cp2tom w C2T2 C2R C2MN
429cp2mul w C2U2 C2T2 C2T1 C2MN
430cp2frm w C2U2 C2U2 C2MN
431cp2tom w C2Q C2X C2MP
432cp2tom w add C2Q 8 C2Y C2MP
433cp2cpy w add C2Q 16 add C2MP 24
434cp2smul w C2P1 C2U1 C2GX
435cp2smul w C2P2 C2U2 C2Q
436cp2padd w C2P1 C2P1 C2P2
437if cp2isz w add C2P1 16
438ret 0
439end
440cp2aff w C2X C2Y C2P1
441cp2modr w C2X C2MN
442if cp2eqv w C2X C2R
443ret 1
444end
445ret 0
446end
447