Model the SE's RSA and random number generator

Both ops finished with OP_DONE and produced nothing. se_rng_pseudo()
left its buffer as it was, so Nyx's partition manager wrote whatever
was on the stack into GPT partition GUIDs, and the SD benchmark drew
its random offsets from uninitialised memory. se_rsa_exp_mod() read
back zeros.

- RSA, as Lockpick's bdk drives it: two keyslots of up to 2048 bits
  loaded through SE_RSA_KEYTABLE_ADDR/DATA, KEY_SIZE in 512-bit steps,
  EXP_SIZE in words, the input a little-endian number over DMA and the
  result in SE_RSA_OUTPUT (or memory). Montgomery multiplication on
  32-bit words; an even modulus fails the op.
- RNG into memory or a keyslot quad, LAST_BLOCK + 1 blocks cut to the
  buffer. The bytes come from SplitMix64 with a fixed seed, reset with
  the SE, so runs stay reproducible.

tests/se/ is a new make test payload: RSA-2048 and RSA-1024 in the two
slots, each m^d and s^e checked against Python (gen_vectors.py writes
vectors.h), SHA-256 one-shot and in two parts, AES-128 ECB, and the
RNG filling a zeroed buffer, changing between calls and stopping at
the size asked for. Run against the previous binary it fails the RSA
and RNG checks. The README's "RSA, RNG and chunked SHA are stubs" is
gone; chunked SHA was already modelled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
This commit is contained in:
Claude committed 2026-09-25 22:40:08 +00:00
1 parent fd98939cca
commit 1aa0ee9f23
10 files changed
+799 -17

No files matched your search

+5 -4
View File
@@ -175,7 +175,7 @@ real consoles. Details in [DESIGN.md](DESIGN.md#ccplex-cpu0).
## Tests
```bash
make test # CCPLEX + display regression payloads (arm-none-eabi-gcc, python3)
make test # CCPLEX, SE + display regression payloads (arm-none-eabi-gcc, python3)
tests/hwtest/build.sh build-hwtest # build hwtest-rcm (+ gcc-aarch64-linux-gnu)
tests/hwtest/run.sh ./rcm_emu build-hwtest/hwtest-rcm/build/hwtest.bin
```
@@ -288,12 +288,12 @@ flowchart LR
root --> top["main.cpp<br/>emu_state.h<br/>Makefile<br/>Dockerfile<br/>README.md / DESIGN.md"]
root --> t210["t210/<br/>(SoC peripheral models)"]
root --> display["display/"]
root --> tests["tests/<br/>ccplex/, hwtest/"]
root --> tests["tests/<br/>ccplex/, se/, display/, hwtest/"]
t210 --> mmio["mmio.{h,cpp}<br/>memory_map.h<br/>regcache.h, tegra_bl.h"]
t210 --> cpus["bpmp.{h,cpp} BPMP clock<br/>ccplex.{h,cpp} CPU0 (A57)"]
t210 --> pcie["pcie.{h,cpp}<br/>root complex + CYW4356"]
t210 --> se["se_engine.{h,cpp}<br/>AES-128, SHA-256"]
t210 --> se["se_engine.{h,cpp}<br/>AES-128, SHA-256, RSA, RNG"]
t210 --> i2c["i2c3.{h,cpp}<br/>STMFTS / FTS4 touch"]
display --> sdl["sdl_display.{h,cpp}<br/>DC window scan-out<br/>+ SDL2"]
@@ -314,7 +314,8 @@ For implementation details, see [DESIGN.md](DESIGN.md).
firmware and the full master-key unwrapping flow are not faithfully emulated.
`--prod-keys` is a pragmatic shortcut: when Lockpick writes a derived BIS
(Boot Image Storage) key into a keyslot, the value from the user-supplied key
file is substituted. RSA, RNG, and chunked SHA are stubs.
file is substituted. The random number generator starts from a fixed
seed, so runs repeat.
- **Single-threaded.** Both cores run in batches on the main thread between
SDL event polls. That is also what keeps them deterministic.