# The crypto engines: AES with keyslots, SHA, RSA, PRNG, OTP Source: GBATEK "3DS Crypto Registers" and subsections (DOC). Keys are not here, by rule (firmware-and-keys.md). ## AES (ARM9 only, 10009000h) - **Modes** (AES_CNT bits 27-29): CCM decrypt/encrypt (with MAC size, associated-data pass and MAC verify source/result bits), CTR, CBC decrypt/encrypt, ECB decrypt/encrypt; FIFO in and out (AES_WRFIFO/AES_RDFIFO) with word and byte-order options; block count AES_BLKCNT; IV/CTR AES_IV; DMA requests; interrupt bit 15 of the ARM9 IF (GBATEK "3DS ARM9 Interrupts"). - **Keyslots**: 64 (00h-3Fh). Slots 00h-03h use the DSi-style key layout and scrambler; 04h-3Fh the 3DS's. A slot is loaded with a **normal key** directly, or with **keyX** and **keyY**, from which the hardware forms the normal key by a fixed function involving a secret constant (GBATEK prints the function and both constants; we specify the function's shape and take the constant from the player: decision K3). Writes go through AES_KEYSEL/AES_KEYCNT and the key FIFOs; GBATEK's "Random notes" give the corner rules the specification must keep: a slot must be selected again after its key is written; a write's last word lands in the slot selected when that word is written; byte writes to a key FIFO become `byte * 01010101h`; each key FIFO buffers 16 bytes. - **Usage** (GBATEK "3DS Crypto - AES Keyslots"): eMMC partitions (04h-07h), NCCH containers (2Ch, 25h, 18h, 1Bh by the NCCH's second-keyslot byte), save data, SD data (34h), the common key for tickets (3Dh), and others. Under HLE with decrypted dumps none of this is exercised by games. - **Judges**: FIPS-197 and NIST SP 800-38A/C test vectors (public, hardware-independent) with our own keys for the arithmetic and modes; crossbar9 (BSD-3, ARM9 tests run on consoles by its author) for the register behaviour, when built (devkitARM) and when console verdicts exist. ## SHA (ARM9 at 1000A000h; ARM11 at 10101000h with its FIFO at 10301000h) SHA-256, SHA-224 and SHA-1; first/final round control, result byte order, FIFO with DMA request (CDMA DRQ 0Bh on the ARM11 side). Judge: FIPS 180-4 vectors. ## RSA (ARM9, 1000B000h) Modular exponentiation with keyslots for modulus and exponent (GBATEK "3DS Crypto - RSA Registers"); timing examples given against the 67 MHz timer ("RSA Timing Examples"). GBATEK's "RSA sighax" section describes the boot ROM's signature-parsing flaw: that is a property of Nintendo's boot code, not of the engine, and is out of scope. ## PRNG and OTP (ARM9) A pseudo-random generator (10011000h) and the console-unique OTP (10012000h, 256 bytes, locked after boot). The OTP is the player's; a homebrew test environment starts with a zero or synthetic OTP and says so. ## Modelling level The engines are **functional at the transaction level**: exact results for any key, the FIFO and DMA behaviour as GBATEK states it, and a busy time per block from a timing model (HYPOTHESIS: GBATEK's RSA timing examples are the only timing given). The board's AES needs no secret to be specified or tested.