Skip to content

Commit

Permalink
Merge pull request #117 from 3DSGuy/ctrtool-cci-initialdata-fix
Browse files Browse the repository at this point in the history
Fix bug where CCI CryptoType 1-2 weren't processed properly.
  • Loading branch information
jakcron committed Apr 11, 2022
2 parents 8876f0e + 5c584f4 commit 5840526
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion ctrtool/deps/libnintendo-n3ds/include/ntd/n3ds/cci.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ struct CciHeader

enum CryptoType
{
CryptoType_Secure = 0, // Secure initial data key (keyX bootrom, keyY initial data seed) (used in production ROMs)
CryptoType_Secure0 = 0, // Secure initial data key (keyX bootrom, keyY initial data seed) (used in production ROMs)
CryptoType_Secure1 = 1, // Secure initial data key (keyX bootrom, keyY initial data seed) (used in production ROMs)
CryptoType_Secure2 = 2, // Secure initial data key (keyX bootrom, keyY initial data seed) (used in production ROMs)
CryptoType_FixedKey = 3, // Zeros initial data key (used in non-HSM enviroments like development)
};

Expand Down
16 changes: 12 additions & 4 deletions ctrtool/src/CciProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ void ctrtool::CciProcess::importHeader()
ctrtool::KeyBag::Aes128Key initial_data_key;
bool initial_data_key_available = false;

// crypto_type 0 is the normal "secure" initial data key
if (mHeader.card_info.flag.crypto_type == ntd::n3ds::CciHeader::CryptoType_Secure)
// crypto_type 0-2 is the normal "secure" initial data key
if (mHeader.card_info.flag.crypto_type == ntd::n3ds::CciHeader::CryptoType_Secure0 ||
mHeader.card_info.flag.crypto_type == ntd::n3ds::CciHeader::CryptoType_Secure1 ||
mHeader.card_info.flag.crypto_type == ntd::n3ds::CciHeader::CryptoType_Secure2)
{
if (mKeyBag.brom_static_key_x.find(mKeyBag.KEYSLOT_INITIAL_DATA) != mKeyBag.brom_static_key_x.end())
{
Expand Down Expand Up @@ -530,8 +532,14 @@ std::string ctrtool::CciProcess::getCryptoTypeString(byte_t crypto_type)

switch(crypto_type)
{
case ntd::n3ds::CciHeader::CryptoType_Secure :
ret_str = "Secure";
case ntd::n3ds::CciHeader::CryptoType_Secure0 :
ret_str = "Secure0";
break;
case ntd::n3ds::CciHeader::CryptoType_Secure1 :
ret_str = "Secure1";
break;
case ntd::n3ds::CciHeader::CryptoType_Secure2 :
ret_str = "Secure2";
break;
case ntd::n3ds::CciHeader::CryptoType_FixedKey :
ret_str = "FixedKey";
Expand Down
2 changes: 1 addition & 1 deletion ctrtool/src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#define BIN_NAME "ctrtool"
#define VER_MAJOR 1
#define VER_MINOR 0
#define VER_PATCH 3
#define VER_PATCH 4
#define AUTHORS "jakcron"

0 comments on commit 5840526

Please sign in to comment.