Skip to content

Fix sha512 buffer copy#333

Draft
padelsbach wants to merge 1 commit intowolfSSL:mainfrom
padelsbach:sha512-alt-modes
Draft

Fix sha512 buffer copy#333
padelsbach wants to merge 1 commit intowolfSSL:mainfrom
padelsbach:sha512-alt-modes

Conversation

@padelsbach
Copy link
Copy Markdown
Contributor

@padelsbach padelsbach commented Apr 10, 2026

Fixes F-2006 and F-2007. See related but independent wolfssl PR.

wh_Client_Sha512 unconditionally copied WC_SHA512_DIGEST_SIZE (64) bytes on finalize, regardless of SHA512 variant. For SHA512/224 (28-byte digest) and SHA512/256 (32-byte digest), this overwrites caller memory past the output buffer.

Today this is masked because the cryptocb dispatcher only handled WC_HASH_TYPE_SHA512, so variants fell through to CRYPTOCB_UNAVAILABLE and wolfSSL's software fallback handled the truncation safely. But the variants were never HSM-accelerated, and any future dispatcher fix would expose the overflow.

Changes

  • Dispatcher (wh_client_cryptocb.c): Add WC_HASH_TYPE_SHA512_224 and WC_HASH_TYPE_SHA512_256 cases, routing to the same wh_Client_Sha512/wh_Client_Sha512Dma functions with info->hash.type passed through
  • wh_Client_Sha512 (wh_client_crypto.c): New hashType parameter selects the correct digest size for memcpy and the correct wc_InitSha512*_ex variant for re-init
  • wh_Client_Sha512Dma: Same treatment -- hashType drives digestSz, req->output.sz, and DMA post-processing size
  • Tests (wh_test_crypto.c): New test cases for SHA512/224 and SHA512/256 with canary bytes to detect overwrite

Design note

The hashType parameter comes from info->hash.type, which is set by wolfSSL's cryptocb dispatch layer based on digestSz -- not from sha512->hashType, which depends on the wolfSSL port's init code setting it. This makes the fix independent of wolfSSL port behavior.

Copy link
Copy Markdown

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

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #333

Scan targets checked: wolfhsm-consttime, wolfhsm-crypto-bugs, wolfhsm-defaults, wolfhsm-mutation, wolfhsm-proptest, wolfhsm-src, wolfhsm-zeroize

No new issues found in the changed files. ✅

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