Skip to content

Commit a2776ad

Browse files
committed
addressed review comments
1 parent 4fd629d commit a2776ad

9 files changed

Lines changed: 247 additions & 170 deletions

File tree

IDE/Renesas/e2studio/RA6M4/test/src/test_main.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void Clr_CallbackCtx(User_SCEPKCbInfo *g)
135135
NULL, DYNAMIC_TYPE_TMP_BUFFER);
136136

137137
if (g->sce_wrapped_key_aes128 != NULL)
138-
XFREE(g->sce_wrapped_key_aes256,
138+
XFREE(g->sce_wrapped_key_aes128,
139139
NULL, DYNAMIC_TYPE_TMP_BUFFER);
140140

141141
#if defined(WOLFSSL_RENESAS_SCEPROTECT_CRYPTONLY)
@@ -220,6 +220,8 @@ void sce_test(void)
220220
printf("wolfCrypt_Cleanup failed %d\n", ret);
221221
}
222222

223+
Clr_CallbackCtx(&guser_PKCbInfo);
224+
223225
#elif defined(BENCHMARK) && \
224226
(defined(WOLFSSL_RENESAS_SCEPROTECT) || \
225227
defined(WOLFSSL_RENESAS_SCEPROTECT_CRYPTONLY))
@@ -253,21 +255,24 @@ void sce_test(void)
253255
(uint32_t *)DIRECT_KEY_ADDRESS_256,
254256
HW_SCE_AES256_KEY_INDEX_WORD_SIZE*4);
255257
p1->type = SCE_KEY_INDEX_TYPE_AES256;
256-
guser_PKCbInfo.flags2.bits.aes256_installedkey_set = 1;
258+
guser_PKCbInfo.keyflgs_crypt.bits.aes256_installedkey_set = 1;
257259

258260
/* aes 128 */
259261
memcpy(p2->value,
260262
(uint32_t *)DIRECT_KEY_ADDRESS_128,
261263
HW_SCE_AES128_KEY_INDEX_WORD_SIZE*4);
262264

263265
p2->type = SCE_KEY_INDEX_TYPE_AES128;
264-
guser_PKCbInfo.flags2.bits.aes128_installedkey_set = 1;
266+
guser_PKCbInfo.keyflgs_crypt.bits.aes128_installedkey_set = 1;
265267
}
266268
#endif
267269
printf("Start wolfCrypt Benchmark\n");
268270
benchmark_test(NULL);
269271
printf("End wolfCrypt Benchmark\n");
270272

273+
/* free */
274+
Clr_CallbackCtx(&guser_PKCbInfo);
275+
271276
#elif defined(TLS_CLIENT)
272277
#include "hal_data.h"
273278
#include "r_sce.h"

IDE/Renesas/e2studio/RA6M4/test/src/wolfssl_sce_unit_test.c

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ static int sce_aesgcm256_test(int prnt, sce_aes_wrapped_key_t* aes256_key)
386386
goto out;
387387
} else {
388388
userContext.sce_wrapped_key_aes256 = (void*)aes256_key;
389-
userContext.flags2.bits.aes256_installedkey_set = 1;
389+
userContext.keyflgs_crypt.bits.aes256_installedkey_set = 1;
390390
enc->ctx.keySize = (word32)enc->keylen;
391391
}
392392

@@ -582,7 +582,7 @@ static int sce_aesgcm128_test(int prnt, sce_aes_wrapped_key_t* aes128_key)
582582
goto out;
583583
} else {
584584
userContext.sce_wrapped_key_aes128 = aes128_key;
585-
userContext.flags2.bits.aes128_installedkey_set = 1;
585+
userContext.keyflgs_crypt.bits.aes128_installedkey_set = 1;
586586
enc->ctx.keySize = (word32)enc->keylen;
587587
}
588588
/* AES-GCM encrypt and decrypt both use AES encrypt internally */
@@ -656,11 +656,15 @@ static int sce_rsa_test(int prnt, int keySize)
656656
const char inStr2[] = TEST_STRING2;
657657
const word32 inLen = (word32)TEST_STRING_SZ;
658658
const word32 outSz = RSA_TEST_BYTES;
659+
byte *in = NULL;
660+
byte *in2 = NULL;
661+
byte *out= NULL;
662+
byte *out2 = NULL;
659663

660-
byte *in = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
661-
byte *in2 = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
662-
byte *out= (byte*)XMALLOC(outSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
663-
byte *out2 = (byte*)XMALLOC(outSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
664+
in = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
665+
in2 = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
666+
out= (byte*)XMALLOC(outSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
667+
out2 = (byte*)XMALLOC(outSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
664668

665669
if (key == NULL || in == NULL || out == NULL ||
666670
in2 == NULL || out2 == NULL) {
@@ -682,8 +686,11 @@ static int sce_rsa_test(int prnt, int keySize)
682686

683687
if ((ret = wc_InitRng(&rng)) != 0)
684688
goto out;
685-
686-
/* make ras key by SCE */
689+
690+
if ((ret = wc_RsaSetRNG(key, &rng)) != 0)
691+
goto out;
692+
693+
/* make rsa key by SCE */
687694
if ((ret = wc_MakeRsaKey(key, keySize, 65537, &rng)) != 0) {
688695
goto out;
689696
}
@@ -694,7 +701,7 @@ static int sce_rsa_test(int prnt, int keySize)
694701
}
695702

696703
ret = wc_RsaPrivateDecrypt(out, keySize/8, out2, outSz, key);
697-
if (ret != 0) {
704+
if (ret < 0) {
698705
ret = -1;
699706
goto out;
700707
}
@@ -703,6 +710,7 @@ static int sce_rsa_test(int prnt, int keySize)
703710
goto out;
704711
}
705712

713+
ret = 0;
706714
out:
707715
if (key != NULL) {
708716
wc_FreeRsaKey(key);
@@ -735,10 +743,14 @@ static int sce_rsa_SignVerify_test(int prnt, int keySize)
735743
const word32 inLen = (word32)TEST_STRING_SZ;
736744
const word32 outSz = RSA_TEST_BYTES;
737745

738-
byte *in = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
739-
byte *in2 = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
740-
byte *out= (byte*)XMALLOC(outSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
746+
byte *in = NULL;
747+
byte *in2 = NULL;
748+
byte *out= NULL;
741749

750+
in = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
751+
in2 = (byte*)XMALLOC(inLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
752+
out= (byte*)XMALLOC(outSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
753+
742754
(void) prnt;
743755

744756
if (key == NULL || in == NULL || out == NULL) {
@@ -759,12 +771,15 @@ static int sce_rsa_SignVerify_test(int prnt, int keySize)
759771
if ((ret = wc_InitRng(&rng)) != 0)
760772
goto out;
761773

762-
/* make ras key by SCE */
774+
if ((ret = wc_RsaSetRNG(key, &rng)) != 0)
775+
goto out;
776+
777+
/* make rsa key by SCE */
763778
if ((ret = wc_MakeRsaKey(key, keySize, 65537, &rng)) != 0) {
764779
goto out;
765780
}
766781

767-
guser_PKCbInfo.flags2.bits.message_type = 0;
782+
guser_PKCbInfo.keyflgs_crypt.bits.message_type = 0;
768783
ret = wc_RsaSSL_Sign(in, inLen, out, outSz, key, &rng);
769784
if (ret < 0) {
770785
goto out;
@@ -778,11 +793,11 @@ static int sce_rsa_SignVerify_test(int prnt, int keySize)
778793
}
779794
/* this should succeed */
780795
ret = wc_RsaSSL_Verify(in, inLen, out, keySize/8, key);
781-
if (ret != 0) {
796+
if (ret < 0) {
782797
ret = -1;
783798
goto out;
784799
}
785-
800+
ret = 0;
786801
out:
787802
if (key != NULL) {
788803
wc_FreeRsaKey(key);
@@ -833,11 +848,26 @@ int sce_crypt_test()
833848
if ( ret > 0)
834849
ret = 0;
835850

851+
if (ret == 0) {
852+
printf(" sce_rsa_test(512)(this will be done"
853+
" by SW because SCE doesn't support 512 bits key size.)");
854+
ret = sce_rsa_test(1, 512);
855+
RESULT_STR(ret)
856+
}
857+
836858
if (ret == 0) {
837859
printf(" sce_rsa_test(1024)");
838860
ret = sce_rsa_test(1, 1024);
839861
RESULT_STR(ret)
840862
}
863+
864+
if (ret == 0) {
865+
printf(" sce_rsa_SignVerify_test(512)(this will be done"
866+
" by SW because SCE doesn't support 512 bits key size.)");
867+
ret = sce_rsa_SignVerify_test(1, 512);
868+
RESULT_STR(ret)
869+
}
870+
841871
if (ret == 0) {
842872
printf(" sce_rsa_SignVerify_test(1024)");
843873
ret = sce_rsa_SignVerify_test(1, 1024);

0 commit comments

Comments
 (0)