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 / core / rsi / om / p256 / tests / run.om

436 lines · 8504 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note om/p256/tests/run.om: the p256.om known-answer and parity runner. Compiled after its units:
3note cat om/p256/sha256.om om/p256/p256.om om/p256/tests/run.om | OMC > run.elf
4note ./run.elf om/p256/tests/rfc6979-a25.txt om/p256/tests/parity-rust.txt om/p256/tests/edge-rust.txt
5note om/p256/tests/interplane.txt
6note Self tests first (G on the curve, n G = identity, (n - 1) G = -G), then every vector file named
7note on the command line. A file holds lines (# starts a comment):
8note K key pub p2pub(key) must equal the 65-byte uncompressed SEC1 pub
9note N key msg k the RFC 6979 nonce p2sign accepts for (key, msg) must equal k
10note S key msg sig p2sign(key, msg) must equal sig (r||s), and p2vrfy must accept it under
11note p2pub(key)
12note V pub msg sig 0|1 p2vrfy(pub, msg, sig) must give the recorded verdict
13note all fields lowercase or uppercase hex; msg is 1..1024 bytes. Prints counts and per-call timing
14note (monons around each call): p2sign, p2vrfy of the S lines (every one a full verification of a
15note valid signature) and p2vrfy of the V lines (early refusals included). Exit 0 iff every check
16note passed, 1 on any mismatch or malformed line, 2 when a file cannot be read.
17global FB uchar 4194304
18global FP ulong 4
19global CT ulong 32
20global PATH uchar 4096
21text TSELF "self tests: "
22text TPASS " pass, "
23text TFAIL " fail\n"
24text TFILE "file "
25text TK ": K "
26text TN " N "
27text TS " S "
28text TV " V "
29text TBAD " malformed "
30text TNL "\n"
31text TSL "/"
32text TMIS "MISMATCH line "
33text TKIND " kind "
34text TTS "timing p2sign: calls "
35text TTV "timing p2vrfy (S lines, valid): calls "
36text TTW "timing p2vrfy (V lines, mixed): calls "
37text TMEAN " mean_us "
38text TMIN " min_us "
39text TMAX " max_us "
40text TOK "p256: PASS\n"
41text TNO "p256: FAIL\n"
42text TRD "cannot read "
43
44const CKP ulong 0
45const CNP ulong 2
46const CSP ulong 4
47const CVP ulong 6
48const CBAD ulong 8
49const CTS ulong 10
50const CTV ulong 14
51const CSELF ulong 18
52const CALL ulong 20
53const CTW ulong 22
54
55fn onum v ulong to void
56d = new uchar 24 0
57n = ulong 0
58x = v
59while true bound 24
60put d sub 23 n uchar add rem x 10 48
61n = add n 1
62x = div x 10
63if eq x 0
64break
65end
66end
67r = write 1 d sub 24 n n
68end
69
70fn ochr ch uchar to void
71d = new uchar 1 ch
72r = write 1 d 0 1
73end
74
75note count a pass (ok) or a fail at counter base (pass at base, fail at base + 1)
76fn tally base ulong ok bool to void
77if ok
78put CT base add get CT base 1
79ret
80end
81put CT add base 1 add get CT add base 1 1
82put CT CALL add get CT CALL 1
83end
84
85note one timed call: count, sum, min, max at base..base+3
86fn tadd base ulong ns ulong to void
87n = get CT base
88put CT base add n 1
89put CT add base 1 add get CT add base 1 ns
90if or eq n 0 lt ns get CT add base 2
91put CT add base 2 ns
92end
93if gt ns get CT add base 3
94put CT add base 3 ns
95end
96end
97
98fn hexv ch uchar to ulong
99if and ge ch 48 le ch 57
100ret ulong sub ch 48
101end
102if and ge ch 97 le ch 102
103ret ulong sub ch 87
104end
105if and ge ch 65 le ch 70
106ret ulong sub ch 55
107end
108ret 16
109end
110
111fn skipsp to void
112p = get FP 0
113e = get FP 1
114while lt p e bound 4096
115if ne get FB p 32
116break
117end
118p = add p 1
119end
120put FP 0 p
121end
122
123note the next hex field into b[off..off+cap); returns its byte count, or cap + 1 when the field is
124note empty, odd, not hex or longer than cap
125fn rhex b edit uchar 4096 off ulong cap ulong to ulong
126skipsp
127n = ulong 0
128p = get FP 0
129e = get FP 1
130while lt p e bound 4096
131h = hexv get FB p
132if eq h 16
133break
134end
135if or ge add p 1 e ge n cap
136ret add cap 1
137end
138l = hexv get FB add p 1
139if eq l 16
140ret add cap 1
141end
142put b add off n uchar or shl h 4 l
143n = add n 1
144p = add p 2
145end
146put FP 0 p
147if eq n 0
148ret add cap 1
149end
150ret n
151end
152
153fn nextln to void
154p = get FP 0
155e = get FP 1
156while lt p e bound 999999
157if eq get FB p 10
158put FP 0 add p 1
159put FP 2 add get FP 2 1
160ret
161end
162p = add p 1
163end
164put FP 0 e
165end
166
167fn beq b edit uchar 4096 x ulong y ulong n ulong to bool
168v = uchar 0
169for i ulong n
170v = or v xor get b add x i get b add y i
171end
172ret eq v 0
173end
174
175fn mism kind uchar to void
176r = write 1 TMIS 0 len TMIS
177onum get FP 2
178r = write 1 TKIND 0 len TKIND
179ochr kind
180r = write 1 TNL 0 len TNL
181end
182
183fn bad to void
184put CT CBAD add get CT CBAD 1
185put CT CALL add get CT CALL 1
186mism 63
187end
188
189fn dok w edit ulong 1024 c edit uchar 104 b edit uchar 4096 s edit ulong 64 to void
190n1 = rhex b PBKEY 32
191n2 = rhex b 3600 65
192if or ne n1 32 ne n2 65
193bad
194ret
195end
196st = p2pub w b
197ok = and eq st 0 beq b PBPUB 3600 65
198tally CKP ok
199if not ok
200mism 75
201end
202end
203
204fn don w edit ulong 1024 c edit uchar 104 b edit uchar 4096 s edit ulong 64 to void
205n1 = rhex b PBKEY 32
206ml = rhex b PBMSG 1024
207n3 = rhex b 3700 32
208if or or ne n1 32 gt ml 1024 ne n3 32
209bad
210ret
211end
212st = p2sign w c b s ml
213p2st w PK b 3740
214ok = and eq st 0 beq b 3700 3740 32
215tally CNP ok
216if not ok
217mism 78
218end
219end
220
221fn dos w edit ulong 1024 c edit uchar 104 b edit uchar 4096 s edit ulong 64 to void
222n1 = rhex b PBKEY 32
223ml = rhex b PBMSG 1024
224n3 = rhex b 3500 64
225if or or ne n1 32 gt ml 1024 ne n3 64
226bad
227ret
228end
229t0 = monons
230st = p2sign w c b s ml
231t1 = monons
232tadd CTS ulong sub t1 t0
233ok = and eq st 0 beq b PBSIG 3500 64
234st = p2pub w b
235t0 = monons
236v = p2vrfy w c b s ml
237t1 = monons
238tadd CTV ulong sub t1 t0
239ok = and ok and eq st 0 eq v 1
240tally CSP ok
241if not ok
242mism 83
243end
244end
245
246fn dov w edit ulong 1024 c edit uchar 104 b edit uchar 4096 s edit ulong 64 to void
247n1 = rhex b PBPUB 65
248ml = rhex b PBMSG 1024
249n3 = rhex b PBSIG 64
250skipsp
251p = get FP 0
252if or or ne n1 65 gt ml 1024 ne n3 64
253bad
254ret
255end
256if ge p get FP 1
257bad
258ret
259end
260ex = hexv get FB p
261if gt ex 1
262bad
263ret
264end
265put FP 0 add p 1
266t0 = monons
267v = p2vrfy w c b s ml
268t1 = monons
269tadd CTW ulong sub t1 t0
270ok = eq v ex
271tally CVP ok
272if not ok
273mism 86
274end
275end
276
277note self tests: G on the curve; n G = identity; (n - 1) G = (Gx, p - Gy)
278fn selft w edit ulong 1024 to void
279p2frm w PX PGX PMP
280p2frm w PY add PGX 8 PMP
281tally CSELF p2oncv w
282p2cpy w 900 PMN
283p2smul w PP2 900 PGX
284tally CSELF p2isz w add PP2 16
285put w 900 sub get w 900 1
286p2smul w PP2 900 PGX
287p2aff w PX PY PP2
288p2frm w 910 PGX PMP
289p2frm w 920 add PGX 8 PMP
290p2add w 920 920 PY PMP
291tally CSELF and p2eqv w PX 910 p2isz w 920
292end
293
294fn report base ulong to void
295onum get CT base
296r = write 1 TSL 0 len TSL
297onum add get CT base get CT add base 1
298end
299
300fn treport base ulong to void
301n = get CT base
302onum n
303if gt n 0
304r = write 1 TMEAN 0 len TMEAN
305onum div div get CT add base 1 n 1000
306r = write 1 TMIN 0 len TMIN
307onum div get CT add base 2 1000
308r = write 1 TMAX 0 len TMAX
309onum div get CT add base 3 1000
310end
311r = write 1 TNL 0 len TNL
312end
313
314note read file argv a into FB; 0 ok, 1 unreadable or too large
315fn rdfile a ulong to ulong
316pl = argread a PATH 0 4096
317if le pl 0
318ret 1
319end
320fd = fopen PATH 0 ulong pl 0 0
321if lt fd 0
322ret 1
323end
324got = ulong 0
325while lt got 4194304 bound 100000
326k = read int fd FB got sub 4194304 got
327if le k 0
328break
329end
330got = add got ulong k
331end
332r = fclose int fd
333if or ge got 4194304 ne r 0
334ret 1
335end
336put FP 0 0
337put FP 1 got
338put FP 2 1
339put FP 3 ulong pl
340ret 0
341end
342
343note after a record only spaces may remain on its line
344fn trail to void
345skipsp
346p = get FP 0
347if lt p get FP 1
348if ne get FB p 10
349bad
350end
351end
352end
353
354fn dofile w edit ulong 1024 c edit uchar 104 b edit uchar 4096 s edit ulong 64 to void
355ch = uchar 0
356while lt get FP 0 get FP 1 bound 999999
357ch = get FB get FP 0
358if or eq ch 35 eq ch 10
359nextln
360continue
361end
362put FP 0 add get FP 0 1
363if eq ch 75
364dok w c b s
365else
366if eq ch 78
367don w c b s
368else
369if eq ch 83
370dos w c b s
371else
372if eq ch 86
373dov w c b s
374else
375bad
376end
377end
378end
379end
380trail
381nextln
382end
383end
384
385fn main to int
386w = new ulong 1024 0
387c = new uchar 104 0
388b = new uchar 4096 0
389s = new ulong 64 0
390p2init w
391selft w
392r = write 1 TSELF 0 len TSELF
393onum get CT CSELF
394r = write 1 TPASS 0 len TPASS
395onum get CT add CSELF 1
396r = write 1 TFAIL 0 len TFAIL
397put CT CALL add get CT CALL get CT add CSELF 1
398na = ulong argcnt
399for a ulong sub na 1
400if ne rdfile add a 1 0
401r = write 1 TRD 0 len TRD
402r = write 1 PATH 0 get FP 3
403r = write 1 TNL 0 len TNL
404ret 2
405end
406for z ulong 10
407put CT z 0
408end
409dofile w c b s
410r = write 1 TFILE 0 len TFILE
411r = write 1 PATH 0 get FP 3
412r = write 1 TK 0 len TK
413report CKP
414r = write 1 TN 0 len TN
415report CNP
416r = write 1 TS 0 len TS
417report CSP
418r = write 1 TV 0 len TV
419report CVP
420r = write 1 TBAD 0 len TBAD
421onum get CT CBAD
422r = write 1 TNL 0 len TNL
423end
424r = write 1 TTS 0 len TTS
425treport CTS
426r = write 1 TTV 0 len TTV
427treport CTV
428r = write 1 TTW 0 len TTW
429treport CTW
430if eq get CT CALL 0
431r = write 1 TOK 0 len TOK
432ret 0
433end
434r = write 1 TNO 0 len TNO
435ret 1
436end