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 / protocol / uor-gpu / prism-gpu.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note protocol/uor-gpu/prism-gpu.om: Pure seeded OM-2 Prism CLI plugin executable |
| 3 | note (PrismPM #293 compatible). Zero CUDApp, zero C/Python/Node. Compose after |
| 4 | note si/directives/om2.om, om/tls/sha2.om, protocol/uor-gpu/b3_uor.om, |
| 5 | note protocol/omnet/om/sha512/sha512.om, protocol/omnet/om/ed25519/ed25519.om, |
| 6 | note protocol/uor-gpu/canonical.om, protocol/uor-gpu/payload_vm.om, protocol/uor-gpu/verify.om, |
| 7 | note protocol/uor-gpu/gate.om, protocol/uor-gpu/emit_kernels.om, protocol/uor-gpu/ed_sign.om. |
| 8 | note |
| 9 | note keygen out.seed 32 random bytes, created 0600, never overwritten |
| 10 | note pubkey in.seed out.pub Ed25519 public key of a seed |
| 11 | note trust out.trust authority.pub signer.pub local trust anchors (append more signer keys) |
| 12 | note bundle sm121|spirv out.holo signer.seed compile from source with pinned omc, replay, seal & sign |
| 13 | note inspect file.holo print the header's claims (nothing verified) |
| 14 | note verify file.holo anchors.trust P2 policy + QMD v5 / SPIR-V structural check |
| 15 | note replay file.holo anchors.trust P3 policy + real kernel VM replay over payload bytes |
| 16 | note grant record64.bin authority.seed out.grant sign a 64-byte capability record |
| 17 | note admit file.holo anchors.trust file.grant P2 policy plus authority-signed live grant |
| 18 | |
| 19 | text pg_usage "usage: prism-gpu keygen out.seed | pubkey in.seed out.pub | trust out.trust authority.pub signer.pub | bundle sm121|spirv out.holo signer.seed | inspect file.holo | verify|replay file.holo anchors.trust | grant record64.bin authority.seed out.grant | admit file.holo anchors.trust file.grant\n" |
| 20 | text pg_err_open "prism-gpu: cannot open, read or write file, or it has the wrong size\n" |
| 21 | text pg_err_short "prism-gpu: bundle shorter than 384-byte UOR-GPU-1 header\n" |
| 22 | text pg_err_rand "prism-gpu: random source failed\n" |
| 23 | text pg_err_anch "prism-gpu: bad trust anchors (authority key equal to signer key?)\n" |
| 24 | text pg_err_comp "prism-gpu: kernel compilation from source failed (run from omega-mv root with pinned seed/out/omc)\n" |
| 25 | text pg_c_keygen "keygen" |
| 26 | text pg_c_pubkey "pubkey" |
| 27 | text pg_c_trust "trust" |
| 28 | text pg_c_bundle "bundle" |
| 29 | text pg_c_inspect "inspect" |
| 30 | text pg_c_verify "verify" |
| 31 | text pg_c_replay "replay" |
| 32 | text pg_c_grant "grant" |
| 33 | text pg_c_admit "admit" |
| 34 | text pg_t_sm121 "sm121" |
| 35 | text pg_t_spirv "spirv" |
| 36 | |
| 37 | const PG_CREATE_FLAGS int 577 |
| 38 | const PG_SECRET_FLAGS int 705 |
| 39 | const PG_CREATE_MODE int 420 |
| 40 | const PG_SECRET_MODE int 384 |
| 41 | note Fixed request fields of this offline CLI: world epoch, CLI subject id, GB10 resource id. |
| 42 | const PG_WORLD_EPOCH ulong 1 |
| 43 | const PG_SUBJECT_CLI ulong 7 |
| 44 | const PG_RES_GB10 ulong 0x4152425247423130 |
| 45 | |
| 46 | fn pg_streq a view uchar * n ulong b view uchar * to ulong |
| 47 | if ne n len b |
| 48 | ret 0 |
| 49 | end |
| 50 | for i ulong n bound 64 |
| 51 | if ne get a i get b i |
| 52 | ret 0 |
| 53 | end |
| 54 | end |
| 55 | ret 1 |
| 56 | end |
| 57 | |
| 58 | fn pg_usage_rc to int |
| 59 | uor_write_all 2 pg_usage len pg_usage |
| 60 | ret 2 |
| 61 | end |
| 62 | |
| 63 | fn pg_open_rc to int |
| 64 | uor_write_all 2 pg_err_open len pg_err_open |
| 65 | ret 3 |
| 66 | end |
| 67 | |
| 68 | note argument i into buf; 0 when absent or empty |
| 69 | fn pg_arg i ulong buf edit uchar 512 to ulong |
| 70 | if ge long i argcnt |
| 71 | ret 0 |
| 72 | end |
| 73 | n = argread i buf 0 512 |
| 74 | if le n 0 |
| 75 | ret 0 |
| 76 | end |
| 77 | ret ulong n |
| 78 | end |
| 79 | |
| 80 | note Read a whole file into buf: byte count, -1 cannot open, -2 longer than buf. |
| 81 | fn pg_read_file path view uchar * pn ulong buf edit uchar * to long |
| 82 | fd = fopen path 0 pn 0 0 |
| 83 | if lt fd 0 |
| 84 | ret -1 |
| 85 | end |
| 86 | cap = len buf |
| 87 | got = ulong 0 |
| 88 | while lt got cap bound 65920 |
| 89 | k = read int fd buf got sub cap got |
| 90 | if le k 0 |
| 91 | break |
| 92 | end |
| 93 | got = add got ulong k |
| 94 | end |
| 95 | extra = new uchar 1 0 |
| 96 | ek = read int fd extra 0 1 |
| 97 | cl = fclose int fd |
| 98 | if gt ek 0 |
| 99 | ret -2 |
| 100 | end |
| 101 | ret long got |
| 102 | end |
| 103 | |
| 104 | note 1 iff the file holds exactly len buf bytes (read into buf) |
| 105 | fn pg_read_exact path view uchar * pn ulong buf edit uchar * to ulong |
| 106 | r = pg_read_file path pn buf |
| 107 | if ne r long len buf |
| 108 | ret 0 |
| 109 | end |
| 110 | ret 1 |
| 111 | end |
| 112 | |
| 113 | note Create path (secret: 0600 and refuse to overwrite) and write all of buf. 1 on success. |
| 114 | fn pg_write_file path view uchar * pn ulong buf view uchar * secret ulong to ulong |
| 115 | fl = PG_CREATE_FLAGS |
| 116 | md = PG_CREATE_MODE |
| 117 | if eq secret 1 |
| 118 | fl = PG_SECRET_FLAGS |
| 119 | md = PG_SECRET_MODE |
| 120 | end |
| 121 | fd = fopen path 0 pn fl md |
| 122 | if lt fd 0 |
| 123 | ret 0 |
| 124 | end |
| 125 | uor_write_all int fd buf len buf |
| 126 | cl = fclose int fd |
| 127 | ret 1 |
| 128 | end |
| 129 | |
| 130 | note Load header + payload: 0 ok, -1 cannot open, -2 short header, -3 length/trailing-byte tamper. |
| 131 | fn pg_load_bundle path view uchar * pn ulong hdr edit uchar 384 pay edit uchar 65536 out_plen edit ulong 1 to long |
| 132 | raw = new uchar 65920 0 |
| 133 | r = pg_read_file path pn raw |
| 134 | if eq r -1 |
| 135 | ret -1 |
| 136 | end |
| 137 | if lt r 0 |
| 138 | ret -3 |
| 139 | end |
| 140 | if lt r 384 |
| 141 | ret -2 |
| 142 | end |
| 143 | for i ulong 384 |
| 144 | put hdr i get raw i |
| 145 | end |
| 146 | plen = uor_get_u32 hdr 24 |
| 147 | if ne sub ulong r 384 plen |
| 148 | ret -3 |
| 149 | end |
| 150 | for i ulong plen bound 65536 |
| 151 | put pay i get raw add 384 i |
| 152 | end |
| 153 | put out_plen 0 plen |
| 154 | ret 0 |
| 155 | end |
| 156 | |
| 157 | fn pg_load_rc rrc long hdr view uchar 384 plvl ulong to int |
| 158 | if eq rrc -1 |
| 159 | ret pg_open_rc |
| 160 | end |
| 161 | if eq rrc -2 |
| 162 | uor_write_all 2 pg_err_short len pg_err_short |
| 163 | ret 4 |
| 164 | end |
| 165 | uor_emit_verdict hdr UOR_ERR_PAYLOAD_TAMPER plvl |
| 166 | ret 1 |
| 167 | end |
| 168 | |
| 169 | fn pg_cmd_keygen to int |
| 170 | ab = new uchar 512 0 |
| 171 | sd = new uchar 32 0 |
| 172 | n = pg_arg 2 ab |
| 173 | if eq n 0 |
| 174 | ret pg_usage_rc |
| 175 | end |
| 176 | rr = random sd 0 32 0 |
| 177 | if ne rr 32 |
| 178 | uor_write_all 2 pg_err_rand len pg_err_rand |
| 179 | ret 5 |
| 180 | end |
| 181 | if eq pg_write_file ab n sd 1 0 |
| 182 | ret pg_open_rc |
| 183 | end |
| 184 | ret 0 |
| 185 | end |
| 186 | |
| 187 | fn pg_cmd_pubkey to int |
| 188 | ab = new uchar 512 0 |
| 189 | sd = new uchar 32 0 |
| 190 | pk = new uchar 32 0 |
| 191 | n = pg_arg 2 ab |
| 192 | if eq n 0 |
| 193 | ret pg_usage_rc |
| 194 | end |
| 195 | if eq pg_read_exact ab n sd 0 |
| 196 | ret pg_open_rc |
| 197 | end |
| 198 | ues_pubkey sd pk |
| 199 | n = pg_arg 3 ab |
| 200 | if eq n 0 |
| 201 | ret pg_usage_rc |
| 202 | end |
| 203 | if eq pg_write_file ab n pk 0 0 |
| 204 | ret pg_open_rc |
| 205 | end |
| 206 | ret 0 |
| 207 | end |
| 208 | |
| 209 | fn pg_cmd_trust to int |
| 210 | ab = new uchar 512 0 |
| 211 | apk = new uchar 32 0 |
| 212 | spk = new uchar 32 0 |
| 213 | anc = new uchar 136 0 |
| 214 | n = pg_arg 3 ab |
| 215 | if eq n 0 |
| 216 | ret pg_usage_rc |
| 217 | end |
| 218 | if eq pg_read_exact ab n apk 0 |
| 219 | ret pg_open_rc |
| 220 | end |
| 221 | n = pg_arg 4 ab |
| 222 | if eq n 0 |
| 223 | ret pg_usage_rc |
| 224 | end |
| 225 | if eq pg_read_exact ab n spk 0 |
| 226 | ret pg_open_rc |
| 227 | end |
| 228 | ug_build_anchors anc apk spk |
| 229 | if eq uor_anchors_nkeys anc 0 |
| 230 | uor_write_all 2 pg_err_anch len pg_err_anch |
| 231 | ret 1 |
| 232 | end |
| 233 | n = pg_arg 2 ab |
| 234 | if eq n 0 |
| 235 | ret pg_usage_rc |
| 236 | end |
| 237 | if eq pg_write_file ab n anc 0 0 |
| 238 | ret pg_open_rc |
| 239 | end |
| 240 | ret 0 |
| 241 | end |
| 242 | |
| 243 | fn pg_write_bundle path view uchar * pn ulong hdr view uchar 384 pay view uchar * to int |
| 244 | fd = fopen path 0 pn PG_CREATE_FLAGS PG_CREATE_MODE |
| 245 | if lt fd 0 |
| 246 | ret pg_open_rc |
| 247 | end |
| 248 | uor_write_all int fd hdr 384 |
| 249 | uor_write_all int fd pay len pay |
| 250 | cl = fclose int fd |
| 251 | ok = uor_emit_inspect hdr |
| 252 | ret 0 |
| 253 | end |
| 254 | |
| 255 | fn pg_bundle_seal hdr edit uchar 384 isa ulong pay view uchar * sdig view uchar 32 sd view uchar 32 to ulong |
| 256 | rc = ug_fill_p3_hdr_real hdr isa pay sdig |
| 257 | if ne rc UOR_VERDICT_PASS |
| 258 | ret rc |
| 259 | end |
| 260 | uor_hdr_seal hdr pay |
| 261 | ues_sign_hdr hdr sd |
| 262 | ret UOR_VERDICT_PASS |
| 263 | end |
| 264 | |
| 265 | fn pg_bundle_sm121 path view uchar * pn ulong sd view uchar 32 to int |
| 266 | hdr = new uchar 384 0 |
| 267 | pay = new uchar 65536 0 |
| 268 | plen = new ulong 1 0 |
| 269 | sdig = new uchar 32 0 |
| 270 | if eq ug_compile_sm121 ug_default_omc pay plen sdig 0 |
| 271 | uor_write_all 2 pg_err_comp len pg_err_comp |
| 272 | ret 6 |
| 273 | end |
| 274 | if ne pg_bundle_seal hdr UOR_GPU_ISA_SM121 part pay 0 get plen 0 sdig sd UOR_VERDICT_PASS |
| 275 | uor_write_all 2 pg_err_comp len pg_err_comp |
| 276 | ret 6 |
| 277 | end |
| 278 | ret pg_write_bundle path pn hdr part pay 0 get plen 0 |
| 279 | end |
| 280 | |
| 281 | fn pg_bundle_spirv path view uchar * pn ulong sd view uchar 32 to int |
| 282 | hdr = new uchar 384 0 |
| 283 | pay = new uchar 65536 0 |
| 284 | plen = new ulong 1 0 |
| 285 | sdig = new uchar 32 0 |
| 286 | if eq ug_compile_spirv ug_default_omc 0 pay plen sdig 0 |
| 287 | uor_write_all 2 pg_err_comp len pg_err_comp |
| 288 | ret 6 |
| 289 | end |
| 290 | if ne pg_bundle_seal hdr UOR_GPU_ISA_SPIRV part pay 0 get plen 0 sdig sd UOR_VERDICT_PASS |
| 291 | uor_write_all 2 pg_err_comp len pg_err_comp |
| 292 | ret 6 |
| 293 | end |
| 294 | ret pg_write_bundle path pn hdr part pay 0 get plen 0 |
| 295 | end |
| 296 | |
| 297 | fn pg_cmd_bundle to int |
| 298 | tg = new uchar 512 0 |
| 299 | ab = new uchar 512 0 |
| 300 | sd = new uchar 32 0 |
| 301 | tn = pg_arg 2 tg |
| 302 | n = pg_arg 4 ab |
| 303 | if or eq tn 0 eq n 0 |
| 304 | ret pg_usage_rc |
| 305 | end |
| 306 | if eq pg_read_exact ab n sd 0 |
| 307 | ret pg_open_rc |
| 308 | end |
| 309 | n = pg_arg 3 ab |
| 310 | if eq n 0 |
| 311 | ret pg_usage_rc |
| 312 | end |
| 313 | if ne pg_streq tg tn pg_t_sm121 0 |
| 314 | ret pg_bundle_sm121 ab n sd |
| 315 | end |
| 316 | if ne pg_streq tg tn pg_t_spirv 0 |
| 317 | ret pg_bundle_spirv ab n sd |
| 318 | end |
| 319 | ret pg_usage_rc |
| 320 | end |
| 321 | |
| 322 | fn pg_cmd_inspect to int |
| 323 | ab = new uchar 512 0 |
| 324 | hdr = new uchar 384 0 |
| 325 | pay = new uchar 65536 0 |
| 326 | pl = new ulong 1 0 |
| 327 | n = pg_arg 2 ab |
| 328 | if eq n 0 |
| 329 | ret pg_usage_rc |
| 330 | end |
| 331 | rrc = pg_load_bundle ab n hdr pay pl |
| 332 | if ne rrc 0 |
| 333 | ret pg_load_rc rrc hdr UOR_LVL_P0 |
| 334 | end |
| 335 | if eq uor_emit_inspect hdr 0 |
| 336 | uor_emit_verdict hdr UOR_ERR_BAD_MAGIC UOR_LVL_P0 |
| 337 | ret 1 |
| 338 | end |
| 339 | ret 0 |
| 340 | end |
| 341 | |
| 342 | note mode P2: verify policy; mode P3: P3 policy plus real kernel VM replay over actual payload bytes |
| 343 | fn pg_check_run hdr view uchar 384 pay view uchar * anc view uchar * mode ulong to int |
| 344 | rc = uor_verify_policy hdr pay anc mode |
| 345 | if and eq rc UOR_VERDICT_PASS eq mode UOR_LVL_P3 |
| 346 | rc = uor_verify_replay_real hdr pay |
| 347 | end |
| 348 | uor_emit_verdict hdr rc mode |
| 349 | if eq rc UOR_VERDICT_PASS |
| 350 | ret 0 |
| 351 | end |
| 352 | ret 1 |
| 353 | end |
| 354 | |
| 355 | fn pg_check_run2 hdr view uchar 384 pay view uchar 65536 plen ulong anc view uchar 617 alen ulong mode ulong to int |
| 356 | ret pg_check_run hdr part pay 0 plen part anc 0 alen mode |
| 357 | end |
| 358 | |
| 359 | fn pg_cmd_check mode ulong to int |
| 360 | ab = new uchar 512 0 |
| 361 | hdr = new uchar 384 0 |
| 362 | pay = new uchar 65536 0 |
| 363 | anc = new uchar 617 0 |
| 364 | pl = new ulong 1 0 |
| 365 | n = pg_arg 2 ab |
| 366 | if eq n 0 |
| 367 | ret pg_usage_rc |
| 368 | end |
| 369 | rrc = pg_load_bundle ab n hdr pay pl |
| 370 | if ne rrc 0 |
| 371 | ret pg_load_rc rrc hdr mode |
| 372 | end |
| 373 | n = pg_arg 3 ab |
| 374 | if eq n 0 |
| 375 | ret pg_usage_rc |
| 376 | end |
| 377 | an = pg_read_file ab n anc |
| 378 | if lt an 0 |
| 379 | ret pg_open_rc |
| 380 | end |
| 381 | ret pg_check_run2 hdr pay get pl 0 anc ulong an mode |
| 382 | end |
| 383 | |
| 384 | fn pg_cmd_grant to int |
| 385 | ab = new uchar 512 0 |
| 386 | rec = new uchar 64 0 |
| 387 | sd = new uchar 32 0 |
| 388 | g = new uchar 168 0 |
| 389 | n = pg_arg 2 ab |
| 390 | if eq n 0 |
| 391 | ret pg_usage_rc |
| 392 | end |
| 393 | if eq pg_read_exact ab n rec 0 |
| 394 | ret pg_open_rc |
| 395 | end |
| 396 | n = pg_arg 3 ab |
| 397 | if eq n 0 |
| 398 | ret pg_usage_rc |
| 399 | end |
| 400 | if eq pg_read_exact ab n sd 0 |
| 401 | ret pg_open_rc |
| 402 | end |
| 403 | for i ulong 64 |
| 404 | put g i get rec i |
| 405 | end |
| 406 | ues_sign_grant g sd |
| 407 | n = pg_arg 4 ab |
| 408 | if eq n 0 |
| 409 | ret pg_usage_rc |
| 410 | end |
| 411 | if eq pg_write_file ab n part g 0 128 0 0 |
| 412 | ret pg_open_rc |
| 413 | end |
| 414 | ret 0 |
| 415 | end |
| 416 | |
| 417 | note Request of the offline CLI: expected generation = the signed record's own generation |
| 418 | note (offline there is no live caproot table; see gate.om), world epoch, wall clock in seconds, |
| 419 | note CLI subject, GB10 resource. |
| 420 | fn pg_fill_req g edit uchar 168 to void |
| 421 | uor_put_u64 g 128 uor_get_u64 g 8 |
| 422 | uor_put_u64 g 136 PG_WORLD_EPOCH |
| 423 | uor_put_u64 g 144 div ulong realns 1000000000 |
| 424 | uor_put_u64 g 152 PG_SUBJECT_CLI |
| 425 | uor_put_u64 g 160 PG_RES_GB10 |
| 426 | end |
| 427 | |
| 428 | note Read exactly 128 grant bytes (record || authority signature) into g[0..128). 1 on success. |
| 429 | fn pg_load_grant path view uchar * pn ulong g edit uchar 168 to ulong |
| 430 | raw = new uchar 128 0 |
| 431 | if eq pg_read_exact path pn raw 0 |
| 432 | ret 0 |
| 433 | end |
| 434 | for i ulong 128 |
| 435 | put g i get raw i |
| 436 | end |
| 437 | ret 1 |
| 438 | end |
| 439 | |
| 440 | fn pg_admit_run hdr view uchar 384 pay view uchar * anc view uchar * g view uchar 168 to int |
| 441 | rc = uor_gpu_admit hdr pay anc g |
| 442 | uor_emit_verdict hdr rc UOR_LVL_P2 |
| 443 | if eq rc UOR_VERDICT_PASS |
| 444 | ret 0 |
| 445 | end |
| 446 | ret 1 |
| 447 | end |
| 448 | |
| 449 | fn pg_admit_run2 hdr view uchar 384 pay view uchar 65536 plen ulong anc view uchar 617 alen ulong g view uchar 168 to int |
| 450 | ret pg_admit_run hdr part pay 0 plen part anc 0 alen g |
| 451 | end |
| 452 | |
| 453 | fn pg_cmd_admit to int |
| 454 | ab = new uchar 512 0 |
| 455 | hdr = new uchar 384 0 |
| 456 | pay = new uchar 65536 0 |
| 457 | anc = new uchar 617 0 |
| 458 | pl = new ulong 1 0 |
| 459 | g = new uchar 168 0 |
| 460 | n = pg_arg 2 ab |
| 461 | if eq n 0 |
| 462 | ret pg_usage_rc |
| 463 | end |
| 464 | rrc = pg_load_bundle ab n hdr pay pl |
| 465 | if ne rrc 0 |
| 466 | ret pg_load_rc rrc hdr UOR_LVL_P2 |
| 467 | end |
| 468 | n = pg_arg 3 ab |
| 469 | if eq n 0 |
| 470 | ret pg_usage_rc |
| 471 | end |
| 472 | an = pg_read_file ab n anc |
| 473 | if lt an 0 |
| 474 | ret pg_open_rc |
| 475 | end |
| 476 | n = pg_arg 4 ab |
| 477 | if eq n 0 |
| 478 | ret pg_usage_rc |
| 479 | end |
| 480 | if eq pg_load_grant ab n g 0 |
| 481 | ret pg_open_rc |
| 482 | end |
| 483 | pg_fill_req g |
| 484 | ret pg_admit_run2 hdr pay get pl 0 anc ulong an g |
| 485 | end |
| 486 | |
| 487 | fn main to int |
| 488 | cmd = new uchar 64 0 |
| 489 | if lt argcnt 3 |
| 490 | ret pg_usage_rc |
| 491 | end |
| 492 | cn = argread 1 cmd 0 64 |
| 493 | if le cn 0 |
| 494 | ret pg_usage_rc |
| 495 | end |
| 496 | c = ulong cn |
| 497 | if ne pg_streq cmd c pg_c_keygen 0 |
| 498 | ret pg_cmd_keygen |
| 499 | end |
| 500 | if ne pg_streq cmd c pg_c_pubkey 0 |
| 501 | ret pg_cmd_pubkey |
| 502 | end |
| 503 | if ne pg_streq cmd c pg_c_trust 0 |
| 504 | ret pg_cmd_trust |
| 505 | end |
| 506 | if ne pg_streq cmd c pg_c_bundle 0 |
| 507 | ret pg_cmd_bundle |
| 508 | end |
| 509 | if ne pg_streq cmd c pg_c_inspect 0 |
| 510 | ret pg_cmd_inspect |
| 511 | end |
| 512 | if ne pg_streq cmd c pg_c_verify 0 |
| 513 | ret pg_cmd_check UOR_LVL_P2 |
| 514 | end |
| 515 | if ne pg_streq cmd c pg_c_replay 0 |
| 516 | ret pg_cmd_check UOR_LVL_P3 |
| 517 | end |
| 518 | if ne pg_streq cmd c pg_c_grant 0 |
| 519 | ret pg_cmd_grant |
| 520 | end |
| 521 | if ne pg_streq cmd c pg_c_admit 0 |
| 522 | ret pg_cmd_admit |
| 523 | end |
| 524 | ret pg_usage_rc |
| 525 | end |