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
omega-mv / aienux / crates / aienos-artifact-tool / artifact_tool.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note aienux/crates/aienos-artifact-tool/artifact_tool.om: Pure-Omega Binary Artifact v0 |
| 3 | note and Admission Receipt v0 qualification tool (pack, inspect, id, sign, verify, |
| 4 | note negative-corpus H01..H29, receipt inspect/check/from-hex/sign-test/verify, CLI dispatch). |
| 5 | note Converted from aienux crates/aienos-artifact-tool/src/{main,corpus,receipt_cmd}.rs |
| 6 | note and crates/aienos-artifact/src/{format,capability,resource,canonical,id,signature,verify,receipt}.rs. |
| 7 | note Compose with: si/directives/om2.om om/tls/sha2.om aienux/crates/aienos-artifact-tool/artifact_tool.om ... |
| 8 | |
| 9 | note Binary Artifact v0 layout constants (ADR 0014) |
| 10 | const AT_HEADER_SIZE ulong 128 |
| 11 | const AT_SEC_TABLE_OFF ulong 128 |
| 12 | const AT_SEC_COUNT ulong 2 |
| 13 | const AT_SEC_REC_SIZE ulong 32 |
| 14 | const AT_SEC_TABLE_SIZE ulong 64 |
| 15 | const AT_CAP_TABLE_OFF ulong 192 |
| 16 | const AT_CAP_REC_SIZE ulong 48 |
| 17 | const AT_MAX_CAPS ulong 16 |
| 18 | const AT_RES_ENV_SIZE ulong 48 |
| 19 | const AT_SIG_BLOCK_SIZE ulong 100 |
| 20 | const AT_SIG_ALG_ED25519 ulong 1 |
| 21 | const AT_TARGET_AARCH64_LE ulong 1 |
| 22 | const AT_ABI_V1 ulong 1 |
| 23 | const AT_PAGE_SIZE ulong 4096 |
| 24 | const AT_MAX_ARTIFACT_SIZE ulong 16777216 |
| 25 | const AT_MAX_PAYLOAD_SIZE ulong 8388608 |
| 26 | |
| 27 | const AT_SEC_KIND_CODE ulong 1 |
| 28 | const AT_SEC_KIND_DATA ulong 2 |
| 29 | const AT_PERM_RX ulong 5 |
| 30 | const AT_PERM_RW ulong 3 |
| 31 | |
| 32 | const AT_RES_KIND_CHANNEL ulong 2 |
| 33 | const AT_RES_KIND_OBJECT ulong 3 |
| 34 | const AT_VALID_RIGHTS ulong 63 |
| 35 | |
| 36 | const AT_MAX_CODE_PAGES ulong 64 |
| 37 | const AT_MAX_DATA_PAGES ulong 64 |
| 38 | const AT_MAX_STACK_PAGES ulong 16 |
| 39 | const AT_MAX_IPC_MSGS ulong 1024 |
| 40 | const AT_MAX_IPC_BYTES ulong 1048576 |
| 41 | const AT_MAX_TICKS ulong 1000000000 |
| 42 | const AT_MAX_SYSCALLS ulong 65536 |
| 43 | const AT_U64_MAX ulong 0xffffffffffffffff |
| 44 | |
| 45 | note Stable fail-closed ArtifactError codes (ADR 0014 section 7.3) |
| 46 | const AT_OK int 0 |
| 47 | const AT_ERR_BAD_MAGIC int 1 |
| 48 | const AT_ERR_UNSUP_VER int 2 |
| 49 | const AT_ERR_WRONG_TARGET int 3 |
| 50 | const AT_ERR_WRONG_ABI int 4 |
| 51 | const AT_ERR_LEN_OVERFLOW int 5 |
| 52 | const AT_ERR_TRUNCATED int 6 |
| 53 | const AT_ERR_WRONG_LEN int 7 |
| 54 | const AT_ERR_RESERVED_NZ int 8 |
| 55 | const AT_ERR_UNSUP_FLAGS int 9 |
| 56 | const AT_ERR_SEC_OVERLAP int 10 |
| 57 | const AT_ERR_BAD_SECTION int 11 |
| 58 | const AT_ERR_BAD_ENTRY int 12 |
| 59 | const AT_ERR_BAD_CAP int 13 |
| 60 | const AT_ERR_RES_LIMIT int 14 |
| 61 | const AT_ERR_BAD_SIG_FMT int 15 |
| 62 | const AT_ERR_DIGEST_MISMATCH int 16 |
| 63 | const AT_ERR_UNTRUSTED int 17 |
| 64 | const AT_ERR_BAD_SIG int 18 |
| 65 | const AT_ERR_RIGHTS_ESC int 19 |
| 66 | const AT_ERR_BAD_RECEIPT int 20 |
| 67 | |
| 68 | note Tool-level negative error codes |
| 69 | const AT_ERR_USAGE int -1 |
| 70 | const AT_ERR_BAD_HEX int -2 |
| 71 | const AT_ERR_BUF_SMALL int -3 |
| 72 | const AT_ERR_RCP_MUST_UNSIGNED int -4 |
| 73 | const AT_ERR_RCP_ADMIT_BAD_ART int -5 |
| 74 | const AT_ERR_RCP_NZ_BAD_ART int -6 |
| 75 | const AT_ERR_RCP_BIND_MISMATCH int -7 |
| 76 | const AT_ERR_RCP_NO_GRANTS int -8 |
| 77 | const AT_ERR_PROD_SIGN_OFF int -9 |
| 78 | const AT_ERR_PACK_BOUNDS int -10 |
| 79 | const AT_ERR_BAD_CASE int -11 |
| 80 | |
| 81 | const AT_EXIT_TOOL_ERR int 2 |
| 82 | |
| 83 | note Admission Receipt v0 constants (ADR 0014 section 7) |
| 84 | const AT_RCP_SIZE ulong 512 |
| 85 | const AT_RCP_HDR_SIZE ulong 96 |
| 86 | const AT_RCP_SIG_OFF ulong 400 |
| 87 | const AT_RCP_VERSION ulong 0 |
| 88 | const AT_RCP_FLAG_MACHINE_ID ulong 1 |
| 89 | const AT_RCP_FLAG_CONTEXT_ID ulong 2 |
| 90 | const AT_RCP_FLAG_TIMESTAMP ulong 4 |
| 91 | const AT_RCP_VALID_FLAGS ulong 7 |
| 92 | |
| 93 | const AT_RCP_RES_READ_OK ulong 1 |
| 94 | const AT_RCP_RES_WRITE_DENIED ulong 2 |
| 95 | const AT_RCP_RES_RECLAIMED ulong 4 |
| 96 | const AT_RCP_RES_CANARY_OK ulong 8 |
| 97 | const AT_RCP_RES_FORGED_DENIED ulong 16 |
| 98 | const AT_RCP_RES_MAPPED_MATCH ulong 32 |
| 99 | const AT_RCP_RES_EXEC_MATCH ulong 64 |
| 100 | const AT_RCP_RES_WX_SEALED ulong 128 |
| 101 | const AT_RCP_VALID_RES_FLAGS ulong 255 |
| 102 | |
| 103 | const AT_DEC_ADMITTED ulong 1 |
| 104 | const AT_DEC_REJECTED ulong 2 |
| 105 | const AT_DEC_CANARY_FAILED ulong 3 |
| 106 | const AT_DEC_DESTROYED ulong 4 |
| 107 | |
| 108 | const AT_TIER_QEMU ulong 1 |
| 109 | const AT_TIER_MACHINE1 ulong 2 |
| 110 | const AT_TIER_PI5 ulong 3 |
| 111 | |
| 112 | const AT_EXEC_NOT_RUN ulong 0 |
| 113 | const AT_EXEC_EXITED ulong 1 |
| 114 | const AT_EXEC_TIMEOUT ulong 2 |
| 115 | const AT_EXEC_FAULT ulong 3 |
| 116 | const AT_EXEC_BAD_SYSCALL ulong 4 |
| 117 | const AT_EXEC_RES_OVERRUN ulong 5 |
| 118 | const AT_EXEC_CANARY_FAILED ulong 6 |
| 119 | |
| 120 | const AT_MAX_REJ_STAGE ulong 9 |
| 121 | const AT_LOADER_REASON_FIRST ulong 257 |
| 122 | const AT_LOADER_REASON_LAST ulong 266 |
| 123 | |
| 124 | note CLI command dispatch IDs |
| 125 | const AT_CMD_INVALID int 0 |
| 126 | const AT_CMD_PACK int 1 |
| 127 | const AT_CMD_INSPECT int 2 |
| 128 | const AT_CMD_ID int 3 |
| 129 | const AT_CMD_SIGN int 4 |
| 130 | const AT_CMD_VERIFY int 5 |
| 131 | const AT_CMD_NEG_CORPUS int 6 |
| 132 | const AT_CMD_RCP_INSPECT int 10 |
| 133 | const AT_CMD_RCP_CHECK int 11 |
| 134 | const AT_CMD_RCP_FROM_HEX int 12 |
| 135 | const AT_CMD_RCP_SIGN_TEST int 13 |
| 136 | const AT_CMD_RCP_VERIFY int 14 |
| 137 | |
| 138 | note Negative corpus constants (P2-7 H01..H29) |
| 139 | const AT_CORPUS_COUNT ulong 29 |
| 140 | const AT_EXP_REJ_VERIFIED ulong 1 |
| 141 | const AT_EXP_REJ_AUTHORIZED ulong 2 |
| 142 | const AT_EXP_ADMITTED ulong 3 |
| 143 | |
| 144 | const AT_CORPUS_EXEC_NONE ulong 0 |
| 145 | const AT_CORPUS_EXEC_EXIT0 ulong 1 |
| 146 | const AT_CORPUS_EXEC_NX ulong 2 |
| 147 | const AT_CORPUS_EXEC_BAD_SYS99 ulong 3 |
| 148 | const AT_CORPUS_EXEC_OVERRUN ulong 4 |
| 149 | |
| 150 | note AArch64 instruction words for negative corpus payloads (corpus.rs) |
| 151 | const AT_INSN_MOV_X0_0 ulong 0xd2800000 |
| 152 | const AT_INSN_MOV_X8_2 ulong 0xd2800048 |
| 153 | const AT_INSN_MOV_X8_6 ulong 0xd28000c8 |
| 154 | const AT_INSN_MOV_X8_99 ulong 0xd2800c68 |
| 155 | const AT_INSN_SVC_0 ulong 0xd4000001 |
| 156 | const AT_INSN_B_SELF ulong 0x14000000 |
| 157 | const AT_INSN_BR_X2 ulong 0xd61f0040 |
| 158 | const AT_INSN_SUB_X9_SP_16 ulong 0xd10043e9 |
| 159 | const AT_INSN_BR_X9 ulong 0xd61f0120 |
| 160 | |
| 161 | note ASCII prefixes (trailing NUL byte appended explicitly where required) |
| 162 | text at_art_magic "AIENART" |
| 163 | text at_rcp_magic "AIENRCP" |
| 164 | text at_dom_art_id "AIENOS-ARTIFACT-V1" |
| 165 | text at_dom_art_sig "AIENOS-ARTIFACT-SIGNATURE-V1" |
| 166 | text at_dom_req_caps "AIENOS-ARTIFACT-CAP-REQUESTS-V1" |
| 167 | text at_dom_res_env "AIENOS-ARTIFACT-RESOURCES-V1" |
| 168 | text at_dom_rcp_dig "AIENOS-ADMISSION-RECEIPT-V1" |
| 169 | text at_dom_rcp_nonce "AIENOS-ADMISSION-RECEIPT-NONCE-V1" |
| 170 | text at_dom_rcp_sig "AIENOS-ADMISSION-RECEIPT-SIGNATURE-V1" |
| 171 | text at_hex_chars "0123456789abcdef" |
| 172 | |
| 173 | note CLI command keyword tables |
| 174 | text at_kw_pack "pack" |
| 175 | text at_kw_inspect "inspect" |
| 176 | text at_kw_id "id" |
| 177 | text at_kw_sign "sign" |
| 178 | text at_kw_verify "verify" |
| 179 | text at_kw_receipt "receipt" |
| 180 | text at_kw_neg_corpus "negative-corpus" |
| 181 | text at_kw_check "check" |
| 182 | text at_kw_from_hex "from-hex" |
| 183 | text at_kw_sign_test "sign-test" |
| 184 | |
| 185 | note Corpus static data tags |
| 186 | text at_tag_baseline "BASELINE" |
| 187 | text at_tag_largest "LARGEST!" |
| 188 | text at_tag_datapage "DATAPAGE" |
| 189 | text at_tag_stackpag "STACKPAG" |
| 190 | text at_tag_badsyscl "BADSYSCL" |
| 191 | text at_tag_overrun "OVERRUN!" |
| 192 | text at_tag_ipcwants "IPCWANTS" |
| 193 | text at_tag_writereq "WRITEREQ" |
| 194 | text at_tag_rwrequst "RWREQUST" |
| 195 | |
| 196 | note Manifest staging globals for at_pack |
| 197 | global at_man_entry ulong 1 |
| 198 | global at_man_cap_cnt ulong 1 |
| 199 | note 16 caps x 8 ulongs: kind, id, rights, bounds_kind, max_ops, max_bytes, byte_off, byte_len |
| 200 | global at_man_caps ulong 128 |
| 201 | note 9 resource fields: code_p, data_p, stack_p, max_caps, ipc_m, ipc_b, cpu_t, elap_t, sys_c |
| 202 | global at_man_res ulong 9 |
| 203 | global at_pack_len ulong 1 |
| 204 | |
| 205 | note Parsed artifact view globals (populated by at_parse / at_parse_and_identify) |
| 206 | note 0=total_len, 1=entry_off, 2=cap_cnt, 3=res_off, 4=pay_off, 5=pay_len, 6=sig_off, |
| 207 | note 7=code_len, 8=data_off, 9=data_len, 10=data_mem_len, 11=sig_alg |
| 208 | global at_art_meta ulong 12 |
| 209 | global at_art_id uchar 32 |
| 210 | global at_art_payload_sha uchar 32 |
| 211 | global at_art_signer_fp uchar 32 |
| 212 | global at_art_req_caps_sha uchar 32 |
| 213 | global at_art_res_env_sha uchar 32 |
| 214 | |
| 215 | note Staged / decoded Admission Receipt v0 globals |
| 216 | note 0=flags, 1=decision, 2=tier, 3=seq, 4=time_ns, 5=exec_st, 6=exit_st, 7=res_flags, |
| 217 | note 8=rej_stage, 9=rej_reason, 10=syscalls, 11=reads_ok, 12=denials, 13=frames, |
| 218 | note 14=generation, 15=context_id |
| 219 | global at_rcp_f ulong 16 |
| 220 | global at_rcp_nonce_buf uchar 16 |
| 221 | note 9 digests x 32 bytes = 288 bytes: |
| 222 | note 0=artifact_id, 1=payload, 2=signer, 3=policy, 4=req_caps, 5=grant_caps, |
| 223 | note 6=res_env, 7=verifier_id, 8=machine_id |
| 224 | global at_rcp_digests uchar 288 |
| 225 | global at_rcp_dig_out uchar 32 |
| 226 | global at_rcp_signed_flag ulong 1 |
| 227 | |
| 228 | note Corpus build and expectation outputs |
| 229 | global at_corpus_len ulong 1 |
| 230 | note 0=expect_kind, 1=expected_code, 2=expected_exec, 3=expected_caps |
| 231 | global at_corpus_exp ulong 4 |
| 232 | |
| 233 | note Little-endian integer helpers |
| 234 | fn at_put_u16_le buf edit uchar * off ulong v ulong to void |
| 235 | put buf off uchar and v 0xff |
| 236 | put buf add off 1 uchar and shr v 8 0xff |
| 237 | end |
| 238 | |
| 239 | fn at_put_u32_le buf edit uchar * off ulong v ulong to void |
| 240 | put buf off uchar and v 0xff |
| 241 | put buf add off 1 uchar and shr v 8 0xff |
| 242 | put buf add off 2 uchar and shr v 16 0xff |
| 243 | put buf add off 3 uchar and shr v 24 0xff |
| 244 | end |
| 245 | |
| 246 | fn at_put_u64_le buf edit uchar * off ulong v ulong to void |
| 247 | for i ulong 8 |
| 248 | put buf add off i uchar and shr v mul i 8 0xff |
| 249 | end |
| 250 | end |
| 251 | |
| 252 | fn at_get_u16_le buf view uchar * off ulong to ulong |
| 253 | b0 = ulong get buf off |
| 254 | b1 = ulong get buf add off 1 |
| 255 | ret or b0 shl b1 8 |
| 256 | end |
| 257 | |
| 258 | fn at_get_u32_le buf view uchar * off ulong to ulong |
| 259 | b0 = ulong get buf off |
| 260 | b1 = ulong get buf add off 1 |
| 261 | b2 = ulong get buf add off 2 |
| 262 | b3 = ulong get buf add off 3 |
| 263 | ret or or b0 shl b1 8 or shl b2 16 shl b3 24 |
| 264 | end |
| 265 | |
| 266 | fn at_get_u64_le buf view uchar * off ulong to ulong |
| 267 | acc = ulong 0 |
| 268 | for i ulong 8 |
| 269 | b = ulong get buf add off i |
| 270 | acc = or acc shl b mul i 8 |
| 271 | end |
| 272 | ret acc |
| 273 | end |
| 274 | |
| 275 | fn at_align_up_16 v ulong to ulong |
| 276 | ret and add v 15 not ulong 15 |
| 277 | end |
| 278 | |
| 279 | fn at_bytes_zero buf view uchar * off ulong cnt ulong to bool |
| 280 | for i ulong cnt bound 4096 |
| 281 | if ne get buf add off i 0 |
| 282 | ret false |
| 283 | end |
| 284 | end |
| 285 | ret true |
| 286 | end |
| 287 | |
| 288 | fn at_bytes_eq a view uchar * b view uchar * to bool |
| 289 | if ne len a len b |
| 290 | ret false |
| 291 | end |
| 292 | for i ulong len a bound 4096 |
| 293 | if ne get a i get b i |
| 294 | ret false |
| 295 | end |
| 296 | end |
| 297 | ret true |
| 298 | end |
| 299 | |
| 300 | note Lowercase hex encoding (2 chars per byte) |
| 301 | fn at_hex_encode src view uchar * dst edit uchar * to int |
| 302 | n = len src |
| 303 | if lt len dst mul n 2 |
| 304 | ret AT_ERR_BUF_SMALL |
| 305 | end |
| 306 | for i ulong n bound 1024 |
| 307 | b = ulong get src i |
| 308 | hi = shr b 4 |
| 309 | lo = and b 0x0f |
| 310 | put dst mul i 2 get at_hex_chars hi |
| 311 | put dst add mul i 2 1 get at_hex_chars lo |
| 312 | end |
| 313 | ret AT_OK |
| 314 | end |
| 315 | |
| 316 | fn at_hex_nibble ch uchar to int |
| 317 | v = ulong ch |
| 318 | if ge v 48 |
| 319 | if le v 57 |
| 320 | ret int sub v 48 |
| 321 | end |
| 322 | end |
| 323 | if ge v 97 |
| 324 | if le v 102 |
| 325 | ret int add sub v 97 10 |
| 326 | end |
| 327 | end |
| 328 | ret -1 |
| 329 | end |
| 330 | |
| 331 | fn at_is_ws ch uchar to bool |
| 332 | if eq ch 32 |
| 333 | ret true |
| 334 | end |
| 335 | if eq ch 9 |
| 336 | ret true |
| 337 | end |
| 338 | if eq ch 10 |
| 339 | ret true |
| 340 | end |
| 341 | if eq ch 13 |
| 342 | ret true |
| 343 | end |
| 344 | ret false |
| 345 | end |
| 346 | |
| 347 | fn at_rcp_decode_hex_body hex_in view uchar * start ulong dst edit uchar * to int |
| 348 | for i ulong AT_RCP_SIZE |
| 349 | pos = add start mul i 2 |
| 350 | hi = at_hex_nibble get hex_in pos |
| 351 | lo = at_hex_nibble get hex_in add pos 1 |
| 352 | if lt hi 0 |
| 353 | ret AT_ERR_BAD_HEX |
| 354 | end |
| 355 | if lt lo 0 |
| 356 | ret AT_ERR_BAD_HEX |
| 357 | end |
| 358 | b = or shl ulong hi 4 ulong lo |
| 359 | put dst i uchar b |
| 360 | end |
| 361 | ret AT_OK |
| 362 | end |
| 363 | |
| 364 | note Strict lowercase hex decoder (matches receipt_cmd.rs::from_hex) |
| 365 | fn at_rcp_from_hex hex_in view uchar * dst edit uchar * to int |
| 366 | if lt len dst AT_RCP_SIZE |
| 367 | ret AT_ERR_BUF_SMALL |
| 368 | end |
| 369 | n = len hex_in |
| 370 | start = ulong 0 |
| 371 | while lt start n bound 4096 |
| 372 | if not at_is_ws get hex_in start |
| 373 | break |
| 374 | end |
| 375 | start = add start 1 |
| 376 | end |
| 377 | endp = n |
| 378 | while gt endp start bound 4096 |
| 379 | if not at_is_ws get hex_in sub endp 1 |
| 380 | break |
| 381 | end |
| 382 | endp = sub endp 1 |
| 383 | end |
| 384 | if ne sub endp start mul AT_RCP_SIZE 2 |
| 385 | ret AT_ERR_BAD_HEX |
| 386 | end |
| 387 | ret at_rcp_decode_hex_body hex_in start dst |
| 388 | end |
| 389 | |
| 390 | note Domain-separated SHA-256 helper: SHA256(dom || 0x00 || payload) |
| 391 | fn at_sha256_dom_nul dom view uchar * msg view uchar * dst edit uchar * to void |
| 392 | ctx = new ulong 40 0 |
| 393 | z = new uchar 1 0 |
| 394 | sha256_init ctx |
| 395 | sha256_update ctx dom |
| 396 | sha256_update ctx z |
| 397 | sha256_update ctx msg |
| 398 | sha256_final ctx dst |
| 399 | end |
| 400 | |
| 401 | note RFC 8032 TEST 1 seed (SEED-0B test-only artifact identity; never a production secret) |
| 402 | fn at_fill_test_art_key dst edit uchar * to void |
| 403 | put dst 0 0x9d |
| 404 | put dst 1 0x61 |
| 405 | put dst 2 0xb1 |
| 406 | put dst 3 0x9d |
| 407 | put dst 4 0xef |
| 408 | put dst 5 0xfd |
| 409 | put dst 6 0x5a |
| 410 | put dst 7 0x60 |
| 411 | put dst 8 0xba |
| 412 | put dst 9 0x84 |
| 413 | put dst 10 0x4a |
| 414 | put dst 11 0xf4 |
| 415 | put dst 12 0x92 |
| 416 | put dst 13 0xec |
| 417 | put dst 14 0x2c |
| 418 | put dst 15 0xc4 |
| 419 | put dst 16 0x44 |
| 420 | put dst 17 0x49 |
| 421 | put dst 18 0xc5 |
| 422 | put dst 19 0x69 |
| 423 | put dst 20 0x7b |
| 424 | put dst 21 0x32 |
| 425 | put dst 22 0x69 |
| 426 | put dst 23 0x19 |
| 427 | put dst 24 0x70 |
| 428 | put dst 25 0x3b |
| 429 | put dst 26 0xac |
| 430 | put dst 27 0x03 |
| 431 | put dst 28 0x1c |
| 432 | put dst 29 0xae |
| 433 | put dst 30 0x7f |
| 434 | put dst 31 0x60 |
| 435 | end |
| 436 | |
| 437 | note RFC 8032 TEST 3 seed (untrusted signer for corpus H15) |
| 438 | fn at_fill_untrusted_key dst edit uchar * to void |
| 439 | put dst 0 0xc5 |
| 440 | put dst 1 0xaa |
| 441 | put dst 2 0x8d |
| 442 | put dst 3 0xf4 |
| 443 | put dst 4 0x3f |
| 444 | put dst 5 0x9f |
| 445 | put dst 6 0x83 |
| 446 | put dst 7 0x7b |
| 447 | put dst 8 0xed |
| 448 | put dst 9 0xb7 |
| 449 | put dst 10 0x44 |
| 450 | put dst 11 0x2f |
| 451 | put dst 12 0x31 |
| 452 | put dst 13 0xdc |
| 453 | put dst 14 0xb7 |
| 454 | put dst 15 0xb1 |
| 455 | put dst 16 0x66 |
| 456 | put dst 17 0xd3 |
| 457 | put dst 18 0x85 |
| 458 | put dst 19 0x35 |
| 459 | put dst 20 0x07 |
| 460 | put dst 21 0x6f |
| 461 | put dst 22 0x09 |
| 462 | put dst 23 0x4b |
| 463 | put dst 24 0x85 |
| 464 | put dst 25 0xce |
| 465 | put dst 26 0x3a |
| 466 | put dst 27 0x2e |
| 467 | put dst 28 0x0b |
| 468 | put dst 29 0x44 |
| 469 | put dst 30 0x58 |
| 470 | put dst 31 0xf7 |
| 471 | end |
| 472 | |
| 473 | note RFC 8032 TEST 2 seed (SEED-0B test-only receipt identity; distinct from artifact key) |
| 474 | fn at_fill_test_rcp_key dst edit uchar * to void |
| 475 | put dst 0 0x4c |
| 476 | put dst 1 0xcd |
| 477 | put dst 2 0x08 |
| 478 | put dst 3 0x9b |
| 479 | put dst 4 0x28 |
| 480 | put dst 5 0xff |
| 481 | put dst 6 0x96 |
| 482 | put dst 7 0xda |
| 483 | put dst 8 0x9d |
| 484 | put dst 9 0xb6 |
| 485 | put dst 10 0xc3 |
| 486 | put dst 11 0x46 |
| 487 | put dst 12 0xec |
| 488 | put dst 13 0x11 |
| 489 | put dst 14 0x4e |
| 490 | put dst 15 0x0f |
| 491 | put dst 16 0x5b |
| 492 | put dst 17 0x8a |
| 493 | put dst 18 0x31 |
| 494 | put dst 19 0x9f |
| 495 | put dst 20 0x35 |
| 496 | put dst 21 0xab |
| 497 | put dst 22 0xa6 |
| 498 | put dst 23 0x24 |
| 499 | put dst 24 0xda |
| 500 | put dst 25 0x8c |
| 501 | put dst 26 0xf6 |
| 502 | put dst 27 0xed |
| 503 | put dst 28 0x4f |
| 504 | put dst 29 0xb8 |
| 505 | put dst 30 0xa6 |
| 506 | put dst 31 0xfb |
| 507 | end |
| 508 | |
| 509 | note Signer fingerprint: SHA256(key[32]) |
| 510 | fn at_signer_fp key view uchar * fp_dst edit uchar * to void |
| 511 | ctx = new ulong 40 0 |
| 512 | sha256_init ctx |
| 513 | sha256_update ctx key |
| 514 | sha256_final ctx fp_dst |
| 515 | end |
| 516 | |
| 517 | note Deterministic 64-byte keyed SHA-256 signature over (dom || 0x00 || dig[32]) |
| 518 | fn at_compute_sig key view uchar 32 dom view uchar * dig view uchar 32 sig_dst edit uchar 64 to void |
| 519 | ctx = new ulong 40 0 |
| 520 | z = new uchar 1 0 |
| 521 | tag = new uchar 1 1 |
| 522 | half = new uchar 32 0 |
| 523 | sha256_init ctx |
| 524 | sha256_update ctx key |
| 525 | sha256_update ctx dom |
| 526 | sha256_update ctx z |
| 527 | sha256_update ctx dig |
| 528 | sha256_update ctx tag |
| 529 | sha256_final ctx half |
| 530 | for i ulong 32 |
| 531 | put sig_dst i get half i |
| 532 | end |
| 533 | put tag 0 2 |
| 534 | sha256_init ctx |
| 535 | sha256_update ctx key |
| 536 | sha256_update ctx dom |
| 537 | sha256_update ctx z |
| 538 | sha256_update ctx dig |
| 539 | sha256_update ctx tag |
| 540 | sha256_final ctx half |
| 541 | for i ulong 32 |
| 542 | put sig_dst add 32 i get half i |
| 543 | end |
| 544 | end |
| 545 | |
| 546 | note Manifest staging helpers |
| 547 | fn at_manifest_reset to void |
| 548 | put at_man_entry 0 0 |
| 549 | put at_man_cap_cnt 0 0 |
| 550 | for i ulong 9 |
| 551 | put at_man_res i 0 |
| 552 | end |
| 553 | end |
| 554 | |
| 555 | fn at_manifest_set_entry entry ulong to void |
| 556 | put at_man_entry 0 entry |
| 557 | end |
| 558 | |
| 559 | fn at_manifest_set_res_pages code_p ulong data_p ulong stack_p ulong max_caps ulong to void |
| 560 | put at_man_res 0 code_p |
| 561 | put at_man_res 1 data_p |
| 562 | put at_man_res 2 stack_p |
| 563 | put at_man_res 3 max_caps |
| 564 | end |
| 565 | |
| 566 | fn at_manifest_set_res_limits ipc_m ulong ipc_b ulong cpu_t ulong elap_t ulong sys_c ulong to void |
| 567 | put at_man_res 4 ipc_m |
| 568 | put at_man_res 5 ipc_b |
| 569 | put at_man_res 6 cpu_t |
| 570 | put at_man_res 7 elap_t |
| 571 | put at_man_res 8 sys_c |
| 572 | end |
| 573 | |
| 574 | fn at_manifest_push_cap kind ulong rid ulong rights ulong bkind ulong max_ops ulong to int |
| 575 | cnt = get at_man_cap_cnt 0 |
| 576 | if ge cnt AT_MAX_CAPS |
| 577 | ret -1 |
| 578 | end |
| 579 | base = mul cnt 8 |
| 580 | put at_man_caps base kind |
| 581 | put at_man_caps add base 1 rid |
| 582 | put at_man_caps add base 2 rights |
| 583 | put at_man_caps add base 3 bkind |
| 584 | put at_man_caps add base 4 max_ops |
| 585 | put at_man_caps add base 5 0 |
| 586 | put at_man_caps add base 6 0 |
| 587 | put at_man_caps add base 7 0 |
| 588 | put at_man_cap_cnt 0 add cnt 1 |
| 589 | ret int cnt |
| 590 | end |
| 591 | |
| 592 | fn at_manifest_set_cap_bounds idx ulong max_b ulong boff ulong blen ulong to void |
| 593 | base = mul idx 8 |
| 594 | put at_man_caps add base 5 max_b |
| 595 | put at_man_caps add base 6 boff |
| 596 | put at_man_caps add base 7 blen |
| 597 | end |
| 598 | |
| 599 | note Section and resource envelope encoders |
| 600 | fn at_encode_section dst edit uchar * off ulong kind ulong perms ulong pay_rel ulong to void |
| 601 | at_put_u16_le dst off kind |
| 602 | at_put_u16_le dst add off 2 perms |
| 603 | at_put_u32_le dst add off 8 pay_rel |
| 604 | at_put_u32_le dst add off 20 AT_PAGE_SIZE |
| 605 | end |
| 606 | |
| 607 | fn at_encode_resources dst edit uchar * off ulong to void |
| 608 | at_put_u32_le dst off get at_man_res 0 |
| 609 | at_put_u32_le dst add off 4 get at_man_res 1 |
| 610 | at_put_u32_le dst add off 8 get at_man_res 2 |
| 611 | at_put_u16_le dst add off 12 get at_man_res 3 |
| 612 | at_put_u32_le dst add off 16 get at_man_res 4 |
| 613 | at_put_u32_le dst add off 20 get at_man_res 5 |
| 614 | at_put_u64_le dst add off 24 get at_man_res 6 |
| 615 | at_put_u64_le dst add off 32 get at_man_res 7 |
| 616 | at_put_u32_le dst add off 40 get at_man_res 8 |
| 617 | end |
| 618 | |
| 619 | fn at_encode_staged_caps dst edit uchar * cnt ulong to void |
| 620 | for i ulong cnt bound 16 |
| 621 | base = mul i 8 |
| 622 | off = add AT_CAP_TABLE_OFF mul i AT_CAP_REC_SIZE |
| 623 | at_put_u16_le dst off get at_man_caps base |
| 624 | at_put_u32_le dst add off 4 get at_man_caps add base 1 |
| 625 | at_put_u32_le dst add off 8 get at_man_caps add base 2 |
| 626 | at_put_u32_le dst add off 12 get at_man_caps add base 3 |
| 627 | at_put_u32_le dst add off 16 get at_man_caps add base 4 |
| 628 | at_put_u64_le dst add off 24 get at_man_caps add base 5 |
| 629 | at_put_u64_le dst add off 32 get at_man_caps add base 6 |
| 630 | at_put_u64_le dst add off 40 get at_man_caps add base 7 |
| 631 | end |
| 632 | end |
| 633 | |
| 634 | note Binary Artifact v0 strict parser (format.rs, capability.rs, resource.rs) |
| 635 | fn at_parse_magic bytes view uchar * to bool |
| 636 | for i ulong 7 |
| 637 | if ne get bytes i get at_art_magic i |
| 638 | ret false |
| 639 | end |
| 640 | end |
| 641 | if ne get bytes 7 0 |
| 642 | ret false |
| 643 | end |
| 644 | ret true |
| 645 | end |
| 646 | |
| 647 | fn at_parse_header bytes view uchar * to int |
| 648 | n = len bytes |
| 649 | if lt n AT_HEADER_SIZE |
| 650 | ret AT_ERR_TRUNCATED |
| 651 | end |
| 652 | if gt n AT_MAX_ARTIFACT_SIZE |
| 653 | ret AT_ERR_RES_LIMIT |
| 654 | end |
| 655 | if not at_parse_magic bytes |
| 656 | ret AT_ERR_BAD_MAGIC |
| 657 | end |
| 658 | if ne at_get_u16_le bytes 8 0 |
| 659 | ret AT_ERR_UNSUP_VER |
| 660 | end |
| 661 | if ne at_get_u16_le bytes 10 AT_HEADER_SIZE |
| 662 | ret AT_ERR_UNSUP_VER |
| 663 | end |
| 664 | if ne at_get_u16_le bytes 12 AT_TARGET_AARCH64_LE |
| 665 | ret AT_ERR_WRONG_TARGET |
| 666 | end |
| 667 | if ne at_get_u16_le bytes 14 AT_ABI_V1 |
| 668 | ret AT_ERR_WRONG_ABI |
| 669 | end |
| 670 | if ne at_get_u32_le bytes 16 0 |
| 671 | ret AT_ERR_UNSUP_FLAGS |
| 672 | end |
| 673 | total_len = at_get_u32_le bytes 20 |
| 674 | if ne total_len n |
| 675 | ret AT_ERR_WRONG_LEN |
| 676 | end |
| 677 | put at_art_meta 0 total_len |
| 678 | ret AT_OK |
| 679 | end |
| 680 | |
| 681 | fn at_parse_header_tables bytes view uchar * to int |
| 682 | if ne at_get_u32_le bytes 24 AT_SEC_TABLE_OFF |
| 683 | ret AT_ERR_UNSUP_VER |
| 684 | end |
| 685 | if ne at_get_u16_le bytes 28 AT_SEC_COUNT |
| 686 | ret AT_ERR_UNSUP_VER |
| 687 | end |
| 688 | if ne at_get_u16_le bytes 30 AT_SEC_REC_SIZE |
| 689 | ret AT_ERR_UNSUP_VER |
| 690 | end |
| 691 | if ne at_get_u16_le bytes 32 0 |
| 692 | ret AT_ERR_UNSUP_VER |
| 693 | end |
| 694 | if ne at_get_u16_le bytes 34 0 |
| 695 | ret AT_ERR_UNSUP_VER |
| 696 | end |
| 697 | if ne at_get_u32_le bytes 40 AT_CAP_TABLE_OFF |
| 698 | ret AT_ERR_UNSUP_VER |
| 699 | end |
| 700 | if ne at_get_u16_le bytes 46 AT_CAP_REC_SIZE |
| 701 | ret AT_ERR_UNSUP_VER |
| 702 | end |
| 703 | if ne at_get_u16_le bytes 52 AT_RES_ENV_SIZE |
| 704 | ret AT_ERR_UNSUP_VER |
| 705 | end |
| 706 | if ne at_get_u16_le bytes 54 0 |
| 707 | ret AT_ERR_UNSUP_VER |
| 708 | end |
| 709 | if not at_bytes_zero bytes 72 56 |
| 710 | ret AT_ERR_RESERVED_NZ |
| 711 | end |
| 712 | put at_art_meta 1 at_get_u32_le bytes 36 |
| 713 | ret AT_OK |
| 714 | end |
| 715 | |
| 716 | fn at_parse_offsets_sig bytes view uchar * to int |
| 717 | total_len = get at_art_meta 0 |
| 718 | pay_off = get at_art_meta 4 |
| 719 | pay_len = at_get_u32_le bytes 60 |
| 720 | if gt pay_len AT_MAX_PAYLOAD_SIZE |
| 721 | ret AT_ERR_RES_LIMIT |
| 722 | end |
| 723 | sig_off = at_get_u32_le bytes 64 |
| 724 | sig_len = at_get_u16_le bytes 68 |
| 725 | sig_alg = at_get_u16_le bytes 70 |
| 726 | if ne sig_len AT_SIG_BLOCK_SIZE |
| 727 | ret AT_ERR_BAD_SIG_FMT |
| 728 | end |
| 729 | if ne sig_alg AT_SIG_ALG_ED25519 |
| 730 | ret AT_ERR_BAD_SIG_FMT |
| 731 | end |
| 732 | if ne sig_off add pay_off pay_len |
| 733 | ret AT_ERR_SEC_OVERLAP |
| 734 | end |
| 735 | if ne add sig_off AT_SIG_BLOCK_SIZE total_len |
| 736 | ret AT_ERR_WRONG_LEN |
| 737 | end |
| 738 | put at_art_meta 5 pay_len |
| 739 | put at_art_meta 6 sig_off |
| 740 | put at_art_meta 11 sig_alg |
| 741 | ret AT_OK |
| 742 | end |
| 743 | |
| 744 | fn at_parse_offsets bytes view uchar * to int |
| 745 | total_len = get at_art_meta 0 |
| 746 | cap_cnt = at_get_u16_le bytes 44 |
| 747 | if gt cap_cnt AT_MAX_CAPS |
| 748 | ret AT_ERR_RES_LIMIT |
| 749 | end |
| 750 | cap_end = add AT_CAP_TABLE_OFF mul cap_cnt AT_CAP_REC_SIZE |
| 751 | res_off = at_get_u32_le bytes 48 |
| 752 | if ne res_off cap_end |
| 753 | ret AT_ERR_SEC_OVERLAP |
| 754 | end |
| 755 | res_end = add res_off AT_RES_ENV_SIZE |
| 756 | exp_pay = at_align_up_16 res_end |
| 757 | pay_off = at_get_u32_le bytes 56 |
| 758 | if ne pay_off exp_pay |
| 759 | ret AT_ERR_SEC_OVERLAP |
| 760 | end |
| 761 | if gt pay_off total_len |
| 762 | ret AT_ERR_TRUNCATED |
| 763 | end |
| 764 | if not at_bytes_zero bytes res_end sub pay_off res_end |
| 765 | ret AT_ERR_RESERVED_NZ |
| 766 | end |
| 767 | put at_art_meta 2 cap_cnt |
| 768 | put at_art_meta 3 res_off |
| 769 | put at_art_meta 4 pay_off |
| 770 | ret at_parse_offsets_sig bytes |
| 771 | end |
| 772 | |
| 773 | fn at_parse_sections bytes view uchar * to int |
| 774 | pay_len = get at_art_meta 5 |
| 775 | if ne at_get_u32_le bytes 132 0 |
| 776 | ret AT_ERR_RESERVED_NZ |
| 777 | end |
| 778 | if not at_bytes_zero bytes 152 8 |
| 779 | ret AT_ERR_RESERVED_NZ |
| 780 | end |
| 781 | if ne at_get_u32_le bytes 164 0 |
| 782 | ret AT_ERR_RESERVED_NZ |
| 783 | end |
| 784 | if not at_bytes_zero bytes 184 8 |
| 785 | ret AT_ERR_RESERVED_NZ |
| 786 | end |
| 787 | c_flen = at_get_u32_le bytes 140 |
| 788 | c_mlen = at_get_u32_le bytes 144 |
| 789 | if ne at_get_u16_le bytes 128 AT_SEC_KIND_CODE |
| 790 | ret AT_ERR_BAD_SECTION |
| 791 | end |
| 792 | if ne at_get_u16_le bytes 130 AT_PERM_RX |
| 793 | ret AT_ERR_BAD_SECTION |
| 794 | end |
| 795 | if ne at_get_u32_le bytes 136 0 |
| 796 | ret AT_ERR_BAD_SECTION |
| 797 | end |
| 798 | if eq c_flen 0 |
| 799 | ret AT_ERR_BAD_SECTION |
| 800 | end |
| 801 | if ne c_mlen c_flen |
| 802 | ret AT_ERR_BAD_SECTION |
| 803 | end |
| 804 | if ne at_get_u32_le bytes 148 AT_PAGE_SIZE |
| 805 | ret AT_ERR_BAD_SECTION |
| 806 | end |
| 807 | d_rel = at_get_u32_le bytes 168 |
| 808 | d_flen = at_get_u32_le bytes 172 |
| 809 | d_mlen = at_get_u32_le bytes 176 |
| 810 | if ne at_get_u16_le bytes 160 AT_SEC_KIND_DATA |
| 811 | ret AT_ERR_BAD_SECTION |
| 812 | end |
| 813 | if ne at_get_u16_le bytes 162 AT_PERM_RW |
| 814 | ret AT_ERR_BAD_SECTION |
| 815 | end |
| 816 | if ne d_rel c_flen |
| 817 | ret AT_ERR_BAD_SECTION |
| 818 | end |
| 819 | if eq d_flen 0 |
| 820 | ret AT_ERR_BAD_SECTION |
| 821 | end |
| 822 | if lt d_mlen d_flen |
| 823 | ret AT_ERR_BAD_SECTION |
| 824 | end |
| 825 | if ne at_get_u32_le bytes 180 AT_PAGE_SIZE |
| 826 | ret AT_ERR_BAD_SECTION |
| 827 | end |
| 828 | if ne add c_flen d_flen pay_len |
| 829 | ret AT_ERR_SEC_OVERLAP |
| 830 | end |
| 831 | put at_art_meta 7 c_flen |
| 832 | put at_art_meta 8 d_rel |
| 833 | put at_art_meta 9 d_flen |
| 834 | put at_art_meta 10 d_mlen |
| 835 | ret AT_OK |
| 836 | end |
| 837 | |
| 838 | fn at_validate_cap_bounds bytes view uchar * off ulong kind ulong bkind ulong to int |
| 839 | max_b = at_get_u64_le bytes add off 24 |
| 840 | boff = at_get_u64_le bytes add off 32 |
| 841 | blen = at_get_u64_le bytes add off 40 |
| 842 | if eq max_b 0 |
| 843 | ret AT_ERR_BAD_CAP |
| 844 | end |
| 845 | if eq kind AT_RES_KIND_OBJECT |
| 846 | if ne bkind 1 |
| 847 | ret AT_ERR_BAD_CAP |
| 848 | end |
| 849 | if gt blen sub AT_U64_MAX boff |
| 850 | ret AT_ERR_LEN_OVERFLOW |
| 851 | end |
| 852 | if eq blen 0 |
| 853 | ret AT_ERR_BAD_CAP |
| 854 | end |
| 855 | if gt max_b blen |
| 856 | ret AT_ERR_BAD_CAP |
| 857 | end |
| 858 | ret AT_OK |
| 859 | end |
| 860 | if ne bkind 2 |
| 861 | ret AT_ERR_BAD_CAP |
| 862 | end |
| 863 | if ne boff 0 |
| 864 | ret AT_ERR_BAD_CAP |
| 865 | end |
| 866 | if ne blen 0 |
| 867 | ret AT_ERR_BAD_CAP |
| 868 | end |
| 869 | ret AT_OK |
| 870 | end |
| 871 | |
| 872 | fn at_validate_one_cap bytes view uchar * off ulong to int |
| 873 | if ne at_get_u16_le bytes add off 2 0 |
| 874 | ret AT_ERR_RESERVED_NZ |
| 875 | end |
| 876 | if ne at_get_u32_le bytes add off 20 0 |
| 877 | ret AT_ERR_RESERVED_NZ |
| 878 | end |
| 879 | kind = at_get_u16_le bytes off |
| 880 | rid = at_get_u32_le bytes add off 4 |
| 881 | rights = at_get_u32_le bytes add off 8 |
| 882 | bkind = at_get_u32_le bytes add off 12 |
| 883 | max_ops = at_get_u32_le bytes add off 16 |
| 884 | if ne kind AT_RES_KIND_OBJECT |
| 885 | if ne kind AT_RES_KIND_CHANNEL |
| 886 | ret AT_ERR_BAD_CAP |
| 887 | end |
| 888 | end |
| 889 | if eq rid 0 |
| 890 | ret AT_ERR_BAD_CAP |
| 891 | end |
| 892 | if eq rights 0 |
| 893 | ret AT_ERR_BAD_CAP |
| 894 | end |
| 895 | if ne and rights not AT_VALID_RIGHTS 0 |
| 896 | ret AT_ERR_BAD_CAP |
| 897 | end |
| 898 | if eq max_ops 0 |
| 899 | ret AT_ERR_BAD_CAP |
| 900 | end |
| 901 | ret at_validate_cap_bounds bytes off kind bkind |
| 902 | end |
| 903 | |
| 904 | fn at_parse_caps bytes view uchar * to int |
| 905 | cap_cnt = get at_art_meta 2 |
| 906 | has_prev = false |
| 907 | prev_k = ulong 0 |
| 908 | prev_id = ulong 0 |
| 909 | for i ulong cap_cnt bound 16 |
| 910 | off = add AT_CAP_TABLE_OFF mul i AT_CAP_REC_SIZE |
| 911 | rc = at_validate_one_cap bytes off |
| 912 | if ne rc AT_OK |
| 913 | ret rc |
| 914 | end |
| 915 | k = at_get_u16_le bytes off |
| 916 | rid = at_get_u32_le bytes add off 4 |
| 917 | if has_prev |
| 918 | if gt prev_k k |
| 919 | ret AT_ERR_BAD_CAP |
| 920 | end |
| 921 | if eq prev_k k |
| 922 | if ge prev_id rid |
| 923 | ret AT_ERR_BAD_CAP |
| 924 | end |
| 925 | end |
| 926 | end |
| 927 | has_prev = true |
| 928 | prev_k = k |
| 929 | prev_id = rid |
| 930 | end |
| 931 | ret AT_OK |
| 932 | end |
| 933 | |
| 934 | fn at_parse_res_limits bytes view uchar * res_off ulong to int |
| 935 | if gt at_get_u32_le bytes add res_off 16 AT_MAX_IPC_MSGS |
| 936 | ret AT_ERR_RES_LIMIT |
| 937 | end |
| 938 | if gt at_get_u32_le bytes add res_off 20 AT_MAX_IPC_BYTES |
| 939 | ret AT_ERR_RES_LIMIT |
| 940 | end |
| 941 | cpu_t = at_get_u64_le bytes add res_off 24 |
| 942 | elap_t = at_get_u64_le bytes add res_off 32 |
| 943 | sys_c = at_get_u32_le bytes add res_off 40 |
| 944 | if eq cpu_t 0 |
| 945 | ret AT_ERR_RES_LIMIT |
| 946 | end |
| 947 | if gt cpu_t AT_MAX_TICKS |
| 948 | ret AT_ERR_RES_LIMIT |
| 949 | end |
| 950 | if eq elap_t 0 |
| 951 | ret AT_ERR_RES_LIMIT |
| 952 | end |
| 953 | if gt elap_t AT_MAX_TICKS |
| 954 | ret AT_ERR_RES_LIMIT |
| 955 | end |
| 956 | if eq sys_c 0 |
| 957 | ret AT_ERR_RES_LIMIT |
| 958 | end |
| 959 | if gt sys_c AT_MAX_SYSCALLS |
| 960 | ret AT_ERR_RES_LIMIT |
| 961 | end |
| 962 | ret AT_OK |
| 963 | end |
| 964 | |
| 965 | fn at_parse_resources bytes view uchar * to int |
| 966 | res_off = get at_art_meta 3 |
| 967 | cap_cnt = get at_art_meta 2 |
| 968 | if ne at_get_u16_le bytes add res_off 14 0 |
| 969 | ret AT_ERR_RESERVED_NZ |
| 970 | end |
| 971 | if ne at_get_u32_le bytes add res_off 44 0 |
| 972 | ret AT_ERR_RESERVED_NZ |
| 973 | end |
| 974 | code_p = at_get_u32_le bytes res_off |
| 975 | data_p = at_get_u32_le bytes add res_off 4 |
| 976 | stack_p = at_get_u32_le bytes add res_off 8 |
| 977 | max_c = at_get_u16_le bytes add res_off 12 |
| 978 | if eq code_p 0 |
| 979 | ret AT_ERR_RES_LIMIT |
| 980 | end |
| 981 | if gt code_p AT_MAX_CODE_PAGES |
| 982 | ret AT_ERR_RES_LIMIT |
| 983 | end |
| 984 | if eq data_p 0 |
| 985 | ret AT_ERR_RES_LIMIT |
| 986 | end |
| 987 | if gt data_p AT_MAX_DATA_PAGES |
| 988 | ret AT_ERR_RES_LIMIT |
| 989 | end |
| 990 | if eq stack_p 0 |
| 991 | ret AT_ERR_RES_LIMIT |
| 992 | end |
| 993 | if gt stack_p AT_MAX_STACK_PAGES |
| 994 | ret AT_ERR_RES_LIMIT |
| 995 | end |
| 996 | if lt max_c cap_cnt |
| 997 | ret AT_ERR_RES_LIMIT |
| 998 | end |
| 999 | if gt max_c AT_MAX_CAPS |
| 1000 | ret AT_ERR_RES_LIMIT |
| 1001 | end |
| 1002 | if gt get at_art_meta 7 mul code_p AT_PAGE_SIZE |
| 1003 | ret AT_ERR_RES_LIMIT |
| 1004 | end |
| 1005 | if gt get at_art_meta 10 mul data_p AT_PAGE_SIZE |
| 1006 | ret AT_ERR_RES_LIMIT |
| 1007 | end |
| 1008 | ret at_parse_res_limits bytes res_off |
| 1009 | end |
| 1010 | |
| 1011 | fn at_parse_entry_and_sig bytes view uchar * to int |
| 1012 | entry_off = get at_art_meta 1 |
| 1013 | code_len = get at_art_meta 7 |
| 1014 | if ne and entry_off 3 0 |
| 1015 | ret AT_ERR_BAD_ENTRY |
| 1016 | end |
| 1017 | if gt add entry_off 4 code_len |
| 1018 | ret AT_ERR_BAD_ENTRY |
| 1019 | end |
| 1020 | sig_off = get at_art_meta 6 |
| 1021 | if ne at_get_u16_le bytes sig_off get at_art_meta 11 |
| 1022 | ret AT_ERR_BAD_SIG_FMT |
| 1023 | end |
| 1024 | if ne get bytes add sig_off 2 0 |
| 1025 | ret AT_ERR_RESERVED_NZ |
| 1026 | end |
| 1027 | if ne get bytes add sig_off 3 0 |
| 1028 | ret AT_ERR_RESERVED_NZ |
| 1029 | end |
| 1030 | ret AT_OK |
| 1031 | end |
| 1032 | |
| 1033 | fn at_parse bytes view uchar * to int |
| 1034 | rc = at_parse_header bytes |
| 1035 | if ne rc AT_OK |
| 1036 | ret rc |
| 1037 | end |
| 1038 | rc = at_parse_header_tables bytes |
| 1039 | if ne rc AT_OK |
| 1040 | ret rc |
| 1041 | end |
| 1042 | rc = at_parse_offsets bytes |
| 1043 | if ne rc AT_OK |
| 1044 | ret rc |
| 1045 | end |
| 1046 | rc = at_parse_sections bytes |
| 1047 | if ne rc AT_OK |
| 1048 | ret rc |
| 1049 | end |
| 1050 | rc = at_parse_caps bytes |
| 1051 | if ne rc AT_OK |
| 1052 | ret rc |
| 1053 | end |
| 1054 | rc = at_parse_resources bytes |
| 1055 | if ne rc AT_OK |
| 1056 | ret rc |
| 1057 | end |
| 1058 | ret at_parse_entry_and_sig bytes |
| 1059 | end |
| 1060 | |
| 1061 | note Parse artifact and compute all canonical identity digests |
| 1062 | fn at_parse_and_identify bytes view uchar * to int |
| 1063 | rc = at_parse bytes |
| 1064 | if ne rc AT_OK |
| 1065 | ret rc |
| 1066 | end |
| 1067 | sig_off = get at_art_meta 6 |
| 1068 | pay_off = get at_art_meta 4 |
| 1069 | pay_len = get at_art_meta 5 |
| 1070 | cap_len = mul get at_art_meta 2 AT_CAP_REC_SIZE |
| 1071 | res_off = get at_art_meta 3 |
| 1072 | dig = new uchar 32 0 |
| 1073 | at_sha256_dom_nul at_dom_art_id part bytes 0 sig_off dig |
| 1074 | for i ulong 32 |
| 1075 | put at_art_id i get dig i |
| 1076 | end |
| 1077 | ctx = new ulong 40 0 |
| 1078 | sha256_init ctx |
| 1079 | sha256_update ctx part bytes pay_off pay_len |
| 1080 | sha256_final ctx dig |
| 1081 | for i ulong 32 |
| 1082 | put at_art_payload_sha i get dig i |
| 1083 | end |
| 1084 | at_sha256_dom_nul at_dom_req_caps part bytes AT_CAP_TABLE_OFF cap_len dig |
| 1085 | for i ulong 32 |
| 1086 | put at_art_req_caps_sha i get dig i |
| 1087 | end |
| 1088 | at_sha256_dom_nul at_dom_res_env part bytes res_off AT_RES_ENV_SIZE dig |
| 1089 | for i ulong 32 |
| 1090 | put at_art_res_env_sha i get dig i |
| 1091 | end |
| 1092 | for i ulong 32 |
| 1093 | put at_art_signer_fp i get bytes add add sig_off 4 i |
| 1094 | end |
| 1095 | ret AT_OK |
| 1096 | end |
| 1097 | |
| 1098 | note Pack staged manifest + code + data into canonical Binary Artifact v0 |
| 1099 | fn at_pack_compute_layout clen ulong dlen ulong dst_len ulong to int |
| 1100 | cap_cnt = get at_man_cap_cnt 0 |
| 1101 | if eq clen 0 |
| 1102 | ret AT_ERR_PACK_BOUNDS |
| 1103 | end |
| 1104 | if eq dlen 0 |
| 1105 | ret AT_ERR_PACK_BOUNDS |
| 1106 | end |
| 1107 | if gt cap_cnt AT_MAX_CAPS |
| 1108 | ret AT_ERR_PACK_BOUNDS |
| 1109 | end |
| 1110 | res_off = add AT_CAP_TABLE_OFF mul cap_cnt AT_CAP_REC_SIZE |
| 1111 | pay_off = at_align_up_16 add res_off AT_RES_ENV_SIZE |
| 1112 | pay_len = add clen dlen |
| 1113 | sig_off = add pay_off pay_len |
| 1114 | total_len = add sig_off AT_SIG_BLOCK_SIZE |
| 1115 | if gt total_len AT_MAX_ARTIFACT_SIZE |
| 1116 | ret AT_ERR_RES_LIMIT |
| 1117 | end |
| 1118 | if gt pay_len AT_MAX_PAYLOAD_SIZE |
| 1119 | ret AT_ERR_RES_LIMIT |
| 1120 | end |
| 1121 | if gt total_len dst_len |
| 1122 | ret AT_ERR_BUF_SMALL |
| 1123 | end |
| 1124 | put at_art_meta 0 total_len |
| 1125 | put at_art_meta 2 cap_cnt |
| 1126 | put at_art_meta 3 res_off |
| 1127 | put at_art_meta 4 pay_off |
| 1128 | put at_art_meta 5 pay_len |
| 1129 | put at_art_meta 6 sig_off |
| 1130 | ret AT_OK |
| 1131 | end |
| 1132 | |
| 1133 | fn at_pack_write_tables dst edit uchar * clen ulong dlen ulong to void |
| 1134 | total_len = get at_art_meta 0 |
| 1135 | cap_cnt = get at_art_meta 2 |
| 1136 | res_off = get at_art_meta 3 |
| 1137 | for i ulong total_len bound 4096 |
| 1138 | put dst i 0 |
| 1139 | end |
| 1140 | for i ulong 7 |
| 1141 | put dst i get at_art_magic i |
| 1142 | end |
| 1143 | at_put_u16_le dst 10 AT_HEADER_SIZE |
| 1144 | at_put_u16_le dst 12 AT_TARGET_AARCH64_LE |
| 1145 | at_put_u16_le dst 14 AT_ABI_V1 |
| 1146 | at_put_u32_le dst 20 total_len |
| 1147 | at_put_u32_le dst 24 AT_SEC_TABLE_OFF |
| 1148 | at_put_u16_le dst 28 AT_SEC_COUNT |
| 1149 | at_put_u16_le dst 30 AT_SEC_REC_SIZE |
| 1150 | at_put_u32_le dst 36 get at_man_entry 0 |
| 1151 | at_put_u32_le dst 40 AT_CAP_TABLE_OFF |
| 1152 | at_put_u16_le dst 44 cap_cnt |
| 1153 | at_put_u16_le dst 46 AT_CAP_REC_SIZE |
| 1154 | at_put_u32_le dst 48 res_off |
| 1155 | at_put_u16_le dst 52 AT_RES_ENV_SIZE |
| 1156 | at_put_u32_le dst 56 get at_art_meta 4 |
| 1157 | at_put_u32_le dst 60 get at_art_meta 5 |
| 1158 | at_put_u32_le dst 64 get at_art_meta 6 |
| 1159 | at_put_u16_le dst 68 AT_SIG_BLOCK_SIZE |
| 1160 | at_put_u16_le dst 70 AT_SIG_ALG_ED25519 |
| 1161 | at_encode_section dst 128 AT_SEC_KIND_CODE AT_PERM_RX 0 |
| 1162 | at_put_u32_le dst 140 clen |
| 1163 | at_put_u32_le dst 144 clen |
| 1164 | at_encode_section dst 160 AT_SEC_KIND_DATA AT_PERM_RW clen |
| 1165 | at_put_u32_le dst 172 dlen |
| 1166 | at_put_u32_le dst 176 mul get at_man_res 1 AT_PAGE_SIZE |
| 1167 | at_encode_staged_caps dst cap_cnt |
| 1168 | at_encode_resources dst res_off |
| 1169 | end |
| 1170 | |
| 1171 | fn at_pack code view uchar * data view uchar * dst edit uchar * to int |
| 1172 | clen = len code |
| 1173 | dlen = len data |
| 1174 | rc = at_pack_compute_layout clen dlen len dst |
| 1175 | if ne rc AT_OK |
| 1176 | ret rc |
| 1177 | end |
| 1178 | at_pack_write_tables dst clen dlen |
| 1179 | pay_off = get at_art_meta 4 |
| 1180 | for i ulong clen bound 2048 |
| 1181 | put dst add pay_off i get code i |
| 1182 | end |
| 1183 | data_off = add pay_off clen |
| 1184 | for i ulong dlen bound 2048 |
| 1185 | put dst add data_off i get data i |
| 1186 | end |
| 1187 | at_put_u16_le dst get at_art_meta 6 AT_SIG_ALG_ED25519 |
| 1188 | total_len = get at_art_meta 0 |
| 1189 | rc = at_parse part dst 0 total_len |
| 1190 | if ne rc AT_OK |
| 1191 | ret rc |
| 1192 | end |
| 1193 | put at_pack_len 0 total_len |
| 1194 | ret AT_OK |
| 1195 | end |
| 1196 | |
| 1197 | note Sign artifact in place with explicit 32-byte key |
| 1198 | fn at_sign_with_key buf edit uchar * key view uchar 32 to int |
| 1199 | rc = at_parse_and_identify buf |
| 1200 | if ne rc AT_OK |
| 1201 | ret rc |
| 1202 | end |
| 1203 | sig_off = get at_art_meta 6 |
| 1204 | fp = new uchar 32 0 |
| 1205 | id_cp = new uchar 32 0 |
| 1206 | sig = new uchar 64 0 |
| 1207 | for i ulong 32 |
| 1208 | put id_cp i get at_art_id i |
| 1209 | end |
| 1210 | at_signer_fp key fp |
| 1211 | at_compute_sig key at_dom_art_sig id_cp sig |
| 1212 | for i ulong 32 |
| 1213 | put buf add add sig_off 4 i get fp i |
| 1214 | end |
| 1215 | for i ulong 64 |
| 1216 | put buf add add sig_off 36 i get sig i |
| 1217 | end |
| 1218 | ret at_parse buf |
| 1219 | end |
| 1220 | |
| 1221 | note Tool `sign` command: requires test_mode (SEED-0B test signing); production fails closed |
| 1222 | fn at_sign_artifact buf edit uchar * test_mode bool to int |
| 1223 | if not test_mode |
| 1224 | ret AT_ERR_PROD_SIGN_OFF |
| 1225 | end |
| 1226 | key = new uchar 32 0 |
| 1227 | at_fill_test_art_key key |
| 1228 | ret at_sign_with_key buf key |
| 1229 | end |
| 1230 | |
| 1231 | note Tool `verify` command: parses, checks trust anchor (empty in production), verifies signature |
| 1232 | fn at_verify_artifact bytes view uchar * test_mode bool to int |
| 1233 | rc = at_parse_and_identify bytes |
| 1234 | if ne rc AT_OK |
| 1235 | ret rc |
| 1236 | end |
| 1237 | if not test_mode |
| 1238 | ret AT_ERR_UNTRUSTED |
| 1239 | end |
| 1240 | key = new uchar 32 0 |
| 1241 | at_fill_test_art_key key |
| 1242 | exp_fp = new uchar 32 0 |
| 1243 | at_signer_fp key exp_fp |
| 1244 | for i ulong 32 |
| 1245 | if ne get at_art_signer_fp i get exp_fp i |
| 1246 | ret AT_ERR_UNTRUSTED |
| 1247 | end |
| 1248 | end |
| 1249 | id_cp = new uchar 32 0 |
| 1250 | for i ulong 32 |
| 1251 | put id_cp i get at_art_id i |
| 1252 | end |
| 1253 | exp_sig = new uchar 64 0 |
| 1254 | at_compute_sig key at_dom_art_sig id_cp exp_sig |
| 1255 | sig_off = get at_art_meta 6 |
| 1256 | for i ulong 64 |
| 1257 | if ne get bytes add add sig_off 36 i get exp_sig i |
| 1258 | ret AT_ERR_BAD_SIG |
| 1259 | end |
| 1260 | end |
| 1261 | ret AT_OK |
| 1262 | end |
| 1263 | |
| 1264 | note Tool `inspect` and `id` commands |
| 1265 | fn at_inspect_artifact bytes view uchar * to int |
| 1266 | ret at_parse_and_identify bytes |
| 1267 | end |
| 1268 | |
| 1269 | fn at_id_hex bytes view uchar * hex_dst edit uchar * to int |
| 1270 | rc = at_parse_and_identify bytes |
| 1271 | if ne rc AT_OK |
| 1272 | ret rc |
| 1273 | end |
| 1274 | id_cp = new uchar 32 0 |
| 1275 | for i ulong 32 |
| 1276 | put id_cp i get at_art_id i |
| 1277 | end |
| 1278 | ret at_hex_encode id_cp hex_dst |
| 1279 | end |
| 1280 | |
| 1281 | note Admission Receipt v0 helpers (receipt.rs and receipt_cmd.rs) |
| 1282 | fn at_rcp_digest rec view uchar * dst edit uchar * to void |
| 1283 | at_sha256_dom_nul at_dom_rcp_dig part rec 0 AT_RCP_SIG_OFF dst |
| 1284 | end |
| 1285 | |
| 1286 | fn at_rcp_nonce ver_id view uchar * seq ulong dst edit uchar * to void |
| 1287 | ctx = new ulong 40 0 |
| 1288 | z = new uchar 1 0 |
| 1289 | seq_b = new uchar 8 0 |
| 1290 | dig = new uchar 32 0 |
| 1291 | at_put_u64_le seq_b 0 seq |
| 1292 | sha256_init ctx |
| 1293 | sha256_update ctx at_dom_rcp_nonce |
| 1294 | sha256_update ctx z |
| 1295 | sha256_update ctx ver_id |
| 1296 | sha256_update ctx seq_b |
| 1297 | sha256_final ctx dig |
| 1298 | for i ulong 16 |
| 1299 | put dst i get dig i |
| 1300 | end |
| 1301 | end |
| 1302 | |
| 1303 | fn at_rcp_is_unsigned rec view uchar * to bool |
| 1304 | ret at_bytes_zero rec AT_RCP_SIG_OFF sub AT_RCP_SIZE AT_RCP_SIG_OFF |
| 1305 | end |
| 1306 | |
| 1307 | fn at_rcp_reset to void |
| 1308 | for i ulong 16 |
| 1309 | put at_rcp_f i 0 |
| 1310 | end |
| 1311 | for i ulong 16 |
| 1312 | put at_rcp_nonce_buf i 0 |
| 1313 | end |
| 1314 | for i ulong 288 |
| 1315 | put at_rcp_digests i 0 |
| 1316 | end |
| 1317 | end |
| 1318 | |
| 1319 | fn at_rcp_set_digest slot ulong val view uchar * to void |
| 1320 | base = mul slot 32 |
| 1321 | for i ulong 32 |
| 1322 | put at_rcp_digests add base i get val i |
| 1323 | end |
| 1324 | end |
| 1325 | |
| 1326 | fn at_rcp_digest_is_zero slot ulong to bool |
| 1327 | base = mul slot 32 |
| 1328 | for i ulong 32 |
| 1329 | if ne get at_rcp_digests add base i 0 |
| 1330 | ret false |
| 1331 | end |
| 1332 | end |
| 1333 | ret true |
| 1334 | end |
| 1335 | |
| 1336 | fn at_rcp_encode dst edit uchar * to int |
| 1337 | if lt len dst AT_RCP_SIZE |
| 1338 | ret AT_ERR_BUF_SMALL |
| 1339 | end |
| 1340 | for i ulong AT_RCP_SIZE |
| 1341 | put dst i 0 |
| 1342 | end |
| 1343 | for i ulong 7 |
| 1344 | put dst i get at_rcp_magic i |
| 1345 | end |
| 1346 | at_put_u16_le dst 8 AT_RCP_VERSION |
| 1347 | at_put_u16_le dst 10 AT_RCP_HDR_SIZE |
| 1348 | at_put_u32_le dst 12 AT_RCP_SIZE |
| 1349 | at_put_u32_le dst 16 get at_rcp_f 0 |
| 1350 | at_put_u16_le dst 20 get at_rcp_f 1 |
| 1351 | at_put_u16_le dst 22 get at_rcp_f 2 |
| 1352 | at_put_u64_le dst 24 get at_rcp_f 3 |
| 1353 | for i ulong 16 |
| 1354 | put dst add 32 i get at_rcp_nonce_buf i |
| 1355 | end |
| 1356 | at_put_u64_le dst 48 get at_rcp_f 4 |
| 1357 | at_put_u32_le dst 64 get at_rcp_f 5 |
| 1358 | at_put_u32_le dst 68 get at_rcp_f 6 |
| 1359 | at_put_u32_le dst 72 get at_rcp_f 7 |
| 1360 | at_put_u16_le dst 76 get at_rcp_f 8 |
| 1361 | at_put_u16_le dst 78 get at_rcp_f 9 |
| 1362 | at_put_u32_le dst 80 get at_rcp_f 10 |
| 1363 | at_put_u32_le dst 84 get at_rcp_f 11 |
| 1364 | at_put_u32_le dst 88 get at_rcp_f 12 |
| 1365 | at_put_u32_le dst 92 get at_rcp_f 13 |
| 1366 | for i ulong 288 |
| 1367 | put dst add 96 i get at_rcp_digests i |
| 1368 | end |
| 1369 | at_put_u64_le dst 384 get at_rcp_f 14 |
| 1370 | at_put_u64_le dst 392 get at_rcp_f 15 |
| 1371 | ret AT_OK |
| 1372 | end |
| 1373 | |
| 1374 | fn at_rcp_valid_reason code ulong to bool |
| 1375 | if ge code 1 |
| 1376 | if le code 19 |
| 1377 | ret true |
| 1378 | end |
| 1379 | end |
| 1380 | if ge code AT_LOADER_REASON_FIRST |
| 1381 | if le code AT_LOADER_REASON_LAST |
| 1382 | ret true |
| 1383 | end |
| 1384 | end |
| 1385 | ret false |
| 1386 | end |
| 1387 | |
| 1388 | fn at_rcp_validate_nonce to int |
| 1389 | ver_id = new uchar 32 0 |
| 1390 | for i ulong 32 |
| 1391 | put ver_id i get at_rcp_digests add 224 i |
| 1392 | end |
| 1393 | exp_nonce = new uchar 16 0 |
| 1394 | at_rcp_nonce ver_id get at_rcp_f 3 exp_nonce |
| 1395 | for i ulong 16 |
| 1396 | if ne get at_rcp_nonce_buf i get exp_nonce i |
| 1397 | ret AT_ERR_BAD_RECEIPT |
| 1398 | end |
| 1399 | end |
| 1400 | ret AT_OK |
| 1401 | end |
| 1402 | |
| 1403 | fn at_rcp_validate_semantics to int |
| 1404 | fl = get at_rcp_f 0 |
| 1405 | dec = get at_rcp_f 1 |
| 1406 | st = get at_rcp_f 5 |
| 1407 | ex = get at_rcp_f 6 |
| 1408 | rfl = get at_rcp_f 7 |
| 1409 | rstg = get at_rcp_f 8 |
| 1410 | rrsn = get at_rcp_f 9 |
| 1411 | if eq and fl AT_RCP_FLAG_MACHINE_ID 0 |
| 1412 | if not at_rcp_digest_is_zero 8 |
| 1413 | ret AT_ERR_BAD_RECEIPT |
| 1414 | end |
| 1415 | end |
| 1416 | if eq and fl AT_RCP_FLAG_CONTEXT_ID 0 |
| 1417 | if ne get at_rcp_f 14 0 |
| 1418 | ret AT_ERR_BAD_RECEIPT |
| 1419 | end |
| 1420 | if ne get at_rcp_f 15 0 |
| 1421 | ret AT_ERR_BAD_RECEIPT |
| 1422 | end |
| 1423 | end |
| 1424 | if eq and fl AT_RCP_FLAG_TIMESTAMP 0 |
| 1425 | if ne get at_rcp_f 4 0 |
| 1426 | ret AT_ERR_BAD_RECEIPT |
| 1427 | end |
| 1428 | end |
| 1429 | if gt rstg AT_MAX_REJ_STAGE |
| 1430 | ret AT_ERR_BAD_RECEIPT |
| 1431 | end |
| 1432 | if ne rrsn 0 |
| 1433 | if not at_rcp_valid_reason rrsn |
| 1434 | ret AT_ERR_BAD_RECEIPT |
| 1435 | end |
| 1436 | end |
| 1437 | if eq dec AT_DEC_REJECTED |
| 1438 | if eq rstg 0 |
| 1439 | ret AT_ERR_BAD_RECEIPT |
| 1440 | end |
| 1441 | if eq rrsn 0 |
| 1442 | ret AT_ERR_BAD_RECEIPT |
| 1443 | end |
| 1444 | if ne st AT_EXEC_NOT_RUN |
| 1445 | ret AT_ERR_BAD_RECEIPT |
| 1446 | end |
| 1447 | if ne ex 0 |
| 1448 | ret AT_ERR_BAD_RECEIPT |
| 1449 | end |
| 1450 | if ne get at_rcp_f 10 0 |
| 1451 | ret AT_ERR_BAD_RECEIPT |
| 1452 | end |
| 1453 | if ne get at_rcp_f 11 0 |
| 1454 | ret AT_ERR_BAD_RECEIPT |
| 1455 | end |
| 1456 | if ne get at_rcp_f 12 0 |
| 1457 | ret AT_ERR_BAD_RECEIPT |
| 1458 | end |
| 1459 | if ne and rfl not AT_RCP_RES_RECLAIMED 0 |
| 1460 | ret AT_ERR_BAD_RECEIPT |
| 1461 | end |
| 1462 | else |
| 1463 | if ne rstg 0 |
| 1464 | ret AT_ERR_BAD_RECEIPT |
| 1465 | end |
| 1466 | if ne rrsn 0 |
| 1467 | ret AT_ERR_BAD_RECEIPT |
| 1468 | end |
| 1469 | end |
| 1470 | dec_can = eq dec AT_DEC_CANARY_FAILED |
| 1471 | st_can = eq st AT_EXEC_CANARY_FAILED |
| 1472 | if ne dec_can st_can |
| 1473 | ret AT_ERR_BAD_RECEIPT |
| 1474 | end |
| 1475 | if ne and rfl AT_RCP_RES_CANARY_OK 0 |
| 1476 | if ne st AT_EXEC_EXITED |
| 1477 | ret AT_ERR_BAD_RECEIPT |
| 1478 | end |
| 1479 | if ne ex 0 |
| 1480 | ret AT_ERR_BAD_RECEIPT |
| 1481 | end |
| 1482 | end |
| 1483 | ret at_rcp_validate_nonce |
| 1484 | end |
| 1485 | |
| 1486 | fn at_rcp_decode rec view uchar * to int |
| 1487 | n = len rec |
| 1488 | if lt n AT_RCP_SIZE |
| 1489 | ret AT_ERR_TRUNCATED |
| 1490 | end |
| 1491 | if gt n AT_RCP_SIZE |
| 1492 | ret AT_ERR_WRONG_LEN |
| 1493 | end |
| 1494 | for i ulong 7 |
| 1495 | if ne get rec i get at_rcp_magic i |
| 1496 | ret AT_ERR_BAD_MAGIC |
| 1497 | end |
| 1498 | end |
| 1499 | if ne get rec 7 0 |
| 1500 | ret AT_ERR_BAD_MAGIC |
| 1501 | end |
| 1502 | if ne at_get_u16_le rec 8 AT_RCP_VERSION |
| 1503 | ret AT_ERR_UNSUP_VER |
| 1504 | end |
| 1505 | if ne at_get_u16_le rec 10 AT_RCP_HDR_SIZE |
| 1506 | ret AT_ERR_UNSUP_VER |
| 1507 | end |
| 1508 | if ne at_get_u32_le rec 12 AT_RCP_SIZE |
| 1509 | ret AT_ERR_UNSUP_VER |
| 1510 | end |
| 1511 | fl = at_get_u32_le rec 16 |
| 1512 | rfl = at_get_u32_le rec 72 |
| 1513 | if ne and fl not AT_RCP_VALID_FLAGS 0 |
| 1514 | ret AT_ERR_UNSUP_FLAGS |
| 1515 | end |
| 1516 | if ne and rfl not AT_RCP_VALID_RES_FLAGS 0 |
| 1517 | ret AT_ERR_UNSUP_FLAGS |
| 1518 | end |
| 1519 | if not at_bytes_zero rec 56 8 |
| 1520 | ret AT_ERR_RESERVED_NZ |
| 1521 | end |
| 1522 | if not at_bytes_zero rec 500 12 |
| 1523 | ret AT_ERR_RESERVED_NZ |
| 1524 | end |
| 1525 | if not at_bytes_zero rec 400 100 |
| 1526 | if ne at_get_u16_le rec 400 AT_SIG_ALG_ED25519 |
| 1527 | ret AT_ERR_BAD_SIG_FMT |
| 1528 | end |
| 1529 | if not at_bytes_zero rec 402 2 |
| 1530 | ret AT_ERR_RESERVED_NZ |
| 1531 | end |
| 1532 | end |
| 1533 | dec = at_get_u16_le rec 20 |
| 1534 | tier = at_get_u16_le rec 22 |
| 1535 | est = at_get_u32_le rec 64 |
| 1536 | if lt dec 1 |
| 1537 | ret AT_ERR_BAD_RECEIPT |
| 1538 | end |
| 1539 | if gt dec 4 |
| 1540 | ret AT_ERR_BAD_RECEIPT |
| 1541 | end |
| 1542 | if lt tier 1 |
| 1543 | ret AT_ERR_BAD_RECEIPT |
| 1544 | end |
| 1545 | if gt tier 3 |
| 1546 | ret AT_ERR_BAD_RECEIPT |
| 1547 | end |
| 1548 | if gt est 6 |
| 1549 | ret AT_ERR_BAD_RECEIPT |
| 1550 | end |
| 1551 | put at_rcp_f 0 fl |
| 1552 | put at_rcp_f 1 dec |
| 1553 | put at_rcp_f 2 tier |
| 1554 | put at_rcp_f 3 at_get_u64_le rec 24 |
| 1555 | put at_rcp_f 4 at_get_u64_le rec 48 |
| 1556 | put at_rcp_f 5 est |
| 1557 | put at_rcp_f 6 at_get_u32_le rec 68 |
| 1558 | put at_rcp_f 7 rfl |
| 1559 | put at_rcp_f 8 at_get_u16_le rec 76 |
| 1560 | put at_rcp_f 9 at_get_u16_le rec 78 |
| 1561 | put at_rcp_f 10 at_get_u32_le rec 80 |
| 1562 | put at_rcp_f 11 at_get_u32_le rec 84 |
| 1563 | put at_rcp_f 12 at_get_u32_le rec 88 |
| 1564 | put at_rcp_f 13 at_get_u32_le rec 92 |
| 1565 | put at_rcp_f 14 at_get_u64_le rec 384 |
| 1566 | put at_rcp_f 15 at_get_u64_le rec 392 |
| 1567 | for i ulong 16 |
| 1568 | put at_rcp_nonce_buf i get rec add 32 i |
| 1569 | end |
| 1570 | for i ulong 288 |
| 1571 | put at_rcp_digests i get rec add 96 i |
| 1572 | end |
| 1573 | ret at_rcp_validate_semantics |
| 1574 | end |
| 1575 | |
| 1576 | fn at_rcp_inspect rec view uchar * to int |
| 1577 | rc = at_rcp_decode rec |
| 1578 | if ne rc AT_OK |
| 1579 | ret rc |
| 1580 | end |
| 1581 | dig = new uchar 32 0 |
| 1582 | at_rcp_digest rec dig |
| 1583 | for i ulong 32 |
| 1584 | put at_rcp_dig_out i get dig i |
| 1585 | end |
| 1586 | if at_rcp_is_unsigned rec |
| 1587 | put at_rcp_signed_flag 0 0 |
| 1588 | else |
| 1589 | put at_rcp_signed_flag 0 1 |
| 1590 | end |
| 1591 | ret AT_OK |
| 1592 | end |
| 1593 | |
| 1594 | fn at_rcp_bind_match slot ulong want view uchar * zero_ok bool to bool |
| 1595 | base = mul slot 32 |
| 1596 | same = true |
| 1597 | for i ulong 32 |
| 1598 | if ne get at_rcp_digests add base i get want i |
| 1599 | same = false |
| 1600 | end |
| 1601 | end |
| 1602 | if same |
| 1603 | ret true |
| 1604 | end |
| 1605 | if zero_ok |
| 1606 | if at_rcp_digest_is_zero slot |
| 1607 | ret true |
| 1608 | end |
| 1609 | end |
| 1610 | ret false |
| 1611 | end |
| 1612 | |
| 1613 | fn at_rcp_check_one_binding slot ulong zero_ok bool to bool |
| 1614 | want = new uchar 32 0 |
| 1615 | if eq slot 0 |
| 1616 | for i ulong 32 |
| 1617 | put want i get at_art_id i |
| 1618 | end |
| 1619 | end |
| 1620 | if eq slot 1 |
| 1621 | for i ulong 32 |
| 1622 | put want i get at_art_payload_sha i |
| 1623 | end |
| 1624 | end |
| 1625 | if eq slot 2 |
| 1626 | for i ulong 32 |
| 1627 | put want i get at_art_signer_fp i |
| 1628 | end |
| 1629 | end |
| 1630 | if eq slot 4 |
| 1631 | for i ulong 32 |
| 1632 | put want i get at_art_req_caps_sha i |
| 1633 | end |
| 1634 | end |
| 1635 | if eq slot 6 |
| 1636 | for i ulong 32 |
| 1637 | put want i get at_art_res_env_sha i |
| 1638 | end |
| 1639 | end |
| 1640 | ret at_rcp_bind_match slot want zero_ok |
| 1641 | end |
| 1642 | |
| 1643 | note Tool `receipt check` command (receipt_cmd.rs::check) |
| 1644 | fn at_rcp_check rec view uchar * art view uchar * to int |
| 1645 | if not at_rcp_is_unsigned rec |
| 1646 | ret AT_ERR_RCP_MUST_UNSIGNED |
| 1647 | end |
| 1648 | rc = at_rcp_decode rec |
| 1649 | if ne rc AT_OK |
| 1650 | ret rc |
| 1651 | end |
| 1652 | admitted = eq get at_rcp_f 1 AT_DEC_ADMITTED |
| 1653 | arc = at_parse_and_identify art |
| 1654 | if ne arc AT_OK |
| 1655 | if admitted |
| 1656 | ret AT_ERR_RCP_ADMIT_BAD_ART |
| 1657 | end |
| 1658 | if not at_rcp_digest_is_zero 0 |
| 1659 | ret AT_ERR_RCP_NZ_BAD_ART |
| 1660 | end |
| 1661 | if not at_rcp_digest_is_zero 1 |
| 1662 | ret AT_ERR_RCP_NZ_BAD_ART |
| 1663 | end |
| 1664 | if not at_rcp_digest_is_zero 2 |
| 1665 | ret AT_ERR_RCP_NZ_BAD_ART |
| 1666 | end |
| 1667 | if not at_rcp_digest_is_zero 4 |
| 1668 | ret AT_ERR_RCP_NZ_BAD_ART |
| 1669 | end |
| 1670 | if not at_rcp_digest_is_zero 6 |
| 1671 | ret AT_ERR_RCP_NZ_BAD_ART |
| 1672 | end |
| 1673 | else |
| 1674 | z_ok = not admitted |
| 1675 | if not at_rcp_check_one_binding 0 z_ok |
| 1676 | ret AT_ERR_RCP_BIND_MISMATCH |
| 1677 | end |
| 1678 | if not at_rcp_check_one_binding 1 z_ok |
| 1679 | ret AT_ERR_RCP_BIND_MISMATCH |
| 1680 | end |
| 1681 | if not at_rcp_check_one_binding 2 z_ok |
| 1682 | ret AT_ERR_RCP_BIND_MISMATCH |
| 1683 | end |
| 1684 | if not at_rcp_check_one_binding 4 z_ok |
| 1685 | ret AT_ERR_RCP_BIND_MISMATCH |
| 1686 | end |
| 1687 | if not at_rcp_check_one_binding 6 z_ok |
| 1688 | ret AT_ERR_RCP_BIND_MISMATCH |
| 1689 | end |
| 1690 | if admitted |
| 1691 | if at_rcp_digest_is_zero 5 |
| 1692 | ret AT_ERR_RCP_NO_GRANTS |
| 1693 | end |
| 1694 | end |
| 1695 | end |
| 1696 | dig = new uchar 32 0 |
| 1697 | at_rcp_digest rec dig |
| 1698 | for i ulong 32 |
| 1699 | put at_rcp_dig_out i get dig i |
| 1700 | end |
| 1701 | ret AT_OK |
| 1702 | end |
| 1703 | |
| 1704 | note Tool `receipt sign-test` command (receipt_cmd.rs::sign_test) |
| 1705 | fn at_rcp_sign_test rec edit uchar * test_mode bool to int |
| 1706 | if not test_mode |
| 1707 | ret AT_ERR_PROD_SIGN_OFF |
| 1708 | end |
| 1709 | if not at_rcp_is_unsigned rec |
| 1710 | ret AT_ERR_BAD_SIG_FMT |
| 1711 | end |
| 1712 | rc = at_rcp_decode rec |
| 1713 | if ne rc AT_OK |
| 1714 | ret rc |
| 1715 | end |
| 1716 | key = new uchar 32 0 |
| 1717 | at_fill_test_rcp_key key |
| 1718 | fp = new uchar 32 0 |
| 1719 | at_signer_fp key fp |
| 1720 | dig = new uchar 32 0 |
| 1721 | at_rcp_digest rec dig |
| 1722 | sig = new uchar 64 0 |
| 1723 | at_compute_sig key at_dom_rcp_sig dig sig |
| 1724 | at_put_u16_le rec 400 AT_SIG_ALG_ED25519 |
| 1725 | for i ulong 32 |
| 1726 | put rec add 404 i get fp i |
| 1727 | end |
| 1728 | for i ulong 64 |
| 1729 | put rec add 436 i get sig i |
| 1730 | end |
| 1731 | ret AT_OK |
| 1732 | end |
| 1733 | |
| 1734 | note Tool `receipt verify` command (receipt_cmd.rs::verify_file) |
| 1735 | fn at_rcp_verify rec view uchar * test_mode bool to int |
| 1736 | rc = at_rcp_decode rec |
| 1737 | if ne rc AT_OK |
| 1738 | ret rc |
| 1739 | end |
| 1740 | if at_rcp_is_unsigned rec |
| 1741 | ret AT_ERR_BAD_SIG_FMT |
| 1742 | end |
| 1743 | if not test_mode |
| 1744 | ret AT_ERR_UNTRUSTED |
| 1745 | end |
| 1746 | key = new uchar 32 0 |
| 1747 | at_fill_test_rcp_key key |
| 1748 | exp_fp = new uchar 32 0 |
| 1749 | at_signer_fp key exp_fp |
| 1750 | for i ulong 32 |
| 1751 | if ne get rec add 404 i get exp_fp i |
| 1752 | ret AT_ERR_UNTRUSTED |
| 1753 | end |
| 1754 | end |
| 1755 | dig = new uchar 32 0 |
| 1756 | at_rcp_digest rec dig |
| 1757 | exp_sig = new uchar 64 0 |
| 1758 | at_compute_sig key at_dom_rcp_sig dig exp_sig |
| 1759 | for i ulong 64 |
| 1760 | if ne get rec add 436 i get exp_sig i |
| 1761 | ret AT_ERR_BAD_SIG |
| 1762 | end |
| 1763 | end |
| 1764 | for i ulong 32 |
| 1765 | put at_rcp_dig_out i get dig i |
| 1766 | end |
| 1767 | ret AT_OK |
| 1768 | end |
| 1769 | |
| 1770 | note P2-7 Negative Corpus generator (corpus.rs: H01..H29) |
| 1771 | fn at_corpus_stage_seed_cap rights ulong to void |
| 1772 | idx = at_manifest_push_cap AT_RES_KIND_OBJECT 1 rights 1 4 |
| 1773 | at_manifest_set_cap_bounds ulong idx 32 0 32 |
| 1774 | end |
| 1775 | |
| 1776 | fn at_corpus_stage_res cp ulong dp ulong sp ulong mc ulong sc ulong to void |
| 1777 | at_manifest_set_res_pages cp dp sp mc |
| 1778 | at_manifest_set_res_limits 0 0 100000000 100000000 sc |
| 1779 | end |
| 1780 | |
| 1781 | fn at_corpus_fill_exit0 buf edit uchar * to void |
| 1782 | at_put_u32_le buf 0 AT_INSN_MOV_X0_0 |
| 1783 | at_put_u32_le buf 4 AT_INSN_MOV_X8_2 |
| 1784 | at_put_u32_le buf 8 AT_INSN_SVC_0 |
| 1785 | at_put_u32_le buf 12 AT_INSN_B_SELF |
| 1786 | end |
| 1787 | |
| 1788 | fn at_corpus_pack_signed code view uchar * data view uchar * dst edit uchar * to int |
| 1789 | rc = at_pack code data dst |
| 1790 | if ne rc AT_OK |
| 1791 | ret rc |
| 1792 | end |
| 1793 | n = get at_pack_len 0 |
| 1794 | rc = at_sign_artifact part dst 0 n true |
| 1795 | if ne rc AT_OK |
| 1796 | ret rc |
| 1797 | end |
| 1798 | put at_corpus_len 0 n |
| 1799 | ret AT_OK |
| 1800 | end |
| 1801 | |
| 1802 | fn at_corpus_build_baseline dst edit uchar * to int |
| 1803 | at_manifest_reset |
| 1804 | at_corpus_stage_seed_cap 1 |
| 1805 | at_corpus_stage_res 1 1 1 1 8 |
| 1806 | code = new uchar 16 0 |
| 1807 | at_corpus_fill_exit0 code |
| 1808 | ret at_corpus_pack_signed code at_tag_baseline dst |
| 1809 | end |
| 1810 | |
| 1811 | fn at_corpus_mutate_base cid ulong dst edit uchar * to int |
| 1812 | ukey = new uchar 32 0 |
| 1813 | rc = at_corpus_build_baseline dst |
| 1814 | if ne rc AT_OK |
| 1815 | ret rc |
| 1816 | end |
| 1817 | n = get at_corpus_len 0 |
| 1818 | pay_off = at_get_u32_le dst 56 |
| 1819 | res_off = add AT_CAP_TABLE_OFF AT_CAP_REC_SIZE |
| 1820 | sig_off = sub n AT_SIG_BLOCK_SIZE |
| 1821 | if eq cid 1 |
| 1822 | put dst 0 88 |
| 1823 | ret AT_OK |
| 1824 | end |
| 1825 | if eq cid 2 |
| 1826 | at_put_u16_le dst 8 1 |
| 1827 | ret AT_OK |
| 1828 | end |
| 1829 | if eq cid 3 |
| 1830 | at_put_u16_le dst 12 2 |
| 1831 | ret AT_OK |
| 1832 | end |
| 1833 | if eq cid 4 |
| 1834 | at_put_u16_le dst 14 2 |
| 1835 | ret AT_OK |
| 1836 | end |
| 1837 | if eq cid 5 |
| 1838 | put at_corpus_len 0 sub n 10 |
| 1839 | ret AT_OK |
| 1840 | end |
| 1841 | if eq cid 6 |
| 1842 | if ge n len dst |
| 1843 | ret AT_ERR_BUF_SMALL |
| 1844 | end |
| 1845 | put dst n 0 |
| 1846 | put at_corpus_len 0 add n 1 |
| 1847 | ret AT_OK |
| 1848 | end |
| 1849 | if eq cid 7 |
| 1850 | t = at_get_u32_le dst 20 |
| 1851 | at_put_u32_le dst 20 add t 1 |
| 1852 | ret AT_OK |
| 1853 | end |
| 1854 | if eq cid 8 |
| 1855 | at_put_u32_le dst 60 0xffffffff |
| 1856 | ret AT_OK |
| 1857 | end |
| 1858 | if eq cid 9 |
| 1859 | at_put_u32_le dst 168 4 |
| 1860 | ret AT_OK |
| 1861 | end |
| 1862 | if eq cid 10 |
| 1863 | at_put_u32_le dst 36 0x1000 |
| 1864 | ret AT_OK |
| 1865 | end |
| 1866 | if eq cid 11 |
| 1867 | put dst pay_off xor get dst pay_off 1 |
| 1868 | ret AT_OK |
| 1869 | end |
| 1870 | if eq cid 12 |
| 1871 | at_put_u32_le dst add AT_CAP_TABLE_OFF 8 3 |
| 1872 | ret AT_OK |
| 1873 | end |
| 1874 | if eq cid 13 |
| 1875 | at_put_u32_le dst add res_off 8 2 |
| 1876 | ret AT_OK |
| 1877 | end |
| 1878 | if eq cid 14 |
| 1879 | p = add sig_off 40 |
| 1880 | put dst p xor get dst p 1 |
| 1881 | ret AT_OK |
| 1882 | end |
| 1883 | if eq cid 15 |
| 1884 | at_fill_untrusted_key ukey |
| 1885 | ret at_sign_with_key part dst 0 n ukey |
| 1886 | end |
| 1887 | if eq cid 16 |
| 1888 | at_put_u16_le dst sig_off 2 |
| 1889 | ret AT_OK |
| 1890 | end |
| 1891 | if eq cid 17 |
| 1892 | put dst 100 1 |
| 1893 | ret AT_OK |
| 1894 | end |
| 1895 | if eq cid 18 |
| 1896 | at_put_u32_le dst add AT_CAP_TABLE_OFF 8 65 |
| 1897 | ret AT_OK |
| 1898 | end |
| 1899 | if eq cid 19 |
| 1900 | at_put_u16_le dst 44 17 |
| 1901 | ret AT_OK |
| 1902 | end |
| 1903 | if eq cid 20 |
| 1904 | at_put_u32_le dst res_off 65 |
| 1905 | ret AT_OK |
| 1906 | end |
| 1907 | if eq cid 22 |
| 1908 | at_put_u16_le dst 130 7 |
| 1909 | ret AT_OK |
| 1910 | end |
| 1911 | ret AT_ERR_BAD_CASE |
| 1912 | end |
| 1913 | |
| 1914 | fn at_corpus_build_custom cid ulong dst edit uchar * to int |
| 1915 | code = new uchar 16 0 |
| 1916 | c4 = new uchar 4 0 |
| 1917 | c8 = new uchar 8 0 |
| 1918 | c12 = new uchar 12 0 |
| 1919 | c32 = new uchar 32 0 |
| 1920 | if eq cid 21 |
| 1921 | at_manifest_reset |
| 1922 | at_corpus_stage_res 64 64 16 0 4 |
| 1923 | at_corpus_fill_exit0 code |
| 1924 | ret at_corpus_pack_signed code at_tag_largest dst |
| 1925 | end |
| 1926 | if eq cid 23 |
| 1927 | at_manifest_reset |
| 1928 | at_corpus_stage_res 1 1 1 0 4 |
| 1929 | at_put_u32_le c4 0 AT_INSN_BR_X2 |
| 1930 | ret at_corpus_pack_signed c4 at_tag_datapage dst |
| 1931 | end |
| 1932 | if eq cid 24 |
| 1933 | at_manifest_reset |
| 1934 | at_corpus_stage_res 1 1 1 0 4 |
| 1935 | at_put_u32_le c8 0 AT_INSN_SUB_X9_SP_16 |
| 1936 | at_put_u32_le c8 4 AT_INSN_BR_X9 |
| 1937 | ret at_corpus_pack_signed c8 at_tag_stackpag dst |
| 1938 | end |
| 1939 | if eq cid 25 |
| 1940 | at_manifest_reset |
| 1941 | at_corpus_stage_res 1 1 1 0 4 |
| 1942 | at_put_u32_le c12 0 AT_INSN_MOV_X8_99 |
| 1943 | at_put_u32_le c12 4 AT_INSN_SVC_0 |
| 1944 | at_put_u32_le c12 8 AT_INSN_B_SELF |
| 1945 | ret at_corpus_pack_signed c12 at_tag_badsyscl dst |
| 1946 | end |
| 1947 | if eq cid 26 |
| 1948 | at_manifest_reset |
| 1949 | at_corpus_stage_res 1 1 1 0 2 |
| 1950 | at_put_u32_le c32 0 AT_INSN_MOV_X0_0 |
| 1951 | at_put_u32_le c32 4 AT_INSN_MOV_X8_6 |
| 1952 | at_put_u32_le c32 8 AT_INSN_SVC_0 |
| 1953 | at_put_u32_le c32 12 AT_INSN_SVC_0 |
| 1954 | at_put_u32_le c32 16 AT_INSN_SVC_0 |
| 1955 | at_put_u32_le c32 20 AT_INSN_MOV_X8_2 |
| 1956 | at_put_u32_le c32 24 AT_INSN_SVC_0 |
| 1957 | at_put_u32_le c32 28 AT_INSN_B_SELF |
| 1958 | ret at_corpus_pack_signed c32 at_tag_overrun dst |
| 1959 | end |
| 1960 | if eq cid 27 |
| 1961 | at_manifest_reset |
| 1962 | at_corpus_stage_seed_cap 1 |
| 1963 | at_manifest_set_res_pages 1 1 1 1 |
| 1964 | at_manifest_set_res_limits 1 64 100000000 100000000 8 |
| 1965 | at_corpus_fill_exit0 code |
| 1966 | ret at_corpus_pack_signed code at_tag_ipcwants dst |
| 1967 | end |
| 1968 | if eq cid 28 |
| 1969 | at_manifest_reset |
| 1970 | at_corpus_stage_seed_cap 2 |
| 1971 | at_corpus_stage_res 1 1 1 1 8 |
| 1972 | at_corpus_fill_exit0 code |
| 1973 | ret at_corpus_pack_signed code at_tag_writereq dst |
| 1974 | end |
| 1975 | if eq cid 29 |
| 1976 | at_manifest_reset |
| 1977 | at_corpus_stage_seed_cap 3 |
| 1978 | at_corpus_stage_res 1 1 1 1 8 |
| 1979 | at_corpus_fill_exit0 code |
| 1980 | ret at_corpus_pack_signed code at_tag_rwrequst dst |
| 1981 | end |
| 1982 | ret AT_ERR_BAD_CASE |
| 1983 | end |
| 1984 | |
| 1985 | fn at_corpus_build_case cid ulong dst edit uchar * to int |
| 1986 | if lt cid 1 |
| 1987 | ret AT_ERR_BAD_CASE |
| 1988 | end |
| 1989 | if gt cid AT_CORPUS_COUNT |
| 1990 | ret AT_ERR_BAD_CASE |
| 1991 | end |
| 1992 | if le cid 20 |
| 1993 | ret at_corpus_mutate_base cid dst |
| 1994 | end |
| 1995 | if eq cid 22 |
| 1996 | ret at_corpus_mutate_base cid dst |
| 1997 | end |
| 1998 | ret at_corpus_build_custom cid dst |
| 1999 | end |
| 2000 | |
| 2001 | note Populate at_corpus_exp[0..4] = (expect_kind, code, exec_kind, caps) for H01..H29 |
| 2002 | fn at_corpus_set_exp k ulong code ulong ex ulong caps ulong to void |
| 2003 | put at_corpus_exp 0 k |
| 2004 | put at_corpus_exp 1 code |
| 2005 | put at_corpus_exp 2 ex |
| 2006 | put at_corpus_exp 3 caps |
| 2007 | end |
| 2008 | |
| 2009 | fn at_corpus_expect cid ulong to int |
| 2010 | if eq cid 1 |
| 2011 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 1 0 0 |
| 2012 | ret AT_OK |
| 2013 | end |
| 2014 | if eq cid 2 |
| 2015 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 2 0 0 |
| 2016 | ret AT_OK |
| 2017 | end |
| 2018 | if eq cid 3 |
| 2019 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 3 0 0 |
| 2020 | ret AT_OK |
| 2021 | end |
| 2022 | if eq cid 4 |
| 2023 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 4 0 0 |
| 2024 | ret AT_OK |
| 2025 | end |
| 2026 | if eq cid 5 |
| 2027 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 7 0 0 |
| 2028 | ret AT_OK |
| 2029 | end |
| 2030 | if eq cid 6 |
| 2031 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 7 0 0 |
| 2032 | ret AT_OK |
| 2033 | end |
| 2034 | if eq cid 7 |
| 2035 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 7 0 0 |
| 2036 | ret AT_OK |
| 2037 | end |
| 2038 | if eq cid 8 |
| 2039 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 14 0 0 |
| 2040 | ret AT_OK |
| 2041 | end |
| 2042 | if eq cid 9 |
| 2043 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 11 0 0 |
| 2044 | ret AT_OK |
| 2045 | end |
| 2046 | if eq cid 10 |
| 2047 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 12 0 0 |
| 2048 | ret AT_OK |
| 2049 | end |
| 2050 | if eq cid 11 |
| 2051 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 18 0 0 |
| 2052 | ret AT_OK |
| 2053 | end |
| 2054 | if eq cid 12 |
| 2055 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 18 0 0 |
| 2056 | ret AT_OK |
| 2057 | end |
| 2058 | if eq cid 13 |
| 2059 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 18 0 0 |
| 2060 | ret AT_OK |
| 2061 | end |
| 2062 | if eq cid 14 |
| 2063 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 18 0 0 |
| 2064 | ret AT_OK |
| 2065 | end |
| 2066 | if eq cid 15 |
| 2067 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 17 0 0 |
| 2068 | ret AT_OK |
| 2069 | end |
| 2070 | if eq cid 16 |
| 2071 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 15 0 0 |
| 2072 | ret AT_OK |
| 2073 | end |
| 2074 | if eq cid 17 |
| 2075 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 8 0 0 |
| 2076 | ret AT_OK |
| 2077 | end |
| 2078 | if eq cid 18 |
| 2079 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 13 0 0 |
| 2080 | ret AT_OK |
| 2081 | end |
| 2082 | if eq cid 19 |
| 2083 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 14 0 0 |
| 2084 | ret AT_OK |
| 2085 | end |
| 2086 | if eq cid 20 |
| 2087 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 14 0 0 |
| 2088 | ret AT_OK |
| 2089 | end |
| 2090 | if eq cid 21 |
| 2091 | at_corpus_set_exp AT_EXP_ADMITTED 0 AT_CORPUS_EXEC_EXIT0 0 |
| 2092 | ret AT_OK |
| 2093 | end |
| 2094 | if eq cid 22 |
| 2095 | at_corpus_set_exp AT_EXP_REJ_VERIFIED 11 0 0 |
| 2096 | ret AT_OK |
| 2097 | end |
| 2098 | if eq cid 23 |
| 2099 | at_corpus_set_exp AT_EXP_ADMITTED 0 AT_CORPUS_EXEC_NX 0 |
| 2100 | ret AT_OK |
| 2101 | end |
| 2102 | if eq cid 24 |
| 2103 | at_corpus_set_exp AT_EXP_ADMITTED 0 AT_CORPUS_EXEC_NX 0 |
| 2104 | ret AT_OK |
| 2105 | end |
| 2106 | if eq cid 25 |
| 2107 | at_corpus_set_exp AT_EXP_ADMITTED 0 AT_CORPUS_EXEC_BAD_SYS99 0 |
| 2108 | ret AT_OK |
| 2109 | end |
| 2110 | if eq cid 26 |
| 2111 | at_corpus_set_exp AT_EXP_ADMITTED 0 AT_CORPUS_EXEC_OVERRUN 0 |
| 2112 | ret AT_OK |
| 2113 | end |
| 2114 | if eq cid 27 |
| 2115 | at_corpus_set_exp AT_EXP_REJ_AUTHORIZED 14 0 0 |
| 2116 | ret AT_OK |
| 2117 | end |
| 2118 | if eq cid 28 |
| 2119 | at_corpus_set_exp AT_EXP_ADMITTED 0 AT_CORPUS_EXEC_EXIT0 0 |
| 2120 | ret AT_OK |
| 2121 | end |
| 2122 | if eq cid 29 |
| 2123 | at_corpus_set_exp AT_EXP_ADMITTED 0 AT_CORPUS_EXEC_EXIT0 1 |
| 2124 | ret AT_OK |
| 2125 | end |
| 2126 | ret AT_ERR_BAD_CASE |
| 2127 | end |
| 2128 | |
| 2129 | note CLI argument parser and command dispatcher (main.rs::run + receipt_cmd.rs::run) |
| 2130 | fn at_cli_dispatch_rcp argc ulong a2 view uchar * to int |
| 2131 | if at_bytes_eq a2 at_kw_inspect |
| 2132 | if eq argc 4 |
| 2133 | ret AT_CMD_RCP_INSPECT |
| 2134 | end |
| 2135 | ret AT_CMD_INVALID |
| 2136 | end |
| 2137 | if at_bytes_eq a2 at_kw_check |
| 2138 | if eq argc 5 |
| 2139 | ret AT_CMD_RCP_CHECK |
| 2140 | end |
| 2141 | ret AT_CMD_INVALID |
| 2142 | end |
| 2143 | if at_bytes_eq a2 at_kw_from_hex |
| 2144 | if eq argc 5 |
| 2145 | ret AT_CMD_RCP_FROM_HEX |
| 2146 | end |
| 2147 | ret AT_CMD_INVALID |
| 2148 | end |
| 2149 | if at_bytes_eq a2 at_kw_sign_test |
| 2150 | if eq argc 5 |
| 2151 | ret AT_CMD_RCP_SIGN_TEST |
| 2152 | end |
| 2153 | ret AT_CMD_INVALID |
| 2154 | end |
| 2155 | if at_bytes_eq a2 at_kw_verify |
| 2156 | if eq argc 4 |
| 2157 | ret AT_CMD_RCP_VERIFY |
| 2158 | end |
| 2159 | ret AT_CMD_INVALID |
| 2160 | end |
| 2161 | ret AT_CMD_INVALID |
| 2162 | end |
| 2163 | |
| 2164 | fn at_cli_dispatch argc ulong a1 view uchar * a2 view uchar * test_mode bool to int |
| 2165 | if lt argc 2 |
| 2166 | ret AT_CMD_INVALID |
| 2167 | end |
| 2168 | if at_bytes_eq a1 at_kw_pack |
| 2169 | if eq argc 6 |
| 2170 | ret AT_CMD_PACK |
| 2171 | end |
| 2172 | ret AT_CMD_INVALID |
| 2173 | end |
| 2174 | if at_bytes_eq a1 at_kw_inspect |
| 2175 | if eq argc 3 |
| 2176 | ret AT_CMD_INSPECT |
| 2177 | end |
| 2178 | ret AT_CMD_INVALID |
| 2179 | end |
| 2180 | if at_bytes_eq a1 at_kw_id |
| 2181 | if eq argc 3 |
| 2182 | ret AT_CMD_ID |
| 2183 | end |
| 2184 | ret AT_CMD_INVALID |
| 2185 | end |
| 2186 | if at_bytes_eq a1 at_kw_sign |
| 2187 | if eq argc 4 |
| 2188 | ret AT_CMD_SIGN |
| 2189 | end |
| 2190 | ret AT_CMD_INVALID |
| 2191 | end |
| 2192 | if at_bytes_eq a1 at_kw_verify |
| 2193 | if eq argc 3 |
| 2194 | ret AT_CMD_VERIFY |
| 2195 | end |
| 2196 | ret AT_CMD_INVALID |
| 2197 | end |
| 2198 | if at_bytes_eq a1 at_kw_neg_corpus |
| 2199 | if test_mode |
| 2200 | if eq argc 3 |
| 2201 | ret AT_CMD_NEG_CORPUS |
| 2202 | end |
| 2203 | end |
| 2204 | ret AT_CMD_INVALID |
| 2205 | end |
| 2206 | if at_bytes_eq a1 at_kw_receipt |
| 2207 | ret at_cli_dispatch_rcp argc a2 |
| 2208 | end |
| 2209 | ret AT_CMD_INVALID |
| 2210 | end |