From b67ce08f8496313bbe9fd747c8f5d51b652e60b0 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 1 Mar 2018 02:00:39 -0800 Subject: [PATCH] Fix Modulus Exponentiation in SE driver --- exosphere/src/se.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exosphere/src/se.c b/exosphere/src/se.c index c6a9ff418..43e0001c9 100644 --- a/exosphere/src/se.c +++ b/exosphere/src/se.c @@ -154,12 +154,12 @@ void set_rsa_keyslot(unsigned int keyslot, const void *modulus, size_t modulus_ for (size_t i = 0; i < (modulus_size >> 2); i++) { SECURITY_ENGINE->RSA_KEYTABLE_ADDR = (keyslot << 7) | 0x40 | i; - SECURITY_ENGINE->RSA_KEYTABLE_DATA = read32be(modulus, 4 * i); + SECURITY_ENGINE->RSA_KEYTABLE_DATA = read32be(modulus, (4 * (modulus_size >> 2)) - (4 * i) - 4); } for (size_t i = 0; i < (exp_size >> 2); i++) { SECURITY_ENGINE->RSA_KEYTABLE_ADDR = (keyslot << 7) | i; - SECURITY_ENGINE->RSA_KEYTABLE_DATA = read32be(exponent, 4 * i); + SECURITY_ENGINE->RSA_KEYTABLE_DATA = read32be(exponent, (4 * (exp_size >> 2)) - (4 * i) - 4); } g_se_modulus_sizes[keyslot] = modulus_size; @@ -307,8 +307,8 @@ void se_synchronous_exp_mod(unsigned int keyslot, void *dst, size_t dst_size, co } /* Endian swap the input. */ - for (size_t i = src_size; i > 0; i--) { - stack_buf[i] = *((uint8_t *)src + src_size - i); + for (size_t i = 0; i < src_size; i++) { + stack_buf[i] = *((uint8_t *)src + src_size - i - 1); } SECURITY_ENGINE->CONFIG_REG = (ALG_RSA | DST_RSAREG);