From 059610f41e88c98cdf28fec5fb2ff62c5afef020 Mon Sep 17 00:00:00 2001 From: jakcron Date: Sun, 17 Apr 2022 09:59:12 +0800 Subject: [PATCH] Import initial data key_x (prod/dev included) --- makerom/src/keyset.c | 14 ++++++++++++++ makerom/src/keyset.h | 4 ++++ makerom/src/pki/dev.h | 5 +++++ makerom/src/pki/prod.h | 5 +++++ 4 files changed, 28 insertions(+) diff --git a/makerom/src/keyset.c b/makerom/src/keyset.c index c706c91..b8cd3e0 100644 --- a/makerom/src/keyset.c +++ b/makerom/src/keyset.c @@ -80,6 +80,9 @@ int LoadKeysFromResources(keys_struct *keys) SetNormalKey(keys,zeros_aesKey); SetSystemFixedKey(keys,zeros_aesKey); + // CCI + SetCciInitialDataKeyX(keys, zeros_aesKey); + /* RSA Keys */ // CIA Rsa2048Key_Set(&keys->rsa.xs, tpki_rsa.priv_exponent, tpki_rsa.modulus); @@ -112,6 +115,9 @@ int LoadKeysFromResources(keys_struct *keys) for(int i = 0; i < 4; i++) SetNcchKeyX(keys, dev_unfixed_ncch_keyX[i],i); + // CCI + SetCciInitialDataKeyX(keys, dev_initial_data_keyx); + /* RSA Keys */ // CIA Rsa2048Key_Set(&keys->rsa.xs, xs9_dpki_rsa.priv_exponent, xs9_dpki_rsa.modulus); @@ -143,6 +149,8 @@ int LoadKeysFromResources(keys_struct *keys) for(int i = 0; i < 4; i++) SetNcchKeyX(keys, prod_unfixed_ncch_keyX[i],i); + // CCI + SetCciInitialDataKeyX(keys, dev_initial_data_keyx); /* RSA Keys */ // CIA @@ -362,6 +370,12 @@ int SetSystemFixedKey(keys_struct *keys, const u8 *key) return CopyData(&keys->aes.systemFixedKey,key,16); } +int SetCciInitialDataKeyX(keys_struct *keys, const u8 *key) +{ + if(!keys) return -1; + return CopyData(&keys->aes.initialDataKeyX,key,16); +} + int SetCaCert(keys_struct *keys, const u8 *cert) { if(!keys) return -1; diff --git a/makerom/src/keyset.h b/makerom/src/keyset.h index 887f3de..47eff79 100644 --- a/makerom/src/keyset.h +++ b/makerom/src/keyset.h @@ -62,6 +62,9 @@ typedef struct u8 *ncchKey0; u8 *ncchKey1; + + // CCI + u8 *initialDataKeyX; } aes; struct @@ -96,6 +99,7 @@ int SetCommonKey(keys_struct *keys, const u8 *key, u8 Index); int SetCurrentCommonKey(keys_struct *keys, u8 Index); int SetNormalKey(keys_struct *keys, const u8 *key); int SetSystemFixedKey(keys_struct *keys, const u8 *key); +int SetCciInitialDataKeyX(keys_struct *keys, const u8 *key); void Rsa2048Key_Alloc(rsa2048_key* key); void Rsa2048Key_Free(rsa2048_key* key); diff --git a/makerom/src/pki/dev.h b/makerom/src/pki/dev.h index eb79385..a1e787b 100644 --- a/makerom/src/pki/dev.h +++ b/makerom/src/pki/dev.h @@ -30,6 +30,11 @@ static const unsigned char ctr_common_etd_key_dpki[6][16] = { 0xAA, 0xDA, 0x4C, 0xA8, 0xF6, 0xE5, 0xA9, 0x77, 0xE0, 0xA0, 0xF9, 0xE4, 0x76, 0xCF, 0x0D, 0x63 } }; +static const unsigned char dev_initial_data_keyx[16] = +{ + 0x5C, 0x3D, 0x38, 0xAC, 0x17, 0x40, 0x99, 0x4E, 0xFC, 0x8F, 0xD0, 0xBE, 0x8D, 0x80, 0x97, 0xB3 +}; + //RSA Keys static const CtrRsa4096Key root_dpki_rsa = { diff --git a/makerom/src/pki/prod.h b/makerom/src/pki/prod.h index 790bd4d..07bc638 100644 --- a/makerom/src/pki/prod.h +++ b/makerom/src/pki/prod.h @@ -23,6 +23,11 @@ static const unsigned char ctr_common_etd_key_ppki[6][16] = { 0xA5, 0x05, 0x1C, 0xA1, 0xB3, 0x7D, 0xCF, 0x3A, 0xFB, 0xCF, 0x8C, 0xC1, 0xED, 0xD9, 0xCE, 0x02 } , // 5 }; +static const unsigned char prod_initial_data_keyx[16] = +{ + 0xB5, 0x29, 0x22, 0x1C, 0xDD, 0xB5, 0xDB, 0x5A, 0x1B, 0xF2, 0x6E, 0xFF, 0x20, 0x41, 0xE8, 0x75 +}; + // RSA KEYS static const CtrRsa4096Key root_ppki_rsa = {