# The program encryption CPS-2 program ROMs are encrypted **for opcode fetches only**. A data read of the same address returns the ROM as dumped; an opcode fetch inside the encrypted range returns the deciphered word. The cipher, the key and the watchdog live in the B-board custom DL-1525 together with the 68000 core, battery-backed. Everything in this document is either measured here (named command) or read in a pinned source (named file); tiers are those of [validation.md](validation.md). ## Where the cipher sits (and what nobody has seen) - **DL-1525** ("SPA", Motorola H4C057 gate array with a 68000 core) is on the **B-board** and holds the 68000, the security and the bus routing. It is decapped but **0 % reversed** (`cps2-reverse` `DLs/README.md`). There is no gate-level description of the cipher, the key store or the watchdog. - **DL-1827** ("CIF") does **not** hold the key. By its die trace it carries object-RAM data, address and bank selection, bus control and the interrupt lines, and *passes* the security injection signals `SECURITY-DATA`, `SECURITY-CLK`, `/SECURITY-E1`, `/SECURITY-E2` from CN9 to the CPU (`DLs/DL-1827/README.md`, pins 23-26, 69, 129, 131-132, 151). Contradiction C2 with the common wording "DL-1827 holds the keys". - Eduardo Cruz (pinned article, 2017): every B-board custom is battery-powered at rest; CN9 appears from B-board revision 93646B-5; tampering with it "suicided" the board. ## The cipher (published specification) From MAME 0.285 `src/mame/capcom/cps2crypt.cpp` (BSD-3-Clause; header credits Andreas Naive for breaking the algorithm, Nicola Salmoria for the code, Charles MacDonald and Razoola for extracting data from the hardware). Cite, never copy. D = FN2( E, K xor EX( FN1( A, K ) ) ) - `E` 16-bit ciphertext word, `A` the low 16 bits of the **word** address, `K` the 64-bit key, `D` the plaintext word. `FN1`, `FN2`: two four-round Feistel networks with eight bits per half; each round is four s-boxes of six inputs and two outputs; an input is a data bit xor a key bit, or a key bit alone. `EX` expands the 16-bit `FN1` output to 64 bits. The bit groupings of each network's halves are drawn in the header; the s-box tables and the key schedules (`expand_1st_key`, `expand_subkey`, `expand_2nd_key`, and the "extra bits for s-boxes with fewer than six inputs") are in the file body. - Because `A` is only 16 bits, `FN1` runs once per 64 Ki-word residue and the same subkey serves every address `a` with `a mod 0x10000` equal (`cps2_decrypt`'s inner loop steps `a += 0x10000`). A board implementation can therefore precompute 65,536 subkeys, or decrypt the whole encrypted range once at load (MAME's approach: a parallel "opcodes" image). - "The s-boxes were chosen in order to use an empty key (all FF) for the dead board" (header). - jtcps2 (GPL-3.0 HDL, https://github.com/jotego/jtcores @ `ea0ef4e9`, not fetched since 2026-11-24) implements the same networks and checks them against a copy of MAME's `cps2crypt.cpp`: **same lineage**, not an independent oracle (HYPOTHESIS: read from its source in Phase 0). - MBDesu `cps2-utils` (MIT, TypeScript, `src/cps2-crypto`) decrypts and encrypts MAME-format sets in a browser (not read beyond its README). jwestfall69 `mad` (Unlicense) builds its CPS-2 diagnostic ROM in "encrypted and suicide versions" for real B-boards with `machine/cps2/main/util/mad-cps2-encrypt.cpp`, which its header calls "a modified version of mamedev's cps2crypt.cpp" (BSD-3-Clause). Both are MAME's lineage. If MAD's encrypted builds run on keyed boards (the README implies it, no test report is given) the inverse cipher is confirmed at tier 3. ## The key file (`.key`, 20 bytes) - 160 bits: the bit string exactly as clocked into a board. Checked here: `ArcadeHacker_CPS2.ino` (the "CPS2 Desuicider" 1.07, Arduino) sends each of the 20 bytes MSB first, one bit per clock pulse on CN9 (`DATA` pin 2, `SETUP1` 3, `CLOCK` 4, `SETUP2` 5; or CN2 A32/A30/A31/A29 on boards without CN9): unlock = `SETUP1` high, `SETUP2` low; then 160 bits of `DATA` each with a `CLOCK` high/low pulse; then `SETUP1` low, `SETUP2` high. **All 246 bit strings in the `.ino` equal a MAME `.key` file in the local sets byte for byte** (245 game keys, matched against the 175 distinct keys in the non-merged zips; the 246th is the all-`FF` "Phoenix" string = `phoenix.key`). Measured 2026-11-12 with a scratch comparison. So the `.key` format is tied, at tier 3, to a programmer that revives real boards. - MAME reorders the bits (`init_cps2crypt` in `cps2.cpp`: bit `b` of the decoded words comes from file bit `(317 - b) % 160`) into ten 16-bit words: | Word | Meaning (MAME's comment) | Local census (176 distinct keys incl. `phoenix.key`) | | --- | --- | --- | | 0-3 | the 64-bit cipher key | | | 4, 5, 6 | the watchdog instruction, third, second, first word | **34** distinct sequences; the commonest `0838 0007 2000` (19 keys) | | 7 | `0x4000`, "bits 8 to 23 of CPS2 object output address" | `0x4000` in all 175 live keys | | 8 | `0x0900` | `0x0900` in all 175 live keys | | 9 | the encrypted range | upper limit `0x100000` (112 keys), `0x200000` (36), `0x800000` (22), `0x40000` (5); `0xFFFF` = dead board (1) | - Range: for a live key `lower = 0`, `upper = (((~w9 & 0x3FF) << 14) | 0x3FFF) + 1` (bytes). For `w9 = 0xFFFF` (dead board) MAME uses `FF0000-FFFFFF` ("the upper half of a 128kB bank"). - **MAME decrypts one word too many** (measured): `cps2_decrypt` tests `a <= upper_limit` with `upper_limit = upper / 2`, so the word at byte `upper` is deciphered too. `spf2tu` (upper `0x40000`): MAME's opcodes space differs from the ROM at `0x40000` (`BA98` against `00CC`) and equals it from `0x40002` on. Whether the hardware's limit is inclusive is unknown (U3). No game is known to execute at that word. - 22 keys have an upper limit of `0x800000`, beyond any program ROM (at most 4 MiB): opcode fetches from `$400000-$7FFFFF` (object output registers, QSound RAM, add-on RAM, object RAM) would be deciphered on such boards. MAME's opcodes map covers `$000000-$3FFFFF` only, so it never deciphers a fetch from RAM. Recorded as U4. ## The watchdog `cps2crypt.cpp` header: decryption is disabled unless a per-game watchdog opcode sequence runs "at least once every few seconds"; the sequence is the same for every region of a game. **MAME does not emulate it** (no code reads words 4-6). A reference board can implement it as an option (off by default, U5: period and exact matching rule unknown; the instruction must presumably be fetched as opcodes, in order). ## Which accesses are deciphered - MAME's 68000 at `mame0285` routes every bus access to its "opcodes" or program space by the program/data function code, so MAME's "opcodes" space receives **every program-space access** (HYPOTHESIS for MAME's routing: read from its generator, a file without a licence header and so GPL-2.0+, before 2026-11-19; not fetched since 2026-11-24; the BSD-3 `m68000.cpp` and a debugger trace can re-establish it): instruction words, extension words, and PC-relative operand reads (UM: PC-relative modes generate program-space references). The reset fetch of SSP and PC is a supervisor-program access and is deciphered; the exception vector table is read as supervisor data and is not. - Measured on `spf2t` (`scripts/mame_trace.py --dump`): program space at 0 reads `5C6E CABA 5995 F7F9`, opcodes space `00FF 8000 0000 091A` (SSP `$FF8000`, PC `$00091A`), and execution starts at `$91A`. - **Whether DL-1525 deciphers PC-relative data reads as MAME does is not known** (U2): the cipher is inside the CPU package and no trace of its decision signal exists. FC lines 2/6 are the natural candidate. Following MAME is the only available choice and is a tier-5 decision. ### What m68000-python offers (pin `3029f56`: HEAD, two documentation commits after tag `v0.1.0` = `f557abf`) `M68000CPU(..., function_codes=True)` passes `fc=` to every bus callable: 1/2 user data/program, 5/6 supervisor data/program, 7 CPU space (`cpu.py` docstring; `_core.py` `_fc`). `reset()` reads SSP and PC through `_read_program_word` with S set (fc 6); `_read_vector` reads exception vectors through the data path (fc 5); immediate and PC-relative operands go through the program path. That is exactly MAME's split, so **no core change is needed**: the board's `read_word(address, fc)` returns the deciphered word when `fc in (2, 6)` and `address` is inside the range, the ROM word otherwise. Byte reads with a program FC (PC-relative `MOVE.B d(PC)`) take the high or low byte of the deciphered word (MAME's opcodes space is a 16-bit space; same behaviour). ## Decrypted sets: what "Phoenix" really is - MAME 0.285 has **43 Phoenix Edition sets** (all `bootleg`), each carrying `phoenix.key` (20 bytes of `FF`, SHA-1 `eff33c65a4f3862c231f9e4d6fefa7b34398dbf2`), so they run on MAME's dead-board path (`dead_cps2_map`: object output registers moved to `$FFFFF0-$FFFFFB`, work RAM `$FF0000-$FFFFEF`). Three more bootlegs carry a key (`cybotsjd` and `progearjbl` the Phoenix key, `ssf2us2` the `ssf2u` key); `gigaman2` (no QSound, an 8051 + OKI) has none. - Eduardo Cruz: CPS-2 Shock (from 1999) used "a bug found in Capcom's security implementation [that] allowed unencrypted memory dumping on the fly" on real boards to make the plaintext sets and to "phoenix" dead boards. So the plaintext opcode words of these sets are of **hardware origin**, older than the 2007 break. - **A Phoenix image is a merge, not a decryption** (measured with `scripts/phoenix_pair.py`). Each word in the encrypted range equals the MAME-deciphered opcode (code), or the raw ROM word (data the CPU reads as data), or neither (patches): | Pair | Range | Phoenix = deciphered | Phoenix = raw | Neither (patched) | Outside the range | | --- | --- | --- | --- | --- | --- | | `spf2td` / `spf2tu` | `0-0x3FFFF` | 70,340 | 58,958 | 1,772 in 34 runs | identical to the ROM (393,216 words) | | `vsav2d` / `vsav2` | `0-0xFFFFF` | 268,946 | 253,560 | 1,779 | (no ROM outside) | The `spf2td` patches: the exception vectors `$08-$2E` point at a handler block `$3F000-$3FD66` (1,708 words), plus about 60 words in boot code. The initial SSP/PC words at 0-7 are stored deciphered (`00FF8000 0000091A`). ## Consequence for the first rung No local pair is "encrypted ROM / plain decryption of every word", and none can be: the hardware never deciphers data, so a decrypted *image* does not exist. The available test vectors are: 1. **Phoenix pairs (hardware-origin plaintext, tier 3 by provenance):** for every word in the range outside the documented patch runs, `cipher(E) == phoenix` **or** `E == phoenix` (data). With 16-bit words, a chance agreement is 1 in 65,536 per word; 70,340 agreements on `spf2tu` and 268,946 on `vsav2` are decisive. 43 pairs exist locally (`scripts/census.py --pairs` lists the candidates; the exact parent of each must be chosen by trying them, as `spf2tu` was for `spf2td`, from the `pzfu_d.03a` file name). 2. **MAME's opcodes image (tier 5):** `saveo` of the keyed set, compared word for word over the whole range (bit-exact, including MAME's extra word at `upper`, which the board must not copy unless U3 is settled). The two checks together make rung 1: (2) catches every bit, (1) shows the bits are the hardware's.