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#508 (code only)

closed derived 11148c268a219448 #508

Imported from GitHub aien-dev/aienux#508 (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 cf6eb73c1133fa0c49509c7727c680f38a9f68be · Head b284ca0fb4c1046103c009a4d489b96d59afda5c

Fetch it

A git bundle of the pull request's head, 11378 bytes.

curl -fsSL https://interplane.io/drakestapleton/aienux/patches/11148c268a219448.bundle -o 11148c268a219448.bundle
git fetch 11148c268a219448.bundle refs/pull/508/head

Raw bundle · 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
508
b284ca0fb4c1046103c009a4d489b96d59afda5c
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":508,"url":"https://github.com/aien-dev/aienux/pull/508","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:39Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/.crumb b/.crumb
index 9a36c8c4..d4be7f9e 100644
--- a/.crumb
+++ b/.crumb
@@ -33,14 +33,14 @@
           "purpose": "Directory docs. Purpose not yet described by a human."
         },
         {
-          "digest": "d00d952f7f65b7021eadacc75d8a89f2fb7c217364191a47d775e0baa4f77bc4",
-          "last_commit": "b079990e",
+          "digest": "5c56b21079e91be22ececbf55290e1a8a90a376ff5cb0ee70efda1de847735d1",
+          "last_commit": "5d00feb1",
           "name": "native",
           "purpose": "Directory native. Purpose not yet described by a human."
         },
         {
           "digest": "e8aeac2d60e55081ae3c39f89c4946cd8f9f6994f97883281f41fcf1a3555c68",
-          "last_commit": "b079990e",
+          "last_commit": "cf6eb73c",
           "name": "scripts",
           "purpose": "Directory scripts. Purpose not yet described by a human."
         },
@@ -51,15 +51,15 @@
           "purpose": "First-party host artifact preparation tools"
         }
       ],
-      "children_root": "sha256:baf3ce29fd4257473f8e28326c4fb1142e98ed64f4eb94f5d29deff43c017124",
-      "compiled_at": "2026-11-06T01:37:45Z",
+      "children_root": "sha256:ee640f797ffcd33ffb37194b1c03f2c276dd5f99fbcb485fe81f72c37aac3944",
+      "compiled_at": "2026-11-06T01:51:50Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:d5891c77ccb010b261c2fe7f7019a3faa5a0afd4b44f381aa2544089f0337c8b",
+      "digest": "sha256:a87d80d50189f23523a04eb98d475221073857f1926952db92f4009aff18debf",
       "evidence_files": 274,
       "evidence_root": "sha256:af014a4ed8f6fe759fc5809807fb47578d3410811b522d9f65d749382b029802",
-      "files": 3777,
-      "generated_at_commit": "b079990e34b1ac0ce69894b065d83e23bae56676",
-      "source_tree": "sha256:385f607a3faaffd0b6da010ec148bc173ac3e33bc8acdb7a7f38d3b8783e7c76"
+      "files": 3778,
+      "generated_at_commit": "5d00feb1747b3084298cd2d0fc5c13d9017cda02",
+      "source_tree": "sha256:8cc7db679222a427eea5269284e147ac06589f93e1aace020e38334324965d93"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/.crumb b/native/.crumb
index cbfccbaa..eb6772ed 100644
--- a/native/.crumb
+++ b/native/.crumb
@@ -80,7 +80,7 @@
         },
         {
           "digest": "b4bbedb50095112fdc0e833f441e9da1423ea3f003c086dd9a478d598530ae68",
-          "last_commit": "b079990e",
+          "last_commit": "cf6eb73c",
           "name": "kernel",
           "purpose": "Directory native/kernel. Purpose not yet described by a human."
         },
@@ -109,21 +109,21 @@
           "purpose": "Directory native/sig. Purpose not yet described by a human."
         },
         {
-          "digest": "e125172a18437b662edf303f4b9615bb791f5e7d2ed94192033823185e7d40e1",
-          "last_commit": "2c9c8b50",
+          "digest": "10d2ff92f485da6012d167453ac7bdb7b3023ec7e2be5536599f5c26948e5563",
+          "last_commit": "77dd40e0",
           "name": "store",
           "purpose": "Directory native/store. Purpose not yet described by a human."
         }
       ],
-      "children_root": "sha256:b0ef7e80795c3cc305298c8ee420e2838e5939075185a91f78875871a715645f",
-      "compiled_at": "2026-11-06T01:37:45Z",
+      "children_root": "sha256:5a2d7883112d301d9f5f1a097e4534d70b9aae096740ba53e99e5ff3d0ad5f62",
+      "compiled_at": "2026-11-06T01:51:50Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:d00d952f7f65b7021eadacc75d8a89f2fb7c217364191a47d775e0baa4f77bc4",
+      "digest": "sha256:5c56b21079e91be22ececbf55290e1a8a90a376ff5cb0ee70efda1de847735d1",
       "evidence_files": 24,
       "evidence_root": "sha256:ecc7ccf2e924c221a5bac1d91e23b13d8f3c8d78c2a893a882ed7ca5e88d855d",
-      "files": 777,
-      "generated_at_commit": "b079990e34b1ac0ce69894b065d83e23bae56676",
-      "source_tree": "sha256:90c4769a3bb9c9eb02121fb3e89957fd99f1aaa855bec80833f75c542563125f"
+      "files": 778,
+      "generated_at_commit": "5d00feb1747b3084298cd2d0fc5c13d9017cda02",
+      "source_tree": "sha256:50b098738167af2e5b8ff4664f8b100d4ad5e1f6a008f2ed81ea2a8c42137e38"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/store/.crumb b/native/store/.crumb
index b62094a5..71c59bea 100644
--- a/native/store/.crumb
+++ b/native/store/.crumb
@@ -13,21 +13,21 @@
     "generated": {
       "children": [
         {
-          "digest": "c3d8412c53594ae21ff6f0bc5811c22c0c6ecf8928ab65667c9066f07cfc01b1",
+          "digest": "e1c6aa9af305c17cb1735a0a11ffea3648365d293a1e43035903f325602bbbb0",
           "last_commit": "f45d00ad",
           "name": "tests",
           "purpose": "Directory native/store/tests. Purpose not yet described by a human."
         }
       ],
-      "children_root": "sha256:7118820a7ed52b1dbf250f7973cb94f80ec953a2730bca80dffb99b64ac9546f",
-      "compiled_at": "2026-10-30T11:55:01Z",
+      "children_root": "sha256:4751b84a301612623b8b7d08d886dec3145a7c955a6e4c8a5b6e1a40f3a7d8f5",
+      "compiled_at": "2026-11-05T02:24:49Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:e125172a18437b662edf303f4b9615bb791f5e7d2ed94192033823185e7d40e1",
+      "digest": "sha256:10d2ff92f485da6012d167453ac7bdb7b3023ec7e2be5536599f5c26948e5563",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "files": 22,
-      "generated_at_commit": "fd4ac5b5bdf13645e310e506c997ca18c39b7fe2",
-      "source_tree": "sha256:966b76d7e3abb3626c693d38e872654f8be8fb27345becb5c04f6caf55e6b426"
+      "files": 23,
+      "generated_at_commit": "3be8290b317427791b12ae1416f055e5e696712d",
+      "source_tree": "sha256:b7e0d0539907740e182661e72e24fe10aa6d1bfae92f1868bd0f1d552458bdc2"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/store/Makefile b/native/store/Makefile
index 5a35a6ff..8e83d631 100644
--- a/native/store/Makefile
+++ b/native/store/Makefile
@@ -126,7 +126,10 @@ else
 endif
 
 # Mutants: remove each GUARD-tagged rule in turn. The tests must fail for
-# every mutant, or that rule is not tested.
+# every mutant, or that rule is not tested. A mutant counts as killed only
+# when a test exits 1 with its own FAIL verdict line (or, for store mutants,
+# a sanitizer report of the invalid access); a crash, a signal, any other exit
+# status, a build failure or a gate timeout is never counted as a detection.
 GUARDS = parity-a parity-b b-needs-a adjacent first-remnant a-alone-seq1
 
 mutants: torn-slot-mutants store-mutants
@@ -145,9 +148,12 @@ torn-slot-mutants: $(OUT)/t_torn_slot_test.o $(OUT)/sha256.o | $(OUT)
 	    $(CC) $(CFLAGS) -Wno-error -I. -c -o $(OUT)/mut_$$g.o $(OUT)/mut_$$g.c \
 	      && $(CC) $(CFLAGS) -Wno-error -o $(OUT)/mut_$$g $(OUT)/t_torn_slot_test.o $(OUT)/mut_$$g.o $(OUT)/sha256.o \
 	      || { echo "mutant $$g: does not compile" > $(OUT)/mut_$$g.msg; echo 1 > $(OUT)/mut_$$g.fail; exit 0; }; \
-	    if ./$(OUT)/mut_$$g --rules-only > $(OUT)/mut_$$g.log 2>&1; then \
+	    ./$(OUT)/mut_$$g --rules-only > $(OUT)/mut_$$g.log 2>&1; rc=$$?; \
+	    if [ $$rc -eq 0 ]; then \
 	      echo "mutant $$g: SURVIVED (FAIL)" > $(OUT)/mut_$$g.msg; echo 1 > $(OUT)/mut_$$g.fail; \
-	    else echo "mutant $$g: killed" > $(OUT)/mut_$$g.msg; : > $(OUT)/mut_$$g.killed; fi \
+	    elif [ $$rc -eq 1 ] && grep -q '^TORN_SLOT_RULES: FAIL' $(OUT)/mut_$$g.log; then \
+	      echo "mutant $$g: killed" > $(OUT)/mut_$$g.msg; : > $(OUT)/mut_$$g.killed; \
+	    else echo "mutant $$g: exit $$rc without a FAIL verdict, not a detection (FAIL)" > $(OUT)/mut_$$g.msg; echo 1 > $(OUT)/mut_$$g.fail; fi \
 	  ) & \
 	done; \
 	wait; \
@@ -182,9 +188,17 @@ store-mutants: $(STORE_OBJS) $(TEST_OBJS) $(DEP_OBJS) $(OUT)/torn_slot.o $(HOST_
 	    dead=0; by=""; \
 	    for t in $$order; do \
 	      $(CC) $(CFLAGS) $(MUTANT_SANFLAGS) -o $$d/$$t $(OUT)/t_$$t.o $$d/m.o $$objs $(OUT)/torn_slot.o $(DEP_OBJS) $(HOST_OBJS) || { dead=2; break; }; \
-	      if ! ./$$d/$$t $$d > $$d/$$g.log 2>&1; then dead=1; by="$$t"; break; fi; \
+	      ./$$d/$$t $$d > $$d/$$g.log 2>&1; rc=$$?; \
+	      if [ $$rc -ne 0 ]; then \
+	        if [ $$rc -eq 1 ] && grep -q '^STORE_[A-Z0-9_]*: FAIL$$' $$d/$$g.log; then dead=1; by="$$t"; \
+	        elif [ $$rc -eq 1 ] && grep -q 'runtime error:' $$d/$$g.log; then dead=1; by="$$t (sanitizer)"; \
+	        else dead=3; by="$$t exit $$rc"; fi; \
+	        break; \
+	      fi; \
 	    done; \
 	    if [ $$dead -eq 1 ]; then echo "mutant $$g ($$f): killed by $$by" > $$d/msg; : > $$d/killed; \
+	    elif [ $$dead -eq 3 ]; then echo "mutant $$g ($$f): $$by without a FAIL verdict, not a detection (FAIL)" > $$d/msg; echo 1 > $$d/fail; \
+	    elif [ $$dead -eq 2 ]; then echo "mutant $$g ($$f): does not link (FAIL)" > $$d/msg; echo 1 > $$d/fail; \
 	    else echo "mutant $$g ($$f): SURVIVED (FAIL)" > $$d/msg; echo 1 > $$d/fail; fi \
 	  ) & \
 	done; \
diff --git a/native/store/README.md b/native/store/README.md
index 8d7abf26..1058a37b 100644
--- a/native/store/README.md
+++ b/native/store/README.md
@@ -110,6 +110,12 @@ envelope whose id or nonce prefix does not follow the version-2 rule.
 `AIENOS_STORE_MUTANTS`), `make freestanding` (`nm -u` closes over the sibling
 native objects), `make lib-checks`. All runs are host emulation over files.
 
+[`tests/SEALED-COVERAGE.md`](tests/SEALED-COVERAGE.md) maps the sealed store's
+rollback and nonce-safety properties (confidentiality under nonce misuse,
+authentication, replay, crash consistency, whole-image freshness) to these
+tests and mutants, including the independent envelope-id oracle and the
+undetected whole-image rollback (#32).
+
 Every `/* GUARD:name */` line in the four store sources is a mutant: `make
 mutants` deletes it and requires some store test to fail. Three Rust-parity
 checks are deliberately untagged because no input can reach them alone:
diff --git a/native/store/store_sealed.c b/native/store/store_sealed.c
index bea37304..1a455ac8 100644
--- a/native/store/store_sealed.c
+++ b/native/store/store_sealed.c
@@ -472,22 +472,26 @@ static int envid_derive(const ss_store *s, uint64_t gen, uint32_t index, uint16_
                         uint16_t version, const uint8_t *pt, size_t len, uint8_t out[32])
 {
     uint8_t k[32], ph[32], m[16 + 8 + 4 + 2 + 2 + 8 + 1 + 8 + 32];
+    /* Zeroed first, so a mutant that drops one bound field below (the envid-*
+     * guards) derives a fixed, wrong value that the tests' independent oracle
+     * sees, instead of whatever the stack held. */
+    memset(m, 0, sizeof m);
     if (m5_hkdf_expand(s->keys.k_domain, (const uint8_t *)ENVID_KEY_INFO, sizeof(ENVID_KEY_INFO), k,
                        sizeof k) != M5_OK)
         return SS_E_CRYPTO;
     sha256_hash(pt, len, ph);
-    memcpy(m, s->uuid, 16);
-    put64(m + 16, gen);
-    put32(m + 24, index);
-    put16(m + 28, kind);
-    put16(m + 30, version);
-    put64(m + 32, s->keys.key_generation);
-    m[40] = s->keys.identity_class;
-    put64(m + 41, (uint64_t)len);
-    memcpy(m + 49, ph, 32);
+    memcpy(m, s->uuid, 16); /* GUARD:envid-store */
+    put64(m + 16, gen); /* GUARD:envid-generation */
+    put32(m + 24, index); /* GUARD:envid-index */
+    put16(m + 28, kind); /* GUARD:envid-kind */
+    put16(m + 30, version); /* GUARD:envid-version */
+    put64(m + 32, s->keys.key_generation); /* GUARD:envid-key-generation */
+    m[40] = s->keys.identity_class; /* GUARD:envid-class */
+    put64(m + 41, (uint64_t)len); /* GUARD:envid-length */
+    memcpy(m + 49, ph, 32); /* GUARD:envid-plaintext */
     aienos_hmac_sha256_ctx c;
     aienos_hmac_sha256_init(&c, k);
-    aienos_hmac_sha256_update(&c, (const uint8_t *)ENVID_DOMAIN, sizeof(ENVID_DOMAIN));
+    aienos_hmac_sha256_update(&c, (const uint8_t *)ENVID_DOMAIN, sizeof(ENVID_DOMAIN)); /* GUARD:envid-domain */
     aienos_hmac_sha256_update(&c, m, sizeof m);
     aienos_hmac_sha256_final(&c, out);
     aienos_wipe(k, sizeof k);
diff --git a/native/store/tests/.crumb b/native/store/tests/.crumb
index d70bc97f..85dfe39c 100644
--- a/native/store/tests/.crumb
+++ b/native/store/tests/.crumb
@@ -7,14 +7,14 @@
     "generated": {
       "children": [],
       "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "compiled_at": "2026-10-24T04:15:32Z",
+      "compiled_at": "2026-11-05T02:24:49Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:c3d8412c53594ae21ff6f0bc5811c22c0c6ecf8928ab65667c9066f07cfc01b1",
+      "digest": "sha256:e1c6aa9af305c17cb1735a0a11ffea3648365d293a1e43035903f325602bbbb0",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
-      "files": 10,
-      "generated_at_commit": "621c9e6fe430ee689836bee3ee2689d7d32e0f7d",
-      "source_tree": "sha256:8bed0d681b0d7d149282e5f937c25db20dcef9b5ded96caa434d185fc01aac4a"
+      "files": 11,
+      "generated_at_commit": "3be8290b317427791b12ae1416f055e5e696712d",
+      "source_tree": "sha256:1c9c851e437eb8a4b4a0fed72e0b2ff296abdfa3bda7f415f4239b8c58297690"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/native/store/tests/SEALED-COVERAGE.md b/native/store/tests/SEALED-COVERAGE.md
new file mode 100644
index 00000000..2e938e96
--- /dev/null
+++ b/native/store/tests/SEALED-COVERAGE.md
@@ -0,0 +1,40 @@
+# Sealed store: coverage matrix (rollback and nonce safety)
+
+This file covers `store_sealed.c` and the tests in this directory. Every run is a host emulation over image files: there is no real disk, no live volume, no key rotation and no GPU. Each row names the test that asserts the property, and the `GUARD:` mutants that `make mutants` deletes, each of which some test must then catch.
+
+A mutant counts as killed only when a test exits 1 and prints its own `STORE_*: FAIL` or `TORN_SLOT_RULES: FAIL` verdict. For store mutants, a UBSan report of the invalid access also counts. A crash, a signal, any other exit status, a build or link failure, or a gate timeout never counts. See the comment on the `mutants` rule in the `Makefile`.
+
+The samples below are finite and collision-free. They are regression checks, not proof that values are unique without condition. Uniqueness rests on HMAC-SHA256 and SHA-256 behaving as PRFs and collision-resistant hashes.
+
+## Key scope, objects and chunks
+
+| Item | Mapping |
+|---|---|
+| Key scope | `k_domain` of one store (`ss_keys`). The rig derives it from seed `0x11` (class production, `key_generation` 1). `K_OTHER` (seed `0x22`) is an unrelated scope. |
+| Envelope id and nonce prefix | `HMAC(HKDF-Expand(k_domain, "AIENOS-SEALED-ENVID-KEY-V2\0", 32), "AIENOS-SEALED-ENVID-V2\0" ‖ uuid ‖ gen u64 ‖ index u32 ‖ kind u16 ‖ version u16 ‖ key_generation u64 ‖ class u8 ‖ len u64 ‖ SHA-256(pt))`. Bytes 0..15 are the envelope id, an input to the per-object key. Bytes 16..23 are the nonce prefix. Everything is little-endian. |
+| Chunk nonce | nonce prefix ‖ chunk index u32 (12 bytes), under the per-object AES-GCM-SIV key (`native/m5`), with `SS_CHUNK` = 4096 B. |
+| Synthetic ids | store `RIG_UUID`. Gen 2: index 0 is kind 40 v1, 700 B (1 chunk); index 1 is kind 41 v2, 9000 B (3 chunks). Gen 3: index 0 is kind 42 v1, 600 B. `test_envid_oracle` prints this line. |
+
+Pairs only need to be new within one key scope, and the tests ask nothing more. They never require nonce bytes to be unique across unrelated keys. `test_envid_oracle` only checks that another `k_domain` gives a different pair.
+
+## Matrix
+
+| Property | What is asserted | Test (`store_sealed_test.c` unless named) | Mutants |
+|---|---|---|---|
+| **Confidentiality under nonce misuse** (rollback, then rewrite) | After a whole-disk rollback to gen 2, a rewrite of gen 3 with different bytes gives a new envelope id and nonce prefix, 24 rounds in a row. A one-bit change gives a new pair, and so does a kind change. The identical object at the identical place gives the identical pair: deterministic, and it shows nothing the old image did not. | `test_nonce` | `envid-plaintext`, `envid-kind` |
+| | Every bound field, checked against an **independent oracle**: HMAC-SHA256 (RFC 2104) and HKDF-Expand (RFC 5869) written in the test over SHA-256 alone, pinned by FIPS 180 "abc", RFC 4231 cases 1–2 and RFC 5869 case 1. The stored pairs of gen 2 objects 0 and 1, and of every gen 3 rewrite, must equal the oracle. | `test_envid_oracle`, `test_nonce` | `envid-store`, `envid-generation`, `envid-index`, `envid-kind`, `envid-version`, `envid-key-generation`, `envid-class`, `envid-length`, `envid-plaintext`, `envid-domain` |
+| | The old predictable V1 id (SHA-256 of uuid ‖ gen ‖ 0) is not produced. A V1-sealed envelope with valid digests mounts but is refused on read, and the output buffer is wiped. | `test_nonce` | The V1 derivation cannot be expressed as a deleted line. The oracle refuses any change to the derivation; the PR that added this file records the replacement mutant run. |
+| | AES-GCM-SIV against its published vectors, plus the chunk AAD and nonce layout. | `native/crypto/tests/crypto_test.c` (RFC 8452), `native/m5/tests/m5_test.c` | (crypto and m5 suites) |
+| **Authentication** | Flipped envelope bytes, a forged commit, wrong store or class, a bad transaction MAC or magic, an unclaimed or twice-claimed envelope, a forged keyslot chain: each is refused with its typed error. | `test_forgery`, `test_identity`, `test_keyslot` | `tx-mac`, `tx-class`, `tx-store`, `commit-*`, `claim-*`, `envelope-digest`, `unclaimed-envelope`, `keyslot-*` |
+| **Replay** | A version-1 transaction record is refused (`SS_E_FORMAT_VERSION`). So are a replayed or duplicate record, a generation gap or skip, a counter mismatch, a broken chain, a forked anchor at the same counter, an anchor naming another store, and a duplicate anchor sequence. | `test_nonce`, `test_forgery`, `test_rollback` | `tx-version-1`, `tx-counter`, `tx-gen-range`, `tx-duplicate`, `tx-gap`, `tx-chain`, `anchor-record-class`, `anchor-record-store`, `anchor-region` |
+| **Crash consistency** | Power cut at every block boundary of one sealed transaction (512 B and 4 KiB): the reopened image shows exactly the old state or exactly the new one. A crash between the Store commit and the anchor leaves the anchor one behind (prepared advance), twice, and the next transaction catches up. Torn anchor slots are covered by the torn_slot rules. | `store_powercut_test.c` `sealed_cuts`, `test_anchor_crash`, `torn_slot_test.c` | `anchor-catch-up`, the torn_slot `GUARDS` |
+| **Store-only and anchor-only rollback** | Store rolled back one or two generations under the current anchor: `SS_E_ROLLBACK`. Anchor one behind: accepted as the crash window (`SS_RB_PREPARED_ADVANCE`). Anchor two behind: `SS_E_INCONSISTENT`. Anchor missing after genesis: `SS_E_ROLLBACK`. | `test_rollback`, `test_nonce` | `anchor-*` |
+| **Whole-image freshness** | **Not detected (documented limit).** Rolling back the Store and the anchor together mounts at the stale generation and reports a valid resume. The test asserts exactly that, so a successful mount is never counted as freshness. | `test_rollback` ("LIMITATION") | none |
+
+## Whole-image freshness needs an external trust anchor
+
+The disk alone cannot tell a whole-image rollback from the real state, because both regions are self-consistent. Freshness needs a monotonic counter that the attacker cannot roll back with the disk, such as a TPM NV counter (TRUST-1). The store's anchor generation is compared against that counter at open. That work belongs to [aienux#32](https://github.com/aien-dev/aienux/issues/32). This file adds no TPM code and no on-disk format change.
+
+## Reproduce
+
+From a checkout at the pinned revision, run `make -C native/store test mutants`. It ends with `AIENOS_STORE_NATIVE: PASS`, `TORN_SLOT_MUTANTS: PASS` and `AIENOS_STORE_MUTANTS: PASS`. The shared gate `tests/gates/aienos-store-native.gate` (`tests/gates/run.sh store-native`) runs the same command.
diff --git a/native/store/tests/store_sealed_test.c b/native/store/tests/store_sealed_test.c
index 8a614bec..4c33bea1 100644
--- a/native/store/tests/store_sealed_test.c
+++ b/native/store/tests/store_sealed_test.c
@@ -212,9 +212,19 @@ static void test_rollback(void)
     memset(t, 0, (size_t)RIG_ANCHOR_UNITS * 4096u);
     CHECK(file_save(g_path, t, RIG_BYTES) == 0, "write");
     SCHECK_EQ(open_rc(&K), SS_E_ROLLBACK, "missing anchor at gen 4");
-    /* whole-disk rollback (both regions) is NOT detected: documented limit */
+    /* LIMITATION, whole-image freshness: rolling back both regions together is
+     * NOT detected. It needs a monotonic counter outside the disk (TPM NV,
+     * TRUST-1, aienux#32). The mount succeeds at the stale generation 2 and
+     * reports a valid resume, so a successful mount is never proof of freshness. */
     CHECK(file_save(g_path, img_a, RIG_BYTES) == 0, "write");
-    SCHECK_EQ(open_rc(&K), 0, "whole-disk rollback mounts (needs TPM NV, TRUST-1)");
+    {
+        rig r;
+        ss_store s;
+        SCHECK_EQ(sopen(&r, &s, &K), 0, "whole-disk rollback mounts (LIMITATION: needs TPM NV, #32)");
+        SCHECK_EQ(ss_generation(&s), 2, "whole-disk rollback: stale generation 2 is served, not 4");
+        SCHECK_EQ(s.rb, SS_RB_VALID_RESUME, "whole-disk rollback reports a valid resume (undetected)");
+        rig_close(&r);
+    }
 
     /* forked anchor: same counter, different digest, valid MAC */
     CHECK(file_save(g_path, img_c, RIG_BYTES) == 0, "write");
@@ -955,6 +965,133 @@ static void last_pair(uint8_t out[24])
     memcpy(out + 16, g_ws.env[0] + 44, 8);
 }
 
+/* ---- independent envelope id oracle (#445) ----
+ * HMAC-SHA256 (RFC 2104) and HKDF-Expand (RFC 5869) written here over the
+ * argus SHA-256 alone, pinned by published vectors, so the expected pair is
+ * computed without envid_derive, aienos_hmac_* or m5_hkdf_expand. The input
+ * layout is the V2 rule as documented above envid_derive (store_sealed.c):
+ * uuid 16 || generation u64 || index u32 || kind u16 || version u16 ||
+ * key_generation u64 || identity_class u8 || plaintext_len u64 ||
+ * SHA-256(plaintext), little-endian, after the domain string and its NUL.
+ * The envelope id (object key input) is bytes 0..15 of the HMAC, the nonce
+ * prefix bytes 16..23; both live in one key scope, the store's k_domain. */
+static void or_hmac(const uint8_t *key, size_t klen, const uint8_t *a, size_t alen, const uint8_t *b,
+                    size_t blen, uint8_t out[32])
+{
+    uint8_t k0[64], pad[64], ih[32];
+    memset(k0, 0, sizeof k0);
+    if (klen > 64) sha256_hash(key, klen, k0);
+    else memcpy(k0, key, klen);
+    sha256_ctx c;
+    for (int i = 0; i < 64; i++) pad[i] = k0[i] ^ 0x36;
+    sha256_init(&c);
+    sha256_update(&c, pad, 64);
+    sha256_update(&c, a, alen);
+    if (blen) sha256_update(&c, b, blen);
+    sha256_final(&c, ih);
+    for (int i = 0; i < 64; i++) pad[i] = k0[i] ^ 0x5c;
+    sha256_init(&c);
+    sha256_update(&c, pad, 64);
+    sha256_update(&c, ih, 32);
+    sha256_final(&c, out);
+}
+
+/* HKDF-Expand, L <= 64, info <= 64 bytes */
+static void or_hkdf_expand(const uint8_t prk[32], const uint8_t *info, size_t ilen, uint8_t *out, size_t L)
+{
+    uint8_t t[32], msg[32 + 64 + 1];
+    size_t got = 0, tl = 0;
+    for (uint8_t i = 1; got < L; i++) {
+        memcpy(msg, t, tl);
+        memcpy(msg + tl, info, ilen);
+        msg[tl + ilen] = i;
+        or_hmac(prk, 32, msg, tl + ilen + 1, NULL, 0, t);
+        tl = 32;
+        size_t n = L - got < 32 ? L - got : 32;
+        memcpy(out + got, t, n);
+        got += n;
+    }
+}
+
+static int hex_eq(const uint8_t *got, const char *hex, size_t n)
+{
+    for (size_t i = 0; i < n; i++) {
+        unsigned v = 0;
+        if (sscanf(hex + 2 * i, "%2x", &v) != 1 || got[i] != (uint8_t)v) return 0;
+    }
+    return 1;
+}
+
+static void le(uint8_t *p, uint64_t v, int n)
+{
+    for (int i = 0; i < n; i++) p[i] = (uint8_t)(v >> (8 * i));
+}
+
+/* expected (envelope_id || nonce_prefix) of the object at (gen, index) */
+static void oracle_pair(const ss_keys *k, uint64_t gen, uint32_t index, uint16_t kind, uint16_t version,
+                        const uint8_t *pt, size_t len, uint8_t out[24])
+{
+    static const char info[] = "AIENOS-SEALED-ENVID-KEY-V2", dom[] = "AIENOS-SEALED-ENVID-V2";
+    uint8_t key[32], m[16 + 8 + 4 + 2 + 2 + 8 + 1 + 8 + 32], h[32];
+    or_hkdf_expand(k->k_domain, (const uint8_t *)info, sizeof info, key, sizeof key);
+    memcpy(m, RIG_UUID, 16);
+    le(m + 16, gen, 8);
+    le(m + 24, index, 4);
+    le(m + 28, kind, 2);
+    le(m + 30, version, 2);
+    le(m + 32, k->key_generation, 8);
+    m[40] = k->identity_class;
+    le(m + 41, len, 8);
+    sha256_hash(pt, len, m + 49);
+    or_hmac(key, sizeof key, (const uint8_t *)dom, sizeof dom, m, sizeof m, h);
+    memcpy(out, h, 24);
+}
+
+static void test_envid_oracle(void)
+{
+    /* the oracle's primitives against published vectors */
+    uint8_t h[42];
+    sha256_hash((const uint8_t *)"abc", 3, h);
+    CHECK(hex_eq(h, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", 32), "SHA-256 FIPS 180 'abc'");
+    uint8_t k0b[20];
+    memset(k0b, 0x0b, sizeof k0b);
+    or_hmac(k0b, sizeof k0b, (const uint8_t *)"Hi There", 8, NULL, 0, h);
+    CHECK(hex_eq(h, "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7", 32), "HMAC RFC 4231 case 1");
+    or_hmac((const uint8_t *)"Jefe", 4, (const uint8_t *)"what do ya want ", 16, (const uint8_t *)"for nothing?", 12, h);
+    CHECK(hex_eq(h, "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843", 32), "HMAC RFC 4231 case 2");
+    static const uint8_t prk[32] = {0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xdf, 0x0d, 0xdc, 0x3f,
+                                    0x0d, 0xc4, 0x7b, 0xba, 0x63, 0x90, 0xb6, 0xc7, 0x3b, 0xb5, 0x0f,
+                                    0x9c, 0x31, 0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2, 0xb3, 0xe5};
+    static const uint8_t info[10] = {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9};
+    or_hkdf_expand(prk, info, sizeof info, h, 42);
+    CHECK(hex_eq(h, "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865", 42),
+          "HKDF-Expand RFC 5869 case 1");
+
+    /* gen 2 = {P1 kind 40 v1 at index 0, P2 kind 41 v2 at index 1}: every
+     * bound field is nonzero in object 1, so dropping any one changes it */
+    uint8_t ids[2][32], want[24], got[24];
+    make_gen2(ids);
+    oracle_pair(&K, 2, 0, 40, 1, P1, sizeof P1, want);
+    memcpy(got, g_ws.env[0] + 28, 16);
+    memcpy(got + 16, g_ws.env[0] + 44, 8);
+    CHECK(memcmp(got, want, 24) == 0, "gen 2 object 0 pair equals the independent oracle");
+    oracle_pair(&K, 2, 1, 41, 2, P2, sizeof P2, want);
+    memcpy(got, g_ws.env[1] + 28, 16);
+    memcpy(got + 16, g_ws.env[1] + 44, 8);
+    CHECK(memcmp(got, want, 24) == 0, "gen 2 object 1 pair equals the independent oracle");
+    if (g_bs == 512)
+        printf("envid oracle: key scope k_domain (rig seed 0x11, class %u, key_generation %llu), store RIG_UUID;"
+               " gen 2 index 0 kind 40 v1 %zu B = %u chunk(s), index 1 kind 41 v2 %zu B = %u chunk(s) of %u B\n",
+               (unsigned)K.identity_class, (unsigned long long)K.key_generation, sizeof P1,
+               (unsigned)((sizeof P1 + SS_CHUNK - 1) / SS_CHUNK), sizeof P2,
+               (unsigned)((sizeof P2 + SS_CHUNK - 1) / SS_CHUNK), (unsigned)SS_CHUNK);
+    /* the same object under another key scope is a different pair; pairs are
+     * only required to be new within one scope, never across unrelated keys */
+    uint8_t other[24];
+    oracle_pair(&K_OTHER, 2, 1, 41, 2, P2, sizeof P2, other);
+    CHECK(memcmp(other, want, 24) != 0, "oracle: another k_domain gives another pair");
+}
+
 static void test_nonce(void)
 {
     uint8_t ids[2][32];
@@ -970,6 +1107,11 @@ static void test_nonce(void)
         uint8_t id[32];
         advance(&K, 42, q, 600, id, 0);
         last_pair(pairs[r]);
+        {
+            uint8_t want[24];
+            oracle_pair(&K, 3, 0, 42, 1, q, 600, want);
+            CHECK(memcmp(pairs[r], want, 24) == 0, "rollback rewrite %d: pair equals the independent oracle", r);
+        }
         rig rr;
         ss_store s;
         SCHECK_EQ(sopen(&rr, &s, &K), 0, "rewritten gen 3 mounts");
@@ -1109,6 +1251,7 @@ int main(int argc, char **argv)
         test_keyslot();
         test_anchor_crash();
         test_nonce();
+        test_envid_oracle();
         test_keyslot_limits();
         printf("sealed store, %u-byte blocks: %s\n", g_bs, g_failed == before ? "ok" : "FAILED");
         unlink(g_path);