Skip to content

add SHA3 support#384

Draft
bigbrett wants to merge 1 commit into
wolfSSL:mainfrom
bigbrett:sha3
Draft

add SHA3 support#384
bigbrett wants to merge 1 commit into
wolfSSL:mainfrom
bigbrett:sha3

Conversation

@bigbrett
Copy link
Copy Markdown
Contributor

Adds support for SHA3 to wolfHSM. Supports blocking wolfCrypt and async native API surface.

Copilot AI review requested due to automatic review settings May 28, 2026 16:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds SHA3 support across wolfHSM’s crypto message formats, client APIs, server handlers, cryptocb dispatch, and tests for blocking, async, and DMA paths.

Changes:

  • Introduces SHA3 wire formats, translation helpers, and comm-buffer sizing checks.
  • Adds SHA3 client/server handling for SHA3-224/256/384/512, including DMA and Keccak rejection/fallback behavior.
  • Expands crypto tests and test configuration to exercise SHA3 variants and async paths.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
wolfhsm/wh_message_crypto.h Adds SHA3/SHA3-DMA message structs, sizing macros, static asserts, and translation prototypes.
wolfhsm/wh_client_crypto.h Adds SHA3 include and public client API declarations.
src/wh_message_crypto.c Implements SHA3 and SHA3-DMA message translation helpers.
src/wh_client_crypto.c Implements shared SHA3 client helpers, per-variant APIs, and DMA APIs.
src/wh_client_cryptocb.c Routes SHA3 cryptocb requests to wolfHSM client APIs with Keccak fallback.
src/wh_server_crypto.c Adds SHA3 and SHA3-DMA server handlers and dispatch cases.
test/wh_test_crypto.c Adds SHA3 functional, async, DMA, bad-argument, and Keccak behavior tests.
test/wh_test_check_struct_padding.c Adds SHA3 message structs to padding checks.
test/config/user_settings.h Enables hash flags for SHA3 Keccak-path test coverage.

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

Comment thread src/wh_client_crypto.c
uint32_t i = 0;
/* Snapshot of partial buffer for rollback if SendRequest fails */
uint32_t savedI;
uint8_t savedT[WC_SHA3_224_BLOCK_SIZE]; /* largest block size: 144 */
Comment thread src/wh_client_crypto.c
const uint8_t* dmaBase = NULL;
uint32_t dmaSz = 0;
uint32_t savedI;
uint8_t savedT[WC_SHA3_224_BLOCK_SIZE];
Comment thread test/wh_test_crypto.c
Comment on lines +5459 to +5460
uint8_t out[WC_SHA3_512_DIGEST_SIZE];
uint8_t ref[WC_SHA3_512_DIGEST_SIZE];
Comment thread test/wh_test_crypto.c
Comment on lines +5696 to +5702
static int whTest_CryptoSha3AsyncOneVariant(whClientContext* ctx, int devId,
const whTestSha3Variant* v)
{
int ret = WH_ERROR_OK;
wc_Sha3 sha[1];
uint8_t out[WC_SHA3_512_DIGEST_SIZE];
uint8_t ref[WC_SHA3_512_DIGEST_SIZE];
Comment thread test/wh_test_crypto.c
Comment on lines +5864 to +5865
uint8_t out[WC_SHA3_512_DIGEST_SIZE];
uint8_t ref[WC_SHA3_512_DIGEST_SIZE];
Comment thread test/wh_test_crypto.c
{
int ret;
wc_Sha3 sha[1];
uint8_t out[WC_SHA3_512_DIGEST_SIZE];
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 #384

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

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

This review was generated automatically by Fenrir. Findings are non-blocking.

/* Per-variant max-inline update sizes (block sizes differ across variants
* so each gets its own macro, rounded down to a whole-block multiple). */
#define WH_MESSAGE_CRYPTO_SHA3_224_MAX_INLINE_UPDATE_SZ \
(((WOLFHSM_CFG_COMM_DATA_LEN - \
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 [Medium] SHA3 inline capacity underflows on small comm buffers · Incorrect sizeof/type usage

The SHA3 inline size macros subtract header sizes as unsigned values, so undersized comm-buffer configs underflow to a huge capacity. The static asserts pass and callers can copy past the comm buffer.

Fix: Assert WOLFHSM_CFG_COMM_DATA_LEN >= header + request + block before deriving each SHA3 capacity.

Comment thread src/wh_server_crypto.c
WH_DMA_OPER_CLIENT_READ_PRE, (whServerDmaFlags){0});
if (ret == WH_ERROR_OK) {
preOk = 1;
ret = ops.updateFn(sha3, inAddr, req.input.sz);
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] SHA3 DMA size truncates at wolfCrypt update · Incorrect sizeof/type usage

req.input.sz is a 64-bit DMA length, but ops.updateFn takes word32, so oversized SHA3 DMA requests hash only the truncated byte count.

Fix: Reject req.input.sz > UINT32_MAX before DMA processing or chunk the update into word32-sized calls.

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