Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/si/seed-challenge/challenge.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / si / seed-challenge / challenge.om` 1171 lines ยท 20051 bytes Raw Blame History 1 om2 2 note si/seed-challenge/challenge.om: Pure-Omega seed-ladder pin table and challenge log verifier. 3 note Faithful OM-2 conversion of omega-seed-challenge (check-result.sh + seed0->hex1->asm2->om4->omc ladder). 4 note Implements FIPS 180-4 SHA-256, strict 40-hex commit pin and 64-hex digest validation, 5 note 5-rung chain completeness verification, challenge log auditing (including stage1..stage3 omc fixpoint), 6 note and fail-closed refusal diagnostics. 7 note Usage: 8 note challenge (verify two files) 9 note challenge < combined.txt (stdin with '---' line separating expected table and log) 10 note Exit codes: 0 = RESULT ACCEPTED, 1 = RESULT REFUSED, 2 = usage / I/O / malformed expected table. 11 12 global expbuf uchar 16384 13 global logbuf uchar 32768 14 global pinbuf uchar 64 15 global omcsha uchar 64 16 global patbuf uchar 512 17 global decbuf uchar 32 18 global argbuf uchar 512 19 global rdbuf uchar 4096 20 global rungseen ulong 8 21 global gmeta ulong 12 22 global shastate uint 8 23 global shak uint 64 24 global shaw uint 64 25 global shablk uchar 64 26 global shadig uchar 32 27 global shahex uchar 64 28 29 note gmeta indices 30 const m_elen ulong 0 31 const m_llen ulong 1 32 const m_plen ulong 2 33 const m_olen ulong 3 34 const m_bad ulong 4 35 const m_patlen ulong 5 36 const m_expe ulong 6 37 const m_lastch ulong 7 38 39 note rungseen indices: 0..4 are seed0, hex1, asm2, om4, omc; 5=pin, 6=inputs, 7=rungs 40 const r_seed0 ulong 0 41 const r_hex1 ulong 1 42 const r_asm2 ulong 2 43 const r_om4 ulong 3 44 const r_omc ulong 4 45 const r_pin ulong 5 46 const r_incnt ulong 6 47 const r_rcnt ulong 7 48 49 text khex "`0123456789abcdef`" 50 text t_nl "\n" 51 text t_sp " " 52 text t_pin "pin " 53 text t_input "input " 54 text t_rung "rung " 55 text t_seed0 "seed0" 56 text t_hex1 "hex1" 57 text t_asm2 "asm2" 58 text t_om4 "om4" 59 text t_omc "omc" 60 text t_host "host " 61 text t_a64 "aarch64" 62 text t_pass_in "PASS input " 63 text t_pass_rg "PASS rung " 64 text t_st1 "stage1 " 65 text t_st2 "stage2 " 66 text t_st3 "stage3 " 67 text t_fail "FAIL " 68 text t_notrun "NOT_RUN " 69 text t_ch_pfx "CHALLENGE " 70 text t_ch_pass "CHALLENGE PASS pin=" 71 text t_ch_omc " omc=" 72 text t_sep "---" 73 text t_ref_pfx "REFUSED " 74 text t_ref_pin "log does not name expected pin\n" 75 text t_ref_host "host line does not say aarch64\n" 76 text t_ref_in "input line missing or mismatched in log\n" 77 text t_ref_rg "rung line missing or mismatched in log\n" 78 text t_ref_st "omc stage1..3 fixpoint line missing or mismatched in log\n" 79 text t_ref_fn "log contains FAIL or NOT_RUN lines\n" 80 text t_ref_last "final CHALLENGE line does not match CHALLENGE PASS pin= omc=\n" 81 text t_ref_chain "expected table missing required seed ladder rung (seed0/hex1/asm2/om4/omc)\n" 82 text t_ref_expe "expected table contains malformed pin, digest, or entry\n" 83 text t_acc1 "RESULT ACCEPTED pin=" 84 text t_acc2 " omc=" 85 text t_rej1 "RESULT REFUSED reasons=" 86 text t_usage "usage: challenge (or stdin with --- separator)\n" 87 text t_ioerr "challenge: failed to read input file\n" 88 89 fn write_all fd int src view uchar * off ulong n ulong to void 90 p = ulong 0 91 while lt p n bound 65536 92 k = write fd src add off p sub n p 93 if le k 0 94 exit 2 95 end 96 p = add p ulong k 97 end 98 end 99 100 fn wstr fd int s view uchar * to void 101 write_all fd s 0 len s 102 end 103 104 fn wdec fd int v ulong to void 105 i = ulong 32 106 n = v 107 while true bound 24 108 i = sub i 1 109 put decbuf i uchar add rem n 10 48 110 n = div n 10 111 if eq n 0 112 break 113 end 114 end 115 p = i 116 while lt p 32 bound 32 117 k = write fd decbuf p sub 32 p 118 if le k 0 119 exit 2 120 end 121 p = add p ulong k 122 end 123 end 124 125 fn wpin fd int to void 126 n = get gmeta m_plen 127 p = ulong 0 128 while lt p n bound 64 129 k = write fd pinbuf p sub n p 130 if le k 0 131 exit 2 132 end 133 p = add p ulong k 134 end 135 end 136 137 fn womc fd int to void 138 n = get gmeta m_olen 139 p = ulong 0 140 while lt p n bound 64 141 k = write fd omcsha p sub n p 142 if le k 0 143 exit 2 144 end 145 p = add p ulong k 146 end 147 end 148 149 fn is_hex_ch c uchar to bool 150 if and ge c 48 le c 57 151 ret true 152 end 153 if and ge c 97 le c 102 154 ret true 155 end 156 ret false 157 end 158 159 fn is_dig_ch c uchar to bool 160 ret and ge c 48 le c 57 161 end 162 163 fn is_hex_exp off ulong n ulong to bool 164 if eq n 0 165 ret false 166 end 167 if gt add off n 16384 168 ret false 169 end 170 i = ulong 0 171 while lt i n bound 128 172 if not is_hex_ch get expbuf add off i 173 ret false 174 end 175 i = add i 1 176 end 177 ret true 178 end 179 180 fn is_dec_exp off ulong n ulong to bool 181 if eq n 0 182 ret false 183 end 184 if gt n 20 185 ret false 186 end 187 if gt add off n 16384 188 ret false 189 end 190 nz = false 191 i = ulong 0 192 while lt i n bound 32 193 c = get expbuf add off i 194 if not is_dig_ch c 195 ret false 196 end 197 if ne c 48 198 nz = true 199 end 200 i = add i 1 201 end 202 ret nz 203 end 204 205 fn is_hex_view s view uchar * n ulong to bool 206 if ne len s n 207 ret false 208 end 209 i = ulong 0 210 while lt i n bound 128 211 if not is_hex_ch get s i 212 ret false 213 end 214 i = add i 1 215 end 216 ret true 217 end 218 219 note FIPS 180-4 SHA-256 constants and block compression 220 fn sha_kinit to void 221 put shak 0 0x428a2f98 222 put shak 1 0x71374491 223 put shak 2 0xb5c0fbcf 224 put shak 3 0xe9b5dba5 225 put shak 4 0x3956c25b 226 put shak 5 0x59f111f1 227 put shak 6 0x923f82a4 228 put shak 7 0xab1c5ed5 229 put shak 8 0xd807aa98 230 put shak 9 0x12835b01 231 put shak 10 0x243185be 232 put shak 11 0x550c7dc3 233 put shak 12 0x72be5d74 234 put shak 13 0x80deb1fe 235 put shak 14 0x9bdc06a7 236 put shak 15 0xc19bf174 237 put shak 16 0xe49b69c1 238 put shak 17 0xefbe4786 239 put shak 18 0x0fc19dc6 240 put shak 19 0x240ca1cc 241 put shak 20 0x2de92c6f 242 put shak 21 0x4a7484aa 243 put shak 22 0x5cb0a9dc 244 put shak 23 0x76f988da 245 put shak 24 0x983e5152 246 put shak 25 0xa831c66d 247 put shak 26 0xb00327c8 248 put shak 27 0xbf597fc7 249 put shak 28 0xc6e00bf3 250 put shak 29 0xd5a79147 251 put shak 30 0x06ca6351 252 put shak 31 0x14292967 253 put shak 32 0x27b70a85 254 put shak 33 0x2e1b2138 255 put shak 34 0x4d2c6dfc 256 put shak 35 0x53380d13 257 put shak 36 0x650a7354 258 put shak 37 0x766a0abb 259 put shak 38 0x81c2c92e 260 put shak 39 0x92722c85 261 put shak 40 0xa2bfe8a1 262 put shak 41 0xa81a664b 263 put shak 42 0xc24b8b70 264 put shak 43 0xc76c51a3 265 put shak 44 0xd192e819 266 put shak 45 0xd6990624 267 put shak 46 0xf40e3585 268 put shak 47 0x106aa070 269 put shak 48 0x19a4c116 270 put shak 49 0x1e376c08 271 put shak 50 0x2748774c 272 put shak 51 0x34b0bcb5 273 put shak 52 0x391c0cb3 274 put shak 53 0x4ed8aa4a 275 put shak 54 0x5b9cca4f 276 put shak 55 0x682e6ff3 277 put shak 56 0x748f82ee 278 put shak 57 0x78a5636f 279 put shak 58 0x84c87814 280 put shak 59 0x8cc70208 281 put shak 60 0x90befffa 282 put shak 61 0xa4506ceb 283 put shak 62 0xbef9a3f7 284 put shak 63 0xc67178f2 285 end 286 287 fn sha_iv to void 288 put shastate 0 0x6a09e667 289 put shastate 1 0xbb67ae85 290 put shastate 2 0x3c6ef372 291 put shastate 3 0xa54ff53a 292 put shastate 4 0x510e527f 293 put shastate 5 0x9b05688c 294 put shastate 6 0x1f83d9ab 295 put shastate 7 0x5be0cd19 296 end 297 298 fn sha_sched to void 299 for i ulong 16 300 q = mul i 4 301 x = uint get shablk q 302 x = or shl x 8 uint get shablk add q 1 303 x = or shl x 8 uint get shablk add q 2 304 put shaw i or shl x 8 uint get shablk add q 3 305 end 306 for i ulong 48 307 x = get shaw add i 1 308 y = get shaw add i 14 309 s0 = xor xor rotr x 7 rotr x 18 shr x 3 310 s1 = xor xor rotr y 17 rotr y 19 shr y 10 311 put shaw add i 16 add add get shaw i get shaw add i 9 add s0 s1 312 end 313 end 314 315 fn sha_compress to void 316 sha_sched 317 a = get shastate 0 318 b = get shastate 1 319 c = get shastate 2 320 d = get shastate 3 321 e = get shastate 4 322 f = get shastate 5 323 g = get shastate 6 324 h = get shastate 7 325 t = uint 0 326 for i ulong 64 327 h = add h get shak i 328 h = add h get shaw i 329 t = xor rotr e 6 rotr e 11 330 t = xor t rotr e 25 331 h = add h t 332 h = add h xor g and e xor f g 333 d = add d h 334 t = xor rotr a 2 rotr a 13 335 t = xor t rotr a 22 336 h = add h t 337 h = add h or and a b and c or a b 338 t = h 339 h = g 340 g = f 341 f = e 342 e = d 343 d = c 344 c = b 345 b = a 346 a = t 347 end 348 put shastate 0 add get shastate 0 a 349 put shastate 1 add get shastate 1 b 350 put shastate 2 add get shastate 2 c 351 put shastate 3 add get shastate 3 d 352 put shastate 4 add get shastate 4 e 353 put shastate 5 add get shastate 5 f 354 put shastate 6 add get shastate 6 g 355 put shastate 7 add get shastate 7 h 356 end 357 358 fn sha256_bytes src view uchar * dlen ulong to void 359 sha_kinit 360 sha_iv 361 off = ulong 0 362 while ge sub dlen off 64 bound 65536 363 for j ulong 64 364 put shablk j get src add off j 365 end 366 sha_compress 367 off = add off 64 368 end 369 remn = sub dlen off 370 for j ulong 64 371 if lt j remn 372 put shablk j get src add off j 373 else 374 put shablk j 0 375 end 376 end 377 put shablk remn 0x80 378 if gt remn 55 379 sha_compress 380 for j ulong 64 381 put shablk j 0 382 end 383 end 384 bits = mul dlen 8 385 put shablk 56 uchar and shr bits 56 255 386 put shablk 57 uchar and shr bits 48 255 387 put shablk 58 uchar and shr bits 40 255 388 put shablk 59 uchar and shr bits 32 255 389 put shablk 60 uchar and shr bits 24 255 390 put shablk 61 uchar and shr bits 16 255 391 put shablk 62 uchar and shr bits 8 255 392 put shablk 63 uchar and bits 255 393 sha_compress 394 for i ulong 8 395 w = get shastate i 396 b0 = uchar and shr w 24 255 397 b1 = uchar and shr w 16 255 398 b2 = uchar and shr w 8 255 399 b3 = uchar and w 255 400 q = mul i 4 401 put shadig q b0 402 put shadig add q 1 b1 403 put shadig add q 2 b2 404 put shadig add q 3 b3 405 end 406 for i ulong 32 407 bv = ulong get shadig i 408 put shahex mul i 2 get khex shr bv 4 409 put shahex add mul i 2 1 get khex and bv 15 410 end 411 end 412 413 fn verify_rung_bytes src view uchar * dlen ulong exphex view uchar * to bool 414 if not is_hex_view exphex 64 415 ret false 416 end 417 sha256_bytes src dlen 418 for i ulong 64 419 if ne get shahex i get exphex i 420 ret false 421 end 422 end 423 ret true 424 end 425 426 note Pattern buffer helpers 427 fn pat_clear to void 428 put gmeta m_patlen 0 429 end 430 431 fn pat_push_ch c uchar to void 432 n = get gmeta m_patlen 433 if lt n 512 434 put patbuf n c 435 put gmeta m_patlen add n 1 436 end 437 end 438 439 fn pat_push_lit s view uchar * to void 440 sl = len s 441 i = ulong 0 442 while lt i sl bound 512 443 pat_push_ch get s i 444 i = add i 1 445 end 446 end 447 448 fn pat_push_exp off ulong n ulong to void 449 i = ulong 0 450 while lt i n bound 512 451 if lt add off i 16384 452 pat_push_ch get expbuf add off i 453 end 454 i = add i 1 455 end 456 end 457 458 fn pat_push_pin to void 459 n = get gmeta m_plen 460 i = ulong 0 461 while lt i n bound 64 462 pat_push_ch get pinbuf i 463 i = add i 1 464 end 465 end 466 467 fn pat_push_omc to void 468 n = get gmeta m_olen 469 i = ulong 0 470 while lt i n bound 64 471 pat_push_ch get omcsha i 472 i = add i 1 473 end 474 end 475 476 note Compare expbuf slice against literal 477 fn exp_eq off ulong n ulong lit view uchar * to bool 478 if ne n len lit 479 ret false 480 end 481 i = ulong 0 482 while lt i n bound 512 483 if ne get expbuf add off i get lit i 484 ret false 485 end 486 i = add i 1 487 end 488 ret true 489 end 490 491 fn exp_starts off ulong elen ulong pfx view uchar * to bool 492 pl = len pfx 493 if lt elen pl 494 ret false 495 end 496 i = ulong 0 497 while lt i pl bound 512 498 if ne get expbuf add off i get pfx i 499 ret false 500 end 501 i = add i 1 502 end 503 ret true 504 end 505 506 fn log_starts off ulong llen ulong pfx view uchar * to bool 507 pl = len pfx 508 if lt llen pl 509 ret false 510 end 511 i = ulong 0 512 while lt i pl bound 512 513 if ne get logbuf add off i get pfx i 514 ret false 515 end 516 i = add i 1 517 end 518 ret true 519 end 520 521 fn log_contains off ulong llen ulong needle view uchar * to bool 522 nl = len needle 523 if gt nl llen 524 ret false 525 end 526 lim = add sub llen nl 1 527 i = ulong 0 528 while lt i lim bound 1024 529 if log_starts add off i sub llen i needle 530 ret true 531 end 532 i = add i 1 533 end 534 ret false 535 end 536 537 note Check if logbuf[off..off+llen) equals patbuf[0..patlen) exactly, or with optional " ms" suffix 538 fn log_line_matches_pat off ulong llen ulong allow_ms bool to bool 539 pl = get gmeta m_patlen 540 if lt llen pl 541 ret false 542 end 543 i = ulong 0 544 while lt i pl bound 512 545 if ne get logbuf add off i get patbuf i 546 ret false 547 end 548 i = add i 1 549 end 550 if eq llen pl 551 ret true 552 end 553 if not allow_ms 554 ret false 555 end 556 if lt sub llen pl 4 557 ret false 558 end 559 if ne get logbuf add off pl 32 560 ret false 561 end 562 if ne get logbuf add off sub llen 2 109 563 ret false 564 end 565 if ne get logbuf add off sub llen 1 115 566 ret false 567 end 568 pos = add pl 1 569 endpos = sub llen 2 570 if ge pos endpos 571 ret false 572 end 573 while lt pos endpos bound 32 574 if not is_dig_ch get logbuf add off pos 575 ret false 576 end 577 pos = add pos 1 578 end 579 ret true 580 end 581 582 fn log_has_pat allow_ms bool to bool 583 tot = get gmeta m_llen 584 pos = ulong 0 585 while lt pos tot bound 32768 586 ls = pos 587 while lt pos tot bound 32768 588 if eq get logbuf pos 10 589 break 590 end 591 pos = add pos 1 592 end 593 ll = sub pos ls 594 if log_line_matches_pat ls ll allow_ms 595 ret true 596 end 597 if lt pos tot 598 pos = add pos 1 599 end 600 end 601 ret false 602 end 603 604 fn log_has_aarch64_host to bool 605 tot = get gmeta m_llen 606 pos = ulong 0 607 while lt pos tot bound 32768 608 ls = pos 609 while lt pos tot bound 32768 610 if eq get logbuf pos 10 611 break 612 end 613 pos = add pos 1 614 end 615 ll = sub pos ls 616 if log_starts ls ll t_host 617 if log_contains ls ll t_a64 618 ret true 619 end 620 end 621 if lt pos tot 622 pos = add pos 1 623 end 624 end 625 ret false 626 end 627 628 fn log_has_fail_or_notrun to bool 629 tot = get gmeta m_llen 630 pos = ulong 0 631 while lt pos tot bound 32768 632 ls = pos 633 while lt pos tot bound 32768 634 if eq get logbuf pos 10 635 break 636 end 637 pos = add pos 1 638 end 639 ll = sub pos ls 640 off = ls 641 remn = ll 642 if log_starts ls ll t_st1 643 off = add ls 7 644 remn = sub ll 7 645 else 646 if log_starts ls ll t_st2 647 off = add ls 7 648 remn = sub ll 7 649 else 650 if log_starts ls ll t_st3 651 off = add ls 7 652 remn = sub ll 7 653 end 654 end 655 end 656 if log_starts off remn t_fail 657 ret true 658 end 659 if log_starts off remn t_notrun 660 ret true 661 end 662 if lt pos tot 663 pos = add pos 1 664 end 665 end 666 ret false 667 end 668 669 fn log_check_last_challenge to bool 670 pat_clear 671 pat_push_lit t_ch_pass 672 pat_push_pin 673 pat_push_lit t_ch_omc 674 pat_push_omc 675 tot = get gmeta m_llen 676 pos = ulong 0 677 found = false 678 matched = false 679 while lt pos tot bound 32768 680 ls = pos 681 while lt pos tot bound 32768 682 if eq get logbuf pos 10 683 break 684 end 685 pos = add pos 1 686 end 687 ll = sub pos ls 688 if log_starts ls ll t_ch_pfx 689 found = true 690 matched = log_line_matches_pat ls ll false 691 end 692 if lt pos tot 693 pos = add pos 1 694 end 695 end 696 if not found 697 ret false 698 end 699 ret matched 700 end 701 702 fn record_refusal msg view uchar * quiet bool to void 703 put gmeta m_bad add get gmeta m_bad 1 704 if not quiet 705 wstr 1 t_ref_pfx 706 wstr 1 msg 707 end 708 end 709 710 fn find_space_exp pos ulong lim ulong to ulong 711 p = pos 712 while lt p lim bound 512 713 if eq get expbuf p 32 714 ret p 715 end 716 p = add p 1 717 end 718 ret lim 719 end 720 721 fn check_input_line ls ulong le_pos ulong quiet bool to void 722 p1 = add ls 6 723 s1 = find_space_exp p1 le_pos 724 if or eq s1 p1 ge s1 le_pos 725 put gmeta m_expe add get gmeta m_expe 1 726 ret 727 end 728 p2 = add s1 1 729 s2 = find_space_exp p2 le_pos 730 if or ne sub s2 p2 64 ge s2 le_pos 731 put gmeta m_expe add get gmeta m_expe 1 732 ret 733 end 734 if not is_hex_exp p2 64 735 put gmeta m_expe add get gmeta m_expe 1 736 ret 737 end 738 p3 = add s2 1 739 b3 = sub le_pos p3 740 if not is_dec_exp p3 b3 741 put gmeta m_expe add get gmeta m_expe 1 742 ret 743 end 744 put rungseen r_incnt add get rungseen r_incnt 1 745 pat_clear 746 pat_push_lit t_pass_in 747 pat_push_exp p1 sub le_pos p1 748 if not log_has_pat false 749 record_refusal t_ref_in quiet 750 end 751 end 752 753 fn identify_rung p1 ulong nlen ulong to ulong 754 if exp_eq p1 nlen t_seed0 755 ret r_seed0 756 end 757 if exp_eq p1 nlen t_hex1 758 ret r_hex1 759 end 760 if exp_eq p1 nlen t_asm2 761 ret r_asm2 762 end 763 if exp_eq p1 nlen t_om4 764 ret r_om4 765 end 766 if exp_eq p1 nlen t_omc 767 ret r_omc 768 end 769 ret 99 770 end 771 772 fn check_omc_stages p1 ulong remn ulong quiet bool to void 773 pat_clear 774 pat_push_lit t_st1 775 pat_push_lit t_pass_rg 776 pat_push_exp p1 remn 777 ok = log_has_pat true 778 pat_clear 779 pat_push_lit t_st2 780 pat_push_lit t_pass_rg 781 pat_push_exp p1 remn 782 if not log_has_pat true 783 ok = false 784 end 785 pat_clear 786 pat_push_lit t_st3 787 pat_push_lit t_pass_rg 788 pat_push_exp p1 remn 789 if not log_has_pat true 790 ok = false 791 end 792 if not ok 793 record_refusal t_ref_st quiet 794 end 795 end 796 797 fn check_rung_line ls ulong le_pos ulong quiet bool to void 798 p1 = add ls 5 799 s1 = find_space_exp p1 le_pos 800 nlen = sub s1 p1 801 if or eq nlen 0 ge s1 le_pos 802 put gmeta m_expe add get gmeta m_expe 1 803 ret 804 end 805 p2 = add s1 1 806 s2 = find_space_exp p2 le_pos 807 if or ne sub s2 p2 64 ge s2 le_pos 808 put gmeta m_expe add get gmeta m_expe 1 809 ret 810 end 811 if not is_hex_exp p2 64 812 put gmeta m_expe add get gmeta m_expe 1 813 ret 814 end 815 p3 = add s2 1 816 if not is_dec_exp p3 sub le_pos p3 817 put gmeta m_expe add get gmeta m_expe 1 818 ret 819 end 820 ridx = identify_rung p1 nlen 821 if eq ridx 99 822 put gmeta m_expe add get gmeta m_expe 1 823 ret 824 end 825 put rungseen ridx 1 826 put rungseen r_rcnt add get rungseen r_rcnt 1 827 if eq ridx r_omc 828 for i ulong 64 829 put omcsha i get expbuf add p2 i 830 end 831 put gmeta m_olen 64 832 check_omc_stages p1 sub le_pos p1 quiet 833 else 834 pat_clear 835 pat_push_lit t_pass_rg 836 pat_push_exp p1 sub le_pos p1 837 if not log_has_pat true 838 record_refusal t_ref_rg quiet 839 end 840 end 841 end 842 843 fn verify_loaded quiet bool to int 844 for i ulong 8 845 put rungseen i 0 846 end 847 put gmeta m_plen 0 848 put gmeta m_olen 0 849 put gmeta m_bad 0 850 put gmeta m_expe 0 851 etot = get gmeta m_elen 852 pos = ulong 0 853 while lt pos etot bound 16384 854 ls = pos 855 while lt pos etot bound 16384 856 if eq get expbuf pos 10 857 break 858 end 859 pos = add pos 1 860 end 861 ll = sub pos ls 862 if gt ll 0 863 if ne get expbuf ls 35 864 if exp_starts ls ll t_pin 865 plen = sub ll 4 866 if and eq plen 40 is_hex_exp add ls 4 40 867 for j ulong 40 868 put pinbuf j get expbuf add add ls 4 j 869 end 870 put gmeta m_plen 40 871 put rungseen r_pin 1 872 else 873 put gmeta m_expe add get gmeta m_expe 1 874 end 875 else 876 if exp_starts ls ll t_input 877 check_input_line ls pos quiet 878 else 879 if exp_starts ls ll t_rung 880 check_rung_line ls pos quiet 881 else 882 put gmeta m_expe add get gmeta m_expe 1 883 end 884 end 885 end 886 end 887 end 888 if lt pos etot 889 pos = add pos 1 890 end 891 end 892 if gt get gmeta m_expe 0 893 record_refusal t_ref_expe quiet 894 ret 2 895 end 896 if eq get rungseen r_pin 0 897 record_refusal t_ref_expe quiet 898 ret 2 899 end 900 chain_ok = true 901 for r ulong 5 902 if eq get rungseen r 0 903 chain_ok = false 904 end 905 end 906 if not chain_ok 907 record_refusal t_ref_chain quiet 908 end 909 pat_clear 910 pat_push_lit t_pin 911 pat_push_pin 912 if not log_has_pat false 913 record_refusal t_ref_pin quiet 914 end 915 if not log_has_aarch64_host 916 record_refusal t_ref_host quiet 917 end 918 if log_has_fail_or_notrun 919 record_refusal t_ref_fn quiet 920 end 921 if not log_check_last_challenge 922 record_refusal t_ref_last quiet 923 end 924 if eq get gmeta m_bad 0 925 ret 0 926 end 927 ret 1 928 end 929 930 fn read_file_into_exp plen ulong to bool 931 fd = fopen argbuf 0 plen 0 0 932 if lt fd 0 933 ret false 934 end 935 tot = ulong 0 936 while true bound 256 937 k = read int fd rdbuf 0 4096 938 if lt k 0 939 cl = fclose int fd 940 if lt cl 0 941 ret false 942 end 943 ret false 944 end 945 if eq k 0 946 break 947 end 948 kn = ulong k 949 i = ulong 0 950 while lt i kn bound 4096 951 c = get rdbuf i 952 if ne c 13 953 if ge tot 16384 954 cl2 = fclose int fd 955 if lt cl2 0 956 ret false 957 end 958 ret false 959 end 960 put expbuf tot c 961 tot = add tot 1 962 end 963 i = add i 1 964 end 965 end 966 cl3 = fclose int fd 967 if lt cl3 0 968 ret false 969 end 970 put gmeta m_elen tot 971 ret true 972 end 973 974 fn read_file_into_log plen ulong to bool 975 fd = fopen argbuf 0 plen 0 0 976 if lt fd 0 977 ret false 978 end 979 tot = ulong 0 980 while true bound 256 981 k = read int fd rdbuf 0 4096 982 if lt k 0 983 cl = fclose int fd 984 if lt cl 0 985 ret false 986 end 987 ret false 988 end 989 if eq k 0 990 break 991 end 992 kn = ulong k 993 i = ulong 0 994 while lt i kn bound 4096 995 c = get rdbuf i 996 if ne c 13 997 if ge tot 32768 998 cl2 = fclose int fd 999 if lt cl2 0 1000 ret false 1001 end 1002 ret false 1003 end 1004 put logbuf tot c 1005 tot = add tot 1 1006 end 1007 i = add i 1 1008 end 1009 end 1010 cl3 = fclose int fd 1011 if lt cl3 0 1012 ret false 1013 end 1014 put gmeta m_llen tot 1015 ret true 1016 end 1017 1018 fn is_sep_line lpos ulong to bool 1019 if ne lpos 3 1020 ret false 1021 end 1022 if ne get patbuf 0 45 1023 ret false 1024 end 1025 if ne get patbuf 1 45 1026 ret false 1027 end 1028 ret eq get patbuf 2 45 1029 end 1030 1031 fn flush_pat_line in_log bool lpos ulong add_nl bool to bool 1032 j = ulong 0 1033 if not in_log 1034 etot = get gmeta m_elen 1035 while lt j lpos bound 512 1036 if ge etot 16384 1037 ret false 1038 end 1039 put expbuf etot get patbuf j 1040 etot = add etot 1 1041 j = add j 1 1042 end 1043 if add_nl 1044 if ge etot 16384 1045 ret false 1046 end 1047 put expbuf etot 10 1048 etot = add etot 1 1049 end 1050 put gmeta m_elen etot 1051 ret true 1052 end 1053 ltot = get gmeta m_llen 1054 while lt j lpos bound 512 1055 if ge ltot 32768 1056 ret false 1057 end 1058 put logbuf ltot get patbuf j 1059 ltot = add ltot 1 1060 j = add j 1 1061 end 1062 if add_nl 1063 if ge ltot 32768 1064 ret false 1065 end 1066 put logbuf ltot 10 1067 ltot = add ltot 1 1068 end 1069 put gmeta m_llen ltot 1070 ret true 1071 end 1072 1073 fn read_stdin_split to bool 1074 put gmeta m_elen 0 1075 put gmeta m_llen 0 1076 in_log = false 1077 lpos = ulong 0 1078 while true bound 256 1079 k = read 0 rdbuf 0 4096 1080 if lt k 0 1081 ret false 1082 end 1083 if eq k 0 1084 break 1085 end 1086 kn = ulong k 1087 i = ulong 0 1088 while lt i kn bound 4096 1089 c = get rdbuf i 1090 if ne c 13 1091 if eq c 10 1092 sep = false 1093 if not in_log 1094 sep = is_sep_line lpos 1095 end 1096 if sep 1097 in_log = true 1098 lpos = ulong 0 1099 else 1100 if not flush_pat_line in_log lpos true 1101 ret false 1102 end 1103 lpos = ulong 0 1104 end 1105 else 1106 if lt lpos 512 1107 put patbuf lpos c 1108 lpos = add lpos 1 1109 end 1110 end 1111 end 1112 i = add i 1 1113 end 1114 end 1115 if gt lpos 0 1116 if not flush_pat_line in_log lpos false 1117 ret false 1118 end 1119 end 1120 ret in_log 1121 end 1122 1123 fn main to int 1124 ac = argcnt 1125 if eq ac 3 1126 n1 = argread 1 argbuf 0 512 1127 if le n1 0 1128 wstr 2 t_usage 1129 ret 2 1130 end 1131 if not read_file_into_exp ulong n1 1132 wstr 2 t_ioerr 1133 ret 2 1134 end 1135 n2 = argread 2 argbuf 0 512 1136 if le n2 0 1137 wstr 2 t_usage 1138 ret 2 1139 end 1140 if not read_file_into_log ulong n2 1141 wstr 2 t_ioerr 1142 ret 2 1143 end 1144 else 1145 if eq ac 1 1146 if not read_stdin_split 1147 wstr 2 t_usage 1148 ret 2 1149 end 1150 else 1151 wstr 2 t_usage 1152 ret 2 1153 end 1154 end 1155 rc = verify_loaded false 1156 if eq rc 0 1157 wstr 1 t_acc1 1158 wpin 1 1159 wstr 1 t_acc2 1160 womc 1 1161 wstr 1 t_nl 1162 ret 0 1163 end 1164 if eq rc 2 1165 ret 2 1166 end 1167 wstr 1 t_rej1 1168 wdec 1 get gmeta m_bad 1169 wstr 1 t_nl 1170 ret 1 1171 end