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/aienux/crates/aienos-artifact/artifact_test.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 / aienux / crates / aienos-artifact / artifact_test.om` 1270 lines ยท 26293 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note aienux/crates/aienos-artifact/artifact_test.om: Comprehensive behavioral self-test 3 note for aienos-artifact (tests.rs + receipt_tests.rs). 4 note Compose with: si/directives/om2.om om/tls/sha2.om protocol/omnet/om/sha512/sha512.om protocol/omnet/om/`ed25519`/`ed25519`.om aienux/crates/aienos-artifact/artifact.om aienux/crates/aienos-artifact/receipt.om aienux/crates/aienos-artifact/artifact_test.om 5 6 const FIX_RES_OFF ulong 240 7 const FIX_PAY_OFF ulong 288 8 const FIX_SIG_OFF ulong 296 9 const FIX_TOTAL ulong 396 10 11 text t_hex_digits "`0123456789abcdef`" 12 text t_data_bytes "DATA" 13 text t_gold_req "`adf96aa3e792b1d4a48fe925532efe34ff2a82fe7c07ce013d6daa8bfecb28db`" 14 text t_gold_res "`02f22c42bc7fff8143e11d282f2cfc7773fc483356a5ad9861c937cc6484a3e5`" 15 text t_gold_pay "`f9f5b6ad6a7b931afdce57c59c806df4971c31d72ef560cd7a140d34aba19758`" 16 text t_gold_aid "`71976b5c38ec15f2307565ed3eea51fde4a5375970cd49338d6e16166238cf4b`" 17 text t_gold_rcp_adm "`16bcbe523a62d9f4c907729fb2fb09d630ce36f80d7169e202730173a59bdfdc`" 18 text t_gold_rcp_rej "`f12ebace5ec0f2a8f06c415d58d936389dcc2fed64dbed4bc91efd01a734a6a3`" 19 text t_commit_ok "`71cb1703484cbc9d56eabe43402a6f9bf62b1028`" 20 text t_commit_up "71CB1703484CBC9D56EABE43402A6F9BF62B1028" 21 text t_commit_bad "71cb1703484cbc9d56eabe43402a6f9bf62b102g" 22 text t_lbl_pi5 "SEED-0B-PI5" 23 text t_gold_rec_hdr "`4149454e52435000000060000002000000000000010001000100000000000000e28b2fcc80dd4e973fbc3d13dc62801b000000000000000000000000000000000100000000000000ff000000000000000800000002000000050000000a000000`" 24 25 fn t_hex_eq raw view uchar * hex_str view uchar * to bool 26 n = len raw 27 if ne mul n 2 len hex_str 28 ret false 29 end 30 for i ulong n bound 512 31 b = ulong get raw i 32 hi = get t_hex_digits shr b 4 33 lo = get t_hex_digits and b 15 34 if ne hi get hex_str mul i 2 35 ret false 36 end 37 if ne lo get hex_str add mul i 2 1 38 ret false 39 end 40 end 41 ret true 42 end 43 44 fn t_pattern seed uchar dst edit uchar * to void 45 for i ulong 32 46 put dst i uchar and add ulong seed i 0xff 47 end 48 end 49 50 fn t_seed1 dst edit uchar * to void 51 put dst 0 0x9d 52 put dst 1 0x61 53 put dst 2 0xb1 54 put dst 3 0x9d 55 put dst 4 0xef 56 put dst 5 0xfd 57 put dst 6 0x5a 58 put dst 7 0x60 59 put dst 8 0xba 60 put dst 9 0x84 61 put dst 10 0x4a 62 put dst 11 0xf4 63 put dst 12 0x92 64 put dst 13 0xec 65 put dst 14 0x2c 66 put dst 15 0xc4 67 put dst 16 0x44 68 put dst 17 0x49 69 put dst 18 0xc5 70 put dst 19 0x69 71 put dst 20 0x7b 72 put dst 21 0x32 73 put dst 22 0x69 74 put dst 23 0x19 75 put dst 24 0x70 76 put dst 25 0x3b 77 put dst 26 0xac 78 put dst 27 0x03 79 put dst 28 0x1c 80 put dst 29 0xae 81 put dst 30 0x7f 82 put dst 31 0x60 83 end 84 85 fn t_seed2 dst edit uchar * to void 86 put dst 0 0x4c 87 put dst 1 0xcd 88 put dst 2 0x08 89 put dst 3 0x9b 90 put dst 4 0x28 91 put dst 5 0xff 92 put dst 6 0x96 93 put dst 7 0xda 94 put dst 8 0x9d 95 put dst 9 0xb6 96 put dst 10 0xc3 97 put dst 11 0x46 98 put dst 12 0xec 99 put dst 13 0x11 100 put dst 14 0x4e 101 put dst 15 0x0f 102 put dst 16 0x5b 103 put dst 17 0x8a 104 put dst 18 0x31 105 put dst 19 0x9f 106 put dst 20 0x35 107 put dst 21 0xab 108 put dst 22 0xa6 109 put dst 23 0x24 110 put dst 24 0xda 111 put dst 25 0x8c 112 put dst 26 0xf6 113 put dst 27 0xed 114 put dst 28 0x4f 115 put dst 29 0xb8 116 put dst 30 0xa6 117 put dst 31 0xfb 118 end 119 120 fn t_seed3 dst edit uchar * to void 121 put dst 0 0xc5 122 put dst 1 0xaa 123 put dst 2 0x8d 124 put dst 3 0xf4 125 put dst 4 0x3f 126 put dst 5 0x9f 127 put dst 6 0x83 128 put dst 7 0x7b 129 put dst 8 0xed 130 put dst 9 0xb7 131 put dst 10 0x44 132 put dst 11 0x2f 133 put dst 12 0x31 134 put dst 13 0xdc 135 put dst 14 0xb7 136 put dst 15 0xb1 137 put dst 16 0x66 138 put dst 17 0xd3 139 put dst 18 0x85 140 put dst 19 0x35 141 put dst 20 0x07 142 put dst 21 0x6f 143 put dst 22 0x09 144 put dst 23 0x4b 145 put dst 24 0x85 146 put dst 25 0xce 147 put dst 26 0x3a 148 put dst 27 0x2e 149 put dst 28 0x0b 150 put dst 29 0x44 151 put dst 30 0x58 152 put dst 31 0xf7 153 end 154 155 fn t_rfc8032_empty_sig dst edit uchar * to void 156 put dst 0 0xe5 157 put dst 1 0x56 158 put dst 2 0x43 159 put dst 3 0x00 160 put dst 4 0xc3 161 put dst 5 0x60 162 put dst 6 0xac 163 put dst 7 0x72 164 put dst 8 0x90 165 put dst 9 0x86 166 put dst 10 0xe2 167 put dst 11 0xcc 168 put dst 12 0x80 169 put dst 13 0x6e 170 put dst 14 0x82 171 put dst 15 0x8a 172 put dst 16 0x84 173 put dst 17 0x87 174 put dst 18 0x7f 175 put dst 19 0x1e 176 put dst 20 0xb8 177 put dst 21 0xe5 178 put dst 22 0xd9 179 put dst 23 0x74 180 put dst 24 0xd8 181 put dst 25 0x73 182 put dst 26 0xe0 183 put dst 27 0x65 184 put dst 28 0x22 185 put dst 29 0x49 186 put dst 30 0x01 187 put dst 31 0x55 188 put dst 32 0x5f 189 put dst 33 0xb8 190 put dst 34 0x82 191 put dst 35 0x15 192 put dst 36 0x90 193 put dst 37 0xa3 194 put dst 38 0x3b 195 put dst 39 0xac 196 put dst 40 0xc6 197 put dst 41 0x1e 198 put dst 42 0x39 199 put dst 43 0x70 200 put dst 44 0x1c 201 put dst 45 0xf9 202 put dst 46 0xb4 203 put dst 47 0x6b 204 put dst 48 0xd2 205 put dst 49 0x5b 206 put dst 50 0xf5 207 put dst 51 0xf0 208 put dst 52 0x59 209 put dst 53 0x5b 210 put dst 54 0xbe 211 put dst 55 0x24 212 put dst 56 0x65 213 put dst 57 0x51 214 put dst 58 0x41 215 put dst 59 0x43 216 put dst 60 0x8e 217 put dst 61 0x7a 218 put dst 62 0x10 219 put dst 63 0x0b 220 end 221 222 note Build canonical 396-byte Binary Artifact v0 fixture (tests.rs: fixture()) 223 fn t_build_fixture buf edit uchar * to void 224 for i ulong FIX_TOTAL 225 put buf i 0 226 end 227 for i ulong 7 228 put buf i get art_magic_pfx i 229 end 230 put buf 7 0 231 art_put_u16_le buf 8 0 232 art_put_u16_le buf 10 128 233 art_put_u16_le buf 12 1 234 art_put_u16_le buf 14 1 235 art_put_u32_le buf 20 FIX_TOTAL 236 art_put_u32_le buf 24 128 237 art_put_u16_le buf 28 2 238 art_put_u16_le buf 30 32 239 art_put_u16_le buf 32 0 240 art_put_u32_le buf 36 0 241 art_put_u32_le buf 40 ART_CAPABILITY_TABLE_OFFSET 242 art_put_u16_le buf 44 1 243 art_put_u16_le buf 46 48 244 art_put_u32_le buf 48 FIX_RES_OFF 245 art_put_u16_le buf 52 48 246 art_put_u32_le buf 56 FIX_PAY_OFF 247 art_put_u32_le buf 60 8 248 art_put_u32_le buf 64 FIX_SIG_OFF 249 art_put_u16_le buf 68 100 250 art_put_u16_le buf 70 1 251 note Code section: AArch64 RET, RX 252 art_put_u16_le buf 128 1 253 art_put_u16_le buf 130 5 254 art_put_u32_le buf 136 0 255 art_put_u32_le buf 140 4 256 art_put_u32_le buf 144 4 257 art_put_u32_le buf 148 4096 258 note Data section: 4 initialized bytes, 1 page reserved, RW 259 art_put_u16_le buf 160 2 260 art_put_u16_le buf 162 3 261 art_put_u32_le buf 168 4 262 art_put_u32_le buf 172 4 263 art_put_u32_le buf 176 4096 264 art_put_u32_le buf 180 4096 265 note Scoped READ capability for object 7, bytes [0, 4) 266 art_put_u16_le buf 192 3 267 art_put_u32_le buf 196 7 268 art_put_u32_le buf 200 ART_RIGHT_READ 269 art_put_u32_le buf 204 1 270 art_put_u32_le buf 208 4 271 art_put_u64_le buf 216 4 272 art_put_u64_le buf 224 0 273 art_put_u64_le buf 232 4 274 note Resource envelope 275 art_put_u32_le buf FIX_RES_OFF 1 276 art_put_u32_le buf add FIX_RES_OFF 4 1 277 art_put_u32_le buf add FIX_RES_OFF 8 1 278 art_put_u16_le buf add FIX_RES_OFF 12 1 279 art_put_u32_le buf add FIX_RES_OFF 16 2 280 art_put_u32_le buf add FIX_RES_OFF 20 16 281 art_put_u64_le buf add FIX_RES_OFF 24 1000 282 art_put_u64_le buf add FIX_RES_OFF 32 2000 283 art_put_u32_le buf add FIX_RES_OFF 40 16 284 note Payload: RET + "DATA" 285 put buf FIX_PAY_OFF 0xc0 286 put buf add FIX_PAY_OFF 1 0x03 287 put buf add FIX_PAY_OFF 2 0x5f 288 put buf add FIX_PAY_OFF 3 0xd6 289 for i ulong 4 290 put buf add add FIX_PAY_OFF 4 i get t_data_bytes i 291 end 292 note Signature block placeholder 293 art_put_u16_le buf FIX_SIG_OFF 1 294 for i ulong 32 295 put buf add add FIX_SIG_OFF 4 i 0xa5 296 end 297 for i ulong 64 298 put buf add add FIX_SIG_OFF 36 i 0x5a 299 end 300 end 301 302 note Populate admitted() receipt in globals (receipt_tests.rs) 303 fn t_load_admitted to void 304 rcp_clear 305 put rcp_scalars 0 0 306 put rcp_scalars 1 RCP_DEC_ADMITTED 307 put rcp_scalars 2 RCP_TIER_QEMU 308 put rcp_scalars 3 1 309 put rcp_scalars 4 0 310 put rcp_scalars 5 RCP_EXEC_EXITED 311 put rcp_exit_status 0 0 312 put rcp_scalars 6 RCP_VALID_RES_FLAGS 313 put rcp_scalars 7 0 314 put rcp_scalars 8 0 315 put rcp_scalars 9 8 316 put rcp_scalars 10 2 317 put rcp_scalars 11 5 318 put rcp_scalars 12 10 319 d = new uchar 32 0 320 t_pattern 0x10 d 321 rcp_set_digest 0 d 322 t_pattern 0x20 d 323 rcp_set_digest 1 d 324 t_pattern 0x30 d 325 rcp_set_digest 2 d 326 t_pattern 0x40 d 327 rcp_set_digest 3 d 328 t_pattern 0x50 d 329 rcp_set_digest 4 d 330 t_pattern 0x60 d 331 rcp_set_digest 5 d 332 t_pattern 0x70 d 333 rcp_set_digest 6 d 334 t_pattern 0x80 d 335 rcp_set_digest 7 d 336 nb = new uchar 16 0 337 rcp_nonce d 1 nb 338 for i ulong 16 339 put rcp_nonce_buf i get nb i 340 end 341 end 342 343 note Populate rejected() receipt in globals (receipt_tests.rs) 344 fn t_load_rejected to void 345 t_load_admitted 346 put rcp_scalars 1 RCP_DEC_REJECTED 347 put rcp_scalars 3 2 348 put rcp_scalars 5 RCP_EXEC_NOT_RUN 349 put rcp_exit_status 0 0 350 put rcp_scalars 6 RCP_RES_RECLAIMED 351 put rcp_scalars 7 3 352 put rcp_scalars 8 ulong ART_ERR_BAD_SIGNATURE 353 put rcp_scalars 9 0 354 put rcp_scalars 10 0 355 put rcp_scalars 11 0 356 put rcp_scalars 12 0 357 z = new uchar 32 0 358 rcp_set_digest 2 z 359 rcp_set_digest 5 z 360 vid = new uchar 32 0 361 rcp_get_digest 7 vid 362 nb = new uchar 16 0 363 rcp_nonce vid 2 nb 364 for i ulong 16 365 put rcp_nonce_buf i get nb i 366 end 367 end 368 369 note Test group 1: Canonical artifact parsing, slices, and exact golden SHA-256 digests 370 fn test_artifact_canonical to int 371 buf = new uchar 396 0 372 t_build_fixture buf 373 if ne art_parse_and_identify buf ART_OK 374 ret 1 375 end 376 if or ne get art_meta 0 1 ne get art_meta 1 1 377 ret 2 378 end 379 if or ne get art_meta 2 0 ne get art_meta 4 1 380 ret 3 381 end 382 if or ne get art_caps 1 7 ne get art_caps 2 ART_RIGHT_READ 383 ret 4 384 end 385 if or ne get art_res 0 1 ne get art_meta 10 FIX_SIG_OFF 386 ret 5 387 end 388 d_req = new uchar 32 0 389 d_grt = new uchar 32 0 390 d_res = new uchar 32 0 391 art_requested_cap_digest part buf ART_CAPABILITY_TABLE_OFFSET 48 d_req 392 art_granted_cap_digest part buf ART_CAPABILITY_TABLE_OFFSET 48 d_grt 393 art_resource_envelope_digest part buf FIX_RES_OFF 48 d_res 394 if art_bytes_eq d_req d_grt 395 ret 6 396 end 397 if not t_hex_eq d_req t_gold_req 398 ret 7 399 end 400 if not t_hex_eq d_res t_gold_res 401 ret 8 402 end 403 pd = new uchar 32 0 404 aid = new uchar 32 0 405 for i ulong 32 406 put pd i get art_payload_dig i 407 put aid i get art_id i 408 end 409 if not t_hex_eq pd t_gold_pay 410 ret 9 411 end 412 if not t_hex_eq aid t_gold_aid 413 ret 10 414 end 415 note Every truncation 0..395 must fail 416 for n ulong FIX_TOTAL 417 if eq art_parse part buf 0 n ART_OK 418 ret 11 419 end 420 end 421 ret 0 422 end 423 424 note Test group 2: Header, length, section, entry, capability, resource, reserved mutations 425 fn test_artifact_mutations to int 426 buf = new uchar 396 0 427 t_build_fixture buf 428 put buf 0 xor get buf 0 1 429 if ne art_parse buf ART_ERR_BAD_MAGIC 430 ret 12 431 end 432 t_build_fixture buf 433 art_put_u16_le buf 8 1 434 if ne art_parse buf ART_ERR_UNSUPPORTED_VERSION 435 ret 13 436 end 437 t_build_fixture buf 438 art_put_u16_le buf 12 2 439 if ne art_parse buf ART_ERR_WRONG_TARGET 440 ret 14 441 end 442 t_build_fixture buf 443 art_put_u16_le buf 14 2 444 if ne art_parse buf ART_ERR_WRONG_ABI 445 ret 15 446 end 447 t_build_fixture buf 448 art_put_u32_le buf 20 sub FIX_TOTAL 1 449 if ne art_parse buf ART_ERR_WRONG_LENGTH 450 ret 16 451 end 452 t_build_fixture buf 453 art_put_u32_le buf 64 0xfffffff0 454 rc = art_parse buf 455 if and ne rc ART_ERR_SECTION_OVERLAP ne rc ART_ERR_LENGTH_OVERFLOW 456 ret 17 457 end 458 t_build_fixture buf 459 art_put_u32_le buf 16 1 460 if ne art_parse buf ART_ERR_UNSUPPORTED_FLAGS 461 ret 18 462 end 463 t_build_fixture buf 464 art_put_u32_le buf 168 0 465 if ne art_parse buf ART_ERR_BAD_SECTION 466 ret 19 467 end 468 t_build_fixture buf 469 art_put_u32_le buf 36 4 470 if ne art_parse buf ART_ERR_BAD_ENTRY_POINT 471 ret 20 472 end 473 t_build_fixture buf 474 art_put_u32_le buf 200 or ART_RIGHT_READ 0x40 475 if ne art_parse buf ART_ERR_MALFORMED_CAPABILITY 476 ret 21 477 end 478 t_build_fixture buf 479 art_put_u64_le buf 224 0xffffffffffffffff 480 if ne art_parse buf ART_ERR_LENGTH_OVERFLOW 481 ret 22 482 end 483 t_build_fixture buf 484 art_put_u32_le buf FIX_RES_OFF 65 485 if ne art_parse buf ART_ERR_RESOURCE_LIMIT 486 ret 23 487 end 488 t_build_fixture buf 489 art_put_u64_le buf add FIX_RES_OFF 24 `1000000001` 490 if ne art_parse buf ART_ERR_RESOURCE_LIMIT 491 ret 24 492 end 493 t_build_fixture buf 494 put buf 34 1 495 if ne art_parse buf ART_ERR_UNSUPPORTED_VERSION 496 ret 25 497 end 498 t_build_fixture buf 499 put buf 194 1 500 if ne art_parse buf ART_ERR_RESERVED_NON_ZERO 501 ret 26 502 end 503 t_build_fixture buf 504 put buf add FIX_RES_OFF 14 1 505 if ne art_parse buf ART_ERR_RESERVED_NON_ZERO 506 ret 27 507 end 508 t_build_fixture buf 509 art_put_u16_le buf 44 17 510 if ne art_parse buf ART_ERR_RESOURCE_LIMIT 511 ret 28 512 end 513 ret 0 514 end 515 516 note Test group 3: Identity sensitivity, signature exclusion, attenuation, bounded fuzz 517 fn test_artifact_identity_and_attenuation to int 518 buf = new uchar 396 0 519 t_build_fixture buf 520 if ne art_parse_and_identify buf ART_OK 521 ret 29 522 end 523 orig_id = new uchar 32 0 524 orig_pd = new uchar 32 0 525 for i ulong 32 526 put orig_id i get art_id i 527 put orig_pd i get art_payload_dig i 528 end 529 note Payload mutation changes artifact_id and payload_digest 530 put buf FIX_PAY_OFF xor get buf FIX_PAY_OFF 1 531 if ne art_parse_and_identify buf ART_OK 532 ret 30 533 end 534 cur_id = new uchar 32 0 535 cur_pd = new uchar 32 0 536 for i ulong 32 537 put cur_id i get art_id i 538 put cur_pd i get art_payload_dig i 539 end 540 if or art_bytes_eq orig_id cur_id art_bytes_eq orig_pd cur_pd 541 ret 31 542 end 543 note Capability mutation changes artifact_id 544 t_build_fixture buf 545 art_put_u32_le buf 200 or ART_RIGHT_READ ART_RIGHT_WRITE 546 if ne art_parse_and_identify buf ART_OK 547 ret 32 548 end 549 for i ulong 32 550 put cur_id i get art_id i 551 end 552 if art_bytes_eq orig_id cur_id 553 ret 33 554 end 555 note Resource mutation changes artifact_id 556 t_build_fixture buf 557 art_put_u64_le buf add FIX_RES_OFF 24 999 558 if ne art_parse_and_identify buf ART_OK 559 ret 34 560 end 561 for i ulong 32 562 put cur_id i get art_id i 563 end 564 if art_bytes_eq orig_id cur_id 565 ret 35 566 end 567 note Signature and signer fingerprint mutations do NOT change artifact_id 568 t_build_fixture buf 569 put buf add FIX_SIG_OFF 36 xor get buf add FIX_SIG_OFF 36 1 570 if ne art_parse_and_identify buf ART_OK 571 ret 36 572 end 573 for i ulong 32 574 put cur_id i get art_id i 575 end 576 if not art_bytes_eq orig_id cur_id 577 ret 37 578 end 579 t_build_fixture buf 580 put buf add FIX_SIG_OFF 4 xor get buf add FIX_SIG_OFF 4 1 581 if ne art_parse_and_identify buf ART_OK 582 ret 38 583 end 584 for i ulong 32 585 put cur_id i get art_id i 586 end 587 if not art_bytes_eq orig_id cur_id 588 ret 39 589 end 590 ret 0 591 end 592 593 note Test group 3b: Capability attenuation, encode/decode round-trip, and bounded fuzzing 594 fn test_artifact_attenuation_and_fuzz to int 595 c_r = new ulong 8 0 596 put c_r 0 3 597 put c_r 1 7 598 put c_r 2 ART_RIGHT_READ 599 put c_r 3 1 600 put c_r 4 4 601 put c_r 5 4 602 put c_r 6 0 603 put c_r 7 4 604 c_rw = new ulong 8 0 605 for i ulong 8 606 put c_rw i get c_r i 607 end 608 put c_rw 2 or ART_RIGHT_READ ART_RIGHT_WRITE 609 c_dec = new ulong 8 0 610 for i ulong 8 611 put c_dec i get c_r i 612 end 613 if not art_cap_is_attenuation_of c_r c_dec 614 ret 40 615 end 616 if art_cap_is_attenuation_of c_rw c_r 617 ret 41 618 end 619 if not art_cap_is_attenuation_of c_r c_rw 620 ret 42 621 end 622 cb = new uchar 48 0 623 art_cap_encode c_r cb 624 if ne art_cap_decode cb c_dec ART_OK 625 ret 43 626 end 627 for i ulong 8 628 if ne get c_dec i get c_r i 629 ret 44 630 end 631 end 632 fuzz = new uchar 512 0 633 st = uint 0x9e3779b9 634 for flen ulong 513 635 for j ulong flen bound 512 636 st = add mul st `1664525` `1013904223` 637 put fuzz j uchar shr st 24 638 end 639 ign = art_parse part fuzz 0 flen 640 end 641 ret 0 642 end 643 644 note Test group 4a: RFC 8032 Ed25519 verification + signing test vector 645 fn test_artifact_`ed25519`_vec to int 646 pk = new uchar 32 0 647 art_seed0b_test_pubkey pk 648 s1 = new uchar 32 0 649 t_seed1 s1 650 derived = new uchar 32 0 651 art_`ed25519`_pubkey s1 derived 652 if not art_bytes_eq pk derived 653 ret 45 654 end 655 empty_buf = new uchar 1 0 656 vec_sig = new uchar 64 0 657 t_rfc8032_empty_sig vec_sig 658 if not art_`ed25519`_verify pk part empty_buf 0 0 vec_sig 659 ret 46 660 end 661 put vec_sig 0 xor get vec_sig 0 1 662 if art_`ed25519`_verify pk part empty_buf 0 0 vec_sig 663 ret 47 664 end 665 t_rfc8032_empty_sig vec_sig 666 gen_sig = new uchar 64 0 667 art_`ed25519`_sign s1 part empty_buf 0 0 gen_sig 668 if not art_bytes_eq gen_sig vec_sig 669 ret 48 670 end 671 ret 0 672 end 673 674 note Test group 4b: Seed0b artifact authentication 675 fn test_artifact_anchor to int 676 pk = new uchar 32 0 677 art_seed0b_test_pubkey pk 678 s1 = new uchar 32 0 679 t_seed1 s1 680 buf = new uchar 396 0 681 t_build_fixture buf 682 if ne art_parse_and_identify buf ART_OK 683 ret 49 684 end 685 aid = new uchar 32 0 686 for i ulong 32 687 put aid i get art_id i 688 end 689 msg = new uchar 61 0 690 art_signature_message aid msg 691 sig = new uchar 64 0 692 art_`ed25519`_sign s1 msg sig 693 fp = new uchar 32 0 694 art_signer_fingerprint pk fp 695 for i ulong 32 696 put buf add add FIX_SIG_OFF 4 i get fp i 697 end 698 for i ulong 64 699 put buf add add FIX_SIG_OFF 36 i get sig i 700 end 701 art_anchors_clear 702 if ne art_verify buf ART_ERR_UNTRUSTED_SIGNER 703 ret 50 704 end 705 if ne art_anchors_add_seed0b_test ART_OK 706 ret 51 707 end 708 if ne art_verify buf ART_OK 709 ret 52 710 end 711 if ne get art_meta 11 ART_TRUST_TIER_SEED0B_QUAL 712 ret 53 713 end 714 put buf add FIX_SIG_OFF 36 xor get buf add FIX_SIG_OFF 36 1 715 if ne art_verify buf ART_ERR_BAD_SIGNATURE 716 ret 54 717 end 718 put buf add FIX_SIG_OFF 36 xor get buf add FIX_SIG_OFF 36 1 719 put buf add FIX_SIG_OFF 4 xor get buf add FIX_SIG_OFF 4 1 720 if ne art_verify buf ART_ERR_UNTRUSTED_SIGNER 721 ret 55 722 end 723 put buf add FIX_SIG_OFF 4 xor get buf add FIX_SIG_OFF 4 1 724 put buf FIX_PAY_OFF xor get buf FIX_PAY_OFF 1 725 if ne art_verify buf ART_ERR_BAD_SIGNATURE 726 ret 56 727 end 728 found_pk = new uchar 32 0 729 if ne art_anchors_find fp found_pk ART_TRUST_TIER_SEED0B_QUAL 730 ret 57 731 end 732 zfp = new uchar 32 0 733 if ne art_anchors_find zfp found_pk ART_TRUST_TIER_NONE 734 ret 58 735 end 736 ret 0 737 end 738 739 note Test group 5a: Receipt layout and golden digests/bytes 740 fn test_receipt_layout_and_goldens to int 741 t_load_admitted 742 b = new uchar 512 0 743 if ne rcp_encode b ART_OK 744 ret 60 745 end 746 if not t_hex_eq part b 0 96 t_gold_rec_hdr 747 ret 61 748 end 749 if not art_all_zero b 352 160 750 ret 62 751 end 752 dig = new uchar 32 0 753 rcp_digest b dig 754 if not t_hex_eq dig t_gold_rcp_adm 755 ret 63 756 end 757 put rcp_exit_status 0 -2 758 put rcp_scalars 6 0 759 b2 = new uchar 512 0 760 if ne rcp_encode b2 ART_OK 761 ret 64 762 end 763 if or ne get b2 68 0xfe ne get b2 69 0xff 764 ret 65 765 end 766 if or ne get b2 70 0xff ne get b2 71 0xff 767 ret 66 768 end 769 if ne rcp_decode b2 ART_OK 770 ret 67 771 end 772 if ne get rcp_exit_status 0 -2 773 ret 68 774 end 775 t_load_rejected 776 r = new uchar 512 0 777 if ne rcp_encode r ART_OK 778 ret 69 779 end 780 rcp_digest r dig 781 if not t_hex_eq dig t_gold_rcp_rej 782 ret 70 783 end 784 if ne rcp_decode r ART_OK 785 ret 71 786 end 787 ret 0 788 end 789 790 note Test group 5b: Receipt nonce, verifier_identity_bytes, Pi5 tier label 791 fn test_receipt_nonce_and_id to int 792 id1 = new uchar 32 0 793 id2 = new uchar 32 0 794 t_pattern 0x80 id1 795 t_pattern 0x81 id2 796 n1 = new uchar 16 0 797 n2 = new uchar 16 0 798 n3 = new uchar 16 0 799 rcp_nonce id1 1 n1 800 rcp_nonce id1 2 n2 801 rcp_nonce id2 1 n3 802 if or art_bytes_eq n1 n2 art_bytes_eq n1 n3 803 ret 72 804 end 805 vib = new uchar 45 0 806 if ne rcp_verifier_identity_bytes t_commit_ok 1 1 1 vib 45 807 ret 73 808 end 809 if or ne get vib 40 1 ne get vib 41 0 810 ret 74 811 end 812 if or ne get vib 42 1 ne get vib 44 1 813 ret 75 814 end 815 if ne rcp_verifier_identity_bytes t_commit_up 1 1 1 vib -1 816 ret 76 817 end 818 if ne rcp_verifier_identity_bytes part t_commit_ok 0 39 1 1 1 vib -1 819 ret 77 820 end 821 if ne rcp_verifier_identity_bytes t_commit_bad 1 1 1 vib -1 822 ret 78 823 end 824 t_load_admitted 825 put rcp_scalars 2 RCP_TIER_PI5 826 b = new uchar 512 0 827 if ne rcp_encode b ART_OK 828 ret 79 829 end 830 if ne rcp_decode b ART_OK 831 ret 80 832 end 833 if ne get rcp_scalars 2 RCP_TIER_PI5 834 ret 81 835 end 836 lbl = new uchar 32 0 837 llen = rcp_tier_label_copy RCP_TIER_PI5 lbl 838 if not art_bytes_eq part lbl 0 llen t_lbl_pi5 839 ret 82 840 end 841 ret 0 842 end 843 844 note Test group 6: Receipt strict decoding (lengths, magic, flags, reserved, enums, presence, consistency) 845 fn test_receipt_strict_decode to int 846 t_load_admitted 847 b = new uchar 512 0 848 ign = rcp_encode b 849 if ne rcp_decode part b 0 511 ART_ERR_TRUNCATED 850 ret 83 851 end 852 if ne rcp_decode part b 0 0 ART_ERR_TRUNCATED 853 ret 84 854 end 855 longb = new uchar 513 0 856 for i ulong 512 857 put longb i get b i 858 end 859 if ne rcp_decode longb ART_ERR_WRONG_LENGTH 860 ret 85 861 end 862 m = new uchar 512 0 863 for i ulong 512 864 put m i get b i 865 end 866 put m 0 88 867 if ne rcp_decode m ART_ERR_BAD_MAGIC 868 ret 86 869 end 870 put m 0 get b 0 871 put m 8 1 872 if ne rcp_decode m ART_ERR_UNSUPPORTED_VERSION 873 ret 87 874 end 875 put m 8 0 876 put m 10 95 877 if ne rcp_decode m ART_ERR_UNSUPPORTED_VERSION 878 ret 88 879 end 880 put m 10 96 881 put m 13 0 882 if ne rcp_decode m ART_ERR_UNSUPPORTED_VERSION 883 ret 89 884 end 885 put m 13 get b 13 886 note Unknown flag bits 3..31 887 for bit ulong 29 888 sh = add bit 3 889 art_put_u32_le m 16 shl ulong 1 sh 890 if ne rcp_decode m ART_ERR_UNSUPPORTED_FLAGS 891 ret 90 892 end 893 end 894 art_put_u32_le m 16 0 895 note Unknown result bits 8..31 896 for bit ulong 24 897 sh = add bit 8 898 art_put_u32_le m 72 or 0xff shl ulong 1 sh 899 if ne rcp_decode m ART_ERR_UNSUPPORTED_FLAGS 900 ret 91 901 end 902 end 903 art_put_u32_le m 72 0xff 904 note Non-zero reserved bytes 56..64 and 500..512 905 for i ulong 8 906 put m add 56 i 1 907 if ne rcp_decode m ART_ERR_RESERVED_NON_ZERO 908 ret 92 909 end 910 put m add 56 i 0 911 end 912 for i ulong 12 913 put m add 500 i 1 914 if ne rcp_decode m ART_ERR_RESERVED_NON_ZERO 915 ret 93 916 end 917 put m add 500 i 0 918 end 919 note Bad decision / tier / status enums 920 art_put_u16_le m 20 0 921 if ne rcp_decode m ART_ERR_MALFORMED_RECEIPT 922 ret 94 923 end 924 art_put_u16_le m 20 5 925 if ne rcp_decode m ART_ERR_MALFORMED_RECEIPT 926 ret 95 927 end 928 art_put_u16_le m 20 1 929 art_put_u16_le m 22 4 930 if ne rcp_decode m ART_ERR_MALFORMED_RECEIPT 931 ret 96 932 end 933 art_put_u16_le m 22 1 934 art_put_u32_le m 64 7 935 if ne rcp_decode m ART_ERR_MALFORMED_RECEIPT 936 ret 97 937 end 938 ret 0 939 end 940 941 note Test group 7: Receipt reason codes, presence flags, decision consistency, canary rules 942 fn test_receipt_semantics to int 943 b = new uchar 512 0 944 note Valid reasons 1..19 and 0x101..0x10a accepted; 0, 20, 0x100, 0x10b rejected 945 t_load_rejected 946 for r ulong 19 947 put rcp_scalars 8 add r 1 948 ign = rcp_encode b 949 if ne rcp_decode b ART_OK 950 ret 98 951 end 952 end 953 for r ulong 10 954 put rcp_scalars 8 add 0x101 r 955 ign = rcp_encode b 956 if ne rcp_decode b ART_OK 957 ret 99 958 end 959 end 960 put rcp_scalars 8 20 961 ign = rcp_encode b 962 if ne rcp_decode b ART_ERR_MALFORMED_RECEIPT 963 ret 100 964 end 965 put rcp_scalars 8 0x10b 966 ign = rcp_encode b 967 if ne rcp_decode b ART_ERR_MALFORMED_RECEIPT 968 ret 101 969 end 970 put rcp_scalars 8 18 971 put rcp_scalars 7 10 972 ign = rcp_encode b 973 if ne rcp_decode b ART_ERR_MALFORMED_RECEIPT 974 ret 102 975 end 976 note Optional fields require their presence flags 977 t_load_admitted 978 d = new uchar 32 0 979 t_pattern 1 d 980 rcp_set_digest 8 d 981 ign = rcp_encode b 982 if ne rcp_decode b ART_ERR_MALFORMED_RECEIPT 983 ret 103 984 end 985 t_load_admitted 986 put rcp_scalars 13 1 987 ign = rcp_encode b 988 if ne rcp_decode b ART_ERR_MALFORMED_RECEIPT 989 ret 104 990 end 991 t_load_admitted 992 put rcp_scalars 14 1 993 ign = rcp_encode b 994 if ne rcp_decode b ART_ERR_MALFORMED_RECEIPT 995 ret 105 996 end 997 t_load_admitted 998 put rcp_scalars 4 1 999 ign = rcp_encode b 1000 if ne rcp_decode b ART_ERR_MALFORMED_RECEIPT 1001 ret 106 1002 end 1003 note All optional fields present with VALID_FLAGS accepted 1004 t_load_admitted 1005 put rcp_scalars 0 RCP_VALID_FLAGS 1006 rcp_set_digest 8 d 1007 put rcp_scalars 13 3 1008 put rcp_scalars 14 4 1009 put rcp_scalars 4 5 1010 ign = rcp_encode b 1011 if ne rcp_decode b ART_OK 1012 ret 107 1013 end 1014 note Decision consistency rules 1015 t_load_admitted 1016 put rcp_scalars 7 3 1017 put rcp_scalars 8 18 1018 if ne rcp_validate ART_ERR_MALFORMED_RECEIPT 1019 ret 108 1020 end 1021 t_load_rejected 1022 put rcp_scalars 9 1 1023 if ne rcp_validate ART_ERR_MALFORMED_RECEIPT 1024 ret 109 1025 end 1026 t_load_rejected 1027 put rcp_scalars 6 or RCP_RES_RECLAIMED RCP_RES_READ_OK 1028 if ne rcp_validate ART_ERR_MALFORMED_RECEIPT 1029 ret 110 1030 end 1031 t_load_admitted 1032 put rcp_exit_status 0 3 1033 if ne rcp_validate ART_ERR_MALFORMED_RECEIPT 1034 ret 111 1035 end 1036 note Fault without RESULT_CANARY_PASSED is valid 1037 t_load_admitted 1038 put rcp_scalars 5 RCP_EXEC_FAULT 1039 put rcp_scalars 6 or RCP_RES_RECLAIMED RCP_RES_WX_SEALED 1040 if ne rcp_validate ART_OK 1041 ret 112 1042 end 1043 note CanaryFailed decision and status must agree 1044 t_load_admitted 1045 put rcp_scalars 1 RCP_DEC_CANARY_FAILED 1046 put rcp_scalars 5 RCP_EXEC_EXITED 1047 if ne rcp_validate ART_ERR_MALFORMED_RECEIPT 1048 ret 113 1049 end 1050 t_load_admitted 1051 put rcp_scalars 1 RCP_DEC_ADMITTED 1052 put rcp_scalars 5 RCP_EXEC_CANARY_FAILED 1053 if ne rcp_validate ART_ERR_MALFORMED_RECEIPT 1054 ret 114 1055 end 1056 t_load_admitted 1057 put rcp_scalars 1 RCP_DEC_CANARY_FAILED 1058 put rcp_scalars 5 RCP_EXEC_CANARY_FAILED 1059 put rcp_scalars 6 and RCP_VALID_RES_FLAGS not RCP_RES_CANARY_PASSED 1060 if ne rcp_validate ART_OK 1061 ret 115 1062 end 1063 ret 0 1064 end 1065 1066 note Test group 8a: Receipt Ed25519 signing, verification, anchor separation 1067 fn test_receipt_signatures to int 1068 s2 = new uchar 32 0 1069 s3 = new uchar 32 0 1070 t_seed2 s2 1071 t_seed3 s3 1072 pk2 = new uchar 32 0 1073 rcp_seed0b_test_pubkey pk2 1074 der2 = new uchar 32 0 1075 art_`ed25519`_pubkey s2 der2 1076 if not art_bytes_eq pk2 der2 1077 ret 116 1078 end 1079 apk = new uchar 32 0 1080 art_seed0b_test_pubkey apk 1081 if art_bytes_eq pk2 apk 1082 ret 117 1083 end 1084 t_load_admitted 1085 u = new uchar 512 0 1086 ign = rcp_encode u 1087 rcp_anchors_clear 1088 ign = rcp_anchors_add_seed0b_test 1089 if ne rcp_verify u ART_ERR_BAD_SIGNATURE_FORMAT 1090 ret 118 1091 end 1092 s = new uchar 512 0 1093 for i ulong 512 1094 put s i get u i 1095 end 1096 if ne rcp_sign s s2 ART_OK 1097 ret 119 1098 end 1099 dig_u = new uchar 32 0 1100 dig_s = new uchar 32 0 1101 rcp_digest u dig_u 1102 rcp_digest s dig_s 1103 if not art_bytes_eq dig_u dig_s 1104 ret 120 1105 end 1106 if ne rcp_verify s ART_OK 1107 ret 121 1108 end 1109 put s 402 1 1110 if ne rcp_decode s ART_ERR_RESERVED_NON_ZERO 1111 ret 122 1112 end 1113 put s 402 0 1114 put s 400 2 1115 if ne rcp_decode s ART_ERR_BAD_SIGNATURE_FORMAT 1116 ret 123 1117 end 1118 put s 400 1 1119 if ne rcp_sign s s2 ART_ERR_BAD_SIGNATURE_FORMAT 1120 ret 124 1121 end 1122 rcp_anchors_clear 1123 if ne rcp_verify s ART_ERR_UNTRUSTED_SIGNER 1124 ret 125 1125 end 1126 ign = rcp_anchors_add_seed0b_test 1127 put s 436 xor get s 436 0xff 1128 if ne rcp_verify s ART_ERR_BAD_SIGNATURE 1129 ret 126 1130 end 1131 put s 436 xor get s 436 0xff 1132 for i ulong 512 1133 put s i get u i 1134 end 1135 if ne rcp_sign s s3 ART_OK 1136 ret 127 1137 end 1138 if ne rcp_verify s ART_ERR_UNTRUSTED_SIGNER 1139 ret 128 1140 end 1141 t_load_rejected 1142 put rcp_scalars 11 1 1143 ign = rcp_encode s 1144 if ne rcp_sign s s2 ART_ERR_MALFORMED_RECEIPT 1145 ret 129 1146 end 1147 ret 0 1148 end 1149 1150 note Test group 8b: Receipt tamper detection and bounded fuzzing 1151 fn test_receipt_tamper_and_fuzz to int 1152 s2 = new uchar 32 0 1153 t_seed2 s2 1154 t_load_admitted 1155 u = new uchar 512 0 1156 ign = rcp_encode u 1157 dig_u = new uchar 32 0 1158 rcp_digest u dig_u 1159 dig_m = new uchar 32 0 1160 for bi ulong 400 1161 put u bi xor get u bi 1 1162 rcp_digest u dig_m 1163 if art_bytes_eq dig_m dig_u 1164 ret 130 1165 end 1166 put u bi xor get u bi 1 1167 end 1168 s = new uchar 512 0 1169 for i ulong 512 1170 put s i get u i 1171 end 1172 rcp_anchors_clear 1173 ign = rcp_anchors_add_seed0b_test 1174 ign = rcp_sign s s2 1175 for bi ulong 112 1176 pos = add 400 bi 1177 put s pos xor get s pos 1 1178 if eq rcp_verify s ART_OK 1179 ret 131 1180 end 1181 put s pos xor get s pos 1 1182 end 1183 for k ulong 25 1184 pos = mul k 16 1185 put s pos xor get s pos 1 1186 if eq rcp_verify s ART_OK 1187 ret 132 1188 end 1189 put s pos xor get s pos 1 1190 end 1191 ret 0 1192 end 1193 1194 note Test group 8c: Arbitrary mutated 512-byte receipt records never trap 1195 fn test_receipt_fuzz to int 1196 t_load_admitted 1197 u = new uchar 512 0 1198 ign = rcp_encode u 1199 st = ulong 0x9e3779b97f4a7c15 1200 m = new uchar 512 0 1201 for iter ulong 512 1202 for i ulong 512 1203 put m i get u i 1204 end 1205 for k ulong 8 1206 st = xor st shl st 13 1207 st = xor st shr st 7 1208 st = xor st shl st 17 1209 put m rem st 512 uchar and shr st 32 0xff 1210 end 1211 ign = rcp_decode m 1212 end 1213 ret 0 1214 end 1215 1216 fn main to int 1217 rc = test_artifact_canonical 1218 if ne rc 0 1219 ret rc 1220 end 1221 rc = test_artifact_mutations 1222 if ne rc 0 1223 ret rc 1224 end 1225 rc = test_artifact_identity_and_attenuation 1226 if ne rc 0 1227 ret rc 1228 end 1229 rc = test_artifact_attenuation_and_fuzz 1230 if ne rc 0 1231 ret rc 1232 end 1233 rc = test_artifact_`ed25519`_vec 1234 if ne rc 0 1235 ret rc 1236 end 1237 rc = test_artifact_anchor 1238 if ne rc 0 1239 ret rc 1240 end 1241 rc = test_receipt_layout_and_goldens 1242 if ne rc 0 1243 ret rc 1244 end 1245 rc = test_receipt_nonce_and_id 1246 if ne rc 0 1247 ret rc 1248 end 1249 rc = test_receipt_strict_decode 1250 if ne rc 0 1251 ret rc 1252 end 1253 rc = test_receipt_semantics 1254 if ne rc 0 1255 ret rc 1256 end 1257 rc = test_receipt_signatures 1258 if ne rc 0 1259 ret rc 1260 end 1261 rc = test_receipt_tamper_and_fuzz 1262 if ne rc 0 1263 ret rc 1264 end 1265 rc = test_receipt_fuzz 1266 if ne rc 0 1267 ret rc 1268 end 1269 ret 0 1270 end