Skip to content

Fix TSIP SHA error propagation in TSIPHashFinal / TSIPHashGet#10789

Draft
miyazakh wants to merge 1 commit into
wolfSSL:masterfrom
miyazakh:f6162_tsiphash
Draft

Fix TSIP SHA error propagation in TSIPHashFinal / TSIPHashGet#10789
miyazakh wants to merge 1 commit into
wolfSSL:masterfrom
miyazakh:f6162_tsiphash

Conversation

@miyazakh

Copy link
Copy Markdown
Contributor

Description

Fix TSIP SHA error propagation in TSIPHashFinal / TSIPHashGet

Problem

TSIPHashFinal and TSIPHashGet in renesas_tsip_sha.c silently returned 0
(success) when the TSIP hardware Init() or Update() step failed, leaving
the digest buffer unwritten. Same defect class as issue #5420 (FSPSM path).

Fix

  • Initialize ret = WC_HW_E instead of leaving it uninitialized.
  • Add else { ret = WC_HW_E; } for Update() failure.
  • Add early return after the hardware block so failures are not swallowed by the
    trailing TSIPHashFree / TSIPHashInit calls.
  • Replace the hardcoded return 0 at the end of TSIPHashGet with return ret.

Tests Added (wolfssl_tsip_unit_test.c)

  • tsip_sha256_hash_test() — verifies wc_Sha256Final digest and confirms
    wc_Sha256GetHash is non-destructive.
  • tsip_sha1_hash_test() — same for SHA-1.

Both tests pass on RX72N EnvisionKit.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@miyazakh miyazakh self-assigned this Jun 26, 2026
Copilot AI review requested due to automatic review settings June 26, 2026 06:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes error propagation in the Renesas TSIP hash (SHA-1/SHA-256) Final/Get paths so hardware failures don’t incorrectly return success, and adds RX72N EnvisionKit demo/unit tests to validate correct digest output and non-destructive GetHash behavior.

Changes:

  • Initialize return codes to a failing default (WC_HW_E) and stop returning hardcoded success in TSIPHashGet.
  • Add explicit failure handling for TSIP Update() failures.
  • Add TSIP SHA-1/SHA-256 tests validating Final correctness and GetHash non-destructiveness.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 10 comments.

File Description
wolfcrypt/src/port/Renesas/renesas_tsip_sha.c Improves TSIP SHA Final/Get error propagation and return semantics.
IDE/Renesas/e2studio/RX72N/EnvisionKit/wolfssl_demo/wolfssl_tsip_unit_test.c Adds SHA-256 and SHA-1 TSIP hash tests and runs them from tsip_crypt_test().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 410 to +414
tsip_hw_unlock();

if (ret != 0) {
return ret;
}
Comment on lines +412 to 417
if (ret != 0) {
return ret;
}

TSIPHashFree(hash);
return TSIPHashInit(hash, heap, 0, hash->sha_type);
Comment on lines +1512 to +1516
wc_Sha256 sha;
byte hash1[WC_SHA256_DIGEST_SIZE];
byte hash2[WC_SHA256_DIGEST_SIZE];
int ret = 0;

Comment on lines +1530 to +1534
ret = wc_InitSha256_ex(&sha, NULL, 0);
if (ret != 0) {
ret = -1;
goto out;
}
Comment on lines +1587 to +1594
out:
if (prnt) {
if (ret != 0)
printf("(code=%d) ", ret);
RESULT_STR(ret)
}
return ret;
}
Comment on lines +1600 to +1604
wc_Sha sha;
byte hash1[WC_SHA_DIGEST_SIZE];
byte hash2[WC_SHA_DIGEST_SIZE];
int ret = 0;

Comment on lines +1617 to +1621
ret = wc_InitSha_ex(&sha, NULL, 0);
if (ret != 0) {
ret = -1;
goto out;
}
Comment on lines +1680 to +1687
out:
if (prnt) {
if (ret != 0)
printf("(code=%d) ", ret);
RESULT_STR(ret)
}
return ret;
}
Comment on lines 403 to 404
return ret;
}
Comment on lines 455 to 456
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants