Skip to content

Add crypto callback for SHAKE - #523

Open
padelsbach wants to merge 1 commit into
wolfSSL:mainfrom
padelsbach:crypto-cb-shake
Open

padelsbach wants to merge 1 commit into
wolfSSL:mainfrom
padelsbach:crypto-cb-shake

Conversation

@padelsbach

@padelsbach padelsbach commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Follows patterns from SHA3

@padelsbach
padelsbach marked this pull request as ready for review September 18, 2026 20:41
@padelsbach padelsbach assigned padelsbach and bigbrett and unassigned padelsbach Sep 18, 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 #523

Scan targets checked: wolfhsm-core-bugs, wolfhsm-crypto-bugs, wolfhsm-src

Findings: 5
5 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

}
#endif /* WOLFSSL_SHAKE128 || WOLFSSL_SHAKE256 */

int whTest_Crypto_Shake(whClientContext* ctx)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

whTest_Crypto_Shake is defined outside the SHAKE feature guard, so NO_SHAKE builds report PASS instead of SKIPPED · Weak or missing assertions

The #if defined(WOLFSSL_SHAKE128) || defined(WOLFSSL_SHAKE256) block closes at line 457, so whTest_Crypto_Shake is always compiled and provides a strong symbol that overrides the weak WH_TEST_SKIPPED stub in wh_test_list.c. The NO_SHAKE=1 variant added by this PR therefore reports the SHAKE suite as passing while running nothing. whTest_Crypto_Sha3 and whTest_Crypto_MlDsa both sit inside their feature guards.

Suggested fix: Move whTest_Crypto_Shake inside the WOLFSSL_SHAKE128 || WOLFSSL_SHAKE256 guard so the weak skip stub is linked when neither variant is built.

Comment thread src/wh_client_crypto.c
}
*requestSent = false;

if (sha->i >= v->blockSize) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SHAKE client helpers omit the Keccak-mode rejection their SHA3 twins perform · Copy-paste errors

_ShakeUpdateRequest and _ShakeFinalRequest have no equivalent of _Sha3RejectKeccak (called at lines 9189 and 9315 of the SHA3 twins). The wire format carries only resumeState.s, and the server re-inits with standard SHAKE padding, so the public wh_Client_Shake128/256* entry points silently return wrong output for a WC_HASH_SHA3_KECCAK256-flagged context. The new _ShakeTestKeccakFlag only covers the cryptocb path, which does guard.

Suggested fix: Call the existing _Sha3RejectKeccak(sha) (it takes a wc_Sha3*, which wc_Shake aliases) at the top of _ShakeUpdateRequest and _ShakeFinalRequest, and extend _ShakeTestBadArgs to cover it.

Comment thread src/wh_client_crypto.c
uint8_t* inlineData;
uint8_t* dataPtr;

if (ctx == NULL || sha == NULL || outSz == 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SHAKE client request helpers omit the Keccak-flag rejection their SHA3 siblings apply · Cryptographic operation flaws

_HandleShake initialises a fresh wc_Shake on the server, so WC_HASH_SHA3_KECCAK256 set via wc_Sha3_SetFlags is never conveyed. _Sha3UpdateRequest/_Sha3FinalRequest guard this with _Sha3RejectKeccak; _ShakeUpdateRequest/_ShakeFinalRequest do not, and the only guard added by the PR lives in wh_Client_CryptoCbStd. Direct callers of the public wh_Client_Shake* API silently receive digests computed with the wrong padding domain.

Suggested fix: Call _Sha3RejectKeccak(sha) at the top of _ShakeUpdateRequest and _ShakeFinalRequest, as the SHA3 request helpers do.

Comment thread src/wh_client_crypto.c
uint32_t inLen, uint8_t* out, uint32_t outSz)
{
int ret = WH_ERROR_OK;
_ShakeSavedState saved;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SHAKE rollback buffers retain sponge state and buffered input on the client stack · Missing ForceZero

_ShakeSavedState saved holds the full 200-byte Keccak sponge state plus up to 168 bytes of unabsorbed message, and _ShakeUpdateRequest keeps a savedT[168] copy; neither is scrubbed on any exit path. SHAKE is used as an XOF over secret seeds, so this leaves derivable secret material in the client's stack frame after return. Adjacent to known finding #8510, which covers the SHA3 copies (_Sha3UpdateRequest, _Sha3Oneshot, and the DMA variants) — these are new functions introduced by this PR and are not fixed by that patch.

Related known finding #8510 (similar but distinct): Operation/root cause: unzeroed stack copies of Keccak sponge state and partial-block buffer (_ShakeSavedState/savedT) left after client-side rollback, directly analogous to #8510's _Sha3SavedState/savedT residue in the SHA3 twins — same missing-ForceZero pattern and same architectural cause (rollback snapshots for cryptocb fallback). Function/path differs: these are new SHAKE-specific helpers (_ShakeOneshot, _ShakeUpdateRequest) introduced by this PR, distinct code locations from the SHA3 functi

Suggested fix: Scrub saved before returning from _ShakeOneshot and savedT before returning from _ShakeUpdateRequest using wc_ForceZero.

}
#endif /* WOLFSSL_SHAKE128 || WOLFSSL_SHAKE256 */
(void)ctx;
return 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

whTest_Crypto_Shake reports PASS instead of SKIPPED when SHAKE is disabled · Weak or missing assertions

The function body is guarded by #if defined(WOLFSSL_SHAKE128) || defined(WOLFSSL_SHAKE256) but the definition itself is unconditional, so with neither variant enabled it executes nothing and returns 0. The NO_SHAKE=1 / SHAKE128_ONLY / SHAKE256_ONLY build options added by this PR make that the normal case, and those CI jobs will report the test as passing.

Suggested fix: Wrap the whTest_Crypto_Shake definition in the SHAKE #if so the weak stub supplies the WH_TEST_SKIPPED result, as whTest_Crypto_Sha3 does.

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