Code style improvements
Signed-off-by: Archana <archana.madhavan@silabs.com>
This commit is contained in:
parent
8a180368fb
commit
449608bc61
6 changed files with 107 additions and 107 deletions
|
@ -431,7 +431,7 @@ mbedtls_ecp_group_id mbedtls_ecc_group_of_psa( psa_ecc_family_t curve,
|
||||||
* defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY) */
|
* defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY) */
|
||||||
|
|
||||||
psa_status_t psa_validate_unstructured_key_bit_size( psa_key_type_t type,
|
psa_status_t psa_validate_unstructured_key_bit_size( psa_key_type_t type,
|
||||||
size_t bits )
|
size_t bits )
|
||||||
{
|
{
|
||||||
/* Check that the bit size is acceptable for the key type */
|
/* Check that the bit size is acceptable for the key type */
|
||||||
switch( type )
|
switch( type )
|
||||||
|
@ -558,7 +558,8 @@ psa_status_t psa_import_key_into_slot(
|
||||||
{
|
{
|
||||||
*bits = PSA_BYTES_TO_BITS( data_length );
|
*bits = PSA_BYTES_TO_BITS( data_length );
|
||||||
|
|
||||||
status = psa_validate_unstructured_key_bit_size( attributes->core.type, *bits );
|
status = psa_validate_unstructured_key_bit_size( attributes->core.type,
|
||||||
|
*bits );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
return( status );
|
return( status );
|
||||||
|
|
||||||
|
@ -1892,7 +1893,7 @@ psa_status_t psa_import_key( const psa_key_attributes_t *attributes,
|
||||||
if( data_length == 0 )
|
if( data_length == 0 )
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
|
||||||
/* Ensure that the bytes-to-bits conversion hasn't overflown. */
|
/* Ensure that the bytes-to-bits conversion cannot overflow. */
|
||||||
if( data_length > SIZE_MAX / 8 )
|
if( data_length > SIZE_MAX / 8 )
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
return( PSA_ERROR_NOT_SUPPORTED );
|
||||||
|
|
||||||
|
@ -1902,15 +1903,15 @@ psa_status_t psa_import_key( const psa_key_attributes_t *attributes,
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
/* In the case of a transparent key or an opaque key stored in local
|
/* In the case of a transparent key or an opaque key stored in local
|
||||||
* storage( thus not in the case of the old-style secure element interface
|
* storage ( thus not in the case of importing a key in a secure element
|
||||||
* (MBEDTLS_PSA_CRYPTO_SE_C)),we have to allocate a buffer to hold the
|
* with storage ( MBEDTLS_PSA_CRYPTO_SE_C ) ),we have to allocate a
|
||||||
* imported key material. */
|
* buffer to hold the imported key material. */
|
||||||
if( slot->key.data == NULL )
|
if( slot->key.data == NULL )
|
||||||
{
|
{
|
||||||
if( psa_key_lifetime_is_external( attributes->core.lifetime ) )
|
if( psa_key_lifetime_is_external( attributes->core.lifetime ) )
|
||||||
{
|
{
|
||||||
status = psa_driver_wrapper_get_key_buffer_size_from_key_data( attributes, data,
|
status = psa_driver_wrapper_get_key_buffer_size_from_key_data(
|
||||||
data_length , &storage_size );
|
attributes, data, data_length, &storage_size );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
@ -2046,7 +2047,7 @@ psa_status_t psa_copy_key( mbedtls_svc_key_id_t source_key,
|
||||||
* If the source and target keys are stored across different locations,
|
* If the source and target keys are stored across different locations,
|
||||||
* the source key would need to be exported as plaintext and re-imported
|
* the source key would need to be exported as plaintext and re-imported
|
||||||
* in the other location. This has security implications which have not
|
* in the other location. This has security implications which have not
|
||||||
* been fully mapped.For now, this can be acheived through
|
* been fully mapped. For now, this can be achieved through
|
||||||
* appropriate API invocations from the application, if needed.
|
* appropriate API invocations from the application, if needed.
|
||||||
* */
|
* */
|
||||||
status = PSA_ERROR_NOT_SUPPORTED;
|
status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
|
@ -2054,14 +2055,14 @@ psa_status_t psa_copy_key( mbedtls_svc_key_id_t source_key,
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* When the source and target keys are within the same location,
|
* When the source and target keys are within the same location,
|
||||||
* - For transparent keys it is a blind copy sans any driver invocation,
|
* - For transparent keys it is a blind copy without any driver invocation,
|
||||||
* - For opaque keys this translates to an invocation of the drivers'
|
* - For opaque keys this translates to an invocation of the drivers'
|
||||||
* copy_key entry point through the dispatch layer.
|
* copy_key entry point through the dispatch layer.
|
||||||
* */
|
* */
|
||||||
if( psa_key_lifetime_is_external( actual_attributes.core.lifetime ) )
|
if( psa_key_lifetime_is_external( actual_attributes.core.lifetime ) )
|
||||||
{
|
{
|
||||||
status = psa_driver_wrapper_get_key_buffer_size( &actual_attributes,
|
status = psa_driver_wrapper_get_key_buffer_size( &actual_attributes,
|
||||||
&storage_size );
|
&storage_size );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
status = psa_allocate_buffer_to_slot( target_slot, storage_size );
|
status = psa_allocate_buffer_to_slot( target_slot, storage_size );
|
||||||
|
@ -4197,7 +4198,8 @@ static psa_status_t psa_generate_derived_key_internal(
|
||||||
|
|
||||||
if( psa_key_lifetime_is_external( attributes.core.lifetime ) )
|
if( psa_key_lifetime_is_external( attributes.core.lifetime ) )
|
||||||
{
|
{
|
||||||
status = psa_driver_wrapper_get_key_buffer_size( &attributes, &storage_size );
|
status = psa_driver_wrapper_get_key_buffer_size( &attributes,
|
||||||
|
&storage_size );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
@ -5193,9 +5195,9 @@ psa_status_t psa_generate_key( const psa_key_attributes_t *attributes,
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
/* In the case of a transparent key or an opaque key stored in local
|
/* In the case of a transparent key or an opaque key stored in local
|
||||||
* storage( thus not in the case of the old-style secure element interface
|
* storage ( thus not in the case of generating a key in a secure element
|
||||||
* (MBEDTLS_PSA_CRYPTO_SE_C)),we have to allocate a buffer to hold the
|
* with storage ( MBEDTLS_PSA_CRYPTO_SE_C ) ),we have to allocate a
|
||||||
* imported key material. */
|
* buffer to hold the generated key material. */
|
||||||
if( slot->key.data == NULL )
|
if( slot->key.data == NULL )
|
||||||
{
|
{
|
||||||
if ( PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ) ==
|
if ( PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime ) ==
|
||||||
|
|
|
@ -546,5 +546,5 @@ psa_status_t psa_verify_hash_builtin(
|
||||||
* the two is not supported.
|
* the two is not supported.
|
||||||
*/
|
*/
|
||||||
psa_status_t psa_validate_unstructured_key_bit_size( psa_key_type_t type,
|
psa_status_t psa_validate_unstructured_key_bit_size( psa_key_type_t type,
|
||||||
size_t bits );
|
size_t bits );
|
||||||
#endif /* PSA_CRYPTO_CORE_H */
|
#endif /* PSA_CRYPTO_CORE_H */
|
||||||
|
|
|
@ -380,10 +380,9 @@ psa_status_t psa_driver_wrapper_verify_hash(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** calculate the key buffer size required to store the key material of a key
|
/** Calculate the key buffer size required to store the key material of a key
|
||||||
* associated with an opaque driver from input key data.
|
* associated with an opaque driver from input key data.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* \param[in] attributes The key attributes
|
* \param[in] attributes The key attributes
|
||||||
* \param[in] data The input key data.
|
* \param[in] data The input key data.
|
||||||
* \param[in] data_length The input data length.
|
* \param[in] data_length The input data length.
|
||||||
|
@ -399,7 +398,8 @@ psa_status_t psa_driver_wrapper_get_key_buffer_size_from_key_data(
|
||||||
size_t data_length,
|
size_t data_length,
|
||||||
size_t *key_buffer_size )
|
size_t *key_buffer_size )
|
||||||
{
|
{
|
||||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
|
psa_key_location_t location =
|
||||||
|
PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
|
||||||
psa_key_type_t key_type = attributes->core.type;
|
psa_key_type_t key_type = attributes->core.type;
|
||||||
|
|
||||||
*key_buffer_size = 0;
|
*key_buffer_size = 0;
|
||||||
|
@ -459,7 +459,8 @@ psa_status_t psa_driver_wrapper_get_key_buffer_size(
|
||||||
return( PSA_SUCCESS );
|
return( PSA_SUCCESS );
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
|
#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
|
||||||
*key_buffer_size = mbedtls_test_opaque_size_function( key_type, key_bits );
|
*key_buffer_size = mbedtls_test_opaque_size_function( key_type,
|
||||||
|
key_bits );
|
||||||
return( ( *key_buffer_size != 0 ) ?
|
return( ( *key_buffer_size != 0 ) ?
|
||||||
PSA_SUCCESS : PSA_ERROR_NOT_SUPPORTED );
|
PSA_SUCCESS : PSA_ERROR_NOT_SUPPORTED );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
|
@ -785,20 +786,12 @@ psa_status_t psa_driver_wrapper_get_builtin_key(
|
||||||
psa_status_t psa_driver_wrapper_copy_key(
|
psa_status_t psa_driver_wrapper_copy_key(
|
||||||
psa_key_attributes_t *attributes,
|
psa_key_attributes_t *attributes,
|
||||||
const uint8_t *source_key, size_t source_key_size,
|
const uint8_t *source_key, size_t source_key_size,
|
||||||
uint8_t *target_key_buffer, size_t target_buffer_size, size_t *key_length )
|
uint8_t *target_key_buffer, size_t target_key_buffer_size,
|
||||||
|
size_t *target_key_buffer_length )
|
||||||
{
|
{
|
||||||
psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
|
psa_key_location_t location =
|
||||||
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
|
||||||
const psa_drv_se_t *drv;
|
|
||||||
psa_drv_se_context_t *drv_context;
|
|
||||||
|
|
||||||
if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) )
|
|
||||||
{
|
|
||||||
/* Copying to a secure element is not implemented yet. */
|
|
||||||
return( PSA_ERROR_NOT_SUPPORTED );
|
|
||||||
}
|
|
||||||
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
|
|
||||||
|
|
||||||
switch( location )
|
switch( location )
|
||||||
{
|
{
|
||||||
|
@ -808,16 +801,16 @@ psa_status_t psa_driver_wrapper_copy_key(
|
||||||
return( mbedtls_test_opaque_copy_key( attributes, source_key,
|
return( mbedtls_test_opaque_copy_key( attributes, source_key,
|
||||||
source_key_size,
|
source_key_size,
|
||||||
target_key_buffer,
|
target_key_buffer,
|
||||||
target_buffer_size,
|
target_key_buffer_size,
|
||||||
key_length ) );
|
target_key_buffer_length) );
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
||||||
default:
|
default:
|
||||||
(void)source_key;
|
(void)source_key;
|
||||||
(void)source_key_size;
|
(void)source_key_size;
|
||||||
(void)target_key_buffer;
|
(void)target_key_buffer;
|
||||||
(void)target_buffer_size;
|
(void)target_key_buffer_size;
|
||||||
(void)key_length;
|
(void)target_key_buffer_length;
|
||||||
status = PSA_ERROR_INVALID_ARGUMENT;
|
status = PSA_ERROR_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
return( status );
|
return( status );
|
||||||
|
|
|
@ -103,7 +103,8 @@ psa_status_t psa_driver_wrapper_get_builtin_key(
|
||||||
psa_status_t psa_driver_wrapper_copy_key(
|
psa_status_t psa_driver_wrapper_copy_key(
|
||||||
psa_key_attributes_t *attributes,
|
psa_key_attributes_t *attributes,
|
||||||
const uint8_t *source_key, size_t source_key_size,
|
const uint8_t *source_key, size_t source_key_size,
|
||||||
uint8_t *target_key_buffer, size_t target_buffer_size, size_t *key_length );
|
uint8_t *target_key_buffer, size_t target_key_buffer_size,
|
||||||
|
size_t *target_key_buffer_length );
|
||||||
/*
|
/*
|
||||||
* Cipher functions
|
* Cipher functions
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -51,19 +51,18 @@ static inline mbedtls_test_driver_key_management_hooks_t
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* In order to convert the plain text keys to Opaque, the size of the key is
|
* In order to convert the plain text keys to Opaque, the size of the key is
|
||||||
* padded up by PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX_SIZE in addition to xor mangling
|
* padded up by PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX_SIZE in addition to
|
||||||
* the key. The pad prefix needs to be accounted for while sizing for the key.
|
* xor mangling the key. The pad prefix needs to be accounted for while
|
||||||
|
* sizing for the key.
|
||||||
*/
|
*/
|
||||||
#define PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX 0xBEEFED00U
|
#define PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX 0xBEEFED00U
|
||||||
#define PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX_SIZE sizeof( PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX )
|
#define PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX_SIZE sizeof( \
|
||||||
|
PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX )
|
||||||
size_t mbedtls_test_opaque_get_base_size();
|
|
||||||
|
|
||||||
size_t mbedtls_test_opaque_size_function(
|
size_t mbedtls_test_opaque_size_function(
|
||||||
const psa_key_type_t key_type,
|
const psa_key_type_t key_type,
|
||||||
const size_t key_bits );
|
const size_t key_bits );
|
||||||
|
|
||||||
|
|
||||||
extern mbedtls_test_driver_key_management_hooks_t
|
extern mbedtls_test_driver_key_management_hooks_t
|
||||||
mbedtls_test_driver_key_management_hooks;
|
mbedtls_test_driver_key_management_hooks;
|
||||||
|
|
||||||
|
@ -118,8 +117,8 @@ psa_status_t mbedtls_test_opaque_copy_key(
|
||||||
const uint8_t *source_key,
|
const uint8_t *source_key,
|
||||||
size_t source_key_size,
|
size_t source_key_size,
|
||||||
uint8_t *target_key_buffer,
|
uint8_t *target_key_buffer,
|
||||||
size_t target_buffer_size,
|
size_t target_key_buffer_size,
|
||||||
size_t *key_length );
|
size_t *target_key_buffer_length);
|
||||||
|
|
||||||
|
|
||||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||||
|
|
|
@ -58,11 +58,13 @@ const uint8_t mbedtls_test_driver_ecdsa_pubkey[65] =
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This macro returns the base size for the key context when SE does not support storage.
|
* This macro returns the base size for the key context when SE does not
|
||||||
* It is the size of the metadata that gets added to the wrapped key.
|
* support storage. It is the size of the metadata that gets added to the
|
||||||
* In its test functionality the metadata is just some padded prefixing to the key.
|
* wrapped key. In its test functionality the metadata is just some padded
|
||||||
|
* prefixing to the key.
|
||||||
*/
|
*/
|
||||||
#define TEST_DRIVER_KEY_CONTEXT_BASE_SIZE PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX_SIZE
|
#define TEST_DRIVER_KEY_CONTEXT_BASE_SIZE \
|
||||||
|
PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX_SIZE
|
||||||
|
|
||||||
|
|
||||||
size_t mbedtls_test_opaque_size_function(
|
size_t mbedtls_test_opaque_size_function(
|
||||||
|
@ -80,62 +82,70 @@ size_t mbedtls_test_opaque_size_function(
|
||||||
return( key_buffer_size );
|
return( key_buffer_size );
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t mbedtls_test_opaque_get_base_size()
|
static size_t mbedtls_test_opaque_get_base_size()
|
||||||
{
|
{
|
||||||
return TEST_DRIVER_KEY_CONTEXT_BASE_SIZE;
|
return TEST_DRIVER_KEY_CONTEXT_BASE_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The wrap function mbedtls_test_opaque_wrap_key pads and wraps the clear key.
|
* The wrap function mbedtls_test_opaque_wrap_key pads and wraps the
|
||||||
* It expects the clear and wrap buffers to be passed in.
|
* clear key. It expects the clear and wrap buffers to be passed in.
|
||||||
* key_buffer_size is the size of the clear key to be wrapped.
|
* key_length is the size of the clear key to be wrapped.
|
||||||
* wrap_buffer_size is the size of the output buffer wrap_key.
|
* wrapped_key_buffer_size is the size of the output buffer wrap_key.
|
||||||
* The argument key_buffer_length is filled with the wrapped key_size on success.
|
* The argument wrapped_key_buffer_length is filled with the wrapped
|
||||||
|
* key_size on success.
|
||||||
* */
|
* */
|
||||||
static psa_status_t mbedtls_test_opaque_wrap_key(
|
static psa_status_t mbedtls_test_opaque_wrap_key(
|
||||||
const uint8_t *key_buffer,
|
const uint8_t *key,
|
||||||
size_t key_buffer_size,
|
size_t key_length,
|
||||||
uint8_t *wrap_key,
|
uint8_t *wrapped_key_buffer,
|
||||||
size_t wrap_buffer_size,
|
size_t wrapped_key_buffer_size,
|
||||||
size_t *key_buffer_length )
|
size_t *wrapped_key_buffer_length )
|
||||||
{
|
{
|
||||||
size_t opaque_key_base_size = mbedtls_test_opaque_get_base_size();
|
size_t opaque_key_base_size = mbedtls_test_opaque_get_base_size();
|
||||||
uint64_t prefix = PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX;
|
uint64_t prefix = PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX;
|
||||||
if( key_buffer_size + opaque_key_base_size > wrap_buffer_size )
|
|
||||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
if( key_length + opaque_key_base_size > wrapped_key_buffer_size )
|
||||||
/* Write in the opaque pad prefix */
|
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||||
memcpy( wrap_key, &prefix, opaque_key_base_size);
|
|
||||||
wrap_key += opaque_key_base_size;
|
/* Write in the opaque pad prefix */
|
||||||
*key_buffer_length = key_buffer_size + opaque_key_base_size;
|
memcpy( wrapped_key_buffer, &prefix, opaque_key_base_size);
|
||||||
while( key_buffer_size-- )
|
wrapped_key_buffer += opaque_key_base_size;
|
||||||
wrap_key[key_buffer_size] = key_buffer[key_buffer_size] ^ 0xFF;
|
*wrapped_key_buffer_length = key_length + opaque_key_base_size;
|
||||||
return( PSA_SUCCESS );
|
|
||||||
|
while( key_length-- )
|
||||||
|
wrapped_key_buffer[key_length] = key[key_length] ^ 0xFF;
|
||||||
|
return( PSA_SUCCESS );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The unwrap function mbedtls_test_opaque_unwrap_key removes a pad prefix and unwraps
|
* The unwrap function mbedtls_test_opaque_unwrap_key removes a pad prefix
|
||||||
* the wrapped key. It expects the clear and wrap buffers to be passed in.
|
* and unwraps the wrapped key. It expects the clear and wrap buffers to be
|
||||||
* wrapped_key_buffer_size is the size of the wrapped key,
|
* passed in.
|
||||||
|
* wrapped_key_length is the size of the wrapped key,
|
||||||
* key_buffer_size is the size of the output buffer clear_key.
|
* key_buffer_size is the size of the output buffer clear_key.
|
||||||
* The argument key_buffer_length is filled with the unwrapped(clear) key_size on success.
|
* The argument key_buffer_length is filled with the unwrapped(clear)
|
||||||
|
* key_size on success.
|
||||||
* */
|
* */
|
||||||
static psa_status_t mbedtls_test_opaque_unwrap_key(
|
static psa_status_t mbedtls_test_opaque_unwrap_key(
|
||||||
const uint8_t *wrapped_key,
|
const uint8_t *wrapped_key,
|
||||||
size_t wrapped_key_buffer_size,
|
size_t wrapped_key_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 *key_buffer_length)
|
||||||
{
|
{
|
||||||
/* Remove the pad prefis from the wrapped key */
|
/* Remove the pad prefix from the wrapped key */
|
||||||
size_t opaque_key_base_size = mbedtls_test_opaque_get_base_size();
|
size_t opaque_key_base_size = mbedtls_test_opaque_get_base_size();
|
||||||
size_t clear_key_size = wrapped_key_buffer_size - opaque_key_base_size;
|
size_t clear_key_size = wrapped_key_length - opaque_key_base_size;
|
||||||
wrapped_key += opaque_key_base_size;
|
|
||||||
if( clear_key_size > key_buffer_size )
|
wrapped_key += opaque_key_base_size;
|
||||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
if( clear_key_size > key_buffer_size )
|
||||||
*key_buffer_length = clear_key_size;
|
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||||
while( clear_key_size-- )
|
|
||||||
key_buffer[clear_key_size] = wrapped_key[clear_key_size] ^ 0xFF;
|
*key_buffer_length = clear_key_size;
|
||||||
return( PSA_SUCCESS );
|
while( clear_key_size-- )
|
||||||
|
key_buffer[clear_key_size] = wrapped_key[clear_key_size] ^ 0xFF;
|
||||||
|
return( PSA_SUCCESS );
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t mbedtls_test_transparent_generate_key(
|
psa_status_t mbedtls_test_transparent_generate_key(
|
||||||
|
@ -257,21 +267,22 @@ psa_status_t mbedtls_test_opaque_import_key(
|
||||||
size_t *key_buffer_length,
|
size_t *key_buffer_length,
|
||||||
size_t *bits)
|
size_t *bits)
|
||||||
{
|
{
|
||||||
|
|
||||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
psa_key_type_t type = psa_get_key_type( attributes );
|
psa_key_type_t type = psa_get_key_type( attributes );
|
||||||
/* This buffer will be used as an intermediate placeholder for the clear
|
/* This buffer will be used as an intermediate placeholder for
|
||||||
* key till we wrap it */
|
* the clear key till we wrap it */
|
||||||
uint8_t *key_buffer_temp;
|
uint8_t *key_buffer_temp;
|
||||||
key_buffer_temp = mbedtls_calloc( 1, key_buffer_size );
|
|
||||||
|
|
||||||
if( !key_buffer_temp )
|
key_buffer_temp = mbedtls_calloc( 1, key_buffer_size );
|
||||||
|
if( key_buffer_temp == NULL )
|
||||||
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
||||||
|
|
||||||
if( PSA_KEY_TYPE_IS_UNSTRUCTURED( type ) )
|
if( PSA_KEY_TYPE_IS_UNSTRUCTURED( type ) )
|
||||||
{
|
{
|
||||||
*bits = PSA_BYTES_TO_BITS( data_length );
|
*bits = PSA_BYTES_TO_BITS( data_length );
|
||||||
|
|
||||||
status = psa_validate_unstructured_key_bit_size( attributes->core.type, *bits );
|
status = psa_validate_unstructured_key_bit_size( attributes->core.type,
|
||||||
|
*bits );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
|
@ -311,13 +322,6 @@ psa_status_t mbedtls_test_opaque_import_key(
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
status = PSA_ERROR_INVALID_ARGUMENT;
|
status = PSA_ERROR_INVALID_ARGUMENT;
|
||||||
(void)data;
|
|
||||||
(void)data_length;
|
|
||||||
(void)key_buffer;
|
|
||||||
(void)key_buffer_size;
|
|
||||||
(void)key_buffer_length;
|
|
||||||
(void)bits;
|
|
||||||
(void)type;
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
status = mbedtls_test_opaque_wrap_key( key_buffer_temp, *key_buffer_length,
|
status = mbedtls_test_opaque_wrap_key( key_buffer_temp, *key_buffer_length,
|
||||||
|
@ -389,10 +393,10 @@ psa_status_t mbedtls_test_opaque_export_key(
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* This buffer will be used as an intermediate placeholder for the opaque key
|
/* This buffer will be used as an intermediate placeholder for
|
||||||
* till we unwrap the key into key_buffer */
|
* the opaque key till we unwrap the key into key_buffer */
|
||||||
uint8_t *key_buffer_temp;
|
uint8_t *key_buffer_temp;
|
||||||
size_t status = PSA_ERROR_BUFFER_TOO_SMALL;
|
size_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
psa_key_type_t type = psa_get_key_type( attributes );
|
psa_key_type_t type = psa_get_key_type( attributes );
|
||||||
|
|
||||||
if( PSA_KEY_TYPE_IS_UNSTRUCTURED( type ) ||
|
if( PSA_KEY_TYPE_IS_UNSTRUCTURED( type ) ||
|
||||||
|
@ -400,7 +404,7 @@ psa_status_t mbedtls_test_opaque_export_key(
|
||||||
PSA_KEY_TYPE_IS_ECC( type ) )
|
PSA_KEY_TYPE_IS_ECC( type ) )
|
||||||
{
|
{
|
||||||
key_buffer_temp = mbedtls_calloc( 1, key_length );
|
key_buffer_temp = mbedtls_calloc( 1, key_length );
|
||||||
if( !key_buffer_temp )
|
if( key_buffer_temp == NULL )
|
||||||
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
||||||
memcpy( key_buffer_temp, key, key_length );
|
memcpy( key_buffer_temp, key, key_length );
|
||||||
status = mbedtls_test_opaque_unwrap_key( key_buffer_temp, key_length,
|
status = mbedtls_test_opaque_unwrap_key( key_buffer_temp, key_length,
|
||||||
|
@ -475,12 +479,14 @@ psa_status_t mbedtls_test_opaque_export_public_key(
|
||||||
{
|
{
|
||||||
if( key_length != sizeof( psa_drv_slot_number_t ) )
|
if( key_length != sizeof( psa_drv_slot_number_t ) )
|
||||||
{
|
{
|
||||||
psa_status_t status = PSA_ERROR_NOT_SUPPORTED;
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
psa_key_type_t key_type = psa_get_key_type( attributes );
|
psa_key_type_t key_type = psa_get_key_type( attributes );
|
||||||
uint8_t *key_buffer_temp;
|
uint8_t *key_buffer_temp;
|
||||||
|
|
||||||
key_buffer_temp = mbedtls_calloc( 1, key_length );
|
key_buffer_temp = mbedtls_calloc( 1, key_length );
|
||||||
if( !key_buffer_temp )
|
if( key_buffer_temp == NULL )
|
||||||
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
||||||
|
|
||||||
#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) || \
|
#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY)
|
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||||
if( PSA_KEY_TYPE_IS_ECC( key_type ) )
|
if( PSA_KEY_TYPE_IS_ECC( key_type ) )
|
||||||
|
@ -512,7 +518,6 @@ psa_status_t mbedtls_test_opaque_export_public_key(
|
||||||
{
|
{
|
||||||
status = PSA_ERROR_NOT_SUPPORTED;
|
status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
(void)key;
|
(void)key;
|
||||||
(void)key_length;
|
|
||||||
(void)key_type;
|
(void)key_type;
|
||||||
}
|
}
|
||||||
mbedtls_free( key_buffer_temp );
|
mbedtls_free( key_buffer_temp );
|
||||||
|
|
Loading…
Reference in a new issue