https://www.3dbrew.org/w/api.php?action=feedcontributions&user=Windwakr&feedformat=atom3dbrew - User contributions [en]2024-03-29T09:05:55ZUser contributionsMediaWiki 1.35.8https://www.3dbrew.org/w/index.php?title=AES_Registers&diff=17757AES Registers2016-07-18T03:36:38Z<p>Windwakr: https://i.imgur.com/O8p41d8.jpg</p>
<hr />
<div>== Registers ==<br />
{| class="wikitable" border="1"<br />
! Old3DS<br />
! Name<br />
! Address<br />
! Width<br />
! RW<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_CNT|AES_CNT]]<br />
| 0x10009000<br />
| 4<br />
| RW<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_BLKCNT|AES_BLKCNT]]<br />
| 0x10009004<br />
| 4<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_WRFIFO/AES_RDFIFO|AES_WRFIFO]]<br />
| 0x10009008<br />
| 4<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_WRFIFO/AES_RDFIFO|AES_RDFIFO]]<br />
| 0x1000900C<br />
| 4<br />
| R<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEYSEL<br />
| 0x10009010<br />
| 1<br />
| RW<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_KEYCNT|AES_KEYCNT]]<br />
| 0x10009011<br />
| 1<br />
| RW<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_CTR|AES_CTR]]<br />
| 0x10009020<br />
| 16<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_MAC|AES_MAC]]<br />
| 0x10009030<br />
| 16<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEY0<br />
| 0x10009040<br />
| 48<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEY1<br />
| 0x10009070<br />
| 48<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEY2<br />
| 0x100090A0<br />
| 48<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEY3<br />
| 0x100090D0<br />
| 48<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEYFIFO<br />
| 0x10009100<br />
| 4<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEYXFIFO<br />
| 0x10009104<br />
| 4<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEYYFIFO<br />
| 0x10009108<br />
| 4<br />
| W<br />
|}<br />
<br />
== AES_CNT ==<br />
{| class="wikitable" border="1"<br />
! Bit<br />
! Description<br />
|-<br />
| 4-0<br />
| Write FIFO count (0-16)<br />
|-<br />
| 9-5<br />
| Read FIFO count (0-16)<br />
|-<br />
| 10<br />
| Flush write FIFO (1=Clear write FIFO)<br />
|-<br />
| 11<br />
| Flush read fifo (1=Clear read FIFO)<br />
|-<br />
| 12-13<br />
| Write FIFO DMA size (0=16, 1=12, 2=8, 3=4 words)<br />
|-<br />
| 14-15<br />
| Read FIFO DMA size (0=4, 1=8, 2=12, 3=16 words)<br />
|-<br />
| 18-16<br />
| MAC size (encoding = (maclen-2)/2)<br />
|-<br />
| 19<br />
|? (MAC related)<br />
|-<br />
| 20<br />
| MAC input control (0 = read MAC from FIFO, 1 = read from MAC register)<br />
|-<br />
| 21<br />
| MAC status (0 = invalid, 1 = verified)<br />
|-<br />
| 22<br />
| Output endianness (1=Big endian, 0=Little endian)<br />
|-<br />
| 23<br />
| Input endianness (1=Big endian, 0=Little endian)<br />
|-<br />
| 24<br />
| Output word order (1=Normal order, 0=Reversed order)<br />
|-<br />
| 25<br />
| Input word order (1=Normal order, 0=Reversed order)<br />
|-<br />
| 26<br />
| Update keyslot (selects the keyslot specified by AES_KEYSEL when this bit is set)<br />
|-<br />
| 29-27<br />
| Mode (0=CCM decrypt, 1=CCM encrypt, 2=CTR, 3=CTR, 4=CBC decrypt, 5=CBC encrypt, 6=ECB decrypt, 7=ECB encrypt)<br />
|-<br />
| 30<br />
| Interrupt enable (1=enable, 0=disable)<br />
|-<br />
| 31<br />
| Start (1=enable/busy, 0=idle)<br />
|}<br />
<br />
When bit31 is set, this register essentially becomes locked and doesn't change when written to. However if bit26 is "set", keyslot-selection is cued to be handled when bit31 is cleared.<br />
<br />
Clearing bit31 while the AES engine is doing crypto will result in the AES engine stopping crypto, once it finishes processing the current block.<br />
<br />
Read/Write FIFO counts and the MAC status can never be set by writing to AES_CNT, they are read-only.<br />
<br />
Changing the input word order triggers the key/keyX/keyY FIFOs to be flushed.<br />
<br />
== AES_BLKCNT ==<br />
<br />
{| class="wikitable" border="1"<br />
! Bit<br />
! Description<br />
|-<br />
| 16-31<br />
| (Data length)>>4 (i.e. the number of blocks to process)<br />
|}<br />
<br />
== AES_WRFIFO/AES_RDFIFO ==<br />
Up to 128 bytes of input data can be buffered. Bits 12-13 and 14-15 in AES_CNT configure the DMA request for the relevant FIFO (see above).<br />
<br />
The input data for the AES crypto operation is written to AES_WRFIFO, the output data is read from AES_RDFIFO.<br />
<br />
Reading from AES_RDFIFO when there's no data available in the RDFIFO will result in reading the last word that was in the RDFIFO.<br />
<br />
When triggering either RDFIFO or WRFIFO to be flushed, the AES Engine does not clear either buffer.<br />
<br />
Word order and endianness can be changed between each read/write to these FIFOs. However changing the word order when writing to WRFIFO can cause the word to be written outside the current block, leaving uninitialized data in its place. Attempts to change endianness or word order are not honored when reading from RDFIFO when no more data is available.<br />
<br />
== AES_KEYCNT ==<br />
{| class="wikitable" border="1"<br />
! Bit<br />
! Description<br />
|-<br />
| 5-0<br />
| Keyslot<br />
|-<br />
| 6<br />
| Hardware key-generator type: 0 = 3DS, 1 = DSi.<br />
|-<br />
| 7<br />
| This normally has value 1 written here when updating keys. 0 = disable key FIFO flush, 1 = enable key FIFO flush.<br />
|}<br />
<br />
Bit6 is only used when keyslots >=4 are used, value1 has the same affect as doing key-init with the TWL keyslots. Bit6 is only checked when a keyY was completely written, for when the final-normalkey needs updated via the key-generator. Changing bit6 has no affect on the generated normalkey when writing to this bit immediately after writing the last keyY word.<br />
<br />
== AES_CTR ==<br />
This register specifies the counter (CTR mode), nonce (CCM mode) or the initialization vector (CBC mode) depending on the mode of operation.<br />
For CBC and CTR mode this register takes up the full 16 bytes, but for CCM mode the nonce is only the first 12 bytes.<br />
The AES engine will automatically increment the counter up to the maximum BLKCNT, after which point it must be manually incremented and set again.<br />
<br />
== AES_MAC ==<br />
This register specifies the message authentication code (MAC) for use in CCM mode.<br />
<br />
== AES_KEY0/1/2/3 ==<br />
{| class="wikitable" border="1"<br />
! Byte<br />
! Description<br />
|-<br />
| 0-15<br />
| Normalkey<br />
|-<br />
| 16-31<br />
| KeyX<br />
|-<br />
| 32-47<br />
| KeyY<br />
|-}<br />
<br />
These registers are the same as they were on TWL, and are likely preserved for compatibility reasons. The keyslot is updated immediately after *any* data(u8/u32/...) is written here, which was used on DSi to [[3DS_System_Flaws|break]] the key-generator.<br />
<br />
== Endianness and word order ==<br />
When writing to the AES_CTR, AES_MAC or AES_KEY0/1/2/3 register, the hardware will process the written data according to the current input endianness specified in AES_CNT. However, the current specified input word order will not be honored for this register, and always defaults to reversed word order. Therefore, for normal word order, the reversal must be carried out manually if required.<br />
<br />
== Keyslot ranges ==<br />
This is approximately a table of what is set by bootrom before booting into FIRM. Often it appears that keyslots in groups of 4 have the same keyX, and sometimes also same keyY set.<br />
<br />
{| class="wikitable" border="1"<br />
! Keyslot<br />
! Name<br />
! KeyX<br />
! KeyY/Normal-key<br />
! Console unique.<br />
|-<br />
| 0x00-0x03<br />
| TWL keys.<br />
| Probably unset.<br />
| Probably unset.<br />
| -<br />
|-<br />
| 0x04-0x07<br />
| NAND partition keys.<br />
| Same for all.<br />
| Different for all.<br />
| style="background: green" | Yes<br />
|-<br />
| 0x08-0x0B<br />
| See below.<br />
| Same for all.<br />
| Different for all.<br />
| style="background: green" | Yes<br />
|-<br />
| 0x0C-0x0F<br />
| SSL cert key.<br />
| Same for all.<br />
| Same for all.<br />
| style="background: red" | No<br />
|-<br />
| 0x10-0x17<br />
| -<br />
| Not set.<br />
| Not set.<br />
| -<br />
|-<br />
| 0x18-0x1B<br />
| Never used.<br />
| Same for all.<br />
| Same for all.<br />
| style="background: green" | Yes<br />
|-<br />
| 0x1C-0x1F<br />
| Never used.<br />
| Same for all.<br />
| Same for all.<br />
| style="background: green" | Yes<br />
|-<br />
| 0x20-0x23<br />
| Never used.<br />
| Same for all.<br />
| Same for all.<br />
| style="background: orange" | Normalkey is not. keyX is. keyY unknown.<br />
|-<br />
| 0x24<br />
| Never used.<br />
| Individually set.<br />
| Individually set.<br />
| style="background: orange" | Normalkey is not. keyX is. keyY unknown.<br />
|-<br />
| 0x25-0x27<br />
| -<br />
| Not set.<br />
| Not set.<br />
| -<br />
|-<br />
| 0x28-0x2B<br />
| Never used.<br />
| Individually set.<br />
| Individually set.<br />
| style="background: orange" | Normalkey is not. keyX is. keyY unknown.<br />
|-<br />
| 0x2C-0x2F<br />
| Various uniques.<br />
| Same for all.<br />
| Same for all, probably.<br />
| style="background: red" | No<br />
|-<br />
| 0x30-0x33<br />
| Various uniques.<br />
| Same for all.<br />
| Same for all, probably.<br />
| style="background: red" | No<br />
|-<br />
| 0x34-0x37<br />
| Various uniques.<br />
| Same for all.<br />
| Same for all, probably.<br />
| style="background: red" | No<br />
|-<br />
| 0x38-0x3B<br />
| Various uniques.<br />
| Same for all.<br />
| Different for all.<br />
| style="background: red" | No<br />
|-<br />
| 0x3C-0x3F<br />
| Various uniques.<br />
| Individually set.<br />
| Individually set.<br />
| style="background: red" | No<br />
|}<br />
<br />
Keyslot pairs (0x24, 0x28) and (0x38, 0x3C) shares the same normal-key, while at the same time having different keyX's. This suggests they were set to same normal-key by bootrom.<br />
<br />
== Keyslots ==<br />
There are 0x40 keyslots, each of which stores three keys called keyX, keyY and normalkey. All keys can be set explicitly, but the normalkey can optionally be generated using a hardware key generator instead (see [[#Hardware_key_generator|below]]). There is no way to read the contents of a keyslot.<br />
<br />
{| class="wikitable" border="1"<br />
! Keyslot<br />
! Description<br />
! KeyX set by<br />
! KeyY set by<br />
! Normal-key<br />
! Old3DS<br />
|-<br />
| 0x00-0x03<br />
| TWL keys.<br />
| NATIVE_FIRM hard-boot.<br />
| NATIVE_FIRM hard-boot.<br />
| -<br />
| Yes<br />
|-<br />
| 0x04..0x07<br />
| [[Flash_Filesystem|NAND]] partition keys.<br />
<br />
Keyslot is determined by [[NCSD]] partition FS type and encryption type. <br />
The New3DS Process9 sets the keyY for keyslot 0x05 (New3DS CTRNAND) to a key from .(ro)data. Its keyX is console-unique and set by the bootloader.<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x0A<br />
| DSiWare export key.<br />
<br />
Used for encrypting the all-zero 0x10-byte block in the [[DSiWare_Exports|DSiWare_Exports]] header. Console-unique.<br />
| See above keyslot info.<br />
| See above keyslot info.<br />
| -<br />
| Yes<br />
|-<br />
| 0x0B<br />
| This is console-unique. This keyslot is used for the NAND [[Title_Database|dbs]] images AES-CMACs, and the [[Nand/private/movable.sed]] AES-CMAC(when used).<br />
| See above keyslot info.<br />
| See above keyslot info.<br />
| -<br />
| Yes<br />
|-<br />
| 0x0D<br />
| SSL-certificate key.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| -<br />
| -<br />
| Bootrom.<br />
| Yes<br />
|-<br />
| 0x11<br />
| Temporary keyslot.<br />
<br />
Used by FIRM for general normal-key crypto. Also used by the New3DS [[FIRM]] arm9 binary loader.<br />
| Arm9Loader. <br />
| Arm9Loader.<br />
| NATIVE_FIRM.<br />
| Yes<br />
|-<br />
| 0x14<br />
| Starting with [[5.0.0-11]], NATIVE_FIRM Process9 now sets the keyY for this to the same one it uses for initializing 3 of the keyslots' keyYs from [[PSPXI:EncryptDecryptAes|here]].<br />
| Bootrom.<br />
| NATIVE_FIRM boot.<br />
| -<br />
| Yes<br />
|-<br />
| 0x15<br />
| Used/initialized by the New3DS arm9 binary loader, see [[FIRM|here]].<br />
| Arm9Loader.<br />
| Arm9Loader.<br />
| See previous info for this keyslot.<br />
| No<br />
|-<br />
| 0x16<br />
| Used/initialized by the New3DS arm9 binary loader starting with [[9.5.0-22|9.5.0-X]], see [[FIRM|here]].<br />
| Arm9Loader.<br />
| Arm9Loader.<br />
| See previous info for this keyslot.<br />
| No<br />
|-<br />
| 0x18..0x1F<br />
| These are the New3DS keyslots, where the keyX is generated with keyslot 0x11 by the New3DS arm9 binary [[FIRM|loader]]. As of [[FIRM]] [[9.6.0-24|9.6.0-X]] keyslots 0x1C..0x1F are not yet used by Process9.<br />
| Arm9Loader.<br />
| NATIVE_FIRM / see previous info for these keyslots.<br />
| See previous info for these keyslots.<br />
| No<br />
|-<br />
| 0x18<br />
| New3DS [[9.3.0-21|9.3.0-X]] [[NCCH]] key, when ncchflag[3] is 0x0A.<br />
| Arm9Loader.<br />
| NATIVE_FIRM<br />
| -<br />
| No<br />
|-<br />
| 0x19<br />
| New3DS gamecard [[Savegames|savedata]] AES-CMAC key.<br />
<br />
Equivalent of keyslot 0x33, used when a [[NCSD]] flag is set to a certain value (implemented with [[9.3.0-21|9.3.0-X]]).<br />
| Arm9Loader.<br />
| NATIVE_FIRM<br />
| -<br />
| No<br />
|-<br />
| 0x1A<br />
| New3DS gamecard [[Savegames|savedata]] actual key.<br />
<br />
Equivalent of keyslot 0x37, used when a [[NCSD]] flag is set to a certain value (implemented with [[9.3.0-21|9.3.0-X]]).<br />
| Arm9Loader.<br />
| NATIVE_FIRM<br />
| -<br />
| No<br />
|-<br />
| 0x1B<br />
| New3DS [[9.6.0-24|9.6.0-X]] [[NCCH]] key, when ncchflag[3] is 0x0B.<br />
| Arm9Loader.<br />
| NATIVE_FIRM<br />
| -<br />
| No<br />
|-<br />
| 0x24<br />
| AGB_FIRM savegame AES-CMAC key.<br />
| Bootrom.<br />
| AGB/NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x25<br />
| [[7.0.0-13|v7.0]] [[NCCH]] key, when ncchflag[3] is 0x01.<br />
| NATIVE_FIRM [[Savegames#6.0.0-11_Savegame_keyY|boot]].<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x2C<br />
| Original [[NCCH|NCCH]] key, when ncchflag[3] is 0x00 and always for certain NCCH sections.<br />
| Bootrom.<br />
| Process9.<br />
| -<br />
| Yes<br />
|-<br />
| 0x2D<br />
| UDS local-WLAN CCMP key.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x2E<br />
| Streetpass key.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x2F<br />
| [[Savegames#6.0.0-11_Savegame_keyY|v6.0]] save key.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x30<br />
| SD/NAND AES-CMAC key.<br />
<br />
This keyY is initialized via [[Nand/private/movable.sed|movable.sed]]. This is used for calculating the AES-CMACs under SD [[SD_Filesystem|/Nintendo 3DS/<ID0>/<ID1>/]] (except [[DSiWare_Exports]]) and [[Flash_Filesystem|NAND]] /data/.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x31<br />
| APT wrap key.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]]. NATIVE_FIRM sets this keyY to the same one used for keyslot 0x2E.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x32<br />
| Unknown.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x33<br />
| Gamecard [[Savegames|savedata]] AES-CMAC.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x34<br />
| SD key.<br />
<br />
This keyY is initialized via [[Nand/private/movable.sed|movable.sed]]. This is used for encrypting *all* SD card data under [[SD_Filesystem|/Nintendo 3DS/<ID0>/<ID1>/]].<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x35<br />
| Movable.sed key.<br />
<br />
This is the keyslot used for movable.sed encryption + AES-CBC MAC with the import/export [[FSPXI:ImportIntegrityVerificationSeed|commands]].<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x36<br />
| Unknown. Used by friends module.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x37<br />
| Gamecard [[Savegames|savedata]] actual key.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x38<br />
| BOSS key.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x39<br />
| Download Play key, and the actual NFC key for generating retail [[Amiibo]] keys.<br />
<br />
This keyslot is used for two different keys. Both are available via [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]]. NATIVE_FIRM sets this keyY to the same one used for keyslot 0x2E.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x3A<br />
| DSiWare export key.<br />
<br />
This keyY is initialized via [[Nand/private/movable.sed|movable.sed]]. This is used for calculating the AES-CMACs for SD [[DSiWare_Exports]].<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x3B<br />
| [[CTRCARD_Registers#CTRCARD_SECSEED|CTR-CARD hardware-crypto seed]] decryption key.<br />
<br />
AES-CCM is used, the keyY, nonce and MAC are stored in the [[NCSD#Card_Info_Header|Card Info Header]].<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x3D<br />
| Common key.<br />
<br />
Used to decrypt title keys in [[Ticket]].<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|}<br />
<br />
=== Updating keydata ===<br />
The contents of the keyslot specified in AES_KEYCNT can be updated by consecutively writing four words to AES_KEYXFIFO (keyX), AES_KEYYFIFO(keyY), or AES_KEYFIFO (normalkey).<br />
<br />
After writing to a keyslot, the keyslot must be selected again(write AES_KEYSEL + set AES_CNT bit26), even when writing to the same keyslot. Writing the last word to a key FIFO immediately after selecting a keyslot will not affect the keyslot keydata that gets used at that time, the new keydata will not get used until the keyslot gets selected again.<br />
<br />
Writing to the key FIFOs with byte writes results in the AES engine converting the byte to a word for setting the key word, with this: word = (byteval) | (byteval<<8) | (byteval<<16) | (byteval<<24). The result is the same regardless of which FIFO register byte was written to.<br />
<br />
The TWL keyslots 0x00-0x03 can be set directly by writing to the AES_KEY0-AES_KEY3 registers.<br />
<br />
The key FIFOs can be written simultaneously. For example, executing the following will result in the keyX and keyY being set to all-zero(unknown for normalkey): memset(0x10009100, 0, 0x100);<br />
<br />
Each key FIFO has a 0x10-byte tmp-buffer for storing the words written to that FIFO. Once the last word is written to a key FIFO, the filled tmp-buffer is then written to the key-data for the keyslot selected by AES_KEYCNT at the time the last word was written.<br />
<br />
=== Hardware key generator ===<br />
A dedicated hardware key generator can be used to generate a keyslot's normal-key from its keyX and keyY. The hardware key generator is triggered by writing the keyY, which is the only way to trigger it with the 3DS keyslots.<br />
<br />
The algorithm for generating the normal-key from keyX and keyY is as follows, in big-endian 128-bit unsigned wraparound arithmetic:<br />
<br />
{| class="wikitable" border="1"<br />
! Mode<br />
! Formula<br />
|-<br />
| 3DS<br />
| NormalKey = (((KeyX ROL 2) XOR KeyY) + C1) ROR 41<br />
|-<br />
| DSi<br />
| NormalKey = ((KeyX XOR KeyY) + C2) ROL 42<br />
|}<br />
<br />
Unless noted otherwise, all keyslots on retail units use the hardware key generator.<br />
<br />
=== FIRM-launch key clearing ===<br />
Starting with [[9.0.0-20]] the Process9 FIRM-launch code now "clears" the following AES keyslots, with certain keydata by writing the normal-key: 0x15 and 0x18-0x20. These are the keyslots used by the New3DS [[FIRM]] arm9bin loader(minus keyslot 0x11), the New3DS Process9 does this too.</div>Windwakrhttps://www.3dbrew.org/w/index.php?title=AES_Registers&diff=17708AES Registers2016-07-17T14:49:48Z<p>Windwakr: Completely wrong. Please at least do a modicum of research/testing before making any further wiki edits. Thanks.</p>
<hr />
<div>== Registers ==<br />
{| class="wikitable" border="1"<br />
! Old3DS<br />
! Name<br />
! Address<br />
! Width<br />
! RW<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_CNT|AES_CNT]]<br />
| 0x10009000<br />
| 4<br />
| RW<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_BLKCNT|AES_BLKCNT]]<br />
| 0x10009004<br />
| 4<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_WRFIFO/AES_RDFIFO|AES_WRFIFO]]<br />
| 0x10009008<br />
| 4<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_WRFIFO/AES_RDFIFO|AES_RDFIFO]]<br />
| 0x1000900C<br />
| 4<br />
| R<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEYSEL<br />
| 0x10009010<br />
| 1<br />
| RW<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_KEYCNT|AES_KEYCNT]]<br />
| 0x10009011<br />
| 1<br />
| RW<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_CTR|AES_CTR]]<br />
| 0x10009020<br />
| 16<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_MAC|AES_MAC]]<br />
| 0x10009030<br />
| 16<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEY0<br />
| 0x10009040<br />
| 48<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEY1<br />
| 0x10009070<br />
| 48<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEY2<br />
| 0x100090A0<br />
| 48<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEY3<br />
| 0x100090D0<br />
| 48<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEYFIFO<br />
| 0x10009100<br />
| 4<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEYXFIFO<br />
| 0x10009104<br />
| 4<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEYYFIFO<br />
| 0x10009108<br />
| 4<br />
| W<br />
|}<br />
<br />
== AES_CNT ==<br />
{| class="wikitable" border="1"<br />
! Bit<br />
! Description<br />
|-<br />
| 4-0<br />
| Write FIFO count (0-16)<br />
|-<br />
| 9-5<br />
| Read FIFO count (0-16)<br />
|-<br />
| 10<br />
| Flush write FIFO (1=Clear write FIFO)<br />
|-<br />
| 11<br />
| Flush read fifo (1=Clear read FIFO)<br />
|-<br />
| 12-13<br />
| Write FIFO DMA size (0=16, 1=12, 2=8, 3=4 words)<br />
|-<br />
| 14-15<br />
| Read FIFO DMA size (0=4, 1=8, 2=12, 3=16 words)<br />
|-<br />
| 18-16<br />
| MAC size (encoding = (maclen-2)/2)<br />
|-<br />
| 19<br />
|? (MAC related)<br />
|-<br />
| 20<br />
| MAC input control (0 = read MAC from FIFO, 1 = read from MAC register)<br />
|-<br />
| 21<br />
| MAC status (0 = invalid, 1 = verified)<br />
|-<br />
| 22<br />
| Output endianness (1=Big endian, 0=Little endian)<br />
|-<br />
| 23<br />
| Input endianness (1=Big endian, 0=Little endian)<br />
|-<br />
| 24<br />
| Output word order (1=Normal order, 0=Reversed order)<br />
|-<br />
| 25<br />
| Input word order (1=Normal order, 0=Reversed order)<br />
|-<br />
| 26<br />
| Update keyslot (selects the keyslot specified by AES_KEYSEL when this bit is set)<br />
|-<br />
| 29-27<br />
| Mode (0=CCM decrypt, 1=CCM encrypt, 2=CTR, 3=CTR, 4=CBC decrypt, 5=CBC encrypt, 6=ECB decrypt, 7=ECB encrypt)<br />
|-<br />
| 30<br />
| Interrupt enable (1=enable, 0=disable)<br />
|-<br />
| 31<br />
| Start (1=enable/busy, 0=idle)<br />
|}<br />
<br />
When bit31 is set, this register essentially becomes locked and doesn't change when written to. However if bit26 is "set", keyslot-selection is cued to be handled when bit31 is cleared.<br />
<br />
Clearing bit31 while the AES engine is doing crypto will result in the AES engine stopping crypto, once it finishes processing the current block.<br />
<br />
Read/Write FIFO counts and the MAC status can never be set by writing to AES_CNT, they are read-only.<br />
<br />
Changing the input word order triggers the key/keyX/keyY FIFOs to be flushed.<br />
<br />
== AES_BLKCNT ==<br />
<br />
{| class="wikitable" border="1"<br />
! Bit<br />
! Description<br />
|-<br />
| 16-31<br />
| (Data length)>>4 (i.e. the number of blocks to process)<br />
|}<br />
<br />
== AES_WRFIFO/AES_RDFIFO ==<br />
Up to 128 bytes of input data can be buffered.<br />
<br />
The input data for the AES crypto operation is written to AES_WRFIFO, the output data is read from AES_RDFIFO.<br />
<br />
Reading from AES_RDFIFO when there's no data available in the RDFIFO will result in reading the last word that was in the RDFIFO.<br />
<br />
When triggering either RDFIFO or WRFIFO to be flushed, the AES Engine does not clear either buffer.<br />
<br />
Word order and endianness can be changed between each read/write to these FIFOs. However changing the word order when writing to WRFIFO can cause the word to be written outside the current block, leaving uninitialized data in its place. Attempts to change endianness or word order are not honored when reading from RDFIFO when no more data is available.<br />
<br />
== AES_KEYCNT ==<br />
{| class="wikitable" border="1"<br />
! Bit<br />
! Description<br />
|-<br />
| 5-0<br />
| Keyslot<br />
|-<br />
| 6<br />
| Hardware key-generator type: 0 = 3DS, 1 = DSi.<br />
|-<br />
| 7<br />
| This normally has value 1 written here when updating keys. 0 = disable key FIFO flush, 1 = enable key FIFO flush.<br />
|}<br />
<br />
Bit6 is only used when keyslots >=4 are used, value1 has the same affect as doing key-init with the TWL keyslots. Bit6 is only checked when a keyY was completely written, for when the final-normalkey needs updated via the key-generator. Changing bit6 has no affect on the generated normalkey when writing to this bit immediately after writing the last keyY word.<br />
<br />
== AES_CTR ==<br />
This register specifies the counter (CTR mode), nonce (CCM mode) or the initialization vector (CBC mode) depending on the mode of operation.<br />
For CBC and CTR mode this register takes up the full 16 bytes, but for CCM mode the nonce is only the first 12 bytes.<br />
The AES engine will automatically increment the counter up to the maximum BLKCNT, after which point it must be manually incremented and set again.<br />
<br />
== AES_MAC ==<br />
This register specifies the message authentication code (MAC) for use in CCM mode.<br />
<br />
== AES_KEY0/1/2/3 ==<br />
{| class="wikitable" border="1"<br />
! Byte<br />
! Description<br />
|-<br />
| 0-15<br />
| Normalkey<br />
|-<br />
| 16-31<br />
| KeyX<br />
|-<br />
| 32-47<br />
| KeyY<br />
|-}<br />
<br />
These registers are the same as they were on TWL, and are likely preserved for compatibility reasons. The keyslot is updated immediately after *any* data(u8/u32/...) is written here, which was used on DSi to [[3DS_System_Flaws|break]] the key-generator.<br />
<br />
== Endianness and word order ==<br />
When writing to the AES_CTR, AES_MAC or AES_KEY0/1/2/3 register, the hardware will process the written data according to the current input endianness specified in AES_CNT. However, the current specified input word order will not be honored for this register, and always defaults to reversed word order. Therefore, for normal word order, the reversal must be carried out manually if required.<br />
<br />
== Keyslot ranges ==<br />
This is approximately a table of what is set by bootrom before booting into FIRM. Often it appears that keyslots in groups of 4 have the same keyX, and sometimes also same keyY set.<br />
<br />
{| class="wikitable" border="1"<br />
! Keyslot<br />
! Name<br />
! KeyX<br />
! KeyY/Normal-key<br />
! Console unique.<br />
|-<br />
| 0x00-0x03<br />
| TWL keys.<br />
| Probably unset.<br />
| Probably unset.<br />
| -<br />
|-<br />
| 0x04-0x07<br />
| NAND partition keys.<br />
| Same for all.<br />
| Different for all.<br />
| style="background: green" | Yes<br />
|-<br />
| 0x08-0x0B<br />
| See below.<br />
| Same for all.<br />
| Different for all.<br />
| style="background: green" | Yes<br />
|-<br />
| 0x0C-0x0F<br />
| SSL cert key.<br />
| Same for all.<br />
| Same for all.<br />
| style="background: red" | No<br />
|-<br />
| 0x10-0x17<br />
| -<br />
| Not set.<br />
| Not set.<br />
| -<br />
|-<br />
| 0x18-0x1B<br />
| Never used.<br />
| Same for all.<br />
| Same for all.<br />
| style="background: green" | Yes<br />
|-<br />
| 0x1C-0x1F<br />
| Never used.<br />
| Same for all.<br />
| Same for all.<br />
| style="background: green" | Yes<br />
|-<br />
| 0x20-0x23<br />
| Never used.<br />
| Same for all.<br />
| Same for all.<br />
| style="background: orange" | Normalkey is not. keyX is. keyY unknown.<br />
|-<br />
| 0x24<br />
| Never used.<br />
| Individually set.<br />
| Individually set.<br />
| style="background: orange" | Normalkey is not. keyX is. keyY unknown.<br />
|-<br />
| 0x25-0x27<br />
| -<br />
| Not set.<br />
| Not set.<br />
| -<br />
|-<br />
| 0x28-0x2B<br />
| Never used.<br />
| Individually set.<br />
| Individually set.<br />
| style="background: orange" | Normalkey is not. keyX is. keyY unknown.<br />
|-<br />
| 0x2C-0x2F<br />
| Various uniques.<br />
| Same for all.<br />
| Same for all, probably.<br />
| style="background: red" | No<br />
|-<br />
| 0x30-0x33<br />
| Various uniques.<br />
| Same for all.<br />
| Same for all, probably.<br />
| style="background: red" | No<br />
|-<br />
| 0x34-0x37<br />
| Various uniques.<br />
| Same for all.<br />
| Same for all, probably.<br />
| style="background: red" | No<br />
|-<br />
| 0x38-0x3B<br />
| Various uniques.<br />
| Same for all.<br />
| Different for all.<br />
| style="background: red" | No<br />
|-<br />
| 0x3C-0x3F<br />
| Various uniques.<br />
| Individually set.<br />
| Individually set.<br />
| style="background: red" | No<br />
|}<br />
<br />
Keyslot pairs (0x24, 0x28) and (0x38, 0x3C) shares the same normal-key, while at the same time having different keyX's. This suggests they were set to same normal-key by bootrom.<br />
<br />
== Keyslots ==<br />
There are 0x40 keyslots, each of which stores three keys called keyX, keyY and normalkey. All keys can be set explicitly, but the normalkey can optionally be generated using a hardware key generator instead (see [[#Hardware_key_generator|below]]). There is no way to read the contents of a keyslot.<br />
<br />
{| class="wikitable" border="1"<br />
! Keyslot<br />
! Description<br />
! KeyX set by<br />
! KeyY set by<br />
! Normal-key<br />
! Old3DS<br />
|-<br />
| 0x00-0x03<br />
| TWL keys.<br />
| NATIVE_FIRM hard-boot.<br />
| NATIVE_FIRM hard-boot.<br />
| -<br />
| Yes<br />
|-<br />
| 0x04..0x07<br />
| [[Flash_Filesystem|NAND]] partition keys.<br />
<br />
Keyslot is determined by [[NCSD]] partition FS type and encryption type. <br />
The New3DS Process9 sets the keyY for keyslot 0x05 (New3DS CTRNAND) to a key from .(ro)data. Its keyX is console-unique and set by the bootloader.<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x0A<br />
| DSiWare export key.<br />
<br />
Used for encrypting the all-zero 0x10-byte block in the [[DSiWare_Exports|DSiWare_Exports]] header. Console-unique.<br />
| See above keyslot info.<br />
| See above keyslot info.<br />
| -<br />
| Yes<br />
|-<br />
| 0x0B<br />
| This is console-unique. This keyslot is used for the NAND [[Title_Database|dbs]] images AESMACs, and the [[Nand/private/movable.sed]] AESMAC(when used).<br />
| See above keyslot info.<br />
| See above keyslot info.<br />
| -<br />
| Yes<br />
|-<br />
| 0x0D<br />
| SSL-certificate key.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| -<br />
| -<br />
| Bootrom.<br />
| Yes<br />
|-<br />
| 0x11<br />
| Temporary keyslot.<br />
<br />
Used by FIRM for general normal-key crypto. Also used by the New3DS [[FIRM]] arm9 binary loader.<br />
| Arm9Loader. <br />
| Arm9Loader.<br />
| NATIVE_FIRM.<br />
| Yes<br />
|-<br />
| 0x14<br />
| Starting with [[5.0.0-11]], NATIVE_FIRM Process9 now sets the keyY for this to the same one it uses for initializing 3 of the keyslots' keyYs from [[PSPXI:EncryptDecryptAes|here]].<br />
| Bootrom.<br />
| NATIVE_FIRM boot.<br />
| -<br />
| Yes<br />
|-<br />
| 0x15<br />
| Used/initialized by the New3DS arm9 binary loader, see [[FIRM|here]].<br />
| Arm9Loader.<br />
| Arm9Loader.<br />
| See previous info for this keyslot.<br />
| No<br />
|-<br />
| 0x16<br />
| Used/initialized by the New3DS arm9 binary loader starting with [[9.5.0-22|9.5.0-X]], see [[FIRM|here]].<br />
| Arm9Loader.<br />
| Arm9Loader.<br />
| See previous info for this keyslot.<br />
| No<br />
|-<br />
| 0x18..0x1F<br />
| These are the New3DS keyslots, where the keyX is generated with keyslot 0x11 by the New3DS arm9 binary [[FIRM|loader]]. As of [[FIRM]] [[9.6.0-24|9.6.0-X]] keyslots 0x1C..0x1F are not yet used by Process9.<br />
| Arm9Loader.<br />
| NATIVE_FIRM / see previous info for these keyslots.<br />
| See previous info for these keyslots.<br />
| No<br />
|-<br />
| 0x18<br />
| New3DS [[9.3.0-21|9.3.0-X]] [[NCCH]] key, when ncchflag[3] is 0x0A.<br />
| Arm9Loader.<br />
| NATIVE_FIRM<br />
| -<br />
| No<br />
|-<br />
| 0x19<br />
| New3DS gamecard [[Savegames|savedata]] AES-MAC key.<br />
<br />
Equivalent of keyslot 0x33, used when a [[NCSD]] flag is set to a certain value (implemented with [[9.3.0-21|9.3.0-X]]).<br />
| Arm9Loader.<br />
| NATIVE_FIRM<br />
| -<br />
| No<br />
|-<br />
| 0x1A<br />
| New3DS gamecard [[Savegames|savedata]] actual key.<br />
<br />
Equivalent of keyslot 0x37, used when a [[NCSD]] flag is set to a certain value (implemented with [[9.3.0-21|9.3.0-X]]).<br />
| Arm9Loader.<br />
| NATIVE_FIRM<br />
| -<br />
| No<br />
|-<br />
| 0x1B<br />
| New3DS [[9.6.0-24|9.6.0-X]] [[NCCH]] key, when ncchflag[3] is 0x0B.<br />
| Arm9Loader.<br />
| NATIVE_FIRM<br />
| -<br />
| No<br />
|-<br />
| 0x24<br />
| AGB_FIRM savegame AES-MAC key.<br />
| Bootrom.<br />
| AGB/NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x25<br />
| [[7.0.0-13|v7.0]] [[NCCH]] key, when ncchflag[3] is 0x01.<br />
| NATIVE_FIRM [[Savegames#6.0.0-11_Savegame_keyY|boot]].<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x2C<br />
| Original [[NCCH|NCCH]] key, when ncchflag[3] is 0x00 and always for certain NCCH sections.<br />
| Bootrom.<br />
| Process9.<br />
| -<br />
| Yes<br />
|-<br />
| 0x2D<br />
| UDS local-WLAN CCMP key.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x2E<br />
| Streetpass key.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x2F<br />
| [[Savegames#6.0.0-11_Savegame_keyY|v6.0]] save key.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x30<br />
| SD/NAND AES-MAC key.<br />
<br />
This keyY is initialized via [[Nand/private/movable.sed|movable.sed]]. This is used for calculating the AESMACs under SD [[SD_Filesystem|/Nintendo 3DS/<ID0>/<ID1>/]] (except [[DSiWare_Exports]]) and [[Flash_Filesystem|NAND]] /data/.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x31<br />
| APT wrap key.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]]. NATIVE_FIRM sets this keyY to the same one used for keyslot 0x2E.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x32<br />
| Unknown.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x33<br />
| Gamecard [[Savegames|savedata]] AES-MAC.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x34<br />
| SD key.<br />
<br />
This keyY is initialized via [[Nand/private/movable.sed|movable.sed]]. This is used for encrypting *all* SD card data under [[SD_Filesystem|/Nintendo 3DS/<ID0>/<ID1>/]].<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x35<br />
| Movable.sed key.<br />
<br />
This is the keyslot used for movable.sed encryption + AES-MAC with the import/export [[FSPXI:ImportIntegrityVerificationSeed|commands]].<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x36<br />
| Unknown. Used by friends module.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x37<br />
| Gamecard [[Savegames|savedata]] actual key.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x38<br />
| BOSS key.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x39<br />
| Download Play key, and the actual NFC key for generating retail [[Amiibo]] keys.<br />
<br />
This keyslot is used for two different keys. Both are available via [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]]. NATIVE_FIRM sets this keyY to the same one used for keyslot 0x2E.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x3A<br />
| DSiWare export key.<br />
<br />
This keyY is initialized via [[Nand/private/movable.sed|movable.sed]]. This is used for calculating the AESMACs for SD [[DSiWare_Exports]].<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x3B<br />
| [[CTRCARD_Registers#CTRCARD_SECSEED|CTR-CARD hardware-crypto seed]] decryption key.<br />
<br />
AES-CCM is used, the keyY, nonce and MAC are stored in the [[NCSD#Card_Info_Header|Card Info Header]].<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x3D<br />
| Common key.<br />
<br />
Used to decrypt title keys in [[Ticket]].<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|}<br />
<br />
=== Updating keydata ===<br />
The contents of the keyslot specified in AES_KEYCNT can be updated by consecutively writing four words to AES_KEYXFIFO (keyX), AES_KEYYFIFO(keyY), or AES_KEYFIFO (normalkey).<br />
<br />
After writing to a keyslot, the keyslot must be selected again(write AES_KEYSEL + set AES_CNT bit26), even when writing to the same keyslot. Writing the last word to a key FIFO immediately after selecting a keyslot will not affect the keyslot keydata that gets used at that time, the new keydata will not get used until the keyslot gets selected again.<br />
<br />
Writing to the key FIFOs with byte writes results in the AES engine converting the byte to a word for setting the key word, with this: word = (byteval) | (byteval<<8) | (byteval<<16) | (byteval<<24). The result is the same regardless of which FIFO register byte was written to.<br />
<br />
The TWL keyslots 0x00-0x03 can be set directly by writing to the AES_KEY0-AES_KEY3 registers.<br />
<br />
The key FIFOs can be written simultaneously. For example, executing the following will result in the keyX and keyY being set to all-zero(unknown for normalkey): memset(0x10009100, 0, 0x100);<br />
<br />
Each key FIFO has a 0x10-byte tmp-buffer for storing the words written to that FIFO. Once the last word is written to a key FIFO, the filled tmp-buffer is then written to the key-data for the keyslot selected by AES_KEYCNT at the time the last word was written.<br />
<br />
=== Hardware key generator ===<br />
A dedicated hardware key generator can be used to generate a keyslot's normal-key from its keyX and keyY. The hardware key generator is triggered by writing the keyY, which is the only way to trigger it with the 3DS keyslots.<br />
<br />
The algorithm for generating the normal-key from keyX and keyY is as follows, in big-endian 128-bit unsigned wraparound arithmetic:<br />
<br />
{| class="wikitable" border="1"<br />
! Mode<br />
! Formula<br />
|-<br />
| 3DS<br />
| NormalKey = (((KeyX ROL 2) XOR KeyY) + C1) ROR 41<br />
|-<br />
| DSi<br />
| NormalKey = ((KeyX XOR KeyY) + C2) ROL 42<br />
|}<br />
<br />
Unless noted otherwise, all keyslots on retail units use the hardware key generator.<br />
<br />
=== FIRM-launch key clearing ===<br />
Starting with [[9.0.0-20]] the Process9 FIRM-launch code now "clears" the following AES keyslots, with certain keydata by writing the normal-key: 0x15 and 0x18-0x20. These are the keyslots used by the New3DS [[FIRM]] arm9bin loader(minus keyslot 0x11), the New3DS Process9 does this too.</div>Windwakrhttps://www.3dbrew.org/w/index.php?title=AES_Registers&diff=17702AES Registers2016-07-16T17:28:42Z<p>Windwakr: :^)</p>
<hr />
<div>== Registers ==<br />
{| class="wikitable" border="1"<br />
! Old3DS<br />
! Name<br />
! Address<br />
! Width<br />
! RW<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_CNT|AES_CNT]]<br />
| 0x10009000<br />
| 4<br />
| RW<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_BLKCNT|AES_BLKCNT]]<br />
| 0x10009004<br />
| 4<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_WRFIFO/AES_RDFIFO|AES_WRFIFO]]<br />
| 0x10009008<br />
| 4<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_WRFIFO/AES_RDFIFO|AES_RDFIFO]]<br />
| 0x1000900C<br />
| 4<br />
| R<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEYSEL<br />
| 0x10009010<br />
| 1<br />
| RW<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_KEYCNT|AES_KEYCNT]]<br />
| 0x10009011<br />
| 1<br />
| RW<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_CTR|AES_CTR]]<br />
| 0x10009020<br />
| 16<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| [[#AES_MAC|AES_MAC]]<br />
| 0x10009030<br />
| 16<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEY0<br />
| 0x10009040<br />
| 48<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEY1<br />
| 0x10009070<br />
| 48<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEY2<br />
| 0x100090A0<br />
| 48<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEY3<br />
| 0x100090D0<br />
| 48<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEYFIFO<br />
| 0x10009100<br />
| 4<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEYXFIFO<br />
| 0x10009104<br />
| 4<br />
| W<br />
|-<br />
| style="background: green" | Yes<br />
| AES_KEYYFIFO<br />
| 0x10009108<br />
| 4<br />
| W<br />
|}<br />
<br />
== AES_CNT ==<br />
{| class="wikitable" border="1"<br />
! Bit<br />
! Description<br />
|-<br />
| 4-0<br />
| Write FIFO count (0-16)<br />
|-<br />
| 9-5<br />
| Read FIFO count (0-16)<br />
|-<br />
| 10<br />
| Flush write FIFO (1=Clear write FIFO)<br />
|-<br />
| 11<br />
| Flush read fifo (1=Clear read FIFO)<br />
|-<br />
| 12-13<br />
| Write FIFO DMA size (0=16, 1=12, 2=8, 3=4 words)<br />
|-<br />
| 14-15<br />
| Read FIFO DMA size (0=4, 1=8, 2=12, 3=16 words)<br />
|-<br />
| 18-16<br />
| MAC size (encoding = (maclen-2)/2)<br />
|-<br />
| 19<br />
|? (MAC related)<br />
|-<br />
| 20<br />
| MAC input control (0 = read MAC from FIFO, 1 = read from MAC register)<br />
|-<br />
| 21<br />
| MAC status (0 = invalid, 1 = verified)<br />
|-<br />
| 22<br />
| Output endianness (1=Big endian, 0=Little endian)<br />
|-<br />
| 23<br />
| Input endianness (1=Big endian, 0=Little endian)<br />
|-<br />
| 24<br />
| Output word order (1=Normal order, 0=Reversed order)<br />
|-<br />
| 25<br />
| Input word order (1=Normal order, 0=Reversed order)<br />
|-<br />
| 26<br />
| Update keyslot (selects the keyslot specified by AES_KEYSEL when this bit is set)<br />
|-<br />
| 29-27<br />
| Mode (0=CCM decrypt, 1=CCM encrypt, 2=CTR, 3=CTR, 4=CBC decrypt, 5=CBC encrypt, 6=ECB decrypt, 7=ECB encrypt)<br />
|-<br />
| 30<br />
| Interrupt enable (1=enable, 0=disable)<br />
|-<br />
| 31<br />
| Start (1=enable/busy, 0=idle)<br />
|}<br />
<br />
When bit31 is set, this register essentially becomes locked and doesn't change when written to. However if bit26 is "set", keyslot-selection is cued to be handled when bit31 is cleared.<br />
<br />
Clearing bit31 while the AES engine is doing crypto will result in the AES engine stopping crypto, once it finishes processing the current block.<br />
<br />
Read/Write FIFO counts and the MAC status can never be set by writing to AES_CNT, they are read-only.<br />
<br />
Changing the input word order triggers the key/keyX/keyY FIFOs to be flushed.<br />
<br />
== AES_BLKCNT ==<br />
<br />
{| class="wikitable" border="1"<br />
! Bit<br />
! Description<br />
|-<br />
| 16-31<br />
| (Data length)>>4 (i.e. the number of blocks to process)<br />
|}<br />
<br />
== AES_WRFIFO/AES_RDFIFO ==<br />
Up to 128 bytes of input data can be buffered.<br />
<br />
The input data for the AES crypto operation is written to AES_WRFIFO, the output data is read from AES_RDFIFO.<br />
<br />
Reading from AES_RDFIFO when there's no data available in the RDFIFO will result in reading the last word that was in the RDFIFO.<br />
<br />
When triggering either RDFIFO or WRFIFO to be flushed, the AES Engine does not clear either buffer.<br />
<br />
Word order and endianness can be changed between each read/write to these FIFOs. However changing the word order when writing to WRFIFO can cause the word to be written outside the current block, leaving uninitialized data in its place. Attempts to change endianness or word order are not honored when reading from RDFIFO when no more data is available.<br />
<br />
== AES_KEYCNT ==<br />
{| class="wikitable" border="1"<br />
! Bit<br />
! Description<br />
|-<br />
| 5-0<br />
| Keyslot<br />
|-<br />
| 6<br />
| Hardware key-generator type: 0 = 3DS, 1 = DSi.<br />
|-<br />
| 7<br />
| This normally has value 1 written here when updating keys. 0 = disable key FIFO flush, 1 = enable key FIFO flush.<br />
|}<br />
<br />
Bit6 is only used when keyslots >=4 are used, value1 has the same affect as doing key-init with the TWL keyslots. Bit6 is only checked when a keyY was completely written, for when the final-normalkey needs updated via the key-generator. Changing bit6 has no affect on the generated normalkey when writing to this bit immediately after writing the last keyY word.<br />
<br />
== AES_CTR ==<br />
This register specifies the counter (CTR mode), nonce (CCM mode) or the initialization vector (CBC mode) depending on the mode of operation.<br />
For CBC and CTR mode this register takes up the full 16 bytes, but for CCM mode the nonce is only the first 12 bytes.<br />
The AES engine will automatically increment the counter up to the maximum BLKCNT, after which point it must be manually incremented and set again.<br />
<br />
== AES_MAC ==<br />
This register specifies the message authentication code (MAC) for use in CCM mode.<br />
<br />
== AES_KEY0/1/2/3 ==<br />
{| class="wikitable" border="1"<br />
! Byte<br />
! Description<br />
|-<br />
| 0-15<br />
| Normalkey<br />
|-<br />
| 16-31<br />
| KeyX<br />
|-<br />
| 32-47<br />
| KeyY<br />
|-}<br />
<br />
These registers are the same as they were on TWL, and are likely preserved for compatibility reasons. The keyslot is updated immediately after *any* data(u8/u32/...) is written here, which was used on DSi to [[3DS_System_Flaws|break]] the key-generator.<br />
<br />
== Endianness and word order ==<br />
When writing to the AES_CTR, AES_MAC or AES_KEY0/1/2/3 register, the hardware will process the written data according to the current input endianness specified in AES_CNT. However, the current specified input word order will not be honored for this register, and always defaults to reversed word order. Therefore, for normal word order, the reversal must be carried out manually if required.<br />
<br />
== Keyslot ranges ==<br />
This is approximately a table of what is set by bootrom before booting into FIRM. Often it appears that keyslots in groups of 4 have the same keyX, and sometimes also same keyY set.<br />
<br />
{| class="wikitable" border="1"<br />
! Keyslot<br />
! Name<br />
! KeyX<br />
! KeyY/Normal-key<br />
! Console unique.<br />
|-<br />
| 0x00-0x03<br />
| TWL keys.<br />
| Probably unset.<br />
| Probably unset.<br />
| -<br />
|-<br />
| 0x04-0x07<br />
| NAND partition keys.<br />
| Same for all.<br />
| Different for all.<br />
| style="background: green" | Yes<br />
|-<br />
| 0x08-0x0B<br />
| See below.<br />
| Same for all.<br />
| Different for all.<br />
| style="background: green" | Yes<br />
|-<br />
| 0x0C-0x0F<br />
| SSL cert key.<br />
| Same for all.<br />
| Same for all.<br />
| style="background: red" | No<br />
|-<br />
| 0x10-0x17<br />
| -<br />
| Not set.<br />
| Not set.<br />
| -<br />
|-<br />
| 0x18-0x1B<br />
| Never used.<br />
| Same for all.<br />
| Same for all.<br />
| style="background: green" | Yes<br />
|-<br />
| 0x1C-0x1F<br />
| Never used.<br />
| Same for all.<br />
| Same for all.<br />
| style="background: green" | Yes<br />
|-<br />
| 0x20-0x23<br />
| Never used.<br />
| Same for all.<br />
| Same for all.<br />
| style="background: orange" | Normalkey is not. keyX is. keyY unknown.<br />
|-<br />
| 0x24<br />
| Never used.<br />
| Individually set.<br />
| Individually set.<br />
| style="background: orange" | Normalkey is not. keyX is. keyY unknown.<br />
|-<br />
| 0x25-0x27<br />
| -<br />
| Not set.<br />
| Not set.<br />
| -<br />
|-<br />
| 0x28-0x2B<br />
| Never used.<br />
| Individually set.<br />
| Individually set.<br />
| style="background: orange" | Normalkey is not. keyX is. keyY unknown.<br />
|-<br />
| 0x2C-0x2F<br />
| Various uniques.<br />
| Same for all.<br />
| Same for all, probably.<br />
| style="background: red" | No<br />
|-<br />
| 0x30-0x33<br />
| Various uniques.<br />
| Same for all.<br />
| Same for all, probably.<br />
| style="background: red" | No<br />
|-<br />
| 0x34-0x37<br />
| Various uniques.<br />
| Same for all.<br />
| Same for all, probably.<br />
| style="background: red" | No<br />
|-<br />
| 0x38-0x3B<br />
| Various uniques.<br />
| Same for all.<br />
| Different for all.<br />
| style="background: red" | No<br />
|-<br />
| 0x3C-0x3F<br />
| Various uniques.<br />
| Individually set.<br />
| Individually set.<br />
| style="background: red" | No<br />
|}<br />
<br />
Keyslot pairs (0x24, 0x28) and (0x38, 0x3C) shares the same normal-key, while at the same time having different keyX's. This suggests they were set to same normal-key by bootrom.<br />
<br />
== Keyslots ==<br />
There are 0x40 keyslots, each of which stores three keys called keyX, keyY and normalkey. All keys can be set explicitly, but the normalkey can optionally be generated using a hardware key generator instead (see [[#Hardware_key_generator|below]]). There is no way to read the contents of a keyslot.<br />
<br />
{| class="wikitable" border="1"<br />
! Keyslot<br />
! Description<br />
! KeyX set by<br />
! KeyY set by<br />
! Normal-key<br />
! Old3DS<br />
|-<br />
| 0x00-0x03<br />
| TWL keys.<br />
| NATIVE_FIRM hard-boot.<br />
| NATIVE_FIRM hard-boot.<br />
| -<br />
| Yes<br />
|-<br />
| 0x04..0x07<br />
| [[Flash_Filesystem|NAND]] partition keys.<br />
<br />
Keyslot is determined by [[NCSD]] partition FS type and encryption type. <br />
The New3DS Process9 sets the keyY for keyslot 0x05 (New3DS CTRNAND) to a key from .(ro)data. Its keyX is console-unique and set by the bootloader.<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x0A<br />
| DSiWare export key.<br />
<br />
Used for encrypting the all-zero 0x10-byte block in the [[DSiWare_Exports|DSiWare_Exports]] header. Console-unique.<br />
| See above keyslot info.<br />
| See above keyslot info.<br />
| -<br />
| Yes<br />
|-<br />
| 0x0B<br />
| This is console-unique. This keyslot is used for the NAND [[Title_Database|dbs]] images AESMACs, and the [[Nand/private/movable.sed]] AESMAC(when used).<br />
| See above keyslot info.<br />
| See above keyslot info.<br />
| -<br />
| Yes<br />
|-<br />
| 0x0D<br />
| SSL-certificate key.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| -<br />
| -<br />
| Bootrom.<br />
| Yes<br />
|-<br />
| 0x11<br />
| Temporary keyslot.<br />
<br />
Used by FIRM for general normal-key crypto. Also used by the New3DS [[FIRM]] arm9 binary loader.<br />
| Arm9Loader. <br />
| Arm9Loader.<br />
| NATIVE_FIRM.<br />
| Yes<br />
|-<br />
| 0x14<br />
| Starting with [[5.0.0-11]], NATIVE_FIRM Process9 now sets the keyY for this to the same one it uses for initializing 3 of the keyslots' keyYs from [[PSPXI:EncryptDecryptAes|here]].<br />
| Bootrom.<br />
| NATIVE_FIRM boot.<br />
| -<br />
| Yes<br />
|-<br />
| 0x15<br />
| Used/initialized by the New3DS arm9 binary loader, see [[FIRM|here]].<br />
| Arm9Loader.<br />
| Arm9Loader.<br />
| See previous info for this keyslot.<br />
| No<br />
|-<br />
| 0x16<br />
| Used/initialized by the New3DS arm9 binary loader starting with [[9.5.0-22|9.5.0-X]], see [[FIRM|here]].<br />
| Arm9Loader.<br />
| Arm9Loader.<br />
| See previous info for this keyslot.<br />
| No<br />
|-<br />
| 0x18..0x1F<br />
| These are the New3DS keyslots, where the keyX is generated with keyslot 0x11 by the New3DS arm9 binary [[FIRM|loader]]. As of [[FIRM]] [[9.6.0-24|9.6.0-X]] keyslots 0x1C..0x1F are not yet used by Process9.<br />
| Arm9Loader.<br />
| NATIVE_FIRM / see previous info for these keyslots.<br />
| See previous info for these keyslots.<br />
| No<br />
|-<br />
| 0x18<br />
| New3DS [[9.3.0-21|9.3.0-X]] [[NCCH]] key, when ncchflag[3] is 0x0A.<br />
| Arm9Loader.<br />
| NATIVE_FIRM<br />
| -<br />
| No<br />
|-<br />
| 0x19<br />
| New3DS gamecard [[Savegames|savedata]] AES-MAC key.<br />
<br />
Equivalent of keyslot 0x33, used when a [[NCSD]] flag is set to a certain value (implemented with [[9.3.0-21|9.3.0-X]]).<br />
| Arm9Loader.<br />
| NATIVE_FIRM<br />
| -<br />
| No<br />
|-<br />
| 0x1A<br />
| New3DS gamecard [[Savegames|savedata]] actual key.<br />
<br />
Equivalent of keyslot 0x37, used when a [[NCSD]] flag is set to a certain value (implemented with [[9.3.0-21|9.3.0-X]]).<br />
| Arm9Loader.<br />
| NATIVE_FIRM<br />
| -<br />
| No<br />
|-<br />
| 0x1B<br />
| New3DS [[9.6.0-24|9.6.0-X]] [[NCCH]] key, when ncchflag[3] is 0x0B.<br />
| Arm9Loader.<br />
| NATIVE_FIRM<br />
| -<br />
| No<br />
|-<br />
| 0x24<br />
| AGB_FIRM savegame AES-MAC key.<br />
| Bootrom.<br />
| AGB/NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x25<br />
| [[7.0.0-13|v7.0]] [[NCCH]] key, when ncchflag[3] is 0x01.<br />
| NATIVE_FIRM [[Savegames#6.0.0-11_Savegame_keyY|boot]].<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x2C<br />
| Original [[NCCH|NCCH]] key, when ncchflag[3] is 0x00 and always for certain NCCH sections.<br />
| Bootrom.<br />
| Process9.<br />
| -<br />
| Yes<br />
|-<br />
| 0x2D<br />
| UDS local-WLAN CCMP key.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x2E<br />
| Streetpass key.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x2F<br />
| [[Savegames#6.0.0-11_Savegame_keyY|v6.0]] save key.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x30<br />
| SD/NAND AES-MAC key.<br />
<br />
This keyY is initialized via [[Nand/private/movable.sed|movable.sed]]. This is used for calculating the AESMACs under SD [[SD_Filesystem|/Nintendo 3DS/<ID0>/<ID1>/]] (except [[DSiWare_Exports]]) and [[Flash_Filesystem|NAND]] /data/.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x31<br />
| APT wrap key.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]]. NATIVE_FIRM sets this keyY to the same one used for keyslot 0x2E.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x32<br />
| Unknown.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x33<br />
| Gamecard [[Savegames|savedata]] AES-MAC.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x34<br />
| SD key.<br />
<br />
This keyY is initialized via [[Nand/private/movable.sed|movable.sed]]. This is used for encrypting *all* SD card data under [[SD_Filesystem|/Nintendo 3DS/<ID0>/<ID1>/]].<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x35<br />
| Movable.sed key.<br />
<br />
This is the keyslot used for movable.sed encryption + AES-MAC with the import/export [[FSPXI:ImportIntegrityVerificationSeed|commands]].<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x36<br />
| Unknown. Used by friends module.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x37<br />
| Gamecard [[Savegames|savedata]] actual key.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x38<br />
| BOSS key.<br />
<br />
See [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]].<br />
| Bootrom.<br />
| Bootrom.<br />
| -<br />
| Yes<br />
|-<br />
| 0x39<br />
| Download Play key, and the actual NFC key for generating retail [[Amiibo]] keys.<br />
<br />
This keyslot is used for two different keys. Both are available via [[PSPXI:EncryptDecryptAes|EncryptDecryptAes]]. NATIVE_FIRM sets this keyY to the same one used for keyslot 0x2E.<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x3A<br />
| DSiWare export key.<br />
<br />
This keyY is initialized via [[Nand/private/movable.sed|movable.sed]]. This is used for calculating the AESMACs for SD [[DSiWare_Exports]].<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x3B<br />
| [[CTRCARD_Registers#CTRCARD_SECSEED|CTR-CARD hardware-crypto seed]] decryption key.<br />
<br />
AES-CCM is used, the keyY, nonce and MAC are stored in the [[NCSD#Card_Info_Header|Card Info Header]].<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|-<br />
| 0x3D<br />
| Common key.<br />
<br />
Used to decrypt title keys in [[Ticket]].<br />
| Bootrom.<br />
| NATIVE_FIRM.<br />
| -<br />
| Yes<br />
|}<br />
<br />
=== Updating keydata ===<br />
The contents of the keyslot specified in AES_KEYCNT can be updated by consecutively writing four words to AES_KEYXFIFO (keyX), AES_KEYYFIFO(keyY), or AES_KEYFIFO (normalkey).<br />
<br />
After writing to a keyslot, the keyslot must be selected again(write AES_KEYSEL + set AES_CNT bit26), even when writing to the same keyslot. Writing the last word to a key FIFO immediately after selecting a keyslot will not affect the keyslot keydata that gets used at that time, the new keydata will not get used until the keyslot gets selected again.<br />
<br />
Writing to the key FIFOs with byte writes results in the AES engine converting the byte to a word for setting the key word, with this: word = (byteval) | (byteval<<8) | (byteval<<16) | (byteval<<24). The result is the same regardless of which FIFO register byte was written to.<br />
<br />
The TWL keyslots 0x00-0x03 can be set directly by writing to the AES_KEY0-AES_KEY3 registers.<br />
<br />
The key FIFOs can be written simultaneously. For example, executing the following will result in the keyX and keyY being set to all-zero(unknown for normalkey): memset(0x10009100, 0, 0x100);<br />
<br />
Each key FIFO has a 0x10-byte tmp-buffer for storing the words written to that FIFO. Once the last word is written to a key FIFO, the filled tmp-buffer is then written to the key-data for the keyslot selected by AES_KEYCNT at the time the last word was written.<br />
<br />
=== Hardware key generator ===<br />
A dedicated hardware key generator can be used to generate a keyslot's normal-key from its keyX and keyY. The hardware key generator is triggered by writing the keyY, which is the only way to trigger it with the 3DS keyslots.<br />
<br />
The algorithm for generating the normal-key from keyX and keyY is as follows, in big-endian 128-bit unsigned wraparound arithmetic:<br />
<br />
{| class="wikitable" border="1"<br />
! Mode<br />
! Formula<br />
|-<br />
| 3DS<br />
| NormalKey = (((KeyX ROL 2) XOR KeyY) + C1) ROR 41<br />
|-<br />
| DSi<br />
| NormalKey = ((KeyX XOR KeyY) + C2) ROL 42<br />
|}<br />
<br />
Unless noted otherwise, all keyslots on retail units use the hardware key generator.<br />
<br />
=== FIRM-launch key clearing ===<br />
Starting with [[9.0.0-20]] the Process9 FIRM-launch code now "clears" the following AES keyslots, with certain keydata by writing the normal-key: 0x15 and 0x18-0x20. These are the keyslots used by the New3DS [[FIRM]] arm9bin loader(minus keyslot 0x11), the New3DS Process9 does this too.</div>Windwakrhttps://www.3dbrew.org/w/index.php?title=EShop&diff=14277EShop2015-10-23T02:27:26Z<p>Windwakr: </p>
<hr />
<div>The Nintendo 3DS eShop was added in the June 2011 update for JP/EUR/USA.<br />
<br />
From here, you can download Virtual Console games, 3D Classics, DSiware software, view screenshots, and 3D trailers for upcoming 3DS titles.<br />
<br />
While eShop is loading, eShop will use command [[NIMS:CheckSysupdateAvailableSOAP]]. If a system update is available where title installation for system titles still needs finalized (or when the updated titles were not downloaded at all), eShop will then display the "system update is available" message.<br />
<br />
The eShop application uses command [[AMNet:FinishInstallToMedia]] to finalize the SD title install (if the whole title is downloaded while eShop is still running), however, before using that command the eShop application also uses [[AMNet:FinishInstallToMedia]] to finalize installing all system titles (from system updates).<br />
<br />
== eShop QR Codes ==<br />
eShop QR Codes can be scanned with the camera, allowing one to quickly navigate to the desired eShop title with just two clicks. The QR Codes themselves is a simple text/url QR, started with "ESHOP://" string followed by a decimal eShop content link id(same IDs used internally by eShop for all content) and then some special data, delimited by a dot symbol, which can be ommited.<br />
<br />
In order for the QR-code string data to be valid for eShop, it must begin with "ESHOP://5", with the first ID being all decimal.<br />
<br />
{| class="wikitable"<br />
|-<br />
! QR Code source<br />
! Region<br />
! Title<br />
! Serial<br />
! Title ID<br />
|-<br />
| ESHOP://50010000000201.PEAALL000000 || EUR || Nintendogs & Cats Demo || ADA/B/C || 0004000200030c01<br />
|-<br />
| ESHOP://50010000007870.PEAALL000000 || EUR || Crush 3D || A??P || 00040002<br />
|-<br />
| ESHOP://50010000008009.PEAALL000000 || EUR || Resident Evil Revelations Demo || ABRE || 000400020005ee01<br />
|-<br />
| ESHOP://50010000008123.J00101Z00095 || JPN || Rhythm Thief And The Emperor's Treasure Demo || ARTJ || 00040002<br />
|-<br />
| ESHOP://50010000008404.PEAALL000000 || EUR || Mario And Sonic At The London 2012 Olympic Games Demo || ACMP [http://mediacontent.nintendo-europe.com/NOE/images/game_content/ACMP-MarioAndSonicAtTheLondon2012OlympicGames-QRCode-EA_ALL_000_001.bmp] || 00040002<br />
|-<br />
| ESHOP://50010000008447.J00101Z00094 || JPN || Resident Evil Revelations Demo || ABRJ || 00040002<br />
|-<br />
| ESHOP://50010000008449.J00101Z00082 || JPN || Swapnote || JFRJ ||?<br />
|-<br />
| ESHOP://50010000008561 || USA || Swapnote || JFRE || 0004000000051700<br />
|-<br />
| ESHOP://50010000008647.J00101Z00096 || JPN || Metal Gear Solid Snake Eater 3D Demo || AMGJ || 0004000200048101<br />
|-<br />
| ESHOP://50010000008648.J00101Z00097 || JPN || Theatrythm Final Fantasy || ATHJ ||?<br />
|-<br />
| ESHOP://50010000008782.PEAALL000000 || EUR || Metal Gear Solid Snake Eater 3D Demo || AMGE || 0004000200082401<br />
|-<br />
| ESHOP://50010000008842.PEAALL000000 || EUR || Rhythm Thief And The Emperor's Treasure Demo || ARTP [http://mediacontent.nintendo-europe.com/NOE/images/game_content/ARTP-RhythmThief_TheEmperorsTreasure-QRCode-EA_ALL_000_001.bmp] || 00040002<br />
|-<br />
| ESHOP://50010000009084.J00101Z00121 || JPN || Hatsune Miku And Future Stars: Project Mirai Demo || AM9J || 00040002<br />
|-<br />
| ESHOP://50010000009102.J00101Z00106 || JPN || Denpa Ningen RPG || JD8J ||?<br />
|-<br />
| ESHOP://50010000009161.J00101Z00118 || JPN || Dillon's Rolling Western || JAMJ || 00040000<br />
|-<br />
| ESHOP://50010000009261 || USA || Dillon's Rolling Western || JAME? || 00040000<br />
|-<br />
| ESHOP://50010000009401.J00101Z00120 || JPN || Kingdom Hearts 3D Video Download || JZ8J ||?<br />
|-<br />
| ESHOP://50010000009403.J00101Z00119 || JPN || DQM 3D Video Download || JZ7J ||?<br />
|-<br />
| ESHOP://50010000009575.PEAALL000000 || EUR || Kid Icarus: Of Myths And Monsters (Virtual Console) ||? ||?<br />
|-<br />
| ESHOP://50010000009846 || USA || Ketzal's Corridors ||? ||?<br />
|}<br />
<br />
* New QR Code for Japanese "Photos with Super Mario" has a different code string: ESHOP://50010000013120.J00108Z00001.CD588EAE95A3A68D15C647DA2AC0945FD88F70AB8A31149E51C4B05FB927B0B8<br />
<br />
* There is a link in the Japanese eShop <nowiki>[http://www.nintendo.co.jp/3ds/eshop/qrCode.html?####]</nowiki> where you can replace the #### with the Japanese eShop title's serial and you will get it's QR code. (i.e. http://www.nintendo.co.jp/3ds/eshop/qrCode.html?jcaj will get you the pushmo QR code)<br />
<br />
* You could use Google's Chart API to create a QR code from the codes above: https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=ESHOP (replace the ESHOP text with the ESHOP:// link from one of the above)<br />
<br />
== NS eShop application parameters ==<br />
This section describes the 0x1C-byte structure stored at the application parameters from [[APT:StartApplication]], under the 0x300-byte buffer listed there.<br />
<br />
{| class="wikitable"<br />
|-<br />
! Offset<br />
! Size<br />
! Description<br />
|-<br />
| 0x0<br />
| 0x4<br />
| Unknown, usually 0x3?<br />
|-<br />
| 0x4<br />
| 0x4<br />
| Unknown, usually 0x0?<br />
|-<br />
| 0x8<br />
| 0x8<br />
| u64 binary eShop content ID, same ID from the first string in eShop QR-codes except in binary form.<br />
|-<br />
| 0x10<br />
| 0x10<br />
| This is the last string from the QR-code(if any), no NUL-termination.<br />
|}<br />
<br />
== ExtData ==<br />
The ExtData [[Extdata#Filesystem|File System]] for eShop is as follows:<br />
<br />
root<br />
├── icon<br />
├── boss<br />
│ └── TIGER100.tmp<br />
└── user<br />
<br />
{| class="wikitable" border="1"<br />
|-<br />
! File<br />
! Details<br />
! Size<br />
! Firmware Introduced<br />
! Plain text<br />
|-<br />
| icon<br />
| Duplicate from application ExeFS. Always image 00000002<br />
| 0x36C0 Bytes<br />
| [[2.0.0-2]]<br />
| [https://dl.dropboxusercontent.com/u/60710927/CTR/Sample/eShopExtdata/icon Download_EUR]<br />
|-<br />
| TIGER100.tmp<br />
| Always image 00000003.<br />
| 0xCE47 bytes (varies?)<br />
| [[2.0.0-2]]<br />
| <br />
|}<br />
<br />
== Music ==<br />
The eShop pulls its music from a static, region-specific link in a format similar to the following: <br />
<br />
https:// a248.e.akamai.net/f/248/103046/10m/npdl.c.app.nintendowifi.net/p01/nsa/CtfKXACbUPl8s7lk/BGM1/US_BGM1 ,<br />
where region is one of the primary system regions (JP, US, EU, KR, etc.) Support also exists for 'BGM2', but this seems to be unused.<br />
The music is held in a [[SpotPass|BOSS]] container. <br />
<br />
The format consists of a brief XML header describing the audio (including the date it was set as the main eShop theme, loop times, size, etc) followed by a raw AAC stream. Tools such as FFmpeg can handle rebuilding this stream with ADTS headers for proper time info and such.<br />
<br />
The [[Home_Menu|Home Menu]] uses nearly the same format for the Theme Shop's background music.<br />
<br />
== URLs ==<br />
<br />
eShop uses the following domains over HTTPS:<br />
<br />
* cp3s-auth.c.shop.nintendowifi.net<br />
* a248.e.akamai.net<br />
* ninja.ctr.shop.nintendo.net<br />
* samurai.ctr.shop.nintendo.net<br />
* ccif.ctr.shop.nintendo.net<br />
* eou.c.shop.nintendowifi.net<br />
<br />
These domains are used by [[NIM_Services|NIM]]:<br />
<br />
* nus.c.shop.nintendowifi.net<br />
* ecs.c.shop.nintendowifi.net<br />
* cas.c.shop.nintendowifi.net<br />
<br />
ninja.ctr.shop.nintendo.net and samurai.ctr.shop.nintendo.net contain the bulk of the eShop information.<br />
<br />
=== Common Parameters to ninja and samurai ===<br />
<br />
For every request to the ninja and samurai servers, three parameters are always sent, though are not necessarily required:<br />
<br />
{| class="wikitable" border="1"<br />
|-<br />
! Parameter<br />
! Required<br />
! Description<br />
! Type<br />
! Normal value<br />
|-<br />
| shop_id<br />
| depends on the URL, usually no<br />
| Describes which eShop instance should be used. 1 indicates the 3DS eShop, 2 indicates the Wii U eShop. 3 seems to yield the same results as 2. Values greater than 3 or less than 1 are invalid. Defaults to 2 or 3 if not given.<br />
| unsigned integer<br />
| 1<br />
|-<br />
| lang<br />
| no<br />
| Describes the language. Seems to be an ISO 639-1 code in lower case. Every eShop region has a default language that is used if this parameter is not given. Some regions have multiple languages, such as CA (en and fr).<br />
| string (two characters)<br />
| depends on region and eShop settings; for US: en<br />
|-<br />
| _type<br />
| no<br />
| Describes whether the client wants to receive JSON or XML. This parameter seems actually unused and the servers always return XML.<br />
| string<br />
| json<br />
|}<br />
<br />
=== samurai ===<br />
<br />
samurai.ctr.shop.nintendo.net (samurai) provides metadata about titles. The samurai server provides the backend for the eShop title search.<br />
<br />
Common parameters described above can always be sent.<br />
<br />
{| class="wikitable" border="1"<br />
|-<br />
! Path<br />
! Description<br />
! Parameters<br />
|-<br />
| /samurai/ws/'''region'''/titles<br />
| Fetches the title list, containing the content id (not the 3DS title id), the product code and the localized title name<br />
| All of these are optional.<br />
* genre[]: genre ID (unsigned int)<br />
* publisher[]: publisher ID (unsigned int)<br />
* price_min: minimum price in region currency (signed int)<br />
* price_max: maximum price in region currency (signed int)<br />
* video_format: "moflex"<br />
* freeword: keyword(s?) to look for (string)<br />
* limit: maximum results<br />
* offset: results to skip<br />
* sort: one of "new", "popular" or "score"<br />
* release_date_before: date/time title must have been released before (UNIX timestamp prefixed by +)<br />
* release_date_after: date/time title must have been released after (UNIX timestamp prefixed by -)<br />
|-<br />
| /samurai/ws/'''region'''/news<br />
| eShop news section<br />
| (none)<br />
|-<br />
| /samurai/ws/'''region'''/telops<br />
| Some kind of news?<br />
| shop_id is required<br />
|-<br />
| /samurai/ws/'''region'''/directory/'''(long long unsigned int)''' and /samurai/ws/'''region'''/directory/~'''(string)'''<br />
| (unknown)<br />
| (unknown)<br />
|-<br />
| /samurai/ws/'''region'''/title/'''content id'''<br />
| Returns information about the title, more verbose than /titles.<br />
| (none)<br />
|-<br />
| /samurai/ws/'''region'''/contents<br />
| Seems identical to /titles.<br />
| see /titles<br />
|-<br />
| /samurai/ws/'''region'''/genres<br />
| Returns a list of human-readable genre names and their corresponding genre id.<br />
| (none)<br />
|-<br />
| /samurai/ws/'''region'''/publishers<br />
| Returns a list of human-readable publisher names and their corresponding publisher id.<br />
| (none)<br />
|-<br />
| /samurai/ws/'''region'''/title/'''content id'''/aocs<br />
| Returns a list of add-on contents/downloadable content and prices in eShop region currency.<br />
| (none)<br />
|}<br />
<br />
=== ninja ===<br />
<br />
ninja.ctr.shop.nintendo.net (ninja) contains the seeds for the new 9.6 crypto, pricing information and handles actions that require authentication, such as purchases. Authentication information seems to be obtained from the [[ACT_Services|act:u sysmodule]] and works through OAuth2.<br />
<br />
{| class="wikitable" border="1"<br />
|-<br />
! Path<br />
! Description<br />
! Parameters<br />
|-<br />
| /ninja/ws/'''region'''/title/'''content id'''/ec_info<br />
| Contains information about the title. Such as title id, content size, and if available, the 9.6 crypto seed<br />
| (none)<br />
|-<br />
| /ninja/ws/titles/id_pair<br />
| Provides the content id for the given title id, or vice versa.<br />
| title_id[] or ns_uid[] is required.<br />
|-<br />
| /ninja/ws/'''region'''/tax_locations<br />
| Provides the tax location ID<br />
| postal_code is required.<br />
|-<br />
| /ninja/ws/service_hosts<br />
| Provides CCIF and Samurai servers<br />
| country and shop_id is required.<br />
|-<br />
| /ninja/ws/country/'''region'''<br />
| Various eshop related information for a given region<br />
| (none)<br />
|-<br />
| /ninja/ws/country/'''region'''/replenish_amounts<br />
| Provides the amounts of money you can replenish to your account.<br />
| (none)<br />
|}</div>Windwakrhttps://www.3dbrew.org/w/index.php?title=EShop&diff=14065EShop2015-10-19T00:02:19Z<p>Windwakr: </p>
<hr />
<div>The Nintendo 3DS eShop was added in the June 2011 update for JP/EUR/USA.<br />
<br />
From here, you can download Virtual Console games, 3D Classics, DSiware software, view screenshots, and 3D trailers for upcoming 3DS titles.<br />
<br />
While eShop is loading, eShop will use command [[NIMS:CheckSysupdateAvailableSOAP]]. If a system update is available where title installation for system titles still needs finalized (or when the updated titles were not downloaded at all), eShop will then display the "system update is available" message.<br />
<br />
The eShop application uses command [[AMNet:FinishInstallToMedia]] to finalize the SD title install (if the whole title is downloaded while eShop is still running), however, before using that command the eShop application also uses [[AMNet:FinishInstallToMedia]] to finalize installing all system titles (from system updates).<br />
<br />
== eShop QR Codes ==<br />
eShop QR Codes can be scanned with the camera, allowing one to quickly navigate to the desired eShop title with just two clicks. The QR Codes themselves is a simple text/url QR, started with "ESHOP://" string followed by a decimal eShop content link id(same IDs used internally by eShop for all content) and then some special data, delimited by a dot symbol, which can be ommited.<br />
<br />
In order for the QR-code string data to be valid for eShop, it must begin with "ESHOP://5", with the first ID being all decimal.<br />
<br />
{| class="wikitable"<br />
|-<br />
! QR Code source<br />
! Region<br />
! Title<br />
! Serial<br />
! Title ID<br />
|-<br />
| ESHOP://50010000000201.PEAALL000000 || EUR || Nintendogs & Cats Demo || ADA/B/C || 0004000200030c01<br />
|-<br />
| ESHOP://50010000007870.PEAALL000000 || EUR || Crush 3D || A??P || 00040002<br />
|-<br />
| ESHOP://50010000008009.PEAALL000000 || EUR || Resident Evil Revelations Demo || ABRE || 000400020005ee01<br />
|-<br />
| ESHOP://50010000008123.J00101Z00095 || JPN || Rhythm Thief And The Emperor's Treasure Demo || ARTJ || 00040002<br />
|-<br />
| ESHOP://50010000008404.PEAALL000000 || EUR || Mario And Sonic At The London 2012 Olympic Games Demo || ACMP [http://mediacontent.nintendo-europe.com/NOE/images/game_content/ACMP-MarioAndSonicAtTheLondon2012OlympicGames-QRCode-EA_ALL_000_001.bmp] || 00040002<br />
|-<br />
| ESHOP://50010000008447.J00101Z00094 || JPN || Resident Evil Revelations Demo || ABRJ || 00040002<br />
|-<br />
| ESHOP://50010000008449.J00101Z00082 || JPN || Swapnote || JFRJ ||?<br />
|-<br />
| ESHOP://50010000008561 || USA || Swapnote || JFRE || 0004000000051700<br />
|-<br />
| ESHOP://50010000008647.J00101Z00096 || JPN || Metal Gear Solid Snake Eater 3D Demo || AMGJ || 0004000200048101<br />
|-<br />
| ESHOP://50010000008648.J00101Z00097 || JPN || Theatrythm Final Fantasy || ATHJ ||?<br />
|-<br />
| ESHOP://50010000008782.PEAALL000000 || EUR || Metal Gear Solid Snake Eater 3D Demo || AMGE || 0004000200082401<br />
|-<br />
| ESHOP://50010000008842.PEAALL000000 || EUR || Rhythm Thief And The Emperor's Treasure Demo || ARTP [http://mediacontent.nintendo-europe.com/NOE/images/game_content/ARTP-RhythmThief_TheEmperorsTreasure-QRCode-EA_ALL_000_001.bmp] || 00040002<br />
|-<br />
| ESHOP://50010000009084.J00101Z00121 || JPN || Hatsune Miku And Future Stars: Project Mirai Demo || AM9J || 00040002<br />
|-<br />
| ESHOP://50010000009102.J00101Z00106 || JPN || Denpa Ningen RPG || JD8J ||?<br />
|-<br />
| ESHOP://50010000009161.J00101Z00118 || JPN || Dillon's Rolling Western || JAMJ || 00040000<br />
|-<br />
| ESHOP://50010000009261 || USA || Dillon's Rolling Western || JAME? || 00040000<br />
|-<br />
| ESHOP://50010000009401.J00101Z00120 || JPN || Kingdom Hearts 3D Video Download || JZ8J ||?<br />
|-<br />
| ESHOP://50010000009403.J00101Z00119 || JPN || DQM 3D Video Download || JZ7J ||?<br />
|-<br />
| ESHOP://50010000009575.PEAALL000000 || EUR || Kid Icarus: Of Myths And Monsters (Virtual Console) ||? ||?<br />
|-<br />
| ESHOP://50010000009846 || USA || Ketzal's Corridors ||? ||?<br />
|}<br />
<br />
* New QR Code for Japanese "Photos with Super Mario" has a different code string: ESHOP://50010000013120.J00108Z00001.CD588EAE95A3A68D15C647DA2AC0945FD88F70AB8A31149E51C4B05FB927B0B8<br />
<br />
* There is a link in the Japanese eShop <nowiki>[http://www.nintendo.co.jp/3ds/eshop/qrCode.html?####]</nowiki> where you can replace the #### with the Japanese eShop title's serial and you will get it's QR code. (i.e. http://www.nintendo.co.jp/3ds/eshop/qrCode.html?jcaj will get you the pushmo QR code)<br />
<br />
* You could use Google's Chart API to create a QR code from the codes above: https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=ESHOP (replace the ESHOP text with the ESHOP:// link from one of the above)<br />
<br />
== NS eShop application parameters ==<br />
This section describes the 0x1C-byte structure stored at the application parameters from [[APT:StartApplication]], under the 0x300-byte buffer listed there.<br />
<br />
{| class="wikitable"<br />
|-<br />
! Offset<br />
! Size<br />
! Description<br />
|-<br />
| 0x0<br />
| 0x4<br />
| Unknown, usually 0x3?<br />
|-<br />
| 0x4<br />
| 0x4<br />
| Unknown, usually 0x0?<br />
|-<br />
| 0x8<br />
| 0x8<br />
| u64 binary eShop content ID, same ID from the first string in eShop QR-codes except in binary form.<br />
|-<br />
| 0x10<br />
| 0x10<br />
| This is the last string from the QR-code(if any), no NUL-termination.<br />
|}<br />
<br />
== ExtData ==<br />
The ExtData [[Extdata#Filesystem|File System]] for eShop is as follows:<br />
<br />
root<br />
├── icon<br />
├── boss<br />
│ └── TIGER100.tmp<br />
└── user<br />
<br />
{| class="wikitable" border="1"<br />
|-<br />
! File<br />
! Details<br />
! Size<br />
! Firmware Introduced<br />
! Plain text<br />
|-<br />
| icon<br />
| Duplicate from application ExeFS. Always image 00000002<br />
| 0x36C0 Bytes<br />
| [[2.0.0-2]]<br />
| [https://dl.dropboxusercontent.com/u/60710927/CTR/Sample/eShopExtdata/icon Download_EUR]<br />
|-<br />
| TIGER100.tmp<br />
| Always image 00000003.<br />
| 0xCE47 bytes (varies?)<br />
| [[2.0.0-2]]<br />
| <br />
|}<br />
<br />
== Music ==<br />
The eShop pulls its music from a static, region-specific link in a format similar to the following: <br />
<br />
https:// a248.e.akamai.net/f/248/103046/10m/npdl.c.app.nintendowifi.net/p01/nsa/CtfKXACbUPl8s7lk/BGM1/US_BGM1 ,<br />
where region is one of the primary system regions (JP, US, EU, KR, etc.) Support also exists for 'BGM2', but this seems to be unused.<br />
The music is held in a [[SpotPass|BOSS]] container. <br />
<br />
The format consists of a brief XML header describing the audio (including the date it was set as the main eShop theme, loop times, size, etc) followed by a raw AAC stream. Tools such as FFmpeg can handle rebuilding this stream with ADTS headers for proper time info and such.<br />
<br />
The [[Home_Menu|Home Menu]] uses nearly the same format for the Theme Shop's background music.<br />
<br />
== URLs ==<br />
<br />
eShop uses the following domains over HTTPS:<br />
<br />
* cp3s-auth.c.shop.nintendowifi.net<br />
* a248.e.akamai.net<br />
* ninja.ctr.shop.nintendo.net<br />
* samurai.ctr.shop.nintendo.net<br />
* ccif.ctr.shop.nintendo.net<br />
* eou.c.shop.nintendowifi.net<br />
<br />
These domains are used by [[NIM_Services|NIM]]:<br />
<br />
* nus.c.shop.nintendowifi.net<br />
* ecs.c.shop.nintendowifi.net<br />
* cas.c.shop.nintendowifi.net<br />
<br />
ninja.ctr.shop.nintendo.net and samurai.ctr.shop.nintendo.net contain the bulk of the eShop information.<br />
<br />
=== Common Parameters to ninja and samurai ===<br />
<br />
For every request to the ninja and samurai servers, three parameters are always sent, though are not necessarily required:<br />
<br />
{| class="wikitable" border="1"<br />
|-<br />
! Parameter<br />
! Required<br />
! Description<br />
! Type<br />
! Normal value<br />
|-<br />
| shop_id<br />
| depends on the URL, usually no<br />
| Describes which eShop instance should be used. 1 indicates the 3DS eShop, 2 indicates the Wii U eShop. 3 seems to yield the same results as 2. Values greater than 3 or less than 1 are invalid. Defaults to 2 or 3 if not given.<br />
| unsigned integer<br />
| 1<br />
|-<br />
| lang<br />
| no<br />
| Describes the language. Seems to be an ISO 639-1 code in lower case. Every eShop region has a default language that is used if this parameter is not given. Some regions have multiple languages, such as CA (en and fr).<br />
| string (two characters)<br />
| depends on region and eShop settings; for US: en<br />
|-<br />
| _type<br />
| no<br />
| Describes whether the client wants to receive JSON or XML. This parameter seems actually unused and the servers always return XML.<br />
| string<br />
| json<br />
|}<br />
<br />
=== samurai ===<br />
<br />
samurai.ctr.shop.nintendo.net (samurai) provides metadata about titles. The samurai server provides the backend for the eShop title search.<br />
<br />
Common parameters described above can always be sent.<br />
<br />
{| class="wikitable" border="1"<br />
|-<br />
! Path<br />
! Description<br />
! Parameters<br />
|-<br />
| /samurai/ws/'''region'''/titles<br />
| Fetches the title list, containing the content id (not the 3DS title id), the product code and the localized title name<br />
| All of these are optional.<br />
* genre[]: genre ID (unsigned int)<br />
* publisher[]: publisher ID (unsigned int)<br />
* price_min: minimum price in region currency (signed int)<br />
* price_max: maximum price in region currency (signed int)<br />
* video_format: "moflex"<br />
* freeword: keyword(s?) to look for (string)<br />
* limit: maximum results<br />
* offset: results to skip<br />
* sort: one of "new", "popular" or "score"<br />
* release_date_before: date/time title must have been released before (UNIX timestamp prefixed by +)<br />
* release_date_after: date/time title must have been released after (UNIX timestamp prefixed by -)<br />
|-<br />
| /samurai/ws/'''region'''/news<br />
| eShop news section<br />
| (none)<br />
|-<br />
| /samurai/ws/'''region'''/telops<br />
| Some kind of news?<br />
| shop_id is required<br />
|-<br />
| /samurai/ws/'''region'''/directory/'''(long long unsigned int)''' and /samurai/ws/'''region'''/directory/~'''(string)'''<br />
| (unknown)<br />
| (unknown)<br />
|-<br />
| /samurai/ws/'''region'''/title/'''content id'''<br />
| Returns information about the title, more verbose than /titles.<br />
| (none)<br />
|-<br />
| /samurai/ws/'''region'''/contents<br />
| Seems identical to /titles.<br />
| see /titles<br />
|-<br />
| /samurai/ws/'''region'''/genres<br />
| Returns a list of human-readable genre names and their corresponding genre id.<br />
| (none)<br />
|-<br />
| /samurai/ws/'''region'''/publishers<br />
| Returns a list of human-readable publisher names and their corresponding publisher id.<br />
| (none)<br />
|-<br />
| /samurai/ws/'''region'''/title/'''content id'''/aocs<br />
| Returns a list of add-on contents/downloadable content and prices in eShop region currency.<br />
| (none)<br />
|}<br />
<br />
=== ninja ===<br />
<br />
ninja.ctr.shop.nintendo.net (ninja) contains the seeds for the new 9.6 crypto, pricing information and handles actions that require authentication, such as purchases. Authentication information seems to be obtained from the [[ACT_Services|act:u sysmodule]] and works through OAuth2.<br />
<br />
{| class="wikitable" border="1"<br />
|-<br />
! Path<br />
! Description<br />
! Parameters<br />
|-<br />
| /ninja/ws/'''region'''/title/'''content id'''/ec_info<br />
| Contains information about the title. Such as title id, content size, and if available, the 9.6 crypto seed<br />
| (none)<br />
|-<br />
| /ninja/ws/titles/id_pair<br />
| Provides the content id for the given title id<br />
| title_id[] is required.<br />
|}</div>Windwakrhttps://www.3dbrew.org/w/index.php?title=EShop&diff=14062EShop2015-10-18T20:09:51Z<p>Windwakr: </p>
<hr />
<div>The Nintendo 3DS eShop was added in the June 2011 update for JP/EUR/USA.<br />
<br />
From here, you can download Virtual Console games, 3D Classics, DSiware software, view screenshots, and 3D trailers for upcoming 3DS titles.<br />
<br />
While eShop is loading, eShop will use command [[NIMS:CheckSysupdateAvailableSOAP]]. If a system update is available where title installation for system titles still needs finalized (or when the updated titles were not downloaded at all), eShop will then display the "system update is available" message.<br />
<br />
The eShop application uses command [[AMNet:FinishInstallToMedia]] to finalize the SD title install (if the whole title is downloaded while eShop is still running), however, before using that command the eShop application also uses [[AMNet:FinishInstallToMedia]] to finalize installing all system titles (from system updates).<br />
<br />
== eShop QR Codes ==<br />
eShop QR Codes can be scanned with the camera, allowing one to quickly navigate to the desired eShop title with just two clicks. The QR Codes themselves is a simple text/url QR, started with "ESHOP://" string followed by a decimal eShop content link id(same IDs used internally by eShop for all content) and then some special data, delimited by a dot symbol, which can be ommited.<br />
<br />
In order for the QR-code string data to be valid for eShop, it must begin with "ESHOP://5", with the first ID being all decimal.<br />
<br />
{| class="wikitable"<br />
|-<br />
! QR Code source<br />
! Region<br />
! Title<br />
! Serial<br />
! Title ID<br />
|-<br />
| ESHOP://50010000000201.PEAALL000000 || EUR || Nintendogs & Cats Demo || ADA/B/C || 0004000200030c01<br />
|-<br />
| ESHOP://50010000007870.PEAALL000000 || EUR || Crush 3D || A??P || 00040002<br />
|-<br />
| ESHOP://50010000008009.PEAALL000000 || EUR || Resident Evil Revelations Demo || ABRE || 000400020005ee01<br />
|-<br />
| ESHOP://50010000008123.J00101Z00095 || JPN || Rhythm Thief And The Emperor's Treasure Demo || ARTJ || 00040002<br />
|-<br />
| ESHOP://50010000008404.PEAALL000000 || EUR || Mario And Sonic At The London 2012 Olympic Games Demo || ACMP [http://mediacontent.nintendo-europe.com/NOE/images/game_content/ACMP-MarioAndSonicAtTheLondon2012OlympicGames-QRCode-EA_ALL_000_001.bmp] || 00040002<br />
|-<br />
| ESHOP://50010000008447.J00101Z00094 || JPN || Resident Evil Revelations Demo || ABRJ || 00040002<br />
|-<br />
| ESHOP://50010000008449.J00101Z00082 || JPN || Swapnote || JFRJ ||?<br />
|-<br />
| ESHOP://50010000008561 || USA || Swapnote || JFRE || 0004000000051700<br />
|-<br />
| ESHOP://50010000008647.J00101Z00096 || JPN || Metal Gear Solid Snake Eater 3D Demo || AMGJ || 0004000200048101<br />
|-<br />
| ESHOP://50010000008648.J00101Z00097 || JPN || Theatrythm Final Fantasy || ATHJ ||?<br />
|-<br />
| ESHOP://50010000008782.PEAALL000000 || EUR || Metal Gear Solid Snake Eater 3D Demo || AMGE || 0004000200082401<br />
|-<br />
| ESHOP://50010000008842.PEAALL000000 || EUR || Rhythm Thief And The Emperor's Treasure Demo || ARTP [http://mediacontent.nintendo-europe.com/NOE/images/game_content/ARTP-RhythmThief_TheEmperorsTreasure-QRCode-EA_ALL_000_001.bmp] || 00040002<br />
|-<br />
| ESHOP://50010000009084.J00101Z00121 || JPN || Hatsune Miku And Future Stars: Project Mirai Demo || AM9J || 00040002<br />
|-<br />
| ESHOP://50010000009102.J00101Z00106 || JPN || Denpa Ningen RPG || JD8J ||?<br />
|-<br />
| ESHOP://50010000009161.J00101Z00118 || JPN || Dillon's Rolling Western || JAMJ || 00040000<br />
|-<br />
| ESHOP://50010000009261 || USA || Dillon's Rolling Western || JAME? || 00040000<br />
|-<br />
| ESHOP://50010000009401.J00101Z00120 || JPN || Kingdom Hearts 3D Video Download || JZ8J ||?<br />
|-<br />
| ESHOP://50010000009403.J00101Z00119 || JPN || DQM 3D Video Download || JZ7J ||?<br />
|-<br />
| ESHOP://50010000009575.PEAALL000000 || EUR || Kid Icarus: Of Myths And Monsters (Virtual Console) ||? ||?<br />
|-<br />
| ESHOP://50010000009846 || USA || Ketzal's Corridors ||? ||?<br />
|}<br />
<br />
* New QR Code for Japanese "Photos with Super Mario" has a different code string: ESHOP://50010000013120.J00108Z00001.CD588EAE95A3A68D15C647DA2AC0945FD88F70AB8A31149E51C4B05FB927B0B8<br />
<br />
* There is a link in the Japanese eShop <nowiki>[http://www.nintendo.co.jp/3ds/eshop/qrCode.html?####]</nowiki> where you can replace the #### with the Japanese eShop title's serial and you will get it's QR code. (i.e. http://www.nintendo.co.jp/3ds/eshop/qrCode.html?jcaj will get you the pushmo QR code)<br />
<br />
* You could use Google's Chart API to create a QR code from the codes above: https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=ESHOP (replace the ESHOP text with the ESHOP:// link from one of the above)<br />
<br />
== NS eShop application parameters ==<br />
This section describes the 0x1C-byte structure stored at the application parameters from [[APT:StartApplication]], under the 0x300-byte buffer listed there.<br />
<br />
{| class="wikitable"<br />
|-<br />
! Offset<br />
! Size<br />
! Description<br />
|-<br />
| 0x0<br />
| 0x4<br />
| Unknown, usually 0x3?<br />
|-<br />
| 0x4<br />
| 0x4<br />
| Unknown, usually 0x0?<br />
|-<br />
| 0x8<br />
| 0x8<br />
| u64 binary eShop content ID, same ID from the first string in eShop QR-codes except in binary form.<br />
|-<br />
| 0x10<br />
| 0x10<br />
| This is the last string from the QR-code(if any), no NUL-termination.<br />
|}<br />
<br />
== ExtData ==<br />
The ExtData [[Extdata#Filesystem|File System]] for eShop is as follows:<br />
<br />
root<br />
├── icon<br />
├── boss<br />
│ └── TIGER100.tmp<br />
└── user<br />
<br />
{| class="wikitable" border="1"<br />
|-<br />
! File<br />
! Details<br />
! Size<br />
! Firmware Introduced<br />
! Plain text<br />
|-<br />
| icon<br />
| Duplicate from application ExeFS. Always image 00000002<br />
| 0x36C0 Bytes<br />
| [[2.0.0-2]]<br />
| [https://dl.dropboxusercontent.com/u/60710927/CTR/Sample/eShopExtdata/icon Download_EUR]<br />
|-<br />
| TIGER100.tmp<br />
| Always image 00000003.<br />
| 0xCE47 bytes (varies?)<br />
| [[2.0.0-2]]<br />
| <br />
|}<br />
<br />
== Music ==<br />
The eShop pulls its music from a static, region-specific link in a format similar to the following: <br />
<br />
https:// a248.e.akamai.net/f/248/103046/10m/npdl.c.app.nintendowifi.net/p01/nsa/CtfKXACbUPl8s7lk/BGM1/US_BGM1 ,<br />
where region is one of the primary system regions (JP, US, EU, KR, etc.) Support also exists for 'BGM2', but this seems to be unused.<br />
The music is held in a [[SpotPass|BOSS]] container. <br />
<br />
The format consists of a brief XML header describing the audio (including the date it was set as the main eShop theme, loop times, size, etc) followed by a raw AAC stream. Tools such as FFmpeg can handle rebuilding this stream with ADTS headers for proper time info and such.<br />
<br />
The [[Home_Menu|Home Menu]] uses nearly the same format for the Theme Shop's background music.<br />
<br />
== URLs ==<br />
<br />
eShop uses the following domains over HTTPS:<br />
<br />
* cp3s-auth.c.shop.nintendowifi.net<br />
* a248.e.akamai.net<br />
* ninja.ctr.shop.nintendo.net<br />
* samurai.ctr.shop.nintendo.net<br />
* ccif.ctr.shop.nintendo.net<br />
* eou.c.shop.nintendowifi.net<br />
<br />
These domains are used by [[NIM_Services|NIM]]:<br />
<br />
* nus.c.shop.nintendowifi.net<br />
* ecs.c.shop.nintendowifi.net<br />
* cas.c.shop.nintendowifi.net<br />
<br />
ninja.ctr.shop.nintendo.net and samurai.ctr.shop.nintendo.net contain the bulk of the eShop information.<br />
<br />
=== Common Parameters to ninja and samurai ===<br />
<br />
For every request to the ninja and samurai servers, three parameters are always sent, though are not necessarily required:<br />
<br />
{| class="wikitable" border="1"<br />
|-<br />
! Parameter<br />
! Required<br />
! Description<br />
! Type<br />
! Normal value<br />
|-<br />
| shop_id<br />
| depends on the URL, usually no<br />
| Describes which eShop instance should be used. 1 indicates the 3DS eShop, 2 indicates the Wii U eShop. 3 seems to yield the same results as 2. Values greater than 3 or less than 1 are invalid. Defaults to 2 or 3 if not given.<br />
| unsigned integer<br />
| 1<br />
|-<br />
| lang<br />
| no<br />
| Describes the language. Seems to be an ISO 639-1 code in lower case. Every eShop region has a default language that is used if this parameter is not given. Some regions have multiple languages, such as CA (en and fr).<br />
| string (two characters)<br />
| depends on region and eShop settings; for US: en<br />
|-<br />
| _type<br />
| no<br />
| Describes whether the client wants to receive JSON or XML. This parameter seems actually unused and the servers always return XML.<br />
| string<br />
| json<br />
|}<br />
<br />
=== samurai ===<br />
<br />
samurai.ctr.shop.nintendo.net (samurai) provides metadata about titles. The samurai server provides the backend for the eShop title search.<br />
<br />
Common parameters described above can always be sent.<br />
<br />
{| class="wikitable" border="1"<br />
|-<br />
! Path<br />
! Description<br />
! Parameters<br />
|-<br />
| /samurai/ws/'''region'''/titles<br />
| Fetches the title list, containing the content id (not the 3DS title id), the product code and the localized title name<br />
| All of these are optional.<br />
* genre[]: genre ID (unsigned int)<br />
* publisher[]: publisher ID (unsigned int)<br />
* price_min: minimum price in region currency (signed int)<br />
* price_max: maximum price in region currency (signed int)<br />
* video_format: "moflex"<br />
* freeword: keyword(s?) to look for (string)<br />
* limit: maximum results<br />
* offset: results to skip<br />
* sort: one of "new", "popular" or "score"<br />
* release_date_before: date/time title must have been released before (UNIX timestamp prefixed by +)<br />
* release_date_after: date/time title must have been released after (UNIX timestamp prefixed by -)<br />
|-<br />
| /samurai/ws/'''region'''/news<br />
| eShop news section<br />
| (none)<br />
|-<br />
| /samurai/ws/'''region'''/telops<br />
| Some kind of news?<br />
| shop_id is required<br />
|-<br />
| /samurai/ws/'''region'''/directory/'''(long long unsigned int)''' and /samurai/ws/'''region'''/directory/~'''(string)'''<br />
| (unknown)<br />
| (unknown)<br />
|-<br />
| /samurai/ws/'''region'''/title/'''content id'''<br />
| Returns information about the title, more verbose than /titles.<br />
| (none)<br />
|-<br />
| /samurai/ws/'''region'''/contents<br />
| Seems identical to /titles.<br />
| see /titles<br />
|-<br />
| /samurai/ws/'''region'''/genres<br />
| Returns a list of human-readable genre names and their corresponding genre id.<br />
| (none)<br />
|-<br />
| /samurai/ws/'''region'''/publishers<br />
| Returns a list of human-readable publisher names and their corresponding publisher id.<br />
| (none)<br />
|-<br />
| /samurai/ws/'''region'''/title/'''content id'''/aocs<br />
| Returns a list of add-on contents/downloadable content and prices in eShop region currency.<br />
| (none)<br />
|}<br />
<br />
=== ninja ===<br />
<br />
ninja.ctr.shop.nintendo.net (ninja) contains the seeds for the new 9.6 crypto, pricing information and handles actions that require authentication, such as purchases. Authentication information seems to be obtained from the [[ACT_Services|act:u sysmodule]] and works through OAuth2.<br />
<br />
{| class="wikitable" border="1"<br />
|-<br />
! Path<br />
! Description<br />
! Parameters<br />
|-<br />
| /ninja/ws/'''region'''/title/'''content id'''/ec_info<br />
| Contains information about the title. Such as title id, content size, and if available, the 9.6 crypto seed<br />
| (none)<br />
|}</div>Windwakr