Reorganise NXCrypto

This commit is contained in:
jakcron 2018-03-31 08:08:10 +08:00
parent 427cdbb059
commit eb04a4341f

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
// AES // AES
namespace crypto namespace crypto
{ {
@ -23,11 +24,11 @@ namespace crypto
/* /*
public static AesKey GetNcaExternalContentKey(IHashCalculator hashCalculator, ulong titleId) public static AesKey GetNcaExternalContentKey(IHashCalculator hashCalculator, ulong titleId)
{ {
Trace.Assert(hashCalculator != null, "IHashCalculator is null."); Trace.Assert(hashCalculator != null, "IHashCalculator is null.");
byte[] array = BitConverter.GetBytes(titleId).Reverse<byte>().ToArray<byte>(); byte[] array = BitConverter.GetBytes(titleId).Reverse<byte>().ToArray<byte>();
byte[] numArray = new byte[hashCalculator.HashSize]; byte[] numArray = new byte[hashCalculator.HashSize];
hashCalculator.CalculateHash(array, 0, (int)array.Length, numArray, 0); hashCalculator.CalculateHash(array, 0, (int)array.Length, numArray, 0);
return new AesKey(((IEnumerable<byte>)numArray).Where<byte>((byte name, int index) => index < 16).ToArray<byte>()); return new AesKey(((IEnumerable<byte>)numArray).Where<byte>((byte name, int index) => index < 16).ToArray<byte>());
} }
*/ */
namespace nx namespace nx
@ -67,7 +68,7 @@ namespace crypto
byte_t titlekey_generate_key[0x20] = { 39, 111, 56, 188, 68, 106, 241, 86, 31, 44, 90, 111, 116, 32, 93, 197, 25, 181, 59, 188, 178, 159, 211, 175, 212, 178, 162, 4, 28, 152, 117, 126 }; byte_t titlekey_generate_key[0x20] = { 39, 111, 56, 188, 68, 106, 241, 86, 31, 44, 90, 111, 116, 32, 93, 197, 25, 181, 59, 188, 178, 159, 211, 175, 212, 178, 162, 4, 28, 152, 117, 126 };
// aes128-cbc keys // aes128-cbc keys
byte_t xci_header_key[16] = { 0x01, 0xc5, 0x8f, 0xe7, 0x2d, 0x13, 0x5a, 0xb2, 0x9a, 0x3f, 0x69, 0x33, 0x95, 0x74, 0xb1 }; byte_t xci_header_key[16] = { 0x01, 0xC5, 0x8F, 0xE7, 0x00, 0x2D, 0x13, 0x5A, 0xB2, 0x9A, 0x3F, 0x69, 0x33, 0x95, 0x74, 0xB1 };
byte_t eticket_common_key[16] = { 0x55, 0xA3, 0xF8, 0x72, 0xBD, 0xC8, 0x0C, 0x55, 0x5A, 0x65, 0x43, 0x81, 0x13, 0x9E, 0x15, 0x3B }; // lol this 3ds dev common key byte_t eticket_common_key[16] = { 0x55, 0xA3, 0xF8, 0x72, 0xBD, 0xC8, 0x0C, 0x55, 0x5A, 0x65, 0x43, 0x81, 0x13, 0x9E, 0x15, 0x3B }; // lol this 3ds dev common key
byte_t wii_sd_key[16] = { 0xAB, 0x01, 0xB9, 0xD8, 0xE1, 0x62, 0x2B, 0x08, 0xAF, 0xBA, 0xD8, 0x4D, 0xBF, 0xC2, 0xA5, 0x5D }; byte_t wii_sd_key[16] = { 0xAB, 0x01, 0xB9, 0xD8, 0xE1, 0x62, 0x2B, 0x08, 0xAF, 0xBA, 0xD8, 0x4D, 0xBF, 0xC2, 0xA5, 0x5D };
@ -75,26 +76,33 @@ namespace crypto
namespace prod namespace prod
{ {
// encrypted with ProdNcaHeaderEncryptionKek byte_t master_key[0x20][16] =
byte_t nca_enc_header_key[2][16] =
{ {
{ 0x5A, 0x3E, 0xD8, 0x4F, 0xDE, 0xC0, 0xD8, 0x26, 0x31, 0xF7, 0xE2, 0x5D, 0x19, 0x7B, 0xF5, 0xD0 }, { 0xC2, 0xCA, 0xAF, 0xF0, 0x89, 0xB9, 0xAE, 0xD5, 0x56, 0x94, 0x87, 0x60, 0x55, 0x27, 0x1C, 0x7D },
{ 0x1C, 0x9B, 0x7B, 0xFA, 0xF6, 0x28, 0x18, 0x3D, 0x71, 0xF6, 0x4D, 0x73, 0xF1, 0x50, 0xB9, 0xD2 } { 0x54, 0xE1, 0xB8, 0xE9, 0x99, 0xC2, 0xFD, 0x16, 0xCD, 0x07, 0xB6, 0x61, 0x09, 0xAC, 0xAA, 0xA6 },
{ 0x4F, 0x6B, 0x10, 0xD3, 0x30, 0x72, 0xAF, 0x2F, 0x25, 0x05, 0x62, 0xBF, 0xF0, 0x6B, 0x6D, 0xA3 },
}; };
byte_t master_key_0[16] = { 0xC2, 0xCA, 0xAF, 0xF0, 0x89, 0xB9, 0xAE, 0xD5, 0x56, 0x94, 0x87, 0x60, 0x55, 0x27, 0x1C, 0x7D }; byte_t nca_header_key[2][16] =
byte_t nca_header_key[2][16] =
{ {
{ 0xAE, 0xAA, 0xB1, 0xCA, 0x08, 0xAD, 0xF9, 0xBE, 0xF1, 0x29, 0x91, 0xF3, 0x69, 0xE3, 0xC5, 0x67 }, { 0xAE, 0xAA, 0xB1, 0xCA, 0x08, 0xAD, 0xF9, 0xBE, 0xF1, 0x29, 0x91, 0xF3, 0x69, 0xE3, 0xC5, 0x67 },
{ 0xD6, 0x88, 0x1E, 0x4E, 0x4A, 0x6A, 0x47, 0xA5, 0x1F, 0x6E, 0x48, 0x77, 0x06, 0x2D, 0x54, 0x2D } { 0xD6, 0x88, 0x1E, 0x4E, 0x4A, 0x6A, 0x47, 0xA5, 0x1F, 0x6E, 0x48, 0x77, 0x06, 0x2D, 0x54, 0x2D }
}; };
byte_t xci_header_key[16] = { 0x01, 0xC5, 0x8F, 0xE7, 0x00, 0x2D, 0x13, 0x5A, 0xB2, 0x9A, 0x3F, 0x69, 0x33, 0x95, 0x74, 0xB1 }; byte_t xci_header_key[16] = { 0x01, 0xC5, 0x8F, 0xE7, 0x00, 0x2D, 0x13, 0x5A, 0xB2, 0x9A, 0x3F, 0x69, 0x33, 0x95, 0x74, 0xB1 };
/*
// encrypted with ProdNcaHeaderEncryptionKek
byte_t nca_enc_header_key[2][16] =
{
{ 0x5A, 0x3E, 0xD8, 0x4F, 0xDE, 0xC0, 0xD8, 0x26, 0x31, 0xF7, 0xE2, 0x5D, 0x19, 0x7B, 0xF5, 0xD0 },
{ 0x1C, 0x9B, 0x7B, 0xFA, 0xF6, 0x28, 0x18, 0x3D, 0x71, 0xF6, 0x4D, 0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