From 655e5172785ae98e529d46ce2b004acbe634bdba Mon Sep 17 00:00:00 2001 From: N2614 Date: Thu, 17 Mar 2011 04:46:31 +0000 Subject: [PATCH] =?UTF-8?q?=E9=96=8B=E7=99=BA=E6=A9=9F=E3=81=A8=E9=87=8F?= =?UTF-8?q?=E7=94=A3=E6=A9=9F=E3=81=A7=E9=8D=B5=E3=82=92=E5=A4=89=E3=81=88?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@145 385bec56-5757-e545-9c3a-d8741f4650f1 --- .../ConsoleBackup/Exporter.cpp | 11 ++++++- .../ConsoleRestore/Importer.cpp | 11 ++++++- .../ConsoleDataMigration/common/Aes_define.h | 30 ++++++++++++++--- .../common/FileTransfer.cpp | 33 ++++++++++++++++--- .../common/SdReaderWriter.cpp | 22 +++++++++++-- 5 files changed, 94 insertions(+), 13 deletions(-) diff --git a/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.cpp b/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.cpp index 766650e..51294de 100644 --- a/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.cpp +++ b/trunk/ConsoleDataMigration/ConsoleBackup/Exporter.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -239,7 +240,15 @@ void WriteIvs() nn::crypto::SwAesCtrContext swAesCtrContest; - swAesCtrContest.Initialize(common::iv, common::key, sizeof(common::key)); + if(nn::os::IsRunOnDevelopmentHardware()) + { + swAesCtrContest.Initialize(common::devIv, common::devKey, sizeof(common::devKey)); + } + else + { + swAesCtrContest.Initialize(common::prodIv, common::prodKey, sizeof(common::prodKey)); + } + swAesCtrContest.Encrypt(enc, ivs, size); s_SdWriter.WriteBufWithCmac(common::IVS_PATHNAME, enc, size); diff --git a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp index 10c5e58..663b2f3 100644 --- a/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp +++ b/trunk/ConsoleDataMigration/ConsoleRestore/Importer.cpp @@ -14,6 +14,7 @@ *---------------------------------------------------------------------------*/ #include +#include #include #include #include @@ -606,7 +607,15 @@ nn::Result ImportIvs() nn::crypto::Initialize(); nn::crypto::SwAesCtrContext swAesCtrContest; - swAesCtrContest.Initialize(common::iv, common::key, sizeof(common::key)); + if(nn::os::IsRunOnDevelopmentHardware()) + { + swAesCtrContest.Initialize(common::devIv, common::devKey, sizeof(common::devKey)); + } + else + { + swAesCtrContest.Initialize(common::prodIv, common::prodKey, sizeof(common::prodKey)); + } + swAesCtrContest.Decrypt(dec, enc, readSize); // IVS書き込み diff --git a/trunk/ConsoleDataMigration/common/Aes_define.h b/trunk/ConsoleDataMigration/common/Aes_define.h index a31eb56..f244569 100644 --- a/trunk/ConsoleDataMigration/common/Aes_define.h +++ b/trunk/ConsoleDataMigration/common/Aes_define.h @@ -20,23 +20,43 @@ namespace common { - const bit8 key[AES_KEY_SIZE] NN_ATTRIBUTE_ALIGN(4) = + const bit8 devKey[AES_KEY_SIZE] NN_ATTRIBUTE_ALIGN(4) = { 0x81, 0x35, 0xc6, 0x54, 0x19, 0x1a, 0x47, 0x2a, 0x6b, 0x78, 0xbe, 0x25, 0x90, 0xf6, 0xee, 0x74 }; - const bit8 cmacKey[AES_KEY_SIZE] = + const bit8 devCmacKey[AES_KEY_SIZE] = { 0x87, 0xdd, 0xc6, 0xd6, 0xf2, 0xe0, 0x2c, 0xa6, 0x04, 0x21, 0x9c, 0x5e, 0x33, 0x8c, 0x3d, 0xaa }; - const bit8 iv[AES_BLOCK_SIZE] NN_ATTRIBUTE_ALIGN(4) = + const bit8 devIv[AES_BLOCK_SIZE] NN_ATTRIBUTE_ALIGN(4) = { - 0xdf, 0x0f, 0xf9, 0x1b, 0x34, 0x47, 0x70, 0x7f, - 0x7d, 0x06, 0x85, 0xe6, 0xe7, 0xb6, 0x4e, 0xe9 + 0xdf, 0x0f, 0xf9, 0x1b, 0x34, 0x47, 0x70, 0x7f, + 0x7d, 0x06, 0x85, 0xe6, 0xe7, 0xb6, 0x4e, 0xe9 }; + + + const bit8 prodKey[AES_KEY_SIZE] NN_ATTRIBUTE_ALIGN(4) = + { + 0x64, 0x02, 0x6d, 0xbd, 0x9f, 0xb6, 0x62, 0x39, + 0x86, 0x90, 0x67, 0x8a, 0xe2, 0xfa, 0xe1, 0x6e + }; + + const bit8 prodCmacKey[AES_KEY_SIZE] = + { + 0xdf, 0x3c, 0x58, 0xeb, 0xeb, 0xbf, 0x45, 0x6d, + 0xc9, 0xbe, 0xe3, 0x10, 0xe2, 0x23, 0xfc, 0x30 + }; + + const bit8 prodIv[AES_BLOCK_SIZE] NN_ATTRIBUTE_ALIGN(4) = + { + 0xe4, 0xcf, 0x58, 0xe5, 0xc9, 0xd6, 0xac, 0x7d, + 0xf1, 0xb9, 0x82, 0xf9, 0xa2, 0xd8, 0xda, 0x7b + }; + } #endif /* AES_DEFINE_H_ */ diff --git a/trunk/ConsoleDataMigration/common/FileTransfer.cpp b/trunk/ConsoleDataMigration/common/FileTransfer.cpp index 7ce23f6..51e5ad6 100644 --- a/trunk/ConsoleDataMigration/common/FileTransfer.cpp +++ b/trunk/ConsoleDataMigration/common/FileTransfer.cpp @@ -15,6 +15,8 @@ #include +#include + #include #include #include @@ -212,7 +214,14 @@ bool CopyDirectory(const wchar_t * from_path, const wchar_t * to_path, void* buf } nn::crypto::SwAesCtrContext swAesCtrContext; - swAesCtrContext.Initialize(iv, common::key, sizeof(key)); + if(nn::os::IsRunOnDevelopmentHardware()) + { + swAesCtrContext.Initialize(devIv, common::devKey, sizeof(devKey)); + } + else + { + swAesCtrContext.Initialize(prodIv, common::prodKey, sizeof(prodKey)); + } size_t totalReadSize = 0; nn::crypto::Sha256Context context; @@ -297,8 +306,16 @@ bool CopyDirectory(const wchar_t * from_path, const wchar_t * to_path, void* buf context.GetHash(sha256Hash); bit8 cmac[nn::crypto::AES_CMAC_MAC_SIZE]; - result = nn::crypto::CalculateAesCmacSw(cmac, sha256Hash, - nn::crypto::Sha256Context::HASH_SIZE, common::cmacKey); + if(nn::os::IsRunOnDevelopmentHardware()) + { + result = nn::crypto::CalculateAesCmacSw(cmac, sha256Hash, + nn::crypto::Sha256Context::HASH_SIZE, common::devCmacKey); + } + else + { + result = nn::crypto::CalculateAesCmacSw(cmac, sha256Hash, + nn::crypto::Sha256Context::HASH_SIZE, common::prodCmacKey); + } COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); result = to_file.TryWrite(&writesize, cmac, sizeof(cmac)); @@ -431,7 +448,15 @@ bool CalculateAndCompareCmac(nn::crypto::Sha256Context* context, bit8* sdCmac) context->GetHash(sha256Hash); context->Finalize(); - result = nn::crypto::CalculateAesCmacSw(cmac, sha256Hash, sizeof(sha256Hash), common::cmacKey); + if(nn::os::IsRunOnDevelopmentHardware()) + { + result = nn::crypto::CalculateAesCmacSw(cmac, sha256Hash, sizeof(sha256Hash), common::devCmacKey); + } + else + { + result = nn::crypto::CalculateAesCmacSw(cmac, sha256Hash, sizeof(sha256Hash), common::prodCmacKey); + } + if (result.IsFailure()) { COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); diff --git a/trunk/ConsoleDataMigration/common/SdReaderWriter.cpp b/trunk/ConsoleDataMigration/common/SdReaderWriter.cpp index 4bea638..5fd268a 100644 --- a/trunk/ConsoleDataMigration/common/SdReaderWriter.cpp +++ b/trunk/ConsoleDataMigration/common/SdReaderWriter.cpp @@ -18,6 +18,8 @@ #include "CommonLogger.h" #include "Aes_define.h" +#include + #include #include #include @@ -122,7 +124,15 @@ nn::Result SdReaderWriter::WriteBufWithCmac(const wchar_t* path, void* buf, size nn::crypto::CalculateSha256(sha256Hash, buf, size); bit8 cmac[nn::crypto::AES_CMAC_MAC_SIZE]; - result = nn::crypto::CalculateAesCmacSw(cmac, sha256Hash, nn::crypto::Sha256Context::HASH_SIZE, common::cmacKey); + + if(nn::os::IsRunOnDevelopmentHardware()) + { + result = nn::crypto::CalculateAesCmacSw(cmac, sha256Hash, nn::crypto::Sha256Context::HASH_SIZE, common::devCmacKey); + } + else + { + result = nn::crypto::CalculateAesCmacSw(cmac, sha256Hash, nn::crypto::Sha256Context::HASH_SIZE, common::prodCmacKey); + } COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); s32 writeSize; @@ -212,7 +222,15 @@ nn::Result SdReaderWriter::ReadBufWithCmac(const wchar_t* path, void* buf, size_ nn::crypto::CalculateSha256(sha256Hash, buf, *totalSize); bit8 cmac[nn::crypto::AES_CMAC_MAC_SIZE]; - result = nn::crypto::CalculateAesCmacSw(cmac, sha256Hash, nn::crypto::Sha256Context::HASH_SIZE, common::cmacKey); + if(nn::os::IsRunOnDevelopmentHardware()) + { + result = nn::crypto::CalculateAesCmacSw(cmac, sha256Hash, nn::crypto::Sha256Context::HASH_SIZE, common::devCmacKey); + } + else + { + result = nn::crypto::CalculateAesCmacSw(cmac, sha256Hash, nn::crypto::Sha256Context::HASH_SIZE, common::prodCmacKey); + } + COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); if(std::memcmp(reinterpret_cast(buf) + *totalSize, cmac, sizeof(cmac)) != 0)