Skip to content

Commit 4e1a7d4

Browse files
authored
CMAC refactor + deprecate cancellation (#279)
* WIP: CMAC state refactor. Passing tests and wolfCrypt tests. About to rip out cancellation * remove cancellation API * - refactor non-dma oneshot cmac generate to support cached keys - refactor DMA CMAC to use client-supplied state vs state by reference - refactor to use stack allocated CMAC context - expand CMAC tests to mimic wolfCrypt tests but with cached keys - housekeeping, error checking * Review feedback: - Reserve removed error codes (wh_error.h): WH_ERROR_RESERVED{1,2} - Reserve removed message group (wh_message.h): WH_MESSAGE_GROUP_RESERVED - Rename CMAC → CmacAes (wh_message_crypto.h, all consumers): All structs and translation functions renamed to indicate AES-specific - Remove `type` field from request structs and translation; use WC_CMAC_AES literal on server - Remove switch(req.type) in server handlers; guard with #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_DIRECT) instead - Extract _CmacResolveKey() static helper for shared key resolution (inline key or keystore + usage policy + size validation) - Extract wh_Crypto_CmacAesSaveStateToMsg() / RestoreStateFromMsg() to deduplicate state pack/unpack across client + server + DMA - BAD_FUNC_ARG → WH_ERROR_BADARGS for bufferSz validation (now inside RestoreStateFromMsg) - Don't read req.* after response may overlap — use WC_CMAC_AES literal instead of req.type - #define/#undef → enum for CMAC_MLEN_* test constants
1 parent 062a005 commit 4e1a7d4

17 files changed

+776
-1333
lines changed

src/wh_client.c

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ int wh_Client_Init(whClientContext* c, const whClientConfig* config)
7676
}
7777

7878
memset(c, 0, sizeof(*c));
79-
#ifdef WOLFHSM_CFG_CANCEL_API
80-
/* register the cancel callback */
81-
c->cancelCb = config->cancelCb;
82-
#endif
8379

8480
rc = wh_CommClient_Init(c->comm, config->comm);
8581

@@ -472,73 +468,6 @@ int wh_Client_CommClose(whClientContext* c)
472468
return rc;
473469
}
474470

475-
#ifdef WOLFHSM_CFG_CANCEL_API
476-
int wh_Client_EnableCancel(whClientContext* c)
477-
{
478-
if (c == NULL)
479-
return WH_ERROR_BADARGS;
480-
c->cancelable = 1;
481-
return 0;
482-
}
483-
484-
int wh_Client_DisableCancel(whClientContext* c)
485-
{
486-
if (c == NULL)
487-
return WH_ERROR_BADARGS;
488-
c->cancelable = 0;
489-
return 0;
490-
}
491-
492-
int wh_Client_CancelRequest(whClientContext* c)
493-
{
494-
if (c == NULL) {
495-
return WH_ERROR_BADARGS;
496-
}
497-
498-
if (c->cancelCb == NULL) {
499-
return WH_ERROR_ABORTED;
500-
}
501-
502-
/* Since we aren't sending this request through the standard transport, we
503-
* need to update the client context's last sent "kind" to prevent the Comm
504-
* Client receive function from discarding the next response as an
505-
* out-of-order/corrupted message. No need to update the sequence number/ID
506-
* as it will not have been incremented by the cancel operation, as it is
507-
* out-of-band */
508-
c->last_req_kind = WH_MESSAGE_KIND(WH_MESSAGE_GROUP_CANCEL, 0);
509-
510-
return c->cancelCb(c->comm->seq);
511-
}
512-
513-
int wh_Client_CancelResponse(whClientContext* c)
514-
{
515-
int ret = 0;
516-
uint16_t group;
517-
uint16_t action;
518-
uint16_t size;
519-
uint8_t* buf;
520-
if (c == NULL)
521-
return WH_ERROR_BADARGS;
522-
/* check if the request was canceled */
523-
buf = wh_CommClient_GetDataPtr(c->comm);
524-
ret = wh_Client_RecvResponse(c, &group, &action, &size, buf);
525-
if (ret == 0 && group != WH_MESSAGE_GROUP_CANCEL)
526-
return WH_ERROR_CANCEL_LATE;
527-
return ret;
528-
}
529-
530-
int wh_Client_Cancel(whClientContext* c)
531-
{
532-
int ret;
533-
ret = wh_Client_CancelRequest(c);
534-
if (ret == 0) {
535-
do {
536-
ret = wh_Client_CancelResponse(c);
537-
} while (ret == WH_ERROR_NOTREADY);
538-
}
539-
return ret;
540-
}
541-
#endif /* WOLFHSM_CFG_CANCEL_API */
542471

543472
int wh_Client_EchoRequest(whClientContext* c, uint16_t size, const void* data)
544473
{

0 commit comments

Comments
 (0)