Repository navigation
SHA3/SHAKE: unify wire format and handlers, enable Keccak-256 - #562
padelsbach wants to merge 7 commits into
Conversation
0ebe91d to
4305394
Compare
Frauschi
left a comment
There was a problem hiding this comment.
Most comments are on the wire encoding and the Keccak-256 policy; the handler unification itself looks good.
|
|
||
| /* SHA3 Request. Data follows: in[inSz] */ | ||
| typedef struct { | ||
| uint32_t isLastBlock; |
There was a problem hiding this comment.
The op is inferred from isLastBlock and outSz, which leaves a zero-length final with no encoding and forces the client-only reset. Since the format is changing anyway, can we replace isLastBlock with an explicit op field from whMessageCrypto_Sha3Op?
There was a problem hiding this comment.
In #523 it was that way initially, but Marco requested to infer it. I don't have a strong opinion either way.
| ret = _ShakeUpdateAll(ctx, sha, v, in, inLen); | ||
| if ((ret == WH_ERROR_OK) && (op == WH_MESSAGE_CRYPTO_SHAKE_OP_ABSORB)) { | ||
| ret = _ShakeStateOp(ctx, sha, v, op, NULL, 0); | ||
| /* A final with no output is only a reset, which discards the input */ |
There was a problem hiding this comment.
A one-shot SHAKE call with outSz == 0 now drops in and resets, while FinalRequest still returns BADARGS for the same input. Can we make both paths agree and document the behaviour in the SHAKE section of wh_client_crypto.h?
| memcpy(sha->s, req->resumeState.s, sizeof(sha->s)); | ||
| #if defined(WOLFSSL_HASH_FLAGS) && !defined(WOLFSSL_NO_KECCAK256) | ||
| if (keccak) { | ||
| ret = wc_Sha3_SetFlags(sha, WC_HASH_SHA3_KECCAK256); |
There was a problem hiding this comment.
Any client now gets Keccak-256 whenever the server has WOLFSSL_HASH_FLAGS, including FIPS v5/v6 builds where it isn't approved. Can we gate it behind a WOLFHSM_CFG_* opt-in and accept the flag only for SHA3-256, since wolfCrypt ignores it on 224/384/512 and applies it to SHAKE256?
There was a problem hiding this comment.
Added WOLFHSM_CFG_KECCAK256 opt-in option
| * padding and has no Keccak fallback. Use the cryptocb path, which routes | ||
| * Keccak to software. | ||
| * Keccak-mode contexts (sha->flags & WC_HASH_SHA3_KECCAK256) are hashed on | ||
| * the server. A server without Keccak-256 returns NOT_COMPILED_IN. |
There was a problem hiding this comment.
Keccak contexts used to fall back to software through the cryptocb, but against a server without WOLFSSL_HASH_FLAGS they now fail with NOT_COMPILED_IN. If that's intended, can we update the wh_Client_CryptoCb comment that still promises software fallback for unsupported algorithms?
| uint32_t inSz; | ||
| whMessageCrypto_Sha3State resumeState; | ||
| whMessageCrypto_DmaBuffer input; | ||
| whMessageCrypto_DmaBuffer output; |
There was a problem hiding this comment.
The server rejects SHAKE over DMA, so this reserved output buffer adds 16 wire bytes plus validation and tests for a path that doesn't exist yet. Since SHA3 isn't released, can we drop it and add it with DMA SHAKE?
There was a problem hiding this comment.
Done, dropped the field
| /* The update sends a block, so check only the final went out */ | ||
| seq = ctx->comm->seq; | ||
| if (ret == 0) { | ||
| ret = v->finalFn(sha, out, sizeof(dev)); |
There was a problem hiding this comment.
This only covers the single FINAL request, so the absorb/squeeze path for long output and multi-block updates never run with the Keccak flag. Can we add a case with output above WH_MESSAGE_CRYPTO_SHA3_MAX_INLINE_OUTPUT_SZ and input longer than one block?


Follow up to #523.
Changelist: