diff --git a/IDE/Renesas/e2studio/RX72N/EnvisionKit/Simple/test/.cproject b/IDE/Renesas/e2studio/RX72N/EnvisionKit/Simple/test/.cproject
index 42c63d72e..9638725c0 100644
--- a/IDE/Renesas/e2studio/RX72N/EnvisionKit/Simple/test/.cproject
+++ b/IDE/Renesas/e2studio/RX72N/EnvisionKit/Simple/test/.cproject
@@ -119,8 +119,12 @@
+
+
+
+
-
+
@@ -218,6 +222,7 @@
+
@@ -261,7 +266,7 @@
-
-
-
+
@@ -380,6 +389,7 @@
+
diff --git a/IDE/Renesas/e2studio/RX72N/EnvisionKit/Simple/test/test.scfg b/IDE/Renesas/e2studio/RX72N/EnvisionKit/Simple/test/test.scfg
index 0417e25f4..c3b4c35b7 100644
--- a/IDE/Renesas/e2studio/RX72N/EnvisionKit/Simple/test/test.scfg
+++ b/IDE/Renesas/e2studio/RX72N/EnvisionKit/Simple/test/test.scfg
@@ -366,8 +366,8 @@
-
-
+
+
@@ -950,69 +950,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1141,8 +1078,8 @@
-
-
+
+
@@ -1184,7 +1121,7 @@
-
+
@@ -1192,6 +1129,78 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/IDE/Renesas/e2studio/RX72N/EnvisionKit/wolfssl_demo/wolfssl_tsip_unit_test.c b/IDE/Renesas/e2studio/RX72N/EnvisionKit/wolfssl_demo/wolfssl_tsip_unit_test.c
index 66569085c..e43795a90 100644
--- a/IDE/Renesas/e2studio/RX72N/EnvisionKit/wolfssl_demo/wolfssl_tsip_unit_test.c
+++ b/IDE/Renesas/e2studio/RX72N/EnvisionKit/wolfssl_demo/wolfssl_tsip_unit_test.c
@@ -44,6 +44,7 @@
#include
#endif
#include
+WOLFSSL_API int wc_CryptoCb_CryptInitRenesasCmn(struct WOLFSSL* ssl, void* ctx);
#ifdef FREERTOS
#include "FreeRTOS.h"
@@ -71,27 +72,27 @@
else \
printf(" failed \n");
#ifdef FREERTOS
-static xSemaphoreHandle exit_semaph;
-static byte exit_loop = 0;
-static byte sha_multTst_rslt = 0;
-static byte sha256_multTst_rslt = 0;
-static byte Aes128_Cbc_multTst_rslt = 0;
-static byte Aes256_Cbc_multTst_rslt = 0;
-static byte Aes128_Gcm_multTst_rslt = 0;
-static byte Aes256_Gcm_multTst_rslt = 0;
+ static xSemaphoreHandle exit_semaph;
+ static byte exit_loop = 0;
+ static byte sha_multTst_rslt = 0;
+ static byte sha256_multTst_rslt = 0;
+ static byte Aes128_Cbc_multTst_rslt = 0;
+ static byte Aes256_Cbc_multTst_rslt = 0;
+ static byte Aes128_Gcm_multTst_rslt = 0;
+ static byte Aes256_Gcm_multTst_rslt = 0;
#endif /* FREERTOS */
#if defined(HAVE_AES_CBC)
-# if defined(WOLFSSL_AES_128)
- static tsip_aes_key_index_t g_user_aes128_key_index1;
- static tsip_aes_key_index_t g_user_aes128_key_index2;
-# endif
+ #if defined(WOLFSSL_AES_128)
+ static tsip_aes_key_index_t g_user_aes128_key_index1;
+ static tsip_aes_key_index_t g_user_aes128_key_index2;
+ #endif
-# if defined(WOLFSSL_AES_256)
- static tsip_aes_key_index_t g_user_aes256_key_index1;
- static tsip_aes_key_index_t g_user_aes256_key_index2;
-# endif
+ #if defined(WOLFSSL_AES_256)
+ static tsip_aes_key_index_t g_user_aes256_key_index1;
+ static tsip_aes_key_index_t g_user_aes256_key_index2;
+ #endif
#endif
@@ -107,23 +108,73 @@ typedef struct tagInfo
void Clr_CallbackCtx(TsipUserCtx *g)
{
- XFREE(g->rsa1024pri_keyIdx, NULL, DYNAMIC_TYPE_TMP_BUFFER);
-
- XFREE(g->rsa1024pub_keyIdx, NULL, DYNAMIC_TYPE_TMP_BUFFER);
-
- XFREE(g->rsa2048pri_keyIdx, NULL, DYNAMIC_TYPE_TMP_BUFFER);
-
- XFREE(g->rsa2048pub_keyIdx, NULL, DYNAMIC_TYPE_TMP_BUFFER);
- XMEMSET(g, 0, sizeof(TsipUserCtx));
+ #ifndef NO_RSA
+ #if defined(TSIP_RSAES_1024) && TSIP_RSAES_1024 == 1
+ XFREE(g->rsa1024pri_keyIdx, NULL, DYNAMIC_TYPE_TMP_BUFFER);
+ XFREE(g->rsa1024pub_keyIdx, NULL, DYNAMIC_TYPE_TMP_BUFFER);
+ #endif
+ #if defined(TSIP_RSAES_2048) && TSIP_RSAES_2048 == 1
+ XFREE(g->rsa2048pri_keyIdx, NULL, DYNAMIC_TYPE_TMP_BUFFER);
+ XFREE(g->rsa2048pub_keyIdx, NULL, DYNAMIC_TYPE_TMP_BUFFER);
+ #endif
+ #endif
+ XMEMSET(g, 0, sizeof(TsipUserCtx));
}
+ int TSIP_AesKeyGeneration(TsipUserCtx *g, byte sz)
+ {
+ e_tsip_err_t tsip_error_code;
+ /* Generate AES tsip Key */
+ if (sz == 16) {
+ tsip_error_code = R_TSIP_GenerateAes128RandomKeyIndex(
+ &g_user_aes128_key_index1);
+ if (tsip_error_code == TSIP_SUCCESS) {
+ XMEMCPY(&g->user_aes128_key_index, &g_user_aes128_key_index1,
+ sizeof(g_user_aes128_key_index1));
+ g->user_aes128_key_set = 1;
+ } else {
+ printf("Failed to generate Aes 256 Key Index %d\n",
+ tsip_error_code);
+ return -1;
+ }
+
+ tsip_error_code = R_TSIP_GenerateAes128RandomKeyIndex(
+ &g_user_aes128_key_index2);
+ if (tsip_error_code != TSIP_SUCCESS) {
+ printf("Failed to generate Aes 128 Key Index %d\n",
+ tsip_error_code);
+ return -1;
+ }
+ } else if (sz == 32) {
+ tsip_error_code = R_TSIP_GenerateAes256RandomKeyIndex(
+ &g_user_aes256_key_index1);
+ if (tsip_error_code == TSIP_SUCCESS) {
+ XMEMCPY(&g->user_aes256_key_index, &g_user_aes256_key_index1,
+ sizeof(g_user_aes256_key_index1));
+ g->user_aes256_key_set = 1;
+ } else {
+ printf("Failed to generate Aes 256 Key Index %d\n",
+ tsip_error_code);
+ return -1;
+ }
+
+ tsip_error_code = R_TSIP_GenerateAes256RandomKeyIndex(
+ &g_user_aes256_key_index2);
+ if (tsip_error_code != TSIP_SUCCESS) {
+ printf("Failed to generate Aes 256 Key Index %d\n",
+ tsip_error_code);
+ return -1;
+ }
+ } else
+ return -1;
+
+ return 0;
+ }
#endif
#if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
-
-static int tsip_aes_cbc_test(int prnt, tsip_aes_key_index_t* aes_key)
+static int tsip_aes128_cbc_test(int prnt, int devId)
{
-
Aes aes[1];
byte cipher[WC_AES_BLOCK_SIZE];
@@ -143,18 +194,15 @@ static int tsip_aes_cbc_test(int prnt, tsip_aes_key_index_t* aes_key)
ForceZero(plain, WC_AES_BLOCK_SIZE);
if (prnt) {
- printf(" tsip_aes_cbc_test() ");
+ printf(" tsip_aes128_cbc_test() ");
}
- ret = wc_AesInit(aes, NULL, INVALID_DEVID);
+ ret = wc_AesInit(aes, NULL, devId);
if (ret == 0) {
ret = wc_AesSetKey(aes, key, WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
- XMEMCPY(&aes->ctx.tsip_keyIdx, aes_key,
- sizeof(tsip_aes_key_index_t));
-
aes->ctx.keySize = aes->keylen;
if (ret == 0) {
- ret = wc_tsip_AesCbcEncrypt(aes, cipher, msg, WC_AES_BLOCK_SIZE);
+ ret = wc_AesCbcEncrypt(aes, cipher, msg, WC_AES_BLOCK_SIZE);
}
wc_AesFree(aes);
@@ -165,14 +213,11 @@ static int tsip_aes_cbc_test(int prnt, tsip_aes_key_index_t* aes_key)
#ifdef HAVE_AES_DECRYPT
if (ret == 0)
- ret = wc_AesInit(aes, NULL, INVALID_DEVID);
+ ret = wc_AesInit(aes, NULL, devId);
if (ret == 0) {
ret = wc_AesSetKey(aes, key, WC_AES_BLOCK_SIZE, iv, AES_DECRYPTION);
- XMEMCPY(&aes->ctx.tsip_keyIdx, aes_key,
- sizeof(tsip_aes_key_index_t));
- aes->ctx.keySize = aes->keylen;
if (ret == 0)
- ret = wc_tsip_AesCbcDecrypt(aes, plain, cipher, WC_AES_BLOCK_SIZE);
+ ret = wc_AesCbcDecrypt(aes, plain, cipher, WC_AES_BLOCK_SIZE);
wc_AesFree(aes);
}
@@ -194,7 +239,7 @@ static int tsip_aes_cbc_test(int prnt, tsip_aes_key_index_t* aes_key)
#if defined(WOLFSSL_AES_COUNTER)
#if (defined(TSIP_AES_128_CTR) && TSIP_AES_128_CTR == 1) &&\
(defined(WOLFSSL_AES_128))
-static int tsip_aes128_ctr_test(int prnt, tsip_aes_key_index_t* aes_key)
+static int tsip_aes128_ctr_test(int prnt, int devId)
{
int ret;
Aes *enc = NULL;
@@ -250,6 +295,18 @@ static int tsip_aes128_ctr_test(int prnt, tsip_aes_key_index_t* aes_key)
0xd3,0xda,0xe1,0x5b,0x04,0xbb,0x35,0x2f,
0xa0,0xf5,0x9f,0xeb,0xfc,0xb4,0xda,0x3e
};
+ WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
+ {
+ 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
+ 0xc2
+ };
+ WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128Cipher[] =
+ {
+ 0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
+ 0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
+ 0xd3,0xda,0xe1,0x5b,0x04
+ };
+
int i;
struct {
const byte* key;
@@ -261,6 +318,14 @@ static int tsip_aes128_ctr_test(int prnt, tsip_aes_key_index_t* aes_key)
} testVec[] = {
{ ctr128Key, (int)sizeof(ctr128Key), ctrIv,
ctrPlain, (int)sizeof(ctrPlain), ctr128Cipher },
+ /* let's try with just 9 bytes, non block size test */
+ { ctr128Key, (int)sizeof(ctr128Key), ctrIv,
+ ctrPlain, (int)sizeof(oddCipher), ctr128Cipher },
+ /* and an additional 9 bytes to reuse tmp left buffer */
+ { NULL, 0, NULL, ctrPlain, (int)sizeof(oddCipher), oddCipher },
+ /* Counter wrapping */
+ { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
+ ctrPlain, (int)sizeof(ctr128Wrap128Cipher), ctr128Wrap128Cipher },
{ ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
ctrPlain, (int)sizeof(ctr128Wrap128CipherLong),
ctr128Wrap128CipherLong },
@@ -270,33 +335,17 @@ static int tsip_aes128_ctr_test(int prnt, tsip_aes_key_index_t* aes_key)
if (prnt)
printf(" tsip_aes128_ctr_test() ");
- enc = wc_AesNew(NULL, INVALID_DEVID, &ret);
+ enc = wc_AesNew(NULL, devId, &ret);
if (enc == NULL){
ret = -1;
goto out;
}
- dec = wc_AesNew(NULL, INVALID_DEVID, &ret);
+ dec = wc_AesNew(NULL, devId, &ret);
if (dec == NULL){
ret = -2;
goto out;
}
- /* test failure cases - null */
- ret = wc_tsip_AesCtr(NULL, NULL, NULL, 1);
- if (ret != BAD_FUNC_ARG) {
- ret = -8; goto out;
- }
- /* test failure cases - size, but no buffer */
- ret = wc_tsip_AesCtr(enc, NULL, NULL, 1);
- if (ret != BAD_FUNC_ARG) {
- ret = -9; goto out;
- }
- /* test failure cases - non block aligned */
- ret = wc_tsip_AesCtr(enc, plain, cipher, 15);
- if (ret != BAD_FUNC_ARG) {
- ret = -10; goto out;
- }
-
for (i = 0; i < AES_CTR_TEST_LEN; i++) {
if (testVec[i].key != NULL) {
ret = wc_AesSetKeyDirect(enc, testVec[i].key, (word32)testVec[i].keySz,
@@ -305,11 +354,6 @@ static int tsip_aes128_ctr_test(int prnt, tsip_aes_key_index_t* aes_key)
if (ret != 0) {
ret = -3;
goto out;
- } else {
- /* set TSIP Aes key */
- XMEMCPY(&enc->ctx.tsip_keyIdx, aes_key,
- sizeof(tsip_aes_key_index_t));
- enc->ctx.keySize = enc->keylen;
}
/* Ctr only uses encrypt, even on key setup */
ret = wc_AesSetKeyDirect(dec, testVec[i].key, (word32)testVec[i].keySz,
@@ -317,19 +361,15 @@ static int tsip_aes128_ctr_test(int prnt, tsip_aes_key_index_t* aes_key)
if (ret != 0) {
ret = -4;
goto out;
- } else {
- XMEMCPY(&dec->ctx.tsip_keyIdx, aes_key,
- sizeof(tsip_aes_key_index_t));
- dec->ctx.keySize = dec->keylen;
}
}
- ret = wc_tsip_AesCtr(enc, cipher, testVec[i].plain, (word32)testVec[i].len);
+ ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, (word32)testVec[i].len);
if (ret != 0) {
ret = -5;
goto out;
}
- ret = wc_tsip_AesCtr(dec, plain, cipher, (word32)testVec[i].len);
+ ret = wc_AesCtrEncrypt(dec, plain, cipher, (word32)testVec[i].len);
if (ret != 0) {
ret = -6;
goto out;
@@ -349,7 +389,7 @@ out:
#endif /* WOLFSSL_AES_128 */
#if (defined(TSIP_AES_256_CTR) && TSIP_AES_256_CTR == 1) &&\
(defined(WOLFSSL_AES_256))
-static int tsip_aes256_ctr_test(int prnt, tsip_aes_key_index_t* aes_key)
+static int tsip_aes256_ctr_test(int prnt, int devId)
{
int ret;
Aes *enc = NULL;
@@ -407,7 +447,17 @@ static int tsip_aes256_ctr_test(int prnt, tsip_aes_key_index_t* aes_key)
0x4b,0x45,0x7c,0xd6,0x8a,0xcc,0xda,0x4a,
0x89,0xfa,0x23,0x6c,0x06,0xbf,0x26,0x05
};
-
+ WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
+ {
+ 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
+ 0xc2
+ };
+ WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128Cipher[] =
+ {
+ 0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
+ 0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
+ 0x4b,0x45,0x7c,0xd6,0x8a
+ };
int i;
struct {
const byte* key;
@@ -419,6 +469,12 @@ static int tsip_aes256_ctr_test(int prnt, tsip_aes_key_index_t* aes_key)
} testVec[] = {
{ ctr256Key, (int)sizeof(ctr256Key), ctrIv,
ctrPlain, (int)sizeof(ctrPlain), ctr256Cipher },
+ /* let's try with just 9 bytes, non block size test */
+ { ctr256Key, (int)sizeof(ctr256Key), ctrIv,
+ ctrPlain, (int)sizeof(oddCipher), ctr256Cipher },
+ /* Counter wrapping */
+ { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
+ ctrPlain, (int)sizeof(ctr256Wrap128Cipher), ctr256Wrap128Cipher },
{ ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
ctrPlain, (int)sizeof(ctr256Wrap128CipherLong),
ctr256Wrap128CipherLong },
@@ -428,33 +484,17 @@ static int tsip_aes256_ctr_test(int prnt, tsip_aes_key_index_t* aes_key)
if (prnt)
printf(" tsip_aes256_ctr_test() ");
- enc = wc_AesNew(NULL, INVALID_DEVID, &ret);
+ enc = wc_AesNew(NULL, devId, &ret);
if (enc == NULL){
ret = -1;
goto out;
}
- dec = wc_AesNew(NULL, INVALID_DEVID, &ret);
+ dec = wc_AesNew(NULL, devId, &ret);
if (dec == NULL){
ret = -2;
goto out;
}
- /* test failure cases - null */
- ret = wc_tsip_AesCtr(NULL, NULL, NULL, 1);
- if (ret != BAD_FUNC_ARG) {
- ret = -8; goto out;
- }
- /* test failure cases - size, but no buffer */
- ret = wc_tsip_AesCtr(enc, NULL, NULL, 1);
- if (ret != BAD_FUNC_ARG) {
- ret = -9; goto out;
- }
- /* test failure cases - non block aligned */
- ret = wc_tsip_AesCtr(enc, plain, cipher, 15);
- if (ret != BAD_FUNC_ARG) {
- ret = -10; goto out;
- }
-
for (i = 0; i < AES_CTR_TEST_LEN; i++) {
if (testVec[i].key != NULL) {
ret = wc_AesSetKeyDirect(enc, testVec[i].key, (word32)testVec[i].keySz,
@@ -462,11 +502,6 @@ static int tsip_aes256_ctr_test(int prnt, tsip_aes_key_index_t* aes_key)
if (ret != 0) {
ret = -3;
goto out;
- } else {
- /* set TSIP Aes key */
- XMEMCPY(&enc->ctx.tsip_keyIdx, aes_key,
- sizeof(tsip_aes_key_index_t));
- enc->ctx.keySize = enc->keylen;
}
/* Ctr only uses encrypt, even on key setup */
ret = wc_AesSetKeyDirect(dec, testVec[i].key, (word32)testVec[i].keySz,
@@ -474,20 +509,15 @@ static int tsip_aes256_ctr_test(int prnt, tsip_aes_key_index_t* aes_key)
if (ret != 0) {
ret = -4;
goto out;
- } else {
- /* set TSIP Aes key */
- XMEMCPY(&dec->ctx.tsip_keyIdx, aes_key,
- sizeof(tsip_aes_key_index_t));
- dec->ctx.keySize = enc->keylen;
}
}
- ret = wc_tsip_AesCtr(enc, cipher, testVec[i].plain, (word32)testVec[i].len);
+ ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, (word32)testVec[i].len);
if (ret != 0) {
ret = -5;
goto out;
}
- ret = wc_tsip_AesCtr(dec, plain, cipher, (word32)testVec[i].len);
+ ret = wc_AesCtrEncrypt(dec, plain, cipher, (word32)testVec[i].len);
if (ret != 0) {
ret = -6;
goto out;
@@ -529,7 +559,7 @@ static void tskAes128_Cbc_Test(void *pvParam)
#endif
#ifdef WOLFSSL_AES_256
-static int tsip_aes256_test(int prnt, tsip_aes_key_index_t* aes_key)
+static int tsip_aes256_cbc_test(int prnt, int devId)
{
Aes enc[1];
byte cipher[WC_AES_BLOCK_SIZE];
@@ -563,14 +593,14 @@ static int tsip_aes256_test(int prnt, tsip_aes_key_index_t* aes_key)
(void)verify;
if (prnt)
- printf(" tsip_aes256_test() ");
+ printf(" tsip_aes256_cbc_test() ");
- if (wc_AesInit(enc, NULL, INVALID_DEVID) != 0) {
+ if (wc_AesInit(enc, NULL, devId) != 0) {
ret = -1;
goto out;
}
- if (wc_AesInit(dec, NULL, INVALID_DEVID) != 0){
+ if (wc_AesInit(dec, NULL, devId) != 0){
ret = -2;
goto out;
}
@@ -579,24 +609,16 @@ static int tsip_aes256_test(int prnt, tsip_aes_key_index_t* aes_key)
if (ret != 0){
ret = -3;
goto out;
- } else {
- XMEMCPY(&enc->ctx.tsip_keyIdx, aes_key,
- sizeof(tsip_aes_key_index_t));
- enc->ctx.keySize = enc->keylen;
}
ret = wc_AesSetKey(dec, key, (int) sizeof(key), iv, AES_DECRYPTION);
if (ret != 0) {
ret = -4;
goto out;
- } else {
- XMEMCPY(&dec->ctx.tsip_keyIdx, aes_key,
- sizeof(tsip_aes_key_index_t));
- dec->ctx.keySize = dec->keylen;
}
ForceZero(cipher, WC_AES_BLOCK_SIZE);
- ret = wc_tsip_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
+ ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
if (ret != 0) {
ret = -5;
@@ -604,7 +626,7 @@ static int tsip_aes256_test(int prnt, tsip_aes_key_index_t* aes_key)
}
ForceZero(plain, WC_AES_BLOCK_SIZE);
- ret = wc_tsip_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
+ ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
if (ret != 0){
ret = -6;
@@ -647,12 +669,10 @@ static void tskAes256_Cbc_Test(void *pvParam)
#endif /* WOLFSSL_AES_256 */
#if defined(WOLFSSL_AES_256)
-static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
+static int tsip_aesgcm256_test(int prnt, int devId)
{
Aes enc[1];
Aes dec[1];
- TsipUserCtx userContext;
-
/*
* This is Test Case 16 from the document Galois/
@@ -727,13 +747,12 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
XMEMSET(resultT, 0, sizeof(resultT));
XMEMSET(resultC, 0, sizeof(resultC));
XMEMSET(resultP, 0, sizeof(resultP));
- XMEMSET(&userContext, 0, sizeof(TsipUserCtx));
- if (wc_AesInit(enc, NULL, INVALID_DEVID) != 0) {
+ if (wc_AesInit(enc, NULL, devId) != 0) {
ret = -1;
goto out;
}
- if (wc_AesInit(dec, NULL, INVALID_DEVID) != 0) {
+ if (wc_AesInit(dec, NULL, devId) != 0) {
ret = -2;
goto out;
}
@@ -742,19 +761,13 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
if (result != 0) {
ret = -3;
goto out;
- } else {
- XMEMCPY(&userContext.user_aes256_key_index, aes256_key,
- sizeof(tsip_aes_key_index_t));
- userContext.user_aes256_key_set = 1;
- enc->ctx.keySize = enc->keylen;
}
/* AES-GCM encrypt and decrypt both use AES encrypt internally */
- result = wc_tsip_AesGcmEncrypt(enc,
+ result = wc_AesGcmEncrypt(enc,
resultC, p, sizeof(p),
(byte*)iv1, sizeof(iv1), resultT, sizeof(resultT),
- a, sizeof(a), &userContext
- );
+ a, sizeof(a));
if (result != 0) {
ret = -4;
goto out;
@@ -768,11 +781,10 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
dec->ctx.keySize = enc->keylen;
}
- result = wc_tsip_AesGcmDecrypt(dec,
+ result = wc_AesGcmDecrypt(dec,
resultP, resultC, sizeof(c1),
iv1, sizeof(iv1), resultT, sizeof(resultT),
- a, sizeof(a), &userContext
- );
+ a, sizeof(a));
if (result != 0){
ret = -8;
goto out;
@@ -788,21 +800,19 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
wc_AesGcmSetKey(enc, k1, sizeof(k1));
/* AES-GCM encrypt and decrypt both use AES encrypt internally */
- result = wc_tsip_AesGcmEncrypt(enc,
+ result = wc_AesGcmEncrypt(enc,
resultC, p, sizeof(p), iv1, sizeof(iv1),
resultT + 1, sizeof(resultT) - 1,
- a, sizeof(a), &userContext
- );
+ a, sizeof(a));
if (result != 0) {
ret = -10;
goto out;
}
- result = wc_tsip_AesGcmDecrypt(enc,
+ result = wc_AesGcmDecrypt(enc,
resultP, resultC, sizeof(p),
iv1, sizeof(iv1), resultT + 1, sizeof(resultT) - 1,
- a, sizeof(a), &userContext
- );
+ a, sizeof(a));
if (result != 0) {
ret = -11;
goto out;
@@ -847,11 +857,10 @@ static void tskAes256_Gcm_Test(void *pvParam)
#if defined(WOLFSSL_AES_128) && defined(HAVE_AESGCM)
-static int tsip_aesgcm128_test(int prnt, tsip_aes_key_index_t* aes128_key)
+static int tsip_aesgcm128_test(int prnt, int devId)
{
Aes enc[1];
Aes dec[1];
- TsipUserCtx userContext;
/* The following is an interesting test case from the example
* FIPS test vectors for AES-GCM. IVlen = 1 byte */
@@ -906,14 +915,13 @@ static int tsip_aesgcm128_test(int prnt, tsip_aes_key_index_t* aes128_key)
XMEMSET(resultT, 0, sizeof(resultT));
XMEMSET(resultC, 0, sizeof(resultC));
XMEMSET(resultP, 0, sizeof(resultP));
- XMEMSET(&userContext, 0, sizeof(TsipUserCtx));
- if (wc_AesInit(enc, NULL, INVALID_DEVID) != 0) {
+ if (wc_AesInit(enc, NULL, devId) != 0) {
ret = -1;
goto out;
}
- if (wc_AesInit(dec, NULL, INVALID_DEVID) != 0) {
+ if (wc_AesInit(dec, NULL, devId) != 0) {
ret = -2;
goto out;
}
@@ -922,29 +930,17 @@ static int tsip_aesgcm128_test(int prnt, tsip_aes_key_index_t* aes128_key)
if (result != 0) {
ret = -3;
goto out;
- } else {
- XMEMCPY(&userContext.user_aes128_key_index, aes128_key,
- sizeof(tsip_aes_key_index_t));
- userContext.user_aes128_key_set = 1;
- enc->ctx.keySize = enc->keylen;
}
/* AES-GCM encrypt and decrypt both use AES encrypt internally */
- result = wc_tsip_AesGcmEncrypt(enc,
- resultC, p3, sizeof(p3),
- iv3, sizeof(iv3),
- resultT, sizeof(t3),
- a3, sizeof(a3), &userContext
- );
+ result = wc_AesGcmEncrypt(enc,resultC, p3, sizeof(p3), iv3, sizeof(iv3),
+ resultT, sizeof(t3),a3, sizeof(a3));
if (result != 0) {
ret = -4;
goto out;
}
- result = wc_tsip_AesGcmDecrypt(enc,
- resultP, resultC, sizeof(c3),
- iv3, sizeof(iv3), resultT, sizeof(resultT),
- a3, sizeof(a3), &userContext
- );
+ result = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c3),
+ iv3, sizeof(iv3), resultT, sizeof(resultT), a3, sizeof(a3));
if (result != 0) {
ret = -5;
goto out;
@@ -1031,7 +1027,7 @@ static void tskSha256_Test(void *pvParam)
#endif
#endif /* FREERTOS */
-#if !defined(NO_RSA)
+#if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
/* testing rsa sign/verify w/ rsa 2048 bit key */
#define TEST_STRING "Everyone gets Friday off."
@@ -1513,90 +1509,91 @@ int tsip_crypt_Sha_AesCbcGcm_multitest(void)
int tsip_crypt_test(void)
{
int ret = 0;
- e_tsip_err_t tsip_error_code;
+ int devId;
- /* Generate AES tsip Key */
- tsip_error_code = R_TSIP_GenerateAes128RandomKeyIndex(
- &g_user_aes128_key_index1);
+ Clr_CallbackCtx(&userContext);
+ if (ret != 0) {
+ printf("TSIP Key Generation failed\n");
+ return -1;
+ }
- if (tsip_error_code == TSIP_SUCCESS)
- tsip_error_code = R_TSIP_GenerateAes128RandomKeyIndex(
- &g_user_aes128_key_index2);
+ devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &userContext);
+ if (devId > 0){
+ ret = 0;
+ }
- if (tsip_error_code == TSIP_SUCCESS)
- tsip_error_code = R_TSIP_GenerateAes256RandomKeyIndex(
- &g_user_aes256_key_index1);
-
- if (tsip_error_code == TSIP_SUCCESS)
- tsip_error_code = R_TSIP_GenerateAes256RandomKeyIndex(
- &g_user_aes256_key_index2);
-
- if (tsip_error_code == TSIP_SUCCESS) {
-
- #ifndef NO_SHA
+ if (ret == 0) {
+ #ifndef NO_SHA
printf(" sha_test()");
ret = sha_test();
- RESULT_STR(ret)
- #endif
+ RESULT_STR(ret);
+ #endif
- #ifndef NO_SHA256
+ #ifndef NO_SHA256
printf(" sha256_test()");
- ret = sha256_test();
- RESULT_STR(ret)
- #endif
-
- ret = tsip_aes_cbc_test(1, &g_user_aes128_key_index1);
-
if (ret == 0) {
-
- ret = tsip_aes256_test(1, &g_user_aes256_key_index1);
-
+ ret = sha256_test();
+ RESULT_STR(ret);
}
+ #endif
-#ifdef HAVE_AESGCM
- if (ret == 0) {
-
- ret = tsip_aesgcm128_test(1, &g_user_aes128_key_index1);
-
- }
-
- if (ret == 0) {
-
- ret = tsip_aesgcm256_test(1, &g_user_aes256_key_index1);
-
- }
-#endif
-#ifdef WOLFSSL_AES_COUNTER
- if (ret == 0) {
- ret = tsip_aes128_ctr_test(1, &g_user_aes128_key_index1);
- RESULT_STR(ret)
- }
-
- if (ret == 0) {
- ret = tsip_aes256_ctr_test(1, &g_user_aes256_key_index1);
- RESULT_STR(ret)
- }
-#endif
-#if defined(WOLFSSL_KEY_GEN) && \
- defined(WOLFSSL_RENESAS_TSIP_CRYPTONLY)
-
+ #ifdef HAVE_AES_CBC
+ ret = TSIP_AesKeyGeneration(&userContext, 16);
+ if (ret == 0)
+ ret = tsip_aes128_cbc_test(1, devId);
if (ret == 0) {
Clr_CallbackCtx(&userContext);
-
- ret = wc_CryptoCb_CryptInitRenesasCmn(NULL, &userContext);
-
- if (ret > 0)
- ret = 0;
+ ret = TSIP_AesKeyGeneration(&userContext, 32);
+ if (ret == 0)
+ ret = tsip_aes256_cbc_test(1, devId);
}
+ #endif
-#if RSA_MIN_SIZE <= 1024
+ #ifdef HAVE_AESGCM
+ if (ret == 0) {
+ Clr_CallbackCtx(&userContext);
+ ret = TSIP_AesKeyGeneration(&userContext, 16);
+ if (ret == 0)
+ ret = tsip_aesgcm128_test(1, devId);
+ }
+ if (ret == 0) {
+ Clr_CallbackCtx(&userContext);
+ ret = TSIP_AesKeyGeneration(&userContext, 32);
+ if (ret == 0)
+ ret = tsip_aesgcm256_test(1, devId);
+ }
+ #endif
+
+ #if defined(WOLFSSL_AES_COUNTER) &&\
+ (defined(TSIP_AES_128_CTR) && TSIP_AES_128_CTR == 1)
+ #if defined(WOLFSSL_AES_128)
+ Clr_CallbackCtx(&userContext);
+ ret = TSIP_AesKeyGeneration(&userContext, 16);
+ if (ret == 0) {
+ ret = tsip_aes128_ctr_test(1, devId);
+ RESULT_STR(ret);
+ }
+ #endif
+ #if defined(WOLFSSL_AES_256)
+ Clr_CallbackCtx(&userContext);
+ ret = TSIP_AesKeyGeneration(&userContext, 32);
+ if (ret == 0) {
+ ret = tsip_aes256_ctr_test(1, devId);
+ RESULT_STR(ret);
+ }
+ #endif
+ #endif
+
+ #if defined(WOLFSSL_KEY_GEN) && \
+ defined(WOLFSSL_RENESAS_TSIP_CRYPTONLY)
+ #if RSA_MIN_SIZE <= 1024
if (ret == 0) {
userContext.wrappedKeyType = TSIP_KEY_TYPE_RSA1024;
printf(" tsip_rsa_test(1024)");
ret = tsip_rsa_test(1, 1024);
RESULT_STR(ret)
}
-#endif
+ #endif
if (ret == 0) {
userContext.wrappedKeyType = TSIP_KEY_TYPE_RSA2048;
printf(" tsip_rsa_test(2048)");
@@ -1605,7 +1602,7 @@ int tsip_crypt_test(void)
}
-#if RSA_MIN_SIZE <= 1024
+ #if RSA_MIN_SIZE <= 1024
if (ret == 0) {
printf(" tsip_rsa_SignVerify_test(1024)");
@@ -1618,7 +1615,7 @@ int tsip_crypt_test(void)
}
Clr_CallbackCtx(&userContext);
-#endif
+ #endif
if (ret == 0) {
printf(" tsip_rsa_SignVerify_test(2048)");
diff --git a/wolfcrypt/src/port/Renesas/renesas_common.c b/wolfcrypt/src/port/Renesas/renesas_common.c
index eacdca52d..b02e93eac 100644
--- a/wolfcrypt/src/port/Renesas/renesas_common.c
+++ b/wolfcrypt/src/port/Renesas/renesas_common.c
@@ -181,68 +181,7 @@ static int Renesas_cmn_CryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
if (info->algo_type == WC_ALGO_TYPE_CIPHER) {
#if !defined(NO_AES)
- #ifdef HAVE_AESGCM
- if (info->cipher.type == WC_CIPHER_AES_GCM
- #ifdef WOLFSSL_RENESAS_TSIP_TLS
- && cbInfo->session_key_set == 1
- #endif
- ) {
-
- if (info->cipher.enc) {
- ret = wc_tsip_AesGcmEncrypt(
- info->cipher.aesgcm_enc.aes,
- (byte*)info->cipher.aesgcm_enc.out,
- (byte*)info->cipher.aesgcm_enc.in,
- info->cipher.aesgcm_enc.sz,
- (byte*)info->cipher.aesgcm_enc.iv,
- info->cipher.aesgcm_enc.ivSz,
- (byte*)info->cipher.aesgcm_enc.authTag,
- info->cipher.aesgcm_enc.authTagSz,
- (byte*)info->cipher.aesgcm_enc.authIn,
- info->cipher.aesgcm_enc.authInSz,
- (void*)ctx);
-
- }
- else {
- ret = wc_tsip_AesGcmDecrypt(
- info->cipher.aesgcm_dec.aes,
- (byte*)info->cipher.aesgcm_dec.out,
- (byte*)info->cipher.aesgcm_dec.in,
- info->cipher.aesgcm_dec.sz,
- (byte*)info->cipher.aesgcm_dec.iv,
- info->cipher.aesgcm_dec.ivSz,
- (byte*)info->cipher.aesgcm_dec.authTag,
- info->cipher.aesgcm_dec.authTagSz,
- (byte*)info->cipher.aesgcm_dec.authIn,
- info->cipher.aesgcm_dec.authInSz,
- (void*)ctx);
- }
- }
- #endif /* HAVE_AESGCM */
- #ifdef HAVE_AES_CBC
- if (info->cipher.type == WC_CIPHER_AES_CBC
- #ifdef WOLFSSL_RENESAS_TSIP_TLS
- && cbInfo->session_key_set == 1
- #endif
- ) {
-
- if (info->cipher.enc) {
- ret = wc_tsip_AesCbcEncrypt(
- info->cipher.aescbc.aes,
- (byte*)info->cipher.aescbc.out,
- (byte*)info->cipher.aescbc.in,
- info->cipher.aescbc.sz);
-
- }
- else {
- ret = wc_tsip_AesCbcDecrypt(
- info->cipher.aescbc.aes,
- (byte*)info->cipher.aescbc.out,
- (byte*)info->cipher.aescbc.in,
- info->cipher.aescbc.sz);
- }
- }
- #endif /* HAVE_AES_CBC */
+ ret = wc_tsip_AesCipher(devIdArg, info, ctx);
#endif /* !NO_AES */
}
diff --git a/wolfcrypt/src/port/Renesas/renesas_tsip_aes.c b/wolfcrypt/src/port/Renesas/renesas_tsip_aes.c
index 020eb001e..0ecbb58ca 100644
--- a/wolfcrypt/src/port/Renesas/renesas_tsip_aes.c
+++ b/wolfcrypt/src/port/Renesas/renesas_tsip_aes.c
@@ -383,6 +383,50 @@ WOLFSSL_LOCAL int tsip_Tls13AesDecrypt(
#if (WOLFSSL_RENESAS_TSIP_VER >= 109)
#ifdef WOLF_CRYPTO_CB
+static int _tsip_cpAesKeyIndex2AesCtx(wc_CryptoInfo* info, TsipUserCtx* cb)
+{
+ Aes* aes = NULL;
+
+ if (!info || !cb)
+ return -1;
+
+ switch(info->cipher.type) {
+ #ifdef HAVE_AESGCM
+ case WC_CIPHER_AES_GCM:
+ if (info->cipher.enc)
+ aes = info->cipher.aesgcm_enc.aes;
+ else
+ aes = info->cipher.aesgcm_dec.aes;
+ break;
+ #endif
+ #ifdef HAVE_AES_CBC
+ case WC_CIPHER_AES_CBC:
+ aes = info->cipher.aescbc.aes;
+ break;
+ #endif
+ #ifdef WOLFSSL_AES_COUNTER
+ case WC_CIPHER_AES_CTR:
+ aes = info->cipher.aesctr.aes;
+ break;
+ #endif
+ default:
+ break;
+ }
+
+ if (aes && cb->user_aes256_key_set == 1) {
+ XMEMCPY(&aes->ctx.tsip_keyIdx,&cb->user_aes256_key_index,
+ sizeof(tsip_aes_key_index_t));
+ aes->ctx.keySize = 32;
+ }else if (aes && cb->user_aes128_key_set == 1) {
+ XMEMCPY(&aes->ctx.tsip_keyIdx,&cb->user_aes128_key_index,
+ sizeof(tsip_aes_key_index_t));
+ aes->ctx.keySize = 16;
+ } else
+ return -1;
+
+ return 0;
+}
+
int wc_tsip_AesCipher(int devIdArg, wc_CryptoInfo* info, void* ctx)
{
int ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
@@ -404,7 +448,12 @@ int wc_tsip_AesCipher(int devIdArg, wc_CryptoInfo* info, void* ctx)
&& cbInfo != NULL && cbInfo->session_key_set == 1
#endif
) {
-
+ ret = _tsip_cpAesKeyIndex2AesCtx(info, cbInfo);
+ if (ret != 0) {
+ WOLFSSL_MSG("Failed to copy Aes Key Index from "
+ "UserCtx to AES Ctx");
+ return ret;
+ }
if (info->cipher.enc) {
ret = wc_tsip_AesGcmEncrypt(
info->cipher.aesgcm_enc.aes,
@@ -443,12 +492,21 @@ int wc_tsip_AesCipher(int devIdArg, wc_CryptoInfo* info, void* ctx)
&& cbInfo != NULL && cbInfo->session_key_set == 1
#endif
) {
- /* encrypt and decrypt use same routine */
- ret = wc_tsip_AesCtr(
- info->cipher.aesctr.aes,
- (byte*)info->cipher.aesctr.out,
- (byte*)info->cipher.aesctr.in,
- info->cipher.aesctr.sz);
+ int remain = (int)(info->cipher.aesctr.sz % WC_AES_BLOCK_SIZE);
+ if (remain == 0) {
+ ret = _tsip_cpAesKeyIndex2AesCtx(info, cbInfo);
+ if (ret != 0) {
+ WOLFSSL_MSG("Failed to copy Aes Key Index from "
+ "UserCtx to AES Ctx");
+ return ret;
+ }
+ /* encrypt and decrypt use same routine */
+ ret = wc_tsip_AesCtr(
+ info->cipher.aesctr.aes,
+ (byte*)info->cipher.aesctr.out,
+ (byte*)info->cipher.aesctr.in,
+ info->cipher.aesctr.sz);
+ }
}
#endif /* WOLFSSL_AES_COUNTER */
@@ -458,7 +516,12 @@ int wc_tsip_AesCipher(int devIdArg, wc_CryptoInfo* info, void* ctx)
&& cbInfo != NULL && cbInfo->session_key_set == 1
#endif
) {
-
+ ret = _tsip_cpAesKeyIndex2AesCtx(info, cbInfo);
+ if (ret != 0) {
+ WOLFSSL_MSG("Failed to copy Aes Key Index from "
+ "UserCtx to AES Ctx");
+ return ret;
+ }
if (info->cipher.enc) {
ret = wc_tsip_AesCbcEncrypt(
info->cipher.aescbc.aes,