From c4813a6e809a38d42db12804f23585518b725d88 Mon Sep 17 00:00:00 2001 From: Steven Cooreman Date: Fri, 23 Oct 2020 11:45:43 +0200 Subject: [PATCH] Rename 'keygen' to 'key management' Signed-off-by: Steven Cooreman --- .../drivers/{keygen.h => key_management.h} | 19 +++++----- tests/include/test/drivers/signature.h | 2 +- tests/include/test/drivers/test_driver.h | 2 +- .../drivers/{keygen.c => key_management.c} | 36 ++++++++++--------- ..._suite_psa_crypto_driver_wrappers.function | 22 ++++++------ visualc/VS2010/mbedTLS.vcxproj | 2 +- 6 files changed, 44 insertions(+), 39 deletions(-) rename tests/include/test/drivers/{keygen.h => key_management.h} (74%) rename tests/src/drivers/{keygen.c => key_management.c} (85%) diff --git a/tests/include/test/drivers/keygen.h b/tests/include/test/drivers/key_management.h similarity index 74% rename from tests/include/test/drivers/keygen.h rename to tests/include/test/drivers/key_management.h index e5a5e4700..56f3ef82e 100644 --- a/tests/include/test/drivers/keygen.h +++ b/tests/include/test/drivers/key_management.h @@ -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 */ diff --git a/tests/include/test/drivers/signature.h b/tests/include/test/drivers/signature.h index e41892e77..8abcb111a 100644 --- a/tests/include/test/drivers/signature.h +++ b/tests/include/test/drivers/signature.h @@ -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; diff --git a/tests/include/test/drivers/test_driver.h b/tests/include/test/drivers/test_driver.h index ee5974217..f26b795dd 100644 --- a/tests/include/test/drivers/test_driver.h +++ b/tests/include/test/drivers/test_driver.h @@ -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" diff --git a/tests/src/drivers/keygen.c b/tests/src/drivers/key_management.c similarity index 85% rename from tests/src/drivers/keygen.c rename to tests/src/drivers/key_management.c index 84fc98a37..6ca03c6be 100644 --- a/tests/src/drivers/keygen.c +++ b/tests/src/drivers/key_management.c @@ -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 -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 ); diff --git a/tests/suites/test_suite_psa_crypto_driver_wrappers.function b/tests/suites/test_suite_psa_crypto_driver_wrappers.function index 3cecbfc67..a0140d2cb 100644 --- a/tests/suites/test_suite_psa_crypto_driver_wrappers.function +++ b/tests/suites/test_suite_psa_crypto_driver_wrappers.function @@ -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 */ diff --git a/visualc/VS2010/mbedTLS.vcxproj b/visualc/VS2010/mbedTLS.vcxproj index 3e9d14a29..3f1be2105 100644 --- a/visualc/VS2010/mbedTLS.vcxproj +++ b/visualc/VS2010/mbedTLS.vcxproj @@ -239,7 +239,7 @@ - +