mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-16 22:20:49 +00: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:
parent
5424cf2e40
commit
18d7142efd
34
3rdparty/p256-m/p256-m_driver_entrypoints.c
vendored
34
3rdparty/p256-m/p256-m_driver_entrypoints.c
vendored
@ -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,
|
||||
|
27
3rdparty/p256-m/p256-m_driver_entrypoints.h
vendored
27
3rdparty/p256-m/p256-m_driver_entrypoints.h
vendored
@ -62,6 +62,33 @@ psa_status_t p256_transparent_import_key(const psa_key_attributes_t *attributes,
|
||||
size_t *key_buffer_length,
|
||||
size_t *bits);
|
||||
|
||||
/** Export SECP256R1 public key, from the private key.
|
||||
*
|
||||
* \param[in] attributes The attributes of the key to use for the
|
||||
* operation.
|
||||
* \param[in] key_buffer The private key in the export format.
|
||||
* \param[in] key_buffer_size The size of the private key in bytes.
|
||||
* \param[out] data The buffer to contain the public key in
|
||||
* the export format upon successful return.
|
||||
* \param[in] data_size The size of the \p data buffer in bytes.
|
||||
* \param[out] data_length The length written to \p data in bytes.
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* Success. Keypair generated and stored in buffer.
|
||||
* \retval #PSA_ERROR_NOT_SUPPORTED
|
||||
* The input is not supported by this driver (not SECP256R1).
|
||||
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
||||
* The input is invalid.
|
||||
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
||||
* \p key_buffer_size is too small.
|
||||
*/
|
||||
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);
|
||||
|
||||
/** Generate SECP256R1 ECC Key Pair.
|
||||
* Interface function which calls the p256-m key generation function and
|
||||
* places it in the key buffer provided by the caller (mbed TLS) in the
|
||||
|
Loading…
x
Reference in New Issue
Block a user