Skip to content

Commit 1e66467

Browse files
committed
unify Sha2 Dma Request/Response
addressed review comment
1 parent 6f789c3 commit 1e66467

File tree

5 files changed

+56
-261
lines changed

5 files changed

+56
-261
lines changed

src/wh_client_crypto.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,8 +2531,8 @@ int wh_Client_Sha256Dma(whClientContext* ctx, wc_Sha256* sha, const uint8_t* in,
25312531
uint16_t respSz = 0;
25322532
uint16_t group = WH_MESSAGE_GROUP_CRYPTO_DMA;
25332533
uint8_t* dataPtr = NULL;
2534-
whMessageCrypto_Sha256DmaRequest* req = NULL;
2535-
whMessageCrypto_Sha256DmaResponse* resp = NULL;
2534+
whMessageCrypto_Sha2DmaRequest* req = NULL;
2535+
whMessageCrypto_Sha2DmaResponse* resp = NULL;
25362536

25372537
/* Get data pointer from the context to use as request/response storage */
25382538
dataPtr = (uint8_t*)wh_CommClient_GetDataPtr(ctx->comm);
@@ -2541,7 +2541,7 @@ int wh_Client_Sha256Dma(whClientContext* ctx, wc_Sha256* sha, const uint8_t* in,
25412541
}
25422542

25432543
/* Setup generic header and get pointer to request data */
2544-
req = (whMessageCrypto_Sha256DmaRequest*)_createCryptoRequest(
2544+
req = (whMessageCrypto_Sha2DmaRequest*)_createCryptoRequest(
25452545
dataPtr, WC_HASH_TYPE_SHA256);
25462546

25472547

@@ -2787,8 +2787,8 @@ int wh_Client_Sha224Dma(whClientContext* ctx, wc_Sha224* sha, const uint8_t* in,
27872787
uint16_t respSz = 0;
27882788
uint16_t group = WH_MESSAGE_GROUP_CRYPTO_DMA;
27892789
uint8_t* dataPtr = NULL;
2790-
whMessageCrypto_Sha224DmaRequest* req = NULL;
2791-
whMessageCrypto_Sha224DmaResponse* resp = NULL;
2790+
whMessageCrypto_Sha2DmaRequest* req = NULL;
2791+
whMessageCrypto_Sha2DmaResponse* resp = NULL;
27922792

27932793
/* Get data pointer from the context to use as request/response storage */
27942794
dataPtr = (uint8_t*)wh_CommClient_GetDataPtr(ctx->comm);
@@ -2797,7 +2797,7 @@ int wh_Client_Sha224Dma(whClientContext* ctx, wc_Sha224* sha, const uint8_t* in,
27972797
}
27982798

27992799
/* Setup generic header and get pointer to request data */
2800-
req = (whMessageCrypto_Sha224DmaRequest*)_createCryptoRequest(
2800+
req = (whMessageCrypto_Sha2DmaRequest*)_createCryptoRequest(
28012801
dataPtr, WC_HASH_TYPE_SHA224);
28022802

28032803

@@ -3041,8 +3041,8 @@ int wh_Client_Sha384Dma(whClientContext* ctx, wc_Sha384* sha, const uint8_t* in,
30413041
uint16_t respSz = 0;
30423042
uint16_t group = WH_MESSAGE_GROUP_CRYPTO_DMA;
30433043
uint8_t* dataPtr = NULL;
3044-
whMessageCrypto_Sha384DmaRequest* req = NULL;
3045-
whMessageCrypto_Sha384DmaResponse* resp = NULL;
3044+
whMessageCrypto_Sha2DmaRequest* req = NULL;
3045+
whMessageCrypto_Sha2DmaResponse* resp = NULL;
30463046

30473047
/* Get data pointer from the context to use as request/response storage */
30483048
dataPtr = (uint8_t*)wh_CommClient_GetDataPtr(ctx->comm);
@@ -3051,7 +3051,7 @@ int wh_Client_Sha384Dma(whClientContext* ctx, wc_Sha384* sha, const uint8_t* in,
30513051
}
30523052

30533053
/* Setup generic header and get pointer to request data */
3054-
req = (whMessageCrypto_Sha384DmaRequest*)_createCryptoRequest(
3054+
req = (whMessageCrypto_Sha2DmaRequest*)_createCryptoRequest(
30553055
dataPtr, WC_HASH_TYPE_SHA384);
30563056

30573057

@@ -3307,8 +3307,8 @@ int wh_Client_Sha512Dma(whClientContext* ctx, wc_Sha512* sha, const uint8_t* in,
33073307
uint16_t respSz = 0;
33083308
uint16_t group = WH_MESSAGE_GROUP_CRYPTO_DMA;
33093309
uint8_t* dataPtr = NULL;
3310-
whMessageCrypto_Sha512DmaRequest* req = NULL;
3311-
whMessageCrypto_Sha512DmaResponse* resp = NULL;
3310+
whMessageCrypto_Sha2DmaRequest* req = NULL;
3311+
whMessageCrypto_Sha2DmaResponse* resp = NULL;
33123312

33133313
/* Get data pointer from the context to use as request/response storage */
33143314
dataPtr = (uint8_t*)wh_CommClient_GetDataPtr(ctx->comm);
@@ -3317,7 +3317,7 @@ int wh_Client_Sha512Dma(whClientContext* ctx, wc_Sha512* sha, const uint8_t* in,
33173317
}
33183318

33193319
/* Setup generic header and get pointer to request data */
3320-
req = (whMessageCrypto_Sha512DmaRequest*)_createCryptoRequest(
3320+
req = (whMessageCrypto_Sha2DmaRequest*)_createCryptoRequest(
33213321
dataPtr, WC_HASH_TYPE_SHA512);
33223322

33233323

src/wh_message_crypto.c

Lines changed: 7 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -628,55 +628,10 @@ int wh_MessageCrypto_TranslateDmaAddrStatus(
628628
return wh_MessageCrypto_TranslateDmaBuffer(magic, &src->badAddr,
629629
&dest->badAddr);
630630
}
631-
632-
/* SHA256 DMA Request translation */
633-
int wh_MessageCrypto_TranslateSha256DmaRequest(
634-
uint16_t magic, const whMessageCrypto_Sha256DmaRequest* src,
635-
whMessageCrypto_Sha256DmaRequest* dest)
636-
{
637-
int ret;
638-
639-
if ((src == NULL) || (dest == NULL)) {
640-
return WH_ERROR_BADARGS;
641-
}
642-
643-
WH_T64(magic, dest, src, finalize);
644-
645-
ret = wh_MessageCrypto_TranslateDmaBuffer(magic, &src->input, &dest->input);
646-
if (ret != 0) {
647-
return ret;
648-
}
649-
650-
ret = wh_MessageCrypto_TranslateDmaBuffer(magic, &src->state, &dest->state);
651-
if (ret != 0) {
652-
return ret;
653-
}
654-
655-
ret =
656-
wh_MessageCrypto_TranslateDmaBuffer(magic, &src->output, &dest->output);
657-
if (ret != 0) {
658-
return ret;
659-
}
660-
661-
return 0;
662-
}
663-
664-
/* SHA256 DMA Response translation */
665-
int wh_MessageCrypto_TranslateSha256DmaResponse(
666-
uint16_t magic, const whMessageCrypto_Sha256DmaResponse* src,
667-
whMessageCrypto_Sha256DmaResponse* dest)
668-
{
669-
if ((src == NULL) || (dest == NULL)) {
670-
return WH_ERROR_BADARGS;
671-
}
672-
return wh_MessageCrypto_TranslateDmaAddrStatus(magic, &src->dmaAddrStatus,
673-
&dest->dmaAddrStatus);
674-
}
675-
676631
/* SHA224 DMA Request translation */
677-
int wh_MessageCrypto_TranslateSha224DmaRequest(
678-
uint16_t magic, const whMessageCrypto_Sha224DmaRequest* src,
679-
whMessageCrypto_Sha224DmaRequest* dest)
632+
int wh_MessageCrypto_TranslateSha2DmaRequest(
633+
uint16_t magic, const whMessageCrypto_Sha2DmaRequest* src,
634+
whMessageCrypto_Sha2DmaRequest* dest)
680635
{
681636
int ret;
682637

@@ -705,10 +660,10 @@ int wh_MessageCrypto_TranslateSha224DmaRequest(
705660
return 0;
706661
}
707662

708-
/* SHA224 DMA Response translation */
709-
int wh_MessageCrypto_TranslateSha224DmaResponse(
710-
uint16_t magic, const whMessageCrypto_Sha224DmaResponse* src,
711-
whMessageCrypto_Sha224DmaResponse* dest)
663+
/* SHA2 DMA Response translation */
664+
int wh_MessageCrypto_TranslateSha2DmaResponse(
665+
uint16_t magic, const whMessageCrypto_Sha2DmaResponse* src,
666+
whMessageCrypto_Sha2DmaResponse* dest)
712667
{
713668
if ((src == NULL) || (dest == NULL)) {
714669
return WH_ERROR_BADARGS;
@@ -717,94 +672,6 @@ int wh_MessageCrypto_TranslateSha224DmaResponse(
717672
&dest->dmaAddrStatus);
718673
}
719674

720-
/* SHA384 DMA Request translation */
721-
int wh_MessageCrypto_TranslateSha384DmaRequest(
722-
uint16_t magic, const whMessageCrypto_Sha384DmaRequest* src,
723-
whMessageCrypto_Sha384DmaRequest* dest)
724-
{
725-
int ret;
726-
727-
if ((src == NULL) || (dest == NULL)) {
728-
return WH_ERROR_BADARGS;
729-
}
730-
731-
WH_T64(magic, dest, src, finalize);
732-
733-
ret = wh_MessageCrypto_TranslateDmaBuffer(magic, &src->input, &dest->input);
734-
if (ret != 0) {
735-
return ret;
736-
}
737-
738-
ret = wh_MessageCrypto_TranslateDmaBuffer(magic, &src->state, &dest->state);
739-
if (ret != 0) {
740-
return ret;
741-
}
742-
743-
ret =
744-
wh_MessageCrypto_TranslateDmaBuffer(magic, &src->output, &dest->output);
745-
if (ret != 0) {
746-
return ret;
747-
}
748-
749-
return 0;
750-
}
751-
752-
/* SHA384 DMA Response translation */
753-
int wh_MessageCrypto_TranslateSha384DmaResponse(
754-
uint16_t magic, const whMessageCrypto_Sha384DmaResponse* src,
755-
whMessageCrypto_Sha384DmaResponse* dest)
756-
{
757-
if ((src == NULL) || (dest == NULL)) {
758-
return WH_ERROR_BADARGS;
759-
}
760-
return wh_MessageCrypto_TranslateDmaAddrStatus(magic, &src->dmaAddrStatus,
761-
&dest->dmaAddrStatus);
762-
}
763-
/* SHA512 DMA Request translation */
764-
int wh_MessageCrypto_TranslateSha512DmaRequest(
765-
uint16_t magic, const whMessageCrypto_Sha512DmaRequest* src,
766-
whMessageCrypto_Sha512DmaRequest* dest)
767-
{
768-
int ret;
769-
770-
if ((src == NULL) || (dest == NULL)) {
771-
return WH_ERROR_BADARGS;
772-
}
773-
774-
WH_T64(magic, dest, src, finalize);
775-
776-
ret = wh_MessageCrypto_TranslateDmaBuffer(magic, &src->input, &dest->input);
777-
if (ret != 0) {
778-
return ret;
779-
}
780-
781-
ret = wh_MessageCrypto_TranslateDmaBuffer(magic, &src->state, &dest->state);
782-
if (ret != 0) {
783-
return ret;
784-
}
785-
786-
ret =
787-
wh_MessageCrypto_TranslateDmaBuffer(magic, &src->output, &dest->output);
788-
if (ret != 0) {
789-
return ret;
790-
}
791-
792-
return 0;
793-
}
794-
795-
/* SHA512 DMA Response translation */
796-
int wh_MessageCrypto_TranslateSha512DmaResponse(
797-
uint16_t magic, const whMessageCrypto_Sha512DmaResponse* src,
798-
whMessageCrypto_Sha512DmaResponse* dest)
799-
{
800-
if ((src == NULL) || (dest == NULL)) {
801-
return WH_ERROR_BADARGS;
802-
}
803-
return wh_MessageCrypto_TranslateDmaAddrStatus(magic, &src->dmaAddrStatus,
804-
&dest->dmaAddrStatus);
805-
}
806-
807-
808675
/* CMAC DMA Request translation */
809676
int wh_MessageCrypto_TranslateCmacDmaRequest(
810677
uint16_t magic, const whMessageCrypto_CmacDmaRequest* src,

src/wh_server_crypto.c

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,8 +1745,7 @@ static int _HandleSha256(whServerContext* ctx, uint16_t magic,
17451745
if (ret != 0) {
17461746
return ret;
17471747
}
1748-
/* Init the SHA256 context if this is the first time, otherwise restore the
1749-
* hash state from the client */
1748+
/* restore the hash state from the client */
17501749
memcpy(sha256->digest, req.resumeState.hash, WC_SHA256_DIGEST_SIZE);
17511750
sha256->loLen = req.resumeState.loLen;
17521751
sha256->hiLen = req.resumeState.hiLen;
@@ -2641,14 +2640,14 @@ static int _HandleSha256Dma(whServerContext* ctx, uint16_t magic, uint16_t seq,
26412640
(void)inSize;
26422641

26432642
int ret = 0;
2644-
whMessageCrypto_Sha256DmaRequest req;
2645-
whMessageCrypto_Sha256DmaResponse res;
2643+
whMessageCrypto_Sha2DmaRequest req;
2644+
whMessageCrypto_Sha2DmaResponse res;
26462645
wc_Sha256 sha256[1];
26472646
int clientDevId;
26482647

26492648
/* Translate the request */
2650-
ret = wh_MessageCrypto_TranslateSha256DmaRequest(
2651-
magic, (whMessageCrypto_Sha256DmaRequest*)cryptoDataIn, &req);
2649+
ret = wh_MessageCrypto_TranslateSha2DmaRequest(
2650+
magic, (whMessageCrypto_Sha2DmaRequest*)cryptoDataIn, &req);
26522651
if (ret != WH_ERROR_OK) {
26532652
return ret;
26542653
}
@@ -2746,8 +2745,8 @@ static int _HandleSha256Dma(whServerContext* ctx, uint16_t magic, uint16_t seq,
27462745
}
27472746

27482747
/* Translate the response */
2749-
(void)wh_MessageCrypto_TranslateSha256DmaResponse(
2750-
magic, &res, (whMessageCrypto_Sha256DmaResponse*)cryptoDataOut);
2748+
(void)wh_MessageCrypto_TranslateSha2DmaResponse(
2749+
magic, &res, (whMessageCrypto_Sha2DmaResponse*)cryptoDataOut);
27512750
*outSize = sizeof(res);
27522751

27532752
/* return value populates rc in response message */
@@ -2763,14 +2762,14 @@ static int _HandleSha224Dma(whServerContext* ctx, uint16_t magic, uint16_t seq,
27632762
(void)seq;
27642763
(void)inSize;
27652764
int ret = 0;
2766-
whMessageCrypto_Sha224DmaRequest req;
2767-
whMessageCrypto_Sha224DmaResponse res;
2765+
whMessageCrypto_Sha2DmaRequest req;
2766+
whMessageCrypto_Sha2DmaResponse res;
27682767
wc_Sha224 sha224[1];
27692768
int clientDevId;
27702769

27712770
/* Translate the request */
2772-
ret = wh_MessageCrypto_TranslateSha224DmaRequest(
2773-
magic, (whMessageCrypto_Sha224DmaRequest*)cryptoDataIn, &req);
2771+
ret = wh_MessageCrypto_TranslateSha2DmaRequest(
2772+
magic, (whMessageCrypto_Sha2DmaRequest*)cryptoDataIn, &req);
27742773
if (ret != WH_ERROR_OK) {
27752774
return ret;
27762775
}
@@ -2868,8 +2867,8 @@ static int _HandleSha224Dma(whServerContext* ctx, uint16_t magic, uint16_t seq,
28682867
}
28692868

28702869
/* Translate the response */
2871-
(void)wh_MessageCrypto_TranslateSha224DmaResponse(
2872-
magic, &res, (whMessageCrypto_Sha224DmaResponse*)cryptoDataOut);
2870+
(void)wh_MessageCrypto_TranslateSha2DmaResponse(
2871+
magic, &res, (whMessageCrypto_Sha2DmaResponse*)cryptoDataOut);
28732872
*outSize = sizeof(res);
28742873

28752874
/* return value populates rc in response message */
@@ -2885,14 +2884,14 @@ static int _HandleSha384Dma(whServerContext* ctx, uint16_t magic, uint16_t seq,
28852884
(void)seq;
28862885
(void)inSize;
28872886
int ret = 0;
2888-
whMessageCrypto_Sha384DmaRequest req;
2889-
whMessageCrypto_Sha384DmaResponse res;
2887+
whMessageCrypto_Sha2DmaRequest req;
2888+
whMessageCrypto_Sha2DmaResponse res;
28902889
wc_Sha384 sha384[1];
28912890
int clientDevId;
28922891

28932892
/* Translate the request */
2894-
ret = wh_MessageCrypto_TranslateSha384DmaRequest(
2895-
magic, (whMessageCrypto_Sha384DmaRequest*)cryptoDataIn, &req);
2893+
ret = wh_MessageCrypto_TranslateSha2DmaRequest(
2894+
magic, (whMessageCrypto_Sha2DmaRequest*)cryptoDataIn, &req);
28962895
if (ret != WH_ERROR_OK) {
28972896
return ret;
28982897
}
@@ -2990,8 +2989,8 @@ static int _HandleSha384Dma(whServerContext* ctx, uint16_t magic, uint16_t seq,
29902989
}
29912990

29922991
/* Translate the response */
2993-
(void)wh_MessageCrypto_TranslateSha384DmaResponse(
2994-
magic, &res, (whMessageCrypto_Sha384DmaResponse*)cryptoDataOut);
2992+
(void)wh_MessageCrypto_TranslateSha2DmaResponse(
2993+
magic, &res, (whMessageCrypto_Sha2DmaResponse*)cryptoDataOut);
29952994
*outSize = sizeof(res);
29962995

29972996
/* return value populates rc in response message */
@@ -3007,15 +3006,15 @@ static int _HandleSha512Dma(whServerContext* ctx, uint16_t magic, uint16_t seq,
30073006
(void)seq;
30083007
(void)inSize;
30093008
int ret = 0;
3010-
whMessageCrypto_Sha512DmaRequest req;
3011-
whMessageCrypto_Sha512DmaResponse res;
3009+
whMessageCrypto_Sha2DmaRequest req;
3010+
whMessageCrypto_Sha2DmaResponse res;
30123011
wc_Sha512 sha512[1];
30133012
int clientDevId;
30143013
int hashType = WC_HASH_TYPE_SHA512;
30153014

30163015
/* Translate the request */
3017-
ret = wh_MessageCrypto_TranslateSha512DmaRequest(
3018-
magic, (whMessageCrypto_Sha512DmaRequest*)cryptoDataIn, &req);
3016+
ret = wh_MessageCrypto_TranslateSha2DmaRequest(
3017+
magic, (whMessageCrypto_Sha2DmaRequest*)cryptoDataIn, &req);
30193018
if (ret != WH_ERROR_OK) {
30203019
return ret;
30213020
}
@@ -3125,8 +3124,8 @@ static int _HandleSha512Dma(whServerContext* ctx, uint16_t magic, uint16_t seq,
31253124
}
31263125

31273126
/* Translate the response */
3128-
(void)wh_MessageCrypto_TranslateSha512DmaResponse(
3129-
magic, &res, (whMessageCrypto_Sha512DmaResponse*)cryptoDataOut);
3127+
(void)wh_MessageCrypto_TranslateSha2DmaResponse(
3128+
magic, &res, (whMessageCrypto_Sha2DmaResponse*)cryptoDataOut);
31303129
*outSize = sizeof(res);
31313130

31323131
/* return value populates rc in response message */

test/wh_test_check_struct_padding.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ whMessageCrypto_Sha2Response hashSha2Res;
120120

121121
/* DMA crypto messages */
122122
#if defined(WOLFHSM_CFG_DMA)
123-
whMessageCrypto_Sha256DmaRequest hashSha256DmaReq;
124-
whMessageCrypto_Sha256DmaResponse hashSha256DmaRes;
123+
whMessageCrypto_Sha2DmaRequest hashSha2DmaReq;
124+
whMessageCrypto_Sha2DmaResponse hashSha2DmaRes;
125125
whMessageCrypto_MlDsaKeyGenDmaRequest pqMldsaKeygenDmaReq;
126126
whMessageCrypto_MlDsaKeyGenDmaResponse pqMldsaKeygenDmaRes;
127127
whMessageCrypto_MlDsaSignDmaRequest pqMldsaSignDmaReq;

0 commit comments

Comments
 (0)