Skip to content

Commit

Permalink
remove resume flag in message and client context, as it is redundant
Browse files Browse the repository at this point in the history
  • Loading branch information
bigbrett committed Aug 9, 2024
1 parent 45e7daf commit 237c8d5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
18 changes: 6 additions & 12 deletions src/wh_client_cryptocb.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,9 +948,6 @@ static int _xferSha256BlockAndUpdateDigest(whClientContext* ctx,
uint16_t dataSz = 0;
wh_Packet_hash_sha256_req* req = &packet->hashSha256Req;

/* Unused wolfCrypt hash flag value. TODO: use devCtx? */
const uint32_t RESUME_HASH_BIT_FLAG = 0x80000000;

/* Ensure we always set the packet type, as if this function is called after
* a response, it will be overwritten*/
req->type = WC_HASH_TYPE_SHA256;
Expand All @@ -969,13 +966,11 @@ static int _xferSha256BlockAndUpdateDigest(whClientContext* ctx,
XMEMCPY(req->inBlock, sha256->buffer,
(isLastBlock) ? sha256->buffLen : WC_SHA256_BLOCK_SIZE);

/* If we are resuming, send the hash state */
if ((sha256->flags & RESUME_HASH_BIT_FLAG) != 0) {
req->resumeState.resumeHashFlag = 1;
XMEMCPY(req->resumeState.hash, sha256->digest, WC_SHA256_DIGEST_SIZE);
packet->hashSha256Req.resumeState.hiLen = sha256->hiLen;
packet->hashSha256Req.resumeState.loLen = sha256->loLen;
}
/* Send the hash state - this will be 0 on the first block on a properly
* initialized sha256 struct */
XMEMCPY(req->resumeState.hash, sha256->digest, WC_SHA256_DIGEST_SIZE);
packet->hashSha256Req.resumeState.hiLen = sha256->hiLen;
packet->hashSha256Req.resumeState.loLen = sha256->loLen;

ret = wh_Client_SendRequest(
ctx, group, WC_ALGO_TYPE_HASH,
Expand All @@ -984,7 +979,7 @@ static int _xferSha256BlockAndUpdateDigest(whClientContext* ctx,
#ifdef DEBUG_CRYPTOCB_VERBOSE
printf("[client] send SHA256 Req:\n");
_hexdump("[client] inBlock: ", req->inBlock, WC_SHA256_BLOCK_SIZE);
if (req->resumeState.resumeHashFlag) {
if (req->resumeState.hiLen != 0 || req->resumeState.loLen != 0) {
_hexdump(" [client] resumeHash: ", req->resumeState.hash,
(isLastBlock) ? req->lastBlockLen : WC_SHA256_BLOCK_SIZE);
printf(" [client] hiLen: %u, loLen: %u\n", req->resumeState.hiLen,
Expand Down Expand Up @@ -1014,7 +1009,6 @@ static int _xferSha256BlockAndUpdateDigest(whClientContext* ctx,
WC_SHA256_DIGEST_SIZE);
sha256->hiLen = packet->hashSha256Res.hiLen;
sha256->loLen = packet->hashSha256Res.loLen;
sha256->flags |= RESUME_HASH_BIT_FLAG;
#ifdef DEBUG_CRYPTOCB_VERBOSE
printf("[client] Client SHA256 Res recv:\n");
_hexdump("[client] hash: ", (uint8_t*)sha256->digest,
Expand Down
2 changes: 1 addition & 1 deletion src/wh_server_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ static int hsmCryptoSha256(whServerContext* server, whPacket* packet,

/* Init the SHA256 context if this is the first time, otherwise restore the
* hash state from the client */
if (req->resumeState.resumeHashFlag == 0) {
if (req->resumeState.hiLen == 0 && req->resumeState.loLen == 0) {
ret = wc_InitSha256_ex(sha256, NULL, server->crypto->devId);
}
else {
Expand Down
2 changes: 0 additions & 2 deletions wolfhsm/wh_packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ typedef struct wh_Packet_hash_sha256_req {
/* TODO change to "wh_Packet_hash_any_req header" */
uint32_t type; /* enum wc_HashType */
struct {
/* Flag indicating whether to use the intermediate hash */
uint32_t resumeHashFlag;
uint32_t hiLen;
uint32_t loLen;
/* intermediate hash value */
Expand Down

0 comments on commit 237c8d5

Please sign in to comment.