diff --git a/docs/src-ja/chapter04.md b/docs/src-ja/chapter04.md index de35be4d0..e733daf7d 100644 --- a/docs/src-ja/chapter04.md +++ b/docs/src-ja/chapter04.md @@ -145,7 +145,7 @@ rc = wh_CommClient_SendRequest(context, req_magic, req_type, &request_id, uint16_t resp_magic, resp_type, resp_id, resp_size; char response_data[20]; while((rc = wh_CommClient_RecvResponse(context,&resp_magic, &resp_type, &resp_id, - &resp_size, resp_data)) == WH_ERROR_NOTREADY) { + &resp_size, sizeof(response_data), response_data)) == WH_ERROR_NOTREADY) { /* 他のタスクを実行 or yield */ } ``` diff --git a/src/wh_client.c b/src/wh_client.c index 5c22f58ae..999044fa3 100644 --- a/src/wh_client.c +++ b/src/wh_client.c @@ -157,12 +157,11 @@ int wh_Client_SendRequest(whClientContext* c, int wh_Client_RecvResponse(whClientContext *c, uint16_t *out_group, uint16_t *out_action, - uint16_t *out_size, void* data) + uint16_t *out_size, uint16_t data_size, void* data) { int rc = 0; uint16_t resp_kind = 0; uint16_t resp_id = 0; - uint16_t resp_size = 0; if (c == NULL) { return WH_ERROR_BADARGS; @@ -170,7 +169,7 @@ int wh_Client_RecvResponse(whClientContext *c, /* Comm layer performs magic and sequence validation */ rc = wh_CommClient_RecvResponse(c->comm, NULL, &resp_kind, &resp_id, - &resp_size, data); + out_size, data_size, data); if (rc == 0) { if ((resp_kind != c->last_req_kind) || (resp_id != c->last_req_id)) { /* Response kind/id doesn't match outstanding request. */ @@ -183,9 +182,6 @@ int wh_Client_RecvResponse(whClientContext *c, if (out_action != NULL) { *out_action = WH_MESSAGE_ACTION(resp_kind); } - if (out_size != NULL) { - *out_size = resp_size; - } } } return rc; @@ -231,7 +227,7 @@ int wh_Client_CommInitResponse(whClientContext* c, rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, - &resp_size, &msg); + &resp_size, sizeof(msg), &msg); if (rc == 0) { /* Validate response */ if ( (resp_group != WH_MESSAGE_GROUP_COMM) || @@ -311,7 +307,7 @@ int wh_Client_CommInfoResponse(whClientContext* c, rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, - &resp_size, &msg); + &resp_size, sizeof(msg), &msg); if (rc == 0) { /* Validate response */ if ( (resp_group != WH_MESSAGE_GROUP_COMM) || @@ -461,7 +457,7 @@ int wh_Client_CommCloseResponse(whClientContext* c) rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, - &resp_size, NULL); + &resp_size, 0, NULL); if (rc == 0) { /* Validate response */ if ( (resp_group != WH_MESSAGE_GROUP_COMM) || @@ -534,7 +530,7 @@ int wh_Client_EchoResponse(whClientContext* c, uint16_t *out_size, void* data) rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, - &resp_size, msg); + &resp_size, WOLFHSM_CFG_COMM_DATA_LEN, msg); if (rc == 0) { /* Validate response */ if ( (resp_group != WH_MESSAGE_GROUP_COMM) || @@ -596,7 +592,8 @@ int wh_Client_CustomCbResponse(whClientContext* c, } rc = - wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, &resp); + wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, + sizeof(resp), &resp); if (rc != WH_ERROR_OK) { return rc; } @@ -746,7 +743,7 @@ int wh_Client_KeyCacheResponse(whClientContext* c, uint16_t* keyId) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == WH_ERROR_OK) { if (resp->rc != 0) { ret = resp->rc; @@ -809,7 +806,8 @@ int wh_Client_KeyEvictResponse(whClientContext* c) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)&resp); + ret = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(resp), + (uint8_t*)&resp); if (ret == 0) { if (resp.rc != 0) { @@ -872,7 +870,7 @@ int wh_Client_KeyExportResponse(whClientContext* c, uint8_t* label, } packOut = (uint8_t*)(resp + 1); - ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == WH_ERROR_OK) { if (resp->rc != 0) { ret = resp->rc; @@ -957,7 +955,7 @@ int wh_Client_KeyExportPublicResponse(whClientContext* c, uint8_t* label, } packOut = (uint8_t*)(resp + 1); - ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == WH_ERROR_OK) { if (resp->rc != 0) { ret = resp->rc; @@ -1034,7 +1032,7 @@ int wh_Client_KeyCommitResponse(whClientContext* c) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == WH_ERROR_OK) { if (resp->rc != 0) { ret = resp->rc; @@ -1090,7 +1088,7 @@ int wh_Client_KeyEraseResponse(whClientContext* c) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == 0) { if (resp->rc != 0) { ret = resp->rc; @@ -1146,7 +1144,7 @@ int wh_Client_KeyRevokeResponse(whClientContext* c) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == 0) { if (resp->rc != 0) { ret = resp->rc; @@ -1204,7 +1202,7 @@ int wh_Client_CounterInitResponse(whClientContext* c, uint32_t* counter) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == WH_ERROR_OK) { if (resp->rc != 0) { ret = resp->rc; @@ -1282,7 +1280,7 @@ int wh_Client_CounterIncrementResponse(whClientContext* c, uint32_t* counter) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == WH_ERROR_OK) { if (resp->rc != 0) { ret = resp->rc; @@ -1342,7 +1340,7 @@ int wh_Client_CounterReadResponse(whClientContext* c, uint32_t* counter) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == WH_ERROR_OK) { if (resp->rc != 0) { ret = resp->rc; @@ -1402,7 +1400,7 @@ int wh_Client_CounterDestroyResponse(whClientContext* c) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == WH_ERROR_OK) { if (resp->rc != 0) { ret = resp->rc; @@ -1491,7 +1489,7 @@ int wh_Client_KeyCacheDmaResponse(whClientContext* c, uint16_t* keyId) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(c, &group, &action, &size, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &size, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == 0) { /* Validate response */ @@ -1570,7 +1568,7 @@ int wh_Client_KeyExportDmaResponse(whClientContext* c, uint8_t* label, } rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, - (uint8_t*)resp); + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (rc == 0) { /* Validate response */ if ((resp_group != WH_MESSAGE_GROUP_KEY) || @@ -1659,7 +1657,7 @@ int wh_Client_KeyExportPublicDmaResponse(whClientContext* c, uint8_t* label, } rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, - (uint8_t*)resp); + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (rc == 0) { if (resp_size != sizeof(*resp)) { rc = WH_ERROR_ABORTED; diff --git a/src/wh_client_auth.c b/src/wh_client_auth.c index 22ca01c13..5b8d74842 100644 --- a/src/wh_client_auth.c +++ b/src/wh_client_auth.c @@ -127,7 +127,7 @@ int wh_Client_AuthLoginResponse(whClientContext* c, int32_t* out_rc, } rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, - buffer); + sizeof(buffer), buffer); if (rc == WH_ERROR_OK) { /* Validate response */ if ((resp_group != WH_MESSAGE_GROUP_AUTH) || @@ -212,7 +212,7 @@ int wh_Client_AuthLogoutResponse(whClientContext* c, int32_t* out_rc) } rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, - buffer); + sizeof(buffer), buffer); if (rc == WH_ERROR_OK) { /* Validate response */ if ((resp_group != WH_MESSAGE_GROUP_AUTH) || @@ -329,7 +329,7 @@ int wh_Client_AuthUserAddResponse(whClientContext* c, int32_t* out_rc, } rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, - buffer); + sizeof(buffer), buffer); if (rc == WH_ERROR_OK) { /* Validate response */ if ((resp_group != WH_MESSAGE_GROUP_AUTH) || @@ -404,7 +404,7 @@ int wh_Client_AuthUserDeleteResponse(whClientContext* c, int32_t* out_rc) } rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, - buffer); + sizeof(buffer), buffer); if (rc == WH_ERROR_OK) { /* Validate response */ if ((resp_group != WH_MESSAGE_GROUP_AUTH) || @@ -480,7 +480,7 @@ int wh_Client_AuthUserGetResponse(whClientContext* c, int32_t* out_rc, } rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, - buffer); + sizeof(buffer), buffer); if (rc == WH_ERROR_OK) { /* Validate response */ if ((resp_group != WH_MESSAGE_GROUP_AUTH) || @@ -567,7 +567,7 @@ int wh_Client_AuthUserSetPermissionsResponse(whClientContext* c, } rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, - buffer); + sizeof(buffer), buffer); if (rc == WH_ERROR_OK) { /* Validate response */ if ((resp_group != WH_MESSAGE_GROUP_AUTH) || @@ -685,7 +685,7 @@ int wh_Client_AuthUserSetCredentialsResponse(whClientContext* c, } rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, - buffer); + sizeof(buffer), buffer); if (rc == WH_ERROR_OK) { /* Validate response */ if ((resp_group != WH_MESSAGE_GROUP_AUTH) || diff --git a/src/wh_client_cert.c b/src/wh_client_cert.c index 0b1e3abe9..3c3b009f9 100644 --- a/src/wh_client_cert.c +++ b/src/wh_client_cert.c @@ -78,7 +78,7 @@ int wh_Client_CertInitResponse(whClientContext* c, int32_t* out_rc) } /* Receive and validate response */ - rc = wh_Client_RecvResponse(c, &group, &action, &size, &resp); + rc = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(resp), &resp); if (rc == 0) { if ((group != WH_MESSAGE_GROUP_CERT) || (action != WH_MESSAGE_CERT_ACTION_INIT) || (size != sizeof(resp))) { @@ -166,7 +166,7 @@ int wh_Client_CertAddTrustedResponse(whClientContext* c, int32_t* out_rc) } /* Receive and validate response */ - rc = wh_Client_RecvResponse(c, &group, &action, &size, &resp); + rc = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(resp), &resp); if (rc == 0) { if ((group != WH_MESSAGE_GROUP_CERT) || (action != WH_MESSAGE_CERT_ACTION_ADDTRUSTED) || @@ -237,7 +237,7 @@ int wh_Client_CertEraseTrustedResponse(whClientContext* c, int32_t* out_rc) } /* Receive and validate response */ - rc = wh_Client_RecvResponse(c, &group, &action, &size, &resp); + rc = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(resp), &resp); if (rc == 0) { if ((group != WH_MESSAGE_GROUP_CERT) || (action != WH_MESSAGE_CERT_ACTION_ERASETRUSTED) || @@ -310,7 +310,8 @@ int wh_Client_CertReadTrustedResponse(whClientContext* c, uint8_t* cert, } /* Receive and validate response */ - rc = wh_Client_RecvResponse(c, &group, &action, &size, buffer); + rc = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(buffer), + buffer); if (rc == 0) { if ((group != WH_MESSAGE_GROUP_CERT) || (action != WH_MESSAGE_CERT_ACTION_READTRUSTED) || @@ -415,7 +416,7 @@ static int _certVerifyResponse(whClientContext* c, whKeyId* out_keyId, } /* Receive and validate response */ - rc = wh_Client_RecvResponse(c, &group, &action, &size, &resp); + rc = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(resp), &resp); if (rc == 0) { if ((group != WH_MESSAGE_GROUP_CERT) || (action != WH_MESSAGE_CERT_ACTION_VERIFY) || @@ -568,7 +569,7 @@ static int _certVerifyMultiRootResponse(whClientContext* c, whKeyId* out_keyId, return WH_ERROR_BADARGS; } - rc = wh_Client_RecvResponse(c, &group, &action, &size, &resp); + rc = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(resp), &resp); if (rc == 0) { if ((group != WH_MESSAGE_GROUP_CERT) || (action != WH_MESSAGE_CERT_ACTION_VERIFY_MULTI_ROOT) || @@ -698,7 +699,7 @@ int wh_Client_CertVerifyCacheClearResponse(whClientContext* c, int32_t* out_rc) return WH_ERROR_BADARGS; } - rc = wh_Client_RecvResponse(c, &group, &action, &size, &resp); + rc = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(resp), &resp); if (rc == WH_ERROR_OK) { if ((group != WH_MESSAGE_GROUP_CERT) || (action != WH_MESSAGE_CERT_ACTION_VERIFY_CACHE_CLEAR) || @@ -763,7 +764,7 @@ int wh_Client_CertVerifyCacheSetEnabledResponse(whClientContext* c, return WH_ERROR_BADARGS; } - rc = wh_Client_RecvResponse(c, &group, &action, &size, &resp); + rc = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(resp), &resp); if (rc == WH_ERROR_OK) { if ((group != WH_MESSAGE_GROUP_CERT) || (action != WH_MESSAGE_CERT_ACTION_VERIFY_CACHE_SET_ENABLED) || @@ -843,7 +844,7 @@ int wh_Client_CertAddTrustedDmaResponse(whClientContext* c, int32_t* out_rc) } /* Receive and validate response */ - rc = wh_Client_RecvResponse(c, &group, &action, &size, &resp); + rc = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(resp), &resp); if (rc == 0) { if ((group != WH_MESSAGE_GROUP_CERT) || (action != WH_MESSAGE_CERT_ACTION_ADDTRUSTED_DMA) || @@ -917,7 +918,7 @@ int wh_Client_CertReadTrustedDmaResponse(whClientContext* c, int32_t* out_rc) } /* Receive and validate response */ - rc = wh_Client_RecvResponse(c, &group, &action, &size, &resp); + rc = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(resp), &resp); if (rc == 0) { if ((group != WH_MESSAGE_GROUP_CERT) || (action != WH_MESSAGE_CERT_ACTION_READTRUSTED_DMA) || @@ -993,7 +994,7 @@ static int _certVerifyDmaResponse(whClientContext* c, whKeyId* out_keyId, } /* Receive and validate response */ - rc = wh_Client_RecvResponse(c, &group, &action, &size, &resp); + rc = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(resp), &resp); if (rc == 0) { if ((group != WH_MESSAGE_GROUP_CERT) || (action != WH_MESSAGE_CERT_ACTION_VERIFY_DMA) || @@ -1137,7 +1138,7 @@ static int _certVerifyMultiRootDmaResponse(whClientContext* c, return WH_ERROR_BADARGS; } - rc = wh_Client_RecvResponse(c, &group, &action, &size, &resp); + rc = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(resp), &resp); if (rc == 0) { if ((group != WH_MESSAGE_GROUP_CERT) || (action != WH_MESSAGE_CERT_ACTION_VERIFY_MULTI_ROOT_DMA) || @@ -1283,7 +1284,7 @@ int wh_Client_CertVerifyAcertResponse(whClientContext* c, int32_t* out_rc) uint16_t size; whMessageCert_SimpleResponse resp; - rc = wh_Client_RecvResponse(c, &group, &action, &size, &resp); + rc = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(resp), &resp); if (rc == 0) { if ((group != WH_MESSAGE_GROUP_CERT) || (action != WH_MESSAGE_CERT_ACTION_VERIFY_ACERT) || @@ -1356,7 +1357,7 @@ int wh_Client_CertVerifyAcertDmaResponse(whClientContext* c, int32_t* out_rc) return WH_ERROR_BADARGS; } - rc = wh_Client_RecvResponse(c, &group, &action, &size, &resp); + rc = wh_Client_RecvResponse(c, &group, &action, &size, sizeof(resp), &resp); if (rc == 0) { if ((group != WH_MESSAGE_GROUP_CERT) || (action != WH_MESSAGE_CERT_ACTION_VERIFY_ACERT_DMA) || diff --git a/src/wh_client_crypto.c b/src/wh_client_crypto.c index ed614d2a0..3ba732784 100644 --- a/src/wh_client_crypto.c +++ b/src/wh_client_crypto.c @@ -243,7 +243,7 @@ int wh_Client_RngGenerateResponse(whClientContext* ctx, uint8_t* out, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != WH_ERROR_OK) { return ret; } @@ -384,7 +384,7 @@ int wh_Client_RngGenerateDmaResponse(whClientContext* ctx) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_NOTREADY) { return ret; } @@ -510,7 +510,7 @@ int wh_Client_AesCtrResponse(whClientContext* ctx, Aes* aes, uint8_t* out, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_OK) { ret = _getCryptoResponse(dataPtr, WC_CIPHER_AES_CTR, (uint8_t**)&res); if (ret == WH_ERROR_OK) { @@ -695,7 +695,7 @@ int wh_Client_AesCtrDmaResponse(whClientContext* ctx, Aes* aes) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, NULL, NULL, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, NULL, NULL, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_NOTREADY) { return ret; } @@ -841,7 +841,7 @@ int wh_Client_AesEcbResponse(whClientContext* ctx, Aes* aes, uint8_t* out, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_OK) { ret = _getCryptoResponse(dataPtr, WC_CIPHER_AES_ECB, (uint8_t**)&res); if (ret == WH_ERROR_OK) { @@ -1012,7 +1012,7 @@ int wh_Client_AesEcbDmaResponse(whClientContext* ctx, Aes* aes) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, NULL, NULL, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, NULL, NULL, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_NOTREADY) { return ret; } @@ -1165,7 +1165,7 @@ int wh_Client_AesCbcResponse(whClientContext* ctx, Aes* aes, uint8_t* out, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_OK) { ret = _getCryptoResponse(dataPtr, WC_CIPHER_AES_CBC, (uint8_t**)&res); if (ret == WH_ERROR_OK) { @@ -1348,7 +1348,7 @@ int wh_Client_AesCbcDmaResponse(whClientContext* ctx, Aes* aes) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, NULL, NULL, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, NULL, NULL, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_NOTREADY) { return ret; } @@ -1521,7 +1521,7 @@ int wh_Client_AesGcmResponse(whClientContext* ctx, Aes* aes, uint8_t* out, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_OK) { ret = _getCryptoResponse(dataPtr, WC_CIPHER_AES_GCM, (uint8_t**)&res); if (ret == WH_ERROR_OK) { @@ -1745,7 +1745,7 @@ int wh_Client_AesGcmDmaResponse(whClientContext* ctx, Aes* aes, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, NULL, NULL, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, NULL, NULL, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_NOTREADY) { return ret; } @@ -1991,7 +1991,7 @@ static int _EccMakeKeyResponse(whClientContext* ctx, whKeyId* out_key_id, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != WH_ERROR_OK) { return ret; } @@ -2172,7 +2172,7 @@ int wh_Client_EccSharedSecretResponse(whClientContext* ctx, uint8_t* out, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != WH_ERROR_OK) { return ret; } @@ -2375,7 +2375,7 @@ int wh_Client_EccSignResponse(whClientContext* ctx, uint8_t* sig, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != WH_ERROR_OK) { return ret; } @@ -2577,7 +2577,7 @@ int wh_Client_EccVerifyResponse(whClientContext* ctx, ecc_key* opt_key, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != WH_ERROR_OK) { return ret; } @@ -2771,7 +2771,7 @@ int wh_Client_EccCheckPubKey(whClientContext* ctx, ecc_key* key, if (ret == 0) { do { ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, - (uint8_t*)packet); + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)packet); } while (ret == WH_ERROR_NOTREADY); } if (ret == 0) { @@ -2936,6 +2936,7 @@ static int _Curve25519MakeKey(whClientContext* ctx, uint16_t size, if (ret == 0) { do { ret = wh_Client_RecvResponse(ctx, &group, &action, &data_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); } @@ -3095,6 +3096,7 @@ int wh_Client_Curve25519SharedSecret(whClientContext* ctx, /* Recv Response */ do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); WH_DEBUG_CLIENT_VERBOSE("resp packet recv. ret:%d\n", @@ -3300,6 +3302,7 @@ static int _Ed25519MakeKey(whClientContext* ctx, whKeyId* inout_key_id, uint16_t res_len = 0; do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); @@ -3446,6 +3449,7 @@ int wh_Client_Ed25519Sign(whClientContext* ctx, ed25519_key* key, uint16_t res_len = 0; do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); @@ -3586,6 +3590,7 @@ int wh_Client_Ed25519Verify(whClientContext* ctx, ed25519_key* key, uint16_t res_len = 0; do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); @@ -3726,6 +3731,7 @@ int wh_Client_Ed25519SignDma(whClientContext* ctx, ed25519_key* key, uint16_t res_len = 0; do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); @@ -3873,6 +3879,7 @@ int wh_Client_Ed25519VerifyDma(whClientContext* ctx, ed25519_key* key, uint16_t res_len = 0; do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); @@ -4098,7 +4105,7 @@ static int _RsaMakeKeyResponse(whClientContext* ctx, whKeyId* out_key_id, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != WH_ERROR_OK) { return ret; } @@ -4278,7 +4285,7 @@ int wh_Client_RsaFunctionResponse(whClientContext* ctx, uint8_t* out, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != WH_ERROR_OK) { return ret; } @@ -4473,7 +4480,7 @@ int wh_Client_RsaGetSizeResponse(whClientContext* ctx, int* out_size) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != WH_ERROR_OK) { return ret; } @@ -4670,7 +4677,7 @@ static int _HkdfMakeKey(whClientContext* ctx, int hashType, whKeyId keyIdIn, uint16_t res_len = 0; do { ret = - wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); } while (ret == WH_ERROR_NOTREADY); WH_DEBUG_CLIENT_VERBOSE("HKDF Res recv: ret:%d, res_len: %u\n", ret, @@ -4837,7 +4844,7 @@ static int _CmacKdfMakeKey(whClientContext* ctx, whKeyId saltKeyId, uint16_t res_len = 0; do { - ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); } while (ret == WH_ERROR_NOTREADY); if (ret == WH_ERROR_OK) { @@ -5065,7 +5072,7 @@ int wh_Client_CmacGenerateResponse(whClientContext* ctx, Cmac* cmac, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != WH_ERROR_OK) { return ret; } @@ -5186,7 +5193,7 @@ int wh_Client_CmacUpdateResponse(whClientContext* ctx, Cmac* cmac) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != WH_ERROR_OK) { return ret; } @@ -5276,7 +5283,7 @@ int wh_Client_CmacFinalResponse(whClientContext* ctx, Cmac* cmac, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != WH_ERROR_OK) { return ret; } @@ -5516,7 +5523,7 @@ int wh_Client_CmacGenerateDmaResponse(whClientContext* ctx, Cmac* cmac, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_NOTREADY) { return ret; } @@ -5661,7 +5668,7 @@ int wh_Client_CmacDmaUpdateResponse(whClientContext* ctx, Cmac* cmac) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_NOTREADY) { return ret; } @@ -5751,7 +5758,7 @@ int wh_Client_CmacDmaFinalResponse(whClientContext* ctx, Cmac* cmac, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != WH_ERROR_OK) { return ret; } @@ -5994,7 +6001,7 @@ int wh_Client_Sha256UpdateResponse(whClientContext* ctx, wc_Sha256* sha) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != WH_ERROR_OK) { return ret; } @@ -6074,7 +6081,7 @@ int wh_Client_Sha256FinalResponse(whClientContext* ctx, wc_Sha256* sha, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != 0) { return ret; } @@ -6292,7 +6299,7 @@ int wh_Client_Sha256DmaUpdateResponse(whClientContext* ctx, wc_Sha256* sha) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_NOTREADY) { return ret; } @@ -6396,7 +6403,7 @@ int wh_Client_Sha256DmaFinalResponse(whClientContext* ctx, wc_Sha256* sha, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_NOTREADY) { return ret; } @@ -6591,7 +6598,7 @@ int wh_Client_Sha224UpdateResponse(whClientContext* ctx, wc_Sha224* sha) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != WH_ERROR_OK) { return ret; } @@ -6672,7 +6679,7 @@ int wh_Client_Sha224FinalResponse(whClientContext* ctx, wc_Sha224* sha, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != 0) { return ret; } @@ -6878,7 +6885,7 @@ int wh_Client_Sha224DmaUpdateResponse(whClientContext* ctx, wc_Sha224* sha) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_NOTREADY) { return ret; } @@ -6978,7 +6985,7 @@ int wh_Client_Sha224DmaFinalResponse(whClientContext* ctx, wc_Sha224* sha, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_NOTREADY) { return ret; } @@ -7173,7 +7180,7 @@ int wh_Client_Sha384UpdateResponse(whClientContext* ctx, wc_Sha384* sha) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != WH_ERROR_OK) { return ret; } @@ -7255,7 +7262,7 @@ int wh_Client_Sha384FinalResponse(whClientContext* ctx, wc_Sha384* sha, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != 0) { return ret; } @@ -7462,7 +7469,7 @@ int wh_Client_Sha384DmaUpdateResponse(whClientContext* ctx, wc_Sha384* sha) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_NOTREADY) { return ret; } @@ -7563,7 +7570,7 @@ int wh_Client_Sha384DmaFinalResponse(whClientContext* ctx, wc_Sha384* sha, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_NOTREADY) { return ret; } @@ -7757,7 +7764,7 @@ int wh_Client_Sha512UpdateResponse(whClientContext* ctx, wc_Sha512* sha) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != WH_ERROR_OK) { return ret; } @@ -7845,7 +7852,7 @@ int wh_Client_Sha512FinalResponse(whClientContext* ctx, wc_Sha512* sha, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret != 0) { return ret; } @@ -8075,7 +8082,7 @@ int wh_Client_Sha512DmaUpdateResponse(whClientContext* ctx, wc_Sha512* sha) return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_NOTREADY) { return ret; } @@ -8182,7 +8189,7 @@ int wh_Client_Sha512DmaFinalResponse(whClientContext* ctx, wc_Sha512* sha, return WH_ERROR_BADARGS; } - ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, dataPtr); + ret = wh_Client_RecvResponse(ctx, NULL, NULL, &respSz, WOLFHSM_CFG_COMM_DATA_LEN, dataPtr); if (ret == WH_ERROR_NOTREADY) { return ret; } @@ -8427,6 +8434,7 @@ static int _MlDsaMakeKey(whClientContext* ctx, int size, int level, uint16_t res_len; do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); @@ -8597,6 +8605,7 @@ int wh_Client_MlDsaSign(whClientContext* ctx, const byte* in, word32 in_len, /* Recv Response */ do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); @@ -8744,6 +8753,7 @@ int wh_Client_MlDsaVerify(whClientContext* ctx, const byte* sig, word32 sig_len, /* Recv Response */ do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); if (ret == 0) { @@ -8944,6 +8954,7 @@ static int _MlDsaMakeKeyDma(whClientContext* ctx, int level, if (ret == WH_ERROR_OK) { do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); } @@ -9129,6 +9140,7 @@ int wh_Client_MlDsaSignDma(whClientContext* ctx, const byte* in, word32 in_len, /* Recv Response */ do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); @@ -9272,6 +9284,7 @@ int wh_Client_MlDsaVerifyDma(whClientContext* ctx, const byte* sig, /* Recv Response */ do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); @@ -9496,6 +9509,7 @@ static int _MlKemMakeKey(whClientContext* ctx, int level, do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); if (ret != WH_ERROR_OK) { @@ -9629,6 +9643,7 @@ int wh_Client_MlKemEncapsulate(whClientContext* ctx, MlKemKey* key, evict = 0; do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); } @@ -9757,6 +9772,7 @@ int wh_Client_MlKemDecapsulate(whClientContext* ctx, MlKemKey* key, evict = 0; do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); } @@ -9956,6 +9972,7 @@ static int _MlKemMakeKeyDma(whClientContext* ctx, int level, if (ret == WH_ERROR_OK) { do { ret = wh_Client_RecvResponse(ctx, &group, &action, &req_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); } @@ -10080,6 +10097,7 @@ int wh_Client_MlKemEncapsulateDma(whClientContext* ctx, MlKemKey* key, evict = 0; do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); } @@ -10204,6 +10222,7 @@ int wh_Client_MlKemDecapsulateDma(whClientContext* ctx, MlKemKey* key, evict = 0; do { ret = wh_Client_RecvResponse(ctx, &group, &action, &res_len, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)dataPtr); } while (ret == WH_ERROR_NOTREADY); } diff --git a/src/wh_client_keywrap.c b/src/wh_client_keywrap.c index 0bb1e15f0..cb8b6b655 100644 --- a/src/wh_client_keywrap.c +++ b/src/wh_client_keywrap.c @@ -75,7 +75,8 @@ int wh_Client_KeyWrapResponse(whClientContext* ctx, } /* Receive the response */ - ret = wh_Client_RecvResponse(ctx, &group, &action, &size, (uint8_t*)resp); + ret = wh_Client_RecvResponse(ctx, &group, &action, &size, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret != WH_ERROR_OK) { return ret; } @@ -194,7 +195,8 @@ int wh_Client_KeyUnwrapAndExportResponse(whClientContext* ctx, } /* Receive the response */ - ret = wh_Client_RecvResponse(ctx, &group, &action, &size, (uint8_t*)resp); + ret = wh_Client_RecvResponse(ctx, &group, &action, &size, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret != WH_ERROR_OK) { return ret; } @@ -310,7 +312,8 @@ int wh_Client_KeyUnwrapAndCacheResponse(whClientContext* ctx, } /* Receive the response */ - ret = wh_Client_RecvResponse(ctx, &group, &action, &size, (uint8_t*)resp); + ret = wh_Client_RecvResponse(ctx, &group, &action, &size, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret != WH_ERROR_OK) { return ret; } @@ -415,7 +418,8 @@ int wh_Client_DataWrapResponse(whClientContext* ctx, } /* Receive the response */ - ret = wh_Client_RecvResponse(ctx, &group, &action, &size, (uint8_t*)resp); + ret = wh_Client_RecvResponse(ctx, &group, &action, &size, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret != WH_ERROR_OK) { return ret; } @@ -528,7 +532,8 @@ int wh_Client_DataUnwrapResponse(whClientContext* ctx, } /* Receive the response */ - ret = wh_Client_RecvResponse(ctx, &group, &action, &size, (uint8_t*)resp); + ret = wh_Client_RecvResponse(ctx, &group, &action, &size, + WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret != WH_ERROR_OK) { return ret; } diff --git a/src/wh_client_nvm.c b/src/wh_client_nvm.c index 5742b97c7..1634a4171 100644 --- a/src/wh_client_nvm.c +++ b/src/wh_client_nvm.c @@ -71,7 +71,7 @@ int wh_Client_NvmInitResponse(whClientContext* c, int32_t *out_rc, rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, - &resp_size, &msg); + &resp_size, sizeof(msg), &msg); if (rc == 0) { /* Validate response */ if ( (resp_group != WH_MESSAGE_GROUP_NVM) || @@ -143,7 +143,7 @@ int wh_Client_NvmCleanupResponse(whClientContext* c, int32_t *out_rc) rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, - &resp_size, &msg); + &resp_size, sizeof(msg), &msg); if (rc == 0) { /* Validate response */ if ( (resp_group != WH_MESSAGE_GROUP_NVM) || @@ -209,7 +209,7 @@ int wh_Client_NvmGetAvailableResponse(whClientContext* c, int32_t *out_rc, rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, - &resp_size, &msg); + &resp_size, sizeof(msg), &msg); if (rc == 0) { /* Validate response */ if ( (resp_group != WH_MESSAGE_GROUP_NVM) || @@ -313,7 +313,7 @@ int wh_Client_NvmAddObjectResponse(whClientContext* c, int32_t *out_rc) rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, - &resp_size, &msg); + &resp_size, sizeof(msg), &msg); if (rc == 0) { /* Validate response */ if ( (resp_group != WH_MESSAGE_GROUP_NVM) || @@ -390,7 +390,7 @@ int wh_Client_NvmListResponse(whClientContext* c, int32_t *out_rc, rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, - &resp_size, &msg); + &resp_size, sizeof(msg), &msg); if (rc == 0) { /* Validate response */ if ( (resp_group != WH_MESSAGE_GROUP_NVM) || @@ -469,7 +469,7 @@ int wh_Client_NvmGetMetadataResponse(whClientContext* c, int32_t *out_rc, rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, - &resp_size, &msg); + &resp_size, sizeof(msg), &msg); if (rc == 0) { /* Validate response */ if ( (resp_group != WH_MESSAGE_GROUP_NVM) || @@ -565,7 +565,7 @@ int wh_Client_NvmDestroyObjectsResponse(whClientContext* c, int32_t *out_rc) rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, - &resp_size, &msg); + &resp_size, sizeof(msg), &msg); if (rc == 0) { /* Validate response */ if ( (resp_group != WH_MESSAGE_GROUP_NVM) || @@ -642,7 +642,7 @@ int wh_Client_NvmReadResponse(whClientContext* c, int32_t *out_rc, rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, - &resp_size, buffer); + &resp_size, sizeof(buffer), buffer); if (rc == 0) { /* Validate response */ if ((resp_group != WH_MESSAGE_GROUP_NVM) || @@ -722,7 +722,8 @@ int wh_Client_NvmAddObjectDmaResponse(whClientContext* c, int32_t* out_rc) return WH_ERROR_BADARGS; } - rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, &msg); + rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, + sizeof(msg), &msg); if (rc == 0) { /* Validate response */ if ((resp_group != WH_MESSAGE_GROUP_NVM) || @@ -793,7 +794,8 @@ int wh_Client_NvmReadDmaResponse(whClientContext* c, int32_t* out_rc) return WH_ERROR_BADARGS; } - rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, &msg); + rc = wh_Client_RecvResponse(c, &resp_group, &resp_action, &resp_size, + sizeof(msg), &msg); if (rc == 0) { /* Validate response */ if ((resp_group != WH_MESSAGE_GROUP_NVM) || diff --git a/src/wh_client_she.c b/src/wh_client_she.c index 716934f83..caf8391ad 100644 --- a/src/wh_client_she.c +++ b/src/wh_client_she.c @@ -95,7 +95,7 @@ int wh_Client_SheSetUidResponse(whClientContext* c) } resp = (whMessageShe_SetUidResponse*)wh_CommClient_GetDataPtr(c->comm); - ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == WH_ERROR_OK) { ret = resp->rc; } @@ -146,7 +146,8 @@ int wh_Client_SheSecureBoot(whClientContext* c, uint8_t* bootloader, if (ret == 0) { do { - ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, respBuf); + ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, + WOLFHSM_CFG_COMM_DATA_LEN, respBuf); initResp = (whMessageShe_SecureBootInitResponse*)respBuf; } while (ret == WH_ERROR_NOTREADY); } @@ -183,6 +184,7 @@ int wh_Client_SheSecureBoot(whClientContext* c, uint8_t* bootloader, if (ret == 0) { do { ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, + WOLFHSM_CFG_COMM_DATA_LEN, respBuf); } while (ret == WH_ERROR_NOTREADY); } @@ -201,7 +203,8 @@ int wh_Client_SheSecureBoot(whClientContext* c, uint8_t* bootloader, if (ret == 0) { do { - ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, respBuf); + ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, + WOLFHSM_CFG_COMM_DATA_LEN, respBuf); finishResp = (whMessageShe_SecureBootFinishResponse*)respBuf; } while (ret == WH_ERROR_NOTREADY); } @@ -241,7 +244,7 @@ int wh_Client_SheGetStatusResponse(whClientContext* c, uint8_t* sreg) resp = (whMessageShe_GetStatusResponse*)wh_CommClient_GetDataPtr(c->comm); - ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); /* return error or set sreg */ if (ret == 0) { @@ -305,7 +308,7 @@ int wh_Client_SheLoadKeyResponse(whClientContext* c, uint8_t* messageFour, resp = (whMessageShe_LoadKeyResponse*)wh_CommClient_GetDataPtr(c->comm); - ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == 0) { if (resp->rc != WH_SHE_ERC_NO_ERROR) { ret = resp->rc; @@ -365,7 +368,7 @@ int wh_Client_SheLoadPlainKeyResponse(whClientContext* c) resp = (whMessageShe_LoadPlainKeyResponse*)wh_CommClient_GetDataPtr(c->comm); - ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == 0) { ret = resp->rc; } @@ -415,7 +418,7 @@ int wh_Client_SheExportRamKeyResponse(whClientContext* c, uint8_t* messageOne, resp = (whMessageShe_ExportRamKeyResponse*)wh_CommClient_GetDataPtr(c->comm); - ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == 0) { if (resp->rc != WH_SHE_ERC_NO_ERROR) { ret = resp->rc; @@ -472,7 +475,7 @@ int wh_Client_SheInitRndResponse(whClientContext* c) } resp = (whMessageShe_InitRngResponse*)wh_CommClient_GetDataPtr(c->comm); - ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == 0) { ret = resp->rc; } @@ -515,7 +518,7 @@ int wh_Client_SheRndResponse(whClientContext* c, uint8_t* out, uint32_t* outSz) resp = (whMessageShe_RndResponse*)wh_CommClient_GetDataPtr(c->comm); - ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == 0) { if (resp->rc != WH_SHE_ERC_NO_ERROR) @@ -575,7 +578,7 @@ int wh_Client_SheExtendSeedResponse(whClientContext* c) } resp = (whMessageShe_ExtendSeedResponse*)wh_CommClient_GetDataPtr(c->comm); - ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == 0) { ret = resp->rc; @@ -638,7 +641,7 @@ int wh_Client_SheEncEcbResponse(whClientContext* c, uint8_t* out, uint32_t sz) /* out is after fixed sized fields */ packOut = (uint8_t*)(resp + 1); - ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == 0) { if (resp->rc != WH_SHE_ERC_NO_ERROR) { ret = resp->rc; @@ -710,7 +713,7 @@ int wh_Client_SheEncCbcResponse(whClientContext* c, uint8_t* out, uint32_t sz) /* out is after fixed sized fields */ packOut = (uint8_t*)(resp + 1); - ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == 0) { if (resp->rc != WH_SHE_ERC_NO_ERROR) { ret = resp->rc; @@ -778,7 +781,7 @@ int wh_Client_SheDecEcbResponse(whClientContext* c, uint8_t* out, uint32_t sz) /* out is after fixed sized fields */ packOut = (uint8_t*)(resp + 1); - ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == 0) { if (resp->rc != WH_SHE_ERC_NO_ERROR) { ret = resp->rc; @@ -850,7 +853,7 @@ int wh_Client_SheDecCbcResponse(whClientContext* c, uint8_t* out, uint32_t sz) /* out is after fixed sized fields */ packOut = (uint8_t*)(resp + 1); - ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == 0) { if (resp->rc != WH_SHE_ERC_NO_ERROR) { ret = resp->rc; @@ -917,7 +920,7 @@ int wh_Client_SheGenerateMacResponse(whClientContext* c, uint8_t* out, resp = (whMessageShe_GenMacResponse*)wh_CommClient_GetDataPtr(c->comm); - ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == 0) { if (resp->rc != WH_SHE_ERC_NO_ERROR) { ret = resp->rc; @@ -989,7 +992,7 @@ int wh_Client_SheVerifyMacResponse(whClientContext* c, uint8_t* outStatus) } resp = (whMessageShe_VerifyMacResponse*)wh_CommClient_GetDataPtr(c->comm); - ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, (uint8_t*)resp); + ret = wh_Client_RecvResponse(c, &group, &action, &dataSz, WOLFHSM_CFG_COMM_DATA_LEN, (uint8_t*)resp); if (ret == 0) { if (resp->rc != WH_SHE_ERC_NO_ERROR) { ret = resp->rc; diff --git a/src/wh_comm.c b/src/wh_comm.c index 021df57a1..0b871f7e4 100644 --- a/src/wh_comm.c +++ b/src/wh_comm.c @@ -151,18 +151,21 @@ int wh_CommClient_SendRequest(whCommClient* context, uint16_t magic, } /* If a response packet has been buffered, get the header and copy the data out - * of the buffer. + * of the buffer. data_size is the capacity of the caller-supplied data buffer; + * if the received payload exceeds it, returns WH_ERROR_BUFFER_SIZE with + * *out_size set to the required size. On success *out_size holds the actual + * payload size. */ int wh_CommClient_RecvResponse(whCommClient* context, uint16_t* out_magic, uint16_t* out_kind, uint16_t* out_seq, - uint16_t* out_size, void* data) + uint16_t* out_size, uint16_t data_size, void* data) { int rc = 0; uint16_t magic = 0; uint16_t kind = 0; uint16_t seq = 0; uint16_t size = sizeof(context->packet); - uint16_t data_size = 0; + uint16_t payload_size = 0; if ((context == NULL) || (context->hdr == NULL) || (context->initialized == 0) || (context->transport_cb == NULL) || @@ -190,7 +193,7 @@ int wh_CommClient_RecvResponse(whCommClient* context, rc = WH_ERROR_ABORTED; } if (rc == 0) { - data_size = size - sizeof(*context->hdr); + payload_size = size - sizeof(*context->hdr); magic = context->hdr->magic; kind = wh_Translate16(magic, context->hdr->kind); seq = wh_Translate16(magic, context->hdr->seq); @@ -221,15 +224,20 @@ int wh_CommClient_RecvResponse(whCommClient* context, return WH_ERROR_NOTREADY; } - if ( (data != NULL) && - (data_size != 0) && - (data != context->data)) { - memcpy(data, context->data, data_size); + if ((data != NULL) && + (payload_size != 0) && + (data != context->data)) { + if (payload_size > data_size) { + rc = WH_ERROR_BUFFER_SIZE; + } + else { + memcpy(data, context->data, payload_size); + } } if (out_magic != NULL) *out_magic = magic; if (out_kind != NULL) *out_kind = kind; if (out_seq != NULL) *out_seq = seq; - if (out_size != NULL) *out_size = data_size; + if (out_size != NULL) *out_size = payload_size; context->pending = 0; } } diff --git a/test-refactor/misc/wh_test_comm.c b/test-refactor/misc/wh_test_comm.c index 0010c1939..60179b630 100644 --- a/test-refactor/misc/wh_test_comm.c +++ b/test-refactor/misc/wh_test_comm.c @@ -135,7 +135,8 @@ static int _whTest_CommMem(void) WH_TEST_ASSERT_RETURN( WH_ERROR_NOTREADY == wh_CommClient_RecvResponse(client, &rx_resp_flags, &rx_resp_type, - &rx_resp_seq, &rx_resp_len, rx_resp)); + &rx_resp_seq, &rx_resp_len, sizeof(rx_resp), + rx_resp)); for (counter = 0; counter < REPEAT_COUNT; counter++) { (void)snprintf((char*)tx_req, sizeof(tx_req), "Request:%u", counter); @@ -151,7 +152,8 @@ static int _whTest_CommMem(void) WH_TEST_ASSERT_RETURN(WH_ERROR_NOTREADY == wh_CommClient_RecvResponse( client, &rx_resp_flags, &rx_resp_type, - &rx_resp_seq, &rx_resp_len, rx_resp)); + &rx_resp_seq, &rx_resp_len, + sizeof(rx_resp), rx_resp)); WH_TEST_ASSERT_RETURN( WH_ERROR_REQUEST_PENDING == @@ -181,7 +183,8 @@ static int _whTest_CommMem(void) WH_TEST_RETURN_ON_FAIL( wh_CommClient_RecvResponse(client, &rx_resp_flags, &rx_resp_type, - &rx_resp_seq, &rx_resp_len, rx_resp)); + &rx_resp_seq, &rx_resp_len, + sizeof(rx_resp), rx_resp)); WH_TEST_DEBUG_PRINT( "Client RecvResponse:%d, flags %x, type:%x, seq:%d, len:%d, %s\n", @@ -219,14 +222,16 @@ static int _whTest_CommMem(void) /* Successful recv clears pending */ WH_TEST_RETURN_ON_FAIL( wh_CommClient_RecvResponse(client, &rx_resp_flags, &rx_resp_type, - &rx_resp_seq, &rx_resp_len, rx_resp)); + &rx_resp_seq, &rx_resp_len, sizeof(rx_resp), + rx_resp)); WH_TEST_ASSERT_RETURN(0 == wh_CommClient_IsRequestPending(client)); /* Second Recv with no outstanding request again yields NOTREADY */ WH_TEST_ASSERT_RETURN( WH_ERROR_NOTREADY == wh_CommClient_RecvResponse(client, &rx_resp_flags, &rx_resp_type, - &rx_resp_seq, &rx_resp_len, rx_resp)); + &rx_resp_seq, &rx_resp_len, sizeof(rx_resp), + rx_resp)); /* Send, then manually abort. Seq must not advance. */ WH_TEST_RETURN_ON_FAIL(wh_CommClient_SendRequest( @@ -249,7 +254,8 @@ static int _whTest_CommMem(void) WH_TEST_ASSERT_RETURN( WH_ERROR_NOTREADY == wh_CommClient_RecvResponse(client, &rx_resp_flags, &rx_resp_type, - &rx_resp_seq, &rx_resp_len, rx_resp)); + &rx_resp_seq, &rx_resp_len, sizeof(rx_resp), + rx_resp)); WH_TEST_ASSERT_RETURN(0 == wh_CommClient_IsRequestPending(client)); WH_TEST_RETURN_ON_FAIL(wh_CommServer_Cleanup(server)); diff --git a/test/wh_test_comm.c b/test/wh_test_comm.c index b695569b3..0803503cb 100644 --- a/test/wh_test_comm.c +++ b/test/wh_test_comm.c @@ -150,7 +150,8 @@ int whTest_CommMem(void) WH_TEST_ASSERT_RETURN( WH_ERROR_NOTREADY == wh_CommClient_RecvResponse(client, &rx_resp_flags, &rx_resp_type, - &rx_resp_seq, &rx_resp_len, rx_resp)); + &rx_resp_seq, &rx_resp_len, sizeof(rx_resp), + rx_resp)); for (counter = 0; counter < REPEAT_COUNT; counter++) { (void)snprintf((char*)tx_req, sizeof(tx_req), "Request:%u", counter); @@ -166,7 +167,8 @@ int whTest_CommMem(void) WH_TEST_ASSERT_RETURN(WH_ERROR_NOTREADY == wh_CommClient_RecvResponse( client, &rx_resp_flags, &rx_resp_type, - &rx_resp_seq, &rx_resp_len, rx_resp)); + &rx_resp_seq, &rx_resp_len, + sizeof(rx_resp), rx_resp)); WH_TEST_ASSERT_RETURN( WH_ERROR_REQUEST_PENDING == @@ -196,7 +198,8 @@ int whTest_CommMem(void) WH_TEST_RETURN_ON_FAIL( wh_CommClient_RecvResponse(client, &rx_resp_flags, &rx_resp_type, - &rx_resp_seq, &rx_resp_len, rx_resp)); + &rx_resp_seq, &rx_resp_len, + sizeof(rx_resp), rx_resp)); WH_TEST_DEBUG_PRINT( "Client RecvResponse:%d, flags %x, type:%x, seq:%d, len:%d, %s\n", @@ -234,14 +237,16 @@ int whTest_CommMem(void) /* Successful recv clears pending */ WH_TEST_RETURN_ON_FAIL( wh_CommClient_RecvResponse(client, &rx_resp_flags, &rx_resp_type, - &rx_resp_seq, &rx_resp_len, rx_resp)); + &rx_resp_seq, &rx_resp_len, sizeof(rx_resp), + rx_resp)); WH_TEST_ASSERT_RETURN(0 == wh_CommClient_IsRequestPending(client)); /* Second Recv with no outstanding request again yields NOTREADY */ WH_TEST_ASSERT_RETURN( WH_ERROR_NOTREADY == wh_CommClient_RecvResponse(client, &rx_resp_flags, &rx_resp_type, - &rx_resp_seq, &rx_resp_len, rx_resp)); + &rx_resp_seq, &rx_resp_len, sizeof(rx_resp), + rx_resp)); /* Send, then manually abort. Seq must not advance. */ WH_TEST_RETURN_ON_FAIL(wh_CommClient_SendRequest( @@ -264,7 +269,8 @@ int whTest_CommMem(void) WH_TEST_ASSERT_RETURN( WH_ERROR_NOTREADY == wh_CommClient_RecvResponse(client, &rx_resp_flags, &rx_resp_type, - &rx_resp_seq, &rx_resp_len, rx_resp)); + &rx_resp_seq, &rx_resp_len, sizeof(rx_resp), + rx_resp)); WH_TEST_ASSERT_RETURN(0 == wh_CommClient_IsRequestPending(client)); WH_TEST_RETURN_ON_FAIL(wh_CommServer_Cleanup(server)); @@ -334,7 +340,8 @@ static void* _whCommClientTask(void* cf) do { ret = wh_CommClient_RecvResponse(client, &rx_resp_flags, &rx_resp_type, &rx_resp_seq, - &rx_resp_len, rx_resp); + &rx_resp_len, sizeof(rx_resp), + rx_resp); WH_TEST_ASSERT_MSG((ret == WH_ERROR_NOTREADY) || (0 == ret), "Client RecvResponse: ret=%d", ret); if(ret != WH_ERROR_NOTREADY) { diff --git a/wolfhsm/wh_client.h b/wolfhsm/wh_client.h index 6be78cc9f..9e1bd5d7e 100644 --- a/wolfhsm/wh_client.h +++ b/wolfhsm/wh_client.h @@ -232,13 +232,16 @@ int wh_Client_SendRequest(whClientContext* c, uint16_t group, uint16_t action, * @param c The client context. * @param out_group Pointer to store the received group value. * @param out_action Pointer to store the received action value. - * @param out_size Pointer to store the received size value. + * @param out_size Pointer to store the received size value. On + * WH_ERROR_BUFFER_SIZE this is set to the required size. + * @param data_size Capacity in bytes of the caller-supplied data buffer. + * Returns WH_ERROR_BUFFER_SIZE if the response payload exceeds it. * @param data Pointer to store the received data. * @return 0 if successful, a negative value if an error occurred. */ int wh_Client_RecvResponse(whClientContext* c, uint16_t* out_group, uint16_t* out_action, uint16_t* out_size, - void* data); + uint16_t data_size, void* data); /** * @brief Reports whether a request has been sent whose matching response has diff --git a/wolfhsm/wh_comm.h b/wolfhsm/wh_comm.h index 2c9355d93..1eebc78f2 100644 --- a/wolfhsm/wh_comm.h +++ b/wolfhsm/wh_comm.h @@ -207,11 +207,14 @@ int wh_CommClient_SendRequest(whCommClient* context, uint16_t magic, uint16_t kind, uint16_t *out_seq, uint16_t data_size, const void* data); /* If a response packet has been buffered, get the header and copy the data out - * of the buffer. + * of the buffer. data_size is the capacity of the caller-supplied data buffer; + * if the received payload exceeds it, returns WH_ERROR_BUFFER_SIZE with + * *out_size set to the required size. On success *out_size holds the actual + * payload size. */ int wh_CommClient_RecvResponse(whCommClient* context, uint16_t* out_magic, uint16_t* out_kind, uint16_t* out_seq, - uint16_t* out_size, void* data); + uint16_t* out_size, uint16_t data_size, void* data); /* Get a pointer to the data portion of the internal buffer that is * HW_COMM_DATA_LEN bytes.