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 3f3e6dc4ee..c84c01aac9 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 @@ -1697,10 +1697,7 @@ int tsip_crypt_test(void) int ret = 0; int devId; - if (ret != 0) { - printf("TSIP Key Generation failed\n"); - return -1; - } + Clr_CallbackCtx(&userContext); devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &userContext); if (devId > 0){ diff --git a/wolfcrypt/src/port/Renesas/renesas_tsip_sha.c b/wolfcrypt/src/port/Renesas/renesas_tsip_sha.c index d79fca096f..55b8eb473c 100644 --- a/wolfcrypt/src/port/Renesas/renesas_tsip_sha.c +++ b/wolfcrypt/src/port/Renesas/renesas_tsip_sha.c @@ -398,9 +398,8 @@ static int TSIPHashFinal(wolfssl_TSIP_Hash* hash, byte* out, word32 outSz) ret = Update(&handle, (uint8_t*)hash->msg, hash->used); if (ret == TSIP_SUCCESS) { ret = Final(&handle, out, (uint32_t*)&sz); - if (ret != TSIP_SUCCESS || sz != outSz) { - tsip_hw_unlock(); - return (ret == TSIP_SUCCESS) ? WC_HW_E : ret; + if (ret == TSIP_SUCCESS && sz != outSz) { + ret = WC_HW_E; } } else { @@ -409,12 +408,17 @@ static int TSIPHashFinal(wolfssl_TSIP_Hash* hash, byte* out, word32 outSz) } tsip_hw_unlock(); - if (ret != 0) { - return ret; + /* Always reset hash state, even on failure, mirroring other wc_*Final() + * implementations (e.g. the STM32 wc_ShaFinal()/wc_Sha256Final()) so + * callers can safely reuse the object and the accumulated message + * buffer isn't left allocated. */ + TSIPHashFree(hash); + if (TSIPHashInit(hash, heap, 0, hash->sha_type) != 0 && + ret == TSIP_SUCCESS) { + ret = WC_HW_E; } - TSIPHashFree(hash); - return TSIPHashInit(hash, heap, 0, hash->sha_type); + return ret; } static int TSIPHashGet(wolfssl_TSIP_Hash* hash, byte* out, word32 outSz)