interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

GitHub aien-dev/aienux#324 (code only)

closed derived 8086d040f76a60fa #324

Imported from GitHub aien-dev/aienux#324 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base ff5da2d84cf36becdd5f66548d8e0afd25c05fc5 · Head a0c3e65d353c29365068144837f29fd5f69e39d8

Apply it

git checkout -b patch-8086d040f76a60fa ff5da2d84cf36becdd5f66548d8e0afd25c05fc5
curl -fsSL https://interplane.io/drakestapleton/aienux/patches/8086d040f76a60fa.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/aienux
324
a0c3e65d353c29365068144837f29fd5f69e39d8
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":324,"url":"https://github.com/aien-dev/aienux/pull/324","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:13Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/.crumb b/.crumb
index 182765c9..a5df5bd9 100644
--- a/.crumb
+++ b/.crumb
@@ -27,33 +27,33 @@
           "purpose": "Directory crates. Purpose not yet described by a human."
         },
         {
-          "digest": "0be0aad1d8cedb87de9de2c71a1bd83b1f4e814664f62d3752d48c6ceea4bbbb",
-          "last_commit": "e8364bb",
+          "digest": "f4c37704f427fe043a2d21b4317a7ae7612f34a66a532e825c5ba78c57e6f31c",
+          "last_commit": "f56f72b",
           "name": "docs",
           "purpose": "Directory docs. Purpose not yet described by a human."
         },
         {
-          "digest": "6de07abca1282ec322f9b0b7dcefe1e9aef7821bd8a3a4483316a6d811065684",
-          "last_commit": "4958cbd",
+          "digest": "794b6a712e50e0a7c597a70aa144ceba0f456e75800d580e85cb0900bf6a1f11",
+          "last_commit": "f56f72b",
           "name": "native",
           "purpose": "Directory native. Purpose not yet described by a human."
         },
         {
-          "digest": "d124a74c6a60db0dbb1b79e7f92f5f90eb0a9cace1873417f986f0075be061bf",
-          "last_commit": "4958cbd",
+          "digest": "654df809529c9ef3d80af6141a30543a957e3ebde6010d9726519f7fa2a24138",
+          "last_commit": "f56f72b",
           "name": "scripts",
           "purpose": "Directory scripts. Purpose not yet described by a human."
         }
       ],
-      "children_root": "sha256:7e669e094edf79ad9cb203a32b7f49e4791481565b1786dd1235bfbb726e1b4a",
-      "compiled_at": "2026-10-12T15:44:24Z",
+      "children_root": "sha256:2557d9a677a43fbc3305da229ee2c32baa0f0f9ceda875e3d98a2202df0f43cf",
+      "compiled_at": "2026-10-12T16:07:30Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:98e959c584dcfc924fd44ae1b96834a47b7dfdd788cfc3e6fe939cdea4c15c07",
+      "digest": "sha256:aae89cca89f281f51b9e3ff3a21560431768779ef435eb1a8f1d6e06f777ff5a",
       "evidence_files": 155,
       "evidence_root": "sha256:d59c0cef4e7dd5172923754a95b411ca54b01f35baca4587f792f1b259f1eaf7",
       "files": 3101,
-      "generated_at_commit": "e8364bb9fd371bc8db7a6f295081c6f4869e5d20",
-      "source_tree": "sha256:9fc0682871e8b42703e9d855850ff318ccd5a5f4926434485603a08806fe0b94"
+      "generated_at_commit": "f56f72b2bdf52b7f2347c6548e42459e465558a0",
+      "source_tree": "sha256:a8369761d4cabdc935989d4a4f3f256f71423ea050fc5a294f2ec842d63c909e"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/docs/.crumb b/docs/.crumb
index dea83fde..9f4feaa7 100644
--- a/docs/.crumb
+++ b/docs/.crumb
@@ -30,14 +30,14 @@
         }
       ],
       "children_root": "sha256:baea130f2c52779b57d90139beb66ac01b21ab499d113471a334be5500f3e369",
-      "compiled_at": "2026-10-12T15:44:24Z",
+      "compiled_at": "2026-10-12T16:07:30Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:0be0aad1d8cedb87de9de2c71a1bd83b1f4e814664f62d3752d48c6ceea4bbbb",
+      "digest": "sha256:f4c37704f427fe043a2d21b4317a7ae7612f34a66a532e825c5ba78c57e6f31c",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 73,
-      "generated_at_commit": "e8364bb9fd371bc8db7a6f295081c6f4869e5d20",
-      "source_tree": "sha256:210f814860278470f223b86f7065fe70bf62f3962a9b747c454c762bbb05815b"
+      "generated_at_commit": "f56f72b2bdf52b7f2347c6548e42459e465558a0",
+      "source_tree": "sha256:cf9279ff0241e20493655128d49892cd61ef02800e77967e4722273624590bc5"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/docs/NATIVE_PACKAGE.md b/docs/NATIVE_PACKAGE.md
index 5ff4896c..d4980824 100644
--- a/docs/NATIVE_PACKAGE.md
+++ b/docs/NATIVE_PACKAGE.md
@@ -1,6 +1,6 @@
 # Reproducible native package with owner-signed verification (P11 cut 1b)
 
-STATUS: IMPLEMENTED host-side (build, sign, verify, self-test). Nothing in
+STATUS: IMPLEMENTED host-side (build, tbs, sign, verify, self-test). Nothing in
 this document installs, boots or touches a machine. Gate N7 stays NOT_RUN.
 SECURITY_IMPACT: RECOVERY (the package is what install, update and recovery
 will carry; the format is covered by `docs/NATIVE_IMAGE_SLOTS.md`).
@@ -8,6 +8,11 @@ will carry; the format is covered by `docs/NATIVE_IMAGE_SLOTS.md`).
 This is the "reproducible native package with exact component/model/firmware
 manifests and owner-signed verification" item of work package P11 (AIEN
 native v1 plan, aien-architecture CURRENT_EXECUTION_PLAN addendum 2026-10-12).
+Format 2 (2026-10-12) adds the provenance record the owner asked for: "matching
+two builds demonstrates reproducibility under the recorded build conditions.
+Connecting the signed package to reviewed source also requires recording the
+source revision, toolchain, inputs, and resulting digest. Keep that evidence
+with the release candidate."
 
 ## What a package is
 
@@ -16,56 +21,122 @@ native v1 plan, aien-architecture CURRENT_EXECUTION_PLAN addendum 2026-10-12).
 | File | Content |
 |---|---|
 | `image/BOOTAA64.EFI` | the image (core, full, or hardware-staging variant), mode 444 |
-| `PACKAGE.txt` | `key value` lines: format, repo, commit and commit time, variant, generation, policy generation, min rollback generation, image bytes/SHA-256/SHA-512, `reproducible two_clean_builds_identical`, gcc/ld/make versions, build host arch, `pin <repo> <sha>` lines from `--pins`, `model_bytes`/`model_sha256` from `--model`, `firmware <name> <bytes> <sha256>` per `--firmware`, and for the staging variant the SHA-256 of the owner public keys file and the machine id file |
+| `PACKAGE.txt` | the provenance record, `key value` lines (next table) |
 | `SHA256SUMS` | `sha256sum` lines over the image and `PACKAGE.txt` |
-| `slot/MANIFEST.bin` | the unsigned slot manifest (`native/boot/slot_format.h`): generation, digests, commit, timestamp = commit time, **provenance = the 64 hex characters of SHA-256(`SHA256SUMS`)** |
-| `slot/MANIFEST.tbs` | the 448 bytes the owner signs |
+| `PROVENANCE.txt` | `package_sha256 <64 hex>` = SHA-256(`SHA256SUMS`): the resulting package digest. It is a separate file because `SHA256SUMS` covers `PACKAGE.txt`, so `PACKAGE.txt` cannot hold a digest of `SHA256SUMS` |
+| `slot/MANIFEST.bin` | the unsigned slot manifest (`native/boot/slot_format.h`): generation, digests, commit, timestamp = commit time, **provenance = `package_sha256`** |
+| `slot/MANIFEST.tbs` | the 448 bytes the owner signs, written by `tbs --package DIR --pubkey HEX64` (or `build --pubkey`). The manifest's `signer_id` (SHA-256 of the owner public key) lies inside the signed bytes, so the bytes to sign depend on which key will sign |
 | `slot/MANIFEST.signed.bin` | after `sign`: the manifest with signer id and signature, verified before it is written |
 
+`PACKAGE.txt` lines (format 2), grouped as the owner's correction names them:
+
+| Group | Lines |
+|---|---|
+| Source revision | `format 2`, `repo aien-dev/aienos`, `commit <40 hex>`, `commit_time <unix seconds>`, `tree_clean yes` (`no` only for test builds with `--allow-dirty`) |
+| What was asked for | `variant`, `generation`, `policy_generation`, `min_rollback_generation` |
+| Toolchain | `toolchain_cross <prefix or none>` (the `CROSS` value the kernel Makefile resolves, asked from make itself), `toolchain_cc`, `toolchain_ld`, `toolchain_objcopy` (first line of `<CROSS>gcc/ld/objcopy --version`), `toolchain_make` (first line of `make --version`), `build_host_arch` (`uname -m`) |
+| Inputs | `input_make_goal` (`all` for core, `full` otherwise), `input_make_vars` (`none`, or `CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS=sha256:<hex> CK_MACHINE_ID=sha256:<hex>`), `input_env_ck none` (any `CK_*` in the environment or in an outer make's `MAKEFLAGS` is refused, so nothing unrecorded selects the image), `input_makefile_sha256` (`native/kernel/Makefile`), `input_image_ld_sha256` (`native/boot/image.ld`), `pin <repo> <sha>` per `--pins` line, `model_bytes`/`model_sha256` from `--model`, `firmware <name> <bytes> <sha256>` per `--firmware`, and for the staging variant `owner_pubkeys_sha256` and `machine_id_sha256` |
+| Resulting image | `image image/BOOTAA64.EFI`, `image_bytes`, `image_sha256`, `image_sha512`, `reproducible two_clean_builds_identical` |
+
+The resulting package digest is `PROVENANCE.txt` `package_sha256`.
+
 One signature covers everything: the manifest signs the image digest and the
-provenance; the provenance is the digest of `SHA256SUMS`; `SHA256SUMS` covers
-`PACKAGE.txt` and the image. Change any pin, digest or toolchain line and the
-provenance no longer matches; the self-test proves each of these refusals.
+provenance; the provenance is `package_sha256`; `SHA256SUMS` covers
+`PACKAGE.txt` and the image. Change any record line and the provenance no
+longer matches; the self-test proves each of these refusals.
+
+TODO (slot loader, `docs/NATIVE_IMAGE_SLOTS.md` section 6 cut 2, in progress
+on another branch): when `SLOTLDR.EFI` exists, the package must carry it (or
+name the loader package it was tested with) and record its digest. This cut
+does not touch the loader or the Makefile.
+
+## What the record proves and what it does not
+
+- **Two identical builds prove reproducibility under the recorded conditions
+  only.** The same commit, built twice in fresh directories with the recorded
+  toolchain, gave the same bytes. It says nothing about other compilers,
+  other hosts or other flags.
+- **The record is what ties the package to reviewed source.** The commit
+  (with `tree_clean yes`), the toolchain lines, the inputs and the resulting
+  digests together say "these bytes came from that reviewed revision, built
+  this way". Anyone with the repository can check the commit, its time and
+  the Makefile and linker-script digests (`verify` does), and with the same
+  toolchain can rebuild and compare the image digest.
+- **It does not prove the toolchain itself is trustworthy.** A compromised
+  compiler or linker produces the same wrong bytes every time, so a
+  reproducible build inherits its flaws. The toolchain lines name what was
+  trusted; they do not vouch for it.
+- **Pins, model and firmware are recorded, not re-checked.** The package
+  carries their digests, not the files; `verify` prints them as recorded.
+- Keep the whole package directory (record, sums, provenance, manifests)
+  with the release candidate: it is the evidence.
 
 ## Rules the script enforces
 
-- **Committed tree only.** A dirty working tree is refused (tests may pass
-  `--allow-dirty`; the self-test does so only when the tree is dirty).
+- **Committed tree only.** A dirty working tree (tracked files changed) is
+  refused. Tests may pass `--allow-dirty`; the record then says
+  `tree_clean no`, and `verify` and `sign` refuse that package unless given
+  `--allow-dirty` too (`sign-test` accepts it; the TEST key never signs for
+  hardware).
 - **Reproducible or not signable** (TRUST-1 Q24). The image is built twice
   into two fresh directories; if the two differ, no package is written. On
   2026-10-12 the full image reproduced byte for byte across clean builds
   (sha256 540b7f75... at aienos 6e3c492).
+- **No unrecorded inputs.** `CK_*` variables in the environment or passed
+  down in `MAKEFLAGS` are refused; the variant's make goal and variables are
+  the only ones used, and they are recorded.
 - **Never overwritten, never re-signed in place.** `--out` must not exist;
   `sign` refuses when `MANIFEST.signed.bin` exists.
-- **Private keys never on the Spark.** `build` emits the to-be-signed bytes;
-  the owner signs them on the air-gapped machine
-  (`openssl pkeyutl -sign -inkey owner_root.pem -rawin -in MANIFEST.tbs -out MANIFEST.sig`)
-  and `sign --sig MANIFEST.sig --pubkey <64 hex>` attaches the signature
-  after verifying it. `sign-test` uses the RFC 8032 TEST 1 key and is for
-  tests only; `ck_owner_gen` and the slot tool refuse that key for hardware.
+- **Private keys never on the Spark.** `tbs --pubkey` emits the to-be-signed
+  bytes for that public key; the owner signs them on the offline machine
+  (`openssl pkeyutl -sign -inkey owner_root.key.pem -rawin -in MANIFEST.tbs -out MANIFEST.sig`,
+  `docs/OWNER_KEY_CEREMONY.md`) and `sign --sig MANIFEST.sig --pubkey <64 hex>`
+  attaches the signature after verifying it. Before 2026-10-12 `ck_slot_tool
+  tbs` emitted the bytes with an empty `signer_id`, while `attach-sig` checks
+  the signature with `signer_id` filled in, so no real offline signature could
+  attach; `tbs` now requires `--pubkey` and the self-test signs with a
+  throwaway OpenSSL key end to end. `sign-test` uses the RFC 8032 TEST 1 key
+  and is for tests only; `ck_owner_gen` and the slot tool refuse that key for
+  hardware.
 - **Verify fails closed.** `verify --package DIR --keys FILE` checks
-  `SHA256SUMS`, the `PACKAGE.txt` image digest and the reproducibility line,
-  the provenance binding, the commit match, the signed manifest's signature
-  under the owner keys (`tools/ck_owner_gen.c` file format), and that the
-  signed manifest equals the built one in every field but signer/signature.
-  An unsigned package is refused unless `--allow-unsigned` (reported as not
-  installable).
+  `SHA256SUMS`, `PROVENANCE.txt`, every record line it can recompute
+  (exactly one of each required line; image bytes, SHA-256 and SHA-512;
+  `tree_clean`; the make goal and variables against the variant; the commit
+  time, Makefile and `image.ld` digests against the commit when the
+  repository has it), the provenance binding, the commit match, the signed
+  manifest's signature under the owner keys (`tools/ck_owner_gen.c` file
+  format), and that the signed manifest equals the built one in every field
+  but signer/signature. With `--same-host` it also compares the toolchain
+  lines with the toolchain running here; without it they are printed as
+  `recorded`. Every line is printed as `checked` or `recorded`. An unsigned
+  package is refused unless `--allow-unsigned` (reported as not installable).
 
 ## Self-test
 
 `make -C native/kernel package-test` runs `scripts/native_package_test.sh`:
-32 checks (build with pins/model/firmware; every PACKAGE.txt line; refusals
-for an existing output, a bad pin, owner files on the wrong variant, an
-unsigned package, double signing, the wrong owner key, a tampered image, a
-tampered PACKAGE.txt with and without re-made sums, a flipped signature byte,
-a missing SHA256SUMS, another package's signed manifest, a non-reproducible
-build via a test hook, the hardware-staging variant with the labelled
-TEST-FIXTURE owner files). About 35 s, nothing booted.
+85 checks. Build with pins/model/firmware; every PACKAGE.txt line including
+each provenance line against an independent computation; the manifest
+provenance equals `package_sha256`; refusals for an existing output, a bad
+pin, owner files on the wrong variant, `CK_*` in the environment and in
+`MAKEFLAGS`, a dirty tree (in a scratch worktree of HEAD, the real checkout is
+never touched), an unsigned package, double signing, the wrong owner key, a
+tampered image, a tampered PACKAGE.txt with and without re-made sums and
+`PROVENANCE.txt`, a tampered or missing `PROVENANCE.txt`, a flipped signature
+byte, a missing SHA256SUMS, another package's signed manifest, a
+non-reproducible build via a test hook; twelve record tampers with re-made
+sums (tree_clean, Makefile and image.ld digests, commit time, image SHA-512
+and size, make goal and variables, `input_env_ck`, a missing and a duplicated
+line, and a toolchain line under `--same-host`); the hardware-staging variant
+with the labelled TEST-FIXTURE owner files; and the offline signing round
+trip with a throwaway OpenSSL Ed25519 key (`tbs` without and with
+`--pubkey`, the TEST key refused, a signature over signer-less bytes refused,
+a dirty-tree package refused for a real signature, attach, verify under the
+keys file, `signer_id` equal to OpenSSL's SHA-256 of the raw public key).
+About 40 s, nothing booted.
 
 ## What is still missing for N7
 
 The package is the input to the updater (slots cut 3) and to the known-good
-recovery image (slots cut 4). Neither exists yet; both wait on the owner
-decision in `docs/NATIVE_IMAGE_SLOTS.md` section 2. Install today is still
+recovery image (slots cut 4). Neither exists yet. Install today is still
 the one-time BootNext procedure of `docs/NATIVE_BOOT_ONE_TIME.md`, which N7
 rejects as the supported path.
diff --git a/native/.crumb b/native/.crumb
index f821494d..1487c2bc 100644
--- a/native/.crumb
+++ b/native/.crumb
@@ -79,8 +79,8 @@
           "purpose": "Directory native/disk. Purpose not yet described by a human."
         },
         {
-          "digest": "4f00e5cd82c3a8f4e474cced14e561ab2bf2c6f811faa8832d333b7bb55293eb",
-          "last_commit": "6e3c492",
+          "digest": "45f810f4c2482700ded9443113f28d6d36c4817b79c3b3e4b4620e8f7c85f687",
+          "last_commit": "f56f72b",
           "name": "kernel",
           "purpose": "Directory native/kernel. Purpose not yet described by a human."
         },
@@ -109,15 +109,15 @@
           "purpose": "Directory native/store. Purpose not yet described by a human."
         }
       ],
-      "children_root": "sha256:e8147bf26595c64fb940cf7162999b78639421380acc616ae7a951228ab79ea3",
-      "compiled_at": "2026-10-12T14:57:41Z",
+      "children_root": "sha256:26313f317f00d90e99c5cbbace065401cab67e6c2fa3aeeb2e57396830e2c637",
+      "compiled_at": "2026-10-12T16:07:30Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:6de07abca1282ec322f9b0b7dcefe1e9aef7821bd8a3a4483316a6d811065684",
+      "digest": "sha256:794b6a712e50e0a7c597a70aa144ceba0f456e75800d580e85cb0900bf6a1f11",
       "evidence_files": 4,
       "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335",
       "files": 477,
-      "generated_at_commit": "6e3c492a4bee0154cb05d1c3e45f8874b6588d2d",
-      "source_tree": "sha256:ace261033fa0166854615f85e0abec520d9a0539786a7d5cb4bc27d8f235c4f4"
+      "generated_at_commit": "f56f72b2bdf52b7f2347c6548e42459e465558a0",
+      "source_tree": "sha256:5622e30e243bcdd5b3625de6aeb0a654621194f380387166ac204bcc3f46e416"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/kernel/.crumb b/native/kernel/.crumb
index b9ef43e3..2f93b322 100644
--- a/native/kernel/.crumb
+++ b/native/kernel/.crumb
@@ -93,21 +93,21 @@
           "purpose": "Directory native/kernel/tests. Purpose not yet described by a human."
         },
         {
-          "digest": "296ff852cc6b1c08d337e2db62489a637ae41385b805290d9a65199c12171865",
-          "last_commit": "6e3c492",
+          "digest": "3136405835c1c24b08ed7d35be097c73761632e89dfe81510a2315c0030b5ab7",
+          "last_commit": "f56f72b",
           "name": "tools",
           "purpose": "Hosted (Linux-built) checkers for the native kernel, run by `make -C native/kernel test`; nothin"
         }
       ],
-      "children_root": "sha256:5fa11a775a53ed4e7d04bd1e414456b153c398a1ac492ed45bb820d49c83872e",
-      "compiled_at": "2026-10-12T14:57:41Z",
+      "children_root": "sha256:bc40eb982c84e2838e3d91f03154b4b04b59c83449f4a9e708520dc0c4e7d612",
+      "compiled_at": "2026-10-12T16:07:30Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:4f00e5cd82c3a8f4e474cced14e561ab2bf2c6f811faa8832d333b7bb55293eb",
+      "digest": "sha256:45f810f4c2482700ded9443113f28d6d36c4817b79c3b3e4b4620e8f7c85f687",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 311,
-      "generated_at_commit": "6e3c492a4bee0154cb05d1c3e45f8874b6588d2d",
-      "source_tree": "sha256:2b63e444dacc4fb2dd35aa99bbe335bdeb1240047f9c3fcaf0f7cff41c3b4b14"
+      "generated_at_commit": "f56f72b2bdf52b7f2347c6548e42459e465558a0",
+      "source_tree": "sha256:80142220b56e31c91c868a9d0ffca5d5ae3c8513be0cfdd4fd44b9d028095b8e"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/kernel/tools/.crumb b/native/kernel/tools/.crumb
index 3e5301c9..4659e92a 100644
--- a/native/kernel/tools/.crumb
+++ b/native/kernel/tools/.crumb
@@ -7,14 +7,14 @@
     "generated": {
       "children": [],
       "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "compiled_at": "2026-10-12T14:57:41Z",
+      "compiled_at": "2026-10-12T16:07:30Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:296ff852cc6b1c08d337e2db62489a637ae41385b805290d9a65199c12171865",
+      "digest": "sha256:3136405835c1c24b08ed7d35be097c73761632e89dfe81510a2315c0030b5ab7",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 18,
-      "generated_at_commit": "6e3c492a4bee0154cb05d1c3e45f8874b6588d2d",
-      "source_tree": "sha256:0742f2cc6c1f0db5f7f3a7c1def0d535a4de467426153cc09b10aa6e9a077938"
+      "generated_at_commit": "f56f72b2bdf52b7f2347c6548e42459e465558a0",
+      "source_tree": "sha256:ea97d599f85b682753158aae34deb974b23d342d27c6ece029910ed13ca5d64d"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/kernel/tools/ck_slot_tool.c b/native/kernel/tools/ck_slot_tool.c
index d16e7fd4..b6b88fde 100644
--- a/native/kernel/tools/ck_slot_tool.c
+++ b/native/kernel/tools/ck_slot_tool.c
@@ -9,8 +9,10 @@
  *       [--policy-generation N] [--min-rollback N] [--commit HEX40]
  *       [--provenance TEXT] [--timestamp N]       unsigned manifest (signature zero)
  *   ck_slot_tool show M                        print the manifest fields (structural check only)
- *   ck_slot_tool tbs M --out F                   the 448 to-be-signed bytes, for an
+ *   ck_slot_tool tbs M --pubkey HEX64 --out F    the 448 to-be-signed bytes, for an
  *       offline signer: openssl pkeyutl -sign -inkey owner_root.pem -rawin -in F -out SIG
+ *       (signer_id = SHA-256(pubkey) lies inside the signed bytes, so it is set
+ *       before the bytes are emitted; attach-sig checks the same bytes)
  *   ck_slot_tool attach-sig M --sig SIG --out M2 --pubkey HEX64
  *   ck_slot_tool sign-test M --out M2            RFC 8032 TEST 1 key. NEVER for hardware.
  *   ck_slot_tool verify M --image F (--keys FILE | --test-key) [--cap BYTES]
@@ -699,11 +701,20 @@ static int cmd_show(int argc, char **argv)
 static int cmd_tbs(int argc, char **argv)
 {
     struct ck_slot_manifest m;
-    const char *out = opt(argc, argv, "--out");
-    if (argc < 3 || !out)
-        return refuse("tbs M --out F");
+    const char *out = opt(argc, argv, "--out"), *pkh = opt(argc, argv, "--pubkey");
+    uint8_t pk[32];
+    if (argc < 3 || !out || !pkh)
+        return refuse("tbs M --pubkey HEX64 --out F");
     if (load_manifest(argv[2], &m) != 0)
         return 1;
+    if (parse_hex(pkh, pk, 32) != 0)
+        return refuse("--pubkey is not 64 hex characters");
+    if (is_test_key(pk))
+        return refuse("--pubkey is a known TEST key");
+    /* signer_id is inside the signed bytes [0, CK_SLOT_TBS_BYTES): attach-sig and
+     * the loader check the signature over the manifest with signer_id set, so the
+     * offline signer must sign those same bytes. */
+    sha256_hash(pk, 32, m.signer_id);
     if (write_file(out, &m, CK_SLOT_TBS_BYTES) != 0)
         return refuse("cannot write the to-be-signed bytes");
     printf("tbs: %u bytes written to %s\n", CK_SLOT_TBS_BYTES, out);
diff --git a/scripts/.crumb b/scripts/.crumb
index 1fa639a8..b7a7a11e 100644
--- a/scripts/.crumb
+++ b/scripts/.crumb
@@ -7,14 +7,14 @@
     "generated": {
       "children": [],
       "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "compiled_at": "2026-10-12T14:57:41Z",
+      "compiled_at": "2026-10-12T16:07:30Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:d124a74c6a60db0dbb1b79e7f92f5f90eb0a9cace1873417f986f0075be061bf",
+      "digest": "sha256:654df809529c9ef3d80af6141a30543a957e3ebde6010d9726519f7fa2a24138",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 86,
-      "generated_at_commit": "6e3c492a4bee0154cb05d1c3e45f8874b6588d2d",
-      "source_tree": "sha256:8e782894349c4cca03bc62e82f5679a8022bb8c3aad7cdcbb9d864b1b750afd2"
+      "generated_at_commit": "f56f72b2bdf52b7f2347c6548e42459e465558a0",
+      "source_tree": "sha256:4104c7c8197e5e1acabf1ccda571c9c116fba7b88bd340f017459bee27d23d7d"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/scripts/native_package.sh b/scripts/native_package.sh
index 28fbaa2e..96d2220e 100755
--- a/scripts/native_package.sh
+++ b/scripts/native_package.sh
@@ -6,31 +6,51 @@
 #   image/BOOTAA64.EFI     the image, built twice from a clean tree; the two
 #                          builds must be byte-identical or the package is
 #                          refused as not signable (TRUST-1 Q24)
-#   PACKAGE.txt            "key value" lines: format, commit, variant, image
-#                          digests, toolchain, component pins, model digest,
-#                          firmware digests (see write_package_txt)
+#   PACKAGE.txt            the provenance record, "key value" lines (format 2):
+#                          source revision (commit, commit time, tree_clean),
+#                          toolchain (cross prefix, gcc/ld/objcopy/make version
+#                          lines, build host arch), inputs (make goal and
+#                          variables, Makefile and image.ld digests, component
+#                          pins, model and firmware digests, owner file digests)
+#                          and the resulting image (bytes, SHA-256, SHA-512).
+#                          See write_package_txt and docs/NATIVE_PACKAGE.md.
 #   SHA256SUMS             sha256sum lines over image/BOOTAA64.EFI and PACKAGE.txt
+#   PROVENANCE.txt         "package_sha256 <sha256(SHA256SUMS)>": the resulting
+#                          package digest, which is also the slot manifest's
+#                          provenance field (it cannot live in PACKAGE.txt,
+#                          which SHA256SUMS covers)
 #   slot/MANIFEST.bin      unsigned slot manifest (native/boot/slot_format.h);
-#                          its provenance field is the 64 hex characters of
-#                          sha256(SHA256SUMS), so the owner's one signature
-#                          over the manifest binds the whole package
-#   slot/MANIFEST.tbs      the 448 bytes the owner signs offline:
-#                          openssl pkeyutl -sign -inkey owner_root.pem -rawin \
+#                          its provenance field is package_sha256, so the
+#                          owner's one signature over the manifest binds the
+#                          whole package
+#   slot/MANIFEST.tbs      the 448 bytes the owner signs offline, written by
+#                          `tbs --pubkey` (or `build --pubkey`): signer_id =
+#                          SHA-256(pubkey) is inside the signed bytes.
+#                          openssl pkeyutl -sign -inkey owner_root.key.pem -rawin \
 #                              -in MANIFEST.tbs -out MANIFEST.sig
 #   slot/MANIFEST.signed.bin  after `sign` (or `sign-test`, TEST key only)
 #
 #   native_package.sh build --out DIR --generation N [--variant core|full|hardware-staging]
 #       [--owner-pubkeys F --machine-id F]   (hardware-staging only)
 #       [--policy-generation N] [--min-rollback N] [--pins FILE] [--model FILE]
-#       [--firmware FILE]... [--allow-dirty]
-#   native_package.sh sign --package DIR --sig FILE --pubkey HEX64
+#       [--firmware FILE]... [--pubkey HEX64] [--allow-dirty]
+#   native_package.sh tbs --package DIR --pubkey HEX64
+#   native_package.sh sign --package DIR --sig FILE --pubkey HEX64 [--allow-dirty]
 #   native_package.sh sign-test --package DIR          RFC 8032 TEST 1 key, tests only
 #   native_package.sh verify --package DIR (--keys FILE | --test-key) [--allow-unsigned]
+#       [--same-host] [--allow-dirty]
 #
 # --pins FILE: lines "<repo> <40 hex>" copied into PACKAGE.txt after validation.
 # --model FILE: its sha256 and size are recorded (the frozen model of P09/P12).
 # --firmware FILE: each file's sha256 and size are recorded (GB10 firmware blobs
 #   of docs/GB10_FIRMWARE_INVENTORY.md). Nothing is loaded or booted.
+# --allow-dirty (tests only): build from a dirty tree, recorded as tree_clean no;
+#   verify and sign refuse such a package unless given --allow-dirty too
+#   (sign-test does not refuse it: the TEST key is never for hardware).
+# --same-host: verify compares the recorded toolchain lines with the toolchain
+#   running here; without it they are printed as "recorded".
+# Any CK_* variable in the environment is refused: every make variable that
+# selects the image is passed explicitly and recorded.
 # Build-only. Never writes outside DIR and the scratch build directories.
 # Every refusal prints "refused: <reason>" and exits 1.
 set -euo pipefail
@@ -38,7 +58,9 @@ set -euo pipefail
 here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
 repo=$(cd "$here/.." && pwd)
 kdir="$repo/native/kernel"
-FORMAT=1
+FORMAT=2
+MAKEFILE_REL=native/kernel/Makefile
+IMAGE_LD_REL=native/boot/image.ld
 
 refuse() { echo "refused: $*"; exit 1; }
 hex40() { [[ "$1" =~ ^[0-9a-f]{40}$ ]]; }
@@ -53,6 +75,39 @@ slot_tool() {
     echo "$out/host/ck_slot_tool"
 }
 
+# ---- toolchain and inputs (what the record says and verify recomputes) -------------
+# The cross prefix exactly as the kernel Makefile resolves it (CROSS ?= ..., by host
+# arch, environment and MAKEFLAGS included), asked from make itself.
+cross_prefix() {
+    make -s --no-print-directory -C "$kdir" --eval 'np-print-cross: ; @echo "[$(CROSS)]"' np-print-cross \
+        | sed -n 's/^\[\(.*\)\]$/\1/p'
+}
+cross_name() { if [ -n "$1" ]; then echo "$1"; else echo none; fi; }
+cross_value() { if [ "$1" = none ]; then echo ""; else echo "$1"; fi; }
+first_line() { "$@" 2>/dev/null | head -1; }
+# toolchain_lines CROSS: the toolchain lines of PACKAGE.txt, in order.
+toolchain_lines() {
+    local c="$1"
+    echo "toolchain_cross $(cross_name "$c")"
+    echo "toolchain_cc $(first_line "${c}gcc" --version)"
+    echo "toolchain_ld $(first_line "${c}ld" --version)"
+    echo "toolchain_objcopy $(first_line "${c}objcopy" --version)"
+    echo "toolchain_make $(first_line make --version)"
+    echo "build_host_arch $(uname -m)"
+}
+# The make goal and variables build_once passes for a variant ($2/$3: owner file digests).
+make_goal_of() { case "$1" in core) echo all;; *) echo full;; esac; }
+make_vars_of() {
+    if [ "$1" = hardware-staging ]; then
+        echo "CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS=sha256:$2 CK_MACHINE_ID=sha256:$3"
+    else
+        echo none
+    fi
+}
+ck_env() { # CK_* in the environment, or passed down from an outer make in MAKEFLAGS
+    { env | sed -n 's/^\(CK_[A-Za-z0-9_]*\)=.*/\1/p'; echo "${MAKEFLAGS:-}" | tr ' ' '\n' | sed -n 's/^\(CK_[A-Za-z0-9_]*\)=.*/\1/p'; } | sort -u | tr '\n' ' ' | sed 's/ $//'
+}
+
 # ---- build ---------------------------------------------------------------------
 build_once() {
     # $1 = OUT dir, $2 = variant, $3 = owner pubkeys, $4 = machine id
@@ -68,27 +123,29 @@ build_once() {
 }
 
 write_package_txt() {
-    # $1 = package dir, then named globals
-    local dir="$1"
+    # $1 = package dir, then named globals of cmd_build
+    local dir="$1" own_sha="" mid_sha=""
+    if [ -n "$own" ]; then own_sha=$(sha256_of "$own"); mid_sha=$(sha256_of "$mid"); fi
     {
         echo "format $FORMAT"
+        # source revision
         echo "repo aien-dev/aienos"
         echo "commit $commit"
         echo "commit_time $commit_time"
-        echo "tree clean"
+        echo "tree_clean $tree_clean"
+        # what was asked for
         echo "variant $variant"
         echo "generation $generation"
         echo "policy_generation $policy_generation"
         echo "min_rollback_generation $min_rollback"
-        echo "image image/BOOTAA64.EFI"
-        echo "image_bytes $(size_of "$dir/image/BOOTAA64.EFI")"
-        echo "image_sha256 $(sha256_of "$dir/image/BOOTAA64.EFI")"
-        echo "image_sha512 $(sha512_of "$dir/image/BOOTAA64.EFI")"
-        echo "reproducible two_clean_builds_identical"
-        echo "toolchain_cc $(gcc --version | head -1)"
-        echo "toolchain_ld $(ld --version | head -1)"
-        echo "toolchain_make $(make --version | head -1)"
-        echo "build_host_arch $(uname -m)"
+        # toolchain (the one make used: CROSS-prefixed tools)
+        toolchain_lines "$cross"
+        # inputs that select the image
+        echo "input_make_goal $(make_goal_of "$variant")"
+        echo "input_make_vars $(make_vars_of "$variant" "$own_sha" "$mid_sha")"
+        echo "input_env_ck none"
+        echo "input_makefile_sha256 $(sha256_of "$repo/$MAKEFILE_REL")"
+        echo "input_image_ld_sha256 $(sha256_of "$repo/$IMAGE_LD_REL")"
         if [ -n "$pins" ]; then
             while read -r r s; do
                 [ -z "$r" ] && continue
@@ -104,15 +161,30 @@ write_package_txt() {
             echo "firmware $(basename "$f") $(size_of "$f") $(sha256_of "$f")"
         done
         if [ -n "$own" ]; then
-            echo "owner_pubkeys_sha256 $(sha256_of "$own")"
-            echo "machine_id_sha256 $(sha256_of "$mid")"
+            echo "owner_pubkeys_sha256 $own_sha"
+            echo "machine_id_sha256 $mid_sha"
         fi
+        # resulting image
+        echo "image image/BOOTAA64.EFI"
+        echo "image_bytes $(size_of "$dir/image/BOOTAA64.EFI")"
+        echo "image_sha256 $(sha256_of "$dir/image/BOOTAA64.EFI")"
+        echo "image_sha512 $(sha512_of "$dir/image/BOOTAA64.EFI")"
+        echo "reproducible two_clean_builds_identical"
     } >"$dir/PACKAGE.txt"
 }
 
+write_tbs() {
+    # $1 = package dir, $2 = pubkey hex, $3 = tool
+    hex64 "$2" || refuse "--pubkey must be 64 hex characters"
+    local tout
+    tout=$("$3" tbs "$1/slot/MANIFEST.bin" --pubkey "$2" --out "$1/slot/MANIFEST.tbs" 2>&1) || {
+        echo "$tout" | /usr/bin/grep '^refused:' || true
+        refuse "to-be-signed bytes not written"; }
+}
+
 cmd_build() {
     local out="" generation="" variant="full" own="" mid="" policy_generation=0 min_rollback=0
-    local pins="" model="" allow_dirty=0
+    local pins="" model="" allow_dirty=0 pubkey=""
     local -a firmware=()
     while [ $# -gt 0 ]; do
         case "$1" in
@@ -126,6 +198,7 @@ cmd_build() {
         --pins) pins="$2"; shift 2;;
         --model) model="$2"; shift 2;;
         --firmware) firmware+=("$2"); shift 2;;
+        --pubkey) pubkey="$2"; shift 2;;
         --allow-dirty) allow_dirty=1; shift;;
         *) refuse "build: unknown argument $1";;
         esac
@@ -134,6 +207,7 @@ cmd_build() {
     [[ "$generation" =~ ^[1-9][0-9]*$ ]] || refuse "build needs --generation N (positive integer)"
     [[ "$policy_generation" =~ ^[0-9]+$ ]] || refuse "--policy-generation must be an integer"
     [[ "$min_rollback" =~ ^[0-9]+$ ]] || refuse "--min-rollback must be an integer"
+    [ -z "$pubkey" ] || hex64 "$pubkey" || refuse "--pubkey must be 64 hex characters"
     [ -e "$out" ] && refuse "--out $out already exists (packages are never overwritten)"
     if [ "$variant" = hardware-staging ]; then
         [ -n "$own" ] && [ -n "$mid" ] || refuse "hardware-staging needs --owner-pubkeys and --machine-id"
@@ -151,16 +225,21 @@ cmd_build() {
     fi
     [ -z "$model" ] || [ -f "$model" ] || refuse "model file missing"
     for f in "${firmware[@]}"; do [ -f "$f" ] || refuse "firmware file missing: $f"; done
+    local envck
+    envck=$(ck_env)
+    [ -z "$envck" ] || refuse "CK_* variables in the environment change the image without being recorded: $envck"
 
-    local dirty
+    local dirty tree_clean=yes
     dirty=$(git -C "$repo" status --porcelain --untracked-files=no)
-    if [ -n "$dirty" ] && [ "$allow_dirty" = 0 ]; then
-        refuse "working tree is dirty; a package is built from a committed tree only (or --allow-dirty for tests)"
+    if [ -n "$dirty" ]; then
+        [ "$allow_dirty" = 1 ] || refuse "working tree is dirty; a package is built from a committed tree only (or --allow-dirty for tests)"
+        tree_clean=no
     fi
-    local commit commit_time
+    local commit commit_time cross
     commit=$(git -C "$repo" rev-parse HEAD)
     commit_time=$(git -C "$repo" log -1 --format=%ct)
     hex40 "$commit" || refuse "cannot read the commit"
+    cross=$(cross_prefix)
 
     local scratch
     scratch=$(mktemp -d "${TMPDIR:-/tmp}/native-package.XXXXXX")
@@ -185,42 +264,131 @@ cmd_build() {
     (cd "$out" && sha256sum image/BOOTAA64.EFI PACKAGE.txt >SHA256SUMS)
     local prov tool
     prov=$(sha256_of "$out/SHA256SUMS")
+    echo "package_sha256 $prov" >"$out/PROVENANCE.txt"
     tool=$(slot_tool)
     "$tool" make-manifest --image "$out/image/BOOTAA64.EFI" --generation "$generation" \
         --policy-generation "$policy_generation" --min-rollback "$min_rollback" \
         --commit "$commit" --provenance "$prov" --timestamp "$commit_time" \
         --out "$out/slot/MANIFEST.bin" >/dev/null || refuse "slot manifest not built"
-    "$tool" tbs "$out/slot/MANIFEST.bin" --out "$out/slot/MANIFEST.tbs" >/dev/null
+    [ -z "$pubkey" ] || write_tbs "$out" "$pubkey" "$tool"
     echo "package built: $out"
-    echo "  commit $commit variant $variant generation $generation"
+    echo "  commit $commit (tree_clean $tree_clean) variant $variant generation $generation"
     echo "  image sha256 $da ($(size_of "$out/image/BOOTAA64.EFI") bytes), two clean builds identical"
-    echo "  provenance (sha256 of SHA256SUMS) $prov"
-    echo "  sign offline: openssl pkeyutl -sign -inkey owner_root.pem -rawin -in $out/slot/MANIFEST.tbs -out MANIFEST.sig"
+    echo "  package_sha256 (sha256 of SHA256SUMS, the slot provenance) $prov"
+    if [ -z "$pubkey" ]; then
+        echo "  next: $0 tbs --package $out --pubkey <owner public key, 64 hex>"
+    fi
+    echo "  sign offline: openssl pkeyutl -sign -inkey owner_root.key.pem -rawin -in $out/slot/MANIFEST.tbs -out MANIFEST.sig"
     echo "  then: $0 sign --package $out --sig MANIFEST.sig --pubkey <64 hex>"
 }
 
-# ---- package integrity (shared by sign and verify) ---------------------------------
+# ---- package integrity (shared by tbs, sign and verify) -----------------------------
+rec() { awk -v k="$2" '$1==k{sub(/^[^ ]+ /,""); print}' "$1/PACKAGE.txt"; }
+
 check_package_files() {
     local dir="$1"
     [ -d "$dir" ] || refuse "package directory missing"
-    for f in image/BOOTAA64.EFI PACKAGE.txt SHA256SUMS slot/MANIFEST.bin; do
+    for f in image/BOOTAA64.EFI PACKAGE.txt SHA256SUMS PROVENANCE.txt slot/MANIFEST.bin; do
         [ -f "$dir/$f" ] || refuse "package is missing $f"
     done
     (cd "$dir" && sha256sum -c --quiet --strict SHA256SUMS >/dev/null 2>&1) || refuse "SHA256SUMS does not match the package files"
     local fmt
-    fmt=$(awk '$1=="format"{print $2}' "$dir/PACKAGE.txt")
+    fmt=$(rec "$dir" format)
     [ "$fmt" = "$FORMAT" ] || refuse "PACKAGE.txt format $fmt is not $FORMAT"
-    local want_sha have_sha
-    want_sha=$(awk '$1=="image_sha256"{print $2}' "$dir/PACKAGE.txt")
-    have_sha=$(sha256_of "$dir/image/BOOTAA64.EFI")
-    [ "$want_sha" = "$have_sha" ] || refuse "PACKAGE.txt image_sha256 does not match the image"
-    local repro
-    repro=$(awk '$1=="reproducible"{print $2}' "$dir/PACKAGE.txt")
-    [ "$repro" = two_clean_builds_identical ] || refuse "PACKAGE.txt does not record a reproducible build"
+    local want have
+    want=$(awk '$1=="package_sha256"{print $2}' "$dir/PROVENANCE.txt")
+    have=$(sha256_of "$dir/SHA256SUMS")
+    [ "$want" = "$have" ] || refuse "PROVENANCE.txt package_sha256 is not the SHA-256 of SHA256SUMS"
+}
+
+# check_record DIR SAME_HOST ALLOW_DIRTY: every PACKAGE.txt line that can be recomputed
+# here must match; the rest are printed as recorded. Prints "  checked|recorded key value".
+check_record() {
+    local dir="$1" same_host="$2" allow_dirty="$3" k
+    local -a required=(format repo commit commit_time tree_clean variant generation policy_generation
+        min_rollback_generation toolchain_cross toolchain_cc toolchain_ld toolchain_objcopy toolchain_make
+        build_host_arch input_make_goal input_make_vars input_env_ck input_makefile_sha256
+        input_image_ld_sha256 image image_bytes image_sha256 image_sha512 reproducible)
+    for k in "${required[@]}"; do
+        [ "$(awk -v k="$k" '$1==k' "$dir/PACKAGE.txt" | wc -l)" = 1 ] || refuse "PACKAGE.txt must hold exactly one $k line"
+    done
+    local img="$dir/image/BOOTAA64.EFI"
+    [ "$(rec "$dir" image)" = image/BOOTAA64.EFI ] || refuse "PACKAGE.txt image is not image/BOOTAA64.EFI"
+    [ "$(rec "$dir" image_bytes)" = "$(size_of "$img")" ] || refuse "PACKAGE.txt image_bytes does not match the image"
+    [ "$(rec "$dir" image_sha256)" = "$(sha256_of "$img")" ] || refuse "PACKAGE.txt image_sha256 does not match the image"
+    [ "$(rec "$dir" image_sha512)" = "$(sha512_of "$img")" ] || refuse "PACKAGE.txt image_sha512 does not match the image"
+    [ "$(rec "$dir" reproducible)" = two_clean_builds_identical ] || refuse "PACKAGE.txt does not record a reproducible build"
+    local tc; tc=$(rec "$dir" tree_clean)
+    case "$tc" in
+    yes) ;;
+    no) [ "$allow_dirty" = 1 ] || refuse "package was built from a dirty tree (tree_clean no): not a release candidate";;
+    *) refuse "PACKAGE.txt tree_clean is neither yes nor no";;
+    esac
+    [ "$(rec "$dir" input_env_ck)" = none ] || refuse "PACKAGE.txt input_env_ck is not none"
+    local variant own_sha mid_sha
+    variant=$(rec "$dir" variant)
+    case "$variant" in core|full|hardware-staging) ;; *) refuse "PACKAGE.txt variant $variant is unknown";; esac
+    own_sha=$(rec "$dir" owner_pubkeys_sha256); mid_sha=$(rec "$dir" machine_id_sha256)
+    if [ "$variant" = hardware-staging ]; then
+        hex64 "$own_sha" && hex64 "$mid_sha" || refuse "hardware-staging PACKAGE.txt lacks the owner file digests"
+    else
+        [ -z "$own_sha$mid_sha" ] || refuse "PACKAGE.txt has owner file digests on a $variant package"
+    fi
+    [ "$(rec "$dir" input_make_goal)" = "$(make_goal_of "$variant")" ] || refuse "PACKAGE.txt input_make_goal does not match variant $variant"
+    [ "$(rec "$dir" input_make_vars)" = "$(make_vars_of "$variant" "$own_sha" "$mid_sha")" ] || refuse "PACKAGE.txt input_make_vars does not match variant $variant"
+    echo "record:"
+    for k in image image_bytes image_sha256 image_sha512 reproducible tree_clean input_env_ck variant input_make_goal input_make_vars; do
+        echo "  checked  $k $(rec "$dir" "$k")"
+    done
+
+    # Source revision and source inputs: recomputed from the commit when this repository
+    # has it (clean package) or from the working tree (dirty package, tests only).
+    local commit; commit=$(rec "$dir" commit)
+    hex40 "$commit" || refuse "PACKAGE.txt commit is not 40 hex characters"
+    if git -C "$repo" cat-file -e "$commit^{commit}" 2>/dev/null; then
+        [ "$(rec "$dir" commit_time)" = "$(git -C "$repo" log -1 --format=%ct "$commit")" ] || refuse "PACKAGE.txt commit_time does not match commit $commit"
+        echo "  checked  commit $commit"
+        echo "  checked  commit_time $(rec "$dir" commit_time)"
+        local f key have
+        for f in "$MAKEFILE_REL:input_makefile_sha256" "$IMAGE_LD_REL:input_image_ld_sha256"; do
+            key=${f#*:}; f=${f%%:*}
+            if [ "$tc" = yes ]; then
+                have=$(git -C "$repo" show "$commit:$f" | sha256sum | cut -d' ' -f1)
+            else
+                have=$(sha256_of "$repo/$f")
+            fi
+            [ "$(rec "$dir" "$key")" = "$have" ] || refuse "PACKAGE.txt $key does not match $f at $([ "$tc" = yes ] && echo "commit $commit" || echo "the working tree")"
+            echo "  checked  $key $have"
+        done
+    else
+        for k in commit commit_time input_makefile_sha256 input_image_ld_sha256; do
+            echo "  recorded $k $(rec "$dir" "$k") (commit not in this repository)"
+        done
+    fi
+
+    # Toolchain: compared with the running toolchain only when asked (--same-host).
+    if [ "$same_host" = 1 ]; then
+        local c line
+        c=$(cross_value "$(rec "$dir" toolchain_cross)")
+        [ "$(cross_name "$(cross_prefix)")" = "$(rec "$dir" toolchain_cross)" ] || refuse "toolchain_cross differs from this host's ($(cross_name "$(cross_prefix)"))"
+        while read -r line; do
+            k=${line%% *}
+            [ "$(rec "$dir" "$k")" = "${line#* }" ] || refuse "$k differs from this host (recorded '$(rec "$dir" "$k")', here '${line#* }')"
+            echo "  checked  $line"
+        done < <(toolchain_lines "$c")
+    else
+        for k in toolchain_cross toolchain_cc toolchain_ld toolchain_objcopy toolchain_make build_host_arch; do
+            echo "  recorded $k $(rec "$dir" "$k")"
+        done
+    fi
+    # Not recomputable from the package alone: generations are checked through the
+    # manifest; pins, model and firmware are the digests of files the package does not carry.
+    awk '$1=="generation"||$1=="policy_generation"||$1=="min_rollback_generation"||$1=="pin"||$1=="model_bytes"||$1=="model_sha256"||$1=="firmware"||$1=="owner_pubkeys_sha256"||$1=="machine_id_sha256"{print "  recorded " $0}' "$dir/PACKAGE.txt"
+    echo "  checked  package_sha256 $(sha256_of "$dir/SHA256SUMS")"
 }
 
 manifest_provenance_check() {
-    # $1 = dir, $2 = manifest file. The manifest's provenance must be sha256(SHA256SUMS)
+    # $1 = dir, $2 = manifest file. The manifest's provenance must be package_sha256
     # and its commit must be PACKAGE.txt's commit. Read via the tool's print lines.
     local dir="$1" mf="$2" tool="$3"
     local line prov commit want_prov want_commit
@@ -228,24 +396,48 @@ manifest_provenance_check() {
     commit=$(echo "$line" | sed -n 's/^  commit=\([0-9a-f]\{40\}\) provenance=.*/\1/p')
     prov=$(echo "$line" | sed -n 's/^  commit=[0-9a-f]\{40\} provenance=\([0-9a-f]\{64\}\).*/\1/p')
     want_prov=$(sha256_of "$dir/SHA256SUMS")
-    want_commit=$(awk '$1=="commit"{print $2}' "$dir/PACKAGE.txt")
+    want_commit=$(rec "$dir" commit)
     [ "$prov" = "$want_prov" ] || refuse "manifest provenance does not bind this package's SHA256SUMS"
     [ "$commit" = "$want_commit" ] || refuse "manifest commit does not match PACKAGE.txt"
 }
 
+cmd_tbs() {
+    local dir="" pk=""
+    while [ $# -gt 0 ]; do
+        case "$1" in
+        --package) dir="$2"; shift 2;;
+        --pubkey) pk="$2"; shift 2;;
+        *) refuse "tbs: unknown argument $1";;
+        esac
+    done
+    [ -n "$dir" ] && [ -n "$pk" ] || refuse "tbs needs --package DIR and --pubkey HEX64"
+    check_package_files "$dir"
+    local tool
+    tool=$(slot_tool)
+    manifest_provenance_check "$dir" "$dir/slot/MANIFEST.bin" "$tool"
+    write_tbs "$dir" "$pk" "$tool"
+    echo "to-be-signed bytes for signer $pk: $dir/slot/MANIFEST.tbs"
+}
+
 cmd_sign() {
-    local dir="" sig="" pk="" test_key=0
+    local dir="" sig="" pk="" test_key=0 allow_dirty=0
     while [ $# -gt 0 ]; do
         case "$1" in
         --package) dir="$2"; shift 2;;
         --sig) sig="$2"; shift 2;;
         --pubkey) pk="$2"; shift 2;;
         --test) test_key=1; shift;;
+        --allow-dirty) allow_dirty=1; shift;;
         *) refuse "sign: unknown argument $1";;
         esac
     done
     [ -n "$dir" ] || refuse "sign needs --package DIR"
     check_package_files "$dir"
+    # A real signature never goes on a dirty-tree package (--allow-dirty: tests only);
+    # TEST signing may.
+    local rout
+    [ "$test_key" = 1 ] && allow_dirty=1
+    rout=$(check_record "$dir" 0 "$allow_dirty") || { echo "$rout" | /usr/bin/grep '^refused:'; exit 1; }
     local tool
     tool=$(slot_tool)
     manifest_provenance_check "$dir" "$dir/slot/MANIFEST.bin" "$tool"
@@ -257,24 +449,33 @@ cmd_sign() {
     fi
     [ -n "$sig" ] && [ -n "$pk" ] || refuse "sign needs --sig FILE and --pubkey HEX64"
     hex64 "$pk" || refuse "--pubkey must be 64 hex characters"
-    "$tool" attach-sig "$dir/slot/MANIFEST.bin" --sig "$sig" --pubkey "$pk" --out "$dir/slot/MANIFEST.signed.bin" | tail -1
+    local aout
+    if ! aout=$("$tool" attach-sig "$dir/slot/MANIFEST.bin" --sig "$sig" --pubkey "$pk" --out "$dir/slot/MANIFEST.signed.bin" 2>&1); then
+        echo "$aout" | /usr/bin/grep '^refused:' || true
+        refuse "signature not attached"
+    fi
+    echo "$aout" | tail -1
     echo "signed package: $dir"
 }
 
 cmd_verify() {
-    local dir="" keys="" test_key=0 allow_unsigned=0
+    local dir="" keys="" test_key=0 allow_unsigned=0 same_host=0 allow_dirty=0
     while [ $# -gt 0 ]; do
         case "$1" in
         --package) dir="$2"; shift 2;;
         --keys) keys="$2"; shift 2;;
         --test-key) test_key=1; shift;;
         --allow-unsigned) allow_unsigned=1; shift;;
+        --same-host) same_host=1; shift;;
+        --allow-dirty) allow_dirty=1; shift;;
         *) refuse "verify: unknown argument $1";;
         esac
     done
     [ -n "$dir" ] || refuse "verify needs --package DIR"
     [ -n "$keys" ] || [ "$test_key" = 1 ] || refuse "verify needs --keys FILE or --test-key"
     check_package_files "$dir"
+    local record
+    record=$(check_record "$dir" "$same_host" "$allow_dirty") || { echo "$record" | /usr/bin/grep '^refused:'; exit 1; }
     local tool
     tool=$(slot_tool)
     local mf="$dir/slot/MANIFEST.signed.bin"
@@ -282,6 +483,7 @@ cmd_verify() {
         [ "$allow_unsigned" = 1 ] || refuse "package is UNSIGNED (slot/MANIFEST.signed.bin missing)"
         manifest_provenance_check "$dir" "$dir/slot/MANIFEST.bin" "$tool"
         echo "VERIFY: UNSIGNED package is internally consistent (not installable)"
+        echo "$record"
         return 0
     fi
     manifest_provenance_check "$dir" "$mf" "$tool"
@@ -296,13 +498,14 @@ cmd_verify() {
     cmp -s <(head -c 184 "$dir/slot/MANIFEST.bin") <(head -c 184 "$mf") || refuse "signed manifest differs from the built manifest"
     echo "VERIFY: PASS $dir"
     echo "$vout" | /usr/bin/grep -E '^(verify:|manifest:|keys:)'
-    awk '$1=="commit"||$1=="variant"||$1=="generation"||$1=="image_sha256"||$1=="model_sha256"||$1=="pin"{print "  " $0}' "$dir/PACKAGE.txt"
+    echo "$record"
 }
 
 case "${1:-}" in
 build) shift; cmd_build "$@";;
+tbs) shift; cmd_tbs "$@";;
 sign) shift; cmd_sign "$@";;
 sign-test) shift; cmd_sign --test "$@";;
 verify) shift; cmd_verify "$@";;
-*) refuse "usage: native_package.sh build|sign|sign-test|verify ... (see the header)";;
+*) refuse "usage: native_package.sh build|tbs|sign|sign-test|verify ... (see the header)";;
 esac
diff --git a/scripts/native_package_test.sh b/scripts/native_package_test.sh
index 163b466c..314c932e 100755
--- a/scripts/native_package_test.sh
+++ b/scripts/native_package_test.sh
@@ -1,15 +1,20 @@
 #!/usr/bin/env bash
-# native_package_test.sh -- self-test of scripts/native_package.sh (P11 cut 1b).
-# Build-only; nothing is booted. Uses the RFC 8032 TEST 1 signer (never for
-# hardware) and the labelled TEST-FIXTURE owner files. Every row prints PASS or
-# FAIL; the last line is NATIVE_PACKAGE_TEST: PASS|FAIL (n checks).
+# native_package_test.sh -- self-test of scripts/native_package.sh (P11 cut 1b and
+# its provenance record). Build-only; nothing is booted. Uses the RFC 8032 TEST 1
+# signer (never for hardware), the labelled TEST-FIXTURE owner files, and one
+# throwaway Ed25519 key made here with OpenSSL for the offline-signing round trip.
+# Every row prints PASS or FAIL; the last line is NATIVE_PACKAGE_TEST: PASS|FAIL (n checks).
 set -uo pipefail
 here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
 repo=$(cd "$here/.." && pwd)
 np="$here/native_package.sh"
 fix="$repo/native/kernel/tests/fixtures/owner"
 T=$(mktemp -d "${TMPDIR:-/tmp}/native-package-test.XXXXXX")
-trap 'rm -rf "$T"' EXIT
+cleanup() {
+    [ -d "$T/wt" ] && git -C "$repo" worktree remove --force "$T/wt" >/dev/null 2>&1
+    rm -rf "$T"
+}
+trap cleanup EXIT
 export NATIVE_PACKAGE_TOOL_OUT="$T/tool"
 checks=0; fails=0
 pass() { checks=$((checks+1)); echo "PASS: $1"; }
@@ -20,8 +25,17 @@ expect_refused() { # what, needle, cmd...
     if out=$("$@" 2>&1); then fail "$what: accepted"; return; fi
     if echo "$out" | /usr/bin/grep -q -- "$needle"; then pass "$what"; else fail "$what: wrong reason: $(echo "$out" | /usr/bin/grep '^refused' | tail -1)"; fi
 }
+has_line() { # what, file, regex
+    if /usr/bin/grep -qE -- "$3" "$2"; then pass "$1"; else fail "$1"; fi
+}
+remake_sums() { (cd "$1" && sha256sum image/BOOTAA64.EFI PACKAGE.txt >SHA256SUMS); }
+remake_all() { remake_sums "$1"; echo "package_sha256 $(sha256sum "$1/SHA256SUMS" | cut -c1-64)" >"$1/PROVENANCE.txt"; }
 dirty=()
-[ -z "$(git -C "$repo" status --porcelain --untracked-files=no)" ] || dirty=(--allow-dirty)
+tree_clean=yes
+if [ -n "$(git -C "$repo" status --porcelain --untracked-files=no)" ]; then dirty=(--allow-dirty); tree_clean=no; fi
+# The cross prefix the kernel Makefile picks when CROSS is not set (native/kernel/Makefile).
+if [ -n "${CROSS+x}" ]; then want_cross="${CROSS:-none}"; elif [ "$(uname -m)" = aarch64 ]; then want_cross=none; else want_cross=aarch64-linux-gnu-; fi
+wc_=""; [ "$want_cross" = none ] || wc_="$want_cross"
 
 printf 'aien-dev/omega 781e98d8224b5bf229991f54722d2dc7c415d79f\naien-dev/physics 57aafa0d69d5d768e46164ff0963ffd87355ab0d\n' >"$T/pins.txt"
 head -c 4096 /dev/urandom >"$T/model.bin"
@@ -29,43 +43,108 @@ head -c 1024 /dev/urandom >"$T/fw1.bin"
 
 # 1. build a full package with pins, model and firmware digests
 expect_ok "build full package (two clean builds identical)" "$np" build --out "$T/p1" --generation 7 --policy-generation 5 --pins "$T/pins.txt" --model "$T/model.bin" --firmware "$T/fw1.bin" "${dirty[@]}"
+P="$T/p1/PACKAGE.txt"
 for k in "commit " "image_sha256 " "reproducible two_clean_builds_identical" "pin aien-dev/omega 781e98d8" "model_sha256 $(sha256sum "$T/model.bin" | cut -c1-64)" "firmware fw1.bin 1024 "; do
-    if /usr/bin/grep -q "^$k" "$T/p1/PACKAGE.txt"; then pass "PACKAGE.txt has $k"; else fail "PACKAGE.txt lacks $k"; fi
+    if /usr/bin/grep -q "^$k" "$P"; then pass "PACKAGE.txt has $k"; else fail "PACKAGE.txt lacks $k"; fi
 done
-[ "$(stat -c %s "$T/p1/slot/MANIFEST.tbs")" = 448 ] && pass "tbs is 448 bytes" || fail "tbs size"
+[ "$(stat -c %s "$T/p1/slot/MANIFEST.bin")" = 4096 ] && pass "manifest is 4096 bytes" || fail "manifest size"
+# 1b. the provenance record: source revision, toolchain, inputs, resulting digest
+has_line "record: format 2" "$P" "^format 2$"
+has_line "record: commit is HEAD" "$P" "^commit $(git -C "$repo" rev-parse HEAD)$"
+has_line "record: commit_time is HEAD's" "$P" "^commit_time $(git -C "$repo" log -1 --format=%ct)$"
+has_line "record: tree_clean $tree_clean" "$P" "^tree_clean $tree_clean$"
+has_line "record: toolchain_cross $want_cross" "$P" "^toolchain_cross $want_cross$"
+has_line "record: toolchain_cc = ${wc_}gcc --version" "$P" "^toolchain_cc $(${wc_}gcc --version | head -1 | sed 's/[][\.*^$()+?{}|]/\\&/g')$"
+has_line "record: toolchain_ld = ${wc_}ld --version" "$P" "^toolchain_ld $(${wc_}ld --version | head -1 | sed 's/[][\.*^$()+?{}|]/\\&/g')$"
+has_line "record: toolchain_objcopy = ${wc_}objcopy --version" "$P" "^toolchain_objcopy $(${wc_}objcopy --version | head -1 | sed 's/[][\.*^$()+?{}|]/\\&/g')$"
+has_line "record: toolchain_make" "$P" "^toolchain_make GNU Make "
+has_line "record: build_host_arch" "$P" "^build_host_arch $(uname -m)$"
+has_line "record: input_make_goal full" "$P" "^input_make_goal full$"
+has_line "record: input_make_vars none" "$P" "^input_make_vars none$"
+has_line "record: input_env_ck none" "$P" "^input_env_ck none$"
+has_line "record: input_makefile_sha256" "$P" "^input_makefile_sha256 $(sha256sum "$repo/native/kernel/Makefile" | cut -c1-64)$"
+has_line "record: input_image_ld_sha256" "$P" "^input_image_ld_sha256 $(sha256sum "$repo/native/boot/image.ld" | cut -c1-64)$"
+has_line "record: image_bytes" "$P" "^image_bytes $(stat -c %s "$T/p1/image/BOOTAA64.EFI")$"
+has_line "record: image_sha512" "$P" "^image_sha512 $(sha512sum "$T/p1/image/BOOTAA64.EFI" | cut -c1-128)$"
+has_line "PROVENANCE.txt package_sha256 = sha256(SHA256SUMS)" "$T/p1/PROVENANCE.txt" "^package_sha256 $(sha256sum "$T/p1/SHA256SUMS" | cut -c1-64)$"
+"$NATIVE_PACKAGE_TOOL_OUT/host/ck_slot_tool" show "$T/p1/slot/MANIFEST.bin" | /usr/bin/grep -q "provenance=$(sha256sum "$T/p1/SHA256SUMS" | cut -c1-64)" \
+    && pass "manifest provenance = package_sha256" || fail "manifest provenance"
+cp -r "$T/p1" "$T/p1o"   # unsigned copy for the offline-signing round trip (section 8)
 expect_refused "build refuses an existing --out" "already exists" "$np" build --out "$T/p1" --generation 7 "${dirty[@]}"
 echo "aien-dev/omega notahash" >"$T/badpins.txt"
 expect_refused "build refuses a bad pins line" "40 hex" "$np" build --out "$T/px" --generation 7 --pins "$T/badpins.txt" "${dirty[@]}"
 expect_refused "build refuses owner files without hardware-staging" "only with --variant hardware-staging" "$np" build --out "$T/py" --generation 7 --owner-pubkeys "$fix/TEST-FIXTURE-owner-pubkeys.txt" --machine-id "$fix/TEST-FIXTURE-machine-id.txt" "${dirty[@]}"
+expect_refused "build refuses CK_* in the environment" "CK_EXTRA_CFLAGS" env CK_EXTRA_CFLAGS=-DX "$np" build --out "$T/pz" --generation 7 "${dirty[@]}"
+expect_refused "build refuses CK_* passed down in MAKEFLAGS" "CK_SERVICE" env MAKEFLAGS=" -- CK_SERVICE=1" "$np" build --out "$T/pz" --generation 7 "${dirty[@]}"
+# A dirty tree is refused: a detached worktree of HEAD with this script and one changed
+# tracked file (the real checkout is never touched).
+if git -C "$repo" -c core.hooksPath=/dev/null worktree add -q --detach "$T/wt" HEAD >/dev/null 2>&1; then
+    cp "$np" "$T/wt/scripts/native_package.sh"
+    echo "# dirty" >>"$T/wt/native/kernel/Makefile"
+    expect_refused "build refuses a dirty tree" "working tree is dirty" "$T/wt/scripts/native_package.sh" build --out "$T/pd" --generation 7 --variant core
+    [ ! -e "$T/pd" ] && pass "dirty refusal leaves no package" || fail "dirty refusal left a package"
+else
+    fail "could not make a scratch worktree for the dirty-tree check"; fail "dirty refusal leaves no package (not run)"
+fi
 
 # 2. unsigned
-expect_refused "verify refuses an unsigned package" "UNSIGNED" "$np" verify --package "$T/p1" --test-key
-expect_ok "verify --allow-unsigned accepts the consistent unsigned package" "$np" verify --package "$T/p1" --test-key --allow-unsigned
+expect_refused "verify refuses an unsigned package" "UNSIGNED" "$np" verify --package "$T/p1" --test-key "${dirty[@]}"
+expect_ok "verify --allow-unsigned accepts the consistent unsigned package" "$np" verify --package "$T/p1" --test-key --allow-unsigned "${dirty[@]}"
 
 # 3. test-signed, verify, wrong key
 expect_ok "sign-test" "$np" sign-test --package "$T/p1"
 expect_refused "sign-test refuses to sign twice" "already signed" "$np" sign-test --package "$T/p1"
-expect_ok "verify PASS with the TEST key" "$np" verify --package "$T/p1" --test-key
-expect_refused "verify refuses under the fixture owner key" "no trusted key" "$np" verify --package "$T/p1" --keys "$fix/TEST-FIXTURE-owner-pubkeys.txt"
+expect_ok "verify PASS with the TEST key" "$np" verify --package "$T/p1" --test-key "${dirty[@]}"
+expect_refused "verify refuses under the fixture owner key" "no trusted key" "$np" verify --package "$T/p1" --keys "$fix/TEST-FIXTURE-owner-pubkeys.txt" "${dirty[@]}"
 expect_refused "verify needs a key source" "needs --keys" "$np" verify --package "$T/p1"
+out=$("$np" verify --package "$T/p1" --test-key "${dirty[@]}" 2>&1)
+echo "$out" | /usr/bin/grep -q "^  recorded toolchain_cc " && pass "verify prints toolchain lines as recorded" || fail "verify toolchain recorded lines"
+echo "$out" | /usr/bin/grep -q "^  checked  input_makefile_sha256 " && pass "verify recomputes the Makefile digest" || fail "verify Makefile digest line"
+out=$("$np" verify --package "$T/p1" --test-key --same-host "${dirty[@]}" 2>&1)
+echo "$out" | /usr/bin/grep -q "^  checked  toolchain_cc " && pass "verify --same-host checks the toolchain" || fail "verify --same-host: $(echo "$out" | tail -1)"
 
 # 4. tampering (each on a fresh copy)
 cp -r "$T/p1" "$T/t1"; chmod u+w "$T/t1/image/BOOTAA64.EFI"; printf '\xff' | dd of="$T/t1/image/BOOTAA64.EFI" bs=1 seek=100 conv=notrunc status=none
-expect_refused "tampered image byte" "SHA256SUMS does not match" "$np" verify --package "$T/t1" --test-key
+expect_refused "tampered image byte" "SHA256SUMS does not match" "$np" verify --package "$T/t1" --test-key "${dirty[@]}"
 cp -r "$T/p1" "$T/t2"; sed -i 's/^generation 7$/generation 9/' "$T/t2/PACKAGE.txt"
-expect_refused "tampered PACKAGE.txt" "SHA256SUMS does not match" "$np" verify --package "$T/t2" --test-key
-cp -r "$T/p1" "$T/t3"; sed -i 's/^generation 7$/generation 9/' "$T/t3/PACKAGE.txt"; (cd "$T/t3" && sha256sum image/BOOTAA64.EFI PACKAGE.txt >SHA256SUMS)
-expect_refused "tampered PACKAGE.txt with re-made SHA256SUMS" "provenance does not bind" "$np" verify --package "$T/t3" --test-key
+expect_refused "tampered PACKAGE.txt" "SHA256SUMS does not match" "$np" verify --package "$T/t2" --test-key "${dirty[@]}"
+cp -r "$T/p1" "$T/t3"; sed -i 's/^generation 7$/generation 9/' "$T/t3/PACKAGE.txt"; remake_sums "$T/t3"
+expect_refused "tampered PACKAGE.txt with re-made SHA256SUMS" "PROVENANCE.txt package_sha256" "$np" verify --package "$T/t3" --test-key "${dirty[@]}"
+cp -r "$T/p1" "$T/t3b"; sed -i 's/^generation 7$/generation 9/' "$T/t3b/PACKAGE.txt"; remake_all "$T/t3b"
+expect_refused "tampered PACKAGE.txt with re-made SHA256SUMS and PROVENANCE.txt" "provenance does not bind" "$np" verify --package "$T/t3b" --test-key "${dirty[@]}"
 cp -r "$T/p1" "$T/t4"; printf '\x01' | dd of="$T/t4/slot/MANIFEST.signed.bin" bs=1 seek=460 conv=notrunc status=none
-expect_refused "flipped signature byte" "signature or digest" "$np" verify --package "$T/t4" --test-key
+expect_refused "flipped signature byte" "signature or digest" "$np" verify --package "$T/t4" --test-key "${dirty[@]}"
 cp -r "$T/p1" "$T/t5"; rm "$T/t5/SHA256SUMS"
-expect_refused "missing SHA256SUMS" "missing SHA256SUMS" "$np" verify --package "$T/t5" --test-key
+expect_refused "missing SHA256SUMS" "missing SHA256SUMS" "$np" verify --package "$T/t5" --test-key "${dirty[@]}"
+cp -r "$T/p1" "$T/t5b"; rm "$T/t5b/PROVENANCE.txt"
+expect_refused "missing PROVENANCE.txt" "missing PROVENANCE.txt" "$np" verify --package "$T/t5b" --test-key "${dirty[@]}"
+cp -r "$T/p1" "$T/t5c"; echo "package_sha256 $(printf '0%.0s' $(seq 64))" >"$T/t5c/PROVENANCE.txt"
+expect_refused "tampered PROVENANCE.txt" "PROVENANCE.txt package_sha256" "$np" verify --package "$T/t5c" --test-key "${dirty[@]}"
+# 4b. record lines that verify recomputes, each with re-made sums so only the record check can catch it
+tamper() { # name, sed expression, needle, extra verify args...
+    local name="$1" d="$T/r-$1" e="$2" needle="$3"; shift 3
+    cp -r "$T/p1" "$d"; sed -i "$e" "$d/PACKAGE.txt"; remake_all "$d"
+    expect_refused "record check: $name" "$needle" "$np" verify --package "$d" --test-key "$@"
+}
+tamper tree-clean-no 's/^tree_clean .*/tree_clean no/' "dirty tree (tree_clean no)"
+tamper makefile-digest 's/^input_makefile_sha256 ./input_makefile_sha256 f/' "input_makefile_sha256 does not match" "${dirty[@]}"
+tamper image-ld-digest 's/^input_image_ld_sha256 ./input_image_ld_sha256 f/' "input_image_ld_sha256 does not match" "${dirty[@]}"
+tamper commit-time 's/^commit_time .*/commit_time 1/' "commit_time does not match" "${dirty[@]}"
+tamper image-sha512 's/^image_sha512 ./image_sha512 f/' "image_sha512 does not match" "${dirty[@]}"
+tamper image-bytes 's/^image_bytes .*/image_bytes 1/' "image_bytes does not match" "${dirty[@]}"
+tamper make-vars 's/^input_make_vars .*/input_make_vars CK_SERVICE=1/' "input_make_vars does not match" "${dirty[@]}"
+tamper make-goal 's/^input_make_goal .*/input_make_goal all/' "input_make_goal does not match" "${dirty[@]}"
+tamper env-ck 's/^input_env_ck .*/input_env_ck CK_EXTRA_CFLAGS/' "input_env_ck is not none" "${dirty[@]}"
+tamper missing-toolchain '/^toolchain_objcopy /d' "exactly one toolchain_objcopy" "${dirty[@]}"
+tamper duplicate-commit '/^commit /p' "exactly one commit" "${dirty[@]}"
+tamper toolchain-same-host 's/^toolchain_cc .*/toolchain_cc gcc 0.0/' "toolchain_cc differs from this host" --same-host "${dirty[@]}"
 
 # 5. a signed manifest from another package does not verify here
 expect_ok "build core package generation 8" "$np" build --out "$T/p2" --generation 8 --variant core "${dirty[@]}"
+has_line "core record: input_make_goal all" "$T/p2/PACKAGE.txt" "^input_make_goal all$"
 expect_ok "sign-test p2" "$np" sign-test --package "$T/p2"
 cp -r "$T/p1" "$T/t6"; cp "$T/p2/slot/MANIFEST.signed.bin" "$T/t6/slot/MANIFEST.signed.bin"
-expect_refused "signed manifest of another package" "provenance does not bind" "$np" verify --package "$T/t6" --test-key
+expect_refused "signed manifest of another package" "provenance does not bind" "$np" verify --package "$T/t6" --test-key "${dirty[@]}"
 
 # 6. non-reproducible build is refused
 expect_refused "non-reproducible build refused (test hook)" "not reproducible, not signable" env NATIVE_PACKAGE_TEST_CORRUPT_SECOND=1 "$np" build --out "$T/p3" --generation 7 --variant core "${dirty[@]}"
@@ -75,7 +154,37 @@ expect_refused "non-reproducible build refused (test hook)" "not reproducible, n
 expect_ok "build hardware-staging package (fixture owner files)" "$np" build --out "$T/p4" --generation 7 --variant hardware-staging --owner-pubkeys "$fix/TEST-FIXTURE-owner-pubkeys.txt" --machine-id "$fix/TEST-FIXTURE-machine-id.txt" "${dirty[@]}"
 /usr/bin/grep -q "^owner_pubkeys_sha256 " "$T/p4/PACKAGE.txt" && pass "staging PACKAGE.txt records owner_pubkeys_sha256" || fail "staging owner digest missing"
 /usr/bin/grep -q "^variant hardware-staging$" "$T/p4/PACKAGE.txt" && pass "staging variant recorded" || fail "staging variant"
+has_line "staging record: input_make_vars names the owner files by digest" "$T/p4/PACKAGE.txt" \
+    "^input_make_vars CK_HARDWARE_STAGING=1 CK_OWNER_PUBKEYS=sha256:$(sha256sum "$fix/TEST-FIXTURE-owner-pubkeys.txt" | cut -c1-64) CK_MACHINE_ID=sha256:$(sha256sum "$fix/TEST-FIXTURE-machine-id.txt" | cut -c1-64)$"
 expect_refused "staging variant needs both owner files" "needs --owner-pubkeys" "$np" build --out "$T/p5" --generation 7 --variant hardware-staging "${dirty[@]}"
 
+# 8. offline signing round trip with a throwaway key and OpenSSL, as the owner will do it
+#    (docs/OWNER_KEY_CEREMONY.md part 3 step 9): tbs --pubkey, openssl pkeyutl -sign -rawin,
+#    sign --sig --pubkey, verify --keys. Only the public key reaches native_package.sh.
+O="$T/p1o"
+if openssl genpkey -algorithm ed25519 -out "$T/throwaway.key.pem" 2>/dev/null; then
+    pk=$(openssl pkey -in "$T/throwaway.key.pem" -pubout -outform DER | tail -c 32 | od -An -tx1 | tr -d ' \n')
+    printf 'owner_root_ed25519 %s\n' "$pk" >"$T/throwaway-keys.txt"
+    expect_refused "tbs needs --pubkey" "needs --package DIR and --pubkey" "$np" tbs --package "$O"
+    expect_refused "tbs refuses the TEST 1 key" "known TEST key" "$np" tbs --package "$O" --pubkey d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a
+    # the old way: signing the manifest's own first 448 bytes (signer_id still zero) cannot attach
+    head -c 448 "$O/slot/MANIFEST.bin" >"$T/old.tbs"
+    openssl pkeyutl -sign -rawin -inkey "$T/throwaway.key.pem" -in "$T/old.tbs" -out "$T/old.sig"
+    expect_refused "signature over signer-less bytes is not attached" "signature not attached" "$np" sign --package "$O" --sig "$T/old.sig" --pubkey "$pk" "${dirty[@]}"
+    expect_ok "tbs --pubkey" "$np" tbs --package "$O" --pubkey "$pk"
+    [ "$(stat -c %s "$O/slot/MANIFEST.tbs")" = 448 ] && pass "tbs is 448 bytes" || fail "tbs size"
+    openssl pkeyutl -sign -rawin -inkey "$T/throwaway.key.pem" -in "$O/slot/MANIFEST.tbs" -out "$T/owner.sig"
+    cp -r "$O" "$T/Od"; sed -i "s/^tree_clean .*/tree_clean no/" "$T/Od/PACKAGE.txt"; remake_all "$T/Od"
+    expect_refused "sign refuses a dirty-tree package without --allow-dirty" "dirty tree" "$np" sign --package "$T/Od" --sig "$T/owner.sig" --pubkey "$pk"
+    expect_ok "sign attaches the OpenSSL signature" "$np" sign --package "$O" --sig "$T/owner.sig" --pubkey "$pk" "${dirty[@]}"
+    expect_ok "verify PASS under the throwaway owner keys file" "$np" verify --package "$O" --keys "$T/throwaway-keys.txt" "${dirty[@]}"
+    sid=$(openssl pkey -in "$T/throwaway.key.pem" -pubout -outform DER | tail -c 32 | openssl dgst -sha256 -r | cut -c1-64)
+    "$NATIVE_PACKAGE_TOOL_OUT/host/ck_slot_tool" show "$O/slot/MANIFEST.signed.bin" | /usr/bin/grep -q "signer_id=$sid" \
+        && pass "signer_id = SHA-256 of the raw 32-byte public key (OpenSSL agrees)" || fail "signer_id derivation"
+    expect_refused "verify refuses the OpenSSL-signed package under the TEST key" "no trusted key" "$np" verify --package "$O" --test-key "${dirty[@]}"
+else
+    fail "openssl genpkey ed25519 unavailable: offline signing round trip not run"
+fi
+
 echo "NATIVE_PACKAGE_TEST: $([ "$fails" = 0 ] && echo PASS || echo FAIL) ($checks checks, $fails failures)"
 [ "$fails" = 0 ]