1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-30 22:43:08 +03:00

Add export_public_key entry point to p256-m driver

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
This commit is contained in:
Manuel Pégourié-Gonnard
2023-08-07 11:18:05 +02:00
parent 5424cf2e40
commit 18d7142efd
2 changed files with 61 additions and 0 deletions

View File

@ -104,6 +104,40 @@ psa_status_t p256_transparent_import_key(const psa_key_attributes_t *attributes,
return PSA_SUCCESS;
}
psa_status_t p256_transparent_export_public_key(const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
uint8_t *data,
size_t data_size,
size_t *data_length)
{
/* Is this the right curve? */
size_t bits = psa_get_key_bits(attributes);
psa_key_type_t type = psa_get_key_type(attributes);
if (bits != 256 || type != PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1)) {
return PSA_ERROR_NOT_SUPPORTED;
}
/* Validate input and output sizes */
if (key_buffer_size != 32) {
return PSA_ERROR_INVALID_ARGUMENT;
}
if (data_size < 65) {
return PSA_ERROR_BUFFER_TOO_SMALL;
}
/* Output public key in the PSA export format */
data[0] = 0x04;
int ret = p256_public_from_private(data + 1, key_buffer);
if (ret != P256_SUCCESS) {
/* The only possible error is the private key was invalid */
return PSA_ERROR_INVALID_ARGUMENT;
}
*data_length = 65;
return PSA_SUCCESS;
}
psa_status_t p256_transparent_generate_key(
const psa_key_attributes_t *attributes,
uint8_t *key_buffer,