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/om/tls/test/rev/driver.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 / om / tls / test / rev / driver.om` 580 lines ยท 12274 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note driver.om: program-mode test driver for om/tls/rev.om (composed after sha2 hkdf ec rsa x509 rev). 3 note Reads case records from stdin, one per line, tokens separated by single spaces; paths are 4 note relative to the working directory (run.sh runs it in vectors/). Records: 5 note O NAME EXPECT NOW LEAF ISSUER STAPLE CRL rev_check (STAPLE, CRL a DER file or - for none) 6 note U NAME EXPECT CERT rev_mustst (EXPECT 0, 1 or a code name) 7 note I NAME WANT STORE CERT... rev_issuer of the certificate_list CERT... with the 8 note PEM store STORE; WANT the DER file it must return, 9 note or - for none 10 note H NAME HEX DIGEST sha1_digest of HEX (- empty) equals DIGEST (hex) 11 note A NAME COUNT BYTE DIGEST sha1_digest of COUNT bytes of value BYTE 12 note E NAME EXPECT CODE rev_errname(CODE) equals EXPECT (- for empty) 13 note F NAME COUNT NOW LEAF ISSUER STAPLE the unmutated staple is accepted and each of COUNT 14 note deterministic mutations of it is refused 15 note G NAME COUNT NOW LEAF ISSUER CRL the same for a CRL: the unmutated result is kept 16 note (revoked) and no mutation returns X509_OK 17 note Prints "MISMATCH line L NAME got G want W" per failure, "fuzz NAME n=N rejected=R" per F/G 18 note record, then "rev driver: C checks, F failed". Exit 0 when F is 0 and C > 0, 1 otherwise, 2 when 19 note input cannot be read. 20 21 global inp uchar `1048576` 22 global ds ulong 16 23 note main owns bb (file bytes, uchar 262144) and pp (the rev_check descriptor, ulong 16): a global 24 note is never passed as an argument (omc error 19) 25 global ob uchar 32 26 global nm uchar 64 27 global onebyte uchar 1 28 text DRSUM "rev driver: " 29 text DRCHK " checks, " 30 text DRFLD " failed\n" 31 text DRMIS "MISMATCH line " 32 text DRGOT " got " 33 text DRWANT " want " 34 text DRFUZ "fuzz " 35 text DRFN " n=" 36 text DRFR " rejected=" 37 text DRNL "\n" 38 text DRSP " " 39 text DRBAD "BAD" 40 text DRERR "ERR" 41 text DRDASH "-" 42 text DRYES "1" 43 text DRNO "0" 44 text DRIO "rev driver: cannot read input\n" 45 46 note ds: 0 input length, 1 cursor, 2 line number, 3 checks, 4 failures, 6 name length, 8 bb fill, 47 note 10 fuzz region (5 staple, 7 CRL) 48 49 fn drv_slurp to int 50 t = ulong 0 51 while true bound 999999 52 room = sub len inp t 53 if eq room 0 54 ret 2 55 end 56 r = read 0 inp t room 57 if lt r 0 58 ret 2 59 end 60 if eq r 0 61 break 62 end 63 t = add t ulong r 64 end 65 put ds 0 t 66 ret 0 67 end 68 69 fn drv_peek to ulong 70 c = get ds 1 71 if ge c get ds 0 72 ret 256 73 end 74 ret ulong get inp c 75 end 76 77 note next token into tk (skipping one space before it); its length (0 at the line end) 78 fn drv_tok tk edit uchar * to ulong 79 if eq drv_peek 32 80 put ds 1 add get ds 1 1 81 end 82 n = ulong 0 83 while true bound 999999 84 c = drv_peek 85 if or or eq c 32 eq c 10 eq c 256 86 break 87 end 88 if lt n len tk 89 put tk n uchar c 90 end 91 n = add n 1 92 put ds 1 add get ds 1 1 93 end 94 if gt n len tk 95 ret 0 96 end 97 ret n 98 end 99 100 fn drv_eol to void 101 while true bound 999999 102 c = drv_peek 103 if eq c 256 104 ret 105 end 106 put ds 1 add get ds 1 1 107 if eq c 10 108 ret 109 end 110 end 111 end 112 113 fn drv_num t view uchar * to ulong 114 v = ulong 0 115 for i ulong len t 116 v = add mul v 10 sub ulong get t i 48 117 end 118 ret v 119 end 120 121 fn drv_prn v ulong to void 122 x = v 123 k = ulong 0 124 while true bound 21 125 put ob sub 31 k uchar add 48 rem x 10 126 k = add k 1 127 x = div x 10 128 if eq x 0 129 break 130 end 131 end 132 r = write 1 ob sub 32 k k 133 end 134 135 note record a mismatch: got / want as text 136 fn drv_mis g view uchar * w view uchar * to void 137 put ds 4 add get ds 4 1 138 r = write 1 DRMIS 0 len DRMIS 139 drv_prn get ds 2 140 r = write 1 DRSP 0 1 141 r = write 1 nm 0 get ds 6 142 r = write 1 DRGOT 0 len DRGOT 143 r = write 1 g 0 len g 144 r = write 1 DRWANT 0 len DRWANT 145 r = write 1 w 0 len w 146 r = write 1 DRNL 0 1 147 end 148 149 note compare code c against the expected name w 150 fn drv_code c ulong w view uchar * to void 151 b = new uchar 64 0 152 put ds 3 add get ds 3 1 153 n = rev_errname c b 154 if eq n 0 155 drv_mis DRBAD w 156 ret 157 end 158 if not der_same part b 0 n w 159 drv_mis part b 0 n w 160 end 161 end 162 163 fn drv_name to void 164 t = new uchar 64 0 165 n = drv_tok t 166 for i ulong n 167 put nm i get t i 168 end 169 put ds 6 n 170 end 171 172 note read the file named p into b; bytes read, or -1 (missing, error, or over len b) 173 fn drv_file p view uchar * b edit uchar * to long 174 fd = fopen p 0 len p 0 0 175 if lt fd 0 176 ret -1 177 end 178 n = ulong 0 179 while lt n len b bound 999999 180 r = read int fd b n sub len b n 181 if le r 0 182 break 183 end 184 n = add n ulong r 185 end 186 r = read int fd onebyte 0 1 187 z = fclose int fd 188 if or ne r 0 eq n len b 189 ret -1 190 end 191 ret long n 192 end 193 194 note the next token, a DER file or -, appended to bb as descriptor slot pp[i], pp[i+1]; 0 ok, 1 failure 195 fn drv_add tk edit uchar 4096 bb edit uchar 262144 pp edit ulong 16 i ulong to ulong 196 n = drv_tok tk 197 put pp i 0 198 put pp add i 1 0 199 if and eq n 1 eq get tk 0 45 200 ret 0 201 end 202 f = get ds 8 203 r = drv_file part tk 0 n part bb f sub len bb f 204 if lt r 1 205 ret 1 206 end 207 put pp i f 208 put pp add i 1 ulong r 209 put ds 8 add f ulong r 210 ret 0 211 end 212 213 note NOW LEAF ISSUER, then the slots 5 and 7 in the order given by k (5: staple only, 7: CRL only, 214 note 0: both); 0 ok, 1 a file failed 215 fn drv_load tk edit uchar 4096 bb edit uchar 262144 pp edit ulong 16 k ulong to ulong 216 put ds 8 0 217 for i ulong 16 218 put pp i 0 219 end 220 n = drv_tok tk 221 put pp 0 drv_num part tk 0 n 222 if ne drv_add tk bb pp 1 0 223 ret 1 224 end 225 if ne drv_add tk bb pp 3 0 226 ret 1 227 end 228 if ne k 7 229 if ne drv_add tk bb pp 5 0 230 ret 1 231 end 232 end 233 if ne k 5 234 if ne drv_add tk bb pp 7 0 235 ret 1 236 end 237 end 238 ret 0 239 end 240 241 note O record 242 fn drv_o tk edit uchar 4096 bb edit uchar 262144 pp edit ulong 16 to void 243 drv_name 244 w = new uchar 64 0 245 wn = drv_tok w 246 if ne drv_load tk bb pp 0 0 247 drv_code 98 part w 0 wn 248 ret 249 end 250 c = rev_check part bb 0 get ds 8 pp 251 drv_code c part w 0 wn 252 end 253 254 note one DER file token into slot 1 (bb restarted); 0 ok 255 fn drv_load2 tk edit uchar 4096 bb edit uchar 262144 pp edit ulong 16 to ulong 256 put ds 8 0 257 ret drv_add tk bb pp 1 258 end 259 260 note U record: EXPECT 1 means rev_mustst returns RVHIT, 0 means 0, a name means that code 261 fn drv_u tk edit uchar 4096 bb edit uchar 262144 pp edit ulong 16 to void 262 drv_name 263 w = new uchar 64 0 264 wn = drv_tok w 265 if ne drv_load2 tk bb pp 0 266 drv_code 98 part w 0 wn 267 ret 268 end 269 c = rev_mustst part bb get pp 1 get pp 2 270 if and gt wn 1 ne get w 0 48 271 drv_code c part w 0 wn 272 ret 273 end 274 put ds 3 add get ds 3 1 275 e = ulong 0 276 if eq get w 0 49 277 e = RVHIT 278 end 279 if ne c e 280 if eq c RVHIT 281 drv_mis DRYES part w 0 wn 282 else 283 drv_mis DRNO part w 0 wn 284 end 285 end 286 end 287 288 note the certificate_list of the remaining file tokens, built at bb[ds[8] ..); its length, 0 on failure 289 fn drv_cl tk edit uchar 4096 bb edit uchar 262144 to ulong 290 b0 = get ds 8 291 p = b0 292 while true bound 64 293 n = drv_tok tk 294 if eq n 0 295 break 296 end 297 q = drv_file part tk 0 n part bb add p 3 sub sub len bb p 5 298 if lt q 1 299 ret 0 300 end 301 l = ulong q 302 put bb p uchar shr l 16 303 put bb add p 1 uchar and shr l 8 255 304 put bb add p 2 uchar and l 255 305 put bb add add p 3 l 0 306 put bb add add p 4 l 0 307 p = add add p 5 l 308 end 309 ret sub p b0 310 end 311 312 note I record result: rev_issuer of the list bb[pp[10] .. +m) with the store st[0 .. pp[9]) against 313 note the expected DER at bb slot 1 (none when slot 1 is empty) 314 fn drv_icmp st view uchar 262144 bb view uchar 262144 pp view ulong 16 m ulong to void 315 kb = new uchar 16896 0 316 k = rev_issuer part bb get pp 10 m part st 0 get pp 9 kb 317 if eq get pp 2 0 318 if ne k 0 319 drv_mis DRBAD DRDASH 320 end 321 ret 322 end 323 if eq k 0 324 drv_mis DRDASH DRBAD 325 ret 326 end 327 if not der_same part kb 0 k part bb get pp 1 get pp 2 328 drv_mis DRERR DRBAD 329 end 330 end 331 332 note I record: the store, then the certificate_list (uint24 length || DER || 2-byte empty 333 note extensions) of the remaining files, built in bb after the expected DER (slot 1) 334 fn drv_i tk edit uchar 4096 bb edit uchar 262144 pp edit ulong 16 to void 335 st = new uchar 262144 0 336 drv_name 337 put ds 3 add get ds 3 1 338 if ne drv_load2 tk bb pp 0 339 drv_mis DRERR DRBAD 340 ret 341 end 342 n = drv_tok tk 343 r = x509_store_loadf st part tk 0 n 344 if le r 0 345 drv_mis DRERR DRBAD 346 ret 347 end 348 put pp 9 ulong r 349 put pp 10 get ds 8 350 m = drv_cl tk bb 351 if eq m 0 352 drv_mis DRERR DRBAD 353 ret 354 end 355 drv_icmp st bb pp m 356 end 357 358 note hex digit value, 99 for a non-hex byte 359 fn drv_hx c ulong to ulong 360 if and ge c 48 le c 57 361 ret sub c 48 362 end 363 if and ge c 97 le c 102 364 ret sub c 87 365 end 366 ret 99 367 end 368 369 note hex t (- for empty) into b; byte count 370 fn drv_unhex t view uchar * b edit uchar * to ulong 371 if and eq len t 1 eq get t 0 45 372 ret 0 373 end 374 n = div len t 2 375 for i ulong n 376 hi = drv_hx ulong get t mul i 2 377 lo = drv_hx ulong get t add mul i 2 1 378 put b i uchar add mul hi 16 lo 379 end 380 ret n 381 end 382 383 note digest d[0 .. 20) against the hex token t 384 fn drv_dig d view uchar 32 t view uchar * to void 385 e = new uchar 32 0 386 put ds 3 add get ds 3 1 387 n = drv_unhex t e 388 if ne n 20 389 drv_mis DRERR DRBAD 390 ret 391 end 392 for i ulong 20 393 if ne get d i get e i 394 drv_mis DRERR DRBAD 395 ret 396 end 397 end 398 end 399 400 note H record 401 fn drv_h tk edit uchar 4096 to void 402 m = new uchar 4096 0 403 d = new uchar 32 0 404 drv_name 405 n = drv_unhex part tk 0 drv_tok tk m 406 k = sha1_digest part m 0 n d 407 drv_dig d part tk 0 drv_tok tk 408 end 409 410 note A record (message built in its own 1 MiB buffer) 411 fn drv_a tk edit uchar 4096 to void 412 bb = new uchar `1048576` 0 413 d = new uchar 32 0 414 drv_name 415 n = drv_num part tk 0 drv_tok tk 416 v = drv_num part tk 0 drv_tok tk 417 if gt n len bb 418 put ds 3 add get ds 3 1 419 drv_mis DRERR DRBAD 420 ret 421 end 422 for i ulong n 423 put bb i uchar v 424 end 425 k = sha1_digest part bb 0 n d 426 drv_dig d part tk 0 drv_tok tk 427 end 428 429 note E record 430 fn drv_e tk edit uchar 4096 to void 431 b = new uchar 64 0 432 drv_name 433 w = new uchar 64 0 434 wn = drv_tok w 435 c = drv_num part tk 0 drv_tok tk 436 put ds 3 add get ds 3 1 437 n = rev_errname c b 438 if and eq wn 1 eq get w 0 45 439 if ne n 0 440 drv_mis part b 0 n DRDASH 441 end 442 ret 443 end 444 if not der_same part b 0 n part w 0 wn 445 drv_mis part b 0 n part w 0 wn 446 end 447 end 448 449 note mb[q] xor a nonzero value taken from x shifted right by s 450 fn drv_flip mb edit uchar 262144 q ulong x ulong s ulong to void 451 y = add 1 rem shr x s 255 452 v = uchar y 453 put mb q xor get mb q v 454 end 455 456 note mutation k of the region pp[r] .. +pp[r+1] of bb into mb (the whole buffer copied): k mod 3 = 0 457 note one byte changed (xor a nonzero value), 1 one byte xor 0x80 in the first 64 bytes of the region 458 note (headers), 2 two bytes changed 459 fn drv_mut mb edit uchar 262144 bb view uchar 262144 pp view ulong 16 k ulong to void 460 for i ulong get ds 8 461 put mb i get bb i 462 end 463 a = get pp get ds 10 464 l = get pp add get ds 10 1 465 x = add mul k `2654435761` 12345 466 x = xor x shr x 13 467 m = rem k 3 468 if eq m 1 469 q = add a rem rem x l 64 470 put mb q xor get mb q 128 471 ret 472 end 473 q = add a rem x l 474 drv_flip mb q x 17 475 if eq m 2 476 q = add a rem mul add sub q a 1 7 l 477 drv_flip mb q x 29 478 end 479 end 480 481 note cnt mutations (drv_mut) through rev_check; how many were refused 482 fn drv_fz bb view uchar 262144 pp view ulong 16 cnt ulong to ulong 483 mb = new uchar 262144 0 484 n = get ds 8 485 rj = ulong 0 486 for j ulong cnt 487 drv_mut mb bb pp j 488 if ne rev_check part mb 0 n pp 0 489 rj = add rj 1 490 end 491 end 492 ret rj 493 end 494 495 note F and G records: r = 5 (staple) or 7 (CRL). The unmutated input must give the record's 496 note expectation (F: accepted, G: refused); every mutation must be refused (code not 0) 497 fn drv_f tk edit uchar 4096 bb edit uchar 262144 pp edit ulong 16 r ulong to void 498 drv_name 499 cnt = drv_num part tk 0 drv_tok tk 500 put ds 3 add get ds 3 1 501 if ne drv_load tk bb pp r 0 502 drv_mis DRERR DRBAD 503 ret 504 end 505 c0 = rev_check part bb 0 get ds 8 pp 506 if and eq r 5 ne c0 0 507 drv_mis DRBAD DRNO 508 ret 509 end 510 if and eq r 7 eq c0 0 511 drv_mis DRNO DRBAD 512 ret 513 end 514 put ds 10 r 515 rj = drv_fz bb pp cnt 516 r2 = write 1 DRFUZ 0 len DRFUZ 517 r2 = write 1 nm 0 get ds 6 518 r2 = write 1 DRFN 0 len DRFN 519 drv_prn cnt 520 r2 = write 1 DRFR 0 len DRFR 521 drv_prn rj 522 r2 = write 1 DRNL 0 1 523 if ne rj cnt 524 drv_mis DRERR DRBAD 525 end 526 end 527 528 fn main to int 529 tk = new uchar 4096 0 530 bb = new uchar 262144 0 531 pp = new ulong 16 0 532 if ne drv_slurp 0 533 r = write 2 DRIO 0 len DRIO 534 ret 2 535 end 536 while lt get ds 1 get ds 0 bound 999999 537 put ds 2 add get ds 2 1 538 c = drv_peek 539 put ds 1 add get ds 1 1 540 if eq c 79 541 drv_o tk bb pp 542 end 543 if eq c 85 544 drv_u tk bb pp 545 end 546 if eq c 73 547 drv_i tk bb pp 548 end 549 if eq c 72 550 drv_h tk 551 end 552 if eq c 65 553 drv_a tk 554 end 555 if eq c 69 556 drv_e tk 557 end 558 if eq c 70 559 drv_f tk bb pp 5 560 end 561 if eq c 71 562 drv_f tk bb pp 7 563 end 564 if ne c 10 565 drv_eol 566 end 567 end 568 r = write 1 DRSUM 0 len DRSUM 569 drv_prn get ds 3 570 r = write 1 DRCHK 0 len DRCHK 571 drv_prn get ds 4 572 r = write 1 DRFLD 0 len DRFLD 573 if ne get ds 4 0 574 ret 1 575 end 576 if eq get ds 3 0 577 ret 1 578 end 579 ret 0 580 end