Skip to content

Set hashType on SHAKE128/256 contexts so crypto-callback Copy/Free can clean up correctly - #11217

Open
night1rider wants to merge 1 commit into
wolfSSL:masterfrom
night1rider:ShakeCB-Issue
Open

Set hashType on SHAKE128/256 contexts so crypto-callback Copy/Free can clean up correctly#11217
night1rider wants to merge 1 commit into
wolfSSL:masterfrom
night1rider:ShakeCB-Issue

Conversation

@night1rider

@night1rider night1rider commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@night1rider night1rider changed the title Set hashType on SHAKE128/256 contexts so crypto-callback Copy/Free Set hashType on SHAKE128/256 contexts so crypto-callback Copy/Free can clean up correctly Aug 20, 2026

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread wolfcrypt/src/sha3.c
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 [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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PSOC6_HASH_SHA3 has a custom sha3 struct that does not have the normal CryptoCB types

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.

3 participants