From 35ef36b62fc4bf4cb7d3d7777849ece063d84f78 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 16 May 2019 19:42:05 +0200 Subject: [PATCH] Rename psa_generate_random_key back to psa_generate_key generate_key is a more classical name. The longer name was only introduced to avoid confusion with getting a key from a generator, which is key derivation, but we no longer use the generator terminology so this reason no longer applies. perl -i -pe 's/psa_generate_random_key/psa_generate_key/g' $(git ls-files) --- docs/getting_started.md | 4 ++-- include/psa/crypto.h | 12 ++++++------ include/psa/crypto_extra.h | 2 +- include/psa/crypto_se_driver.h | 2 +- library/psa_crypto.c | 10 +++++----- library/ssl_cli.c | 2 +- programs/psa/crypto_examples.c | 6 +++--- programs/psa/key_ladder_demo.c | 2 +- tests/suites/test_suite_pk.function | 2 +- tests/suites/test_suite_psa_crypto.function | 6 +++--- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/getting_started.md b/docs/getting_started.md index ac1bc3166..9ab4f8f6c 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -494,7 +494,7 @@ Prerequisites to using key generation and export APIs: Generate a piece of random 128-bit AES data: 1. Set the key policy for key generation by calling `psa_key_policy_set_usage()` with the `PSA_KEY_USAGE_EXPORT` parameter and the algorithm `PSA_ALG_GCM`. -1. Generate a random AES key by calling `psa_generate_random_key()`. +1. Generate a random AES key by calling `psa_generate_key()`. 1. Export the generated key by calling `psa_export_key()`: ```C int slot = 1; @@ -510,7 +510,7 @@ Generate a piece of random 128-bit AES data: psa_set_key_policy(slot, &policy); /* Generate a key */ - psa_generate_random_key(slot, PSA_KEY_TYPE_AES, bits); + psa_generate_key(slot, PSA_KEY_TYPE_AES, bits); psa_export_key(slot, exported, exported_size, &exported_length) diff --git a/include/psa/crypto.h b/include/psa/crypto.h index 4a3388994..4e1f18d4e 100644 --- a/include/psa/crypto.h +++ b/include/psa/crypto.h @@ -180,10 +180,10 @@ psa_status_t psa_crypto_init(void); * psa_set_key_algorithm(). * -# Set the key type with psa_set_key_type(). * Skip this step if copying an existing key with psa_copy_key(). - * -# When generating a random key with psa_generate_random_key() or deriving a key + * -# When generating a random key with psa_generate_key() or deriving a key * with psa_key_derivation_output_key(), set the desired key size with * psa_set_key_bits(). - * -# Call a key creation function: psa_import_key(), psa_generate_random_key(), + * -# Call a key creation function: psa_import_key(), psa_generate_key(), * psa_key_derivation_output_key() or psa_copy_key(). This function reads * the attribute structure, creates a key with these attributes, and * outputs a handle to the newly created key. @@ -214,7 +214,7 @@ typedef struct psa_key_attributes_s psa_key_attributes_t; * value in the structure. * The persistent key will be written to storage when the attribute * structure is passed to a key creation function such as - * psa_import_key(), psa_generate_random_key(), + * psa_import_key(), psa_generate_key(), * psa_key_derivation_output_key() or psa_copy_key(). * * This function may be declared as `static` (i.e. without external @@ -239,7 +239,7 @@ static void psa_set_key_id(psa_key_attributes_t *attributes, * value in the structure. * The persistent key will be written to storage when the attribute * structure is passed to a key creation function such as - * psa_import_key(), psa_generate_random_key(), + * psa_import_key(), psa_generate_key(), * psa_key_derivation_output_key() or psa_copy_key(). * * This function may be declared as `static` (i.e. without external @@ -3398,7 +3398,7 @@ psa_status_t psa_raw_key_agreement(psa_algorithm_t alg, * and MUST NOT use the content of the output buffer if the return * status is not #PSA_SUCCESS. * - * \note To generate a key, use psa_generate_random_key() instead. + * \note To generate a key, use psa_generate_key() instead. * * \param[out] output Output buffer for the generated data. * \param output_size Number of bytes to generate and output. @@ -3453,7 +3453,7 @@ psa_status_t psa_generate_random(uint8_t *output, * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_generate_random_key(const psa_key_attributes_t *attributes, +psa_status_t psa_generate_key(const psa_key_attributes_t *attributes, psa_key_handle_t *handle); /**@}*/ diff --git a/include/psa/crypto_extra.h b/include/psa/crypto_extra.h index a260964ce..d731c0350 100644 --- a/include/psa/crypto_extra.h +++ b/include/psa/crypto_extra.h @@ -436,7 +436,7 @@ psa_status_t psa_generate_derived_key_to_handle(psa_key_handle_t handle, size_t bits, psa_key_derivation_operation_t *operation); -psa_status_t psa_generate_random_key_to_handle(psa_key_handle_t handle, +psa_status_t psa_generate_key_to_handle(psa_key_handle_t handle, psa_key_type_t type, size_t bits, const void *extra, diff --git a/include/psa/crypto_se_driver.h b/include/psa/crypto_se_driver.h index 8c7ad6d00..5fb7bc3ae 100644 --- a/include/psa/crypto_se_driver.h +++ b/include/psa/crypto_se_driver.h @@ -783,7 +783,7 @@ typedef psa_status_t (*psa_drv_se_export_key_t)(psa_key_slot_number_t key, * \param[in] extra Extra parameters for key generation. The * interpretation of this parameter should match the * interpretation in the `extra` parameter is the - * `psa_generate_random_key` function + * `psa_generate_key` function * \param[in] extra_size The size in bytes of the \p extra buffer * \param[out] p_pubkey_out The buffer where the public key information will * be placed diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 5fab16268..ae93e8b8f 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -5308,7 +5308,7 @@ static psa_status_t psa_read_rsa_exponent( const uint8_t *domain_parameters, } #endif /* MBEDTLS_RSA_C && MBEDTLS_GENPRIME */ -static psa_status_t psa_generate_random_key_internal( +static psa_status_t psa_generate_key_internal( psa_key_slot_t *slot, size_t bits, const uint8_t *domain_parameters, size_t domain_parameters_size ) { @@ -5414,7 +5414,7 @@ static psa_status_t psa_generate_random_key_internal( return( PSA_SUCCESS ); } -psa_status_t psa_generate_random_key_to_handle( psa_key_handle_t handle, +psa_status_t psa_generate_key_to_handle( psa_key_handle_t handle, psa_key_type_t type, size_t bits, const void *extra, @@ -5434,7 +5434,7 @@ psa_status_t psa_generate_random_key_to_handle( psa_key_handle_t handle, return( status ); slot->type = type; - status = psa_generate_random_key_internal( slot, bits, extra, extra_size ); + status = psa_generate_key_internal( slot, bits, extra, extra_size ); if( status != PSA_SUCCESS ) slot->type = 0; @@ -5448,7 +5448,7 @@ psa_status_t psa_generate_random_key_to_handle( psa_key_handle_t handle, return( status ); } -psa_status_t psa_generate_random_key( const psa_key_attributes_t *attributes, +psa_status_t psa_generate_key( const psa_key_attributes_t *attributes, psa_key_handle_t *handle ) { psa_status_t status; @@ -5456,7 +5456,7 @@ psa_status_t psa_generate_random_key( const psa_key_attributes_t *attributes, status = psa_start_key_creation( attributes, handle, &slot ); if( status == PSA_SUCCESS ) { - status = psa_generate_random_key_internal( + status = psa_generate_key_internal( slot, attributes->bits, attributes->domain_parameters, attributes->domain_parameters_size ); } diff --git a/library/ssl_cli.c b/library/ssl_cli.c index cde368f2f..c20ff1e90 100644 --- a/library/ssl_cli.c +++ b/library/ssl_cli.c @@ -3148,7 +3148,7 @@ static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl ) return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); /* Generate ECDH private key. */ - status = psa_generate_random_key_to_handle( handshake->ecdh_psa_privkey, + status = psa_generate_key_to_handle( handshake->ecdh_psa_privkey, PSA_KEY_TYPE_ECC_KEY_PAIR( handshake->ecdh_psa_curve ), MBEDTLS_PSA_ECC_KEY_BITS_OF_CURVE( handshake->ecdh_psa_curve ), NULL, 0 ); diff --git a/programs/psa/crypto_examples.c b/programs/psa/crypto_examples.c index 922a30125..1a81f45f8 100644 --- a/programs/psa/crypto_examples.c +++ b/programs/psa/crypto_examples.c @@ -164,7 +164,7 @@ cipher_example_encrypt_decrypt_aes_cbc_nopad_1_block( void ) psa_set_key_type( &attributes, PSA_KEY_TYPE_AES ); psa_set_key_bits( &attributes, key_bits ); - status = psa_generate_random_key( &attributes, &key_handle ); + status = psa_generate_key( &attributes, &key_handle ); ASSERT_STATUS( status, PSA_SUCCESS ); status = cipher_encrypt( key_handle, alg, iv, sizeof( iv ), @@ -215,7 +215,7 @@ static psa_status_t cipher_example_encrypt_decrypt_aes_cbc_pkcs7_multi( void ) psa_set_key_type( &attributes, PSA_KEY_TYPE_AES ); psa_set_key_bits( &attributes, key_bits ); - status = psa_generate_random_key( &attributes, &key_handle ); + status = psa_generate_key( &attributes, &key_handle ); ASSERT_STATUS( status, PSA_SUCCESS ); status = cipher_encrypt( key_handle, alg, iv, sizeof( iv ), @@ -262,7 +262,7 @@ static psa_status_t cipher_example_encrypt_decrypt_aes_ctr_multi( void ) psa_set_key_type( &attributes, PSA_KEY_TYPE_AES ); psa_set_key_bits( &attributes, key_bits ); - status = psa_generate_random_key( &attributes, &key_handle ); + status = psa_generate_key( &attributes, &key_handle ); ASSERT_STATUS( status, PSA_SUCCESS ); status = cipher_encrypt( key_handle, alg, iv, sizeof( iv ), diff --git a/programs/psa/key_ladder_demo.c b/programs/psa/key_ladder_demo.c index 4ebb7e049..36d7b5dcb 100644 --- a/programs/psa/key_ladder_demo.c +++ b/programs/psa/key_ladder_demo.c @@ -208,7 +208,7 @@ static psa_status_t generate( const char *key_file_name ) psa_set_key_type( &attributes, PSA_KEY_TYPE_DERIVE ); psa_set_key_bits( &attributes, PSA_BYTES_TO_BITS( KEY_SIZE_BYTES ) ); - PSA_CHECK( psa_generate_random_key( &attributes, &key_handle ) ); + PSA_CHECK( psa_generate_key( &attributes, &key_handle ) ); PSA_CHECK( save_key( key_handle, key_file_name ) ); diff --git a/tests/suites/test_suite_pk.function b/tests/suites/test_suite_pk.function index 8064be573..de90b47ea 100644 --- a/tests/suites/test_suite_pk.function +++ b/tests/suites/test_suite_pk.function @@ -97,7 +97,7 @@ psa_key_handle_t pk_psa_genkey( void ) return( PK_PSA_INVALID_SLOT ); /* generate key */ - if( PSA_SUCCESS != psa_generate_random_key_to_handle( key, type, bits, NULL, 0 ) ) + if( PSA_SUCCESS != psa_generate_key_to_handle( key, type, bits, NULL, 0 ) ) return( PK_PSA_INVALID_SLOT ); return( key ); diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index c7c3e3d88..4aa4026fd 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -4755,7 +4755,7 @@ void generate_key( int type_arg, psa_set_key_bits( &attributes, bits ); /* Generate a key */ - TEST_EQUAL( psa_generate_random_key( &attributes, &handle ), expected_status ); + TEST_EQUAL( psa_generate_key( &attributes, &handle ), expected_status ); if( expected_status != PSA_SUCCESS ) goto exit; @@ -4815,7 +4815,7 @@ void generate_key_rsa( int bits_arg, psa_set_key_bits( &attributes, bits ); /* Generate a key */ - TEST_EQUAL( psa_generate_random_key( &attributes, &handle ), expected_status ); + TEST_EQUAL( psa_generate_key( &attributes, &handle ), expected_status ); if( expected_status != PSA_SUCCESS ) goto exit; @@ -4923,7 +4923,7 @@ void persistent_key_load_key_from_storage( data_t *data, case GENERATE_KEY: /* Generate a key */ - PSA_ASSERT( psa_generate_random_key( &attributes, &handle ) ); + PSA_ASSERT( psa_generate_key( &attributes, &handle ) ); break; case DERIVE_KEY: