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 / receipt.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note aienux/crates/aienos-artifact/receipt.om: Pure-Omega Admission Receipt v0 (ADR 0014 s7) |
| 3 | note 512-byte canonical encoder, strict fail-closed decoder, semantic validator, |
| 4 | note nonce/identity builders, and Ed25519 signing/verification. |
| 5 | note Converted from aienux crates/aienos-artifact/src/receipt.rs. |
| 6 | note Compose after: 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 |
| 7 | |
| 8 | const RCP_VERSION ulong 0 |
| 9 | const RCP_HEADER_SIZE ulong 96 |
| 10 | const RCP_SIZE ulong 512 |
| 11 | const RCP_SIG_OFFSET ulong 400 |
| 12 | const RCP_SIG_MSG_SIZE ulong 70 |
| 13 | |
| 14 | note Presence flags (offset 16) |
| 15 | const RCP_FLAG_MACHINE_ID ulong 1 |
| 16 | const RCP_FLAG_CONTEXT_ID ulong 2 |
| 17 | const RCP_FLAG_TIMESTAMP ulong 4 |
| 18 | const RCP_VALID_FLAGS ulong 7 |
| 19 | |
| 20 | note Result flags (offset 72) |
| 21 | const RCP_RES_READ_OK ulong 1 |
| 22 | const RCP_RES_WRITE_DENIED ulong 2 |
| 23 | const RCP_RES_RECLAIMED ulong 4 |
| 24 | const RCP_RES_CANARY_PASSED ulong 8 |
| 25 | const RCP_RES_FORGED_DENIED ulong 16 |
| 26 | const RCP_RES_MAPPED_BYTES_MATCH ulong 32 |
| 27 | const RCP_RES_EXECUTED_BYTES_MATCH ulong 64 |
| 28 | const RCP_RES_WX_SEALED ulong 128 |
| 29 | const RCP_VALID_RES_FLAGS ulong 255 |
| 30 | |
| 31 | note ReceiptDecision enum values |
| 32 | const RCP_DEC_ADMITTED ulong 1 |
| 33 | const RCP_DEC_REJECTED ulong 2 |
| 34 | const RCP_DEC_CANARY_FAILED ulong 3 |
| 35 | const RCP_DEC_DESTROYED ulong 4 |
| 36 | |
| 37 | note QualificationTier enum values |
| 38 | const RCP_TIER_QEMU ulong 1 |
| 39 | const RCP_TIER_MACHINE1 ulong 2 |
| 40 | const RCP_TIER_PI5 ulong 3 |
| 41 | |
| 42 | note ExecutionStatusCode enum values |
| 43 | const RCP_EXEC_NOT_RUN ulong 0 |
| 44 | const RCP_EXEC_EXITED ulong 1 |
| 45 | const RCP_EXEC_TIMEOUT ulong 2 |
| 46 | const RCP_EXEC_FAULT ulong 3 |
| 47 | const RCP_EXEC_BAD_SYSCALL ulong 4 |
| 48 | const RCP_EXEC_RESOURCE_OVERRUN ulong 5 |
| 49 | const RCP_EXEC_CANARY_FAILED ulong 6 |
| 50 | |
| 51 | note Stage and loader reason bounds |
| 52 | const RCP_MAX_REJECTION_STAGE ulong 9 |
| 53 | const RCP_LOADER_REASON_FIRST ulong 0x101 |
| 54 | const RCP_LOADER_REASON_LAST ulong 0x10a |
| 55 | const RCP_MAX_ANCHORS ulong 8 |
| 56 | |
| 57 | note Domain and label strings (domains get trailing NUL byte when hashed/framed) |
| 58 | text rcp_magic_pfx "AIENRCP" |
| 59 | text rcp_sig_dom_pfx "AIENOS-ADMISSION-RECEIPT-SIGNATURE-V1" |
| 60 | text rcp_dig_dom_pfx "AIENOS-ADMISSION-RECEIPT-V1" |
| 61 | text rcp_nonce_dom_pfx "AIENOS-ADMISSION-RECEIPT-NONCE-V1" |
| 62 | text rcp_lbl_qemu "SEED-0B-QEMU" |
| 63 | text rcp_lbl_machine1 "SEED-0B-MACHINE1" |
| 64 | text rcp_lbl_pi5 "SEED-0B-PI5" |
| 65 | |
| 66 | note Working receipt record in globals |
| 67 | note rcp_scalars slots: |
| 68 | note 0=flags, 1=decision, 2=tier, 3=sequence, 4=observed_time_ns, |
| 69 | note 5=execution_status, 6=result_flags, 7=rejection_stage, 8=rejection_reason, |
| 70 | note 9=syscalls, 10=object_reads_ok, 11=denials, 12=frames_reserved, |
| 71 | note 13=generation, 14=context_id |
| 72 | global rcp_scalars ulong 15 |
| 73 | global rcp_exit_status int 1 |
| 74 | global rcp_nonce_buf uchar 16 |
| 75 | note 9 digests * 32 bytes = 288 bytes: |
| 76 | note 0: artifact_id (offset 96) |
| 77 | note 1: payload_digest (offset 128) |
| 78 | note 2: artifact_signer_fingerprint (offset 160) |
| 79 | note 3: policy_digest (offset 192) |
| 80 | note 4: requested_capability_digest (offset 224) |
| 81 | note 5: granted_capability_digest (offset 256) |
| 82 | note 6: resource_envelope_digest (offset 288) |
| 83 | note 7: verifier_identity (offset 320) |
| 84 | note 8: machine_id_digest (offset 352) |
| 85 | global rcp_digests uchar 288 |
| 86 | |
| 87 | note Receipt trust anchor table (distinct from artifact anchors) |
| 88 | global rcp_anchor_cnt ulong 1 |
| 89 | global rcp_anchor_pks uchar 256 |
| 90 | |
| 91 | fn rcp_clear to void |
| 92 | for i ulong 15 |
| 93 | put rcp_scalars i 0 |
| 94 | end |
| 95 | put rcp_exit_status 0 0 |
| 96 | for i ulong 16 |
| 97 | put rcp_nonce_buf i 0 |
| 98 | end |
| 99 | for i ulong 288 |
| 100 | put rcp_digests i 0 |
| 101 | end |
| 102 | end |
| 103 | |
| 104 | fn rcp_set_digest idx ulong src view uchar * to void |
| 105 | base = mul idx 32 |
| 106 | for i ulong 32 |
| 107 | put rcp_digests add base i get src i |
| 108 | end |
| 109 | end |
| 110 | |
| 111 | fn rcp_get_digest idx ulong dst edit uchar * to void |
| 112 | base = mul idx 32 |
| 113 | for i ulong 32 |
| 114 | put dst i get rcp_digests add base i |
| 115 | end |
| 116 | end |
| 117 | |
| 118 | fn rcp_put_i32_le buf edit uchar * off ulong v int to void |
| 119 | u = ulong 0 |
| 120 | if ge v 0 |
| 121 | u = ulong v |
| 122 | else |
| 123 | u = ulong add long v 4294967296 |
| 124 | end |
| 125 | art_put_u32_le buf off u |
| 126 | end |
| 127 | |
| 128 | fn rcp_get_i32_le buf view uchar * off ulong to int |
| 129 | u = art_get_u32_le buf off |
| 130 | if ge u 2147483648 |
| 131 | ret int sub long u 4294967296 |
| 132 | end |
| 133 | ret int u |
| 134 | end |
| 135 | |
| 136 | note Canonical 512-byte encoding with all-zero signature block (receipt::encode) |
| 137 | fn rcp_encode dst edit uchar * to int |
| 138 | if lt len dst RCP_SIZE |
| 139 | ret ART_ERR_TRUNCATED |
| 140 | end |
| 141 | for i ulong 512 |
| 142 | put dst i 0 |
| 143 | end |
| 144 | for i ulong 7 |
| 145 | put dst i get rcp_magic_pfx i |
| 146 | end |
| 147 | put dst 7 0 |
| 148 | art_put_u16_le dst 8 RCP_VERSION |
| 149 | art_put_u16_le dst 10 RCP_HEADER_SIZE |
| 150 | art_put_u32_le dst 12 RCP_SIZE |
| 151 | art_put_u32_le dst 16 get rcp_scalars 0 |
| 152 | art_put_u16_le dst 20 get rcp_scalars 1 |
| 153 | art_put_u16_le dst 22 get rcp_scalars 2 |
| 154 | art_put_u64_le dst 24 get rcp_scalars 3 |
| 155 | for i ulong 16 |
| 156 | put dst add 32 i get rcp_nonce_buf i |
| 157 | end |
| 158 | art_put_u64_le dst 48 get rcp_scalars 4 |
| 159 | art_put_u32_le dst 64 get rcp_scalars 5 |
| 160 | rcp_put_i32_le dst 68 get rcp_exit_status 0 |
| 161 | art_put_u32_le dst 72 get rcp_scalars 6 |
| 162 | art_put_u16_le dst 76 get rcp_scalars 7 |
| 163 | art_put_u16_le dst 78 get rcp_scalars 8 |
| 164 | art_put_u32_le dst 80 get rcp_scalars 9 |
| 165 | art_put_u32_le dst 84 get rcp_scalars 10 |
| 166 | art_put_u32_le dst 88 get rcp_scalars 11 |
| 167 | art_put_u32_le dst 92 get rcp_scalars 12 |
| 168 | for i ulong 288 |
| 169 | put dst add 96 i get rcp_digests i |
| 170 | end |
| 171 | art_put_u64_le dst 384 get rcp_scalars 13 |
| 172 | art_put_u64_le dst 392 get rcp_scalars 14 |
| 173 | ret ART_OK |
| 174 | end |
| 175 | |
| 176 | note SHA256("AIENOS-ADMISSION-RECEIPT-V1\0" || bytes[0..400]) |
| 177 | fn rcp_digest bytes view uchar * dst edit uchar * to void |
| 178 | art_sha256_dom rcp_dig_dom_pfx part bytes 0 RCP_SIG_OFFSET dst |
| 179 | end |
| 180 | |
| 181 | note Deterministic per-context nonce: first 16 bytes of SHA256(NONCE_DOMAIN || verifier_id || seq_le) |
| 182 | fn rcp_nonce verifier_id view uchar * seq ulong dst edit uchar * to void |
| 183 | ctx = new ulong 40 0 |
| 184 | nul = new uchar 1 0 |
| 185 | seqb = new uchar 8 0 |
| 186 | art_put_u64_le seqb 0 seq |
| 187 | sha256_init ctx |
| 188 | sha256_update ctx rcp_nonce_dom_pfx |
| 189 | sha256_update ctx nul |
| 190 | sha256_update ctx part verifier_id 0 32 |
| 191 | sha256_update ctx seqb |
| 192 | dig = new uchar 32 0 |
| 193 | sha256_final ctx dig |
| 194 | for i ulong 16 |
| 195 | put dst i get dig i |
| 196 | end |
| 197 | end |
| 198 | |
| 199 | note Canonical 45-byte verifier build identity (returns 45 on valid 40-char lowercase hex commit, else -1) |
| 200 | fn rcp_verifier_identity_bytes commit view uchar * target ulong abi ulong feat uchar dst edit uchar 45 to int |
| 201 | if ne len commit 40 |
| 202 | ret -1 |
| 203 | end |
| 204 | for i ulong 40 |
| 205 | c = get commit i |
| 206 | is_dig = and ge c 48 le c 57 |
| 207 | is_af = and ge c 97 le c 102 |
| 208 | if not or is_dig is_af |
| 209 | ret -1 |
| 210 | end |
| 211 | put dst i c |
| 212 | end |
| 213 | art_put_u16_le dst 40 target |
| 214 | art_put_u16_le dst 42 abi |
| 215 | put dst 44 feat |
| 216 | ret 45 |
| 217 | end |
| 218 | |
| 219 | fn rcp_tier_label_copy tier ulong dst edit uchar * to ulong |
| 220 | if eq tier RCP_TIER_QEMU |
| 221 | n = len rcp_lbl_qemu |
| 222 | for i ulong n bound 32 |
| 223 | put dst i get rcp_lbl_qemu i |
| 224 | end |
| 225 | ret n |
| 226 | end |
| 227 | if eq tier RCP_TIER_MACHINE1 |
| 228 | n = len rcp_lbl_machine1 |
| 229 | for i ulong n bound 32 |
| 230 | put dst i get rcp_lbl_machine1 i |
| 231 | end |
| 232 | ret n |
| 233 | end |
| 234 | if eq tier RCP_TIER_PI5 |
| 235 | n = len rcp_lbl_pi5 |
| 236 | for i ulong n bound 32 |
| 237 | put dst i get rcp_lbl_pi5 i |
| 238 | end |
| 239 | ret n |
| 240 | end |
| 241 | ret 0 |
| 242 | end |
| 243 | |
| 244 | fn rcp_valid_reason code ulong to bool |
| 245 | if and ge code 1 le code 19 |
| 246 | ret true |
| 247 | end |
| 248 | if and ge code RCP_LOADER_REASON_FIRST le code RCP_LOADER_REASON_LAST |
| 249 | ret true |
| 250 | end |
| 251 | ret false |
| 252 | end |
| 253 | |
| 254 | fn rcp_machine_id_is_zero to bool |
| 255 | for i ulong 32 |
| 256 | if ne get rcp_digests add 256 i 0 |
| 257 | ret false |
| 258 | end |
| 259 | end |
| 260 | ret true |
| 261 | end |
| 262 | |
| 263 | note s7.1 / s7.3 semantic validation of working receipt |
| 264 | fn rcp_validate to int |
| 265 | if eq and get rcp_scalars 0 RCP_FLAG_MACHINE_ID 0 |
| 266 | if not rcp_machine_id_is_zero |
| 267 | ret ART_ERR_MALFORMED_RECEIPT |
| 268 | end |
| 269 | end |
| 270 | if eq and get rcp_scalars 0 RCP_FLAG_CONTEXT_ID 0 |
| 271 | if or ne get rcp_scalars 13 0 ne get rcp_scalars 14 0 |
| 272 | ret ART_ERR_MALFORMED_RECEIPT |
| 273 | end |
| 274 | end |
| 275 | if eq and get rcp_scalars 0 RCP_FLAG_TIMESTAMP 0 |
| 276 | if ne get rcp_scalars 4 0 |
| 277 | ret ART_ERR_MALFORMED_RECEIPT |
| 278 | end |
| 279 | end |
| 280 | rst = get rcp_scalars 7 |
| 281 | rrs = get rcp_scalars 8 |
| 282 | if gt rst RCP_MAX_REJECTION_STAGE |
| 283 | ret ART_ERR_MALFORMED_RECEIPT |
| 284 | end |
| 285 | if ne rrs 0 |
| 286 | if not rcp_valid_reason rrs |
| 287 | ret ART_ERR_MALFORMED_RECEIPT |
| 288 | end |
| 289 | end |
| 290 | dec = get rcp_scalars 1 |
| 291 | es = get rcp_scalars 5 |
| 292 | ex = get rcp_exit_status 0 |
| 293 | rf = get rcp_scalars 6 |
| 294 | if eq dec RCP_DEC_REJECTED |
| 295 | if or eq rst 0 eq rrs 0 |
| 296 | ret ART_ERR_MALFORMED_RECEIPT |
| 297 | end |
| 298 | if or ne es RCP_EXEC_NOT_RUN ne ex 0 |
| 299 | ret ART_ERR_MALFORMED_RECEIPT |
| 300 | end |
| 301 | if or ne get rcp_scalars 9 0 ne get rcp_scalars 10 0 |
| 302 | ret ART_ERR_MALFORMED_RECEIPT |
| 303 | end |
| 304 | if ne get rcp_scalars 11 0 |
| 305 | ret ART_ERR_MALFORMED_RECEIPT |
| 306 | end |
| 307 | if ne and rf not RCP_RES_RECLAIMED 0 |
| 308 | ret ART_ERR_MALFORMED_RECEIPT |
| 309 | end |
| 310 | else |
| 311 | if or ne rst 0 ne rrs 0 |
| 312 | ret ART_ERR_MALFORMED_RECEIPT |
| 313 | end |
| 314 | end |
| 315 | if ne eq dec RCP_DEC_CANARY_FAILED eq es RCP_EXEC_CANARY_FAILED |
| 316 | ret ART_ERR_MALFORMED_RECEIPT |
| 317 | end |
| 318 | if ne and rf RCP_RES_CANARY_PASSED 0 |
| 319 | if or ne es RCP_EXEC_EXITED ne ex 0 |
| 320 | ret ART_ERR_MALFORMED_RECEIPT |
| 321 | end |
| 322 | end |
| 323 | vid = new uchar 32 0 |
| 324 | rcp_get_digest 7 vid |
| 325 | exp_n = new uchar 16 0 |
| 326 | rcp_nonce vid get rcp_scalars 3 exp_n |
| 327 | for i ulong 16 |
| 328 | if ne get rcp_nonce_buf i get exp_n i |
| 329 | ret ART_ERR_MALFORMED_RECEIPT |
| 330 | end |
| 331 | end |
| 332 | ret ART_OK |
| 333 | end |
| 334 | |
| 335 | note Strict fail-closed decode of 512-byte receipt record (receipt::decode) |
| 336 | fn rcp_decode_header bytes view uchar * to int |
| 337 | n = len bytes |
| 338 | if lt n RCP_SIZE |
| 339 | ret ART_ERR_TRUNCATED |
| 340 | end |
| 341 | if gt n RCP_SIZE |
| 342 | ret ART_ERR_WRONG_LENGTH |
| 343 | end |
| 344 | for i ulong 7 |
| 345 | if ne get bytes i get rcp_magic_pfx i |
| 346 | ret ART_ERR_BAD_MAGIC |
| 347 | end |
| 348 | end |
| 349 | if ne get bytes 7 0 |
| 350 | ret ART_ERR_BAD_MAGIC |
| 351 | end |
| 352 | if or ne art_get_u16_le bytes 8 RCP_VERSION ne art_get_u16_le bytes 10 RCP_HEADER_SIZE |
| 353 | ret ART_ERR_UNSUPPORTED_VERSION |
| 354 | end |
| 355 | if ne art_get_u32_le bytes 12 RCP_SIZE |
| 356 | ret ART_ERR_UNSUPPORTED_VERSION |
| 357 | end |
| 358 | fl = art_get_u32_le bytes 16 |
| 359 | rf = art_get_u32_le bytes 72 |
| 360 | if or ne and fl not RCP_VALID_FLAGS 0 ne and rf not RCP_VALID_RES_FLAGS 0 |
| 361 | ret ART_ERR_UNSUPPORTED_FLAGS |
| 362 | end |
| 363 | if or not art_all_zero bytes 56 8 not art_all_zero bytes 500 12 |
| 364 | ret ART_ERR_RESERVED_NON_ZERO |
| 365 | end |
| 366 | if not art_all_zero bytes 400 100 |
| 367 | if ne art_get_u16_le bytes 400 ART_SIG_ALG_ED25519 |
| 368 | ret ART_ERR_BAD_SIGNATURE_FORMAT |
| 369 | end |
| 370 | if not art_all_zero bytes 402 2 |
| 371 | ret ART_ERR_RESERVED_NON_ZERO |
| 372 | end |
| 373 | end |
| 374 | ret ART_OK |
| 375 | end |
| 376 | |
| 377 | fn rcp_decode bytes view uchar * to int |
| 378 | rc = rcp_decode_header bytes |
| 379 | if ne rc ART_OK |
| 380 | ret rc |
| 381 | end |
| 382 | dec = art_get_u16_le bytes 20 |
| 383 | if or lt dec 1 gt dec 4 |
| 384 | ret ART_ERR_MALFORMED_RECEIPT |
| 385 | end |
| 386 | tier = art_get_u16_le bytes 22 |
| 387 | if or lt tier 1 gt tier 3 |
| 388 | ret ART_ERR_MALFORMED_RECEIPT |
| 389 | end |
| 390 | es = art_get_u32_le bytes 64 |
| 391 | if gt es 6 |
| 392 | ret ART_ERR_MALFORMED_RECEIPT |
| 393 | end |
| 394 | put rcp_scalars 0 art_get_u32_le bytes 16 |
| 395 | put rcp_scalars 1 dec |
| 396 | put rcp_scalars 2 tier |
| 397 | put rcp_scalars 3 art_get_u64_le bytes 24 |
| 398 | for i ulong 16 |
| 399 | put rcp_nonce_buf i get bytes add 32 i |
| 400 | end |
| 401 | put rcp_scalars 4 art_get_u64_le bytes 48 |
| 402 | put rcp_scalars 5 es |
| 403 | put rcp_exit_status 0 rcp_get_i32_le bytes 68 |
| 404 | put rcp_scalars 6 art_get_u32_le bytes 72 |
| 405 | put rcp_scalars 7 art_get_u16_le bytes 76 |
| 406 | put rcp_scalars 8 art_get_u16_le bytes 78 |
| 407 | put rcp_scalars 9 art_get_u32_le bytes 80 |
| 408 | put rcp_scalars 10 art_get_u32_le bytes 84 |
| 409 | put rcp_scalars 11 art_get_u32_le bytes 88 |
| 410 | put rcp_scalars 12 art_get_u32_le bytes 92 |
| 411 | for i ulong 288 |
| 412 | put rcp_digests i get bytes add 96 i |
| 413 | end |
| 414 | put rcp_scalars 13 art_get_u64_le bytes 384 |
| 415 | put rcp_scalars 14 art_get_u64_le bytes 392 |
| 416 | ret rcp_validate |
| 417 | end |
| 418 | |
| 419 | fn rcp_is_unsigned bytes view uchar * to bool |
| 420 | ret art_all_zero bytes RCP_SIG_OFFSET 112 |
| 421 | end |
| 422 | |
| 423 | note Build 70-byte receipt signature message: "AIENOS-ADMISSION-RECEIPT-SIGNATURE-V1\0" || digest |
| 424 | fn rcp_signature_message dig view uchar * msg_out edit uchar * to void |
| 425 | for i ulong 37 |
| 426 | put msg_out i get rcp_sig_dom_pfx i |
| 427 | end |
| 428 | put msg_out 37 0 |
| 429 | for i ulong 32 |
| 430 | put msg_out add 38 i get dig i |
| 431 | end |
| 432 | end |
| 433 | |
| 434 | note Sign a valid unsigned 512-byte receipt in place using 32-byte Ed25519 seed |
| 435 | fn rcp_sign bytes edit uchar * seed view uchar * to int |
| 436 | if ne len bytes RCP_SIZE |
| 437 | ret ART_ERR_WRONG_LENGTH |
| 438 | end |
| 439 | if not rcp_is_unsigned bytes |
| 440 | ret ART_ERR_BAD_SIGNATURE_FORMAT |
| 441 | end |
| 442 | rc = rcp_decode bytes |
| 443 | if ne rc ART_OK |
| 444 | ret rc |
| 445 | end |
| 446 | dig = new uchar 32 0 |
| 447 | rcp_digest bytes dig |
| 448 | msg = new uchar 70 0 |
| 449 | rcp_signature_message dig msg |
| 450 | pk = new uchar 32 0 |
| 451 | art_ed25519_pubkey seed pk |
| 452 | fp = new uchar 32 0 |
| 453 | art_signer_fingerprint pk fp |
| 454 | sg = new uchar 64 0 |
| 455 | art_ed25519_sign seed msg sg |
| 456 | art_put_u16_le bytes 400 ART_SIG_ALG_ED25519 |
| 457 | put bytes 402 0 |
| 458 | put bytes 403 0 |
| 459 | for i ulong 32 |
| 460 | put bytes add 404 i get fp i |
| 461 | end |
| 462 | for i ulong 64 |
| 463 | put bytes add 436 i get sg i |
| 464 | end |
| 465 | ret ART_OK |
| 466 | end |
| 467 | |
| 468 | note Receipt trust anchor set (distinct from artifact trust anchors) |
| 469 | fn rcp_anchors_clear to void |
| 470 | put rcp_anchor_cnt 0 0 |
| 471 | end |
| 472 | |
| 473 | fn rcp_anchors_add pk view uchar * to int |
| 474 | if ne len pk 32 |
| 475 | ret ART_ERR_BAD_SIGNATURE_FORMAT |
| 476 | end |
| 477 | cnt = get rcp_anchor_cnt 0 |
| 478 | if ge cnt RCP_MAX_ANCHORS |
| 479 | ret ART_ERR_RESOURCE_LIMIT |
| 480 | end |
| 481 | base = mul cnt 32 |
| 482 | for i ulong 32 |
| 483 | put rcp_anchor_pks add base i get pk i |
| 484 | end |
| 485 | put rcp_anchor_cnt 0 add cnt 1 |
| 486 | ret ART_OK |
| 487 | end |
| 488 | |
| 489 | note Populate RFC 8032 TEST 2 public key (Seed0bTestReceiptAnchorSet, TEST ONLY) |
| 490 | fn rcp_seed0b_test_pubkey dst edit uchar * to void |
| 491 | put dst 0 0x3d |
| 492 | put dst 1 0x40 |
| 493 | put dst 2 0x17 |
| 494 | put dst 3 0xc3 |
| 495 | put dst 4 0xe8 |
| 496 | put dst 5 0x43 |
| 497 | put dst 6 0x89 |
| 498 | put dst 7 0x5a |
| 499 | put dst 8 0x92 |
| 500 | put dst 9 0xb7 |
| 501 | put dst 10 0x0a |
| 502 | put dst 11 0xa7 |
| 503 | put dst 12 0x4d |
| 504 | put dst 13 0x1b |
| 505 | put dst 14 0x7e |
| 506 | put dst 15 0xbc |
| 507 | put dst 16 0x9c |
| 508 | put dst 17 0x98 |
| 509 | put dst 18 0x2c |
| 510 | put dst 19 0xcf |
| 511 | put dst 20 0x2e |
| 512 | put dst 21 0xc4 |
| 513 | put dst 22 0x96 |
| 514 | put dst 23 0x8c |
| 515 | put dst 24 0xc0 |
| 516 | put dst 25 0xcd |
| 517 | put dst 26 0x55 |
| 518 | put dst 27 0xf1 |
| 519 | put dst 28 0x2a |
| 520 | put dst 29 0xf4 |
| 521 | put dst 30 0x66 |
| 522 | put dst 31 0x0c |
| 523 | end |
| 524 | |
| 525 | fn rcp_anchors_add_seed0b_test to int |
| 526 | pk = new uchar 32 0 |
| 527 | rcp_seed0b_test_pubkey pk |
| 528 | ret rcp_anchors_add pk |
| 529 | end |
| 530 | |
| 531 | fn rcp_anchors_find fp view uchar * pk_out edit uchar * to bool |
| 532 | cnt = get rcp_anchor_cnt 0 |
| 533 | cand = new uchar 32 0 |
| 534 | cfp = new uchar 32 0 |
| 535 | for idx ulong cnt bound 8 |
| 536 | base = mul idx 32 |
| 537 | for i ulong 32 |
| 538 | put cand i get rcp_anchor_pks add base i |
| 539 | end |
| 540 | art_signer_fingerprint cand cfp |
| 541 | if art_bytes_eq fp cfp |
| 542 | for i ulong 32 |
| 543 | put pk_out i get cand i |
| 544 | end |
| 545 | ret true |
| 546 | end |
| 547 | end |
| 548 | ret false |
| 549 | end |
| 550 | |
| 551 | note Decode and authenticate a signed 512-byte receipt record (receipt::verify) |
| 552 | fn rcp_verify bytes view uchar * to int |
| 553 | rc = rcp_decode bytes |
| 554 | if ne rc ART_OK |
| 555 | ret rc |
| 556 | end |
| 557 | if rcp_is_unsigned bytes |
| 558 | ret ART_ERR_BAD_SIGNATURE_FORMAT |
| 559 | end |
| 560 | fp = new uchar 32 0 |
| 561 | for i ulong 32 |
| 562 | put fp i get bytes add 404 i |
| 563 | end |
| 564 | pk = new uchar 32 0 |
| 565 | if not rcp_anchors_find fp pk |
| 566 | ret ART_ERR_UNTRUSTED_SIGNER |
| 567 | end |
| 568 | chk_fp = new uchar 32 0 |
| 569 | art_signer_fingerprint pk chk_fp |
| 570 | if not art_bytes_eq chk_fp fp |
| 571 | ret ART_ERR_UNTRUSTED_SIGNER |
| 572 | end |
| 573 | sg = new uchar 64 0 |
| 574 | for i ulong 64 |
| 575 | put sg i get bytes add 436 i |
| 576 | end |
| 577 | dig = new uchar 32 0 |
| 578 | rcp_digest bytes dig |
| 579 | msg = new uchar 70 0 |
| 580 | rcp_signature_message dig msg |
| 581 | if not art_ed25519_verify pk msg sg |
| 582 | ret ART_ERR_BAD_SIGNATURE |
| 583 | end |
| 584 | ret ART_OK |
| 585 | end |