From 0340085c67852c5a9b0aed8a03c1ccf2da82d5d7 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Mon, 19 Feb 2018 20:28:37 -0800 Subject: [PATCH] smcComputeCmac implementation. --- exosphere/smc_api.c | 4 ++++ exosphere/smc_user.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/exosphere/smc_api.c b/exosphere/smc_api.c index db5f804cf..eb95e41a6 100644 --- a/exosphere/smc_api.c +++ b/exosphere/smc_api.c @@ -277,6 +277,10 @@ uint32_t smc_crypt_aes(smc_args_t *args) { return smc_wrapper_async(args, user_crypt_aes, smc_crypt_aes_status_check); } +uint32_t smc_compute_cmac(smc_args_t *args) { + return smc_wrapper_sync(args, user_compute_cmac); +} + uint32_t smc_cpu_on(smc_args_t *args) { diff --git a/exosphere/smc_user.c b/exosphere/smc_user.c index 64c8b11eb..1371baa1b 100644 --- a/exosphere/smc_user.c +++ b/exosphere/smc_user.c @@ -1,9 +1,11 @@ #include #include "utils.h" +#include "cache.h" #include "smc_api.h" #include "smc_user.h" #include "se.h" +#include "userpage.h" /* Globals. */ int g_crypt_aes_done = 0; @@ -87,4 +89,32 @@ uint32_t user_crypt_aes(smc_args_t *args) { } return result; +} + +uint32_t user_compute_cmac(smc_args_t *args) { + uint32_t keyslot = (uint32_t)args->X[1]; + void *user_address = (void *)args->X[2]; + size_t size = (size_t)args->X[3]; + + uint8_t user_data[0x400]; + uint64_t result_cmac[2]; + upage_ref_t page_ref; + + /* Validate keyslot and size. */ + if (keyslot > 3 || args->X[3] > 0x400) { + return 2; + } + + if (upage_init(&page_ref, (void *)user_address) == 0 || user_copy_to_secure() == 0) { + return 2; + } + + flush_dcache_range(user_data, user_data + size); + se_compute_aes_128_cmac(keyslot, result_cmac, 0x10, user_data, size); + + /* Copy CMAC out. */ + args->X[1] = result_cmac[0]; + args->X[2] = result_cmac[1]; + + return 0; } \ No newline at end of file