@@ -408,10 +408,10 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
408408 printf (" tsip_aes256_gcm_test() " );
409409 }
410410
411- ForceZero (resultT , sizeof (resultT ));
412- ForceZero (resultC , sizeof (resultC ));
413- ForceZero (resultP , sizeof (resultP ));
414- ForceZero (& userContext , sizeof (TsipUserCtx ));
411+ XMEMSET (resultT , 0 , sizeof (resultT ));
412+ XMEMSET (resultC , 0 , sizeof (resultC ));
413+ XMEMSET (resultP , 0 , sizeof (resultP ));
414+ XMEMSET (& userContext , 0 , sizeof (TsipUserCtx ));
415415
416416 if (wc_AesInit (enc , NULL , INVALID_DEVID ) != 0 ) {
417417 ret = -1 ;
@@ -434,10 +434,11 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
434434 }
435435
436436 /* AES-GCM encrypt and decrypt both use AES encrypt internally */
437- result = wc_tsip_AesGcmEncrypt (enc , resultC , p , sizeof (p ),
438- (byte * )iv1 , sizeof (iv1 ), resultT , sizeof (resultT ),
439- a , sizeof (a ), & userContext );
440-
437+ result = wc_tsip_AesGcmEncrypt (enc ,
438+ resultC , p , sizeof (p ),
439+ (byte * )iv1 , sizeof (iv1 ), resultT , sizeof (resultT ),
440+ a , sizeof (a ), & userContext
441+ );
441442 if (result != 0 ) {
442443 ret = -4 ;
443444 goto out ;
@@ -451,9 +452,11 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
451452 dec -> ctx .keySize = enc -> keylen ;
452453 }
453454
454- result = wc_tsip_AesGcmDecrypt (dec , resultP , resultC , sizeof (c1 ),
455- iv1 , sizeof (iv1 ), resultT , sizeof (resultT ),
456- a , sizeof (a ), & userContext );
455+ result = wc_tsip_AesGcmDecrypt (dec ,
456+ resultP , resultC , sizeof (c1 ),
457+ iv1 , sizeof (iv1 ), resultT , sizeof (resultT ),
458+ a , sizeof (a ), & userContext
459+ );
457460 if (result != 0 ){
458461 ret = -8 ;
459462 goto out ;
@@ -469,18 +472,21 @@ static int tsip_aesgcm256_test(int prnt, tsip_aes_key_index_t* aes256_key)
469472
470473 wc_AesGcmSetKey (enc , k1 , sizeof (k1 ));
471474 /* AES-GCM encrypt and decrypt both use AES encrypt internally */
472- result = wc_tsip_AesGcmEncrypt (enc , resultC , p , sizeof (p ), iv1 , sizeof (iv1 ),
473- resultT + 1 , sizeof (resultT ) - 1 ,
474- a , sizeof (a ), & userContext );
475+ result = wc_tsip_AesGcmEncrypt (enc ,
476+ resultC , p , sizeof (p ), iv1 , sizeof (iv1 ),
477+ resultT + 1 , sizeof (resultT ) - 1 ,
478+ a , sizeof (a ), & userContext
479+ );
475480 if (result != 0 ) {
476481 ret = -10 ;
477482 goto out ;
478483 }
479484
480- result = wc_tsip_AesGcmDecrypt (enc , resultP , resultC , sizeof (p ),
481- iv1 , sizeof (iv1 ), resultT + 1 , sizeof (resultT ) - 1 ,
482- a , sizeof (a ), & userContext );
483-
485+ result = wc_tsip_AesGcmDecrypt (enc ,
486+ resultP , resultC , sizeof (p ),
487+ iv1 , sizeof (iv1 ), resultT + 1 , sizeof (resultT ) - 1 ,
488+ a , sizeof (a ), & userContext
489+ );
484490 if (result != 0 ) {
485491 ret = -11 ;
486492 goto out ;
@@ -523,7 +529,7 @@ static void tskAes256_Gcm_Test(void *pvParam)
523529#endif /* FREERTOS */
524530#endif
525531
526- #if defined(WOLFSSL_AES_128 )
532+ #if defined(WOLFSSL_AES_128 ) && defined( HAVE_AESGCM )
527533
528534static int tsip_aesgcm128_test (int prnt , tsip_aes_key_index_t * aes128_key )
529535{
@@ -568,9 +574,9 @@ static int tsip_aesgcm128_test(int prnt, tsip_aes_key_index_t* aes128_key)
568574 0x31 , 0x2e , 0x2a , 0xf9 , 0x57 , 0x7a , 0x1e , 0xa6
569575 };
570576
571- byte resultT [16 ];
572- byte resultP [60 + AES_BLOCK_SIZE ];
573- byte resultC [60 + AES_BLOCK_SIZE ];
577+ byte resultT [sizeof ( t3 ) ];
578+ byte resultP [sizeof ( p3 ) + AES_BLOCK_SIZE ];
579+ byte resultC [sizeof ( p3 ) + AES_BLOCK_SIZE ];
574580 int result = 0 ;
575581 int ret ;
576582
@@ -581,10 +587,10 @@ static int tsip_aesgcm128_test(int prnt, tsip_aes_key_index_t* aes128_key)
581587 printf (" tsip_aes128_gcm_test() " );
582588 }
583589
584- ForceZero (resultT , sizeof (resultT ));
585- ForceZero (resultC , sizeof (resultC ));
586- ForceZero (resultP , sizeof (resultP ));
587- ForceZero (& userContext , sizeof (TsipUserCtx ));
590+ XMEMSET (resultT , 0 , sizeof (resultT ));
591+ XMEMSET (resultC , 0 , sizeof (resultC ));
592+ XMEMSET (resultP , 0 , sizeof (resultP ));
593+ XMEMSET (& userContext , 0 , sizeof (TsipUserCtx ));
588594
589595 if (wc_AesInit (enc , NULL , INVALID_DEVID ) != 0 ) {
590596 ret = -1 ;
@@ -607,21 +613,27 @@ static int tsip_aesgcm128_test(int prnt, tsip_aes_key_index_t* aes128_key)
607613 enc -> ctx .keySize = enc -> keylen ;
608614 }
609615 /* AES-GCM encrypt and decrypt both use AES encrypt internally */
610- result = wc_tsip_AesGcmEncrypt (enc , resultC , p3 , sizeof (p3 ),
611- iv3 , sizeof (iv3 ),
612- resultT , sizeof (t3 ),
613- a3 , sizeof (a3 ), & userContext );
616+ result = wc_tsip_AesGcmEncrypt (enc ,
617+ resultC , p3 , sizeof (p3 ),
618+ iv3 , sizeof (iv3 ),
619+ resultT , sizeof (t3 ),
620+ a3 , sizeof (a3 ), & userContext
621+ );
614622 if (result != 0 ) {
615623 ret = -4 ;
616624 goto out ;
617625 }
618- result = wc_tsip_AesGcmDecrypt (enc , resultP , resultC , sizeof (c3 ),
619- iv3 , sizeof (iv3 ), resultT , sizeof (resultT ),
620- a3 , sizeof (a3 ), & userContext );
626+
627+ result = wc_tsip_AesGcmDecrypt (enc ,
628+ resultP , resultC , sizeof (c3 ),
629+ iv3 , sizeof (iv3 ), resultT , sizeof (resultT ),
630+ a3 , sizeof (a3 ), & userContext
631+ );
621632 if (result != 0 ) {
622633 ret = -5 ;
623634 goto out ;
624635 }
636+
625637 if (XMEMCMP (p3 , resultP , sizeof (p3 ))) {
626638 ret = -6 ;
627639 goto out ;
@@ -805,6 +817,7 @@ static int tsip_rsa_SignVerify_test(int prnt, int keySize)
805817 const char inStr2 [] = TEST_STRING2 ;
806818 const word32 inLen = (word32 )TEST_STRING_SZ ;
807819 const word32 outSz = RSA_TEST_BYTES ;
820+ word32 signSz = 0 ;
808821 byte * in = NULL ;
809822 byte * in2 = NULL ;
810823 byte * out = NULL ;
@@ -848,15 +861,16 @@ static int tsip_rsa_SignVerify_test(int prnt, int keySize)
848861 if (ret < 0 ) {
849862 goto out ;
850863 }
864+ signSz = ret ;
851865
852866 /* this should fail */
853- ret = wc_RsaSSL_Verify (in2 , inLen , out , keySize / 8 , key );
867+ ret = wc_RsaSSL_Verify (out , signSz , in2 , inLen , key );
854868 if (ret != SIG_VERIFY_E ) {
855869 ret = -1 ;
856870 goto out ;
857871 }
858872 /* this should succeed */
859- ret = wc_RsaSSL_Verify (in , inLen , out , keySize / 8 , key );
873+ ret = wc_RsaSSL_Verify (out , signSz , in , inLen , key );
860874 if (ret < 0 ) {
861875 ret = -1 ;
862876 goto out ;
@@ -1223,6 +1237,7 @@ int tsip_crypt_test(void)
12231237
12241238 }
12251239
1240+ #ifdef HAVE_AESGCM
12261241 if (ret == 0 ) {
12271242
12281243 ret = tsip_aesgcm128_test (1 , & g_user_aes128_key_index1 );
@@ -1234,8 +1249,10 @@ int tsip_crypt_test(void)
12341249 ret = tsip_aesgcm256_test (1 , & g_user_aes256_key_index1 );
12351250
12361251 }
1237- #if defined(WOLFSSL_KEY_GEN ) && \
1238- defined(WOLFSSL_RENESAS_TSIP_CRYPTONLY )
1252+ #endif
1253+
1254+ #if defined(WOLFSSL_KEY_GEN ) && \
1255+ defined(WOLFSSL_RENESAS_TSIP_CRYPTONLY )
12391256
12401257 if (ret == 0 ) {
12411258 Clr_CallbackCtx (& userContext );
@@ -1248,20 +1265,21 @@ int tsip_crypt_test(void)
12481265
12491266#if RSA_MIN_SIZE <= 1024
12501267 if (ret == 0 ) {
1251- userContext .wrappedKeyType = TSIP_KEY_TYPE_RSA1024 ;
1268+ userContext .wrappedKeyType = TSIP_KEY_TYPE_RSA1024 ;
12521269 printf (" tsip_rsa_test(1024)" );
12531270 ret = tsip_rsa_test (1 , 1024 );
12541271 RESULT_STR (ret )
12551272 }
12561273#endif
12571274 if (ret == 0 ) {
1258- userContext .wrappedKeyType = TSIP_KEY_TYPE_RSA2048 ;
1275+ userContext .wrappedKeyType = TSIP_KEY_TYPE_RSA2048 ;
12591276 printf (" tsip_rsa_test(2048)" );
12601277 ret = tsip_rsa_test (1 , 2048 );
12611278 RESULT_STR (ret )
12621279 }
12631280
12641281
1282+ #if RSA_MIN_SIZE <= 1024
12651283 if (ret == 0 ) {
12661284 printf (" tsip_rsa_SignVerify_test(1024)" );
12671285
@@ -1274,6 +1292,7 @@ int tsip_crypt_test(void)
12741292 }
12751293
12761294 Clr_CallbackCtx (& userContext );
1295+ #endif
12771296
12781297 if (ret == 0 ) {
12791298 printf (" tsip_rsa_SignVerify_test(2048)" );
@@ -1287,12 +1306,11 @@ int tsip_crypt_test(void)
12871306 }
12881307
12891308 Clr_CallbackCtx (& userContext );
1290- #endif
1309+ #endif /* WOLFSSL_KEY_GEN && WOLFSSL_RENESAS_TSIP_CRYPTONLY */
12911310 }
1292- else
1311+ else {
12931312 ret = -1 ;
1294-
1295-
1313+ }
12961314 return ret ;
12971315}
12981316
0 commit comments