psasim: minor fixes to the core

- do not try to close a connection that was never started
- fix data chunks length for psa_write (prevent memcpy-ing
  to large blocks of data)

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
Valerio Setti 2024-06-27 18:14:43 +02:00
parent 76ac620d70
commit 7fe75ba72d
3 changed files with 13 additions and 3 deletions

View File

@ -474,7 +474,7 @@ void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
while (sofar < num_bytes) {
size_t sending = (num_bytes - sofar);
if (sending >= MAX_FRAGMENT_SIZE) {
if (sending > (MAX_FRAGMENT_SIZE - (sizeof(size_t) * 2))) {
sending = MAX_FRAGMENT_SIZE - (sizeof(size_t) * 2);
}

View File

@ -44,7 +44,7 @@ int psa_crypto_call(int function,
invec.base = in_params;
invec.len = in_params_len;
size_t max_receive = 8192;
size_t max_receive = 24576;
uint8_t *receive = malloc(max_receive);
if (receive == NULL) {
fprintf(stderr, "FAILED to allocate %u bytes\n", (unsigned) max_receive);
@ -119,6 +119,11 @@ fail:
void mbedtls_psa_crypto_free(void)
{
/* Do not try to close a connection that was never started.*/
if (handle == -1) {
return;
}
CLIENT_PRINT("Closing handle");
psa_close(handle);
handle = -1;

View File

@ -349,7 +349,7 @@ int psa_crypto_call(int function,
invec.base = in_params;
invec.len = in_params_len;
size_t max_receive = 8192;
size_t max_receive = 24576;
uint8_t *receive = malloc(max_receive);
if (receive == NULL) {
fprintf(stderr, "FAILED to allocate %u bytes\n", (unsigned) max_receive);
@ -424,6 +424,11 @@ fail:
void mbedtls_psa_crypto_free(void)
{
/* Do not try to close a connection that was never started.*/
if (handle == -1) {
return;
}
CLIENT_PRINT("Closing handle");
psa_close(handle);
handle = -1;