diff --git a/IDE/Renesas/e2studio/RA6M4/common/wolfssl_demo.h b/IDE/Renesas/e2studio/RA6M4/common/wolfssl_demo.h index 77cd17d0fe..2fed8a75c7 100644 --- a/IDE/Renesas/e2studio/RA6M4/common/wolfssl_demo.h +++ b/IDE/Renesas/e2studio/RA6M4/common/wolfssl_demo.h @@ -32,7 +32,8 @@ #define FLASH_HP_DF_BLOCK_1 0x08000040U /* 64 B: 0x40100040 - 0x4010007F */ #define FLASH_HP_DF_BLOCK_2 0x08000080U /* 64 B: 0x40100080 - 0x401000BF */ #define FLASH_HP_DF_BLOCK_3 0x080000C0U /* 64 B: 0x401000C0 - 0x401000FF */ -#define DIRECT_KEY_ADDRESS FLASH_HP_DF_BLOCK_1 +#define DIRECT_KEY_ADDRESS_256 FLASH_HP_DF_BLOCK_1 +#define DIRECT_KEY_ADDRESS_128 FLASH_HP_DF_BLOCK_2 /* Enable wolfcrypt test */ /* can be enabled with benchmark test */ diff --git a/IDE/Renesas/e2studio/RA6M4/test/key_data/key_data_sce.c b/IDE/Renesas/e2studio/RA6M4/test/key_data/key_data_sce.c index abc7fcb96d..b4ce9c61b5 100644 --- a/IDE/Renesas/e2studio/RA6M4/test/key_data/key_data_sce.c +++ b/IDE/Renesas/e2studio/RA6M4/test/key_data/key_data_sce.c @@ -72,32 +72,32 @@ const st_user_key_block_data_t g_key_block_data = * This is used for Root Certificate verify by SCE */ const unsigned char ca_cert_der_sign[] = { - 0x07, 0x1A, 0x68, 0xF4, 0x53, 0x2A, 0x9B, 0x1F, 0xF7, 0x7B, - 0x5C, 0x70, 0x88, 0x46, 0x03, 0x10, 0x35, 0x0C, 0x84, 0x4F, - 0xDC, 0x09, 0x8D, 0xD8, 0x97, 0x10, 0xFA, 0xC7, 0x1D, 0x7F, - 0xCC, 0xF2, 0xC9, 0x41, 0x27, 0xBA, 0x0C, 0x93, 0x77, 0x64, - 0x46, 0x89, 0xC3, 0x36, 0x45, 0x5B, 0x2E, 0xC7, 0xCF, 0xE7, -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xC3, 0xC2, 0x75, 0xA9, 0xA4, 0x3B, 0x4E, + 0x8E, 0xFC, 0x43, 0xB9, 0x03, 0x56, 0xBB, 0x12, 0xD3, 0x64, + 0x65, 0x1E, 0x79, 0x18, 0xC8, 0x29, 0x3C, 0xB2, 0x9F, 0x5B, + 0x3B, 0x0B, 0x7A, 0x59, 0x43, 0xBB, 0x2A, 0xEF, 0xF0, 0x2C, + 0x50, 0xCD, 0x0C, 0xC5, 0x0E, 0x08, 0x5C, 0xB0, 0x31, 0xD4, + 0x9C, 0xF4, 0xE2, 0x45, 0xC3, 0x4C, 0xBB, 0x29, 0x44, 0x13, + 0x89, 0xE2, 0x7F, 0xD7, 0xE5, 0x7C, 0x2D, 0x89, 0xCA, 0xD4, + 0xB0, 0x2E, 0xAF, 0x2C, 0x8D, 0x84, 0x87, 0x30, 0x40, 0x4D, + 0xC5, 0x42, 0x6A, 0x1C, 0xF3, 0x6A, 0x24, 0xE5, 0x48, 0xA5, + 0x53, 0x74, 0x87, 0xA0, 0xE5, 0x69, 0xF1, 0xD1, 0x7A, 0x85, + 0x5E, 0x14, 0xD1, 0x00, 0x8A, 0xD2 }; const int sizeof_ca_cert_der_sign = sizeof(ca_cert_der_sign); @@ -108,32 +108,32 @@ const int sizeof_ca_cert_der_sign = sizeof(ca_cert_der_sign); */ const unsigned char ca_ecc_cert_der_sign[] = { - 0x07, 0xCA, 0x3B, 0x8F, 0x49, 0x26, 0x33, 0x80, 0x46, 0xFE, - 0x07, 0x91, 0x75, 0x5B, 0xC3, 0x98, 0x5F, 0x0E, 0x93, 0x0B, - 0xDF, 0x1B, 0x1B, 0x01, 0x00, 0xD0, 0x5A, 0x48, 0x81, 0x05, - 0xFC, 0x57, 0xB6, 0x0F, 0xF4, 0x6E, 0x4E, 0x7D, 0xB4, 0x14, - 0x88, 0xFF, 0x8D, 0x75, 0x7A, 0xF5, 0xDE, 0x7B, 0x74, 0xF0, - 0x98, 0x0B, 0xE2, 0x7A, 0xCB, 0xF3, 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x52, + 0xF1, 0x6F, 0x33, 0x79, 0x5A, 0xBD, 0x33, 0x95, 0xA1, 0x02, + 0x51, 0x1C, 0x48, 0x9D, 0x09, 0x96, 0x34, 0xF6, 0x4A, 0x10, + 0x7F, 0xEF, 0x5C, 0xF0, 0x61, 0xFE, 0xA4, 0xE4, 0x39, 0xAA, + 0xE8, 0x30, 0x11, 0x9E, 0x1D, 0x08, 0x5D, 0x05, 0x78, 0x27, + 0x82, 0x5E, 0xAC, 0x73, 0x0F, 0xE9, 0xC3, 0xDA, 0x57, 0x41, + 0x26, 0x02, 0x7B, 0xBA, 0x10, 0x97, 0x5D, 0x6F, 0x3E, 0xFA, + 0xEE, 0x9C, 0x34, 0x7C, 0x09, 0x32, 0xB7, 0x49, 0xC9, 0x75, + 0xA1, 0x2E, 0x94, 0x4A, 0x4F, 0xC4, 0xAF, 0xDE, 0x6C, 0x07, + 0xFE, 0x2B, 0x1D, 0x59, 0xD1, 0x7E, 0x20, 0xDF, 0x4E, 0x6D, + 0x3D, 0x2C, 0xDA, 0xFB, 0xF3, 0x88 }; static const int sizeof_ca_ecc_cert_der_sign = sizeof(ca_ecc_cert_der_sign); #endif /* USE_CERT_BUFFERS_256 */ diff --git a/IDE/Renesas/e2studio/RA6M4/test/src/test_main.c b/IDE/Renesas/e2studio/RA6M4/test/src/test_main.c index 96199642d4..a0b21c4f13 100644 --- a/IDE/Renesas/e2studio/RA6M4/test/src/test_main.c +++ b/IDE/Renesas/e2studio/RA6M4/test/src/test_main.c @@ -135,11 +135,14 @@ void sce_test(void) #if defined(WOLFSSL_RENESAS_SCEPROTECT) && defined(SCEKEY_INSTALLED) /* aes 256 */ memcpy(guser_PKCbInfo.sce_wrapped_key_aes256.value, - (uint32_t *)DIRECT_KEY_ADDRESS, HW_SCE_AES256_KEY_INDEX_WORD_SIZE*4); + (uint32_t *)DIRECT_KEY_ADDRESS_256, HW_SCE_AES256_KEY_INDEX_WORD_SIZE*4); guser_PKCbInfo.sce_wrapped_key_aes256.type = SCE_KEY_INDEX_TYPE_AES256; guser_PKCbInfo.aes256_installedkey_set = 1; /* aes 128 */ - guser_PKCbInfo.aes128_installedkey_set = 0; + memcpy(guser_PKCbInfo.sce_wrapped_key_aes128.value, + (uint32_t *)DIRECT_KEY_ADDRESS_128, HW_SCE_AES128_KEY_INDEX_WORD_SIZE*4); + guser_PKCbInfo.sce_wrapped_key_aes128.type = SCE_KEY_INDEX_TYPE_AES128; + guser_PKCbInfo.aes128_installedkey_set = 1; #endif printf("Start wolfCrypt Benchmark\n"); benchmark_test(NULL); diff --git a/wolfcrypt/src/port/Renesas/renesas_sce_aes.c b/wolfcrypt/src/port/Renesas/renesas_sce_aes.c index d45383cc42..840896dcb7 100644 --- a/wolfcrypt/src/port/Renesas/renesas_sce_aes.c +++ b/wolfcrypt/src/port/Renesas/renesas_sce_aes.c @@ -173,11 +173,19 @@ WOLFSSL_LOCAL int wc_sce_AesGcmEncrypt(struct Aes* aes, byte* out, } } - else if (info->aes256_installedkey_set == 1) { - XMEMCPY(&key_client_aes, &info->sce_wrapped_key_aes256, + else if (info->aes256_installedkey_set == 1 || info->aes128_installedkey_set == 1) { + if(aes->ctx.keySize == 32) { + XMEMCPY(&key_client_aes, &info->sce_wrapped_key_aes256, sizeof(sce_aes_wrapped_key_t)); - iv_l = iv; - ivSz_l = ivSz; + } else { + XMEMCPY(&key_client_aes, &info->sce_wrapped_key_aes128, + sizeof(sce_aes_wrapped_key_t)); + } + iv_l = iv; + ivSz_l = ivSz; + } else { + WOLFSSL_MSG("AES key for SCE is not set."); + ret = -1; } if (ret == 0) { @@ -346,11 +354,19 @@ WOLFSSL_LOCAL int wc_sce_AesGcmDecrypt(struct Aes* aes, byte* out, ret = -1; } } - else if (info->aes256_installedkey_set == 1) { - XMEMCPY(&key_server_aes, &info->sce_wrapped_key_aes256, - sizeof(sce_aes_wrapped_key_t)); + else if (info->aes256_installedkey_set == 1 || info->aes128_installedkey_set == 1) { + if(aes->ctx.keySize == 32) { + XMEMCPY(&key_server_aes, &info->sce_wrapped_key_aes256, + sizeof(sce_aes_wrapped_key_t)); + } else { + XMEMCPY(&key_server_aes, &info->sce_wrapped_key_aes128, + sizeof(sce_aes_wrapped_key_t)); + } iv_l = iv; ivSz_l = ivSz; + } else { + WOLFSSL_MSG("AES key for SCE is not set."); + ret = -1; } if (ret == 0) {