CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
CUDApp / tests / portable_receipts.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note HOST_ONLY portable public receipt inverse checker. Compose om/cache/digest.om first. |
| 3 | note argv: original-file derived-file original-git-blob. Original is supplied by git cat-file. |
| 4 | note No writes, network, GPU, truststore or production authority. All refusals are nonzero. |
| 5 | note Buffers bound each input to 262144 bytes; capacity and read errors fail closed. |
| 6 | text prhome "/home/" |
| 7 | text prplace "$AIEN_RECEIPT_HOME" |
| 8 | text prkey "\"_portable_derivation\"" |
| 9 | text prhex "0123456789abcdef" |
| 10 | text prm0 " \"_portable_derivation\":{\"schema\":\"AIEN_PORTABLE_RECEIPT_V1\",\"original_sha256\":\"" |
| 11 | text prm1 "\",\"original_git_blob\":\"" |
| 12 | text prm2 "\",\"placeholder\":\"$AIEN_RECEIPT_HOME\",\"rule\":\"Remove this metadata line and replace the placeholder with the producer HOME prefix obtained from the original Git blob.\",\"scrubbed_sha256\":\"" |
| 13 | text prm3 "\",\"scrubbed_hash_domain\":\"document bytes with exactly the _portable_derivation metadata line removed\"},\n" |
| 14 | text prpass "PORTABLE_RECEIPT HOST_ONLY PASS controls=11\n" |
| 15 | global pro uchar 262144 |
| 16 | global prd uchar 262144 |
| 17 | global prr uchar 262144 |
| 18 | global prs uchar 262144 |
| 19 | global prh uchar 256 |
| 20 | global prm uchar 1024 |
| 21 | global prb uchar 40 |
| 22 | global prn ulong 7 |
| 23 | note prn: original length, derived length, HOME length, metadata length, first body placeholder, |
| 24 | note scrubbed length, scrubbed metadata hash offset. Scrubbed domain excludes exactly the added line. |
| 25 | fn pr_load which ulong to bool |
| 26 | pathbuf = new uchar 4096 0 |
| 27 | extra = new uchar 1 0 |
| 28 | n = argread add which 1 pathbuf 0 len pathbuf |
| 29 | if le n 0 |
| 30 | ret false |
| 31 | end |
| 32 | fd = fopen pathbuf 0 ulong n 0 0 |
| 33 | if lt fd 0 |
| 34 | ret false |
| 35 | end |
| 36 | pos = ulong 0 |
| 37 | ok = true |
| 38 | while lt pos 262144 bound 262144 |
| 39 | k = long 0 |
| 40 | if eq which 0 |
| 41 | k = read int fd pro pos sub ulong 262144 pos |
| 42 | else |
| 43 | k = read int fd prd pos sub ulong 262144 pos |
| 44 | end |
| 45 | if lt k 0 |
| 46 | ok = false |
| 47 | break |
| 48 | end |
| 49 | if eq k 0 |
| 50 | break |
| 51 | end |
| 52 | pos = add pos ulong k |
| 53 | end |
| 54 | if eq pos 262144 |
| 55 | k = read int fd extra 0 1 |
| 56 | if ne k 0 |
| 57 | ok = false |
| 58 | end |
| 59 | end |
| 60 | if ne fclose int fd 0 |
| 61 | ok = false |
| 62 | end |
| 63 | put prn which pos |
| 64 | ret ok |
| 65 | end |
| 66 | fn pr_user c uchar to bool |
| 67 | if and ge c 97 le c 122 |
| 68 | ret true |
| 69 | end |
| 70 | if and ge c 65 le c 90 |
| 71 | ret true |
| 72 | end |
| 73 | if and ge c 48 le c 57 |
| 74 | ret true |
| 75 | end |
| 76 | ret or eq c 95 or eq c 45 eq c 46 |
| 77 | end |
| 78 | note Keep delimiter alternatives shallow at the pinned non-spilling register allocator. |
| 79 | fn pr_delim c uchar to bool |
| 80 | if or eq c 47 eq c 34 |
| 81 | ret true |
| 82 | end |
| 83 | if or eq c 32 eq c 10 |
| 84 | ret true |
| 85 | end |
| 86 | ret or eq c 9 eq c 39 |
| 87 | end |
| 88 | fn pr_ohome p ulong to bool |
| 89 | if gt add p len prhome get prn 0 |
| 90 | ret false |
| 91 | end |
| 92 | for i ulong len prhome |
| 93 | if ne get pro add p i get prhome i |
| 94 | ret false |
| 95 | end |
| 96 | end |
| 97 | ret true |
| 98 | end |
| 99 | fn pr_oplace p ulong to bool |
| 100 | if gt add p len prplace get prn 0 |
| 101 | ret false |
| 102 | end |
| 103 | for i ulong len prplace |
| 104 | if ne get pro add p i get prplace i |
| 105 | ret false |
| 106 | end |
| 107 | end |
| 108 | ret true |
| 109 | end |
| 110 | fn pr_dplace p ulong to bool |
| 111 | if gt add p len prplace get prn 1 |
| 112 | ret false |
| 113 | end |
| 114 | for i ulong len prplace |
| 115 | if ne get prd add p i get prplace i |
| 116 | ret false |
| 117 | end |
| 118 | end |
| 119 | ret true |
| 120 | end |
| 121 | fn pr_okey p ulong to bool |
| 122 | if gt add p len prkey get prn 0 |
| 123 | ret false |
| 124 | end |
| 125 | for i ulong len prkey |
| 126 | if ne get pro add p i get prkey i |
| 127 | ret false |
| 128 | end |
| 129 | end |
| 130 | ret true |
| 131 | end |
| 132 | fn pr_infer to bool |
| 133 | put prn 2 0 |
| 134 | for p ulong get prn 0 |
| 135 | if or pr_oplace p pr_okey p |
| 136 | ret false |
| 137 | end |
| 138 | if pr_ohome p |
| 139 | q = add p len prhome |
| 140 | while lt q get prn 0 bound 256 |
| 141 | if not pr_user get pro q |
| 142 | break |
| 143 | end |
| 144 | q = add q 1 |
| 145 | if ge sub q p 256 |
| 146 | ret false |
| 147 | end |
| 148 | end |
| 149 | if eq q add p len prhome |
| 150 | ret false |
| 151 | end |
| 152 | note Require a complete username and an unescaped path delimiter, not a truncated suffix. |
| 153 | if eq q get prn 0 |
| 154 | ret false |
| 155 | end |
| 156 | c = get pro q |
| 157 | if not pr_delim c |
| 158 | ret false |
| 159 | end |
| 160 | n = sub q p |
| 161 | if eq get prn 2 0 |
| 162 | put prn 2 n |
| 163 | for j ulong n |
| 164 | put prh j get pro add p j |
| 165 | end |
| 166 | else |
| 167 | if ne n get prn 2 |
| 168 | ret false |
| 169 | end |
| 170 | for j ulong n |
| 171 | if ne get prh j get pro add p j |
| 172 | ret false |
| 173 | end |
| 174 | end |
| 175 | end |
| 176 | end |
| 177 | end |
| 178 | ret gt get prn 2 6 |
| 179 | end |
| 180 | note Reuse existing SHA ABI. Separate transport/scheduling/tail stages keep register scopes bounded. |
| 181 | fn pr_source which ulong p ulong to uchar |
| 182 | if eq which 0 |
| 183 | ret get pro p |
| 184 | end |
| 185 | if eq which 1 |
| 186 | ret get prr p |
| 187 | end |
| 188 | ret get prs p |
| 189 | end |
| 190 | fn pr_schedule which ulong off ulong w edit uint 64 to void |
| 191 | block = new uchar 4096 0 |
| 192 | for j ulong 64 |
| 193 | p = add off j |
| 194 | put block j pr_source which p |
| 195 | end |
| 196 | kc_sched w block 0 |
| 197 | end |
| 198 | fn pr_tail which ulong n ulong padbuf edit uchar 128 to void |
| 199 | base = mul div n 64 64 |
| 200 | for j ulong rem n 64 |
| 201 | p = add base j |
| 202 | put padbuf j pr_source which p |
| 203 | end |
| 204 | end |
| 205 | fn pr_hash which ulong out edit uchar 32 to void |
| 206 | padbuf = new uchar 128 0 |
| 207 | s = new uint 8 0 |
| 208 | w = new uint 64 0 |
| 209 | kt = new uint 64 0 |
| 210 | kc_k kt |
| 211 | kc_iv s |
| 212 | n = get prn 0 |
| 213 | if eq which 2 |
| 214 | n = get prn 5 |
| 215 | end |
| 216 | for off ulong div n 64 |
| 217 | pr_schedule which mul off 64 w |
| 218 | kc_rounds s w kt |
| 219 | end |
| 220 | pr_tail which n padbuf |
| 221 | kc_finish s w kt padbuf n |
| 222 | kc_output s out |
| 223 | end |
| 224 | fn pr_metadata digest view uchar 32 scrub view uchar 32 to void |
| 225 | p = ulong 0 |
| 226 | for i ulong len prm0 |
| 227 | put prm p get prm0 i |
| 228 | p = add p 1 |
| 229 | end |
| 230 | for i ulong 32 |
| 231 | put prm p get prhex shr get digest i 4 |
| 232 | p = add p 1 |
| 233 | put prm p get prhex and get digest i 15 |
| 234 | p = add p 1 |
| 235 | end |
| 236 | for i ulong len prm1 |
| 237 | put prm p get prm1 i |
| 238 | p = add p 1 |
| 239 | end |
| 240 | for i ulong 40 |
| 241 | put prm p get prb i |
| 242 | p = add p 1 |
| 243 | end |
| 244 | for i ulong len prm2 |
| 245 | put prm p get prm2 i |
| 246 | p = add p 1 |
| 247 | end |
| 248 | put prn 6 p |
| 249 | for i ulong 32 |
| 250 | put prm p get prhex shr get scrub i 4 |
| 251 | p = add p 1 |
| 252 | put prm p get prhex and get scrub i 15 |
| 253 | p = add p 1 |
| 254 | end |
| 255 | for i ulong len prm3 |
| 256 | put prm p get prm3 i |
| 257 | p = add p 1 |
| 258 | end |
| 259 | put prn 3 p |
| 260 | end |
| 261 | fn pr_inverse to bool |
| 262 | p = add get prn 3 2 |
| 263 | q = ulong 2 |
| 264 | put prr 0 123 |
| 265 | put prr 1 10 |
| 266 | put prn 4 0 |
| 267 | while lt p get prn 1 bound 262144 |
| 268 | if pr_dplace p |
| 269 | if eq get prn 4 0 |
| 270 | put prn 4 p |
| 271 | end |
| 272 | if gt add q get prn 2 get prn 0 |
| 273 | ret false |
| 274 | end |
| 275 | for j ulong get prn 2 |
| 276 | put prr q get prh j |
| 277 | q = add q 1 |
| 278 | end |
| 279 | p = add p len prplace |
| 280 | else |
| 281 | if ge q get prn 0 |
| 282 | ret false |
| 283 | end |
| 284 | put prr q get prd p |
| 285 | q = add q 1 |
| 286 | p = add p 1 |
| 287 | end |
| 288 | end |
| 289 | if ne q get prn 0 |
| 290 | ret false |
| 291 | end |
| 292 | for i ulong q |
| 293 | if ne get pro i get prr i |
| 294 | ret false |
| 295 | end |
| 296 | end |
| 297 | ret ne get prn 4 0 |
| 298 | end |
| 299 | note Exact forward comparison additionally refuses missed substitutions and extra metadata anywhere. |
| 300 | fn pr_forward to bool |
| 301 | p = ulong 2 |
| 302 | q = add get prn 3 2 |
| 303 | while lt p get prn 0 bound 262144 |
| 304 | match = false |
| 305 | if le add p get prn 2 get prn 0 |
| 306 | match = true |
| 307 | for j ulong get prn 2 |
| 308 | if ne get pro add p j get prh j |
| 309 | match = false |
| 310 | end |
| 311 | end |
| 312 | end |
| 313 | if match |
| 314 | if gt add q len prplace get prn 1 |
| 315 | ret false |
| 316 | end |
| 317 | for j ulong len prplace |
| 318 | if ne get prd add q j get prplace j |
| 319 | ret false |
| 320 | end |
| 321 | end |
| 322 | q = add q len prplace |
| 323 | p = add p get prn 2 |
| 324 | else |
| 325 | if ge q get prn 1 |
| 326 | ret false |
| 327 | end |
| 328 | if ne get pro p get prd q |
| 329 | ret false |
| 330 | end |
| 331 | p = add p 1 |
| 332 | q = add q 1 |
| 333 | end |
| 334 | end |
| 335 | ret eq q get prn 1 |
| 336 | end |
| 337 | note Phase helpers isolate global-to-global byte transport from the digest-array register scope. |
| 338 | fn pr_strip to bool |
| 339 | m = get prn 3 |
| 340 | n = get prn 1 |
| 341 | if lt n add m 2 |
| 342 | ret false |
| 343 | end |
| 344 | n = sub n m |
| 345 | put prn 5 n |
| 346 | put prs 0 123 |
| 347 | put prs 1 10 |
| 348 | count = sub n 2 |
| 349 | for i ulong count |
| 350 | dst = add i 2 |
| 351 | src = add dst m |
| 352 | v = get prd src |
| 353 | put prs dst v |
| 354 | end |
| 355 | ret true |
| 356 | end |
| 357 | fn pr_metacheck to bool |
| 358 | count = get prn 3 |
| 359 | for i ulong count |
| 360 | src = add i 2 |
| 361 | v = get prd src |
| 362 | if ne get prm i v |
| 363 | ret false |
| 364 | end |
| 365 | end |
| 366 | ret true |
| 367 | end |
| 368 | fn pr_verify to int |
| 369 | sha = new uchar 32 0 |
| 370 | invsha = new uchar 32 0 |
| 371 | if or lt get prn 0 3 lt get prn 1 3 |
| 372 | ret 10 |
| 373 | end |
| 374 | if or ne get pro 0 123 ne get pro 1 10 |
| 375 | ret 11 |
| 376 | end |
| 377 | if or ne get prd 0 123 ne get prd 1 10 |
| 378 | ret 12 |
| 379 | end |
| 380 | if not pr_infer |
| 381 | ret 13 |
| 382 | end |
| 383 | pr_hash 0 sha |
| 384 | note First assemble only to determine the fixed metadata-line length; digest values cannot change it. |
| 385 | pr_metadata sha invsha |
| 386 | if not pr_strip |
| 387 | ret 14 |
| 388 | end |
| 389 | pr_hash 2 invsha |
| 390 | pr_metadata sha invsha |
| 391 | if not pr_metacheck |
| 392 | ret 15 |
| 393 | end |
| 394 | if not pr_inverse |
| 395 | ret 16 |
| 396 | end |
| 397 | if not pr_forward |
| 398 | ret 17 |
| 399 | end |
| 400 | pr_hash 1 invsha |
| 401 | for i ulong 32 |
| 402 | if ne get sha i get invsha i |
| 403 | ret 18 |
| 404 | end |
| 405 | end |
| 406 | ret 0 |
| 407 | end |
| 408 | note Controls mutate one independent input dimension at a time, restore it, and demand refusal. |
| 409 | note Original/hash/blob/schema/placeholder/body; body and metadata truncation; duplicate metadata; |
| 410 | note scrubbed hash and scrubbed hash-domain mutations are independent mandatory controls. |
| 411 | note Backward insertion and forward restoration preserve overlapping source bytes exactly. |
| 412 | fn pr_duplicate to bool |
| 413 | n = get prn 1 |
| 414 | m = get prn 3 |
| 415 | if gt add n m 262144 |
| 416 | ret false |
| 417 | end |
| 418 | count = sub n 2 |
| 419 | for i ulong count |
| 420 | src = sub n 1 |
| 421 | src = sub src i |
| 422 | dst = add src m |
| 423 | v = get prd src |
| 424 | put prd dst v |
| 425 | end |
| 426 | for i ulong m |
| 427 | dst = add i 2 |
| 428 | v = get prm i |
| 429 | put prd dst v |
| 430 | end |
| 431 | put prn 1 add n m |
| 432 | rc = pr_verify |
| 433 | for i ulong count |
| 434 | dst = add i 2 |
| 435 | src = add dst m |
| 436 | v = get prd src |
| 437 | put prd dst v |
| 438 | end |
| 439 | put prn 1 n |
| 440 | if eq rc 0 |
| 441 | ret false |
| 442 | end |
| 443 | ret eq pr_verify 0 |
| 444 | end |
| 445 | fn pr_controls to bool |
| 446 | last = sub get prn 0 1 |
| 447 | saved = get pro last |
| 448 | put pro last xor saved 1 |
| 449 | rc = pr_verify |
| 450 | put pro last saved |
| 451 | if eq rc 0 |
| 452 | ret false |
| 453 | end |
| 454 | p = add len prm0 2 |
| 455 | saved = get prd p |
| 456 | put prd p 33 |
| 457 | rc = pr_verify |
| 458 | put prd p saved |
| 459 | if eq rc 0 |
| 460 | ret false |
| 461 | end |
| 462 | p = add get prn 6 2 |
| 463 | saved = get prd p |
| 464 | put prd p 33 |
| 465 | rc = pr_verify |
| 466 | put prd p saved |
| 467 | if eq rc 0 |
| 468 | ret false |
| 469 | end |
| 470 | p = sub add get prn 3 2 5 |
| 471 | saved = get prd p |
| 472 | put prd p 33 |
| 473 | rc = pr_verify |
| 474 | put prd p saved |
| 475 | if eq rc 0 |
| 476 | ret false |
| 477 | end |
| 478 | saved = get prb 0 |
| 479 | put prb 0 103 |
| 480 | rc = pr_verify |
| 481 | put prb 0 saved |
| 482 | if eq rc 0 |
| 483 | ret false |
| 484 | end |
| 485 | saved = get prd 30 |
| 486 | put prd 30 33 |
| 487 | rc = pr_verify |
| 488 | put prd 30 saved |
| 489 | if eq rc 0 |
| 490 | ret false |
| 491 | end |
| 492 | rc = pr_verify |
| 493 | if ne rc 0 |
| 494 | ret false |
| 495 | end |
| 496 | p = get prn 4 |
| 497 | saved = get prd p |
| 498 | put prd p 33 |
| 499 | rc = pr_verify |
| 500 | put prd p saved |
| 501 | if eq rc 0 |
| 502 | ret false |
| 503 | end |
| 504 | p = sub get prn 1 1 |
| 505 | saved = get prd p |
| 506 | put prd p xor saved 1 |
| 507 | rc = pr_verify |
| 508 | put prd p saved |
| 509 | if eq rc 0 |
| 510 | ret false |
| 511 | end |
| 512 | put prn 1 sub get prn 1 1 |
| 513 | rc = pr_verify |
| 514 | put prn 1 add get prn 1 1 |
| 515 | if eq rc 0 |
| 516 | ret false |
| 517 | end |
| 518 | note Truncate inside metadata independently of the final-body-byte truncation above. |
| 519 | oldlen = get prn 1 |
| 520 | put prn 1 add get prn 3 1 |
| 521 | rc = pr_verify |
| 522 | put prn 1 oldlen |
| 523 | if eq rc 0 |
| 524 | ret false |
| 525 | end |
| 526 | rc = pr_verify |
| 527 | if ne rc 0 |
| 528 | ret false |
| 529 | end |
| 530 | ret pr_duplicate |
| 531 | end |
| 532 | fn pr_hexchar c uchar to bool |
| 533 | if and ge c 48 le c 57 |
| 534 | ret true |
| 535 | end |
| 536 | ret and ge c 97 le c 102 |
| 537 | end |
| 538 | fn main to int |
| 539 | blobbuf = new uchar 41 0 |
| 540 | if ne argcnt 4 |
| 541 | ret 90 |
| 542 | end |
| 543 | if ne argread 3 blobbuf 0 len blobbuf 40 |
| 544 | ret 91 |
| 545 | end |
| 546 | for i ulong 40 |
| 547 | c = get blobbuf i |
| 548 | if not pr_hexchar c |
| 549 | ret 91 |
| 550 | end |
| 551 | put prb i c |
| 552 | end |
| 553 | if not pr_load 0 |
| 554 | ret 92 |
| 555 | end |
| 556 | if not pr_load 1 |
| 557 | ret 93 |
| 558 | end |
| 559 | rc = pr_verify |
| 560 | if ne rc 0 |
| 561 | ret rc |
| 562 | end |
| 563 | if not pr_controls |
| 564 | ret 94 |
| 565 | end |
| 566 | if ne write 1 prpass 0 len prpass long len prpass |
| 567 | ret 95 |
| 568 | end |
| 569 | ret 0 |
| 570 | end |