## Summary PoC-A proved that dynamically loaded ELF plugins are workable on ESP32-S3: plugins ship as signed MPB packages, are parsed by a strict single-type parser shared between host and target, and execute from PSRAM+IRAM within a measured admission budget. A 1000-cycle load/unload soak passed 18/18 trend gates with stable heaps, the capacity ladder settled at 8 coexisting plugin instances with a 3356B per-instance budget, and the fail-closed corpus executed zero attacker-controlled bytes across 14 rejection classes. Scheduler semantics (strand FIFO ordering, completion-cancel CAS, quiesce-as-noop ABI) were validated on both host (TSan suite) and target. **Gate-A verdict: PASS** — ADR-0002 moves to **Accepted** with the capacity value 8 and global-sum admission rule as PoC-derived proposals. ## Changes by area Grouped from `git log main..HEAD --oneline` (18 commits): - **Vendored loader + patches**: `4bb53f2` vendor elf_loader 1.3.3 + harness scaffold; `2f67b4f` plugin_iram loader patch with budget consistency (p1-p5 patch series in `PATCHES.md`). - **MPB toolchain**: `4793cc2` deterministic MPB manifest builder with test signing; `408df44` strict single-type MPB parser shared host/target; `796f9d2` host MPB corpus + policy CI lane. - **Plugin pipeline + probes**: `21d2842` plugin pipeline and first PSRAM execution on target; `cab9664` relocation/import allowlist matrix with probes; `c5d6c6c` C++ feature rejection matrix. - **Harness commands**: `e0e7159` generation coexistence with measured admission budget; `2a37556` thousand-cycle lifecycle soak with heap trend gate; `093a72b` on-target scheduler semantics validation (+ `eea3876` clang-format-18 sweep); `a302151` capacity ladder with signed budget; `f34dc72` fail-closed corpus with execution sentinel. - **Host prototypes**: `6198bca` strand FIFO prototype with TSan suite; `1c3ad59` completion-cancel CAS and cleanup semantics. - **Evidence + ADR/docs**: `887d0f7` Gate-A manifest and report; `1c29e8a` ADR-0002 outcome + frozen PoC values. ## QA evidence - `poc/evidence/poc-a-20260901/manifest.json` — 67-artifact hash index, every sha256 recomputed at assembly. - `poc/evidence/poc-a-20260901/GATE-A-REPORT.md` — full nine-item development-plan §4 mapping; TEST-003 10/10 clauses. - 14 verbatim per-task transcripts (`task-1` … `task-15-*.log`) + fresh build artifacts (`build/frame_poc_a.map`, size components). - Frozen in-repo references: `ALLOWLIST.md`, `REJECT-MATRIX.md`, `ADMISSION-BUDGET.md`, `soak_samples_1000.csv`, fc corpus (33 committed `.mpb` containers). - F1-F4 final-wave verdicts: **APPROVE**. - Key numbers: soak **18/18** trend gates over 1000 cycles; capacity **8/8** instances, **3356B** per-instance; fc corpus **14 rejection classes, zero attacker bytes executed**; **4 upstream loader defects found and patched** (p1-p5). ## Requirement IDs (GOV-006) ADR-0002; TEST-002, TEST-003; PLUG-001, PLUG-004, PLUG-008, PLUG-009; MEM-001, MEM-003, MEM-007, MEM-008; LIFE-001, LIFE-002, LIFE-005, LIFE-007; SEC-002, SEC-003, SEC-004, SEC-005; GH-003; GOV-004, GOV-005. ## Risks / known limitations From `GATE-A-REPORT.md` §(f) plus the trade-off table: 1. **Capacity descent path 7-5 unexercised** — rung 8 passed first attempt; rungs 7/6/5 and retry-once logic never ran on hardware (untested against real OOM). 2. **No Wi-Fi in the harness (MEM-001 caveat)** — all PSRAM/IRAM budget numbers are radio-off harness-class; product admission budgets must be re-measured with the network stack active. 3. **On-target scheduler vectors are a subset of the host suite** (256-node pool / 2e4 storm posts vs host 31000 / 1e5); consistency declaration covers only the vectors actually run. 4. **Quiesce is a no-op by ABI semantics** — plugin ABI 1.2 has no quiesce slot; NULL entry is defined as trivial success; real quiesce coordination is later-gate work. 5. **MEMPROT=n trade-off** — `CONFIG_ESP_SYSTEM_MEMPROT=n` is required for the IDF exec heap (`MALLOC_CAP_EXEC`) that `.plugin_iram` needs; software-only PMP config, no eFuse burned (documented in `PATCHES.md` p5); production must re-decide security vs plugin IRAM. 6. **Owner sign-off PENDING** — Gate-A PASS is the PoC team's verdict; formal acceptance of ADR-0002 awaits the owner. ## Not in scope - Product components (GOV-004) — this PR is PoC evidence only; no product code paths change. - **Merge is the owner's call** — do not merge without owner sign-off on ADR-0002. --------- Co-authored-by: ania-lain <[email protected]>
106 lines
4.0 KiB
C
106 lines
4.0 KiB
C
#include "sha256_ref.h"
|
|
|
|
/* FIPS 180-4 SHA-256, written directly from the specification. Host test
|
|
* helper only; the target build uses PSA crypto via mpb_mbedtls_glue.c. */
|
|
|
|
static const uint32_t k[64] = {
|
|
0x428a2f98u, 0x71374491u, 0xb5c0fbcfu, 0xe9b5dba5u, 0x3956c25bu, 0x59f111f1u, 0x923f82a4u,
|
|
0xab1c5ed5u, 0xd807aa98u, 0x12835b01u, 0x243185beu, 0x550c7dc3u, 0x72be5d74u, 0x80deb1feu,
|
|
0x9bdc06a7u, 0xc19bf174u, 0xe49b69c1u, 0xefbe4786u, 0x0fc19dc6u, 0x240ca1ccu, 0x2de92c6fu,
|
|
0x4a7484aau, 0x5cb0a9dcu, 0x76f988dau, 0x983e5152u, 0xa831c66du, 0xb00327c8u, 0xbf597fc7u,
|
|
0xc6e00bf3u, 0xd5a79147u, 0x06ca6351u, 0x14292967u, 0x27b70a85u, 0x2e1b2138u, 0x4d2c6dfcu,
|
|
0x53380d13u, 0x650a7354u, 0x766a0abbu, 0x81c2c92eu, 0x92722c85u, 0xa2bfe8a1u, 0xa81a664bu,
|
|
0xc24b8b70u, 0xc76c51a3u, 0xd192e819u, 0xd6990624u, 0xf40e3585u, 0x106aa070u, 0x19a4c116u,
|
|
0x1e376c08u, 0x2748774cu, 0x34b0bcb5u, 0x391c0cb3u, 0x4ed8aa4au, 0x5b9cca4fu, 0x682e6ff3u,
|
|
0x748f82eeu, 0x78a5636fu, 0x84c87814u, 0x8cc70208u, 0x90befffau, 0xa4506cebu, 0xbef9a3f7u,
|
|
0xc67178f2u,
|
|
};
|
|
|
|
static uint32_t rotr(uint32_t x, uint32_t n) { return (x >> n) | (x << (32 - n)); }
|
|
|
|
static void sha256_block(const uint32_t state_in[8], const uint8_t block[64],
|
|
uint32_t state_out[8]) {
|
|
uint32_t w[64];
|
|
for (int i = 0; i < 16; ++i) {
|
|
w[i] = ((uint32_t)block[i * 4] << 24) | ((uint32_t)block[i * 4 + 1] << 16) |
|
|
((uint32_t)block[i * 4 + 2] << 8) | (uint32_t)block[i * 4 + 3];
|
|
}
|
|
for (int i = 16; i < 64; ++i) {
|
|
uint32_t s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >> 3);
|
|
uint32_t s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >> 10);
|
|
w[i] = w[i - 16] + s0 + w[i - 7] + s1;
|
|
}
|
|
uint32_t a = state_in[0];
|
|
uint32_t b = state_in[1];
|
|
uint32_t c = state_in[2];
|
|
uint32_t d = state_in[3];
|
|
uint32_t e = state_in[4];
|
|
uint32_t f = state_in[5];
|
|
uint32_t g = state_in[6];
|
|
uint32_t h = state_in[7];
|
|
for (int i = 0; i < 64; ++i) {
|
|
uint32_t s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
uint32_t ch = (e & f) ^ (~e & g);
|
|
uint32_t t1 = h + s1 + ch + k[i] + w[i];
|
|
uint32_t s0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
uint32_t maj = (a & b) ^ (a & c) ^ (b & c);
|
|
uint32_t t2 = s0 + maj;
|
|
h = g;
|
|
g = f;
|
|
f = e;
|
|
e = d + t1;
|
|
d = c;
|
|
c = b;
|
|
b = a;
|
|
a = t1 + t2;
|
|
}
|
|
state_out[0] = state_in[0] + a;
|
|
state_out[1] = state_in[1] + b;
|
|
state_out[2] = state_in[2] + c;
|
|
state_out[3] = state_in[3] + d;
|
|
state_out[4] = state_in[4] + e;
|
|
state_out[5] = state_in[5] + f;
|
|
state_out[6] = state_in[6] + g;
|
|
state_out[7] = state_in[7] + h;
|
|
}
|
|
|
|
void sha256_ref(const uint8_t* data, size_t length, uint8_t digest_out[32]) {
|
|
uint32_t state[8] = {
|
|
0x6a09e667u, 0xbb67ae85u, 0x3c6ef372u, 0xa54ff53au,
|
|
0x510e527fu, 0x9b05688cu, 0x1f83d9abu, 0x5be0cd19u,
|
|
};
|
|
size_t full_blocks = length / 64;
|
|
for (size_t i = 0; i < full_blocks; ++i) {
|
|
uint32_t next[8];
|
|
sha256_block(state, data + i * 64, next);
|
|
for (int j = 0; j < 8; ++j) {
|
|
state[j] = next[j];
|
|
}
|
|
}
|
|
uint8_t tail[128];
|
|
size_t remainder = length - full_blocks * 64;
|
|
for (size_t i = 0; i < remainder; ++i) {
|
|
tail[i] = data[full_blocks * 64 + i];
|
|
}
|
|
tail[remainder] = 0x80;
|
|
size_t tail_length = remainder + 1 <= 56 ? 64 : 128;
|
|
for (size_t i = remainder + 1; i < tail_length; ++i) {
|
|
tail[i] = 0x00;
|
|
}
|
|
uint64_t bits = (uint64_t)length * 8;
|
|
for (int i = 0; i < 8; ++i) {
|
|
tail[tail_length - 1 - i] = (uint8_t)(bits >> (8 * i));
|
|
}
|
|
uint32_t next[8];
|
|
sha256_block(state, tail, next);
|
|
if (tail_length == 128) {
|
|
sha256_block(next, tail + 64, next);
|
|
}
|
|
for (int i = 0; i < 8; ++i) {
|
|
digest_out[i * 4] = (uint8_t)(next[i] >> 24);
|
|
digest_out[i * 4 + 1] = (uint8_t)(next[i] >> 16);
|
|
digest_out[i * 4 + 2] = (uint8_t)(next[i] >> 8);
|
|
digest_out[i * 4 + 3] = (uint8_t)next[i];
|
|
}
|
|
}
|