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.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.om` 1011 lines ยท 25408 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note aienux/crates/aienos-artifact/artifact.om: Pure-Omega Binary Artifact v0 parser, 3 note capability/resource codecs, canonical domain-separated digests, identity, and 4 note Ed25519 signature verification. 5 note Converted from aienux crates/aienos-artifact/src/{lib,error,id,canonical,capability,resource,format,signature,verify}.rs. 6 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 ... 7 8 note Stable fail-closed error codes matching ArtifactError repr(u16) 9 const ART_OK int 0 10 const ART_ERR_BAD_MAGIC int 1 11 const ART_ERR_UNSUPPORTED_VERSION int 2 12 const ART_ERR_WRONG_TARGET int 3 13 const ART_ERR_WRONG_ABI int 4 14 const ART_ERR_LENGTH_OVERFLOW int 5 15 const ART_ERR_TRUNCATED int 6 16 const ART_ERR_WRONG_LENGTH int 7 17 const ART_ERR_RESERVED_NON_ZERO int 8 18 const ART_ERR_UNSUPPORTED_FLAGS int 9 19 const ART_ERR_SECTION_OVERLAP int 10 20 const ART_ERR_BAD_SECTION int 11 21 const ART_ERR_BAD_ENTRY_POINT int 12 22 const ART_ERR_MALFORMED_CAPABILITY int 13 23 const ART_ERR_RESOURCE_LIMIT int 14 24 const ART_ERR_BAD_SIGNATURE_FORMAT int 15 25 const ART_ERR_DIGEST_MISMATCH int 16 26 const ART_ERR_UNTRUSTED_SIGNER int 17 27 const ART_ERR_BAD_SIGNATURE int 18 28 const ART_ERR_RIGHTS_ESCALATION int 19 29 const ART_ERR_MALFORMED_RECEIPT int 20 30 31 note Format constants (format.rs) 32 const ART_FORMAT_VERSION ulong 0 33 const ART_HEADER_SIZE ulong 128 34 const ART_SECTION_TABLE_OFFSET ulong 128 35 const ART_SECTION_COUNT ulong 2 36 const ART_SECTION_RECORD_SIZE ulong 32 37 const ART_SECTION_TABLE_SIZE ulong 64 38 const ART_CAPABILITY_TABLE_OFFSET ulong 192 39 const ART_SIGNATURE_BLOCK_SIZE ulong 100 40 const ART_SIG_ALG_ED25519 ulong 1 41 const ART_MAX_ARTIFACT_SIZE ulong `16777216` 42 const ART_MAX_PAYLOAD_SIZE ulong `8388608` 43 const ART_TARGET_AARCH64_LE ulong 1 44 const ART_ABI_V1 ulong 1 45 const ART_SECTION_KIND_CODE ulong 1 46 const ART_SECTION_KIND_DATA ulong 2 47 const ART_PERM_RX ulong 5 48 const ART_PERM_RW ulong 3 49 50 note Capability constants (capability.rs) 51 const ART_CAP_RECORD_SIZE ulong 48 52 const ART_MAX_CAPABILITIES ulong 16 53 const ART_RESOURCE_KIND_CHANNEL ulong 2 54 const ART_RESOURCE_KIND_OBJECT ulong 3 55 const ART_RIGHT_READ ulong 1 56 const ART_RIGHT_WRITE ulong 2 57 const ART_RIGHT_MAP ulong 4 58 const ART_RIGHT_GRANT ulong 8 59 const ART_RIGHT_DERIVE ulong 16 60 const ART_RIGHT_REVOKE ulong 32 61 const ART_VALID_RIGHTS ulong 63 62 63 note Resource envelope constants (resource.rs) 64 const ART_RESOURCE_ENVELOPE_SIZE ulong 48 65 const ART_PAGE_SIZE ulong 4096 66 const ART_MAX_CODE_PAGES ulong 64 67 const ART_MAX_DATA_PAGES ulong 64 68 const ART_MAX_STACK_PAGES ulong 16 69 const ART_MAX_IPC_MESSAGES ulong 1024 70 const ART_MAX_IPC_BYTES ulong `1048576` 71 const ART_MAX_CPU_TICKS ulong `1000000000` 72 const ART_MAX_ELAPSED_TICKS ulong `1000000000` 73 const ART_MAX_SYSCALLS ulong 65536 74 75 note Signature and trust tier constants (signature.rs) 76 const ART_SIG_SIZE ulong 64 77 const ART_PUBKEY_SIZE ulong 32 78 const ART_SIG_MSG_SIZE ulong 61 79 const ART_TRUST_TIER_NONE ulong 0 80 const ART_TRUST_TIER_PRODUCTION ulong 1 81 const ART_TRUST_TIER_SEED0B_QUAL ulong 2 82 const ART_MAX_ANCHORS ulong 8 83 84 note Domain strings (each followed by a trailing NUL byte when hashed/framed) 85 text art_magic_pfx "AIENART" 86 text art_id_dom_pfx "AIENOS-ARTIFACT-V1" 87 text art_req_dom_pfx "AIENOS-ARTIFACT-CAP-REQUESTS-V1" 88 text art_grant_dom_pfx "AIENOS-ADMISSION-CAP-GRANTS-V1" 89 text art_res_dom_pfx "AIENOS-ARTIFACT-RESOURCES-V1" 90 text art_pol_dom_pfx "AIENOS-ADMISSION-POLICY-V1" 91 text art_mach_dom_pfx "AIENOS-MACHINE-ID-V1" 92 text art_ver_dom_pfx "AIENOS-VERIFIER-IDENTITY-V1" 93 text art_sig_dom_pfx "AIENOS-ARTIFACT-SIGNATURE-V1" 94 95 note Parsed artifact state 96 note art_meta slots: 97 note 0=target_arch, 1=abi_version, 2=entry_offset, 3=sig_alg, 98 note 4=cap_cnt, 5=cap_off, 6=cap_bytes_len, 7=res_off, 99 note 8=payload_off, 9=payload_len, 10=sig_off, 11=verified_tier 100 global art_meta ulong 12 101 note Two sections, 6 ulongs each: kind, perm, poff, flen, mlen, align 102 global art_sections ulong 12 103 note Up to 16 capabilities, 8 ulongs each: 104 note 0=resource_kind, 1=resource_id, 2=rights, 3=bounds_kind, 105 note 4=max_operations, 5=max_bytes, 6=byte_offset, 7=byte_length 106 global art_caps ulong 128 107 note Resource envelope, 9 ulongs: 108 note 0=code_pages, 1=data_pages, 2=stack_pages, 3=max_capabilities, 109 note 4=ipc_messages, 5=ipc_bytes, 6=cpu_ticks, 7=elapsed_ticks, 8=syscall_count 110 global art_res ulong 9 111 global art_signer_fp uchar 32 112 global art_sig uchar 64 113 global art_id uchar 32 114 global art_payload_dig uchar 32 115 116 note Artifact trust anchor table (distinct from receipt anchors) 117 global art_anchor_cnt ulong 1 118 global art_anchor_pks uchar 256 119 global art_anchor_tiers ulong 8 120 121 note Little-endian byte helpers 122 fn art_get_u16_le buf view uchar * off ulong to ulong 123 b0 = ulong get buf off 124 b1 = ulong get buf add off 1 125 ret or b0 shl b1 8 126 end 127 128 fn art_get_u32_le buf view uchar * off ulong to ulong 129 b0 = ulong get buf off 130 b1 = ulong get buf add off 1 131 b2 = ulong get buf add off 2 132 b3 = ulong get buf add off 3 133 ret or or b0 shl b1 8 or shl b2 16 shl b3 24 134 end 135 136 fn art_get_u64_le buf view uchar * off ulong to ulong 137 acc = ulong 0 138 for i ulong 8 139 b = ulong get buf add off i 140 acc = or acc shl b mul i 8 141 end 142 ret acc 143 end 144 145 fn art_put_u16_le buf edit uchar * off ulong v ulong to void 146 put buf off uchar and v 0xff 147 put buf add off 1 uchar and shr v 8 0xff 148 end 149 150 fn art_put_u32_le buf edit uchar * off ulong v ulong to void 151 put buf off uchar and v 0xff 152 put buf add off 1 uchar and shr v 8 0xff 153 put buf add off 2 uchar and shr v 16 0xff 154 put buf add off 3 uchar and shr v 24 0xff 155 end 156 157 fn art_put_u64_le buf edit uchar * off ulong v ulong to void 158 for i ulong 8 159 sh = mul i 8 160 put buf add off i uchar and shr v sh 0xff 161 end 162 end 163 164 fn art_all_zero buf view uchar * off ulong n ulong to bool 165 for i ulong n bound 1024 166 if ne get buf add off i 0 167 ret false 168 end 169 end 170 ret true 171 end 172 173 fn art_bytes_eq a view uchar * b view uchar * to bool 174 if ne len a len b 175 ret false 176 end 177 n = len a 178 for i ulong n bound 4096 179 if ne get a i get b i 180 ret false 181 end 182 end 183 ret true 184 end 185 186 note Domain-separated SHA-256: SHA256(dom_pfx || 0x00 || data) 187 fn art_sha256_dom dom view uchar * data view uchar * dst edit uchar * to void 188 ctx = new ulong 40 0 189 nul = new uchar 1 0 190 sha256_init ctx 191 sha256_update ctx dom 192 sha256_update ctx nul 193 sha256_update ctx data 194 sha256_final ctx dst 195 end 196 197 note Canonical digests (canonical.rs, id.rs) 198 fn art_id_from_unsigned_bytes data view uchar * dst edit uchar * to void 199 art_sha256_dom art_id_dom_pfx data dst 200 end 201 202 fn art_compute_id bytes view uchar * dst edit uchar * to void 203 so = get art_meta 10 204 art_id_from_unsigned_bytes part bytes 0 so dst 205 end 206 207 fn art_payload_digest_slice payload view uchar * dst edit uchar * to void 208 dlen = sha2_digest 256 payload dst 209 if ne dlen 32 210 trap 8 211 end 212 end 213 214 fn art_requested_cap_digest data view uchar * dst edit uchar * to void 215 art_sha256_dom art_req_dom_pfx data dst 216 end 217 218 fn art_granted_cap_digest data view uchar * dst edit uchar * to void 219 art_sha256_dom art_grant_dom_pfx data dst 220 end 221 222 fn art_resource_envelope_digest data view uchar * dst edit uchar * to void 223 art_sha256_dom art_res_dom_pfx data dst 224 end 225 226 fn art_policy_digest data view uchar * dst edit uchar * to void 227 art_sha256_dom art_pol_dom_pfx data dst 228 end 229 230 fn art_machine_id_digest data view uchar * dst edit uchar * to void 231 art_sha256_dom art_mach_dom_pfx data dst 232 end 233 234 fn art_verifier_identity_digest data view uchar * dst edit uchar * to void 235 art_sha256_dom art_ver_dom_pfx data dst 236 end 237 238 fn art_signer_fingerprint pk view uchar * dst edit uchar * to void 239 dlen = sha2_digest 256 pk dst 240 if ne dlen 32 241 trap 8 242 end 243 end 244 245 note CapabilityRequest encode / validate / decode / attenuation (capability.rs) 246 fn art_cap_encode cap view ulong * dst edit uchar * to void 247 for i ulong 48 248 put dst i 0 249 end 250 art_put_u16_le dst 0 get cap 0 251 art_put_u32_le dst 4 get cap 1 252 art_put_u32_le dst 8 get cap 2 253 art_put_u32_le dst 12 get cap 3 254 art_put_u32_le dst 16 get cap 4 255 art_put_u64_le dst 24 get cap 5 256 art_put_u64_le dst 32 get cap 6 257 art_put_u64_le dst 40 get cap 7 258 end 259 260 fn art_cap_validate cap view ulong * to int 261 rk = get cap 0 262 rid = get cap 1 263 rts = get cap 2 264 bk = get cap 3 265 mops = get cap 4 266 mb = get cap 5 267 if and ne rk ART_RESOURCE_KIND_OBJECT ne rk ART_RESOURCE_KIND_CHANNEL 268 ret ART_ERR_MALFORMED_CAPABILITY 269 end 270 if or eq rid 0 eq rts 0 271 ret ART_ERR_MALFORMED_CAPABILITY 272 end 273 if ne and rts not ART_VALID_RIGHTS 0 274 ret ART_ERR_MALFORMED_CAPABILITY 275 end 276 if or eq mops 0 eq mb 0 277 ret ART_ERR_MALFORMED_CAPABILITY 278 end 279 boff = get cap 6 280 blen = get cap 7 281 if and eq rk ART_RESOURCE_KIND_OBJECT eq bk 1 282 bend = add boff blen 283 if lt bend boff 284 ret ART_ERR_LENGTH_OVERFLOW 285 end 286 if or eq blen 0 gt mb blen 287 ret ART_ERR_MALFORMED_CAPABILITY 288 end 289 ret ART_OK 290 end 291 if and eq rk ART_RESOURCE_KIND_CHANNEL eq bk 2 292 if or ne boff 0 ne blen 0 293 ret ART_ERR_MALFORMED_CAPABILITY 294 end 295 ret ART_OK 296 end 297 ret ART_ERR_MALFORMED_CAPABILITY 298 end 299 300 fn art_cap_decode bytes view uchar * cap edit ulong * to int 301 n = len bytes 302 if lt n ART_CAP_RECORD_SIZE 303 ret ART_ERR_TRUNCATED 304 end 305 if gt n ART_CAP_RECORD_SIZE 306 ret ART_ERR_WRONG_LENGTH 307 end 308 if or ne art_get_u16_le bytes 2 0 ne art_get_u32_le bytes 20 0 309 ret ART_ERR_RESERVED_NON_ZERO 310 end 311 put cap 0 art_get_u16_le bytes 0 312 put cap 1 art_get_u32_le bytes 4 313 put cap 2 art_get_u32_le bytes 8 314 put cap 3 art_get_u32_le bytes 12 315 put cap 4 art_get_u32_le bytes 16 316 put cap 5 art_get_u64_le bytes 24 317 put cap 6 art_get_u64_le bytes 32 318 put cap 7 art_get_u64_le bytes 40 319 ret art_cap_validate cap 320 end 321 322 fn art_cap_is_attenuation_of cand view ulong * req view ulong * to bool 323 if ne art_cap_validate cand ART_OK 324 ret false 325 end 326 if ne art_cap_validate req ART_OK 327 ret false 328 end 329 if or ne get cand 0 get req 0 ne get cand 1 get req 1 330 ret false 331 end 332 if ne get cand 3 get req 3 333 ret false 334 end 335 if ne and get cand 2 not get req 2 0 336 ret false 337 end 338 if or gt get cand 4 get req 4 gt get cand 5 get req 5 339 ret false 340 end 341 bk = get cand 3 342 if eq bk 1 343 co = get cand 6 344 cl = get cand 7 345 ce = add co cl 346 if lt ce co 347 ret false 348 end 349 ro = get req 6 350 rl = get req 7 351 re = add ro rl 352 if lt re ro 353 ret false 354 end 355 ret and ge co ro le ce re 356 end 357 if eq bk 2 358 ret and eq get cand 6 0 eq get cand 7 0 359 end 360 ret false 361 end 362 363 note ResourceEnvelope validate / decode / capacity (resource.rs) 364 fn art_res_validate env view ulong * req_caps ulong to int 365 cp = get env 0 366 dp = get env 1 367 sp = get env 2 368 mc = get env 3 369 if or eq cp 0 gt cp ART_MAX_CODE_PAGES 370 ret ART_ERR_RESOURCE_LIMIT 371 end 372 if or eq dp 0 gt dp ART_MAX_DATA_PAGES 373 ret ART_ERR_RESOURCE_LIMIT 374 end 375 if or eq sp 0 gt sp ART_MAX_STACK_PAGES 376 ret ART_ERR_RESOURCE_LIMIT 377 end 378 if or lt mc req_caps gt mc ART_MAX_CAPABILITIES 379 ret ART_ERR_RESOURCE_LIMIT 380 end 381 if or gt get env 4 ART_MAX_IPC_MESSAGES gt get env 5 ART_MAX_IPC_BYTES 382 ret ART_ERR_RESOURCE_LIMIT 383 end 384 ct = get env 6 385 et = get env 7 386 sc = get env 8 387 if or eq ct 0 gt ct ART_MAX_CPU_TICKS 388 ret ART_ERR_RESOURCE_LIMIT 389 end 390 if or eq et 0 gt et ART_MAX_ELAPSED_TICKS 391 ret ART_ERR_RESOURCE_LIMIT 392 end 393 if or eq sc 0 gt sc ART_MAX_SYSCALLS 394 ret ART_ERR_RESOURCE_LIMIT 395 end 396 ret ART_OK 397 end 398 399 fn art_res_decode bytes view uchar * req_caps ulong env edit ulong * to int 400 n = len bytes 401 if lt n ART_RESOURCE_ENVELOPE_SIZE 402 ret ART_ERR_TRUNCATED 403 end 404 if gt n ART_RESOURCE_ENVELOPE_SIZE 405 ret ART_ERR_WRONG_LENGTH 406 end 407 if or ne art_get_u16_le bytes 14 0 ne art_get_u32_le bytes 44 0 408 ret ART_ERR_RESERVED_NON_ZERO 409 end 410 put env 0 art_get_u32_le bytes 0 411 put env 1 art_get_u32_le bytes 4 412 put env 2 art_get_u32_le bytes 8 413 put env 3 art_get_u16_le bytes 12 414 put env 4 art_get_u32_le bytes 16 415 put env 5 art_get_u32_le bytes 20 416 put env 6 art_get_u64_le bytes 24 417 put env 7 art_get_u64_le bytes 32 418 put env 8 art_get_u32_le bytes 40 419 ret art_res_validate env req_caps 420 end 421 422 fn art_res_code_cap_bytes env view ulong * to ulong 423 ret mul get env 0 ART_PAGE_SIZE 424 end 425 426 fn art_res_data_cap_bytes env view ulong * to ulong 427 ret mul get env 1 ART_PAGE_SIZE 428 end 429 430 note SignatureBlock decode (signature.rs) 431 fn art_sig_block_decode bytes view uchar * fp_out edit uchar * sig_out edit uchar * to int 432 n = len bytes 433 if lt n ART_SIGNATURE_BLOCK_SIZE 434 ret ART_ERR_TRUNCATED 435 end 436 if gt n ART_SIGNATURE_BLOCK_SIZE 437 ret ART_ERR_WRONG_LENGTH 438 end 439 alg = art_get_u16_le bytes 0 440 if ne alg ART_SIG_ALG_ED25519 441 ret ART_ERR_BAD_SIGNATURE_FORMAT 442 end 443 if or ne get bytes 2 0 ne get bytes 3 0 444 ret ART_ERR_RESERVED_NON_ZERO 445 end 446 for i ulong 32 447 put fp_out i get bytes add 4 i 448 end 449 for i ulong 64 450 put sig_out i get bytes add 36 i 451 end 452 ret ART_OK 453 end 454 455 note Section decode and validation (format.rs) 456 fn art_decode_section bytes view uchar * off ulong slot ulong to int 457 if ne art_get_u32_le bytes add off 4 0 458 ret ART_ERR_RESERVED_NON_ZERO 459 end 460 if not art_all_zero bytes add off 24 8 461 ret ART_ERR_RESERVED_NON_ZERO 462 end 463 base = mul slot 6 464 put art_sections base art_get_u16_le bytes off 465 put art_sections add base 1 art_get_u16_le bytes add off 2 466 put art_sections add base 2 art_get_u32_le bytes add off 8 467 put art_sections add base 3 art_get_u32_le bytes add off 12 468 put art_sections add base 4 art_get_u32_le bytes add off 16 469 put art_sections add base 5 art_get_u32_le bytes add off 20 470 ret ART_OK 471 end 472 473 fn art_validate_sections payload_len ulong to int 474 cf = get art_sections 3 475 if or ne get art_sections 0 ART_SECTION_KIND_CODE ne get art_sections 1 ART_PERM_RX 476 ret ART_ERR_BAD_SECTION 477 end 478 if or ne get art_sections 2 0 eq cf 0 479 ret ART_ERR_BAD_SECTION 480 end 481 if or ne get art_sections 4 cf ne get art_sections 5 ART_PAGE_SIZE 482 ret ART_ERR_BAD_SECTION 483 end 484 df = get art_sections 9 485 if or ne get art_sections 6 ART_SECTION_KIND_DATA ne get art_sections 7 ART_PERM_RW 486 ret ART_ERR_BAD_SECTION 487 end 488 if or ne get art_sections 8 cf eq df 0 489 ret ART_ERR_BAD_SECTION 490 end 491 if or lt get art_sections 10 df ne get art_sections 11 ART_PAGE_SIZE 492 ret ART_ERR_BAD_SECTION 493 end 494 end_p = add cf df 495 if lt end_p cf 496 ret ART_ERR_LENGTH_OVERFLOW 497 end 498 if ne end_p payload_len 499 ret ART_ERR_SECTION_OVERLAP 500 end 501 ret ART_OK 502 end 503 504 note Header validation helper for art_parse (keeps register pressure low) 505 fn art_parse_header bytes view uchar * to int 506 n = len bytes 507 if lt n ART_HEADER_SIZE 508 ret ART_ERR_TRUNCATED 509 end 510 if gt n ART_MAX_ARTIFACT_SIZE 511 ret ART_ERR_RESOURCE_LIMIT 512 end 513 for i ulong 7 514 if ne get bytes i get art_magic_pfx i 515 ret ART_ERR_BAD_MAGIC 516 end 517 end 518 if ne get bytes 7 0 519 ret ART_ERR_BAD_MAGIC 520 end 521 if or ne art_get_u16_le bytes 8 ART_FORMAT_VERSION ne art_get_u16_le bytes 10 ART_HEADER_SIZE 522 ret ART_ERR_UNSUPPORTED_VERSION 523 end 524 ta = art_get_u16_le bytes 12 525 if ne ta ART_TARGET_AARCH64_LE 526 ret ART_ERR_WRONG_TARGET 527 end 528 av = art_get_u16_le bytes 14 529 if ne av ART_ABI_V1 530 ret ART_ERR_WRONG_ABI 531 end 532 if ne art_get_u32_le bytes 16 0 533 ret ART_ERR_UNSUPPORTED_FLAGS 534 end 535 tlen = art_get_u32_le bytes 20 536 if ne tlen n 537 ret ART_ERR_WRONG_LENGTH 538 end 539 if or ne art_get_u32_le bytes 24 ART_SECTION_TABLE_OFFSET ne art_get_u16_le bytes 28 ART_SECTION_COUNT 540 ret ART_ERR_UNSUPPORTED_VERSION 541 end 542 if or ne art_get_u16_le bytes 30 ART_SECTION_RECORD_SIZE ne art_get_u16_le bytes 32 0 543 ret ART_ERR_UNSUPPORTED_VERSION 544 end 545 if ne art_get_u16_le bytes 34 0 546 ret ART_ERR_UNSUPPORTED_VERSION 547 end 548 if or ne art_get_u32_le bytes 40 ART_CAPABILITY_TABLE_OFFSET ne art_get_u16_le bytes 46 ART_CAP_RECORD_SIZE 549 ret ART_ERR_UNSUPPORTED_VERSION 550 end 551 if or ne art_get_u16_le bytes 52 ART_RESOURCE_ENVELOPE_SIZE ne art_get_u16_le bytes 54 0 552 ret ART_ERR_UNSUPPORTED_VERSION 553 end 554 if not art_all_zero bytes 72 56 555 ret ART_ERR_RESERVED_NON_ZERO 556 end 557 put art_meta 0 ta 558 put art_meta 1 av 559 put art_meta 2 art_get_u32_le bytes 36 560 ret ART_OK 561 end 562 563 note Layout offsets check helper for art_parse 564 fn art_parse_layout bytes view uchar * to int 565 n = len bytes 566 cc = art_get_u16_le bytes 44 567 if gt cc ART_MAX_CAPABILITIES 568 ret ART_ERR_RESOURCE_LIMIT 569 end 570 clen = mul cc ART_CAP_RECORD_SIZE 571 roff = art_get_u32_le bytes 48 572 if ne roff add ART_CAPABILITY_TABLE_OFFSET clen 573 ret ART_ERR_SECTION_OVERLAP 574 end 575 rend = add roff ART_RESOURCE_ENVELOPE_SIZE 576 poff = art_get_u32_le bytes 56 577 if ne poff and add rend 15 not ulong 15 578 ret ART_ERR_SECTION_OVERLAP 579 end 580 if gt poff n 581 ret ART_ERR_TRUNCATED 582 end 583 if not art_all_zero bytes rend sub poff rend 584 ret ART_ERR_RESERVED_NON_ZERO 585 end 586 plen = art_get_u32_le bytes 60 587 if gt plen ART_MAX_PAYLOAD_SIZE 588 ret ART_ERR_RESOURCE_LIMIT 589 end 590 soff = art_get_u32_le bytes 64 591 if or ne art_get_u16_le bytes 68 ART_SIGNATURE_BLOCK_SIZE ne art_get_u16_le bytes 70 ART_SIG_ALG_ED25519 592 ret ART_ERR_BAD_SIGNATURE_FORMAT 593 end 594 if ne soff add poff plen 595 ret ART_ERR_SECTION_OVERLAP 596 end 597 if ne add soff ART_SIGNATURE_BLOCK_SIZE n 598 ret ART_ERR_WRONG_LENGTH 599 end 600 put art_meta 3 ART_SIG_ALG_ED25519 601 put art_meta 4 cc 602 put art_meta 5 ART_CAPABILITY_TABLE_OFFSET 603 put art_meta 6 clen 604 put art_meta 7 roff 605 put art_meta 8 poff 606 put art_meta 9 plen 607 put art_meta 10 soff 608 put art_meta 11 ART_TRUST_TIER_NONE 609 ret ART_OK 610 end 611 612 note Parse capability table into art_caps with strict (resource_kind, resource_id) ordering 613 fn art_parse_caps bytes view uchar * cc ulong to int 614 prev_key = ulong 0 615 tmp = new ulong 8 0 616 for idx ulong cc bound 16 617 rc = art_cap_decode part bytes add ART_CAPABILITY_TABLE_OFFSET mul idx ART_CAP_RECORD_SIZE ART_CAP_RECORD_SIZE tmp 618 if ne rc ART_OK 619 ret rc 620 end 621 key = or shl get tmp 0 32 get tmp 1 622 if le key prev_key 623 ret ART_ERR_MALFORMED_CAPABILITY 624 end 625 prev_key = key 626 for f ulong 8 627 put art_caps add mul idx 8 f get tmp f 628 end 629 end 630 ret ART_OK 631 end 632 633 note Strict fail-closed Binary Artifact v0 parser (Artifact::parse) 634 fn art_parse bytes view uchar * to int 635 rc = art_parse_header bytes 636 if ne rc ART_OK 637 ret rc 638 end 639 rc = art_parse_layout bytes 640 if ne rc ART_OK 641 ret rc 642 end 643 rc = art_decode_section bytes 128 0 644 if ne rc ART_OK 645 ret rc 646 end 647 rc = art_decode_section bytes 160 1 648 if ne rc ART_OK 649 ret rc 650 end 651 rc = art_validate_sections get art_meta 9 652 if ne rc ART_OK 653 ret rc 654 end 655 rc = art_parse_caps bytes get art_meta 4 656 if ne rc ART_OK 657 ret rc 658 end 659 env = new ulong 9 0 660 rc = art_res_decode part bytes get art_meta 7 ART_RESOURCE_ENVELOPE_SIZE get art_meta 4 env 661 if ne rc ART_OK 662 ret rc 663 end 664 for i ulong 9 665 put art_res i get env i 666 end 667 if or gt get art_sections 4 art_res_code_cap_bytes env gt get art_sections 10 art_res_data_cap_bytes env 668 ret ART_ERR_RESOURCE_LIMIT 669 end 670 if ne and get art_meta 2 3 0 671 ret ART_ERR_BAD_ENTRY_POINT 672 end 673 if gt add get art_meta 2 4 0xffffffff 674 ret ART_ERR_LENGTH_OVERFLOW 675 end 676 if gt add get art_meta 2 4 get art_sections 3 677 ret ART_ERR_BAD_ENTRY_POINT 678 end 679 fp = new uchar 32 0 680 sg = new uchar 64 0 681 rc = art_sig_block_decode part bytes get art_meta 10 ART_SIGNATURE_BLOCK_SIZE fp sg 682 if ne rc ART_OK 683 ret rc 684 end 685 for i ulong 32 686 put art_signer_fp i get fp i 687 end 688 for i ulong 64 689 put art_sig i get sg i 690 end 691 ret ART_OK 692 end 693 694 note Parse and compute ArtifactId + payload_digest (verify.rs: parse_and_identify) 695 fn art_parse_and_identify bytes view uchar * to int 696 if gt len bytes ART_MAX_ARTIFACT_SIZE 697 ret ART_ERR_RESOURCE_LIMIT 698 end 699 rc = art_parse bytes 700 if ne rc ART_OK 701 ret rc 702 end 703 id_buf = new uchar 32 0 704 art_compute_id bytes id_buf 705 for i ulong 32 706 put art_id i get id_buf i 707 end 708 pd_buf = new uchar 32 0 709 poff = get art_meta 8 710 plen = get art_meta 9 711 art_payload_digest_slice part bytes poff plen pd_buf 712 for i ulong 32 713 put art_payload_dig i get pd_buf i 714 end 715 ret ART_OK 716 end 717 718 note Ed25519 scalar multiplication [s]B (256 bits) for RFC 8032 keygen and signing 719 fn art_ed_smul_b w edit ulong 1024 s view uchar 32 to void 720 edfcpy w edq edzero 64 721 edfcpy w add edq 16 edone 16 722 edfcpy w add edq 32 edone 16 723 for j ulong 256 724 i = sub 255 j 725 edpdbl w edq 726 if eq edbit s i 1 727 edpadd w edq edbp 728 end 729 end 730 end 731 732 note Compute S = (r + k * a) mod L (32-byte little-endian scalars) 733 fn art_ed_muladd_l r view uchar 32 k view uchar 32 a view uchar 32 dst edit uchar 32 to void 734 x = new long 64 0 735 for i ulong 32 736 put x i long get r i 737 end 738 for i ulong 32 739 ki = long get k i 740 for j ulong 32 741 idx = add i j 742 put x idx add get x idx mul ki long get a j 743 end 744 end 745 carry = long 0 746 for i ulong 64 747 v = add get x i carry 748 put x i and v 255 749 carry = shr v 8 750 end 751 edmodl x 752 for i ulong 32 753 put dst i uchar get x i 754 end 755 end 756 757 note Derive RFC 8032 Ed25519 public key from 32-byte seed 758 fn art_`ed25519`_pubkey seed view uchar * pk_out edit uchar * to void 759 h = new uchar 64 0 760 dlen = sha2_digest 512 part seed 0 32 h 761 if ne dlen 64 762 trap 8 763 end 764 a = new uchar 32 0 765 for i ulong 32 766 put a i get h i 767 end 768 put a 0 and get a 0 248 769 put a 31 or and get a 31 127 64 770 w = new ulong 1024 0 771 edinit w 772 art_ed_smul_b w a 773 pk32 = new uchar 32 0 774 edpenc w edq pk32 775 for i ulong 32 776 put pk_out i get pk32 i 777 end 778 end 779 780 note Reduce 64-byte SHA-512 digest modulo L into 32-byte scalar 781 fn art_ed_reduce64 hd view uchar 64 dst edit uchar 32 to void 782 x = new long 64 0 783 for i ulong 64 784 put x i long get hd i 785 end 786 edmodl x 787 for i ulong 32 788 put dst i uchar get x i 789 end 790 end 791 792 note Helper: compute r = SHA512(prefix || msg) mod L and R = encode([r]B) 793 fn art_ed_sign_step1 pfx view uchar 32 msg view uchar * r_out edit uchar 32 rb_out edit uchar 32 to void 794 ctx = new ulong 40 0 795 sha512_init ctx 796 sha512_update ctx pfx 797 sha512_update ctx msg 798 hd = new uchar 64 0 799 sha512_final ctx hd 800 art_ed_reduce64 hd r_out 801 w = new ulong 1024 0 802 edinit w 803 art_ed_smul_b w r_out 804 edpenc w edq rb_out 805 end 806 807 note Helper: compute k = SHA512(R || A || msg) mod L 808 fn art_ed_sign_step2 rb view uchar 32 pk view uchar 32 msg view uchar * k_out edit uchar 32 to void 809 ctx = new ulong 40 0 810 sha512_init ctx 811 sha512_update ctx rb 812 sha512_update ctx pk 813 sha512_update ctx msg 814 hd = new uchar 64 0 815 sha512_final ctx hd 816 art_ed_reduce64 hd k_out 817 end 818 819 note Helper: expand 32-byte seed into clamped scalar a, 32-byte prefix, and 32-byte public key 820 fn art_ed_expand seed view uchar * a_out edit uchar 32 pfx_out edit uchar 32 pk_out edit uchar 32 to void 821 h = new uchar 64 0 822 dlen = sha2_digest 512 part seed 0 32 h 823 if ne dlen 64 824 trap 8 825 end 826 for i ulong 32 827 put a_out i get h i 828 put pfx_out i get h add 32 i 829 end 830 put a_out 0 and get a_out 0 248 831 put a_out 31 or and get a_out 31 127 64 832 w = new ulong 1024 0 833 edinit w 834 art_ed_smul_b w a_out 835 edpenc w edq pk_out 836 end 837 838 note RFC 8032 pure Ed25519 signing (seed[0..32], msg, sig_out[0..64]) 839 fn art_`ed25519`_sign seed view uchar * msg view uchar * sig_out edit uchar * to void 840 a = new uchar 32 0 841 pfx = new uchar 32 0 842 pk = new uchar 32 0 843 art_ed_expand seed a pfx pk 844 r = new uchar 32 0 845 rb = new uchar 32 0 846 art_ed_sign_step1 pfx msg r rb 847 k = new uchar 32 0 848 art_ed_sign_step2 rb pk msg k 849 art_ed_muladd_l r k a pfx 850 for i ulong 32 851 put sig_out i get rb i 852 put sig_out add 32 i get pfx i 853 end 854 end 855 856 note RFC 8032 Ed25519 strict verification (mode 0) via protocol/omnet/om/`ed25519`/`ed25519`.om 857 fn art_`ed25519`_verify pk view uchar * msg view uchar * sig view uchar * to bool 858 if or ne len pk 32 ne len sig 64 859 ret false 860 end 861 mlen = len msg 862 if gt mlen 65536 863 ret false 864 end 865 pk32 = new uchar 32 0 866 for i ulong 32 867 put pk32 i get pk i 868 end 869 sig64 = new uchar 64 0 870 for i ulong 64 871 put sig64 i get sig i 872 end 873 mbuf = new uchar 65536 0 874 for i ulong mlen bound 65536 875 put mbuf i get msg i 876 end 877 ret eq edverify pk32 mbuf mlen sig64 0 1 878 end 879 880 note Build 61-byte artifact signature message: "AIENOS-ARTIFACT-SIGNATURE-V1\0" || artifact_id 881 fn art_signature_message aid view uchar * msg_out edit uchar * to void 882 for i ulong 28 883 put msg_out i get art_sig_dom_pfx i 884 end 885 put msg_out 28 0 886 for i ulong 32 887 put msg_out add 29 i get aid i 888 end 889 end 890 891 note Trust anchor management (EmptyTrustAnchorSet / ProductionTrustAnchorSet / Seed0bTestAnchorSet) 892 fn art_anchors_clear to void 893 put art_anchor_cnt 0 0 894 end 895 896 fn art_anchors_add pk view uchar * tier ulong to int 897 if ne len pk 32 898 ret ART_ERR_BAD_SIGNATURE_FORMAT 899 end 900 cnt = get art_anchor_cnt 0 901 if ge cnt ART_MAX_ANCHORS 902 ret ART_ERR_RESOURCE_LIMIT 903 end 904 base = mul cnt 32 905 for i ulong 32 906 put art_anchor_pks add base i get pk i 907 end 908 put art_anchor_tiers cnt tier 909 put art_anchor_cnt 0 add cnt 1 910 ret ART_OK 911 end 912 913 note Populate RFC 8032 TEST 1 public key (Seed0bTestAnchorSet, TEST ONLY) 914 fn art_seed0b_test_pubkey dst edit uchar * to void 915 put dst 0 0xd7 916 put dst 1 0x5a 917 put dst 2 0x98 918 put dst 3 0x01 919 put dst 4 0x82 920 put dst 5 0xb1 921 put dst 6 0x0a 922 put dst 7 0xb7 923 put dst 8 0xd5 924 put dst 9 0x4b 925 put dst 10 0xfe 926 put dst 11 0xd3 927 put dst 12 0xc9 928 put dst 13 0x64 929 put dst 14 0x07 930 put dst 15 0x3a 931 put dst 16 0x0e 932 put dst 17 0xe1 933 put dst 18 0x72 934 put dst 19 0xf3 935 put dst 20 0xda 936 put dst 21 0xa6 937 put dst 22 0x23 938 put dst 23 0x25 939 put dst 24 0xaf 940 put dst 25 0x02 941 put dst 26 0x1a 942 put dst 27 0x68 943 put dst 28 0xf7 944 put dst 29 0x07 945 put dst 30 0x51 946 put dst 31 0x1a 947 end 948 949 fn art_anchors_add_seed0b_test to int 950 pk = new uchar 32 0 951 art_seed0b_test_pubkey pk 952 ret art_anchors_add pk ART_TRUST_TIER_SEED0B_QUAL 953 end 954 955 note Find trusted anchor by SHA-256 fingerprint; writes 32-byte pk to pk_out and returns tier (or 0) 956 fn art_anchors_find fp view uchar * pk_out edit uchar * to ulong 957 cnt = get art_anchor_cnt 0 958 cand = new uchar 32 0 959 cfp = new uchar 32 0 960 for idx ulong cnt bound 8 961 base = mul idx 32 962 for i ulong 32 963 put cand i get art_anchor_pks add base i 964 end 965 art_signer_fingerprint cand cfp 966 if art_bytes_eq fp cfp 967 for i ulong 32 968 put pk_out i get cand i 969 end 970 ret get art_anchor_tiers idx 971 end 972 end 973 ret ART_TRUST_TIER_NONE 974 end 975 976 note ConfiguredArtifactVerifier::verify 977 fn art_verify bytes view uchar * to int 978 rc = art_parse_and_identify bytes 979 if ne rc ART_OK 980 ret rc 981 end 982 fp = new uchar 32 0 983 for i ulong 32 984 put fp i get art_signer_fp i 985 end 986 pk = new uchar 32 0 987 tier = art_anchors_find fp pk 988 if eq tier ART_TRUST_TIER_NONE 989 ret ART_ERR_UNTRUSTED_SIGNER 990 end 991 chk_fp = new uchar 32 0 992 art_signer_fingerprint pk chk_fp 993 if not art_bytes_eq chk_fp fp 994 ret ART_ERR_UNTRUSTED_SIGNER 995 end 996 aid = new uchar 32 0 997 for i ulong 32 998 put aid i get art_id i 999 end 1000 msg = new uchar 61 0 1001 art_signature_message aid msg 1002 sg = new uchar 64 0 1003 for i ulong 64 1004 put sg i get art_sig i 1005 end 1006 if not art_`ed25519`_verify pk msg sg 1007 ret ART_ERR_BAD_SIGNATURE 1008 end 1009 put art_meta 11 tier 1010 ret ART_OK 1011 end