Getting the 0x31 normal key yourself
What you need
- Any model of Nintendo 3DS with boot9strap installed and GodMode9 as a boot9strap payload. Installing those is way out of this document scope but is already wonderfully explained step by step in this guide.
- If you have a New Nintendo 3DS model and its firmware is up to date (as of this guide writing: 11.16.0), you're good to go, update it else (or follow the Old 3DS route).
- If you have the older model, we will need to grab the New 3DS 11.16.0 firmware from Nintendo's update server.
The keyscrambler
The Nintendo 3DS contains an AES engine, handling all crypto on the system. This engine can hold keys securely, once written, they cannot be read back. This engine also contains a keyscrambler. It's a clever solution to update keys without allowing hackers to get the key from the update file. Basically, for each key slots, the software can send two keys, called keyX and keyY. The scrambler then mixes them up using an algorithm written in the hardware (so no dump possible) to generate what is called a normal key. This is the key used and there is no way of getting it without knowing the keyX, the keyY and the secret algorithm.
The algorithm
Luckily for us, the algorithm mixing keys is not very good at his job and the marvelous folks who were hacking the 3DS in those golden days managed to guess how it works and presented it back in 2015 at 32c3. Here is it : normalkey = (((keyX <<< 2) ^ keyY) + C) <<< 87
.
That C
is a secret constant written in hardware, so again, no dump possible. But let's rearrange the formula a bit and we get C = normalkey >>> 87 - ((keyX <<< 2) ^ keyY)
. So if we could get a triplet of keyX, keyY and normal key, we could extract the constant from it.
The secret constant
Again from the 32c3 presentation, plutoo teaches us that Nintendo likely rushed the New Nintendo 3DS release and accidentaly included the 0x39 normal key in the firmware 8.1, before replacing it with a keyY in 9.3! And what's even better: 3DS contains a copy of their firmware to boot in recovery mode and this copy is not up to date. Yup, the recovery firmware on 11.14 New 3DS STILL CONTAINS the 0x39 normal key! So we will need to dump the firmware for the keyY and the recovery firmware for the normal key.
Finally, to get the keyX, we need to get the bootrom of the ARM9 processor since the bootrom sets most keyX. I won't get into how this is made possible but it's once again a fantastic story I encourage you to read (more in the credits!). So let's add the ARM9 bootrom to our grocery list.
The 0x31 normal key
This is our final goal, the 0x31 normal key (this key technically is in the Wii U but I did not research nearly enough the Wii U to be bothered trying). This key is what the Nintendo 3DS ultimately uses when reading and generating Mii QR Codes (and many other things). As discussed in the keyscrambler part above, to get a normal key, we will need the 0x31 keyX and keyY. Fortunately, those are found respectively in the ARM9 bootrom and the console firmware, which we already need to find the keyscrambler secret constant.
Downloading the New 3DS recovery firmware
As discussed above, we need one key that is not available in the console you have in your hands. But it's inside a firmware we can easily download straight from Nintendo's servers! Just download this file and that file and place them on your SD card in SD:/gm9/out
. It's encrypted but nothing GodMode9 can't handle in a few buttons presses.
Dumping the keys with GodMode9
Let's get our all those keys now. Open GodMode9 in boot9strap context and follow those instructions:
- Getting 0x31 keyX and 0x39 keyX from the bootrom:
- Go to M:/boot9.bin and press A. Then select
Show in Hexeditor
. - Press X and select
Go to offset
, then enter 0000d9e0. The 16 first bytes your see are the 0x31 keyX! - SHA-256 of the 0x31 keyX : 5C1B1C9C7A29FAA158D62D377859E08EE32D6D3012B57A289A5ED6F72C21F3AC
- Press X and select
Go to offset
, then enter 0000da00. The 16 first bytes your see are the 0x39 keyX! - SHA-256 of the 0x39 keyX : F5242DC69FA0176ADD50ADD2DBDFDD6F2A096BE89E179690B64A5E07D994BE41
- Press B to exit the hexeditor.
- New 3DS 11.16.0 only Dumping the installed firmware:
- Go to 1:/title/00040138/20000002/content/0000003d.app and press A. Then select
NCCH image options... / Mount image to drive
and press A when asked to enterG:
- Go to G:/exefs/.firm and press A. Then select
FIRM image options... / Decrypt file (0:/gm9/out)
and wait for the operation to end. - Old 3DS and non up-to-date New 3DS Decrypting the New 3DS 11.16.0 firmware:
- Go to 0:/gm9/out/0000003d and press A. Then select
Decrypt NUS/CDN file / Decrypt in place
. - Go to 0:/gm9/out/0000003d Then select
NCCH image options... / Mount image to drive
and press A when asked to enterG:
. - Go to G:/exefs/.firm and press A. Then select
FIRM image options... / Decrypt file (0:/gm9/out)
and wait for the operation to end. - Getting 0x31 keyY and 0x39 keyY:
- Go to 0:/gm9/out/.firm and press A. Then select
Show in Hexeditor
. - Press X and select
Go to offset
, then enter 000e6c04. Skip the first 4 bytes and the next 16 your see are the 0x31 keyY! - SHA-256 of the 0x31 keyY : F2C1662DE48D389EED4A6537248145CA754F0830DD08269EBDE47EA92D9C8D34
- Press X and select
Go to offset
, then enter 000e6c24. Skip the first 4 bytes and the next 16 your see are the 0x39 keyY! - SHA-256 of the 0x39 keyY : 16D4E021B37170C716BBBAC4D72A433CFAE66303508BB4E94E8BB03DF24B1826
- Press B to exit the hexeditor.
- New 3DS 11.16.0 only Dumping the recovery firmware:
- Go to 1:/title/00040138/20000003/content/00000002.app and press A. Then select
NCCH image options... / Mount image to drive
and press A when asked to enterG:
. - Go to G:/exefs/.firm and press A. Then select
FIRM image options... / Decrypt file (0:/gm9/out)
and wait for the operation to end. - Old 3DS and non up-to-date New 3DS Decrypting the New 3DS recovery firmware:
- Go to 0:/gm9/out/00000002 and press A. Then select
Decrypt NUS/CDN file / Decrypt in place
. - Go to 0:/gm9/out/00000002 Then select
NCCH image options... / Mount image to drive
and press A when asked to enterG:
. - Go to G:/exefs/.firm and press A. Then select
FIRM image options... / Decrypt file (0:/gm9/out)
and wait for the operation to end. - Getting 0x39 normal key:
- Go to 0:/gm9/out/.firm and press A. Then select
Show in Hexeditor
. - Press X and select
Go to offset
, then enter 000e55e0. The 16 first bytes your see are the 0x39 normal key! - SHA-256 of the 0x39 normal key : 68280A228EC5D5ED3BC66ABA304F3891B62CB2DFAB6607235CF622AA8DE5A9B4
- Press B to exit the hexeditor.
Getting the constant
Apply the following formula using your preffered method of dealing with very large numbers or use this tool I made and fill the Constant
form.
normalkey_0x39 >>> 87 - ((keyX_0x39 <<< 2) ^ keyY_0x39)
SHA-256 of the secret constant : 05D6564396705F79890A12CD05DD914B0ADC01CCAA4D5158A90BB32553025997
Getting the 0x31 normal key
Finally, apply the following formula using your preffered method of dealing with very large numbers or use this tool I made and fill the Normal key
form.
(((keyX_0x31 <<< 2) ^ keyY_0x31) + secret_constant) <<< 87
SHA-256 of the 0x31 normal key : A2E6468B41CFA903988D4BC89BE0C1CD8AB52A23A3E15361AA1C1ADCE6C9F953
Credits
Many thanks to the wonderful folks that made all of this possible! I'm sorry for not naming everyone here, especially after many years far from the scene but feel free to request additions and corrections at this email.
- smealum, derrek and plutoo for their 32c3 talk, Breaking the 3DS which you absolutely should watch if you want a more technical explanation of the nonsense above and how the keyscrambler algorithm was reversed.
- d0k3 for GodMode9, along with all the contributors to the best tool ever made for the 3DS still getting a large update in 2021 for its 5th anniversary.
- SciresM for his Sighax and boot9strap 33.5c3 presentation, I cannot encourage enough curious people to read about sighax.
- Plailect for the amazing homebrew guide and all the subsequent mainteners. Video guides are bad!
- AuroraWright and TuxSH for the incredible Luma3DS that brought unity and stability for the CFW scene.
- Every single person reversing, testing, contributing to code or documentation, making guides... You made the 3DS hacking scene.
- emn178 for their hex to SHA-256 hash tool.