@@ -611,50 +611,56 @@ int wc_tsip_AesCtr(struct Aes* aes, byte* out, const byte* in, word32 sz)
611611 int ret ;
612612 byte * iv ;
613613
614- if ((in == NULL ) || (out == NULL ) || (aes == NULL ))
615- return BAD_FUNC_ARG ;
616-
617- /* while doing TLS handshake, TSIP driver keeps true-key and iv *
618- * on the device. iv is dummy */
619- iv = (uint8_t * )aes -> reg ;
614+ if ((in == NULL ) || (out == NULL ) || (aes == NULL )) {
615+ return BAD_FUNC_ARG ;
616+ }
620617
621618 if ((ret = tsip_hw_lock ()) != 0 ) {
622619 WOLFSSL_MSG ("Failed to lock" );
623620 return ret ;
624621 }
625622
623+ /* while doing TLS handshake, TSIP driver keeps true-key and iv *
624+ * on the device. iv is dummy */
625+ iv = (uint8_t * )aes -> reg ;
626+
626627 if (aes -> ctx .keySize == 16 ) {
628+ #if defined(TSIP_AES_128_CTR ) && TSIP_AES_128_CTR == 1
627629 ret = R_TSIP_Aes128CtrInit (& _handle , & aes -> ctx .tsip_keyIdx , iv );
630+ if (ret == TSIP_SUCCESS ) {
631+ ret = R_TSIP_Aes128CtrUpdate (& _handle , (uint8_t * )in ,
632+ (uint8_t * )out , sz );
633+ if (ret == TSIP_SUCCESS ) {
634+ ret = R_TSIP_Aes128CtrFinal (& _handle );
635+ }
636+ }
637+ #else
638+ ret = NOT_COMPILED_IN ;
639+ #endif
628640 }
629- else if (aes -> ctx .keySize == 32 ) {
641+ if (aes -> ctx .keySize == 32 ) {
642+ #if defined(TSIP_AES_256_CTR ) && TSIP_AES_256_CTR == 1
630643 ret = R_TSIP_Aes256CtrInit (& _handle , & aes -> ctx .tsip_keyIdx , iv );
631- }
632- else {
633- tsip_hw_unlock ();
634- return -1 ;
635- }
636-
637- if (aes -> ctx .keySize == 16 )
638- ret = R_TSIP_Aes128CtrUpdate (& _handle , (uint8_t * )in ,
639- (uint8_t * )out , sz );
640- else
641- ret = R_TSIP_Aes256CtrUpdate (& _handle , (uint8_t * )in ,
642- (uint8_t * )out , sz );
643-
644- if (ret == TSIP_SUCCESS ) {
645- if (aes -> ctx .keySize == 16 ) {
646- ret = R_TSIP_Aes128CtrFinal (& _handle );
647- }
648- else {
649- ret = R_TSIP_Aes256CtrFinal (& _handle );
644+ if (ret == TSIP_SUCCESS ) {
645+ ret = R_TSIP_Aes256CtrUpdate (& _handle , (uint8_t * )in ,
646+ (uint8_t * )out , sz );
647+ if (ret == TSIP_SUCCESS ) {
648+ ret = R_TSIP_Aes256CtrFinal (& _handle );
649+ }
650650 }
651+ #else
652+ ret = NOT_COMPILED_IN ;
653+ #endif
651654 }
652- else {
655+
656+ if (ret != TSIP_SUCCESS ) {
657+ WOLFSSL_ERROR (ret );
653658 WOLFSSL_MSG ("TSIP AES CTR failed" );
654659 ret = -1 ;
655660 }
656661
657662 tsip_hw_unlock ();
663+
658664 return ret ;
659665}
660666#endif /* WOLFSSL_AES_COUNTER */
@@ -720,7 +726,7 @@ int wc_tsip_AesGcmEncrypt(
720726 if (aes -> ctx .keySize != 16 && aes -> ctx .keySize != 32 ) {
721727 WOLFSSL_MSG ("illegal key size" );
722728 WOLFSSL_LEAVE ("wc_tsip_AesGcmEncrypt" , BAD_FUNC_ARG );
723- return BAD_FUNC_ARG ;
729+ return BAD_FUNC_ARG ;
724730 }
725731
726732 if (aes -> ctx .keySize == 16 ) {
0 commit comments