Skip to content

Commit d22b6c4

Browse files
Merge pull request #264 from adrianlshaw/adrianlshaw/116
Rename psa_generator_import_key
2 parents 971bd69 + 5a5a79a commit d22b6c4

File tree

10 files changed

+41
-41
lines changed

10 files changed

+41
-41
lines changed

docs/getting_started.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ Deriving a new AES-CTR 128-bit encryption key into a given key slot using HKDF w
335335
1. Set up the generator using the `psa_key_derivation` function providing a key slot containing a key that can be used for key derivation and a salt and label (Note: salt and label are optional).
336336
1. Initiate a key policy to for the derived key by calling `psa_key_policy_set_usage()` with `PSA_KEY_USAGE_ENCRYPT` parameter and the algorithm `PSA_ALG_CTR`.
337337
1. Set the key policy to the derived key slot.
338-
1. Import a key from generator into the desired key slot using (`psa_generator_import_key`).
338+
1. Import a key from generator into the desired key slot using (`psa_generate_derived_key`).
339339
1. Clean up generator.
340340
341341
At this point the derived key slot holds a new 128-bit AES-CTR encryption key derived from the key, salt and label provided:
@@ -378,7 +378,7 @@ At this point the derived key slot holds a new 128-bit AES-CTR encryption key de
378378
379379
psa_set_key_policy(derived_key, &policy);
380380
381-
psa_generator_import_key(derived_key, PSA_KEY_TYPE_AES, derived_bits, &generator);
381+
psa_generate_derived_key(derived_key, PSA_KEY_TYPE_AES, derived_bits, &generator);
382382
383383
/* Clean up generator and key */
384384
psa_generator_abort(&generator);
@@ -494,7 +494,7 @@ Prerequisites to using key generation and export APIs:
494494

495495
Generate a piece of random 128-bit AES data:
496496
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`.
497-
1. Generate a random AES key by calling `psa_generate_key()`.
497+
1. Generate a random AES key by calling `psa_generate_random_key()`.
498498
1. Export the generated key by calling `psa_export_key()`:
499499
```C
500500
int slot = 1;
@@ -510,7 +510,7 @@ Generate a piece of random 128-bit AES data:
510510
psa_set_key_policy(slot, &policy);
511511

512512
/* Generate a key */
513-
psa_generate_key(slot, PSA_KEY_TYPE_AES, bits);
513+
psa_generate_random_key(slot, PSA_KEY_TYPE_AES, bits);
514514

515515
psa_export_key(slot, exported, exported_size, &exported_length)
516516

include/psa/crypto.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ psa_status_t psa_crypto_init(void);
179179
* -# Set the key type with psa_set_key_type(). If the key type requires
180180
* domain parameters, call psa_set_key_domain_parameters() instead.
181181
* Skip this step if copying an existing key with psa_copy_key().
182-
* -# When generating a random key with psa_generate_key() or deriving a key
183-
* with psa_generator_import_key(), set the desired key size with
182+
* -# When generating a random key with psa_generate_random_key() or deriving a key
183+
* with psa_generate_derived_key(), set the desired key size with
184184
* psa_set_key_bits().
185-
* -# Call a key creation function: psa_import_key(), psa_generate_key(),
186-
* psa_generator_import_key() or psa_copy_key(). This function reads
185+
* -# Call a key creation function: psa_import_key(), psa_generate_random_key(),
186+
* psa_generate_derived_key() or psa_copy_key(). This function reads
187187
* the attribute structure, creates a key with these attributes, and
188188
* outputs a handle to the newly created key.
189189
* -# The attribute structure is now no longer necessary. If you called
@@ -208,8 +208,8 @@ typedef struct psa_key_attributes_s psa_key_attributes_t;
208208
* This function does not access storage, it merely fills the attribute
209209
* structure with given values. The persistent key will be written to
210210
* storage when the attribute structure is passed to a key creation
211-
* function such as psa_import_key(), psa_generate_key(),
212-
* psa_generator_import_key() or psa_copy_key().
211+
* function such as psa_import_key(), psa_generate_random_key(),
212+
* psa_generate_derived_key() or psa_copy_key().
213213
*
214214
* This function overwrites any identifier and lifetime values
215215
* previously set in \p attributes.
@@ -3087,7 +3087,7 @@ psa_status_t psa_generator_read(psa_crypto_generator_t *generator,
30873087
* It is implementation-dependent whether a failure to initialize
30883088
* results in this error code.
30893089
*/
3090-
psa_status_t psa_generator_import_key(const psa_key_attributes_t *attributes,
3090+
psa_status_t psa_generate_derived_key(const psa_key_attributes_t *attributes,
30913091
psa_key_handle_t *handle,
30923092
psa_crypto_generator_t *generator);
30933093

@@ -3148,7 +3148,7 @@ psa_status_t psa_generator_abort(psa_crypto_generator_t *generator);
31483148
* or after providing inputs. For some algorithms, this step is mandatory
31493149
* because the output depends on the maximum capacity.
31503150
* - Generate output with psa_generator_read() or
3151-
* psa_generator_import_key(). Successive calls to these functions
3151+
* psa_generate_derived_key(). Successive calls to these functions
31523152
* use successive output bytes from the generator.
31533153
* - Clean up the generator object with psa_generator_abort().
31543154
*
@@ -3385,7 +3385,7 @@ psa_status_t psa_key_agreement_raw_shared_secret(psa_algorithm_t alg,
33853385
* and MUST NOT use the content of the output buffer if the return
33863386
* status is not #PSA_SUCCESS.
33873387
*
3388-
* \note To generate a key, use psa_generate_key() instead.
3388+
* \note To generate a key, use psa_generate_random_key() instead.
33893389
*
33903390
* \param[out] output Output buffer for the generated data.
33913391
* \param output_size Number of bytes to generate and output.
@@ -3447,7 +3447,7 @@ psa_status_t psa_generate_random(uint8_t *output,
34473447
* It is implementation-dependent whether a failure to initialize
34483448
* results in this error code.
34493449
*/
3450-
psa_status_t psa_generate_key(const psa_key_attributes_t *attributes,
3450+
psa_status_t psa_generate_random_key(const psa_key_attributes_t *attributes,
34513451
psa_key_handle_t *handle);
34523452

34533453
/**@}*/

include/psa/crypto_extra.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,12 @@ psa_status_t psa_copy_key_to_handle(psa_key_handle_t source_handle,
430430
psa_key_handle_t target_handle,
431431
const psa_key_policy_t *constraint);
432432

433-
psa_status_t psa_generator_import_key_to_handle(psa_key_handle_t handle,
433+
psa_status_t psa_generate_derived_key_to_handle(psa_key_handle_t handle,
434434
psa_key_type_t type,
435435
size_t bits,
436436
psa_crypto_generator_t *generator);
437437

438-
psa_status_t psa_generate_key_to_handle(psa_key_handle_t handle,
438+
psa_status_t psa_generate_random_key_to_handle(psa_key_handle_t handle,
439439
psa_key_type_t type,
440440
size_t bits,
441441
const void *extra,

include/psa/crypto_se_driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ typedef psa_status_t (*psa_drv_se_export_key_t)(psa_key_slot_number_t key,
783783
* \param[in] extra Extra parameters for key generation. The
784784
* interpretation of this parameter should match the
785785
* interpretation in the `extra` parameter is the
786-
* `psa_generate_key` function
786+
* `psa_generate_random_key` function
787787
* \param[in] extra_size The size in bytes of the \p extra buffer
788788
* \param[out] p_pubkey_out The buffer where the public key information will
789789
* be placed

library/psa_crypto.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4313,7 +4313,7 @@ static void psa_des_set_key_parity( uint8_t *data, size_t data_size )
43134313
}
43144314
#endif /* MBEDTLS_DES_C */
43154315

4316-
static psa_status_t psa_generator_import_key_internal(
4316+
static psa_status_t psa_generate_derived_key_internal(
43174317
psa_key_slot_t *slot,
43184318
size_t bits,
43194319
psa_crypto_generator_t *generator )
@@ -4344,7 +4344,7 @@ static psa_status_t psa_generator_import_key_internal(
43444344
return( status );
43454345
}
43464346

4347-
psa_status_t psa_generator_import_key( const psa_key_attributes_t *attributes,
4347+
psa_status_t psa_generate_derived_key( const psa_key_attributes_t *attributes,
43484348
psa_key_handle_t *handle,
43494349
psa_crypto_generator_t *generator )
43504350
{
@@ -4353,7 +4353,7 @@ psa_status_t psa_generator_import_key( const psa_key_attributes_t *attributes,
43534353
status = psa_start_key_creation( attributes, handle, &slot );
43544354
if( status == PSA_SUCCESS )
43554355
{
4356-
status = psa_generator_import_key_internal( slot,
4356+
status = psa_generate_derived_key_internal( slot,
43574357
attributes->bits,
43584358
generator );
43594359
}
@@ -4367,7 +4367,7 @@ psa_status_t psa_generator_import_key( const psa_key_attributes_t *attributes,
43674367
return( status );
43684368
}
43694369

4370-
psa_status_t psa_generator_import_key_to_handle( psa_key_handle_t handle,
4370+
psa_status_t psa_generate_derived_key_to_handle( psa_key_handle_t handle,
43714371
psa_key_type_t type,
43724372
size_t bits,
43734373
psa_crypto_generator_t *generator )
@@ -5148,7 +5148,7 @@ static psa_status_t psa_read_rsa_exponent( const uint8_t *domain_parameters,
51485148
}
51495149
#endif /* MBEDTLS_RSA_C && MBEDTLS_GENPRIME */
51505150

5151-
static psa_status_t psa_generate_key_internal(
5151+
static psa_status_t psa_generate_random_key_internal(
51525152
psa_key_slot_t *slot, size_t bits,
51535153
const uint8_t *domain_parameters, size_t domain_parameters_size )
51545154
{
@@ -5254,7 +5254,7 @@ static psa_status_t psa_generate_key_internal(
52545254
return( PSA_SUCCESS );
52555255
}
52565256

5257-
psa_status_t psa_generate_key_to_handle( psa_key_handle_t handle,
5257+
psa_status_t psa_generate_random_key_to_handle( psa_key_handle_t handle,
52585258
psa_key_type_t type,
52595259
size_t bits,
52605260
const void *extra,
@@ -5274,7 +5274,7 @@ psa_status_t psa_generate_key_to_handle( psa_key_handle_t handle,
52745274
return( status );
52755275

52765276
slot->type = type;
5277-
status = psa_generate_key_internal( slot, bits, extra, extra_size );
5277+
status = psa_generate_random_key_internal( slot, bits, extra, extra_size );
52785278
if( status != PSA_SUCCESS )
52795279
slot->type = 0;
52805280

@@ -5288,15 +5288,15 @@ psa_status_t psa_generate_key_to_handle( psa_key_handle_t handle,
52885288
return( status );
52895289
}
52905290

5291-
psa_status_t psa_generate_key( const psa_key_attributes_t *attributes,
5291+
psa_status_t psa_generate_random_key( const psa_key_attributes_t *attributes,
52925292
psa_key_handle_t *handle )
52935293
{
52945294
psa_status_t status;
52955295
psa_key_slot_t *slot = NULL;
52965296
status = psa_start_key_creation( attributes, handle, &slot );
52975297
if( status == PSA_SUCCESS )
52985298
{
5299-
status = psa_generate_key_internal(
5299+
status = psa_generate_random_key_internal(
53005300
slot, attributes->bits,
53015301
attributes->domain_parameters, attributes->domain_parameters_size );
53025302
}

library/ssl_cli.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3148,7 +3148,7 @@ static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl )
31483148
return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
31493149

31503150
/* Generate ECDH private key. */
3151-
status = psa_generate_key_to_handle( handshake->ecdh_psa_privkey,
3151+
status = psa_generate_random_key_to_handle( handshake->ecdh_psa_privkey,
31523152
PSA_KEY_TYPE_ECC_KEYPAIR( handshake->ecdh_psa_curve ),
31533153
MBEDTLS_PSA_ECC_KEY_BITS_OF_CURVE( handshake->ecdh_psa_curve ),
31543154
NULL, 0 );

programs/psa/crypto_examples.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ cipher_example_encrypt_decrypt_aes_cbc_nopad_1_block( void )
164164
psa_set_key_type( &attributes, PSA_KEY_TYPE_AES );
165165
psa_set_key_bits( &attributes, key_bits );
166166

167-
status = psa_generate_key( &attributes, &key_handle );
167+
status = psa_generate_random_key( &attributes, &key_handle );
168168
ASSERT_STATUS( status, PSA_SUCCESS );
169169

170170
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 )
215215
psa_set_key_type( &attributes, PSA_KEY_TYPE_AES );
216216
psa_set_key_bits( &attributes, key_bits );
217217

218-
status = psa_generate_key( &attributes, &key_handle );
218+
status = psa_generate_random_key( &attributes, &key_handle );
219219
ASSERT_STATUS( status, PSA_SUCCESS );
220220

221221
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 )
262262
psa_set_key_type( &attributes, PSA_KEY_TYPE_AES );
263263
psa_set_key_bits( &attributes, key_bits );
264264

265-
status = psa_generate_key( &attributes, &key_handle );
265+
status = psa_generate_random_key( &attributes, &key_handle );
266266
ASSERT_STATUS( status, PSA_SUCCESS );
267267

268268
status = cipher_encrypt( key_handle, alg, iv, sizeof( iv ),

programs/psa/key_ladder_demo.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static psa_status_t generate( const char *key_file_name )
208208
psa_set_key_type( &attributes, PSA_KEY_TYPE_DERIVE );
209209
psa_set_key_bits( &attributes, PSA_BYTES_TO_BITS( KEY_SIZE_BYTES ) );
210210

211-
PSA_CHECK( psa_generate_key( &attributes, &key_handle ) );
211+
PSA_CHECK( psa_generate_random_key( &attributes, &key_handle ) );
212212

213213
PSA_CHECK( save_key( key_handle, key_file_name ) );
214214

@@ -306,7 +306,7 @@ static psa_status_t derive_key_ladder( const char *ladder[],
306306
*key_handle = 0;
307307
/* Use the generator obtained from the parent key to create
308308
* the next intermediate key. */
309-
PSA_CHECK( psa_generator_import_key( &attributes, key_handle,
309+
PSA_CHECK( psa_generate_derived_key( &attributes, key_handle,
310310
&generator ) );
311311
PSA_CHECK( psa_generator_abort( &generator ) );
312312
}
@@ -343,7 +343,7 @@ static psa_status_t derive_wrapping_key( psa_key_usage_t usage,
343343
WRAPPING_KEY_SALT, WRAPPING_KEY_SALT_LENGTH,
344344
NULL, 0,
345345
PSA_BITS_TO_BYTES( WRAPPING_KEY_BITS ) ) );
346-
PSA_CHECK( psa_generator_import_key( &attributes, wrapping_key_handle,
346+
PSA_CHECK( psa_generate_derived_key( &attributes, wrapping_key_handle,
347347
&generator ) );
348348

349349
exit:

tests/suites/test_suite_pk.function

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ psa_key_handle_t pk_psa_genkey( void )
9797
return( PK_PSA_INVALID_SLOT );
9898

9999
/* generate key */
100-
if( PSA_SUCCESS != psa_generate_key_to_handle( key, type, bits, NULL, 0 ) )
100+
if( PSA_SUCCESS != psa_generate_random_key_to_handle( key, type, bits, NULL, 0 ) )
101101
return( PK_PSA_INVALID_SLOT );
102102

103103
return( key );

tests/suites/test_suite_psa_crypto.function

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4322,7 +4322,7 @@ void derive_key_exercise( int alg_arg,
43224322
psa_set_key_algorithm( &attributes, derived_alg );
43234323
psa_set_key_type( &attributes, derived_type );
43244324
psa_set_key_bits( &attributes, derived_bits );
4325-
PSA_ASSERT( psa_generator_import_key( &attributes, &derived_handle,
4325+
PSA_ASSERT( psa_generate_derived_key( &attributes, &derived_handle,
43264326
&generator ) );
43274327

43284328
/* Test the key information */
@@ -4393,15 +4393,15 @@ void derive_key_export( int alg_arg,
43934393
psa_set_key_algorithm( &derived_attributes, 0 );
43944394
psa_set_key_type( &derived_attributes, PSA_KEY_TYPE_RAW_DATA );
43954395
psa_set_key_bits( &derived_attributes, PSA_BYTES_TO_BITS( bytes1 ) );
4396-
PSA_ASSERT( psa_generator_import_key( &derived_attributes, &derived_handle,
4396+
PSA_ASSERT( psa_generate_derived_key( &derived_attributes, &derived_handle,
43974397
&generator ) );
43984398
PSA_ASSERT( psa_export_key( derived_handle,
43994399
export_buffer, bytes1,
44004400
&length ) );
44014401
TEST_EQUAL( length, bytes1 );
44024402
PSA_ASSERT( psa_destroy_key( derived_handle ) );
44034403
psa_set_key_bits( &derived_attributes, PSA_BYTES_TO_BITS( bytes2 ) );
4404-
PSA_ASSERT( psa_generator_import_key( &derived_attributes, &derived_handle,
4404+
PSA_ASSERT( psa_generate_derived_key( &derived_attributes, &derived_handle,
44054405
&generator ) );
44064406
PSA_ASSERT( psa_export_key( derived_handle,
44074407
export_buffer + bytes1, bytes2,
@@ -4695,7 +4695,7 @@ void generate_key( int type_arg,
46954695
psa_set_key_bits( &attributes, bits );
46964696

46974697
/* Generate a key */
4698-
TEST_EQUAL( psa_generate_key( &attributes, &handle ), expected_status );
4698+
TEST_EQUAL( psa_generate_random_key( &attributes, &handle ), expected_status );
46994699
if( expected_status != PSA_SUCCESS )
47004700
goto exit;
47014701

@@ -4755,7 +4755,7 @@ void generate_key_rsa( int bits_arg,
47554755
psa_set_key_bits( &attributes, bits );
47564756

47574757
/* Generate a key */
4758-
TEST_EQUAL( psa_generate_key( &attributes, &handle ), expected_status );
4758+
TEST_EQUAL( psa_generate_random_key( &attributes, &handle ), expected_status );
47594759
if( expected_status != PSA_SUCCESS )
47604760
goto exit;
47614761

@@ -4863,7 +4863,7 @@ void persistent_key_load_key_from_storage( data_t *data,
48634863

48644864
case GENERATE_KEY:
48654865
/* Generate a key */
4866-
PSA_ASSERT( psa_generate_key( &attributes, &handle ) );
4866+
PSA_ASSERT( psa_generate_random_key( &attributes, &handle ) );
48674867
break;
48684868

48694869
case DERIVE_KEY:
@@ -4885,7 +4885,7 @@ void persistent_key_load_key_from_storage( data_t *data,
48854885
PSA_ASSERT( psa_key_derivation_input_bytes(
48864886
&generator, PSA_KDF_STEP_INFO,
48874887
NULL, 0 ) );
4888-
PSA_ASSERT( psa_generator_import_key( &attributes, &handle,
4888+
PSA_ASSERT( psa_generate_derived_key( &attributes, &handle,
48894889
&generator ) );
48904890
PSA_ASSERT( psa_generator_abort( &generator ) );
48914891
PSA_ASSERT( psa_destroy_key( base_key ) );

0 commit comments

Comments
 (0)