Set hashType on SHAKE128/256 contexts so crypto-callback Copy/Free can clean up correctly - #11217
Set hashType on SHAKE128/256 contexts so crypto-callback Copy/Free can clean up correctly#11217night1rider wants to merge 1 commit into
Conversation
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11217
Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src
Findings: 8
7 finding(s) posted as inline comments (see file-level comments below)
Low (1)
PSOC6 variants of wc_Shake128_Final/wc_Shake256_Final still leave hashType as WC_HASH_TYPE_NONE
File: wolfcrypt/src/sha3.c:2078
Function: wc_Shake128_Final
Category: Logic errors
wc_Psoc6_Sha3_Init zeroes the whole wc_Sha3 (psoc6_crypto.c:736), clearing hashType, but the PSOC6 definitions of wc_Shake128_Final/wc_Shake256_Final did not get the restore added to their software counterparts. Under PSOC6_HASH_SHA3 + WOLF_CRYPTO_CB_COPY a post-Final wc_Shake*_Copy still dispatches with WC_HASH_TYPE_NONE.
Recommendation: Apply the same shake->hashType = WC_HASH_TYPE_SHAKE128/256 restore in the PSOC6 branches of both Final functions.
This review was generated automatically by Fenrir. Findings are non-blocking.
75ae69b to
f48a7fa
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11217
Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src
Findings: 10
9 finding(s) posted as inline comments (see file-level comments below)
Info (1)
New myCryptoDevCtx fields left uninitialized in cryptocb_test
File: wolfcrypt/test/test.c:82916
Function: cryptocb_test
Category: Weak or missing assertions
cryptocb_test explicitly initializes every other myCryptoDevCtx field of the stack-allocated myCtx, but the PR adds hashCopyType/hashFreeType without initializers; they are indeterminate until shake_cb_copy_free_test writes them.
Recommendation: Initialize myCtx.hashCopyType and myCtx.hashFreeType to WC_HASH_TYPE_NONE with the other field initializers.
This review was generated automatically by Fenrir. Findings are non-blocking.
dispatch with the correct type instead of WC_HASH_TYPE_NONE
f48a7fa to
2c67d6a
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11217
Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src
Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Findings are non-blocking.
| return wc_InitSha3(shake, heap, devId); | ||
| int ret = wc_InitSha3(shake, heap, devId); | ||
| /* The PSoC6 wc_Sha3 variant has no hashType member */ | ||
| #if defined(WOLF_CRYPTO_CB) && !defined(PSOC6_HASH_SHA3) |
There was a problem hiding this comment.
🔵 [Low] hashType fix carves out PSOC6_HASH_SHA3, leaving SHAKE Copy/Free dispatch broken in that build · Preprocessor-conditional security bypass
The new assignment is gated on !defined(PSOC6_HASH_SHA3), but wc_Sha3Free (sha3.c:1598) and wc_Sha3Copy (sha3.c:1644) are shared and still dispatch on hashType. In PSOC6 builds SHAKE contexts keep WC_HASH_TYPE_NONE, so wc_Shake*_Copy returns the callback's error and wc_Shake*_Free returns early before wc_Psoc6_Sha_Free() at sha3.c:1621.
Fix: Drop the !defined(PSOC6_HASH_SHA3) condition in both wc_InitShake128 and wc_InitShake256 so all WOLF_CRYPTO_CB builds set the type.
There was a problem hiding this comment.
PSOC6_HASH_SHA3 has a custom sha3 struct that does not have the normal CryptoCB types
No description provided.