psasim: add support for psa_can_do_hash()

This commit also includes regenerated C and H files.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
Valerio Setti 2025-03-03 15:36:00 +01:00
parent 886fa8d71a
commit 1027c4cc3c
4 changed files with 152 additions and 0 deletions

View File

@ -26,6 +26,7 @@ enum {
PSA_AEAD_VERIFY,
PSA_ASYMMETRIC_DECRYPT,
PSA_ASYMMETRIC_ENCRYPT,
PSA_CAN_DO_HASH,
PSA_CIPHER_ABORT,
PSA_CIPHER_DECRYPT,
PSA_CIPHER_DECRYPT_SETUP,

View File

@ -1544,6 +1544,68 @@ fail:
}
int psa_can_do_hash(
psa_algorithm_t hash_alg
)
{
uint8_t *ser_params = NULL;
uint8_t *ser_result = NULL;
size_t result_length;
int value = 0;
size_t needed =
psasim_serialise_begin_needs() +
psasim_serialise_psa_algorithm_t_needs(hash_alg);
ser_params = malloc(needed);
if (ser_params == NULL) {
goto fail;
}
uint8_t *pos = ser_params;
size_t remaining = needed;
int ok;
ok = psasim_serialise_begin(&pos, &remaining);
if (!ok) {
goto fail;
}
ok = psasim_serialise_psa_algorithm_t(
&pos, &remaining,
hash_alg);
if (!ok) {
goto fail;
}
ok = psa_crypto_call(PSA_CAN_DO_HASH,
ser_params, (size_t) (pos - ser_params), &ser_result, &result_length);
if (!ok) {
printf("PSA_CAN_DO_HASH server call failed\n");
goto fail;
}
uint8_t *rpos = ser_result;
size_t rremain = result_length;
ok = psasim_deserialise_begin(&rpos, &rremain);
if (!ok) {
goto fail;
}
ok = psasim_deserialise_int(
&rpos, &rremain,
&value);
if (!ok) {
goto fail;
}
fail:
free(ser_params);
free(ser_result);
return value;
}
psa_status_t psa_cipher_abort(
psa_cipher_operation_t *operation
)

View File

@ -1705,6 +1705,73 @@ fail:
return 0; // This shouldn't happen!
}
// Returns 1 for success, 0 for failure
int psa_can_do_hash_wrapper(
uint8_t *in_params, size_t in_params_len,
uint8_t **out_params, size_t *out_params_len)
{
int value = 0;
psa_algorithm_t hash_alg;
uint8_t *pos = in_params;
size_t remaining = in_params_len;
uint8_t *result = NULL;
int ok;
ok = psasim_deserialise_begin(&pos, &remaining);
if (!ok) {
goto fail;
}
ok = psasim_deserialise_psa_algorithm_t(
&pos, &remaining,
&hash_alg);
if (!ok) {
goto fail;
}
// Now we call the actual target function
value = psa_can_do_hash(
hash_alg
);
// NOTE: Should really check there is no overflow as we go along.
size_t result_size =
psasim_serialise_begin_needs() +
psasim_serialise_int_needs(value);
result = malloc(result_size);
if (result == NULL) {
goto fail;
}
uint8_t *rpos = result;
size_t rremain = result_size;
ok = psasim_serialise_begin(&rpos, &rremain);
if (!ok) {
goto fail;
}
ok = psasim_serialise_int(
&rpos, &rremain,
value);
if (!ok) {
goto fail;
}
*out_params = result;
*out_params_len = result_size;
return 1; // success
fail:
free(result);
return 0; // This shouldn't happen!
}
// Returns 1 for success, 0 for failure
int psa_cipher_abort_wrapper(
uint8_t *in_params, size_t in_params_len,
@ -8826,6 +8893,10 @@ psa_status_t psa_crypto_call(psa_msg_t msg)
ok = psa_asymmetric_encrypt_wrapper(in_params, in_params_len,
&out_params, &out_params_len);
break;
case PSA_CAN_DO_HASH:
ok = psa_can_do_hash_wrapper(in_params, in_params_len,
&out_params, &out_params_len);
break;
case PSA_CIPHER_ABORT:
ok = psa_cipher_abort_wrapper(in_params, in_params_len,
&out_params, &out_params_len);
@ -8878,6 +8949,22 @@ psa_status_t psa_crypto_call(psa_msg_t msg)
ok = psa_export_public_key_wrapper(in_params, in_params_len,
&out_params, &out_params_len);
break;
case PSA_EXPORT_PUBLIC_KEY_IOP_ABORT:
ok = psa_export_public_key_iop_abort_wrapper(in_params, in_params_len,
&out_params, &out_params_len);
break;
case PSA_EXPORT_PUBLIC_KEY_IOP_COMPLETE:
ok = psa_export_public_key_iop_complete_wrapper(in_params, in_params_len,
&out_params, &out_params_len);
break;
case PSA_EXPORT_PUBLIC_KEY_IOP_GET_NUM_OPS:
ok = psa_export_public_key_iop_get_num_ops_wrapper(in_params, in_params_len,
&out_params, &out_params_len);
break;
case PSA_EXPORT_PUBLIC_KEY_IOP_SETUP:
ok = psa_export_public_key_iop_setup_wrapper(in_params, in_params_len,
&out_params, &out_params_len);
break;
case PSA_GENERATE_KEY:
ok = psa_generate_key_wrapper(in_params, in_params_len,
&out_params, &out_params_len);

View File

@ -1107,11 +1107,13 @@ sub get_functions
my $ret_name = "";
$ret_name = "status" if $ret_type eq "psa_status_t";
$ret_name = "value" if $ret_type eq "uint32_t";
$ret_name = "value" if $ret_type eq "int";
$ret_name = "(void)" if $ret_type eq "void";
die("ret_name for $ret_type?") unless length($ret_name);
my $ret_default = "";
$ret_default = "PSA_ERROR_CORRUPTION_DETECTED" if $ret_type eq "psa_status_t";
$ret_default = "0" if $ret_type eq "uint32_t";
$ret_default = "0" if $ret_type eq "int";
$ret_default = "(void)" if $ret_type eq "void";
die("ret_default for $ret_type?") unless length($ret_default);