Skip to content

Commit 8d45952

Browse files
committed
review: hash type macro protection and padding
1 parent 2672aa8 commit 8d45952

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/wh_client_crypto.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5709,7 +5709,7 @@ int wh_Client_Sha384DmaUpdateRequest(whClientContext* ctx, wc_Sha384* sha,
57095709
memcpy(req->resumeState.hash, sha->digest, WC_SHA512_DIGEST_SIZE);
57105710
req->resumeState.hiLen = sha->hiLen;
57115711
req->resumeState.loLen = sha->loLen;
5712-
req->resumeState.hashType = sha->hashType;
5712+
req->resumeState.hashType = WC_HASH_TYPE_SHA384;
57135713
req->input.sz = dmaSz;
57145714
req->input.addr = 0;
57155715

@@ -5817,7 +5817,7 @@ int wh_Client_Sha384DmaFinalRequest(whClientContext* ctx, wc_Sha384* sha)
58175817
memcpy(req->resumeState.hash, sha->digest, WC_SHA512_DIGEST_SIZE);
58185818
req->resumeState.hiLen = sha->hiLen;
58195819
req->resumeState.loLen = sha->loLen;
5820-
req->resumeState.hashType = sha->hashType;
5820+
req->resumeState.hashType = WC_HASH_TYPE_SHA384;
58215821
req->input.sz = 0;
58225822
req->input.addr = 0;
58235823

@@ -6117,14 +6117,18 @@ int wh_Client_Sha512FinalResponse(whClientContext* ctx, wc_Sha512* sha,
61176117
/* reset the state of the sha context (without blowing away devId and
61186118
* hashType), and copy only the digest bytes for the active variant */
61196119
switch (hashType) {
6120+
#ifndef WOLFSSL_NOSHA512_224
61206121
case WC_HASH_TYPE_SHA512_224:
61216122
memcpy(out, res->hash, WC_SHA512_224_DIGEST_SIZE);
61226123
(void)wc_InitSha512_224_ex(sha, NULL, sha->devId);
61236124
break;
6125+
#endif
6126+
#ifndef WOLFSSL_NOSHA512_256
61246127
case WC_HASH_TYPE_SHA512_256:
61256128
memcpy(out, res->hash, WC_SHA512_256_DIGEST_SIZE);
61266129
(void)wc_InitSha512_256_ex(sha, NULL, sha->devId);
61276130
break;
6131+
#endif
61286132
default:
61296133
memcpy(out, res->hash, WC_SHA512_DIGEST_SIZE);
61306134
(void)wc_InitSha512_ex(sha, NULL, sha->devId);
@@ -6408,14 +6412,18 @@ int wh_Client_Sha512DmaFinalResponse(whClientContext* ctx, wc_Sha512* sha,
64086412
* and hashType), and copy only the digest bytes for the active
64096413
* variant */
64106414
switch (hashType) {
6415+
#ifndef WOLFSSL_NOSHA512_224
64116416
case WC_HASH_TYPE_SHA512_224:
64126417
memcpy(out, resp->hash, WC_SHA512_224_DIGEST_SIZE);
64136418
(void)wc_InitSha512_224_ex(sha, NULL, sha->devId);
64146419
break;
6420+
#endif
6421+
#ifndef WOLFSSL_NOSHA512_256
64156422
case WC_HASH_TYPE_SHA512_256:
64166423
memcpy(out, resp->hash, WC_SHA512_256_DIGEST_SIZE);
64176424
(void)wc_InitSha512_256_ex(sha, NULL, sha->devId);
64186425
break;
6426+
#endif
64196427
default:
64206428
memcpy(out, resp->hash, WC_SHA512_DIGEST_SIZE);
64216429
(void)wc_InitSha512_ex(sha, NULL, sha->devId);

src/wh_server_crypto.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5149,12 +5149,16 @@ static int _HandleSha512Dma(whServerContext* ctx, uint16_t magic, int devId,
51495149
if (ret == 0) {
51505150
if (req.isLastBlock) {
51515151
switch (hashType) {
5152+
#ifndef WOLFSSL_NOSHA512_224
51525153
case WC_HASH_TYPE_SHA512_224:
51535154
ret = wc_Sha512_224Final(sha512, res.hash);
51545155
break;
5156+
#endif
5157+
#ifndef WOLFSSL_NOSHA512_256
51555158
case WC_HASH_TYPE_SHA512_256:
51565159
ret = wc_Sha512_256Final(sha512, res.hash);
51575160
break;
5161+
#endif
51585162
default:
51595163
ret = wc_Sha512Final(sha512, res.hash);
51605164
break;

wolfhsm/wh_message_crypto.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,7 @@ typedef struct {
10521052
uint32_t loLen;
10531053
uint8_t hash[64]; /* WC_SHA512_DIGEST_SIZE */
10541054
uint32_t hashType;
1055+
uint8_t WH_PAD[4];
10551056
} resumeState;
10561057
whMessageCrypto_DmaBuffer input;
10571058
uint32_t isLastBlock;
@@ -1065,6 +1066,7 @@ typedef struct {
10651066
uint8_t hash[64]; /* big enough for all SHA2 variants */
10661067
uint32_t hashType;
10671068
whMessageCrypto_DmaAddrStatus dmaAddrStatus;
1069+
uint8_t WH_PAD[4];
10681070
} whMessageCrypto_Sha2DmaResponse;
10691071

10701072
/* SHA2 DMA translation functions */

0 commit comments

Comments
 (0)