mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
Merge pull request #157 from gilles-peskine-arm/psa-se_driver-create_key
Secure element key creation foundation
This commit is contained in:
@ -1715,12 +1715,15 @@
|
||||
* Enable secure element support in the Platform Security Architecture
|
||||
* cryptography API.
|
||||
*
|
||||
* \warning This feature is not yet suitable for production. It is provided
|
||||
* for API evaluation and testing purposes only.
|
||||
*
|
||||
* Module: library/psa_crypto_se.c
|
||||
*
|
||||
* Requires: MBEDTLS_PSA_CRYPTO_C, MBEDTLS_PSA_CRYPTO_STORAGE_C
|
||||
*
|
||||
*/
|
||||
#define MBEDTLS_PSA_CRYPTO_SE_C
|
||||
//#define MBEDTLS_PSA_CRYPTO_SE_C
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_PSA_CRYPTO_STORAGE_C
|
||||
|
@ -93,117 +93,10 @@ psa_status_t psa_crypto_init(void);
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** \defgroup attributes Key attributes
|
||||
/** \addtogroup attributes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** The type of a structure containing key attributes.
|
||||
*
|
||||
* This is an opaque structure that can represent the metadata of a key
|
||||
* object. Metadata that can be stored in attributes includes:
|
||||
* - The location of the key in storage, indicated by its key identifier
|
||||
* and its lifetime.
|
||||
* - The key's policy, comprising usage flags and a specification of
|
||||
* the permitted algorithm(s).
|
||||
* - Information about the key itself: the key type and its size.
|
||||
* - Implementations may define additional attributes.
|
||||
*
|
||||
* The actual key material is not considered an attribute of a key.
|
||||
* Key attributes do not contain information that is generally considered
|
||||
* highly confidential.
|
||||
*
|
||||
* An attribute structure can be a simple data structure where each function
|
||||
* `psa_set_key_xxx` sets a field and the corresponding function
|
||||
* `psa_get_key_xxx` retrieves the value of the corresponding field.
|
||||
* However, implementations may report values that are equivalent to the
|
||||
* original one, but have a different encoding. For example, an
|
||||
* implementation may use a more compact representation for types where
|
||||
* many bit-patterns are invalid or not supported, and store all values
|
||||
* that it does not support as a special marker value. In such an
|
||||
* implementation, after setting an invalid value, the corresponding
|
||||
* get function returns an invalid value which may not be the one that
|
||||
* was originally stored.
|
||||
*
|
||||
* An attribute structure may contain references to auxiliary resources,
|
||||
* for example pointers to allocated memory or indirect references to
|
||||
* pre-calculated values. In order to free such resources, the application
|
||||
* must call psa_reset_key_attributes(). As an exception, calling
|
||||
* psa_reset_key_attributes() on an attribute structure is optional if
|
||||
* the structure has only been modified by the following functions
|
||||
* since it was initialized or last reset with psa_reset_key_attributes():
|
||||
* - psa_set_key_id()
|
||||
* - psa_set_key_lifetime()
|
||||
* - psa_set_key_type()
|
||||
* - psa_set_key_bits()
|
||||
* - psa_set_key_usage_flags()
|
||||
* - psa_set_key_algorithm()
|
||||
*
|
||||
* Before calling any function on a key attribute structure, the application
|
||||
* must initialize it by any of the following means:
|
||||
* - Set the structure to all-bits-zero, for example:
|
||||
* \code
|
||||
* psa_key_attributes_t attributes;
|
||||
* memset(&attributes, 0, sizeof(attributes));
|
||||
* \endcode
|
||||
* - Initialize the structure to logical zero values, for example:
|
||||
* \code
|
||||
* psa_key_attributes_t attributes = {0};
|
||||
* \endcode
|
||||
* - Initialize the structure to the initializer #PSA_KEY_ATTRIBUTES_INIT,
|
||||
* for example:
|
||||
* \code
|
||||
* psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
* \endcode
|
||||
* - Assign the result of the function psa_key_attributes_init()
|
||||
* to the structure, for example:
|
||||
* \code
|
||||
* psa_key_attributes_t attributes;
|
||||
* attributes = psa_key_attributes_init();
|
||||
* \endcode
|
||||
*
|
||||
* A freshly initialized attribute structure contains the following
|
||||
* values:
|
||||
*
|
||||
* - lifetime: #PSA_KEY_LIFETIME_VOLATILE.
|
||||
* - key identifier: unspecified.
|
||||
* - type: \c 0.
|
||||
* - key size: \c 0.
|
||||
* - usage flags: \c 0.
|
||||
* - algorithm: \c 0.
|
||||
*
|
||||
* A typical sequence to create a key is as follows:
|
||||
* -# Create and initialize an attribute structure.
|
||||
* -# If the key is persistent, call psa_set_key_id().
|
||||
* Also call psa_set_key_lifetime() to place the key in a non-default
|
||||
* location.
|
||||
* -# Set the key policy with psa_set_key_usage_flags() and
|
||||
* 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_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_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.
|
||||
* -# The attribute structure is now no longer necessary.
|
||||
* You may call psa_reset_key_attributes(), although this is optional
|
||||
* with the workflow presented here because the attributes currently
|
||||
* defined in this specification do not require any additional resources
|
||||
* beyond the structure itself.
|
||||
*
|
||||
* A typical sequence to query a key's attributes is as follows:
|
||||
* -# Call psa_get_key_attributes().
|
||||
* -# Call `psa_get_key_xxx` functions to retrieve the attribute(s) that
|
||||
* you are interested in.
|
||||
* -# Call psa_reset_key_attributes() to free any resources that may be
|
||||
* used by the attribute structure.
|
||||
*
|
||||
* Once a key has been created, it is impossible to change its attributes.
|
||||
*/
|
||||
typedef struct psa_key_attributes_s psa_key_attributes_t;
|
||||
|
||||
/** \def PSA_KEY_ATTRIBUTES_INIT
|
||||
*
|
||||
* This macro returns a suitable initializer for a key attribute structure
|
||||
|
@ -40,10 +40,106 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** \defgroup se_init Secure element driver initialization
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/** \brief Driver context structure
|
||||
*
|
||||
* Driver functions receive a pointer to this structure.
|
||||
* Each registered driver has one instance of this structure.
|
||||
*
|
||||
* Implementations must include the fields specified here and
|
||||
* may include other fields.
|
||||
*/
|
||||
typedef struct {
|
||||
/** A read-only pointer to the driver's persistent data.
|
||||
*
|
||||
* Drivers typically use this persistent data to keep track of
|
||||
* which slot numbers are available. This is only a guideline:
|
||||
* drivers may use the persistent data for any purpose, keeping
|
||||
* in mind the restrictions on when the persistent data is saved
|
||||
* to storage: the persistent data is only saved after calling
|
||||
* certain functions that receive a writable pointer to the
|
||||
* persistent data.
|
||||
*
|
||||
* The core allocates a memory buffer for the persistent data.
|
||||
* The pointer is guaranteed to be suitably aligned for any data type,
|
||||
* like a pointer returned by `malloc` (but the core can use any
|
||||
* method to allocate the buffer, not necessarily `malloc`).
|
||||
*
|
||||
* The size of this buffer is in the \c persistent_data_size field of
|
||||
* this structure.
|
||||
*
|
||||
* Before the driver is initialized for the first time, the content of
|
||||
* the persistent data is all-bits-zero. After a driver upgrade, if the
|
||||
* size of the persistent data has increased, the original data is padded
|
||||
* on the right with zeros; if the size has decreased, the original data
|
||||
* is truncated to the new size.
|
||||
*
|
||||
* This pointer is to read-only data. Only a few driver functions are
|
||||
* allowed to modify the persistent data. These functions receive a
|
||||
* writable pointer. These functions are:
|
||||
* - psa_drv_se_t::p_init
|
||||
* - psa_drv_se_key_management_t::p_allocate
|
||||
* - psa_drv_se_key_management_t::p_destroy
|
||||
*
|
||||
* The PSA Cryptography core saves the persistent data from one
|
||||
* session to the next. It does this before returning from API functions
|
||||
* that call a driver method that is allowed to modify the persistent
|
||||
* data, specifically:
|
||||
* - psa_crypto_init() causes a call to psa_drv_se_t::p_init, and may call
|
||||
* psa_drv_se_key_management_t::p_destroy to complete an action
|
||||
* that was interrupted by a power failure.
|
||||
* - Key creation functions cause a call to
|
||||
* psa_drv_se_key_management_t::p_allocate, and may cause a call to
|
||||
* psa_drv_se_key_management_t::p_destroy in case an error occurs.
|
||||
* - psa_destroy_key() causes a call to
|
||||
* psa_drv_se_key_management_t::p_destroy.
|
||||
*/
|
||||
const void *const persistent_data;
|
||||
|
||||
/** The size of \c persistent_data in bytes.
|
||||
*
|
||||
* This is always equal to the value of the `persistent_data_size` field
|
||||
* of the ::psa_drv_se_t structure when the driver is registered.
|
||||
*/
|
||||
const size_t persistent_data_size;
|
||||
|
||||
/** Driver transient data.
|
||||
*
|
||||
* The core initializes this value to 0 and does not read or modify it
|
||||
* afterwards. The driver may store whatever it wants in this field.
|
||||
*/
|
||||
uintptr_t transient_data;
|
||||
} psa_drv_se_context_t;
|
||||
|
||||
/** \brief A driver initialization function.
|
||||
*
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in,out] persistent_data A pointer to the persistent data
|
||||
* that allows writing.
|
||||
* \param lifetime The lifetime value for which this driver
|
||||
* is registered.
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* The driver is operational.
|
||||
* The core will update the persistent data in storage.
|
||||
* \return
|
||||
* Any other return value prevents the driver from being used in
|
||||
* this session.
|
||||
* The core will NOT update the persistent data in storage.
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_init_t)(psa_drv_se_context_t *drv_context,
|
||||
void *persistent_data,
|
||||
psa_key_lifetime_t lifetime);
|
||||
|
||||
/** An internal designation of a key slot between the core part of the
|
||||
* PSA Crypto implementation and the driver. The meaning of this value
|
||||
* is driver-dependent. */
|
||||
typedef uint32_t psa_key_slot_number_t; // Change this to psa_key_slot_t after psa_key_slot_t is removed from Mbed crypto
|
||||
typedef uint64_t psa_key_slot_number_t;
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** \defgroup se_mac Secure Element Message Authentication Codes
|
||||
* Generation and authentication of Message Authentication Codes (MACs) using
|
||||
@ -65,7 +161,8 @@ typedef uint32_t psa_key_slot_number_t; // Change this to psa_key_slot_t after p
|
||||
/** \brief A function that starts a secure element MAC operation for a PSA
|
||||
* Crypto Driver implementation
|
||||
*
|
||||
* \param[in,out] p_context A structure that will contain the
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in,out] op_context A structure that will contain the
|
||||
* hardware-specific MAC context
|
||||
* \param[in] key_slot The slot of the key to be used for the
|
||||
* operation
|
||||
@ -75,28 +172,29 @@ typedef uint32_t psa_key_slot_number_t; // Change this to psa_key_slot_t after p
|
||||
* \retval PSA_SUCCESS
|
||||
* Success.
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_mac_setup_t)(void *p_context,
|
||||
typedef psa_status_t (*psa_drv_se_mac_setup_t)(psa_drv_se_context_t *drv_context,
|
||||
void *op_context,
|
||||
psa_key_slot_number_t key_slot,
|
||||
psa_algorithm_t algorithm);
|
||||
|
||||
/** \brief A function that continues a previously started secure element MAC
|
||||
* operation
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the
|
||||
* \param[in,out] op_context A hardware-specific structure for the
|
||||
* previously-established MAC operation to be
|
||||
* updated
|
||||
* \param[in] p_input A buffer containing the message to be appended
|
||||
* to the MAC operation
|
||||
* \param[in] input_length The size in bytes of the input message buffer
|
||||
* \param[in] input_length The size in bytes of the input message buffer
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_mac_update_t)(void *p_context,
|
||||
typedef psa_status_t (*psa_drv_se_mac_update_t)(void *op_context,
|
||||
const uint8_t *p_input,
|
||||
size_t input_length);
|
||||
|
||||
/** \brief a function that completes a previously started secure element MAC
|
||||
* operation by returning the resulting MAC.
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the
|
||||
* \param[in,out] op_context A hardware-specific structure for the
|
||||
* previously started MAC operation to be
|
||||
* finished
|
||||
* \param[out] p_mac A buffer where the generated MAC will be
|
||||
@ -109,7 +207,7 @@ typedef psa_status_t (*psa_drv_se_mac_update_t)(void *p_context,
|
||||
* \retval PSA_SUCCESS
|
||||
* Success.
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_mac_finish_t)(void *p_context,
|
||||
typedef psa_status_t (*psa_drv_se_mac_finish_t)(void *op_context,
|
||||
uint8_t *p_mac,
|
||||
size_t mac_size,
|
||||
size_t *p_mac_length);
|
||||
@ -117,11 +215,11 @@ typedef psa_status_t (*psa_drv_se_mac_finish_t)(void *p_context,
|
||||
/** \brief A function that completes a previously started secure element MAC
|
||||
* operation by comparing the resulting MAC against a provided value
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the previously
|
||||
* started MAC operation to be fiinished
|
||||
* \param[in] p_mac The MAC value against which the resulting MAC will
|
||||
* be compared against
|
||||
* \param[in] mac_length The size in bytes of the value stored in `p_mac`
|
||||
* \param[in,out] op_context A hardware-specific structure for the previously
|
||||
* started MAC operation to be fiinished
|
||||
* \param[in] p_mac The MAC value against which the resulting MAC
|
||||
* will be compared against
|
||||
* \param[in] mac_length The size in bytes of the value stored in `p_mac`
|
||||
*
|
||||
* \retval PSA_SUCCESS
|
||||
* The operation completed successfully and the MACs matched each
|
||||
@ -130,21 +228,22 @@ typedef psa_status_t (*psa_drv_se_mac_finish_t)(void *p_context,
|
||||
* The operation completed successfully, but the calculated MAC did
|
||||
* not match the provided MAC
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_mac_finish_verify_t)(void *p_context,
|
||||
typedef psa_status_t (*psa_drv_se_mac_finish_verify_t)(void *op_context,
|
||||
const uint8_t *p_mac,
|
||||
size_t mac_length);
|
||||
|
||||
/** \brief A function that aborts a previous started secure element MAC
|
||||
* operation
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the previously
|
||||
* started MAC operation to be aborted
|
||||
* \param[in,out] op_context A hardware-specific structure for the previously
|
||||
* started MAC operation to be aborted
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_mac_abort_t)(void *p_context);
|
||||
typedef psa_status_t (*psa_drv_se_mac_abort_t)(void *op_context);
|
||||
|
||||
/** \brief A function that performs a secure element MAC operation in one
|
||||
* command and returns the calculated MAC
|
||||
*
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in] p_input A buffer containing the message to be MACed
|
||||
* \param[in] input_length The size in bytes of `p_input`
|
||||
* \param[in] key_slot The slot of the key to be used
|
||||
@ -159,7 +258,8 @@ typedef psa_status_t (*psa_drv_se_mac_abort_t)(void *p_context);
|
||||
* \retval PSA_SUCCESS
|
||||
* Success.
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_mac_generate_t)(const uint8_t *p_input,
|
||||
typedef psa_status_t (*psa_drv_se_mac_generate_t)(psa_drv_se_context_t *drv_context,
|
||||
const uint8_t *p_input,
|
||||
size_t input_length,
|
||||
psa_key_slot_number_t key_slot,
|
||||
psa_algorithm_t alg,
|
||||
@ -170,6 +270,7 @@ typedef psa_status_t (*psa_drv_se_mac_generate_t)(const uint8_t *p_input,
|
||||
/** \brief A function that performs a secure element MAC operation in one
|
||||
* command and compares the resulting MAC against a provided value
|
||||
*
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in] p_input A buffer containing the message to be MACed
|
||||
* \param[in] input_length The size in bytes of `input`
|
||||
* \param[in] key_slot The slot of the key to be used
|
||||
@ -186,7 +287,8 @@ typedef psa_status_t (*psa_drv_se_mac_generate_t)(const uint8_t *p_input,
|
||||
* The operation completed successfully, but the calculated MAC did
|
||||
* not match the provided MAC
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_mac_verify_t)(const uint8_t *p_input,
|
||||
typedef psa_status_t (*psa_drv_se_mac_verify_t)(psa_drv_se_context_t *drv_context,
|
||||
const uint8_t *p_input,
|
||||
size_t input_length,
|
||||
psa_key_slot_number_t key_slot,
|
||||
psa_algorithm_t alg,
|
||||
@ -263,7 +365,8 @@ typedef struct {
|
||||
/** \brief A function that provides the cipher setup function for a
|
||||
* secure element driver
|
||||
*
|
||||
* \param[in,out] p_context A structure that will contain the
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in,out] op_context A structure that will contain the
|
||||
* hardware-specific cipher context.
|
||||
* \param[in] key_slot The slot of the key to be used for the
|
||||
* operation
|
||||
@ -275,7 +378,8 @@ typedef struct {
|
||||
* \retval PSA_SUCCESS
|
||||
* \retval PSA_ERROR_NOT_SUPPORTED
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_cipher_setup_t)(void *p_context,
|
||||
typedef psa_status_t (*psa_drv_se_cipher_setup_t)(psa_drv_se_context_t *drv_context,
|
||||
void *op_context,
|
||||
psa_key_slot_number_t key_slot,
|
||||
psa_algorithm_t algorithm,
|
||||
psa_encrypt_or_decrypt_t direction);
|
||||
@ -288,21 +392,21 @@ typedef psa_status_t (*psa_drv_se_cipher_setup_t)(void *p_context,
|
||||
* generate function is not necessary for the drivers to implement as the PSA
|
||||
* Crypto implementation can do the generation using its RNG features.
|
||||
*
|
||||
* \param[in,out] p_context A structure that contains the previously set up
|
||||
* \param[in,out] op_context A structure that contains the previously set up
|
||||
* hardware-specific cipher context
|
||||
* \param[in] p_iv A buffer containing the initialization vector
|
||||
* \param[in] iv_length The size (in bytes) of the `p_iv` buffer
|
||||
*
|
||||
* \retval PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_cipher_set_iv_t)(void *p_context,
|
||||
typedef psa_status_t (*psa_drv_se_cipher_set_iv_t)(void *op_context,
|
||||
const uint8_t *p_iv,
|
||||
size_t iv_length);
|
||||
|
||||
/** \brief A function that continues a previously started secure element cipher
|
||||
* operation
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the
|
||||
* \param[in,out] op_context A hardware-specific structure for the
|
||||
* previously started cipher operation
|
||||
* \param[in] p_input A buffer containing the data to be
|
||||
* encrypted/decrypted
|
||||
@ -317,7 +421,7 @@ typedef psa_status_t (*psa_drv_se_cipher_set_iv_t)(void *p_context,
|
||||
*
|
||||
* \retval PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_cipher_update_t)(void *p_context,
|
||||
typedef psa_status_t (*psa_drv_se_cipher_update_t)(void *op_context,
|
||||
const uint8_t *p_input,
|
||||
size_t input_size,
|
||||
uint8_t *p_output,
|
||||
@ -327,7 +431,7 @@ typedef psa_status_t (*psa_drv_se_cipher_update_t)(void *p_context,
|
||||
/** \brief A function that completes a previously started secure element cipher
|
||||
* operation
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the
|
||||
* \param[in,out] op_context A hardware-specific structure for the
|
||||
* previously started cipher operation
|
||||
* \param[out] p_output The caller-allocated buffer where the output
|
||||
* will be placed
|
||||
@ -338,7 +442,7 @@ typedef psa_status_t (*psa_drv_se_cipher_update_t)(void *p_context,
|
||||
*
|
||||
* \retval PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_cipher_finish_t)(void *p_context,
|
||||
typedef psa_status_t (*psa_drv_se_cipher_finish_t)(void *op_context,
|
||||
uint8_t *p_output,
|
||||
size_t output_size,
|
||||
size_t *p_output_length);
|
||||
@ -346,10 +450,10 @@ typedef psa_status_t (*psa_drv_se_cipher_finish_t)(void *p_context,
|
||||
/** \brief A function that aborts a previously started secure element cipher
|
||||
* operation
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure for the
|
||||
* \param[in,out] op_context A hardware-specific structure for the
|
||||
* previously started cipher operation
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_cipher_abort_t)(void *p_context);
|
||||
typedef psa_status_t (*psa_drv_se_cipher_abort_t)(void *op_context);
|
||||
|
||||
/** \brief A function that performs the ECB block mode for secure element
|
||||
* cipher operations
|
||||
@ -357,23 +461,25 @@ typedef psa_status_t (*psa_drv_se_cipher_abort_t)(void *p_context);
|
||||
* Note: this function should only be used with implementations that do not
|
||||
* provide a needed higher-level operation.
|
||||
*
|
||||
* \param[in] key_slot The slot of the key to be used for the operation
|
||||
* \param[in] algorithm The algorithm to be used in the cipher operation
|
||||
* \param[in] direction Indicates whether the operation is an encrypt or
|
||||
* decrypt
|
||||
* \param[in] p_input A buffer containing the data to be
|
||||
* encrypted/decrypted
|
||||
* \param[in] input_size The size in bytes of the buffer pointed to by
|
||||
* `p_input`
|
||||
* \param[out] p_output The caller-allocated buffer where the output will
|
||||
* be placed
|
||||
* \param[in] output_size The allocated size in bytes of the `p_output`
|
||||
* buffer
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in] key_slot The slot of the key to be used for the operation
|
||||
* \param[in] algorithm The algorithm to be used in the cipher operation
|
||||
* \param[in] direction Indicates whether the operation is an encrypt or
|
||||
* decrypt
|
||||
* \param[in] p_input A buffer containing the data to be
|
||||
* encrypted/decrypted
|
||||
* \param[in] input_size The size in bytes of the buffer pointed to by
|
||||
* `p_input`
|
||||
* \param[out] p_output The caller-allocated buffer where the output
|
||||
* will be placed
|
||||
* \param[in] output_size The allocated size in bytes of the `p_output`
|
||||
* buffer
|
||||
*
|
||||
* \retval PSA_SUCCESS
|
||||
* \retval PSA_ERROR_NOT_SUPPORTED
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_cipher_ecb_t)(psa_key_slot_number_t key_slot,
|
||||
typedef psa_status_t (*psa_drv_se_cipher_ecb_t)(psa_drv_se_context_t *drv_context,
|
||||
psa_key_slot_number_t key_slot,
|
||||
psa_algorithm_t algorithm,
|
||||
psa_encrypt_or_decrypt_t direction,
|
||||
const uint8_t *p_input,
|
||||
@ -427,6 +533,7 @@ typedef struct {
|
||||
* \brief A function that signs a hash or short message with a private key in
|
||||
* a secure element
|
||||
*
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in] key_slot Key slot of an asymmetric key pair
|
||||
* \param[in] alg A signature algorithm that is compatible
|
||||
* with the type of `key`
|
||||
@ -439,7 +546,8 @@ typedef struct {
|
||||
*
|
||||
* \retval PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_asymmetric_sign_t)(psa_key_slot_number_t key_slot,
|
||||
typedef psa_status_t (*psa_drv_se_asymmetric_sign_t)(psa_drv_se_context_t *drv_context,
|
||||
psa_key_slot_number_t key_slot,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *p_hash,
|
||||
size_t hash_length,
|
||||
@ -451,6 +559,7 @@ typedef psa_status_t (*psa_drv_se_asymmetric_sign_t)(psa_key_slot_number_t key_s
|
||||
* \brief A function that verifies the signature a hash or short message using
|
||||
* an asymmetric public key in a secure element
|
||||
*
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in] key_slot Key slot of a public key or an asymmetric key
|
||||
* pair
|
||||
* \param[in] alg A signature algorithm that is compatible with
|
||||
@ -463,7 +572,8 @@ typedef psa_status_t (*psa_drv_se_asymmetric_sign_t)(psa_key_slot_number_t key_s
|
||||
* \retval PSA_SUCCESS
|
||||
* The signature is valid.
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_asymmetric_verify_t)(psa_key_slot_number_t key_slot,
|
||||
typedef psa_status_t (*psa_drv_se_asymmetric_verify_t)(psa_drv_se_context_t *drv_context,
|
||||
psa_key_slot_number_t key_slot,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *p_hash,
|
||||
size_t hash_length,
|
||||
@ -474,6 +584,7 @@ typedef psa_status_t (*psa_drv_se_asymmetric_verify_t)(psa_key_slot_number_t key
|
||||
* \brief A function that encrypts a short message with an asymmetric public
|
||||
* key in a secure element
|
||||
*
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in] key_slot Key slot of a public key or an asymmetric key
|
||||
* pair
|
||||
* \param[in] alg An asymmetric encryption algorithm that is
|
||||
@ -499,7 +610,8 @@ typedef psa_status_t (*psa_drv_se_asymmetric_verify_t)(psa_key_slot_number_t key
|
||||
*
|
||||
* \retval PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_asymmetric_encrypt_t)(psa_key_slot_number_t key_slot,
|
||||
typedef psa_status_t (*psa_drv_se_asymmetric_encrypt_t)(psa_drv_se_context_t *drv_context,
|
||||
psa_key_slot_number_t key_slot,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *p_input,
|
||||
size_t input_length,
|
||||
@ -513,6 +625,7 @@ typedef psa_status_t (*psa_drv_se_asymmetric_encrypt_t)(psa_key_slot_number_t ke
|
||||
* \brief A function that decrypts a short message with an asymmetric private
|
||||
* key in a secure element.
|
||||
*
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in] key_slot Key slot of an asymmetric key pair
|
||||
* \param[in] alg An asymmetric encryption algorithm that is
|
||||
* compatible with the type of `key`
|
||||
@ -537,7 +650,8 @@ typedef psa_status_t (*psa_drv_se_asymmetric_encrypt_t)(psa_key_slot_number_t ke
|
||||
*
|
||||
* \retval PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_asymmetric_decrypt_t)(psa_key_slot_number_t key_slot,
|
||||
typedef psa_status_t (*psa_drv_se_asymmetric_decrypt_t)(psa_drv_se_context_t *drv_context,
|
||||
psa_key_slot_number_t key_slot,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *p_input,
|
||||
size_t input_length,
|
||||
@ -581,6 +695,7 @@ typedef struct {
|
||||
/** \brief A function that performs a secure element authenticated encryption
|
||||
* operation
|
||||
*
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in] key_slot Slot containing the key to use.
|
||||
* \param[in] algorithm The AEAD algorithm to compute
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
@ -608,7 +723,8 @@ typedef struct {
|
||||
* \retval #PSA_SUCCESS
|
||||
* Success.
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_aead_encrypt_t)(psa_key_slot_number_t key_slot,
|
||||
typedef psa_status_t (*psa_drv_se_aead_encrypt_t)(psa_drv_se_context_t *drv_context,
|
||||
psa_key_slot_number_t key_slot,
|
||||
psa_algorithm_t algorithm,
|
||||
const uint8_t *p_nonce,
|
||||
size_t nonce_length,
|
||||
@ -622,6 +738,7 @@ typedef psa_status_t (*psa_drv_se_aead_encrypt_t)(psa_key_slot_number_t key_slot
|
||||
|
||||
/** A function that peforms a secure element authenticated decryption operation
|
||||
*
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in] key_slot Slot containing the key to use
|
||||
* \param[in] algorithm The AEAD algorithm to compute
|
||||
* (\c PSA_ALG_XXX value such that
|
||||
@ -648,7 +765,8 @@ typedef psa_status_t (*psa_drv_se_aead_encrypt_t)(psa_key_slot_number_t key_slot
|
||||
* \retval #PSA_SUCCESS
|
||||
* Success.
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_aead_decrypt_t)(psa_key_slot_number_t key_slot,
|
||||
typedef psa_status_t (*psa_drv_se_aead_decrypt_t)(psa_drv_se_context_t *drv_context,
|
||||
psa_key_slot_number_t key_slot,
|
||||
psa_algorithm_t algorithm,
|
||||
const uint8_t *p_nonce,
|
||||
size_t nonce_length,
|
||||
@ -685,25 +803,50 @@ typedef struct {
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/** \brief A function that allocates a slot for a key.
|
||||
*
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in,out] persistent_data A pointer to the persistent data
|
||||
* that allows writing.
|
||||
* \param[in] attributes Attributes of the key.
|
||||
* \param[out] key_slot Slot where the key will be stored.
|
||||
* This must be a valid slot for a key of the
|
||||
* chosen type. It must be unoccupied.
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* Success.
|
||||
* The core will record \c *key_slot as the key slot where the key
|
||||
* is stored and will update the persistent data in storage.
|
||||
* \retval #PSA_ERROR_NOT_SUPPORTED
|
||||
* \retval #PSA_ERROR_INSUFFICIENT_STORAGE
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_allocate_key_t)(
|
||||
psa_drv_se_context_t *drv_context,
|
||||
void *persistent_data,
|
||||
const psa_key_attributes_t *attributes,
|
||||
psa_key_slot_number_t *key_slot);
|
||||
|
||||
/** \brief A function that imports a key into a secure element in binary format
|
||||
*
|
||||
* This function can support any output from psa_export_key(). Refer to the
|
||||
* documentation of psa_export_key() for the format for each key type.
|
||||
*
|
||||
* \param[in] key_slot Slot where the key will be stored
|
||||
* This must be a valid slot for a key of the chosen
|
||||
* type. It must be unoccupied.
|
||||
* \param[in] lifetime The required lifetime of the key storage
|
||||
* \param[in] type Key type (a \c PSA_KEY_TYPE_XXX value)
|
||||
* \param[in] algorithm Key algorithm (a \c PSA_ALG_XXX value)
|
||||
* \param[in] usage The allowed uses of the key
|
||||
* \param[in] p_data Buffer containing the key data
|
||||
* \param[in] data_length Size of the `data` buffer in bytes
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in] key_slot Slot where the key will be stored
|
||||
* This must be a valid slot for a key of the chosen
|
||||
* type. It must be unoccupied.
|
||||
* \param[in] lifetime The required lifetime of the key storage
|
||||
* \param[in] type Key type (a \c PSA_KEY_TYPE_XXX value)
|
||||
* \param[in] algorithm Key algorithm (a \c PSA_ALG_XXX value)
|
||||
* \param[in] usage The allowed uses of the key
|
||||
* \param[in] p_data Buffer containing the key data
|
||||
* \param[in] data_length Size of the `data` buffer in bytes
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* Success.
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_import_key_t)(psa_key_slot_number_t key_slot,
|
||||
typedef psa_status_t (*psa_drv_se_import_key_t)(psa_drv_se_context_t *drv_context,
|
||||
psa_key_slot_number_t key_slot,
|
||||
psa_key_lifetime_t lifetime,
|
||||
psa_key_type_t type,
|
||||
psa_algorithm_t algorithm,
|
||||
@ -721,12 +864,18 @@ typedef psa_status_t (*psa_drv_se_import_key_t)(psa_key_slot_number_t key_slot,
|
||||
*
|
||||
* This function returns the specified slot to its default state.
|
||||
*
|
||||
* \param[in] key_slot The key slot to erase.
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in,out] persistent_data A pointer to the persistent data
|
||||
* that allows writing.
|
||||
* \param key_slot The key slot to erase.
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* The slot's content, if any, has been erased.
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_destroy_key_t)(psa_key_slot_number_t key_slot);
|
||||
typedef psa_status_t (*psa_drv_se_destroy_key_t)(
|
||||
psa_drv_se_context_t *drv_context,
|
||||
void *persistent_data,
|
||||
psa_key_slot_number_t key_slot);
|
||||
|
||||
/**
|
||||
* \brief A function that exports a secure element key in binary format
|
||||
@ -743,6 +892,7 @@ typedef psa_status_t (*psa_drv_se_destroy_key_t)(psa_key_slot_number_t key_slot)
|
||||
* `psa_export_key()` does. Refer to the
|
||||
* documentation of `psa_export_key()` for the format for each key type.
|
||||
*
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in] key Slot whose content is to be exported. This must
|
||||
* be an occupied key slot.
|
||||
* \param[out] p_data Buffer where the key data is to be written.
|
||||
@ -758,7 +908,8 @@ typedef psa_status_t (*psa_drv_se_destroy_key_t)(psa_key_slot_number_t key_slot)
|
||||
* \retval #PSA_ERROR_HARDWARE_FAILURE
|
||||
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_export_key_t)(psa_key_slot_number_t key,
|
||||
typedef psa_status_t (*psa_drv_se_export_key_t)(psa_drv_se_context_t *drv_context,
|
||||
psa_key_slot_number_t key,
|
||||
uint8_t *p_data,
|
||||
size_t data_size,
|
||||
size_t *p_data_length);
|
||||
@ -767,31 +918,34 @@ typedef psa_status_t (*psa_drv_se_export_key_t)(psa_key_slot_number_t key,
|
||||
* \brief A function that generates a symmetric or asymmetric key on a secure
|
||||
* element
|
||||
*
|
||||
* If \p type is asymmetric (`#PSA_KEY_TYPE_IS_ASYMMETRIC(\p type) == 1`),
|
||||
* If \p type is asymmetric (#PSA_KEY_TYPE_IS_ASYMMETRIC(\p type) = 1),
|
||||
* the public component of the generated key will be placed in `p_pubkey_out`.
|
||||
* The format of the public key information will match the format specified for
|
||||
* the psa_export_key() function for the key type.
|
||||
*
|
||||
* \param[in] key_slot Slot where the generated key will be placed
|
||||
* \param[in] type The type of the key to be generated
|
||||
* \param[in] usage The prescribed usage of the generated key
|
||||
* Note: Not all Secure Elements support the same
|
||||
* restrictions that PSA Crypto does (and vice versa).
|
||||
* Driver developers should endeavor to match the
|
||||
* usages as close as possible.
|
||||
* \param[in] bits The size in bits of the key to be generated.
|
||||
* \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_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
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in] key_slot Slot where the generated key will be placed
|
||||
* \param[in] type The type of the key to be generated
|
||||
* \param[in] usage The prescribed usage of the generated key
|
||||
* Note: Not all Secure Elements support the same
|
||||
* restrictions that PSA Crypto does (and vice
|
||||
* versa).
|
||||
* Driver developers should endeavor to match the
|
||||
* usages as close as possible.
|
||||
* \param[in] bits The size in bits of the key to be generated.
|
||||
* \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_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
|
||||
* \param[in] pubkey_out_size The size in bytes of the `p_pubkey_out` buffer
|
||||
* \param[out] p_pubkey_length Upon successful completion, will contain the
|
||||
* size of the data placed in `p_pubkey_out`.
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_generate_key_t)(psa_key_slot_number_t key_slot,
|
||||
typedef psa_status_t (*psa_drv_se_generate_key_t)(psa_drv_se_context_t *drv_context,
|
||||
psa_key_slot_number_t key_slot,
|
||||
psa_key_type_t type,
|
||||
psa_key_usage_t usage,
|
||||
size_t bits,
|
||||
@ -811,6 +965,8 @@ typedef psa_status_t (*psa_drv_se_generate_key_t)(psa_key_slot_number_t key_slot
|
||||
* If one of the functions is not implemented, it should be set to NULL.
|
||||
*/
|
||||
typedef struct {
|
||||
/** Function that allocates a slot. */
|
||||
psa_drv_se_allocate_key_t p_allocate;
|
||||
/** Function that performs a key import operation */
|
||||
psa_drv_se_import_key_t p_import;
|
||||
/** Function that performs a generation */
|
||||
@ -819,6 +975,8 @@ typedef struct {
|
||||
psa_drv_se_destroy_key_t p_destroy;
|
||||
/** Function that performs a key export operation */
|
||||
psa_drv_se_export_key_t p_export;
|
||||
/** Function that performs a public key export operation */
|
||||
psa_drv_se_export_key_t p_export_public;
|
||||
} psa_drv_se_key_management_t;
|
||||
|
||||
/**@}*/
|
||||
@ -875,15 +1033,17 @@ typedef struct {
|
||||
/** \brief A function that Sets up a secure element key derivation operation by
|
||||
* specifying the algorithm and the source key sot
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure containing any
|
||||
* context information for the implementation
|
||||
* \param[in] kdf_alg The algorithm to be used for the key derivation
|
||||
* \param[in] source_key The key to be used as the source material for the
|
||||
* key derivation
|
||||
* \param[in,out] drv_context The driver context structure.
|
||||
* \param[in,out] op_context A hardware-specific structure containing any
|
||||
* context information for the implementation
|
||||
* \param[in] kdf_alg The algorithm to be used for the key derivation
|
||||
* \param[in] source_key The key to be used as the source material for
|
||||
* the key derivation
|
||||
*
|
||||
* \retval PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_key_derivation_setup_t)(void *p_context,
|
||||
typedef psa_status_t (*psa_drv_se_key_derivation_setup_t)(psa_drv_se_context_t *drv_context,
|
||||
void *op_context,
|
||||
psa_algorithm_t kdf_alg,
|
||||
psa_key_slot_number_t source_key);
|
||||
|
||||
@ -894,7 +1054,7 @@ typedef psa_status_t (*psa_drv_se_key_derivation_setup_t)(void *p_context,
|
||||
* expeced that this function may be called multiple times for the same
|
||||
* operation, each with a different algorithm-specific `collateral_id`
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure containing any
|
||||
* \param[in,out] op_context A hardware-specific structure containing any
|
||||
* context information for the implementation
|
||||
* \param[in] collateral_id An ID for the collateral being provided
|
||||
* \param[in] p_collateral A buffer containing the collateral data
|
||||
@ -902,7 +1062,7 @@ typedef psa_status_t (*psa_drv_se_key_derivation_setup_t)(void *p_context,
|
||||
*
|
||||
* \retval PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_key_derivation_collateral_t)(void *p_context,
|
||||
typedef psa_status_t (*psa_drv_se_key_derivation_collateral_t)(void *op_context,
|
||||
uint32_t collateral_id,
|
||||
const uint8_t *p_collateral,
|
||||
size_t collateral_size);
|
||||
@ -910,14 +1070,14 @@ typedef psa_status_t (*psa_drv_se_key_derivation_collateral_t)(void *p_context,
|
||||
/** \brief A function that performs the final secure element key derivation
|
||||
* step and place the generated key material in a slot
|
||||
*
|
||||
* \param[in,out] p_context A hardware-specific structure containing any
|
||||
* \param[in,out] op_context A hardware-specific structure containing any
|
||||
* context information for the implementation
|
||||
* \param[in] dest_key The slot where the generated key material
|
||||
* should be placed
|
||||
*
|
||||
* \retval PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_key_derivation_derive_t)(void *p_context,
|
||||
typedef psa_status_t (*psa_drv_se_key_derivation_derive_t)(void *op_context,
|
||||
psa_key_slot_number_t dest_key);
|
||||
|
||||
/** \brief A function that performs the final step of a secure element key
|
||||
@ -931,7 +1091,7 @@ typedef psa_status_t (*psa_drv_se_key_derivation_derive_t)(void *p_context,
|
||||
*
|
||||
* \retval PSA_SUCCESS
|
||||
*/
|
||||
typedef psa_status_t (*psa_drv_se_key_derivation_export_t)(void *p_context,
|
||||
typedef psa_status_t (*psa_drv_se_key_derivation_export_t)(void *op_context,
|
||||
uint8_t *p_output,
|
||||
size_t output_size,
|
||||
size_t *p_output_length);
|
||||
@ -978,12 +1138,35 @@ typedef struct {
|
||||
* Use #PSA_DRV_SE_HAL_VERSION.
|
||||
*/
|
||||
uint32_t hal_version;
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_drv_se_mac_t mac;
|
||||
psa_drv_se_cipher_t cipher;
|
||||
psa_drv_se_aead_t aead;
|
||||
psa_drv_se_asymmetric_t asymmetric;
|
||||
psa_drv_se_key_derivation_t derivation;
|
||||
|
||||
/** The size of the driver's persistent data in bytes.
|
||||
*
|
||||
* This can be 0 if the driver does not need persistent data.
|
||||
*
|
||||
* See the documentation of psa_drv_se_context_t::persistent_data
|
||||
* for more information about why and how a driver can use
|
||||
* persistent data.
|
||||
*/
|
||||
size_t persistent_data_size;
|
||||
|
||||
/** The driver initialization function.
|
||||
*
|
||||
* This function is called once during the initialization of the
|
||||
* PSA Cryptography subsystem, before any other function of the
|
||||
* driver is called. If this function returns a failure status,
|
||||
* the driver will be unusable, at least until the next system reset.
|
||||
*
|
||||
* If this field is \c NULL, it is equivalent to a function that does
|
||||
* nothing and returns #PSA_SUCCESS.
|
||||
*/
|
||||
psa_drv_se_init_t p_init;
|
||||
|
||||
const psa_drv_se_key_management_t *key_management;
|
||||
const psa_drv_se_mac_t *mac;
|
||||
const psa_drv_se_cipher_t *cipher;
|
||||
const psa_drv_se_aead_t *aead;
|
||||
const psa_drv_se_asymmetric_t *asymmetric;
|
||||
const psa_drv_se_key_derivation_t *derivation;
|
||||
} psa_drv_se_t;
|
||||
|
||||
/** The current version of the secure element driver HAL.
|
||||
|
@ -133,6 +133,119 @@ typedef uint32_t psa_key_usage_t;
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** \defgroup attributes Key attributes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** The type of a structure containing key attributes.
|
||||
*
|
||||
* This is an opaque structure that can represent the metadata of a key
|
||||
* object. Metadata that can be stored in attributes includes:
|
||||
* - The location of the key in storage, indicated by its key identifier
|
||||
* and its lifetime.
|
||||
* - The key's policy, comprising usage flags and a specification of
|
||||
* the permitted algorithm(s).
|
||||
* - Information about the key itself: the key type and its size.
|
||||
* - Implementations may define additional attributes.
|
||||
*
|
||||
* The actual key material is not considered an attribute of a key.
|
||||
* Key attributes do not contain information that is generally considered
|
||||
* highly confidential.
|
||||
*
|
||||
* An attribute structure can be a simple data structure where each function
|
||||
* `psa_set_key_xxx` sets a field and the corresponding function
|
||||
* `psa_get_key_xxx` retrieves the value of the corresponding field.
|
||||
* However, implementations may report values that are equivalent to the
|
||||
* original one, but have a different encoding. For example, an
|
||||
* implementation may use a more compact representation for types where
|
||||
* many bit-patterns are invalid or not supported, and store all values
|
||||
* that it does not support as a special marker value. In such an
|
||||
* implementation, after setting an invalid value, the corresponding
|
||||
* get function returns an invalid value which may not be the one that
|
||||
* was originally stored.
|
||||
*
|
||||
* An attribute structure may contain references to auxiliary resources,
|
||||
* for example pointers to allocated memory or indirect references to
|
||||
* pre-calculated values. In order to free such resources, the application
|
||||
* must call psa_reset_key_attributes(). As an exception, calling
|
||||
* psa_reset_key_attributes() on an attribute structure is optional if
|
||||
* the structure has only been modified by the following functions
|
||||
* since it was initialized or last reset with psa_reset_key_attributes():
|
||||
* - psa_set_key_id()
|
||||
* - psa_set_key_lifetime()
|
||||
* - psa_set_key_type()
|
||||
* - psa_set_key_bits()
|
||||
* - psa_set_key_usage_flags()
|
||||
* - psa_set_key_algorithm()
|
||||
*
|
||||
* Before calling any function on a key attribute structure, the application
|
||||
* must initialize it by any of the following means:
|
||||
* - Set the structure to all-bits-zero, for example:
|
||||
* \code
|
||||
* psa_key_attributes_t attributes;
|
||||
* memset(&attributes, 0, sizeof(attributes));
|
||||
* \endcode
|
||||
* - Initialize the structure to logical zero values, for example:
|
||||
* \code
|
||||
* psa_key_attributes_t attributes = {0};
|
||||
* \endcode
|
||||
* - Initialize the structure to the initializer #PSA_KEY_ATTRIBUTES_INIT,
|
||||
* for example:
|
||||
* \code
|
||||
* psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
* \endcode
|
||||
* - Assign the result of the function psa_key_attributes_init()
|
||||
* to the structure, for example:
|
||||
* \code
|
||||
* psa_key_attributes_t attributes;
|
||||
* attributes = psa_key_attributes_init();
|
||||
* \endcode
|
||||
*
|
||||
* A freshly initialized attribute structure contains the following
|
||||
* values:
|
||||
*
|
||||
* - lifetime: #PSA_KEY_LIFETIME_VOLATILE.
|
||||
* - key identifier: unspecified.
|
||||
* - type: \c 0.
|
||||
* - key size: \c 0.
|
||||
* - usage flags: \c 0.
|
||||
* - algorithm: \c 0.
|
||||
*
|
||||
* A typical sequence to create a key is as follows:
|
||||
* -# Create and initialize an attribute structure.
|
||||
* -# If the key is persistent, call psa_set_key_id().
|
||||
* Also call psa_set_key_lifetime() to place the key in a non-default
|
||||
* location.
|
||||
* -# Set the key policy with psa_set_key_usage_flags() and
|
||||
* 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_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_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.
|
||||
* -# The attribute structure is now no longer necessary.
|
||||
* You may call psa_reset_key_attributes(), although this is optional
|
||||
* with the workflow presented here because the attributes currently
|
||||
* defined in this specification do not require any additional resources
|
||||
* beyond the structure itself.
|
||||
*
|
||||
* A typical sequence to query a key's attributes is as follows:
|
||||
* -# Call psa_get_key_attributes().
|
||||
* -# Call `psa_get_key_xxx` functions to retrieve the attribute(s) that
|
||||
* you are interested in.
|
||||
* -# Call psa_reset_key_attributes() to free any resources that may be
|
||||
* used by the attribute structure.
|
||||
*
|
||||
* Once a key has been created, it is impossible to change its attributes.
|
||||
*/
|
||||
typedef struct psa_key_attributes_s psa_key_attributes_t;
|
||||
|
||||
/**@}*/
|
||||
|
||||
/** \defgroup derivation Key derivation
|
||||
* @{
|
||||
*/
|
||||
|
Reference in New Issue
Block a user