Rename 'keygen' to 'key management'

Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
This commit is contained in:
Steven Cooreman 2020-10-23 11:45:43 +02:00
parent 3ea0ce450f
commit c4813a6e80
6 changed files with 44 additions and 39 deletions

View File

@ -17,8 +17,8 @@
* limitations under the License.
*/
#ifndef PSA_CRYPTO_TEST_DRIVERS_KEYGEN_H
#define PSA_CRYPTO_TEST_DRIVERS_KEYGEN_H
#ifndef PSA_CRYPTO_TEST_DRIVERS_KEY_MANAGEMENT_H
#define PSA_CRYPTO_TEST_DRIVERS_KEY_MANAGEMENT_H
#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
@ -36,18 +36,19 @@ typedef struct {
/* If not PSA_SUCCESS, return this error code instead of processing the
* function call. */
psa_status_t forced_status;
/* Count the amount of times one of the keygen driver functions is called. */
/* Count the amount of times one of the key management driver functions
* is called. */
unsigned long hits;
} test_driver_keygen_hooks_t;
} test_driver_key_management_hooks_t;
#define TEST_DRIVER_KEYGEN_INIT { NULL, 0, PSA_ERROR_NOT_SUPPORTED, 0 }
static inline test_driver_keygen_hooks_t test_driver_keygen_hooks_init( void )
#define TEST_DRIVER_KEY_MANAGEMENT_INIT { NULL, 0, PSA_ERROR_NOT_SUPPORTED, 0 }
static inline test_driver_key_management_hooks_t test_driver_key_management_hooks_init( void )
{
const test_driver_keygen_hooks_t v = TEST_DRIVER_KEYGEN_INIT;
const test_driver_key_management_hooks_t v = TEST_DRIVER_KEY_MANAGEMENT_INIT;
return( v );
}
extern test_driver_keygen_hooks_t test_driver_keygen_hooks;
extern test_driver_key_management_hooks_t test_driver_key_management_hooks;
psa_status_t test_transparent_generate_key(
const psa_key_attributes_t *attributes,
@ -63,4 +64,4 @@ psa_status_t test_transparent_validate_key(const psa_key_attributes_t *attribute
size_t *bits);
#endif /* PSA_CRYPTO_DRIVER_TEST */
#endif /* PSA_CRYPTO_TEST_DRIVERS_KEYGEN_H */
#endif /* PSA_CRYPTO_TEST_DRIVERS_KEY_MANAGEMENT_H */

View File

@ -36,7 +36,7 @@ typedef struct {
/* If not PSA_SUCCESS, return this error code instead of processing the
* function call. */
psa_status_t forced_status;
/* Count the amount of times one of the keygen driver functions is called. */
/* Count the amount of times one of the signature driver functions is called. */
unsigned long hits;
} test_driver_signature_hooks_t;

View File

@ -23,7 +23,7 @@
#define PSA_CRYPTO_TEST_DRIVER_LIFETIME 0x7fffff
#include "test/drivers/signature.h"
#include "test/drivers/keygen.h"
#include "test/drivers/key_management.h"
#include "test/drivers/cipher.h"
#include "test/drivers/size.h"

View File

@ -30,30 +30,31 @@
#include "mbedtls/ecp.h"
#include "mbedtls/error.h"
#include "test/drivers/keygen.h"
#include "test/drivers/key_management.h"
#include "test/random.h"
#include <string.h>
test_driver_keygen_hooks_t test_driver_keygen_hooks = TEST_DRIVER_KEYGEN_INIT;
test_driver_key_management_hooks_t test_driver_key_management_hooks =
TEST_DRIVER_KEY_MANAGEMENT_INIT;
psa_status_t test_transparent_generate_key(
const psa_key_attributes_t *attributes,
uint8_t *key, size_t key_size, size_t *key_length )
{
++test_driver_keygen_hooks.hits;
++test_driver_key_management_hooks.hits;
if( test_driver_keygen_hooks.forced_status != PSA_SUCCESS )
return( test_driver_keygen_hooks.forced_status );
if( test_driver_key_management_hooks.forced_status != PSA_SUCCESS )
return( test_driver_key_management_hooks.forced_status );
if( test_driver_keygen_hooks.forced_output != NULL )
if( test_driver_key_management_hooks.forced_output != NULL )
{
if( test_driver_keygen_hooks.forced_output_length > key_size )
if( test_driver_key_management_hooks.forced_output_length > key_size )
return( PSA_ERROR_BUFFER_TOO_SMALL );
memcpy( key, test_driver_keygen_hooks.forced_output,
test_driver_keygen_hooks.forced_output_length );
*key_length = test_driver_keygen_hooks.forced_output_length;
memcpy( key, test_driver_key_management_hooks.forced_output,
test_driver_key_management_hooks.forced_output_length );
*key_length = test_driver_key_management_hooks.forced_output_length;
return( PSA_SUCCESS );
}
@ -62,9 +63,12 @@ psa_status_t test_transparent_generate_key(
if ( PSA_KEY_TYPE_IS_ECC( psa_get_key_type( attributes ) )
&& PSA_KEY_TYPE_IS_KEY_PAIR( psa_get_key_type( attributes ) ) )
{
psa_ecc_family_t curve = PSA_KEY_TYPE_ECC_GET_FAMILY( psa_get_key_type( attributes ) );
psa_ecc_family_t curve = PSA_KEY_TYPE_ECC_GET_FAMILY(
psa_get_key_type( attributes ) );
mbedtls_ecp_group_id grp_id =
mbedtls_ecc_group_of_psa( curve, PSA_BITS_TO_BYTES( psa_get_key_bits( attributes ) ) );
mbedtls_ecc_group_of_psa(
curve,
PSA_BITS_TO_BYTES( psa_get_key_bits( attributes ) ) );
const mbedtls_ecp_curve_info *curve_info =
mbedtls_ecp_curve_info_from_grp_id( grp_id );
mbedtls_ecp_keypair ecp;
@ -127,10 +131,10 @@ psa_status_t test_transparent_validate_key(const psa_key_attributes_t *attribute
size_t data_length,
size_t *bits)
{
++test_driver_keygen_hooks.hits;
++test_driver_key_management_hooks.hits;
if( test_driver_keygen_hooks.forced_status != PSA_SUCCESS )
return( test_driver_keygen_hooks.forced_status );
if( test_driver_key_management_hooks.forced_status != PSA_SUCCESS )
return( test_driver_key_management_hooks.forced_status );
#if defined(MBEDTLS_ECP_C)
psa_key_type_t type = psa_get_key_type( attributes );
@ -154,7 +158,7 @@ psa_status_t test_transparent_validate_key(const psa_key_attributes_t *attribute
* - The byte 0x04;
* - `x_P` as a `ceiling(m/8)`-byte string, big-endian;
* - `y_P` as a `ceiling(m/8)`-byte string, big-endian.
* So its data length is 2m+1 where n is the key size in bits.
* So its data length is 2m+1 where m is the curve size in bits.
*/
if( ( data_length & 1 ) == 0 )
return( PSA_ERROR_INVALID_ARGUMENT );

View File

@ -132,7 +132,7 @@ void generate_key( int force_status_arg,
psa_status_t actual_status;
uint8_t actual_output[PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(256)] = {0};
size_t actual_output_length;
test_driver_keygen_hooks = test_driver_keygen_hooks_init();
test_driver_key_management_hooks = test_driver_key_management_hooks_init();
psa_set_key_type( &attributes,
PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_CURVE_SECP_R1 ) );
@ -142,18 +142,18 @@ void generate_key( int force_status_arg,
if( fake_output->len > 0 )
{
expected_output = test_driver_keygen_hooks.forced_output = fake_output->x;
expected_output_length = test_driver_keygen_hooks.forced_output_length =
expected_output = test_driver_key_management_hooks.forced_output = fake_output->x;
expected_output_length = test_driver_key_management_hooks.forced_output_length =
fake_output->len;
}
test_driver_keygen_hooks.hits = 0;
test_driver_keygen_hooks.forced_status = force_status;
test_driver_key_management_hooks.hits = 0;
test_driver_key_management_hooks.forced_status = force_status;
PSA_ASSERT( psa_crypto_init( ) );
actual_status = psa_generate_key( &attributes, &handle );
TEST_EQUAL( test_driver_keygen_hooks.hits, 1 );
TEST_EQUAL( test_driver_key_management_hooks.hits, 1 );
TEST_EQUAL( actual_status, expected_status );
if( actual_status == PSA_SUCCESS )
@ -180,7 +180,7 @@ exit:
psa_reset_key_attributes( &attributes );
psa_destroy_key( handle );
PSA_DONE( );
test_driver_keygen_hooks = test_driver_keygen_hooks_init();
test_driver_key_management_hooks = test_driver_key_management_hooks_init();
}
/* END_CASE */
@ -196,25 +196,25 @@ void validate_key( int force_status_arg,
psa_key_handle_t handle = 0;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t actual_status;
test_driver_keygen_hooks = test_driver_keygen_hooks_init();
test_driver_key_management_hooks = test_driver_key_management_hooks_init();
psa_set_key_type( &attributes,
key_type );
psa_set_key_bits( &attributes, 0 );
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_EXPORT );
test_driver_keygen_hooks.forced_status = force_status;
test_driver_key_management_hooks.forced_status = force_status;
PSA_ASSERT( psa_crypto_init( ) );
actual_status = psa_import_key( &attributes, key_input->x, key_input->len, &handle );
TEST_EQUAL( test_driver_keygen_hooks.hits, 1 );
TEST_EQUAL( test_driver_key_management_hooks.hits, 1 );
TEST_EQUAL( actual_status, expected_status );
exit:
psa_reset_key_attributes( &attributes );
psa_destroy_key( handle );
PSA_DONE( );
test_driver_keygen_hooks = test_driver_keygen_hooks_init();
test_driver_key_management_hooks = test_driver_key_management_hooks_init();
}
/* END_CASE */

View File

@ -239,7 +239,7 @@
<ClInclude Include="..\..\tests\include\test\psa_helpers.h" />
<ClInclude Include="..\..\tests\include\test\random.h" />
<ClInclude Include="..\..\tests\include\test\drivers\cipher.h" />
<ClInclude Include="..\..\tests\include\test\drivers\keygen.h" />
<ClInclude Include="..\..\tests\include\test\drivers\key_management.h" />
<ClInclude Include="..\..\tests\include\test\drivers\signature.h" />
<ClInclude Include="..\..\tests\include\test\drivers\size.h" />
<ClInclude Include="..\..\tests\include\test\drivers\test_driver.h" />