psa: Change psa_import_ecp_key() signature

Change psa_import_ecp_key() signature to the signature of an
import_key driver entry point.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron 2020-11-08 14:54:25 +01:00
parent 13f8b098cb
commit 79cc548cf2

View File

@ -536,43 +536,59 @@ static psa_status_t validate_unstructured_key_bit_size( psa_key_type_t type,
#if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \ #if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
/** Import an ECP key from import representation to a slot /** Import an ECP key in binary format.
* *
* \param[in,out] slot The slot where to store the export representation to * \note The signature of this function is that of a PSA driver
* \param[in] data The buffer containing the import representation * import_key entry point. This function behaves as an import_key
* \param[in] data_length The amount of bytes in \p data * entry point as defined in the PSA driver interface specification for
* \param[out] key_buffer The buffer containing the export representation * transparent drivers.
* \param[in] key_buffer_size The size of \p key_buffer in bytes *
* \param[out] key_buffer_length The length of the data written in the key * \param[in] attributes The attributes for the key to import.
* buffer in bytes. * \param[in] data The buffer containing the key data in import
* format.
* \param[in] data_length Size of the \p data buffer in bytes.
* \param[out] key_buffer The buffer containing the key data in output
* format.
* \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes. This
* size is greater or equal to \p data_length.
* \param[out] key_buffer_length The length of the data written in \p
* key_buffer in bytes.
* \param[out] bits The key size in number of bits.
*
* \retval #PSA_SUCCESS The ECP key was imported successfully.
* \retval #PSA_ERROR_INVALID_ARGUMENT
* The key data is not correctly formatted.
* \retval #PSA_ERROR_NOT_SUPPORTED
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
* \retval #PSA_ERROR_CORRUPTION_DETECTED
*/ */
static psa_status_t psa_import_ecp_key( psa_key_slot_t *slot, static psa_status_t psa_import_ecp_key(
const uint8_t *data, const psa_key_attributes_t *attributes,
size_t data_length, const uint8_t *data, size_t data_length,
uint8_t *key_buffer, uint8_t *key_buffer, size_t key_buffer_size,
size_t key_buffer_size, size_t *key_buffer_length, size_t *bits )
size_t *key_buffer_length )
{ {
psa_status_t status; psa_status_t status;
mbedtls_ecp_keypair *ecp = NULL; mbedtls_ecp_keypair *ecp = NULL;
/* Parse input */ /* Parse input */
status = mbedtls_psa_ecp_load_representation( slot->attr.type, status = mbedtls_psa_ecp_load_representation( attributes->core.type,
data, data,
data_length, data_length,
&ecp ); &ecp );
if( status != PSA_SUCCESS ) if( status != PSA_SUCCESS )
goto exit; goto exit;
if( PSA_KEY_TYPE_ECC_GET_FAMILY( slot->attr.type ) == PSA_ECC_FAMILY_MONTGOMERY) if( PSA_KEY_TYPE_ECC_GET_FAMILY( attributes->core.type ) ==
slot->attr.bits = (psa_key_bits_t) ecp->grp.nbits + 1; PSA_ECC_FAMILY_MONTGOMERY )
*bits = ecp->grp.nbits + 1;
else else
slot->attr.bits = (psa_key_bits_t) ecp->grp.nbits; *bits = ecp->grp.nbits;
/* Re-export the data to PSA export format. There is currently no support /* Re-export the data to PSA export format. There is currently no support
* for other input formats then the export format, so this is a 1-1 * for other input formats then the export format, so this is a 1-1
* copy operation. */ * copy operation. */
status = mbedtls_psa_ecp_export_key( slot->attr.type, status = mbedtls_psa_ecp_export_key( attributes->core.type,
ecp, ecp,
key_buffer, key_buffer,
key_buffer_size, key_buffer_size,
@ -745,10 +761,12 @@ static psa_status_t psa_import_key_into_slot( psa_key_slot_t *slot,
if( status != PSA_SUCCESS ) if( status != PSA_SUCCESS )
return( status ); return( status );
status = psa_import_ecp_key( slot, status = psa_import_ecp_key( &attributes,
data, data_length, data, data_length,
slot->key.data, data_length, slot->key.data, data_length,
&slot->key.bytes ); &slot->key.bytes,
&bit_size );
slot->attr.bits = (psa_key_bits_t) bit_size;
return( status ); return( status );
} }
#endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || #endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) ||