Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/wh_client_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -3008,6 +3008,14 @@ static int _Curve25519MakeKey(whClientContext* ctx, uint16_t size,
(uint8_t**)&res);
/* wolfCrypt allows positive error codes on success in some scenarios */
if (ret >= 0) {
const size_t hdr_sz =
sizeof(whMessageCrypto_GenericResponseHeader) + sizeof(*res);

/* Defensive bound: res->len must fit within the received frame */
if (data_len < hdr_sz || res->len > (data_len - hdr_sz)) {
return WH_ERROR_ABORTED;
}

WH_DEBUG_CLIENT_VERBOSE("Curve25519 KeyGen Res recv:keyid:%u, len:%u, "
"ret:%d\n",
(unsigned int)res->keyId, (unsigned int)res->len, ret);
Expand Down Expand Up @@ -3470,6 +3478,14 @@ static int _Ed25519MakeKey(whClientContext* ctx, whKeyId* inout_key_id,
ret =
_getCryptoResponse(dataPtr, WC_PK_TYPE_ED25519_KEYGEN, (uint8_t**)&res);
if (ret >= 0) {
const size_t hdr_sz =
sizeof(whMessageCrypto_GenericResponseHeader) + sizeof(*res);

/* Defensive bound: res->outSz must fit within the received frame */
if (res_len < hdr_sz || res->outSz > (res_len - hdr_sz)) {
return WH_ERROR_ABORTED;
}

key_id = (whKeyId)res->keyId;
if (inout_key_id != NULL) {
*inout_key_id = key_id;
Expand All @@ -3479,11 +3495,6 @@ static int _Ed25519MakeKey(whClientContext* ctx, whKeyId* inout_key_id,
if (flags & WH_NVM_FLAGS_EPHEMERAL) {
uint8_t* out = (uint8_t*)(res + 1);
uint16_t outSz = (uint16_t)res->outSz;
if (outSz + sizeof(whMessageCrypto_GenericResponseHeader) +
sizeof(*res) >
WOLFHSM_CFG_COMM_DATA_LEN) {
return WH_ERROR_ABORTED;
}
ret = wh_Crypto_Ed25519DeserializeKeyDer(out, outSz, key);
}
}
Expand Down
Loading
Loading