engine
- AES engine tools
The engine
module provides tools to perform cryptographic operations on Nintendo 3DS data, including emulating keyslots and the key scrambler.
Warning
This page is incomplete.
AES engine
The 3DS uses keyslots in an attempt to obscure the encryption keys used. Each slot consists of X, Y, and normal keys.
Often, one slot contains a fixed key (often X), while the other is a key unique to something such as a game or console (often Y). When key Y is set, both keys are put into a key scrambler, and the result is stored as a normal key. The AES engine would then use the result for encryption. A normal key can also be set directly.
The AES engine only has keyslots 0x0 to 0x3F (0 to 63). Keyslots 0x0 to 0x3 are for DSi-mode software, and use the DSi key scrambler. This module uses keyslots above 0x3F for internal use.
CryptoEngine objects
- class pyctr.crypto.engine.CryptoEngine(boot9=None, dev=False, setup_b9_keys=True)[source]
Emulates the AES engine, including keyslots and the key scrambler.
- Parameters:
- create_cbc_cipher(keyslot, iv)[source]
Create an AES-CBC cipher.
- Parameters:
keyslot (Keyslot) – Keyslot to use.
iv (bytes) – Initialization vector.
- Returns:
An AES-CBC cipher object.
- Return type:
CbcMode
- create_ctr_cipher(keyslot, ctr)[source]
Create an AES-CTR cipher.
- Parameters:
keyslot (Keyslot) – Keyslot to use.
ctr (int) – Counter to start with.
- Returns:
An AES-CTR cipher object.
- Return type:
CtrMode | _TWLCryptoWrapper
- create_ecb_cipher(keyslot)[source]
Create an AES-ECB cipher.
- Parameters:
keyslot (Keyslot) – Keyslot to use.
- Returns:
An AES-ECB cipher object.
- Return type:
EcbMode
- create_cmac_object(keyslot)[source]
Create a CMAC object.
- Parameters:
keyslot (Keyslot) – Keyslot to use.
- Returns:
A CMAC object.
- Return type:
CMAC
- create_ctr_io(keyslot, fh, ctr, closefd=False)[source]
Create an AES-CTR read-write file object with the given keyslot.
- create_cbc_io(keyslot, fh, iv, closefd=False)[source]
Create an AES-CBC read-write file object with the given keyslot.
- set_normal_key(keyslot, key)[source]
Set a keyslot’s normal key.
- Parameters:
keyslot (Keyslot) – Keyslot to set.
key (bytes) – Key to set it to.
- update_normal_keys()[source]
Refresh normal keys. This is only required if
set_keyslot()
was called with update_normal_key=False.