Skip to content

Commit 150b88c

Browse files
Merge pull request #9280 from valeriosetti/psasim-reset-slots-on-disconnection
psasim-server: add function to reset operations slots
2 parents 125440d + 2468896 commit 150b88c

File tree

6 files changed

+65
-0
lines changed

6 files changed

+65
-0
lines changed

tests/psa-client-server/psasim/src/psa_sim_crypto_server.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,3 +2314,8 @@ psa_status_t psa_crypto_call(psa_msg_t msg)
23142314

23152315
return ok ? PSA_SUCCESS : PSA_ERROR_GENERIC_ERROR;
23162316
}
2317+
2318+
void psa_crypto_close(void)
2319+
{
2320+
psa_sim_serialize_reset();
2321+
}

tests/psa-client-server/psasim/src/psa_sim_generate.pl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ sub write_server_implementations
242242
243243
return ok ? PSA_SUCCESS : PSA_ERROR_GENERIC_ERROR;
244244
}
245+
EOF
246+
247+
# Finally, add psa_crypto_close()
248+
249+
print $fh <<EOF;
250+
251+
void psa_crypto_close(void)
252+
{
253+
psa_sim_serialize_reset();
254+
}
245255
EOF
246256

247257
close($fh);

tests/psa-client-server/psasim/src/psa_sim_serialise.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,3 +713,11 @@ int psasim_deserialise_mbedtls_svc_key_id_t(uint8_t **pos,
713713

714714
return 1;
715715
}
716+
717+
void psa_sim_serialize_reset(void)
718+
{
719+
memset(hash_operation_handles, 0, sizeof(hash_operation_handles));
720+
memset(hash_operations, 0, sizeof(hash_operations));
721+
memset(aead_operation_handles, 0, sizeof(aead_operation_handles));
722+
memset(aead_operations, 0, sizeof(aead_operations));
723+
}

tests/psa-client-server/psasim/src/psa_sim_serialise.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
* don't contain pointers.
5555
*/
5656

57+
/** Reset all operation slots.
58+
*
59+
* Should be called when all clients have disconnected.
60+
*/
61+
void psa_sim_serialize_reset(void);
62+
5763
/** Return how much buffer space is needed by \c psasim_serialise_begin().
5864
*
5965
* \return The number of bytes needed in the buffer for

tests/psa-client-server/psasim/src/psa_sim_serialise.pl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
}
106106
}
107107

108+
print define_server_serialize_reset(@types);
108109
} else {
109110
die("internal error - shouldn't happen");
110111
}
@@ -329,6 +330,12 @@ sub h_header
329330
* don't contain pointers.
330331
*/
331332
333+
/** Reset all operation slots.
334+
*
335+
* Should be called when all clients have disconnected.
336+
*/
337+
void psa_sim_serialize_reset(void);
338+
332339
/** Return how much buffer space is needed by \c psasim_serialise_begin().
333340
*
334341
* \return The number of bytes needed in the buffer for
@@ -913,6 +920,33 @@ sub c_define_begins
913920
EOF
914921
}
915922

923+
# Return the code for psa_sim_serialize_reset()
924+
sub define_server_serialize_reset
925+
{
926+
my @types = @_;
927+
928+
my $code = <<EOF;
929+
930+
void psa_sim_serialize_reset(void)
931+
{
932+
EOF
933+
934+
for my $type (@types) {
935+
next unless $type =~ /^psa_(\w+_operation)_t$/;
936+
937+
my $what = $1; # e.g. "hash_operation"
938+
939+
$code .= <<EOF;
940+
memset(${what}_handles, 0, sizeof(${what}_handles));
941+
memset(${what}s, 0, sizeof(${what}s));
942+
EOF
943+
}
944+
945+
$code .= <<EOF;
946+
}
947+
EOF
948+
}
949+
916950
# Horrible way to align first, second and third lines of function signature to
917951
# appease uncrustify (these are the 2nd-4th lines of code, indices 1, 2 and 3)
918952
#

tests/psa-client-server/psasim/src/server.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ int psa_server_main(int argc, char *argv[])
5454
int client_disconnected = 0;
5555
char mbedtls_version[18];
5656
extern psa_status_t psa_crypto_call(psa_msg_t msg);
57+
extern psa_status_t psa_crypto_close(void);
5758

5859
mbedtls_version_get_string_full(mbedtls_version);
5960
SERVER_PRINT("%s", mbedtls_version);
@@ -81,6 +82,7 @@ int psa_server_main(int argc, char *argv[])
8182
SERVER_PRINT("Got a disconnection message");
8283
ret = PSA_SUCCESS;
8384
client_disconnected = 1;
85+
psa_crypto_close();
8486
break;
8587
default:
8688
SERVER_PRINT("Got an IPC call of type %d", msg.type);

0 commit comments

Comments
 (0)