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 / si / seed-challenge / test.om

1077 lines · 21832 bytes Raw Blame History
1om2
2note si/seed-challenge/test.om: Standalone OM-2 behavioral test suite for seed-challenge verifier.
3note Tests positive verification (SHA-256 KATs, full seed0->hex1->asm2->om4->omc ladder pin table + log)
4note and negative/refusal controls (flipped rung byte, forged stage2 digest, uppercase/short digest,
5note missing rung chain link, injected FAIL/NOT_RUN line, non-aarch64 host, forged CHALLENGE footer).
6
7global expbuf uchar 16384
8global logbuf uchar 32768
9global pinbuf uchar 64
10global omcsha uchar 64
11global patbuf uchar 512
12global decbuf uchar 32
13global rungseen ulong 8
14global gmeta ulong 12
15global shastate uint 8
16global shak uint 64
17global shaw uint 64
18global shablk uchar 64
19global shadig uchar 32
20global shahex uchar 64
21global testbuf uchar 128
22
23const m_elen ulong 0
24const m_llen ulong 1
25const m_plen ulong 2
26const m_olen ulong 3
27const m_bad ulong 4
28const m_patlen ulong 5
29const m_expe ulong 6
30
31const r_seed0 ulong 0
32const r_hex1 ulong 1
33const r_asm2 ulong 2
34const r_om4 ulong 3
35const r_omc ulong 4
36const r_pin ulong 5
37const r_incnt ulong 6
38const r_rcnt ulong 7
39
40text khex "0123456789abcdef"
41text t_pin "pin "
42text t_input "input "
43text t_rung "rung "
44text t_seed0 "seed0"
45text t_hex1 "hex1"
46text t_asm2 "asm2"
47text t_om4 "om4"
48text t_omc "omc"
49text t_host "host "
50text t_a64 "aarch64"
51text t_pass_in "PASS input "
52text t_pass_rg "PASS rung "
53text t_st1 "stage1 "
54text t_st2 "stage2 "
55text t_st3 "stage3 "
56text t_fail "FAIL "
57text t_notrun "NOT_RUN "
58text t_ch_pfx "CHALLENGE "
59text t_ch_pass "CHALLENGE PASS pin="
60text t_ch_omc " omc="
61
62note Test vectors (real omega-mv seed/challenge/expected-v1.txt and DGX Spark log)
63text sha_empty "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
64text msg_abc "abc"
65text sha_abc "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
66text hex_short "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015a"
67text hex_upper "BA7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
68text hex_badch "ga7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
69text pin_ok "369dbc96daa1684db2d7c2c7085bbf16b3fd77ee"
70
71text exp_v1_a "# seed-chain v1\npin 369dbc96daa1684db2d7c2c7085bbf16b3fd77ee\ninput seed/rung0/seed0.hex baaf081fe6055a768485c5d25d7435681ce00b04cfa80b26c48169f78944e14d 7903\n"
72text exp_v1_b "rung seed0 aca00cf3677236809f0f223437398c6bb429e4c65f13d58762bcf96d13799474 408\nrung hex1 920e1756aec399c7c74f5cedd1676abb91b844ea75448e14aa50dcb0bbc7ba5d 776\n"
73text exp_v1_c "rung asm2 6988abe072fac3cdef2240d5ad13a3ecd8fb576fa09112d344b9e7c2315969c4 2464\nrung om4 d0da40e45f1fcc45d9a39c9c52c9d745b545e076970729e51c12d76ef519efab 14224\nrung omc 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f 325524\n"
74text exp_no_asm2 "rung om4 d0da40e45f1fcc45d9a39c9c52c9d745b545e076970729e51c12d76ef519efab 14224\nrung omc 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f 325524\n"
75text exp_bad_hex "pin 369dbc96daa1684db2d7c2c7085bbf16b3fd77ee\nrung seed0 ACA00cf3677236809f0f223437398c6bb429e4c65f13d58762bcf96d13799474 408\n"
76
77text log_v1_a "omega seed-chain bootstrap challenge\nhost Linux 7.0.0-1019-nvidia aarch64\npin 369dbc96daa1684db2d7c2c7085bbf16b3fd77ee\n"
78text log_v1_b "PASS input seed/rung0/seed0.hex baaf081fe6055a768485c5d25d7435681ce00b04cfa80b26c48169f78944e14d 7903\nPASS rung seed0 aca00cf3677236809f0f223437398c6bb429e4c65f13d58762bcf96d13799474 408 219ms\nPASS rung hex1 920e1756aec399c7c74f5cedd1676abb91b844ea75448e14aa50dcb0bbc7ba5d 776 4ms\n"
79text log_v1_c "PASS rung asm2 6988abe072fac3cdef2240d5ad13a3ecd8fb576fa09112d344b9e7c2315969c4 2464 1ms\nPASS rung om4 d0da40e45f1fcc45d9a39c9c52c9d745b545e076970729e51c12d76ef519efab 14224 9ms\n"
80text log_v1_d "stage1 PASS rung omc 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f 325524 6ms\nstage2 PASS rung omc 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f 325524 12ms\nstage3 PASS rung omc 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f 325524 13ms\n"
81text log_v1_e "CHALLENGE PASS pin=369dbc96daa1684db2d7c2c7085bbf16b3fd77ee omc=2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f\n"
82text log_bad_st2 "stage1 PASS rung omc 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f 325524 6ms\nstage2 PASS rung omc 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029e 325524 12ms\nstage3 PASS rung omc 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f 325524 13ms\n"
83text log_x86_host "omega seed-chain bootstrap challenge\nhost Linux 6.8.0-generic x86_64\npin 369dbc96daa1684db2d7c2c7085bbf16b3fd77ee\n"
84text log_inj_fail "FAIL rung hex1 mismatch\n"
85text log_bad_foot "CHALLENGE PASS pin=369dbc96daa1684db2d7c2c7085bbf16b3fd77ee omc=0000000000000000000000000000000000000000000000000000000000000000\n"
86
87text p_sha_kat "PASS sha256_kat_empty_and_abc\n"
88text p_flip_byte "PASS neg_flipped_rung_byte_caught\n"
89text p_hex_fmt "PASS digest_format_validation_pos_and_neg\n"
90text p_valid_v1 "PASS valid_v1_ladder_log_accepted\n"
91text p_neg_st2 "PASS neg_forged_stage2_digest_refused\n"
92text p_neg_chain "PASS neg_missing_asm2_rung_refused\n"
93text p_neg_fail "PASS neg_injected_fail_line_refused\n"
94text p_neg_host "PASS neg_non_aarch64_host_refused\n"
95text p_neg_exp "PASS neg_malformed_expected_digest_refused\n"
96text p_neg_foot "PASS neg_forged_challenge_footer_refused\n"
97text p_all "SEED-CHALLENGE TEST SUITE PASS (10/10)\n"
98text f_msg "FAIL test case "
99text t_nl "\n"
100
101fn write_all fd int src view uchar * off ulong n ulong to void
102p = ulong 0
103while lt p n bound 4096
104k = write fd src add off p sub n p
105if le k 0
106exit 2
107end
108p = add p ulong k
109end
110end
111
112fn wstr fd int s view uchar * to void
113write_all fd s 0 len s
114end
115
116fn wdec fd int v ulong to void
117i = ulong 32
118n = v
119while true bound 24
120i = sub i 1
121put decbuf i uchar add rem n 10 48
122n = div n 10
123if eq n 0
124break
125end
126end
127p = i
128while lt p 32 bound 32
129k = write fd decbuf p sub 32 p
130if le k 0
131exit 2
132end
133p = add p ulong k
134end
135end
136
137fn fail_case id ulong to void
138wstr 2 f_msg
139wdec 2 id
140wstr 2 t_nl
141exit 1
142end
143
144fn is_hex_ch c uchar to bool
145if and ge c 48 le c 57
146ret true
147end
148if and ge c 97 le c 102
149ret true
150end
151ret false
152end
153
154fn is_dig_ch c uchar to bool
155ret and ge c 48 le c 57
156end
157
158fn is_hex_exp off ulong n ulong to bool
159if eq n 0
160ret false
161end
162if gt add off n 16384
163ret false
164end
165i = ulong 0
166while lt i n bound 128
167if not is_hex_ch get expbuf add off i
168ret false
169end
170i = add i 1
171end
172ret true
173end
174
175fn is_dec_exp off ulong n ulong to bool
176if eq n 0
177ret false
178end
179if gt n 20
180ret false
181end
182if gt add off n 16384
183ret false
184end
185nz = false
186i = ulong 0
187while lt i n bound 32
188c = get expbuf add off i
189if not is_dig_ch c
190ret false
191end
192if ne c 48
193nz = true
194end
195i = add i 1
196end
197ret nz
198end
199
200fn is_hex_view s view uchar * n ulong to bool
201if ne len s n
202ret false
203end
204i = ulong 0
205while lt i n bound 128
206if not is_hex_ch get s i
207ret false
208end
209i = add i 1
210end
211ret true
212end
213
214fn sha_kinit to void
215put shak 0 0x428a2f98
216put shak 1 0x71374491
217put shak 2 0xb5c0fbcf
218put shak 3 0xe9b5dba5
219put shak 4 0x3956c25b
220put shak 5 0x59f111f1
221put shak 6 0x923f82a4
222put shak 7 0xab1c5ed5
223put shak 8 0xd807aa98
224put shak 9 0x12835b01
225put shak 10 0x243185be
226put shak 11 0x550c7dc3
227put shak 12 0x72be5d74
228put shak 13 0x80deb1fe
229put shak 14 0x9bdc06a7
230put shak 15 0xc19bf174
231put shak 16 0xe49b69c1
232put shak 17 0xefbe4786
233put shak 18 0x0fc19dc6
234put shak 19 0x240ca1cc
235put shak 20 0x2de92c6f
236put shak 21 0x4a7484aa
237put shak 22 0x5cb0a9dc
238put shak 23 0x76f988da
239put shak 24 0x983e5152
240put shak 25 0xa831c66d
241put shak 26 0xb00327c8
242put shak 27 0xbf597fc7
243put shak 28 0xc6e00bf3
244put shak 29 0xd5a79147
245put shak 30 0x06ca6351
246put shak 31 0x14292967
247put shak 32 0x27b70a85
248put shak 33 0x2e1b2138
249put shak 34 0x4d2c6dfc
250put shak 35 0x53380d13
251put shak 36 0x650a7354
252put shak 37 0x766a0abb
253put shak 38 0x81c2c92e
254put shak 39 0x92722c85
255put shak 40 0xa2bfe8a1
256put shak 41 0xa81a664b
257put shak 42 0xc24b8b70
258put shak 43 0xc76c51a3
259put shak 44 0xd192e819
260put shak 45 0xd6990624
261put shak 46 0xf40e3585
262put shak 47 0x106aa070
263put shak 48 0x19a4c116
264put shak 49 0x1e376c08
265put shak 50 0x2748774c
266put shak 51 0x34b0bcb5
267put shak 52 0x391c0cb3
268put shak 53 0x4ed8aa4a
269put shak 54 0x5b9cca4f
270put shak 55 0x682e6ff3
271put shak 56 0x748f82ee
272put shak 57 0x78a5636f
273put shak 58 0x84c87814
274put shak 59 0x8cc70208
275put shak 60 0x90befffa
276put shak 61 0xa4506ceb
277put shak 62 0xbef9a3f7
278put shak 63 0xc67178f2
279end
280
281fn sha_iv to void
282put shastate 0 0x6a09e667
283put shastate 1 0xbb67ae85
284put shastate 2 0x3c6ef372
285put shastate 3 0xa54ff53a
286put shastate 4 0x510e527f
287put shastate 5 0x9b05688c
288put shastate 6 0x1f83d9ab
289put shastate 7 0x5be0cd19
290end
291
292fn sha_sched to void
293for i ulong 16
294q = mul i 4
295x = uint get shablk q
296x = or shl x 8 uint get shablk add q 1
297x = or shl x 8 uint get shablk add q 2
298put shaw i or shl x 8 uint get shablk add q 3
299end
300for i ulong 48
301x = get shaw add i 1
302y = get shaw add i 14
303s0 = xor xor rotr x 7 rotr x 18 shr x 3
304s1 = xor xor rotr y 17 rotr y 19 shr y 10
305put shaw add i 16 add add get shaw i get shaw add i 9 add s0 s1
306end
307end
308
309fn sha_compress to void
310sha_sched
311a = get shastate 0
312b = get shastate 1
313c = get shastate 2
314d = get shastate 3
315e = get shastate 4
316f = get shastate 5
317g = get shastate 6
318h = get shastate 7
319t = uint 0
320for i ulong 64
321h = add h get shak i
322h = add h get shaw i
323t = xor rotr e 6 rotr e 11
324t = xor t rotr e 25
325h = add h t
326h = add h xor g and e xor f g
327d = add d h
328t = xor rotr a 2 rotr a 13
329t = xor t rotr a 22
330h = add h t
331h = add h or and a b and c or a b
332t = h
333h = g
334g = f
335f = e
336e = d
337d = c
338c = b
339b = a
340a = t
341end
342put shastate 0 add get shastate 0 a
343put shastate 1 add get shastate 1 b
344put shastate 2 add get shastate 2 c
345put shastate 3 add get shastate 3 d
346put shastate 4 add get shastate 4 e
347put shastate 5 add get shastate 5 f
348put shastate 6 add get shastate 6 g
349put shastate 7 add get shastate 7 h
350end
351
352fn sha256_bytes src view uchar * dlen ulong to void
353sha_kinit
354sha_iv
355off = ulong 0
356while ge sub dlen off 64 bound 65536
357for j ulong 64
358put shablk j get src add off j
359end
360sha_compress
361off = add off 64
362end
363remn = sub dlen off
364for j ulong 64
365if lt j remn
366put shablk j get src add off j
367else
368put shablk j 0
369end
370end
371put shablk remn 0x80
372if gt remn 55
373sha_compress
374for j ulong 64
375put shablk j 0
376end
377end
378bits = mul dlen 8
379put shablk 56 uchar and shr bits 56 255
380put shablk 57 uchar and shr bits 48 255
381put shablk 58 uchar and shr bits 40 255
382put shablk 59 uchar and shr bits 32 255
383put shablk 60 uchar and shr bits 24 255
384put shablk 61 uchar and shr bits 16 255
385put shablk 62 uchar and shr bits 8 255
386put shablk 63 uchar and bits 255
387sha_compress
388for i ulong 8
389w = get shastate i
390q = mul i 4
391put shadig q uchar and shr w 24 255
392put shadig add q 1 uchar and shr w 16 255
393put shadig add q 2 uchar and shr w 8 255
394put shadig add q 3 uchar and w 255
395end
396for i ulong 32
397bv = ulong get shadig i
398put shahex mul i 2 get khex shr bv 4
399put shahex add mul i 2 1 get khex and bv 15
400end
401end
402
403fn verify_rung_bytes src view uchar * dlen ulong exphex view uchar * to bool
404if not is_hex_view exphex 64
405ret false
406end
407sha256_bytes src dlen
408for i ulong 64
409if ne get shahex i get exphex i
410ret false
411end
412end
413ret true
414end
415
416fn exp_reset to void
417put gmeta m_elen 0
418end
419
420fn exp_append s view uchar * to void
421tot = get gmeta m_elen
422n = len s
423i = ulong 0
424while lt i n bound 4096
425put expbuf add tot i get s i
426i = add i 1
427end
428put gmeta m_elen add tot n
429end
430
431fn log_reset to void
432put gmeta m_llen 0
433end
434
435fn log_append s view uchar * to void
436tot = get gmeta m_llen
437n = len s
438i = ulong 0
439while lt i n bound 4096
440put logbuf add tot i get s i
441i = add i 1
442end
443put gmeta m_llen add tot n
444end
445
446fn pat_clear to void
447put gmeta m_patlen 0
448end
449
450fn pat_push_ch c uchar to void
451n = get gmeta m_patlen
452if lt n 512
453put patbuf n c
454put gmeta m_patlen add n 1
455end
456end
457
458fn pat_push_lit s view uchar * to void
459sl = len s
460i = ulong 0
461while lt i sl bound 512
462pat_push_ch get s i
463i = add i 1
464end
465end
466
467fn pat_push_exp off ulong n ulong to void
468i = ulong 0
469while lt i n bound 512
470if lt add off i 16384
471pat_push_ch get expbuf add off i
472end
473i = add i 1
474end
475end
476
477fn pat_push_pin to void
478n = get gmeta m_plen
479i = ulong 0
480while lt i n bound 64
481pat_push_ch get pinbuf i
482i = add i 1
483end
484end
485
486fn pat_push_omc to void
487n = get gmeta m_olen
488i = ulong 0
489while lt i n bound 64
490pat_push_ch get omcsha i
491i = add i 1
492end
493end
494
495fn exp_eq off ulong n ulong lit view uchar * to bool
496if ne n len lit
497ret false
498end
499i = ulong 0
500while lt i n bound 512
501if ne get expbuf add off i get lit i
502ret false
503end
504i = add i 1
505end
506ret true
507end
508
509fn exp_starts off ulong elen ulong pfx view uchar * to bool
510pl = len pfx
511if lt elen pl
512ret false
513end
514i = ulong 0
515while lt i pl bound 512
516if ne get expbuf add off i get pfx i
517ret false
518end
519i = add i 1
520end
521ret true
522end
523
524fn log_starts off ulong llen ulong pfx view uchar * to bool
525pl = len pfx
526if lt llen pl
527ret false
528end
529i = ulong 0
530while lt i pl bound 512
531if ne get logbuf add off i get pfx i
532ret false
533end
534i = add i 1
535end
536ret true
537end
538
539fn log_contains off ulong llen ulong needle view uchar * to bool
540nl = len needle
541if gt nl llen
542ret false
543end
544lim = add sub llen nl 1
545i = ulong 0
546while lt i lim bound 1024
547if log_starts add off i sub llen i needle
548ret true
549end
550i = add i 1
551end
552ret false
553end
554
555fn log_line_matches_pat off ulong llen ulong allow_ms bool to bool
556pl = get gmeta m_patlen
557if lt llen pl
558ret false
559end
560i = ulong 0
561while lt i pl bound 512
562if ne get logbuf add off i get patbuf i
563ret false
564end
565i = add i 1
566end
567if eq llen pl
568ret true
569end
570if not allow_ms
571ret false
572end
573if lt sub llen pl 4
574ret false
575end
576if ne get logbuf add off pl 32
577ret false
578end
579if ne get logbuf add off sub llen 2 109
580ret false
581end
582if ne get logbuf add off sub llen 1 115
583ret false
584end
585pos = add pl 1
586endpos = sub llen 2
587if ge pos endpos
588ret false
589end
590while lt pos endpos bound 32
591if not is_dig_ch get logbuf add off pos
592ret false
593end
594pos = add pos 1
595end
596ret true
597end
598
599fn log_has_pat allow_ms bool to bool
600tot = get gmeta m_llen
601pos = ulong 0
602while lt pos tot bound 32768
603ls = pos
604while lt pos tot bound 32768
605if eq get logbuf pos 10
606break
607end
608pos = add pos 1
609end
610ll = sub pos ls
611if log_line_matches_pat ls ll allow_ms
612ret true
613end
614if lt pos tot
615pos = add pos 1
616end
617end
618ret false
619end
620
621fn log_has_aarch64_host to bool
622tot = get gmeta m_llen
623pos = ulong 0
624while lt pos tot bound 32768
625ls = pos
626while lt pos tot bound 32768
627if eq get logbuf pos 10
628break
629end
630pos = add pos 1
631end
632ll = sub pos ls
633if log_starts ls ll t_host
634if log_contains ls ll t_a64
635ret true
636end
637end
638if lt pos tot
639pos = add pos 1
640end
641end
642ret false
643end
644
645fn log_has_fail_or_notrun to bool
646tot = get gmeta m_llen
647pos = ulong 0
648while lt pos tot bound 32768
649ls = pos
650while lt pos tot bound 32768
651if eq get logbuf pos 10
652break
653end
654pos = add pos 1
655end
656ll = sub pos ls
657off = ls
658remn = ll
659if log_starts ls ll t_st1
660off = add ls 7
661remn = sub ll 7
662else
663if log_starts ls ll t_st2
664off = add ls 7
665remn = sub ll 7
666else
667if log_starts ls ll t_st3
668off = add ls 7
669remn = sub ll 7
670end
671end
672end
673if log_starts off remn t_fail
674ret true
675end
676if log_starts off remn t_notrun
677ret true
678end
679if lt pos tot
680pos = add pos 1
681end
682end
683ret false
684end
685
686fn log_check_last_challenge to bool
687pat_clear
688pat_push_lit t_ch_pass
689pat_push_pin
690pat_push_lit t_ch_omc
691pat_push_omc
692tot = get gmeta m_llen
693pos = ulong 0
694found = false
695matched = false
696while lt pos tot bound 32768
697ls = pos
698while lt pos tot bound 32768
699if eq get logbuf pos 10
700break
701end
702pos = add pos 1
703end
704ll = sub pos ls
705if log_starts ls ll t_ch_pfx
706found = true
707matched = log_line_matches_pat ls ll false
708end
709if lt pos tot
710pos = add pos 1
711end
712end
713if not found
714ret false
715end
716ret matched
717end
718
719fn find_space_exp pos ulong lim ulong to ulong
720p = pos
721while lt p lim bound 512
722if eq get expbuf p 32
723ret p
724end
725p = add p 1
726end
727ret lim
728end
729
730fn identify_rung p1 ulong nlen ulong to ulong
731if exp_eq p1 nlen t_seed0
732ret r_seed0
733end
734if exp_eq p1 nlen t_hex1
735ret r_hex1
736end
737if exp_eq p1 nlen t_asm2
738ret r_asm2
739end
740if exp_eq p1 nlen t_om4
741ret r_om4
742end
743if exp_eq p1 nlen t_omc
744ret r_omc
745end
746ret 99
747end
748
749fn check_omc_stages p1 ulong remn ulong to void
750pat_clear
751pat_push_lit t_st1
752pat_push_lit t_pass_rg
753pat_push_exp p1 remn
754ok = log_has_pat true
755pat_clear
756pat_push_lit t_st2
757pat_push_lit t_pass_rg
758pat_push_exp p1 remn
759if not log_has_pat true
760ok = false
761end
762pat_clear
763pat_push_lit t_st3
764pat_push_lit t_pass_rg
765pat_push_exp p1 remn
766if not log_has_pat true
767ok = false
768end
769if not ok
770put gmeta m_bad add get gmeta m_bad 1
771end
772end
773
774fn check_input_line ls ulong le_pos ulong to void
775p1 = add ls 6
776s1 = find_space_exp p1 le_pos
777if or eq s1 p1 ge s1 le_pos
778put gmeta m_expe add get gmeta m_expe 1
779ret
780end
781p2 = add s1 1
782s2 = find_space_exp p2 le_pos
783if or ne sub s2 p2 64 ge s2 le_pos
784put gmeta m_expe add get gmeta m_expe 1
785ret
786end
787if not is_hex_exp p2 64
788put gmeta m_expe add get gmeta m_expe 1
789ret
790end
791p3 = add s2 1
792if not is_dec_exp p3 sub le_pos p3
793put gmeta m_expe add get gmeta m_expe 1
794ret
795end
796pat_clear
797pat_push_lit t_pass_in
798pat_push_exp p1 sub le_pos p1
799if not log_has_pat false
800put gmeta m_bad add get gmeta m_bad 1
801end
802end
803
804fn check_rung_line ls ulong le_pos ulong to void
805p1 = add ls 5
806s1 = find_space_exp p1 le_pos
807nlen = sub s1 p1
808if or eq nlen 0 ge s1 le_pos
809put gmeta m_expe add get gmeta m_expe 1
810ret
811end
812p2 = add s1 1
813s2 = find_space_exp p2 le_pos
814if or ne sub s2 p2 64 ge s2 le_pos
815put gmeta m_expe add get gmeta m_expe 1
816ret
817end
818if not is_hex_exp p2 64
819put gmeta m_expe add get gmeta m_expe 1
820ret
821end
822p3 = add s2 1
823if not is_dec_exp p3 sub le_pos p3
824put gmeta m_expe add get gmeta m_expe 1
825ret
826end
827ridx = identify_rung p1 nlen
828if eq ridx 99
829put gmeta m_expe add get gmeta m_expe 1
830ret
831end
832put rungseen ridx 1
833if eq ridx r_omc
834for i ulong 64
835put omcsha i get expbuf add p2 i
836end
837put gmeta m_olen 64
838check_omc_stages p1 sub le_pos p1
839else
840pat_clear
841pat_push_lit t_pass_rg
842pat_push_exp p1 sub le_pos p1
843if not log_has_pat true
844put gmeta m_bad add get gmeta m_bad 1
845end
846end
847end
848
849fn verify_loaded to int
850for i ulong 8
851put rungseen i 0
852end
853put gmeta m_plen 0
854put gmeta m_olen 0
855put gmeta m_bad 0
856put gmeta m_expe 0
857etot = get gmeta m_elen
858pos = ulong 0
859while lt pos etot bound 16384
860ls = pos
861while lt pos etot bound 16384
862if eq get expbuf pos 10
863break
864end
865pos = add pos 1
866end
867ll = sub pos ls
868if gt ll 0
869if ne get expbuf ls 35
870if exp_starts ls ll t_pin
871plen = sub ll 4
872if and eq plen 40 is_hex_exp add ls 4 40
873for j ulong 40
874put pinbuf j get expbuf add add ls 4 j
875end
876put gmeta m_plen 40
877put rungseen r_pin 1
878else
879put gmeta m_expe add get gmeta m_expe 1
880end
881else
882if exp_starts ls ll t_input
883check_input_line ls pos
884else
885if exp_starts ls ll t_rung
886check_rung_line ls pos
887else
888put gmeta m_expe add get gmeta m_expe 1
889end
890end
891end
892end
893end
894if lt pos etot
895pos = add pos 1
896end
897end
898if gt get gmeta m_expe 0
899ret 2
900end
901if eq get rungseen r_pin 0
902ret 2
903end
904chain_ok = true
905for r ulong 5
906if eq get rungseen r 0
907chain_ok = false
908end
909end
910if not chain_ok
911put gmeta m_bad add get gmeta m_bad 1
912end
913pat_clear
914pat_push_lit t_pin
915pat_push_pin
916if not log_has_pat false
917put gmeta m_bad add get gmeta m_bad 1
918end
919if not log_has_aarch64_host
920put gmeta m_bad add get gmeta m_bad 1
921end
922if log_has_fail_or_notrun
923put gmeta m_bad add get gmeta m_bad 1
924end
925if not log_check_last_challenge
926put gmeta m_bad add get gmeta m_bad 1
927end
928if eq get gmeta m_bad 0
929ret 0
930end
931ret 1
932end
933
934fn load_valid_exp to void
935exp_reset
936exp_append exp_v1_a
937exp_append exp_v1_b
938exp_append exp_v1_c
939end
940
941fn load_valid_log to void
942log_reset
943log_append log_v1_a
944log_append log_v1_b
945log_append log_v1_c
946log_append log_v1_d
947log_append log_v1_e
948end
949
950fn test_sha_and_flip to void
951note Test 1: SHA-256 KATs (empty and "abc")
952empty_arr = new uchar 4 0
953if not verify_rung_bytes empty_arr 0 sha_empty
954fail_case 1
955end
956if not verify_rung_bytes msg_abc 3 sha_abc
957fail_case 1
958end
959wstr 1 p_sha_kat
960note Test 2: negative control - flip 1 bit in rung bytes ("abc" -> "bbc") must fail
961rung_buf = new uchar 8 0
962put rung_buf 0 97
963put rung_buf 1 98
964put rung_buf 2 99
965if not verify_rung_bytes rung_buf 3 sha_abc
966fail_case 2
967end
968put rung_buf 0 98
969if verify_rung_bytes rung_buf 3 sha_abc
970fail_case 2
971end
972wstr 1 p_flip_byte
973end
974
975fn test_hex_formats to void
976note Test 3: strict 64-hex and 40-hex lowercase format validation
977if not is_hex_view sha_abc 64
978fail_case 3
979end
980if not is_hex_view pin_ok 40
981fail_case 3
982end
983if is_hex_view hex_short 64
984fail_case 3
985end
986if is_hex_view hex_upper 64
987fail_case 3
988end
989if is_hex_view hex_badch 64
990fail_case 3
991end
992wstr 1 p_hex_fmt
993end
994
995fn main to int
996test_sha_and_flip
997test_hex_formats
998
999note Test 4: positive full v1 ladder + DGX Spark log
1000load_valid_exp
1001load_valid_log
1002if ne verify_loaded 0
1003fail_case 4
1004end
1005wstr 1 p_valid_v1
1006
1007note Test 5: negative control - forged stage2 omc digest
1008load_valid_exp
1009log_reset
1010log_append log_v1_a
1011log_append log_v1_b
1012log_append log_v1_c
1013log_append log_bad_st2
1014log_append log_v1_e
1015if ne verify_loaded 1
1016fail_case 5
1017end
1018wstr 1 p_neg_st2
1019
1020note Test 6: negative control - incomplete rung chain (missing asm2)
1021exp_reset
1022exp_append exp_v1_a
1023exp_append exp_v1_b
1024exp_append exp_no_asm2
1025load_valid_log
1026if ne verify_loaded 1
1027fail_case 6
1028end
1029wstr 1 p_neg_chain
1030
1031note Test 7: negative control - injected FAIL line in log
1032load_valid_exp
1033load_valid_log
1034log_append log_inj_fail
1035if ne verify_loaded 1
1036fail_case 7
1037end
1038wstr 1 p_neg_fail
1039
1040note Test 8: negative control - non-aarch64 host line
1041load_valid_exp
1042log_reset
1043log_append log_x86_host
1044log_append log_v1_b
1045log_append log_v1_c
1046log_append log_v1_d
1047log_append log_v1_e
1048if ne verify_loaded 1
1049fail_case 8
1050end
1051wstr 1 p_neg_host
1052
1053note Test 9: negative control - malformed expected digest (uppercase hex)
1054exp_reset
1055exp_append exp_bad_hex
1056load_valid_log
1057if ne verify_loaded 2
1058fail_case 9
1059end
1060wstr 1 p_neg_exp
1061
1062note Test 10: negative control - forged final CHALLENGE footer
1063load_valid_exp
1064log_reset
1065log_append log_v1_a
1066log_append log_v1_b
1067log_append log_v1_c
1068log_append log_v1_d
1069log_append log_bad_foot
1070if ne verify_loaded 1
1071fail_case 10
1072end
1073wstr 1 p_neg_foot
1074
1075wstr 1 p_all
1076ret 0
1077end