diff --git a/docs/getting_started.md b/docs/getting_started.md index ec8cc08ce..9a702eaed 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -335,7 +335,7 @@ Deriving a new AES-CTR 128-bit encryption key into a given key slot using HKDF w 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). 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`. 1. Set the key policy to the derived key slot. -1. Import a key from generator into the desired key slot using (`psa_generate_derived_key`). +1. Import a key from generator into the desired key slot using (`psa_key_derivation_output_key`). 1. Clean up generator. At this point the derived key slot holds a new 128-bit AES-CTR encryption key derived from the key, salt and label provided: @@ -358,7 +358,7 @@ At this point the derived key slot holds a new 128-bit AES-CTR encryption key de psa_algorithm_t alg = PSA_ALG_HKDF(PSA_ALG_SHA_256); psa_key_policy_t policy = PSA_KEY_POLICY_INIT; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; size_t derived_bits = 128; size_t capacity = PSA_BITS_TO_BYTES(derived_bits); @@ -378,10 +378,10 @@ At this point the derived key slot holds a new 128-bit AES-CTR encryption key de psa_set_key_policy(derived_key, &policy); - psa_generate_derived_key(derived_key, PSA_KEY_TYPE_AES, derived_bits, &generator); + psa_key_derivation_output_key(derived_key, PSA_KEY_TYPE_AES, derived_bits, &generator); /* Clean up generator and key */ - psa_generator_abort(&generator); + psa_key_derivation_abort(&generator); /* as part of clean up you may want to clean up the keys used by calling: * psa_destroy_key( base_key ); or psa_destroy_key( derived_key ); */ mbedtls_psa_crypto_free(); diff --git a/include/psa/crypto.h b/include/psa/crypto.h index 8c42e932e..0bff6cee9 100644 --- a/include/psa/crypto.h +++ b/include/psa/crypto.h @@ -183,10 +183,10 @@ psa_status_t psa_crypto_init(void); * domain parameters, call psa_set_key_domain_parameters() instead. * 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 - * with psa_generate_derived_key(), set the desired key size with + * 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(), - * psa_generate_derived_key() or psa_copy_key(). This function reads + * 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. * -# The attribute structure is now no longer necessary. If you called @@ -217,7 +217,7 @@ typedef struct psa_key_attributes_s psa_key_attributes_t; * 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_generate_derived_key() or psa_copy_key(). + * psa_key_derivation_output_key() or psa_copy_key(). * * This function may be declared as `static` (i.e. without external * linkage). This function may be provided as a function-like macro, @@ -242,7 +242,7 @@ static void psa_set_key_id(psa_key_attributes_t *attributes, * 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_generate_derived_key() or psa_copy_key(). + * psa_key_derivation_output_key() or psa_copy_key(). * * This function may be declared as `static` (i.e. without external * linkage). This function may be provided as a function-like macro, @@ -2979,46 +2979,46 @@ psa_status_t psa_asymmetric_decrypt(psa_key_handle_t handle, * initialize it by any of the following means: * - Set the structure to all-bits-zero, for example: * \code - * psa_crypto_generator_t generator; + * psa_key_derivation_operation_t generator; * memset(&generator, 0, sizeof(generator)); * \endcode * - Initialize the structure to logical zero values, for example: * \code - * psa_crypto_generator_t generator = {0}; + * psa_key_derivation_operation_t generator = {0}; * \endcode - * - Initialize the structure to the initializer #PSA_CRYPTO_GENERATOR_INIT, + * - Initialize the structure to the initializer #PSA_KEY_DERIVATION_OPERATION_INIT, * for example: * \code - * psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + * psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; * \endcode - * - Assign the result of the function psa_crypto_generator_init() + * - Assign the result of the function psa_key_derivation_operation_init() * to the structure, for example: * \code - * psa_crypto_generator_t generator; - * generator = psa_crypto_generator_init(); + * psa_key_derivation_operation_t generator; + * generator = psa_key_derivation_operation_init(); * \endcode * * This is an implementation-defined \c struct. Applications should not * make any assumptions about the content of this structure except * as directed by the documentation of a specific implementation. */ -typedef struct psa_crypto_generator_s psa_crypto_generator_t; +typedef struct psa_crypto_generator_s psa_key_derivation_operation_t; -/** \def PSA_CRYPTO_GENERATOR_INIT +/** \def PSA_KEY_DERIVATION_OPERATION_INIT * * This macro returns a suitable initializer for a generator object - * of type #psa_crypto_generator_t. + * of type #psa_key_derivation_operation_t. */ #ifdef __DOXYGEN_ONLY__ /* This is an example definition for documentation purposes. * Implementations should define a suitable value in `crypto_struct.h`. */ -#define PSA_CRYPTO_GENERATOR_INIT {0} +#define PSA_KEY_DERIVATION_OPERATION_INIT {0} #endif /** Return an initial value for a generator object. */ -static psa_crypto_generator_t psa_crypto_generator_init(void); +static psa_key_derivation_operation_t psa_key_derivation_operation_init(void); /** Retrieve the current capacity of a generator. * @@ -3032,7 +3032,7 @@ static psa_crypto_generator_t psa_crypto_generator_init(void); * \retval #PSA_ERROR_BAD_STATE * \retval #PSA_ERROR_COMMUNICATION_FAILURE */ -psa_status_t psa_get_generator_capacity(const psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation_get_capacity(const psa_key_derivation_operation_t *generator, size_t *capacity); /** Set the maximum capacity of a generator. @@ -3048,7 +3048,7 @@ psa_status_t psa_get_generator_capacity(const psa_crypto_generator_t *generator, * \retval #PSA_ERROR_BAD_STATE * \retval #PSA_ERROR_COMMUNICATION_FAILURE */ -psa_status_t psa_set_generator_capacity(psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation_set_capacity(psa_key_derivation_operation_t *generator, size_t capacity); /** Read some data from a generator. @@ -3076,7 +3076,7 @@ psa_status_t psa_set_generator_capacity(psa_crypto_generator_t *generator, * \retval #PSA_ERROR_HARDWARE_FAILURE * \retval #PSA_ERROR_TAMPERING_DETECTED */ -psa_status_t psa_generator_read(psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation_output_bytes(psa_key_derivation_operation_t *generator, uint8_t *output, size_t output_length); @@ -3088,7 +3088,7 @@ psa_status_t psa_generator_read(psa_crypto_generator_t *generator, * * - For key types for which the key is an arbitrary sequence of bytes * of a given size, - * this function is functionally equivalent to calling #psa_generator_read + * this function is functionally equivalent to calling #psa_key_derivation_output_bytes * and passing the resulting output to #psa_import_key. * However, this function has a security benefit: * if the implementation provides an isolation boundary then @@ -3188,8 +3188,8 @@ psa_status_t psa_generator_read(psa_crypto_generator_t *generator, * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_generate_derived_key(const psa_key_attributes_t *attributes, - psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation_output_key(const psa_key_attributes_t *attributes, + psa_key_derivation_operation_t *generator, psa_key_handle_t *handle); /** Abort a generator. @@ -3199,9 +3199,9 @@ psa_status_t psa_generate_derived_key(const psa_key_attributes_t *attributes, * \c generator structure itself. * * This function may be called at any time as long as the generator - * object has been initialized to #PSA_CRYPTO_GENERATOR_INIT, to - * psa_crypto_generator_init() or a zero value. In particular, it is valid - * to call psa_generator_abort() twice, or to call psa_generator_abort() + * object has been initialized to #PSA_KEY_DERIVATION_OPERATION_INIT, to + * psa_key_derivation_operation_init() or a zero value. In particular, it is valid + * to call psa_key_derivation_abort() twice, or to call psa_key_derivation_abort() * on a generator that has not been set up. * * Once aborted, the generator object may be called. @@ -3214,7 +3214,7 @@ psa_status_t psa_generate_derived_key(const psa_key_attributes_t *attributes, * \retval #PSA_ERROR_HARDWARE_FAILURE * \retval #PSA_ERROR_TAMPERING_DETECTED */ -psa_status_t psa_generator_abort(psa_crypto_generator_t *generator); +psa_status_t psa_key_derivation_abort(psa_key_derivation_operation_t *generator); /** Use the maximum possible capacity for a generator. * @@ -3223,7 +3223,7 @@ psa_status_t psa_generator_abort(psa_crypto_generator_t *generator); * The value of the maximum possible capacity depends on the generator * algorithm. */ -#define PSA_GENERATOR_UNBRIDLED_CAPACITY ((size_t)(-1)) +#define PSA_KEY_DERIVATION_UNLIMITED_CAPACITY ((size_t)(-1)) /**@}*/ @@ -3238,20 +3238,20 @@ psa_status_t psa_generator_abort(psa_crypto_generator_t *generator); * cryptographic material. * * To use a generator for key derivation: - * - Start with an initialized object of type #psa_crypto_generator_t. + * - Start with an initialized object of type #psa_key_derivation_operation_t. * - Call psa_key_derivation_setup() to select the algorithm. * - Provide the inputs for the key derivation by calling * psa_key_derivation_input_bytes() or psa_key_derivation_input_key() * as appropriate. Which inputs are needed, in what order, and whether * they may be keys and if so of what type depends on the algorithm. * - Optionally set the generator's maximum capacity with - * psa_set_generator_capacity(). You may do this before, in the middle of + * psa_key_derivation_set_capacity(). You may do this before, in the middle of * or after providing inputs. For some algorithms, this step is mandatory * because the output depends on the maximum capacity. - * - Generate output with psa_generator_read() or - * psa_generate_derived_key(). Successive calls to these functions + * - Generate output with psa_key_derivation_output_bytes() or + * psa_key_derivation_output_key(). Successive calls to these functions * use successive output bytes from the generator. - * - Clean up the generator object with psa_generator_abort(). + * - Clean up the generator object with psa_key_derivation_abort(). * * \param[in,out] generator The generator object to set up. It must * have been initialized but not set up yet. @@ -3271,7 +3271,7 @@ psa_status_t psa_generator_abort(psa_crypto_generator_t *generator); * \retval #PSA_ERROR_TAMPERING_DETECTED * \retval #PSA_ERROR_BAD_STATE */ -psa_status_t psa_key_derivation_setup(psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation_setup(psa_key_derivation_operation_t *generator, psa_algorithm_t alg); /** Provide an input for key derivation or key agreement. @@ -3309,7 +3309,7 @@ psa_status_t psa_key_derivation_setup(psa_crypto_generator_t *generator, * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_key_derivation_input_bytes(psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation_input_bytes(psa_key_derivation_operation_t *generator, psa_key_derivation_step_t step, const uint8_t *data, size_t data_length); @@ -3354,7 +3354,7 @@ psa_status_t psa_key_derivation_input_bytes(psa_crypto_generator_t *generator, * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_key_derivation_input_key(psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation_input_key(psa_key_derivation_operation_t *generator, psa_key_derivation_step_t step, psa_key_handle_t handle); @@ -3411,7 +3411,7 @@ psa_status_t psa_key_derivation_input_key(psa_crypto_generator_t *generator, * \retval #PSA_ERROR_HARDWARE_FAILURE * \retval #PSA_ERROR_TAMPERING_DETECTED */ -psa_status_t psa_key_agreement(psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation_key_agreement(psa_key_derivation_operation_t *generator, psa_key_derivation_step_t step, psa_key_handle_t private_key, const uint8_t *peer_key, @@ -3427,7 +3427,7 @@ psa_status_t psa_key_agreement(psa_crypto_generator_t *generator, * Diffie-Hellman or elliptic curve Diffie-Hellman has biases and should * not be used directly as key material. It should instead be passed as * input to a key derivation algorithm. To chain a key agreement with - * a key derivation, use psa_key_agreement() and other functions from + * a key derivation, use psa_key_derivation_key_agreement() and other functions from * the key derivation and generator interface. * * \param alg The key agreement algorithm to compute diff --git a/include/psa/crypto_extra.h b/include/psa/crypto_extra.h index 216039c85..66e5dbc64 100644 --- a/include/psa/crypto_extra.h +++ b/include/psa/crypto_extra.h @@ -159,7 +159,7 @@ psa_status_t mbedtls_psa_inject_entropy(const unsigned char *seed, * * \param[in,out] generator The generator object to set up. It must have * been initialized as per the documentation for - * #psa_crypto_generator_t and not yet in use. + * #psa_key_derivation_operation_t and not yet in use. * \param handle Handle to the secret key. * \param alg The key derivation algorithm to compute * (\c PSA_ALG_XXX value such that @@ -190,7 +190,7 @@ psa_status_t mbedtls_psa_inject_entropy(const unsigned char *seed, * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_key_derivation(psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation(psa_key_derivation_operation_t *generator, psa_key_handle_t handle, psa_algorithm_t alg, const uint8_t *salt, @@ -433,7 +433,7 @@ psa_status_t psa_copy_key_to_handle(psa_key_handle_t source_handle, psa_status_t psa_generate_derived_key_to_handle(psa_key_handle_t handle, psa_key_type_t type, size_t bits, - psa_crypto_generator_t *generator); + psa_key_derivation_operation_t *generator); psa_status_t psa_generate_random_key_to_handle(psa_key_handle_t handle, psa_key_type_t type, diff --git a/include/psa/crypto_struct.h b/include/psa/crypto_struct.h index df765711c..74e362d8e 100644 --- a/include/psa/crypto_struct.h +++ b/include/psa/crypto_struct.h @@ -240,10 +240,10 @@ struct psa_crypto_generator_s } ctx; }; -#define PSA_CRYPTO_GENERATOR_INIT {0, 0, {{0, 0}}} -static inline struct psa_crypto_generator_s psa_crypto_generator_init( void ) +#define PSA_KEY_DERIVATION_OPERATION_INIT {0, 0, {{0, 0}}} +static inline struct psa_crypto_generator_s psa_key_derivation_operation_init( void ) { - const struct psa_crypto_generator_s v = PSA_CRYPTO_GENERATOR_INIT; + const struct psa_crypto_generator_s v = PSA_KEY_DERIVATION_OPERATION_INIT; return( v ); } diff --git a/library/psa_crypto.c b/library/psa_crypto.c index 90de4fa87..88e646ab1 100644 --- a/library/psa_crypto.c +++ b/library/psa_crypto.c @@ -4066,7 +4066,7 @@ exit: #define HKDF_STATE_OUTPUT 3 /* output started */ static psa_algorithm_t psa_generator_get_kdf_alg( - const psa_crypto_generator_t *generator ) + const psa_key_derivation_operation_t *generator ) { if ( PSA_ALG_IS_KEY_AGREEMENT( generator->alg ) ) return( PSA_ALG_KEY_AGREEMENT_GET_KDF( generator->alg ) ); @@ -4075,7 +4075,7 @@ static psa_algorithm_t psa_generator_get_kdf_alg( } -psa_status_t psa_generator_abort( psa_crypto_generator_t *generator ) +psa_status_t psa_key_derivation_abort( psa_key_derivation_operation_t *generator ) { psa_status_t status = PSA_SUCCESS; psa_algorithm_t kdf_alg = psa_generator_get_kdf_alg( generator ); @@ -4129,7 +4129,7 @@ psa_status_t psa_generator_abort( psa_crypto_generator_t *generator ) return( status ); } -psa_status_t psa_get_generator_capacity(const psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation_get_capacity(const psa_key_derivation_operation_t *generator, size_t *capacity) { if( generator->alg == 0 ) @@ -4142,7 +4142,7 @@ psa_status_t psa_get_generator_capacity(const psa_crypto_generator_t *generator, return( PSA_SUCCESS ); } -psa_status_t psa_set_generator_capacity( psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation_set_capacity( psa_key_derivation_operation_t *generator, size_t capacity ) { if( generator->alg == 0 ) @@ -4181,7 +4181,7 @@ static psa_status_t psa_generator_hkdf_read( psa_hkdf_generator_t *hkdf, if( output_length == 0 ) break; /* We can't be wanting more output after block 0xff, otherwise - * the capacity check in psa_generator_read() would have + * the capacity check in psa_key_derivation_output_bytes() would have * prevented this call. It could happen only if the generator * object was corrupted or if this function is called directly * inside the library. */ @@ -4236,7 +4236,7 @@ static psa_status_t psa_generator_tls12_prf_generate_next_block( size_t Ai_len; /* We can't be wanting more output after block 0xff, otherwise - * the capacity check in psa_generator_read() would have + * the capacity check in psa_key_derivation_output_bytes() would have * prevented this call. It could happen only if the generator * object was corrupted or if this function is called directly * inside the library. */ @@ -4376,7 +4376,7 @@ static psa_status_t psa_generator_tls12_prf_read( } #endif /* MBEDTLS_MD_C */ -psa_status_t psa_generator_read( psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation_output_bytes( psa_key_derivation_operation_t *generator, uint8_t *output, size_t output_length ) { @@ -4454,7 +4454,7 @@ exit: * blank generators, so we can return PSA_ERROR_BAD_STATE on blank * generators. */ psa_algorithm_t alg = generator->alg; - psa_generator_abort( generator ); + psa_key_derivation_abort( generator ); generator->alg = alg; memset( output, '!', output_length ); } @@ -4476,7 +4476,7 @@ static void psa_des_set_key_parity( uint8_t *data, size_t data_size ) static psa_status_t psa_generate_derived_key_internal( psa_key_slot_t *slot, size_t bits, - psa_crypto_generator_t *generator ) + psa_key_derivation_operation_t *generator ) { uint8_t *data = NULL; size_t bytes = PSA_BITS_TO_BYTES( bits ); @@ -4490,7 +4490,7 @@ static psa_status_t psa_generate_derived_key_internal( if( data == NULL ) return( PSA_ERROR_INSUFFICIENT_MEMORY ); - status = psa_generator_read( generator, data, bytes ); + status = psa_key_derivation_output_bytes( generator, data, bytes ); if( status != PSA_SUCCESS ) goto exit; #if defined(MBEDTLS_DES_C) @@ -4504,8 +4504,8 @@ exit: return( status ); } -psa_status_t psa_generate_derived_key( const psa_key_attributes_t *attributes, - psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation_output_key( const psa_key_attributes_t *attributes, + psa_key_derivation_operation_t *generator, psa_key_handle_t *handle ) { psa_status_t status; @@ -4530,7 +4530,7 @@ psa_status_t psa_generate_derived_key( const psa_key_attributes_t *attributes, psa_status_t psa_generate_derived_key_to_handle( psa_key_handle_t handle, psa_key_type_t type, size_t bits, - psa_crypto_generator_t *generator ) + psa_key_derivation_operation_t *generator ) { uint8_t *data = NULL; size_t bytes = PSA_BITS_TO_BYTES( bits ); @@ -4544,7 +4544,7 @@ psa_status_t psa_generate_derived_key_to_handle( psa_key_handle_t handle, if( data == NULL ) return( PSA_ERROR_INSUFFICIENT_MEMORY ); - status = psa_generator_read( generator, data, bytes ); + status = psa_key_derivation_output_bytes( generator, data, bytes ); if( status != PSA_SUCCESS ) goto exit; #if defined(MBEDTLS_DES_C) @@ -4568,7 +4568,7 @@ exit: /* Set up an HKDF-based generator. This is exactly the extract phase * of the HKDF algorithm. * - * Note that if this function fails, you must call psa_generator_abort() + * Note that if this function fails, you must call psa_key_derivation_abort() * to potentially free embedded data structures and wipe confidential data. */ static psa_status_t psa_generator_hkdf_setup( psa_hkdf_generator_t *hkdf, @@ -4613,7 +4613,7 @@ static psa_status_t psa_generator_hkdf_setup( psa_hkdf_generator_t *hkdf, #if defined(MBEDTLS_MD_C) /* Set up a TLS-1.2-prf-based generator (see RFC 5246, Section 5). * - * Note that if this function fails, you must call psa_generator_abort() + * Note that if this function fails, you must call psa_key_derivation_abort() * to potentially free embedded data structures and wipe confidential data. */ static psa_status_t psa_generator_tls12_prf_setup( @@ -4661,7 +4661,7 @@ static psa_status_t psa_generator_tls12_prf_setup( } /* The first block gets generated when - * psa_generator_read() is called. */ + * psa_key_derivation_output_bytes() is called. */ tls12_prf->block_number = 0; tls12_prf->offset_in_block = hash_length; @@ -4710,11 +4710,11 @@ static psa_status_t psa_generator_tls12_psk_to_ms_setup( } #endif /* MBEDTLS_MD_C */ -/* Note that if this function fails, you must call psa_generator_abort() +/* Note that if this function fails, you must call psa_key_derivation_abort() * to potentially free embedded data structures and wipe confidential data. */ static psa_status_t psa_key_derivation_internal( - psa_crypto_generator_t *generator, + psa_key_derivation_operation_t *generator, const uint8_t *secret, size_t secret_length, psa_algorithm_t alg, const uint8_t *salt, size_t salt_length, @@ -4801,7 +4801,7 @@ static psa_status_t psa_key_derivation_internal( if( capacity <= max_capacity ) generator->capacity = capacity; - else if( capacity == PSA_GENERATOR_UNBRIDLED_CAPACITY ) + else if( capacity == PSA_KEY_DERIVATION_UNLIMITED_CAPACITY ) generator->capacity = max_capacity; else return( PSA_ERROR_INVALID_ARGUMENT ); @@ -4809,7 +4809,7 @@ static psa_status_t psa_key_derivation_internal( return( PSA_SUCCESS ); } -psa_status_t psa_key_derivation( psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation( psa_key_derivation_operation_t *generator, psa_key_handle_t handle, psa_algorithm_t alg, const uint8_t *salt, @@ -4845,12 +4845,12 @@ psa_status_t psa_key_derivation( psa_crypto_generator_t *generator, label, label_length, capacity ); if( status != PSA_SUCCESS ) - psa_generator_abort( generator ); + psa_key_derivation_abort( generator ); return( status ); } static psa_status_t psa_key_derivation_setup_kdf( - psa_crypto_generator_t *generator, + psa_key_derivation_operation_t *generator, psa_algorithm_t kdf_alg ) { /* Make sure that kdf_alg is a supported key derivation algorithm. */ @@ -4877,7 +4877,7 @@ static psa_status_t psa_key_derivation_setup_kdf( return( PSA_ERROR_NOT_SUPPORTED ); } -psa_status_t psa_key_derivation_setup( psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation_setup( psa_key_derivation_operation_t *generator, psa_algorithm_t alg ) { psa_status_t status; @@ -4972,7 +4972,7 @@ static psa_status_t psa_hkdf_input( psa_hkdf_generator_t *hkdf, #endif /* MBEDTLS_MD_C */ static psa_status_t psa_key_derivation_input_raw( - psa_crypto_generator_t *generator, + psa_key_derivation_operation_t *generator, psa_key_derivation_step_t step, const uint8_t *data, size_t data_length ) @@ -5018,11 +5018,11 @@ static psa_status_t psa_key_derivation_input_raw( } if( status != PSA_SUCCESS ) - psa_generator_abort( generator ); + psa_key_derivation_abort( generator ); return( status ); } -psa_status_t psa_key_derivation_input_bytes( psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation_input_bytes( psa_key_derivation_operation_t *generator, psa_key_derivation_step_t step, const uint8_t *data, size_t data_length ) @@ -5039,7 +5039,7 @@ psa_status_t psa_key_derivation_input_bytes( psa_crypto_generator_t *generator, } } -psa_status_t psa_key_derivation_input_key( psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation_input_key( psa_key_derivation_operation_t *generator, psa_key_derivation_step_t step, psa_key_handle_t handle ) { @@ -5148,10 +5148,10 @@ static psa_status_t psa_key_agreement_raw_internal( psa_algorithm_t alg, } } -/* Note that if this function fails, you must call psa_generator_abort() +/* Note that if this function fails, you must call psa_key_derivation_abort() * to potentially free embedded data structures and wipe confidential data. */ -static psa_status_t psa_key_agreement_internal( psa_crypto_generator_t *generator, +static psa_status_t psa_key_agreement_internal( psa_key_derivation_operation_t *generator, psa_key_derivation_step_t step, psa_key_slot_t *private_key, const uint8_t *peer_key, @@ -5183,7 +5183,7 @@ exit: return( status ); } -psa_status_t psa_key_agreement( psa_crypto_generator_t *generator, +psa_status_t psa_key_derivation_key_agreement( psa_key_derivation_operation_t *generator, psa_key_derivation_step_t step, psa_key_handle_t private_key, const uint8_t *peer_key, @@ -5201,7 +5201,7 @@ psa_status_t psa_key_agreement( psa_crypto_generator_t *generator, slot, peer_key, peer_key_length ); if( status != PSA_SUCCESS ) - psa_generator_abort( generator ); + psa_key_derivation_abort( generator ); return( status ); } diff --git a/library/ssl_cli.c b/library/ssl_cli.c index 81c69dd5f..41c2bd23a 100644 --- a/library/ssl_cli.c +++ b/library/ssl_cli.c @@ -3116,7 +3116,7 @@ static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl ) unsigned char *own_pubkey_ecpoint; size_t own_pubkey_ecpoint_len; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; header_len = 4; @@ -3178,7 +3178,7 @@ static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl ) content_len = own_pubkey_ecpoint_len + 1; /* Compute ECDH shared secret. */ - status = psa_key_agreement( &generator, + status = psa_key_derivation_key_agreement( &generator, handshake->ecdh_psa_privkey, handshake->ecdh_psa_peerkey, handshake->ecdh_psa_peerkey_len, @@ -3191,16 +3191,16 @@ static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl ) ssl->handshake->pmslen = MBEDTLS_PSA_ECC_KEY_BYTES_OF_CURVE( handshake->ecdh_psa_curve ); - status = psa_generator_read( &generator, + status = psa_key_derivation_output_bytes( &generator, ssl->handshake->premaster, ssl->handshake->pmslen ); if( status != PSA_SUCCESS ) { - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); } - status = psa_generator_abort( &generator ); + status = psa_key_derivation_abort( &generator ); if( status != PSA_SUCCESS ) return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 26814429e..42d823063 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -526,7 +526,7 @@ static int tls_prf_generic( mbedtls_md_type_t md_type, psa_algorithm_t alg; psa_key_policy_t policy; psa_key_handle_t master_slot; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; if( ( status = psa_allocate_key( &master_slot ) ) != PSA_SUCCESS ) return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); @@ -556,20 +556,20 @@ static int tls_prf_generic( mbedtls_md_type_t md_type, dlen ); if( status != PSA_SUCCESS ) { - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); psa_destroy_key( master_slot ); return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); } - status = psa_generator_read( &generator, dstbuf, dlen ); + status = psa_key_derivation_output_bytes( &generator, dstbuf, dlen ); if( status != PSA_SUCCESS ) { - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); psa_destroy_key( master_slot ); return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); } - status = psa_generator_abort( &generator ); + status = psa_key_derivation_abort( &generator ); if( status != PSA_SUCCESS ) { psa_destroy_key( master_slot ); @@ -892,7 +892,7 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl ) /* Perform PSK-to-MS expansion in a single step. */ psa_status_t status; psa_algorithm_t alg; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; psa_key_handle_t psk; MBEDTLS_SSL_DEBUG_MSG( 2, ( "perform PSA-based PSK-to-MS expansion" ) ); @@ -913,19 +913,19 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl ) master_secret_len ); if( status != PSA_SUCCESS ) { - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); } - status = psa_generator_read( &generator, session->master, + status = psa_key_derivation_output_bytes( &generator, session->master, master_secret_len ); if( status != PSA_SUCCESS ) { - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); } - status = psa_generator_abort( &generator ); + status = psa_key_derivation_abort( &generator ); if( status != PSA_SUCCESS ) return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED ); } diff --git a/programs/psa/key_ladder_demo.c b/programs/psa/key_ladder_demo.c index aded3bc38..4ebb7e049 100644 --- a/programs/psa/key_ladder_demo.c +++ b/programs/psa/key_ladder_demo.c @@ -279,7 +279,7 @@ static psa_status_t derive_key_ladder( const char *ladder[], { psa_status_t status = PSA_SUCCESS; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; size_t i; psa_set_key_usage_flags( &attributes, @@ -306,13 +306,13 @@ static psa_status_t derive_key_ladder( const char *ladder[], *key_handle = 0; /* Use the generator obtained from the parent key to create * the next intermediate key. */ - PSA_CHECK( psa_generate_derived_key( &attributes, &generator, + PSA_CHECK( psa_key_derivation_output_key( &attributes, &generator, key_handle ) ); - PSA_CHECK( psa_generator_abort( &generator ) ); + PSA_CHECK( psa_key_derivation_abort( &generator ) ); } exit: - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); if( status != PSA_SUCCESS ) { psa_close_key( *key_handle ); @@ -328,7 +328,7 @@ static psa_status_t derive_wrapping_key( psa_key_usage_t usage, { psa_status_t status = PSA_SUCCESS; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; *wrapping_key_handle = 0; psa_set_key_usage_flags( &attributes, usage ); @@ -343,11 +343,11 @@ static psa_status_t derive_wrapping_key( psa_key_usage_t usage, WRAPPING_KEY_SALT, WRAPPING_KEY_SALT_LENGTH, NULL, 0, PSA_BITS_TO_BYTES( WRAPPING_KEY_BITS ) ) ); - PSA_CHECK( psa_generate_derived_key( &attributes, &generator, + PSA_CHECK( psa_key_derivation_output_key( &attributes, &generator, wrapping_key_handle ) ); exit: - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); if( status != PSA_SUCCESS ) { psa_close_key( *wrapping_key_handle ); diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index 8b5773733..ab74bafb3 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -525,7 +525,7 @@ static int exercise_key_derivation_key( psa_key_handle_t handle, psa_key_usage_t usage, psa_algorithm_t alg ) { - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; unsigned char label[16] = "This is a label."; size_t label_length = sizeof( label ); unsigned char seed[16] = "abcdefghijklmnop"; @@ -558,10 +558,10 @@ static int exercise_key_derivation_key( psa_key_handle_t handle, seed, seed_length, sizeof( output ) ) ); } - PSA_ASSERT( psa_generator_read( &generator, + PSA_ASSERT( psa_key_derivation_output_bytes( &generator, output, sizeof( output ) ) ); - PSA_ASSERT( psa_generator_abort( &generator ) ); + PSA_ASSERT( psa_key_derivation_abort( &generator ) ); } return( 1 ); @@ -572,7 +572,7 @@ exit: /* We need two keys to exercise key agreement. Exercise the * private key against its own public key. */ -static psa_status_t key_agreement_with_self( psa_crypto_generator_t *generator, +static psa_status_t key_agreement_with_self( psa_key_derivation_operation_t *generator, psa_key_handle_t handle ) { psa_key_type_t private_key_type; @@ -581,7 +581,7 @@ static psa_status_t key_agreement_with_self( psa_crypto_generator_t *generator, uint8_t *public_key = NULL; size_t public_key_length; /* Return GENERIC_ERROR if something other than the final call to - * psa_key_agreement fails. This isn't fully satisfactory, but it's + * psa_key_derivation_key_agreement fails. This isn't fully satisfactory, but it's * good enough: callers will report it as a failed test anyway. */ psa_status_t status = PSA_ERROR_GENERIC_ERROR; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; @@ -596,7 +596,7 @@ static psa_status_t key_agreement_with_self( psa_crypto_generator_t *generator, public_key, public_key_length, &public_key_length ) ); - status = psa_key_agreement( generator, PSA_KDF_STEP_SECRET, handle, + status = psa_key_derivation_key_agreement( generator, PSA_KDF_STEP_SECRET, handle, public_key, public_key_length ); exit: mbedtls_free( public_key ); @@ -617,7 +617,7 @@ static psa_status_t raw_key_agreement_with_self( psa_algorithm_t alg, uint8_t output[1024]; size_t output_length; /* Return GENERIC_ERROR if something other than the final call to - * psa_key_agreement fails. This isn't fully satisfactory, but it's + * psa_key_derivation_key_agreement fails. This isn't fully satisfactory, but it's * good enough: callers will report it as a failed test anyway. */ psa_status_t status = PSA_ERROR_GENERIC_ERROR; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; @@ -664,7 +664,7 @@ static int exercise_key_agreement_key( psa_key_handle_t handle, psa_key_usage_t usage, psa_algorithm_t alg ) { - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; unsigned char output[1]; int ok = 0; @@ -674,10 +674,10 @@ static int exercise_key_agreement_key( psa_key_handle_t handle, * private key against its own public key. */ PSA_ASSERT( psa_key_derivation_setup( &generator, alg ) ); PSA_ASSERT( key_agreement_with_self( &generator, handle ) ); - PSA_ASSERT( psa_generator_read( &generator, + PSA_ASSERT( psa_key_derivation_output_bytes( &generator, output, sizeof( output ) ) ); - PSA_ASSERT( psa_generator_abort( &generator ) ); + PSA_ASSERT( psa_key_derivation_abort( &generator ) ); } ok = 1; @@ -1844,7 +1844,7 @@ void derive_key_policy( int policy_usage, { psa_key_handle_t handle = 0; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; psa_status_t status; PSA_ASSERT( psa_crypto_init( ) ); @@ -1868,7 +1868,7 @@ void derive_key_policy( int policy_usage, TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED ); exit: - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); psa_destroy_key( handle ); mbedtls_psa_crypto_free( ); } @@ -1884,7 +1884,7 @@ void agreement_key_policy( int policy_usage, psa_key_handle_t handle = 0; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_key_type_t key_type = key_type_arg; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; psa_status_t status; PSA_ASSERT( psa_crypto_init( ) ); @@ -1906,7 +1906,7 @@ void agreement_key_policy( int policy_usage, TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED ); exit: - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); psa_destroy_key( handle ); mbedtls_psa_crypto_free( ); } @@ -1922,7 +1922,7 @@ void raw_agreement_key_policy( int policy_usage, psa_key_handle_t handle = 0; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_key_type_t key_type = key_type_arg; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; psa_status_t status; PSA_ASSERT( psa_crypto_init( ) ); @@ -1943,7 +1943,7 @@ void raw_agreement_key_policy( int policy_usage, TEST_EQUAL( status, PSA_ERROR_NOT_PERMITTED ); exit: - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); psa_destroy_key( handle ); mbedtls_psa_crypto_free( ); } @@ -4003,24 +4003,24 @@ void crypto_generator_init( ) * though it's OK by the C standard. We could test for this, but we'd need * to supress the Clang warning for the test. */ size_t capacity; - psa_crypto_generator_t func = psa_crypto_generator_init( ); - psa_crypto_generator_t init = PSA_CRYPTO_GENERATOR_INIT; - psa_crypto_generator_t zero; + psa_key_derivation_operation_t func = psa_key_derivation_operation_init( ); + psa_key_derivation_operation_t init = PSA_KEY_DERIVATION_OPERATION_INIT; + psa_key_derivation_operation_t zero; memset( &zero, 0, sizeof( zero ) ); /* A default generator should not be able to report its capacity. */ - TEST_EQUAL( psa_get_generator_capacity( &func, &capacity ), + TEST_EQUAL( psa_key_derivation_get_capacity( &func, &capacity ), PSA_ERROR_BAD_STATE ); - TEST_EQUAL( psa_get_generator_capacity( &init, &capacity ), + TEST_EQUAL( psa_key_derivation_get_capacity( &init, &capacity ), PSA_ERROR_BAD_STATE ); - TEST_EQUAL( psa_get_generator_capacity( &zero, &capacity ), + TEST_EQUAL( psa_key_derivation_get_capacity( &zero, &capacity ), PSA_ERROR_BAD_STATE ); /* A default generator should be abortable without error. */ - PSA_ASSERT( psa_generator_abort(&func) ); - PSA_ASSERT( psa_generator_abort(&init) ); - PSA_ASSERT( psa_generator_abort(&zero) ); + PSA_ASSERT( psa_key_derivation_abort(&func) ); + PSA_ASSERT( psa_key_derivation_abort(&init) ); + PSA_ASSERT( psa_key_derivation_abort(&zero) ); } /* END_CASE */ @@ -4038,7 +4038,7 @@ void derive_setup( int key_type_arg, psa_algorithm_t alg = alg_arg; size_t requested_capacity = requested_capacity_arg; psa_status_t expected_status = expected_status_arg; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; PSA_ASSERT( psa_crypto_init( ) ); @@ -4057,7 +4057,7 @@ void derive_setup( int key_type_arg, expected_status ); exit: - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); psa_destroy_key( handle ); mbedtls_psa_crypto_free( ); } @@ -4068,7 +4068,7 @@ void test_derive_invalid_generator_state( ) { psa_key_handle_t handle = 0; size_t key_type = PSA_KEY_TYPE_DERIVE; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; psa_algorithm_t alg = PSA_ALG_HKDF( PSA_ALG_SHA_256 ); uint8_t buffer[42]; size_t capacity = sizeof( buffer ); @@ -4100,13 +4100,13 @@ void test_derive_invalid_generator_state( ) capacity ), PSA_ERROR_BAD_STATE ); - PSA_ASSERT( psa_generator_read( &generator, buffer, capacity ) ); + PSA_ASSERT( psa_key_derivation_output_bytes( &generator, buffer, capacity ) ); - TEST_EQUAL( psa_generator_read( &generator, buffer, capacity ), + TEST_EQUAL( psa_key_derivation_output_bytes( &generator, buffer, capacity ), PSA_ERROR_INSUFFICIENT_DATA ); exit: - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); psa_destroy_key( handle ); mbedtls_psa_crypto_free( ); } @@ -4118,24 +4118,24 @@ void test_derive_invalid_generator_tests( ) uint8_t output_buffer[16]; size_t buffer_size = 16; size_t capacity = 0; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; - TEST_ASSERT( psa_generator_read( &generator, output_buffer, buffer_size ) + TEST_ASSERT( psa_key_derivation_output_bytes( &generator, output_buffer, buffer_size ) == PSA_ERROR_BAD_STATE ); - TEST_ASSERT( psa_get_generator_capacity( &generator, &capacity ) + TEST_ASSERT( psa_key_derivation_get_capacity( &generator, &capacity ) == PSA_ERROR_BAD_STATE ); - PSA_ASSERT( psa_generator_abort( &generator ) ); + PSA_ASSERT( psa_key_derivation_abort( &generator ) ); - TEST_ASSERT( psa_generator_read( &generator, output_buffer, buffer_size ) + TEST_ASSERT( psa_key_derivation_output_bytes( &generator, output_buffer, buffer_size ) == PSA_ERROR_BAD_STATE ); - TEST_ASSERT( psa_get_generator_capacity( &generator, &capacity ) + TEST_ASSERT( psa_key_derivation_get_capacity( &generator, &capacity ) == PSA_ERROR_BAD_STATE ); exit: - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); } /* END_CASE */ @@ -4151,7 +4151,7 @@ void derive_output( int alg_arg, psa_key_handle_t handle = 0; psa_algorithm_t alg = alg_arg; size_t requested_capacity = requested_capacity_arg; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; uint8_t *expected_outputs[2] = {expected_output1->x, expected_output2->x}; size_t output_sizes[2] = @@ -4185,7 +4185,7 @@ void derive_output( int alg_arg, if( PSA_ALG_IS_HKDF( alg ) ) { PSA_ASSERT( psa_key_derivation_setup( &generator, alg ) ); - PSA_ASSERT( psa_set_generator_capacity( &generator, + PSA_ASSERT( psa_key_derivation_set_capacity( &generator, requested_capacity ) ); PSA_ASSERT( psa_key_derivation_input_bytes( &generator, PSA_KDF_STEP_SALT, @@ -4205,7 +4205,7 @@ void derive_output( int alg_arg, label->x, label->len, requested_capacity ) ); } - PSA_ASSERT( psa_get_generator_capacity( &generator, + PSA_ASSERT( psa_key_derivation_get_capacity( &generator, ¤t_capacity ) ); TEST_EQUAL( current_capacity, requested_capacity ); expected_capacity = requested_capacity; @@ -4214,7 +4214,7 @@ void derive_output( int alg_arg, for( i = 0; i < ARRAY_LENGTH( expected_outputs ); i++ ) { /* Read some bytes. */ - status = psa_generator_read( &generator, + status = psa_key_derivation_output_bytes( &generator, output_buffer, output_sizes[i] ); if( expected_capacity == 0 && output_sizes[i] == 0 ) { @@ -4238,15 +4238,15 @@ void derive_output( int alg_arg, expected_outputs[i], output_sizes[i] ); /* Check the generator status. */ expected_capacity -= output_sizes[i]; - PSA_ASSERT( psa_get_generator_capacity( &generator, + PSA_ASSERT( psa_key_derivation_get_capacity( &generator, ¤t_capacity ) ); TEST_EQUAL( expected_capacity, current_capacity ); } - PSA_ASSERT( psa_generator_abort( &generator ) ); + PSA_ASSERT( psa_key_derivation_abort( &generator ) ); exit: mbedtls_free( output_buffer ); - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); psa_destroy_key( handle ); mbedtls_psa_crypto_free( ); } @@ -4262,7 +4262,7 @@ void derive_full( int alg_arg, psa_key_handle_t handle = 0; psa_algorithm_t alg = alg_arg; size_t requested_capacity = requested_capacity_arg; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; unsigned char output_buffer[16]; size_t expected_capacity = requested_capacity; size_t current_capacity; @@ -4281,7 +4281,7 @@ void derive_full( int alg_arg, if( PSA_ALG_IS_HKDF( alg ) ) { PSA_ASSERT( psa_key_derivation_setup( &generator, alg ) ); - PSA_ASSERT( psa_set_generator_capacity( &generator, + PSA_ASSERT( psa_key_derivation_set_capacity( &generator, requested_capacity ) ); PSA_ASSERT( psa_key_derivation_input_bytes( &generator, PSA_KDF_STEP_SALT, @@ -4301,7 +4301,7 @@ void derive_full( int alg_arg, label->x, label->len, requested_capacity ) ); } - PSA_ASSERT( psa_get_generator_capacity( &generator, + PSA_ASSERT( psa_key_derivation_get_capacity( &generator, ¤t_capacity ) ); TEST_EQUAL( current_capacity, expected_capacity ); @@ -4311,23 +4311,23 @@ void derive_full( int alg_arg, size_t read_size = sizeof( output_buffer ); if( read_size > current_capacity ) read_size = current_capacity; - PSA_ASSERT( psa_generator_read( &generator, + PSA_ASSERT( psa_key_derivation_output_bytes( &generator, output_buffer, read_size ) ); expected_capacity -= read_size; - PSA_ASSERT( psa_get_generator_capacity( &generator, + PSA_ASSERT( psa_key_derivation_get_capacity( &generator, ¤t_capacity ) ); TEST_EQUAL( current_capacity, expected_capacity ); } /* Check that the generator refuses to go over capacity. */ - TEST_EQUAL( psa_generator_read( &generator, output_buffer, 1 ), + TEST_EQUAL( psa_key_derivation_output_bytes( &generator, output_buffer, 1 ), PSA_ERROR_INSUFFICIENT_DATA ); - PSA_ASSERT( psa_generator_abort( &generator ) ); + PSA_ASSERT( psa_key_derivation_abort( &generator ) ); exit: - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); psa_destroy_key( handle ); mbedtls_psa_crypto_free( ); } @@ -4351,7 +4351,7 @@ void derive_key_exercise( int alg_arg, psa_key_usage_t derived_usage = derived_usage_arg; psa_algorithm_t derived_alg = derived_alg_arg; size_t capacity = PSA_BITS_TO_BYTES( derived_bits ); - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_key_attributes_t got_attributes = PSA_KEY_ATTRIBUTES_INIT; @@ -4372,7 +4372,7 @@ void derive_key_exercise( int alg_arg, psa_set_key_algorithm( &attributes, derived_alg ); psa_set_key_type( &attributes, derived_type ); psa_set_key_bits( &attributes, derived_bits ); - PSA_ASSERT( psa_generate_derived_key( &attributes, &generator, + PSA_ASSERT( psa_key_derivation_output_key( &attributes, &generator, &derived_handle ) ); /* Test the key information */ @@ -4385,7 +4385,7 @@ void derive_key_exercise( int alg_arg, goto exit; exit: - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); psa_reset_key_attributes( &got_attributes ); psa_destroy_key( base_handle ); psa_destroy_key( derived_handle ); @@ -4407,7 +4407,7 @@ void derive_key_export( int alg_arg, size_t bytes1 = bytes1_arg; size_t bytes2 = bytes2_arg; size_t capacity = bytes1 + bytes2; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; uint8_t *output_buffer = NULL; uint8_t *export_buffer = NULL; psa_key_attributes_t base_attributes = PSA_KEY_ATTRIBUTES_INIT; @@ -4429,10 +4429,10 @@ void derive_key_export( int alg_arg, salt->x, salt->len, label->x, label->len, capacity ) ); - PSA_ASSERT( psa_generator_read( &generator, + PSA_ASSERT( psa_key_derivation_output_bytes( &generator, output_buffer, capacity ) ); - PSA_ASSERT( psa_generator_abort( &generator ) ); + PSA_ASSERT( psa_key_derivation_abort( &generator ) ); /* Derive the same output again, but this time store it in key objects. */ PSA_ASSERT( psa_key_derivation( &generator, base_handle, alg, @@ -4443,7 +4443,7 @@ void derive_key_export( int alg_arg, psa_set_key_algorithm( &derived_attributes, 0 ); psa_set_key_type( &derived_attributes, PSA_KEY_TYPE_RAW_DATA ); psa_set_key_bits( &derived_attributes, PSA_BYTES_TO_BITS( bytes1 ) ); - PSA_ASSERT( psa_generate_derived_key( &derived_attributes, &generator, + PSA_ASSERT( psa_key_derivation_output_key( &derived_attributes, &generator, &derived_handle ) ); PSA_ASSERT( psa_export_key( derived_handle, export_buffer, bytes1, @@ -4451,7 +4451,7 @@ void derive_key_export( int alg_arg, TEST_EQUAL( length, bytes1 ); PSA_ASSERT( psa_destroy_key( derived_handle ) ); psa_set_key_bits( &derived_attributes, PSA_BYTES_TO_BITS( bytes2 ) ); - PSA_ASSERT( psa_generate_derived_key( &derived_attributes, &generator, + PSA_ASSERT( psa_key_derivation_output_key( &derived_attributes, &generator, &derived_handle ) ); PSA_ASSERT( psa_export_key( derived_handle, export_buffer + bytes1, bytes2, @@ -4465,7 +4465,7 @@ void derive_key_export( int alg_arg, exit: mbedtls_free( output_buffer ); mbedtls_free( export_buffer ); - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); psa_destroy_key( base_handle ); psa_destroy_key( derived_handle ); mbedtls_psa_crypto_free( ); @@ -4481,7 +4481,7 @@ void key_agreement_setup( int alg_arg, psa_key_handle_t our_key = 0; psa_algorithm_t alg = alg_arg; psa_key_type_t our_key_type = our_key_type_arg; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; psa_status_t expected_status = expected_status_arg; psa_status_t status; @@ -4502,7 +4502,7 @@ void key_agreement_setup( int alg_arg, status = psa_key_derivation_setup( &generator, alg ); if( status == PSA_SUCCESS ) { - TEST_EQUAL( psa_key_agreement( &generator, PSA_KDF_STEP_SECRET, + TEST_EQUAL( psa_key_derivation_key_agreement( &generator, PSA_KDF_STEP_SECRET, our_key, peer_key_data->x, peer_key_data->len ), expected_status ); @@ -4513,7 +4513,7 @@ void key_agreement_setup( int alg_arg, } exit: - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); psa_destroy_key( our_key ); mbedtls_psa_crypto_free( ); } @@ -4565,7 +4565,7 @@ void key_agreement_capacity( int alg_arg, psa_key_handle_t our_key = 0; psa_algorithm_t alg = alg_arg; psa_key_type_t our_key_type = our_key_type_arg; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; size_t actual_capacity; unsigned char output[16]; @@ -4580,7 +4580,7 @@ void key_agreement_capacity( int alg_arg, &our_key ) ); PSA_ASSERT( psa_key_derivation_setup( &generator, alg ) ); - PSA_ASSERT( psa_key_agreement( &generator, PSA_KDF_STEP_SECRET, + PSA_ASSERT( psa_key_derivation_key_agreement( &generator, PSA_KDF_STEP_SECRET, our_key, peer_key_data->x, peer_key_data->len ) ); if( PSA_ALG_IS_HKDF( PSA_ALG_KEY_AGREEMENT_GET_KDF( alg ) ) ) @@ -4592,24 +4592,24 @@ void key_agreement_capacity( int alg_arg, } /* Test the advertized capacity. */ - PSA_ASSERT( psa_get_generator_capacity( + PSA_ASSERT( psa_key_derivation_get_capacity( &generator, &actual_capacity ) ); TEST_EQUAL( actual_capacity, (size_t) expected_capacity_arg ); /* Test the actual capacity by reading the output. */ while( actual_capacity > sizeof( output ) ) { - PSA_ASSERT( psa_generator_read( &generator, + PSA_ASSERT( psa_key_derivation_output_bytes( &generator, output, sizeof( output ) ) ); actual_capacity -= sizeof( output ); } - PSA_ASSERT( psa_generator_read( &generator, + PSA_ASSERT( psa_key_derivation_output_bytes( &generator, output, actual_capacity ) ); - TEST_EQUAL( psa_generator_read( &generator, output, 1 ), + TEST_EQUAL( psa_key_derivation_output_bytes( &generator, output, 1 ), PSA_ERROR_INSUFFICIENT_DATA ); exit: - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); psa_destroy_key( our_key ); mbedtls_psa_crypto_free( ); } @@ -4624,7 +4624,7 @@ void key_agreement_output( int alg_arg, psa_key_handle_t our_key = 0; psa_algorithm_t alg = alg_arg; psa_key_type_t our_key_type = our_key_type_arg; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; uint8_t *actual_output = NULL; @@ -4641,7 +4641,7 @@ void key_agreement_output( int alg_arg, &our_key ) ); PSA_ASSERT( psa_key_derivation_setup( &generator, alg ) ); - PSA_ASSERT( psa_key_agreement( &generator, PSA_KDF_STEP_SECRET, + PSA_ASSERT( psa_key_derivation_key_agreement( &generator, PSA_KDF_STEP_SECRET, our_key, peer_key_data->x, peer_key_data->len ) ); if( PSA_ALG_IS_HKDF( PSA_ALG_KEY_AGREEMENT_GET_KDF( alg ) ) ) @@ -4652,14 +4652,14 @@ void key_agreement_output( int alg_arg, NULL, 0 ) ); } - PSA_ASSERT( psa_generator_read( &generator, + PSA_ASSERT( psa_key_derivation_output_bytes( &generator, actual_output, expected_output1->len ) ); ASSERT_COMPARE( actual_output, expected_output1->len, expected_output1->x, expected_output1->len ); if( expected_output2->len != 0 ) { - PSA_ASSERT( psa_generator_read( &generator, + PSA_ASSERT( psa_key_derivation_output_bytes( &generator, actual_output, expected_output2->len ) ); ASSERT_COMPARE( actual_output, expected_output2->len, @@ -4667,7 +4667,7 @@ void key_agreement_output( int alg_arg, } exit: - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); psa_destroy_key( our_key ); mbedtls_psa_crypto_free( ); mbedtls_free( actual_output ); @@ -4886,7 +4886,7 @@ void persistent_key_load_key_from_storage( data_t *data, size_t bits = bits_arg; psa_key_usage_t usage_flags = usage_flags_arg; psa_algorithm_t alg = alg_arg; - psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; + psa_key_derivation_operation_t generator = PSA_KEY_DERIVATION_OPERATION_INIT; unsigned char *first_export = NULL; unsigned char *second_export = NULL; size_t export_size = PSA_KEY_EXPORT_MAX_SIZE( type, bits ); @@ -4940,9 +4940,9 @@ void persistent_key_load_key_from_storage( data_t *data, PSA_ASSERT( psa_key_derivation_input_bytes( &generator, PSA_KDF_STEP_INFO, NULL, 0 ) ); - PSA_ASSERT( psa_generate_derived_key( &attributes, &generator, + PSA_ASSERT( psa_key_derivation_output_key( &attributes, &generator, &handle ) ); - PSA_ASSERT( psa_generator_abort( &generator ) ); + PSA_ASSERT( psa_key_derivation_abort( &generator ) ); PSA_ASSERT( psa_destroy_key( base_key ) ); base_key = 0; } @@ -4994,7 +4994,7 @@ exit: psa_reset_key_attributes( &attributes ); mbedtls_free( first_export ); mbedtls_free( second_export ); - psa_generator_abort( &generator ); + psa_key_derivation_abort( &generator ); psa_destroy_key( base_key ); if( handle == 0 ) {