From 938da08e1446cff77efef985ac95ba8827d37076 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 19 Jun 2019 12:22:37 -0700 Subject: [PATCH] sept: add vector check to key derivation --- .../key_derivation/src/key_derivation.c | 23 ++++++++++++++++++- sept/sept-secondary/key_derivation/src/se.c | 2 +- .../sept-secondary/key_derivation/src/utils.c | 2 ++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/sept/sept-secondary/key_derivation/src/key_derivation.c b/sept/sept-secondary/key_derivation/src/key_derivation.c index e66f836d8..349e72ada 100644 --- a/sept/sept-secondary/key_derivation/src/key_derivation.c +++ b/sept/sept-secondary/key_derivation/src/key_derivation.c @@ -14,9 +14,10 @@ * along with this program. If not, see . */ -#include +#include #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; diff --git a/sept/sept-secondary/key_derivation/src/se.c b/sept/sept-secondary/key_derivation/src/se.c index ede5a05d2..b32595c99 100644 --- a/sept/sept-secondary/key_derivation/src/se.c +++ b/sept/sept-secondary/key_derivation/src/se.c @@ -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(); } diff --git a/sept/sept-secondary/key_derivation/src/utils.c b/sept/sept-secondary/key_derivation/src/utils.c index a515fb57a..b9e7c2551 100644 --- a/sept/sept-secondary/key_derivation/src/utils.c +++ b/sept/sept-secondary/key_derivation/src/utils.c @@ -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) { /* ... */ } }