mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-26 05:42:17 +00:00
sept: add vector check to key derivation
This commit is contained in:
parent
c077c75b8d
commit
938da08e14
3 changed files with 25 additions and 2 deletions
|
@ -14,9 +14,10 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "pmc.h"
|
||||
#include "se.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define AL16 __attribute__((aligned(16)))
|
||||
|
||||
|
@ -42,6 +43,10 @@ static const uint8_t AL16 masterkey_4x_seed[0x10] = {
|
|||
0x2D, 0xC1, 0xF4, 0x8D, 0xF3, 0x5B, 0x69, 0x33, 0x42, 0x10, 0xAC, 0x65, 0xDA, 0x90, 0x46, 0x66
|
||||
};
|
||||
|
||||
static const uint8_t AL16 zeroes[0x10] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
static const uint8_t AL16 master_kek_seeds[DERIVATION_ID_MAX][0x10] = {
|
||||
{0x9A, 0x3E, 0xA9, 0xAB, 0xFD, 0x56, 0x46, 0x1C, 0x9B, 0xF6, 0x48, 0x7F, 0x5C, 0xFA, 0x09, 0x5C},
|
||||
{0xDE, 0xDC, 0xE3, 0x39, 0x30, 0x88, 0x16, 0xF8, 0xAE, 0x97, 0xAD, 0xEC, 0x64, 0x2D, 0x41, 0x41},
|
||||
|
@ -52,6 +57,11 @@ static const uint8_t AL16 master_devkey_seeds[DERIVATION_ID_MAX][0x10] = {
|
|||
{0x67, 0x62, 0xD4, 0x8E, 0x55, 0xCF, 0xFF, 0x41, 0x31, 0x15, 0x3B, 0x24, 0x0C, 0x7C, 0x07, 0xAE},
|
||||
};
|
||||
|
||||
static const uint8_t AL16 master_devkey_vectors[DERIVATION_ID_MAX][0x10] = {
|
||||
{0xD8, 0xD3, 0x67, 0x4F, 0xF3, 0xA2, 0xA4, 0x4E, 0xE4, 0x04, 0x37, 0xC2, 0xD9, 0xCF, 0x41, 0x6F},
|
||||
{0x72, 0xD0, 0xAD, 0xEB, 0xE1, 0xF6, 0x35, 0x90, 0xB4, 0x43, 0xCC, 0x4B, 0xC4, 0xDC, 0x88, 0x0A},
|
||||
};
|
||||
|
||||
void derive_keys(void) {
|
||||
/* Set mailbox. */
|
||||
volatile uint32_t *mailbox = (volatile uint32_t *)0x4003FF00;
|
||||
|
@ -87,6 +97,17 @@ void derive_keys(void) {
|
|||
decrypt_data_into_keyslot(0xE, 0xE, work_buffer, 0x10);
|
||||
clear_aes_keyslot(0xD);
|
||||
|
||||
/* Test against a vector. */
|
||||
se_aes_ecb_decrypt_block(0xE, work_buffer, 0x10, master_devkey_vectors[derivation_id], 0x10);
|
||||
if (memcmp(work_buffer, zeroes, 0x10) == 0) {
|
||||
clear_aes_keyslot(0xE);
|
||||
clear_aes_keyslot(0xD);
|
||||
clear_aes_keyslot(0xC);
|
||||
clear_aes_keyslot(0xA);
|
||||
clear_aes_keyslot(0xF);
|
||||
generic_panic();
|
||||
}
|
||||
|
||||
/* Clear work buffer. */
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
work_buffer[i] = 0xCCCCCCCC;
|
||||
|
|
|
@ -346,7 +346,7 @@ void trigger_se_blocking_op(unsigned int op, void *dst, size_t dst_size, const v
|
|||
se->ERR_STATUS_REG = se->ERR_STATUS_REG;
|
||||
se->INT_STATUS_REG = se->INT_STATUS_REG;
|
||||
|
||||
if (se->IN_LL_ADDR_REG != (uint32_t) get_physical_address(&in_ll) || se->OUT_LL_ADDR_REG != (uint32_t) get_physical_address(&out_ll) || (se->FLAGS_REG & 0x3)) {
|
||||
if (se->IN_LL_ADDR_REG != (uint32_t) get_physical_address(&in_ll) || se->OUT_LL_ADDR_REG != (uint32_t) get_physical_address(&out_ll) || (se->INT_STATUS_REG & 0x10) || (se->FLAGS_REG & 0x3)) {
|
||||
generic_panic();
|
||||
}
|
||||
|
||||
|
|
|
@ -23,9 +23,11 @@
|
|||
__attribute__ ((noreturn)) void generic_panic(void) {
|
||||
/* Clear keyslots. */
|
||||
clear_aes_keyslot(0xD);
|
||||
clear_aes_keyslot(0xE);
|
||||
for (size_t i = 0; i < 0x10; i++) {
|
||||
clear_aes_keyslot(i);
|
||||
}
|
||||
clear_aes_keyslot(0xD);
|
||||
clear_aes_keyslot(0xE);
|
||||
while(1) { /* ... */ }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue