psasim-server: add function to reset operations slots

When the client disconnects the server can clean operations slots
so that upcoming clients will not hit the maximum slot limit
(at least it's very unlikely to happen for normal clients).

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
Valerio Setti 2024-06-17 17:34:03 +02:00
parent 7c52100fbd
commit 2fd9572f27
4 changed files with 15 additions and 0 deletions

View File

@ -2314,3 +2314,8 @@ psa_status_t psa_crypto_call(psa_msg_t msg)
return ok ? PSA_SUCCESS : PSA_ERROR_GENERIC_ERROR;
}
void psa_crypto_close(void)
{
psa_sim_serialize_reset();
}

View File

@ -706,3 +706,9 @@ int psasim_deserialise_mbedtls_svc_key_id_t(uint8_t **pos,
return 1;
}
void psa_sim_serialize_reset(void)
{
memset(hash_operation_handles, 0, sizeof(hash_operation_handles));
memset(hash_operations, 0, sizeof(hash_operations));
}

View File

@ -54,6 +54,8 @@
* don't contain pointers.
*/
void psa_sim_serialize_reset(void);
/** Return how much buffer space is needed by \c psasim_serialise_begin().
*
* \return The number of bytes needed in the buffer for

View File

@ -54,6 +54,7 @@ int psa_server_main(int argc, char *argv[])
int client_disconnected = 0;
char mbedtls_version[18];
extern psa_status_t psa_crypto_call(psa_msg_t msg);
extern psa_status_t psa_crypto_close(void);
mbedtls_version_get_string_full(mbedtls_version);
SERVER_PRINT("%s", mbedtls_version);
@ -81,6 +82,7 @@ int psa_server_main(int argc, char *argv[])
SERVER_PRINT("Got a disconnection message");
ret = PSA_SUCCESS;
client_disconnected = 1;
psa_crypto_close();
break;
default:
SERVER_PRINT("Got an IPC call of type %d", msg.type);