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/omtls/blob/main/tools/gate.om # omtls omtls: a TLS 1.3 client (RFC 8446) written fresh in seeded Omega, for mailhand. Not audited by a cryptographer. Free (Apache-2.0). Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omtls / tools / gate.om` 902 lines ยท 17169 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note gate.om: the omtls gate. Build: build/boot gate (units/gate.list). Run from the repository root: 3 note build/gate [GATE-FILE] (default tests/GATE) 4 note First it reads PIN (the one place the compiler pin is written: "omega-mv <40 hex>" then "omc-sha256 <64 hex>") 5 note and checks that ./omc has that sha256 (exit 2, "NOT_RUN", otherwise). Then it runs the steps of the 6 note gate file in order, one per line ("note" lines and blank lines skipped): 7 note build UNIT build/boot UNIT must exit 0 8 note run UNIT EXIT PREFIX ARGS... build/UNIT ARGS... must exit EXIT and its last stdout line must start with PREFIX 9 note ("-" for no line check); stdin is /dev/null 10 note mut NAME UNIT MUTFILE ARGS... build/boot UNIT MUTFILE NAME must exit 0, then build/UNIT.mut ARGS... must NOT 11 note exit 0 (the mutant is killed); a trap or signal also kills it 12 note ctscan UNIT build/boot UNIT, then the emitted AArch64 words must contain no conditional branch 13 note (B.cond, CBZ, CBNZ, TBZ, TBNZ), no UDIV/SDIV, no register-offset load or store and no 14 note indirect branch (BR/BLR: the trap path); see README "Constant time" 15 note ctmut NAME UNIT MUTFILE the mutant built for a ctscan unit must be flagged by the scan 16 note pincheck no tracked file but PIN restates the pin: a whole hex word of 7 or more digits 17 note that is a prefix of the PIN revision or compiler sha256 is a finding (git ls-files) 18 note Every child gets 3600 seconds; running out is a failure, never a pass (an alarm, not a capacity limit). 19 note Output: one line per step, then "OMTLS GATE PASS steps=N mutants-killed=K/M" (exit 0) or "OMTLS GATE FAIL ..." (exit 1). 20 const GT_LIMIT long `3600000000000` 21 global gt_file uchar `8388608` 22 global gt_buf uchar `8388608` 23 global gt_v ulong 64 24 global gt_pk uchar 65536 25 global gt_tok ulong 4096 26 global gt_path uchar 8192 27 global gt_pinv uchar 256 28 global gt_list uchar `1048576` 29 text gt_pinf "PIN" 30 text gt_pmv "omega-mv " 31 text gt_psha "omc-sha256 " 32 text gt_git "/usr/bin/git" 33 text gt_lsf "ls-files" 34 text gt_w_pincheck "pincheck" 35 text gt_s_restate "FAIL pincheck: restates PIN: " 36 text gt_omc "./omc" 37 text gt_t_boot "build/boot" 38 text gt_buildp "build/" 39 text gt_mutsfx ".mut" 40 text gt_defgate "tests/GATE" 41 text gt_null "/dev/null" 42 text gt_outf "build/gate.out" 43 text gt_errf "build/gate.err" 44 text gt_w_note "note" 45 text gt_w_build "build" 46 text gt_w_run "run" 47 text gt_w_mut "mut" 48 text gt_w_ctscan "ctscan" 49 text gt_w_ctmut "ctmut" 50 text gt_w_dash "-" 51 text gt_nl "\n" 52 text gt_sp " " 53 text gt_s_pass "PASS " 54 text gt_s_fail "FAIL " 55 text gt_s_killed "KILLED " 56 text gt_s_surv "SURVIVED " 57 text gt_s_exit " exit=" 58 text gt_s_want " want=" 59 text gt_s_last " last=" 60 text gt_s_ct " words=" 61 text gt_s_cb " condbr=" 62 text gt_s_dv " div=" 63 text gt_s_rm " regmem=" 64 text gt_s_ib " indirect=" 65 text gt_s_bad "FAIL malformed gate line: " 66 text gt_s_io "OMTLS GATE FAIL cannot read " 67 text gt_s_notrun "OMTLS GATE NOT_RUN ./omc is not the compiler PIN names (or PIN is malformed)\n" 68 text gt_s_final "OMTLS GATE " 69 text gt_s_steps " steps=" 70 text gt_s_failed " failed=" 71 text gt_s_mk " mutants-killed=" 72 text gt_s_slash "/" 73 74 note ---- output ---- 75 fn gt_say t view uchar * to void 76 k = write 1 t 0 len t 77 end 78 fn gt_num n ulong to void 79 d = new uchar 24 0 80 i = ulong 24 81 v = n 82 while true bound 30 83 i = sub i 1 84 put d i uchar add 48 rem v 10 85 v = div v 10 86 if eq v 0 87 break 88 end 89 end 90 k = write 1 d i sub 24 i 91 end 92 fn gt_saytok t ulong to void 93 note print token t of the current line (offsets in gt_tok) 94 s = get gt_tok mul t 2 95 e = get gt_tok add mul t 2 1 96 k = write 1 gt_file s sub e s 97 end 98 fn gt_sayline to void 99 k = write 1 gt_file get gt_v 20 sub get gt_v 21 get gt_v 20 100 gt_say gt_nl 101 end 102 103 note ---- read a whole file into gt_buf (length gt_v[1]) from the path in gt_path (length gt_v[6]) ---- 104 fn gt_load to bool 105 fd = fopen gt_path 0 get gt_v 6 0 0 106 if lt fd 0 107 ret false 108 end 109 n = ulong 0 110 ok = true 111 cap = len gt_buf 112 while true bound `9223372036854775807` 113 if ge n cap 114 ok = false 115 break 116 end 117 k = read int fd gt_buf n sub cap n 118 if eq k -4 119 continue 120 end 121 if lt k 0 122 ok = false 123 break 124 end 125 if eq k 0 126 break 127 end 128 n = add n ulong k 129 end 130 z = fclose int fd 131 put gt_v 1 n 132 ret ok 133 end 134 fn gt_pset t view uchar * to void 135 for i ulong len t 136 put gt_path i get t i 137 end 138 put gt_v 6 len t 139 end 140 fn gt_padd t view uchar * to void 141 p = get gt_v 6 142 for i ulong len t 143 put gt_path add p i get t i 144 end 145 put gt_v 6 add p len t 146 end 147 fn gt_paddtok t ulong to void 148 s = get gt_tok mul t 2 149 e = get gt_tok add mul t 2 1 150 p = get gt_v 6 151 for i ulong sub e s 152 put gt_path add p i get gt_file add s i 153 end 154 put gt_v 6 add p sub e s 155 end 156 157 note ---- the compiler pin: sha256 of ./omc with the vendored FIPS 180-4 unit ---- 158 fn gt_pinok to bool 159 fd = fopen gt_omc 0 len gt_omc 0 0 160 if lt fd 0 161 ret false 162 end 163 c = new uchar 104 0 164 b = new uchar 65536 0 165 d = new uchar 32 0 166 sha256_init c 167 while true bound `9223372036854775807` 168 k = read int fd b 0 65536 169 if eq k -4 170 continue 171 end 172 if lt k 0 173 z = fclose int fd 174 ret false 175 end 176 if eq k 0 177 break 178 end 179 sha256_update c part b 0 ulong k 180 end 181 z = fclose int fd 182 sha256_final c d 183 ret gt_pincmp d 184 end 185 fn gt_pincmp d view uchar 32 to bool 186 hx = new uchar 16 0 187 for i ulong 16 188 if lt i 10 189 put hx i uchar add 48 i 190 else 191 put hx i uchar add 87 i 192 end 193 end 194 for i ulong 32 195 v = get d i 196 o = add 64 mul i 2 197 hi = get hx ulong shr v 4 198 lo = get hx ulong and v 15 199 if or ne get gt_pinv o hi ne get gt_pinv add o 1 lo 200 ret false 201 end 202 end 203 ret true 204 end 205 note ---- PIN: exactly "omega-mv " + 40 hex, LF, "omc-sha256 " + 64 hex, LF; into gt_pinv[0..40) and [64..128) ---- 206 fn gt_ishex c uchar to bool 207 ret or and ge c 48 le c 57 and ge c 97 le c 102 208 end 209 fn gt_loadpin to bool 210 gt_pset gt_pinf 211 if not gt_load 212 ret false 213 end 214 if ne get gt_v 1 126 215 ret false 216 end 217 for i ulong 9 218 if ne get gt_buf i get gt_pmv i 219 ret false 220 end 221 end 222 for i ulong 11 223 if ne get gt_buf add 50 i get gt_psha i 224 ret false 225 end 226 end 227 if or ne get gt_buf 49 10 ne get gt_buf 125 10 228 ret false 229 end 230 for i ulong 40 231 c = get gt_buf add 9 i 232 if not gt_ishex c 233 ret false 234 end 235 put gt_pinv i c 236 end 237 for i ulong 64 238 c = get gt_buf add 61 i 239 if not gt_ishex c 240 ret false 241 end 242 put gt_pinv add 64 i c 243 end 244 ret true 245 end 246 note ---- pincheck: the tracked files (git ls-files) must not restate the pin ---- 247 fn gt_step_pincheck to bool 248 gt_pkstart 249 gt_pkt gt_git 250 gt_pkt gt_lsf 251 st = gt_exec 252 if ne st 0 253 ret gt_fail 254 end 255 gt_pset gt_outf 256 if not gt_load 257 ret gt_fail 258 end 259 n = get gt_v 1 260 if gt n len gt_list 261 ret gt_fail 262 end 263 for i ulong n 264 put gt_list i get gt_buf i 265 end 266 bad = ulong 0 267 files = ulong 0 268 p = ulong 0 269 while lt p n bound `9223372036854775807` 270 q = p 271 while lt q n bound `9223372036854775807` 272 if eq get gt_list q 10 273 break 274 end 275 q = add q 1 276 end 277 if gt q p 278 files = add files 1 279 bad = add bad gt_scanpin p q 280 end 281 p = add q 1 282 end 283 put gt_v 52 files 284 if gt bad 0 285 ret gt_fail 286 end 287 ret gt_pass 288 end 289 note one tracked path gt_list[p, q): its findings (PIN itself is the pin's one place and is skipped) 290 fn gt_ispinpath p ulong q ulong to bool 291 if ne sub q p 3 292 ret false 293 end 294 a = and eq get gt_list p 80 eq get gt_list add p 1 73 295 ret and a eq get gt_list add p 2 78 296 end 297 fn gt_scanpin p ulong q ulong to ulong 298 if gt_ispinpath p q 299 ret 0 300 end 301 put gt_v 6 sub q p 302 for i ulong sub q p 303 put gt_path i get gt_list add p i 304 end 305 if not gt_load 306 ret 0 307 end 308 n = get gt_v 1 309 bad = ulong 0 310 i = ulong 0 311 while lt i n bound `9223372036854775807` 312 e = gt_hexrun i n 313 if gt e i 314 if gt_restates i e n 315 bad = add bad 1 316 gt_say gt_s_restate 317 k = write 1 gt_path 0 get gt_v 6 318 gt_say gt_nl 319 end 320 i = e 321 else 322 i = add i 1 323 end 324 end 325 ret bad 326 end 327 fn gt_isword c uchar to bool 328 dg = and ge c 48 le c 57 329 lo = and ge c 97 le c 122 330 up = and ge c 65 le c 90 331 ret or or dg lo or up eq c 95 332 end 333 note the end of the run of lowercase hex digits starting at i (i itself when there is none or i is inside a word) 334 fn gt_hexrun i ulong n ulong to ulong 335 if gt i 0 336 c = get gt_buf sub i 1 337 if gt_isword c 338 ret i 339 end 340 end 341 e = i 342 while lt e n bound `9223372036854775807` 343 if not gt_ishex get gt_buf e 344 break 345 end 346 e = add e 1 347 end 348 ret e 349 end 350 note a whole hex word of at least 7 digits that is a prefix of the PIN revision or of the compiler sha256 351 fn gt_restates s ulong e ulong n ulong to bool 352 l = sub e s 353 if lt l 7 354 ret false 355 end 356 if lt e n 357 c = get gt_buf e 358 if gt_isword c 359 ret false 360 end 361 end 362 ret or gt_prefix s l 0 40 gt_prefix s l 64 64 363 end 364 fn gt_prefix s ulong l ulong o ulong m ulong to bool 365 if gt l m 366 ret false 367 end 368 for i ulong l 369 if ne get gt_buf add s i get gt_pinv add o i 370 ret false 371 end 372 end 373 ret true 374 end 375 376 note ---- tokens of the current line [gt_v20, gt_v21) into gt_tok; count in gt_v[22] ---- 377 fn gt_tokens to void 378 s = get gt_v 20 379 e = get gt_v 21 380 n = ulong 0 381 p = s 382 while lt p e bound `9223372036854775807` 383 while lt p e bound `9223372036854775807` 384 if ne get gt_file p 32 385 break 386 end 387 p = add p 1 388 end 389 if ge p e 390 break 391 end 392 q = p 393 while lt q e bound `9223372036854775807` 394 if eq get gt_file q 32 395 break 396 end 397 q = add q 1 398 end 399 put gt_tok mul n 2 p 400 put gt_tok add mul n 2 1 q 401 n = add n 1 402 p = q 403 end 404 put gt_v 22 n 405 end 406 fn gt_tokis t ulong w view uchar * to bool 407 s = get gt_tok mul t 2 408 e = get gt_tok add mul t 2 1 409 if ne sub e s len w 410 ret false 411 end 412 for i ulong len w 413 if ne get gt_file add s i get w i 414 ret false 415 end 416 end 417 ret true 418 end 419 fn gt_tokint t ulong to ulong 420 s = get gt_tok mul t 2 421 e = get gt_tok add mul t 2 1 422 v = ulong 0 423 for i ulong sub e s 424 c = get gt_file add s i 425 if or lt c 48 gt c 57 426 ret 999999 427 end 428 v = add mul v 10 ulong sub c 48 429 if gt v 999999 430 ret 999999 431 end 432 end 433 ret v 434 end 435 436 note ---- packet building in gt_pk (length gt_v[14], count gt_v[15]) ---- 437 fn gt_pkstart to void 438 put gt_v 14 2 439 put gt_v 15 0 440 end 441 fn gt_pkdone to void 442 n = get gt_v 15 443 put gt_pk 0 uchar and n 255 444 put gt_pk 1 uchar shr n 8 445 end 446 fn gt_pkhead to ulong 447 p = get gt_v 14 448 put gt_v 15 add get gt_v 15 1 449 ret p 450 end 451 fn gt_pkset p ulong n ulong to void 452 put gt_pk p uchar and n 255 453 put gt_pk add p 1 uchar shr n 8 454 put gt_v 14 add add p 2 n 455 end 456 fn gt_pkt t view uchar * to void 457 p = gt_pkhead 458 for i ulong len t 459 put gt_pk add add p 2 i get t i 460 end 461 gt_pkset p len t 462 end 463 fn gt_pktok t ulong to void 464 s = get gt_tok mul t 2 465 e = get gt_tok add mul t 2 1 466 p = gt_pkhead 467 for i ulong sub e s 468 put gt_pk add add p 2 i get gt_file add s i 469 end 470 gt_pkset p sub e s 471 end 472 fn gt_pkpath to void 473 p = gt_pkhead 474 for i ulong get gt_v 6 475 put gt_pk add add p 2 i get gt_path i 476 end 477 gt_pkset p get gt_v 6 478 end 479 fn gt_pkbin t ulong mut bool to void 480 note "build/UNIT" (or "build/UNIT.mut") from token t 481 gt_pset gt_buildp 482 gt_paddtok t 483 if mut 484 gt_padd gt_mutsfx 485 end 486 gt_pkpath 487 end 488 489 fn gt_le4 b view uchar 4 to ulong 490 lo = or ulong get b 0 shl ulong get b 1 8 491 hi = or shl ulong get b 2 16 shl ulong get b 3 24 492 ret or lo hi 493 end 494 fn gt_word o ulong to ulong 495 lo = or ulong get gt_buf o shl ulong get gt_buf add o 1 8 496 hi = or shl ulong get gt_buf add o 2 16 shl ulong get gt_buf add o 3 24 497 ret or lo hi 498 end 499 note ---- run the packet with stdin /dev/null, stdout build/gate.out, stderr build/gate.err; exit status, 500 note 1000+signal, 2000 timeout, 3000 I/O ---- 501 fn gt_exec to ulong 502 gt_pkdone 503 fi = fopen gt_null 0 len gt_null 0 0 504 fo = fopen gt_outf 0 len gt_outf 577 420 505 fe = fopen gt_errf 0 len gt_errf 577 420 506 if or or lt fi 0 lt fo 0 lt fe 0 507 ret 3000 508 end 509 pid = fork 510 if lt pid 0 511 ret 3000 512 end 513 if eq pid 0 514 if lt dupfd int fi 0 0 0 515 exit 126 516 end 517 if lt dupfd int fo 1 0 0 518 exit 126 519 end 520 if lt dupfd int fe 2 0 0 521 exit 126 522 end 523 r = execprog gt_pk 0 get gt_v 14 524 exit 127 525 end 526 z = fclose int fi 527 z = fclose int fo 528 z = fclose int fe 529 b = new uchar 4 0 530 t0 = monons 531 while true bound `9223372036854775807` 532 w = waitpid int pid b 0 4 1 533 if eq w pid 534 st = gt_le4 b 535 if eq and st 127 0 536 ret and shr st 8 255 537 end 538 ret add 1000 and st 127 539 end 540 if lt w 0 541 if ne w -4 542 ret 3000 543 end 544 end 545 if gt sub monons t0 GT_LIMIT 546 r = killpid int pid 9 547 w = waitpid int pid b 0 4 0 548 ret 2000 549 end 550 r = sleepns `2000000` 551 end 552 ret 3000 553 end 554 555 note ---- last nonempty line of build/gate.out into gt_buf[gt_v30, gt_v31) ---- 556 fn gt_lastline to void 557 gt_pset gt_outf 558 put gt_v 30 0 559 put gt_v 31 0 560 if not gt_load 561 ret 562 end 563 e = get gt_v 1 564 while gt e 0 bound `9223372036854775807` 565 if ne get gt_buf sub e 1 10 566 break 567 end 568 e = sub e 1 569 end 570 s = e 571 while gt s 0 bound `9223372036854775807` 572 if eq get gt_buf sub s 1 10 573 break 574 end 575 s = sub s 1 576 end 577 put gt_v 30 s 578 put gt_v 31 e 579 end 580 fn gt_lastprefix t ulong to bool 581 s = get gt_tok mul t 2 582 e = get gt_tok add mul t 2 1 583 ls = get gt_v 30 584 lz = get gt_v 31 585 if gt sub e s sub lz ls 586 ret false 587 end 588 for i ulong sub e s 589 if ne get gt_file add s i get gt_buf add ls i 590 ret false 591 end 592 end 593 ret true 594 end 595 fn gt_saylast to void 596 k = write 1 gt_buf get gt_v 30 sub get gt_v 31 get gt_v 30 597 end 598 fn gt_sayerr to void 599 gt_pset gt_errf 600 if gt_load 601 k = write 1 gt_buf 0 get gt_v 1 602 end 603 end 604 605 note ---- build/boot UNIT [MUTFILE NAME] ---- 606 fn gt_boot unit ulong mutfile ulong name ulong mut bool to ulong 607 gt_pkstart 608 gt_pkt gt_t_boot 609 gt_pktok unit 610 if mut 611 gt_pktok mutfile 612 gt_pktok name 613 end 614 ret gt_exec 615 end 616 617 note ---- scan build/UNIT (or .mut) for the forbidden instruction classes; counts in gt_v[40..44] ---- 618 fn gt_scan unit ulong mut bool to bool 619 gt_pset gt_buildp 620 gt_paddtok unit 621 if mut 622 gt_padd gt_mutsfx 623 end 624 for i ulong 5 625 put gt_v add 40 i 0 626 end 627 if not gt_load 628 ret false 629 end 630 n = div get gt_v 1 4 631 for i ulong n 632 c = gt_class gt_word mul i 4 633 if gt c 0 634 put gt_v add 40 c add get gt_v add 40 c 1 635 end 636 end 637 put gt_v 40 n 638 ret true 639 end 640 note class of one AArch64 word: 1 conditional branch, 2 divide, 3 register-offset load/store, 4 BR/BLR, 0 other 641 fn gt_class w ulong to ulong 642 if eq and w `4278190096` `1409286144` 643 ret 1 644 end 645 if eq and w `2113929216` `872415232` 646 ret 1 647 end 648 if eq and w `2113929216` `905969664` 649 ret 1 650 end 651 if eq and w `2145449984` `448792576` 652 ret 2 653 end 654 if eq and w `991955968` `941623296` 655 ret 3 656 end 657 if eq and w `4294966303` `3592355840` 658 ret 4 659 end 660 if eq and w `4294966303` `3594452992` 661 ret 4 662 end 663 ret 0 664 end 665 fn gt_scanclean to bool 666 ret and and eq get gt_v 41 0 eq get gt_v 42 0 and eq get gt_v 43 0 eq get gt_v 44 0 667 end 668 fn gt_sayscan to void 669 gt_say gt_s_ct 670 gt_num get gt_v 40 671 gt_say gt_s_cb 672 gt_num get gt_v 41 673 gt_say gt_s_dv 674 gt_num get gt_v 42 675 gt_say gt_s_rm 676 gt_num get gt_v 43 677 gt_say gt_s_ib 678 gt_num get gt_v 44 679 end 680 681 note ---- one step; true when it passed ---- 682 fn gt_pass to bool 683 gt_say gt_s_pass 684 gt_sayline 685 ret true 686 end 687 fn gt_fail to bool 688 gt_say gt_s_fail 689 gt_sayline 690 ret false 691 end 692 fn gt_step_build to bool 693 st = gt_boot 1 0 0 false 694 if ne st 0 695 gt_sayerr 696 ret gt_fail 697 end 698 ret gt_pass 699 end 700 fn gt_step_run to bool 701 nt = get gt_v 22 702 if lt nt 4 703 ret false 704 end 705 want = gt_tokint 2 706 gt_pkstart 707 gt_pkbin 1 false 708 for t ulong sub nt 4 709 gt_pktok add 4 t 710 end 711 st = gt_exec 712 gt_lastline 713 ok = eq st want 714 if not gt_tokis 3 gt_w_dash 715 if not gt_lastprefix 3 716 ok = false 717 end 718 end 719 if ok 720 ret gt_pass 721 end 722 gt_say gt_s_fail 723 gt_sayline 724 gt_say gt_s_exit 725 gt_num st 726 gt_say gt_s_want 727 gt_num want 728 gt_say gt_s_last 729 gt_saylast 730 gt_say gt_nl 731 gt_sayerr 732 ret false 733 end 734 fn gt_step_mut to bool 735 nt = get gt_v 22 736 if lt nt 4 737 ret false 738 end 739 put gt_v 51 add get gt_v 51 1 740 st = gt_boot 2 3 1 true 741 if ne st 0 742 gt_say gt_s_fail 743 gt_sayline 744 gt_sayerr 745 ret false 746 end 747 gt_pkstart 748 gt_pkbin 2 true 749 for t ulong sub nt 4 750 gt_pktok add 4 t 751 end 752 st = gt_exec 753 if eq st 0 754 gt_say gt_s_surv 755 gt_sayline 756 ret false 757 end 758 put gt_v 50 add get gt_v 50 1 759 gt_say gt_s_killed 760 gt_saytok 1 761 gt_say gt_s_exit 762 gt_num st 763 gt_say gt_nl 764 ret true 765 end 766 fn gt_step_ctscan to bool 767 st = gt_boot 1 0 0 false 768 if ne st 0 769 gt_sayerr 770 ret gt_fail 771 end 772 if not gt_scan 1 false 773 ret gt_fail 774 end 775 ok = gt_scanclean 776 if ok 777 gt_say gt_s_pass 778 else 779 gt_say gt_s_fail 780 end 781 k = write 1 gt_file get gt_v 20 sub get gt_v 21 get gt_v 20 782 gt_sayscan 783 gt_say gt_nl 784 ret ok 785 end 786 fn gt_step_ctmut to bool 787 put gt_v 51 add get gt_v 51 1 788 st = gt_boot 2 3 1 true 789 if ne st 0 790 gt_say gt_s_fail 791 gt_sayline 792 gt_sayerr 793 ret false 794 end 795 if not gt_scan 2 true 796 ret gt_fail 797 end 798 if gt_scanclean 799 gt_say gt_s_surv 800 gt_sayline 801 ret false 802 end 803 put gt_v 50 add get gt_v 50 1 804 gt_say gt_s_killed 805 gt_saytok 1 806 gt_sayscan 807 gt_say gt_nl 808 ret true 809 end 810 fn gt_step to bool 811 nt = get gt_v 22 812 if and gt_tokis 0 gt_w_build eq nt 2 813 ret gt_step_build 814 end 815 if gt_tokis 0 gt_w_run 816 ret gt_step_run 817 end 818 if gt_tokis 0 gt_w_mut 819 ret gt_step_mut 820 end 821 if and gt_tokis 0 gt_w_ctscan eq nt 2 822 ret gt_step_ctscan 823 end 824 if and gt_tokis 0 gt_w_ctmut eq nt 4 825 ret gt_step_ctmut 826 end 827 if and gt_tokis 0 gt_w_pincheck eq nt 1 828 ret gt_step_pincheck 829 end 830 gt_say gt_s_bad 831 gt_sayline 832 ret false 833 end 834 835 fn main to int 836 if not and gt_loadpin gt_pinok 837 gt_say gt_s_notrun 838 ret 2 839 end 840 if gt argcnt 1 841 k = argread 1 gt_path 0 8192 842 if le k 0 843 ret 2 844 end 845 put gt_v 6 ulong k 846 else 847 gt_pset gt_defgate 848 end 849 if not gt_load 850 gt_say gt_s_io 851 k = write 1 gt_path 0 get gt_v 6 852 gt_say gt_nl 853 ret 1 854 end 855 n = get gt_v 1 856 for i ulong n 857 put gt_file i get gt_buf i 858 end 859 steps = ulong 0 860 failed = ulong 0 861 p = ulong 0 862 while lt p n bound `9223372036854775807` 863 q = p 864 while lt q n bound `9223372036854775807` 865 if eq get gt_file q 10 866 break 867 end 868 q = add q 1 869 end 870 put gt_v 20 p 871 put gt_v 21 q 872 gt_tokens 873 if gt get gt_v 22 0 874 if not gt_tokis 0 gt_w_note 875 steps = add steps 1 876 if not gt_step 877 failed = add failed 1 878 end 879 end 880 end 881 p = add q 1 882 end 883 gt_say gt_s_final 884 if eq failed 0 885 gt_say gt_s_pass 886 else 887 gt_say gt_s_fail 888 end 889 gt_say gt_s_steps 890 gt_num steps 891 gt_say gt_s_failed 892 gt_num failed 893 gt_say gt_s_mk 894 gt_num get gt_v 50 895 gt_say gt_s_slash 896 gt_num get gt_v 51 897 gt_say gt_nl 898 if eq failed 0 899 ret 0 900 end 901 ret 1 902 end