diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/TARGET_TFM_V8M/src/tfm_ns_interface.c b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/TARGET_TFM_V8M/src/tfm_ns_interface.c index 7b016950cd..2f745c23f2 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/TARGET_TFM_V8M/src/tfm_ns_interface.c +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/TARGET_TFM_V8M/src/tfm_ns_interface.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019, Arm Limited. All rights reserved. + * Copyright (c) 2017-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -25,16 +25,12 @@ int32_t tfm_ns_interface_dispatch(veneer_fn fn, int32_t result; /* TFM request protected by NS lock */ - if (os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER) - != OS_WRAPPER_SUCCESS) { - return (int32_t)TFM_ERROR_GENERIC; - } + while (os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER) + != OS_WRAPPER_SUCCESS); result = fn(arg0, arg1, arg2, arg3); - if (os_wrapper_mutex_release(ns_lock_handle) != OS_WRAPPER_SUCCESS) { - return (int32_t)TFM_ERROR_GENERIC; - } + while (os_wrapper_mutex_release(ns_lock_handle) != OS_WRAPPER_SUCCESS); return result; } diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/os_wrapper/msg_queue.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/os_wrapper/msg_queue.h new file mode 100644 index 0000000000..ac69773f10 --- /dev/null +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/os_wrapper/msg_queue.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2020-2021, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +#ifndef __OS_WRAPPER_MSG_QUEUE_H__ +#define __OS_WRAPPER_MSG_QUEUE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include "common.h" + +/** + * \brief Create and initialize a message queue + * + * \param[in] msg_size The maximum message size in bytes + * \param[in] msg_count The maximum number of messages in queue + * + * \return Returns handle of the message queue created, or NULL in case of error + */ +void *os_wrapper_msg_queue_create(size_t msg_size, uint8_t msg_count); + +/** + * \brief Send a message via message queue + * + * \param[in] mq_handle The handle of message queue + * \param[in] msg_ptr The pointer to the message to be sent + * + * \return \ref OS_WRAPPER_SUCCESS if the message is successfully sent, or + * \ref OS_WRAPPER_ERROR in case of error + * + * \note The message size must be the same as the value set in + * \ref os_wrapper_msg_queue_create. + * + * \note Time out value is not specified here. Whether the function is blocked + * or returns instantly depends on the actual implementation and usage + * scenario. + */ +int32_t os_wrapper_msg_queue_send(void *mq_handle, + const void *msg_ptr); + +/** + * \brief Receive a message from message queue + * + * \param[in] mq_handle The handle of message queue + * \param[in] msg_ptr The pointer to buffer for message to be received + * + * \return \ref OS_WRAPPER_SUCCESS if the message is successfully received, or + * \ref OS_WRAPPER_ERROR in case of error + * + * \note The message size is the same as the value set in + * \ref os_wrapper_msg_queue_create. + * + * \note The function should be blocked until a message is received from message + * queue, unless an error occurs. + */ +int32_t os_wrapper_msg_queue_receive(void *mq_handle, + void *msg_ptr); + +#ifdef __cplusplus +} +#endif + +#endif /* __OS_WRAPPER_MSG_QUEUE_H__ */ diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/client.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/client.h index a5e851803f..8fd2d13674 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/client.h +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Arm Limited. All rights reserved. + * Copyright (c) 2018-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -21,9 +21,10 @@ extern "C" { /** * The version of the PSA Framework API that is being used to build the calling - * firmware. + * firmware. Only part of features of FF-M v1.1 have been implemented. FF-M v1.1 + * is compatible with v1.0. */ -#define PSA_FRAMEWORK_VERSION (0x0100u) +#define PSA_FRAMEWORK_VERSION (0x0101u) /** * Return value from psa_version() if the requested RoT Service is not present @@ -130,7 +131,7 @@ psa_handle_t psa_connect(uint32_t sid, uint32_t version); * Must be zero( \ref PSA_IPC_CALL) or positive. * \param[in] in_vec Array of input \ref psa_invec structures. * \param[in] in_len Number of input \ref psa_invec structures. - * \param[in/out] out_vec Array of output \ref psa_outvec structures. + * \param[in,out] out_vec Array of output \ref psa_outvec structures. * \param[in] out_len Number of output \ref psa_outvec structures. * * \retval >=0 RoT Service-specific status value. diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto.h index c58abda240..e9d3c66d46 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto.h +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Arm Limited. All rights reserved. + * Copyright (c) 2018-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -24,16 +24,6 @@ * @{ */ -/** \brief Key handle. - * - * This type represents open handles to keys. It must be an unsigned integral - * type. The choice of type is implementation-dependent. - * - * 0 is not a valid key handle. How other handle values are assigned is - * implementation-dependent. - */ -typedef _unsigned_integral_type_ psa_key_handle_t; - /**@}*/ #endif /* __DOXYGEN_ONLY__ */ @@ -134,11 +124,11 @@ static psa_key_attributes_t psa_key_attributes_init(void); * linkage). This function may be provided as a function-like macro, * but in this case it must evaluate each of its arguments exactly once. * - * \param[out] attributes The attribute structure to write to. - * \param id The persistent identifier for the key. + * \param[out] attributes The attribute structure to write to. + * \param key The persistent identifier for the key. */ static void psa_set_key_id(psa_key_attributes_t *attributes, - psa_key_id_t id); + psa_key_id_t key); /** Set the location of a persistent key. * @@ -335,7 +325,7 @@ static size_t psa_get_key_bits(const psa_key_attributes_t *attributes); * Once you have called this function on an attribute structure, * you must call psa_reset_key_attributes() to free these resources. * - * \param[in] handle Handle to the key to query. + * \param[in] key Identifier of the key to query. * \param[in,out] attributes On success, the attributes of the key. * On failure, equivalent to a * freshly-initialized structure. @@ -351,7 +341,7 @@ static size_t psa_get_key_bits(const psa_key_attributes_t *attributes); * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_get_key_attributes(psa_key_handle_t handle, +psa_status_t psa_get_key_attributes(psa_key_id_t key, psa_key_attributes_t *attributes); /** Reset a key attribute structure to a freshly initialized state. @@ -374,93 +364,28 @@ void psa_reset_key_attributes(psa_key_attributes_t *attributes); * @{ */ -/** Open a handle to an existing persistent key. +/** Remove non-essential copies of key material from memory. * - * Open a handle to a persistent key. A key is persistent if it was created - * with a lifetime other than #PSA_KEY_LIFETIME_VOLATILE. A persistent key - * always has a nonzero key identifier, set with psa_set_key_id() when - * creating the key. Implementations may provide additional pre-provisioned - * keys that can be opened with psa_open_key(). Such keys have a key identifier - * in the vendor range, as documented in the description of #psa_key_id_t. + * If the key identifier designates a volatile key, this functions does not do + * anything and returns successfully. * - * The application must eventually close the handle with psa_close_key() or - * psa_destroy_key() to release associated resources. If the application dies - * without calling one of these functions, the implementation should perform - * the equivalent of a call to psa_close_key(). + * If the key identifier designates a persistent key, then this function will + * free all resources associated with the key in volatile memory. The key + * data in persistent storage is not affected and the key can still be used. * - * Some implementations permit an application to open the same key multiple - * times. If this is successful, each call to psa_open_key() will return a - * different key handle. - * - * \note Applications that rely on opening a key multiple times will not be - * portable to implementations that only permit a single key handle to be - * opened. See also :ref:\`key-handles\`. - * - * \param id The persistent identifier of the key. - * \param[out] handle On success, a handle to the key. + * \param key Identifier of the key to purge. * * \retval #PSA_SUCCESS - * Success. The application can now use the value of `*handle` - * to access the key. - * \retval #PSA_ERROR_INSUFFICIENT_MEMORY - * The implementation does not have sufficient resources to open the - * key. This can be due to reaching an implementation limit on the - * number of open keys, the number of open key handles, or available - * memory. - * \retval #PSA_ERROR_DOES_NOT_EXIST - * There is no persistent key with key identifier \p id. + * The key material will have been removed from memory if it is not + * currently required. * \retval #PSA_ERROR_INVALID_ARGUMENT - * \p id is not a valid persistent key identifier. - * \retval #PSA_ERROR_NOT_PERMITTED - * The specified key exists, but the application does not have the - * permission to access it. Note that this specification does not - * define any way to create such a key, but it may be possible - * through implementation-specific means. - * \retval #PSA_ERROR_COMMUNICATION_FAILURE - * \retval #PSA_ERROR_CORRUPTION_DETECTED - * \retval #PSA_ERROR_STORAGE_FAILURE + * \p key is not a valid key identifier. * \retval #PSA_ERROR_BAD_STATE * The library has not been previously initialized by psa_crypto_init(). * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_open_key(psa_key_id_t id, - psa_key_handle_t *handle); - - -/** Close a key handle. - * - * If the handle designates a volatile key, this will destroy the key material - * and free all associated resources, just like psa_destroy_key(). - * - * If this is the last open handle to a persistent key, then closing the handle - * will free all resources associated with the key in volatile memory. The key - * data in persistent storage is not affected and can be opened again later - * with a call to psa_open_key(). - * - * Closing the key handle makes the handle invalid, and the key handle - * must not be used again by the application. - * - * \note If the key handle was used to set up an active - * :ref:\`multipart operation \`, then closing the - * key handle can cause the multipart operation to fail. Applications should - * maintain the key handle until after the multipart operation has finished. - * - * \param handle The key handle to close. - * If this is \c 0, do nothing and return \c PSA_SUCCESS. - * - * \retval #PSA_SUCCESS - * \p handle was a valid handle or \c 0. It is now closed. - * \retval #PSA_ERROR_INVALID_HANDLE - * \p handle is not a valid handle nor \c 0. - * \retval #PSA_ERROR_COMMUNICATION_FAILURE - * \retval #PSA_ERROR_CORRUPTION_DETECTED - * \retval #PSA_ERROR_BAD_STATE - * The library has not been previously initialized by psa_crypto_init(). - * It is implementation-dependent whether a failure to initialize - * results in this error code. - */ -psa_status_t psa_close_key(psa_key_handle_t handle); +psa_status_t psa_purge_key(psa_key_id_t key); /** Make a copy of a key. * @@ -499,7 +424,10 @@ psa_status_t psa_close_key(psa_key_handle_t handle); * The effect of this function on implementation-defined attributes is * implementation-defined. * - * \param source_handle The key to copy. It must be a valid key handle. + * \param source_key The key to copy. It must allow the usage + * #PSA_KEY_USAGE_COPY. If a private or secret key is + * being copied outside of a secure element it must + * also allow #PSA_KEY_USAGE_EXPORT. * \param[in] attributes The attributes for the new key. * They are used as follows: * - The key type and size may be 0. If either is @@ -513,12 +441,14 @@ psa_status_t psa_close_key(psa_key_handle_t handle); * the source key and \p attributes so that * both sets of restrictions apply, as * described in the documentation of this function. - * \param[out] target_handle On success, a handle to the newly created key. + * \param[out] target_key On success, an identifier for the newly created + * key. For persistent keys, this is the key + * identifier defined in \p attributes. * \c 0 on failure. * * \retval #PSA_SUCCESS * \retval #PSA_ERROR_INVALID_HANDLE - * \p source_handle is invalid. + * \p source_key is invalid. * \retval #PSA_ERROR_ALREADY_EXISTS * This is an attempt to create a persistent key, and there is * already a persistent key with the given identifier. @@ -546,9 +476,9 @@ psa_status_t psa_close_key(psa_key_handle_t handle); * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_copy_key(psa_key_handle_t source_handle, +psa_status_t psa_copy_key(psa_key_id_t source_key, const psa_key_attributes_t *attributes, - psa_key_handle_t *target_handle); + psa_key_id_t *target_key); /** @@ -559,28 +489,22 @@ psa_status_t psa_copy_key(psa_key_handle_t source_handle, * make a best effort to ensure that that the key material cannot be recovered. * * This function also erases any metadata such as policies and frees - * resources associated with the key. To free all resources associated with - * the key, all handles to the key must be closed or destroyed. - * - * Destroying the key makes the handle invalid, and the key handle - * must not be used again by the application. Using other open handles to the - * destroyed key in a cryptographic operation will result in an error. + * resources associated with the key. * * If a key is currently in use in a multipart operation, then destroying the * key will cause the multipart operation to fail. * - * \param handle Handle to the key to erase. - * If this is \c 0, do nothing and return \c PSA_SUCCESS. + * \param key Identifier of the key to erase. If this is \c 0, do nothing and + * return #PSA_SUCCESS. * * \retval #PSA_SUCCESS - * \p handle was a valid handle and the key material that it - * referred to has been erased. - * Alternatively, \p handle is \c 0. + * \p key was a valid identifier and the key material that it + * referred to has been erased. Alternatively, \p key is \c 0. * \retval #PSA_ERROR_NOT_PERMITTED * The key cannot be erased because it is * read-only, either due to a policy or due to physical restrictions. * \retval #PSA_ERROR_INVALID_HANDLE - * \p handle is not a valid handle nor \c 0. + * \p key is not a valid identifier nor \c 0. * \retval #PSA_ERROR_COMMUNICATION_FAILURE * There was an failure in communication with the cryptoprocessor. * The key material may still be present in the cryptoprocessor. @@ -598,7 +522,7 @@ psa_status_t psa_copy_key(psa_key_handle_t source_handle, * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_destroy_key(psa_key_handle_t handle); +psa_status_t psa_destroy_key(psa_key_id_t key); /**@}*/ @@ -633,7 +557,9 @@ psa_status_t psa_destroy_key(psa_key_handle_t handle); * \p data buffer. * If the key size in \p attributes is nonzero, * it must be equal to the size from \p data. - * \param[out] handle On success, a handle to the newly created key. + * \param[out] key On success, an identifier to the newly created key. + * For persistent keys, this is the key identifier + * defined in \p attributes. * \c 0 on failure. * \param[in] data Buffer containing the key data. The content of this * buffer is interpreted according to the type declared @@ -678,7 +604,7 @@ psa_status_t psa_destroy_key(psa_key_handle_t handle); psa_status_t psa_import_key(const psa_key_attributes_t *attributes, const uint8_t *data, size_t data_length, - psa_key_handle_t *handle); + psa_key_id_t *key); @@ -739,7 +665,9 @@ psa_status_t psa_import_key(const psa_key_attributes_t *attributes, * * The policy on the key must have the usage flag #PSA_KEY_USAGE_EXPORT set. * - * \param handle Handle to the key to export. + * \param key Identifier of the key to export. It must allow the + * usage #PSA_KEY_USAGE_EXPORT, unless it is a public + * key. * \param[out] data Buffer where the key data is to be written. * \param data_size Size of the \p data buffer in bytes. * \param[out] data_length On success, the number of bytes @@ -766,7 +694,7 @@ psa_status_t psa_import_key(const psa_key_attributes_t *attributes, * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_export_key(psa_key_handle_t handle, +psa_status_t psa_export_key(psa_key_id_t key, uint8_t *data, size_t data_size, size_t *data_length); @@ -809,7 +737,7 @@ psa_status_t psa_export_key(psa_key_handle_t handle, * Exporting a public key object or the public part of a key pair is * always permitted, regardless of the key's usage flags. * - * \param handle Handle to the key to export. + * \param key Identifier of the key to export. * \param[out] data Buffer where the key data is to be written. * \param data_size Size of the \p data buffer in bytes. * \param[out] data_length On success, the number of bytes @@ -836,7 +764,7 @@ psa_status_t psa_export_key(psa_key_handle_t handle, * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_export_public_key(psa_key_handle_t handle, +psa_status_t psa_export_public_key(psa_key_id_t key, uint8_t *data, size_t data_size, size_t *data_length); @@ -1213,7 +1141,8 @@ psa_status_t psa_hash_clone(const psa_hash_operation_t *source_operation, * about the MAC value which could allow an attacker to guess * a valid MAC and thereby bypass security controls. * - * \param handle Handle to the key to use for the operation. + * \param key Identifier of the key to use for the operation. It + * must allow the usage PSA_KEY_USAGE_SIGN_MESSAGE. * \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value * such that #PSA_ALG_IS_MAC(\p alg) is true). * \param[in] input Buffer containing the input message. @@ -1228,7 +1157,7 @@ psa_status_t psa_hash_clone(const psa_hash_operation_t *source_operation, * \retval #PSA_ERROR_INVALID_HANDLE * \retval #PSA_ERROR_NOT_PERMITTED * \retval #PSA_ERROR_INVALID_ARGUMENT - * \p handle is not compatible with \p alg. + * \p key is not compatible with \p alg. * \retval #PSA_ERROR_NOT_SUPPORTED * \p alg is not supported or is not a MAC algorithm. * \retval #PSA_ERROR_BUFFER_TOO_SMALL @@ -1244,7 +1173,7 @@ psa_status_t psa_hash_clone(const psa_hash_operation_t *source_operation, * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_mac_compute(psa_key_handle_t handle, +psa_status_t psa_mac_compute(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, @@ -1254,7 +1183,8 @@ psa_status_t psa_mac_compute(psa_key_handle_t handle, /** Calculate the MAC of a message and compare it with a reference value. * - * \param handle Handle to the key to use for the operation. + * \param key Identifier of the key to use for the operation. It + * must allow the usage PSA_KEY_USAGE_VERIFY_MESSAGE. * \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value * such that #PSA_ALG_IS_MAC(\p alg) is true). * \param[in] input Buffer containing the input message. @@ -1270,7 +1200,7 @@ psa_status_t psa_mac_compute(psa_key_handle_t handle, * \retval #PSA_ERROR_INVALID_HANDLE * \retval #PSA_ERROR_NOT_PERMITTED * \retval #PSA_ERROR_INVALID_ARGUMENT - * \p handle is not compatible with \p alg. + * \p key is not compatible with \p alg. * \retval #PSA_ERROR_NOT_SUPPORTED * \p alg is not supported or is not a MAC algorithm. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY @@ -1284,7 +1214,7 @@ psa_status_t psa_mac_compute(psa_key_handle_t handle, * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_mac_verify(psa_key_handle_t handle, +psa_status_t psa_mac_verify(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, @@ -1369,9 +1299,9 @@ static psa_mac_operation_t psa_mac_operation_init(void); * \param[in,out] operation The operation object to set up. It must have * been initialized as per the documentation for * #psa_mac_operation_t and not yet in use. - * \param handle Handle to the key to use for the operation. - * It must remain valid until the operation - * terminates. + * \param key Identifier of the key to use for the operation. It + * must remain valid until the operation terminates. + * It must allow the usage PSA_KEY_USAGE_SIGN_MESSAGE. * \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value * such that #PSA_ALG_IS_MAC(\p alg) is true). * @@ -1380,7 +1310,7 @@ static psa_mac_operation_t psa_mac_operation_init(void); * \retval #PSA_ERROR_INVALID_HANDLE * \retval #PSA_ERROR_NOT_PERMITTED * \retval #PSA_ERROR_INVALID_ARGUMENT - * \p handle is not compatible with \p alg. + * \p key is not compatible with \p alg. * \retval #PSA_ERROR_NOT_SUPPORTED * \p alg is not supported or is not a MAC algorithm. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY @@ -1397,7 +1327,7 @@ static psa_mac_operation_t psa_mac_operation_init(void); * results in this error code. */ psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation, - psa_key_handle_t handle, + psa_key_id_t key, psa_algorithm_t alg); /** Set up a multipart MAC verification operation. @@ -1431,9 +1361,10 @@ psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation, * \param[in,out] operation The operation object to set up. It must have * been initialized as per the documentation for * #psa_mac_operation_t and not yet in use. - * \param handle Handle to the key to use for the operation. - * It must remain valid until the operation - * terminates. + * \param key Identifier of the key to use for the operation. It + * must remain valid until the operation terminates. + * It must allow the usage + * PSA_KEY_USAGE_VERIFY_MESSAGE. * \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value * such that #PSA_ALG_IS_MAC(\p alg) is true). * @@ -1459,7 +1390,7 @@ psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation, * results in this error code. */ psa_status_t psa_mac_verify_setup(psa_mac_operation_t *operation, - psa_key_handle_t handle, + psa_key_id_t key, psa_algorithm_t alg); /** Add a message fragment to a multipart MAC operation. @@ -1626,9 +1557,8 @@ psa_status_t psa_mac_abort(psa_mac_operation_t *operation); * vector). Use the multipart operation interface with a * #psa_cipher_operation_t object to provide other forms of IV. * - * \param handle Handle to the key to use for the operation. - * It must remain valid until the operation - * terminates. + * \param key Identifier of the key to use for the operation. + * It must allow the usage #PSA_KEY_USAGE_ENCRYPT. * \param alg The cipher algorithm to compute * (\c PSA_ALG_XXX value such that * #PSA_ALG_IS_CIPHER(\p alg) is true). @@ -1646,7 +1576,7 @@ psa_status_t psa_mac_abort(psa_mac_operation_t *operation); * \retval #PSA_ERROR_INVALID_HANDLE * \retval #PSA_ERROR_NOT_PERMITTED * \retval #PSA_ERROR_INVALID_ARGUMENT - * \p handle is not compatible with \p alg. + * \p key is not compatible with \p alg. * \retval #PSA_ERROR_NOT_SUPPORTED * \p alg is not supported or is not a cipher algorithm. * \retval #PSA_ERROR_BUFFER_TOO_SMALL @@ -1660,7 +1590,7 @@ psa_status_t psa_mac_abort(psa_mac_operation_t *operation); * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_cipher_encrypt(psa_key_handle_t handle, +psa_status_t psa_cipher_encrypt(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, @@ -1672,9 +1602,10 @@ psa_status_t psa_cipher_encrypt(psa_key_handle_t handle, * * This function decrypts a message encrypted with a symmetric cipher. * - * \param handle Handle to the key to use for the operation. + * \param key Identifier of the key to use for the operation. * It must remain valid until the operation - * terminates. + * terminates. It must allow the usage + * #PSA_KEY_USAGE_DECRYPT. * \param alg The cipher algorithm to compute * (\c PSA_ALG_XXX value such that * #PSA_ALG_IS_CIPHER(\p alg) is true). @@ -1692,7 +1623,7 @@ psa_status_t psa_cipher_encrypt(psa_key_handle_t handle, * \retval #PSA_ERROR_INVALID_HANDLE * \retval #PSA_ERROR_NOT_PERMITTED * \retval #PSA_ERROR_INVALID_ARGUMENT - * \p handle is not compatible with \p alg. + * \p key is not compatible with \p alg. * \retval #PSA_ERROR_NOT_SUPPORTED * \p alg is not supported or is not a cipher algorithm. * \retval #PSA_ERROR_BUFFER_TOO_SMALL @@ -1706,7 +1637,7 @@ psa_status_t psa_cipher_encrypt(psa_key_handle_t handle, * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_cipher_decrypt(psa_key_handle_t handle, +psa_status_t psa_cipher_decrypt(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, @@ -1792,9 +1723,10 @@ static psa_cipher_operation_t psa_cipher_operation_init(void); * \param[in,out] operation The operation object to set up. It must have * been initialized as per the documentation for * #psa_cipher_operation_t and not yet in use. - * \param handle Handle to the key to use for the operation. + * \param key Identifier of the key to use for the operation. * It must remain valid until the operation - * terminates. + * terminates. It must allow the usage + * #PSA_KEY_USAGE_ENCRYPT. * \param alg The cipher algorithm to compute * (\c PSA_ALG_XXX value such that * #PSA_ALG_IS_CIPHER(\p alg) is true). @@ -1804,7 +1736,7 @@ static psa_cipher_operation_t psa_cipher_operation_init(void); * \retval #PSA_ERROR_INVALID_HANDLE * \retval #PSA_ERROR_NOT_PERMITTED * \retval #PSA_ERROR_INVALID_ARGUMENT - * \p handle is not compatible with \p alg. + * \p key is not compatible with \p alg. * \retval #PSA_ERROR_NOT_SUPPORTED * \p alg is not supported or is not a cipher algorithm. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY @@ -1820,7 +1752,7 @@ static psa_cipher_operation_t psa_cipher_operation_init(void); * results in this error code. */ psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation, - psa_key_handle_t handle, + psa_key_id_t key, psa_algorithm_t alg); /** Set the key for a multipart symmetric decryption operation. @@ -1855,9 +1787,10 @@ psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation, * \param[in,out] operation The operation object to set up. It must have * been initialized as per the documentation for * #psa_cipher_operation_t and not yet in use. - * \param handle Handle to the key to use for the operation. + * \param key Identifier of the key to use for the operation. * It must remain valid until the operation - * terminates. + * terminates. It must allow the usage + * #PSA_KEY_USAGE_DECRYPT. * \param alg The cipher algorithm to compute * (\c PSA_ALG_XXX value such that * #PSA_ALG_IS_CIPHER(\p alg) is true). @@ -1867,7 +1800,7 @@ psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation, * \retval #PSA_ERROR_INVALID_HANDLE * \retval #PSA_ERROR_NOT_PERMITTED * \retval #PSA_ERROR_INVALID_ARGUMENT - * \p handle is not compatible with \p alg. + * \p key is not compatible with \p alg. * \retval #PSA_ERROR_NOT_SUPPORTED * \p alg is not supported or is not a cipher algorithm. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY @@ -1883,7 +1816,7 @@ psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation, * results in this error code. */ psa_status_t psa_cipher_decrypt_setup(psa_cipher_operation_t *operation, - psa_key_handle_t handle, + psa_key_id_t key, psa_algorithm_t alg); /** Generate an IV for a symmetric encryption operation. @@ -2097,7 +2030,9 @@ psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation); /** Process an authenticated encryption operation. * - * \param handle Handle to the key to use for the operation. + * \param key Identifier of the key to use for the + * operation. It must allow the usage + * #PSA_KEY_USAGE_ENCRYPT. * \param alg The AEAD algorithm to compute * (\c PSA_ALG_XXX value such that * #PSA_ALG_IS_AEAD(\p alg) is true). @@ -2128,7 +2063,7 @@ psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation); * \retval #PSA_ERROR_INVALID_HANDLE * \retval #PSA_ERROR_NOT_PERMITTED * \retval #PSA_ERROR_INVALID_ARGUMENT - * \p handle is not compatible with \p alg. + * \p key is not compatible with \p alg. * \retval #PSA_ERROR_NOT_SUPPORTED * \p alg is not supported or is not an AEAD algorithm. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY @@ -2143,7 +2078,7 @@ psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation); * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_aead_encrypt(psa_key_handle_t handle, +psa_status_t psa_aead_encrypt(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *nonce, size_t nonce_length, @@ -2157,7 +2092,9 @@ psa_status_t psa_aead_encrypt(psa_key_handle_t handle, /** Process an authenticated decryption operation. * - * \param handle Handle to the key to use for the operation. + * \param key Identifier of the key to use for the + * operation. It must allow the usage + * #PSA_KEY_USAGE_DECRYPT. * \param alg The AEAD algorithm to compute * (\c PSA_ALG_XXX value such that * #PSA_ALG_IS_AEAD(\p alg) is true). @@ -2188,7 +2125,7 @@ psa_status_t psa_aead_encrypt(psa_key_handle_t handle, * The ciphertext is not authentic. * \retval #PSA_ERROR_NOT_PERMITTED * \retval #PSA_ERROR_INVALID_ARGUMENT - * \p handle is not compatible with \p alg. + * \p key is not compatible with \p alg. * \retval #PSA_ERROR_NOT_SUPPORTED * \p alg is not supported or is not an AEAD algorithm. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY @@ -2203,7 +2140,7 @@ psa_status_t psa_aead_encrypt(psa_key_handle_t handle, * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_aead_decrypt(psa_key_handle_t handle, +psa_status_t psa_aead_decrypt(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *nonce, size_t nonce_length, @@ -2299,9 +2236,10 @@ static psa_aead_operation_t psa_aead_operation_init(void); * \param[in,out] operation The operation object to set up. It must have * been initialized as per the documentation for * #psa_aead_operation_t and not yet in use. - * \param handle Handle to the key to use for the operation. + * \param key Identifier of the key to use for the operation. * It must remain valid until the operation - * terminates. + * terminates. It must allow the usage + * #PSA_KEY_USAGE_ENCRYPT. * \param alg The AEAD algorithm to compute * (\c PSA_ALG_XXX value such that * #PSA_ALG_IS_AEAD(\p alg) is true). @@ -2310,10 +2248,10 @@ static psa_aead_operation_t psa_aead_operation_init(void); * Success. * \retval #PSA_ERROR_BAD_STATE * The operation state is not valid (it must be inactive). - * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_INVALID_HANDLE * \retval #PSA_ERROR_NOT_PERMITTED * \retval #PSA_ERROR_INVALID_ARGUMENT - * \p handle is not compatible with \p alg. + * \p key is not compatible with \p alg. * \retval #PSA_ERROR_NOT_SUPPORTED * \p alg is not supported or is not an AEAD algorithm. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY @@ -2327,7 +2265,7 @@ static psa_aead_operation_t psa_aead_operation_init(void); * results in this error code. */ psa_status_t psa_aead_encrypt_setup(psa_aead_operation_t *operation, - psa_key_handle_t handle, + psa_key_id_t key, psa_algorithm_t alg); /** Set the key for a multipart authenticated decryption operation. @@ -2365,9 +2303,10 @@ psa_status_t psa_aead_encrypt_setup(psa_aead_operation_t *operation, * \param[in,out] operation The operation object to set up. It must have * been initialized as per the documentation for * #psa_aead_operation_t and not yet in use. - * \param handle Handle to the key to use for the operation. + * \param key Identifier of the key to use for the operation. * It must remain valid until the operation - * terminates. + * terminates. It must allow the usage + * #PSA_KEY_USAGE_DECRYPT. * \param alg The AEAD algorithm to compute * (\c PSA_ALG_XXX value such that * #PSA_ALG_IS_AEAD(\p alg) is true). @@ -2376,10 +2315,10 @@ psa_status_t psa_aead_encrypt_setup(psa_aead_operation_t *operation, * Success. * \retval #PSA_ERROR_BAD_STATE * The operation state is not valid (it must be inactive). - * \retval #PSA_ERROR_INVALID_HANDLE + * \retval #PSA_ERROR_INVALID_HANDLE * \retval #PSA_ERROR_NOT_PERMITTED * \retval #PSA_ERROR_INVALID_ARGUMENT - * \p handle is not compatible with \p alg. + * \p key is not compatible with \p alg. * \retval #PSA_ERROR_NOT_SUPPORTED * \p alg is not supported or is not an AEAD algorithm. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY @@ -2393,7 +2332,7 @@ psa_status_t psa_aead_encrypt_setup(psa_aead_operation_t *operation, * results in this error code. */ psa_status_t psa_aead_decrypt_setup(psa_aead_operation_t *operation, - psa_key_handle_t handle, + psa_key_id_t key, psa_algorithm_t alg); /** Generate a random nonce for an authenticated encryption operation. @@ -2419,7 +2358,7 @@ psa_status_t psa_aead_decrypt_setup(psa_aead_operation_t *operation, * Success. * \retval #PSA_ERROR_BAD_STATE * The operation state is not valid (it must be an active aead encrypt - operation, with no nonce set). + * operation, with no nonce set). * \retval #PSA_ERROR_BUFFER_TOO_SMALL * The size of the \p nonce buffer is too small. * \retval #PSA_ERROR_INSUFFICIENT_MEMORY @@ -2851,10 +2790,11 @@ psa_status_t psa_aead_abort(psa_aead_operation_t *operation); * parameter to this function. You can use #PSA_ALG_SIGN_GET_HASH(\p alg) * to determine the hash algorithm to use. * - * \param handle Handle to the key to use for the operation. - * It must be an asymmetric key pair. + * \param key Identifier of the key to use for the operation. + * It must be an asymmetric key pair. The key must + * allow the usage #PSA_KEY_USAGE_SIGN_HASH. * \param alg A signature algorithm that is compatible with - * the type of \p handle. + * the type of \p key. * \param[in] hash The hash or message to sign. * \param hash_length Size of the \p hash buffer in bytes. * \param[out] signature Buffer where the signature is to be written. @@ -2870,7 +2810,7 @@ psa_status_t psa_aead_abort(psa_aead_operation_t *operation); * determine a sufficient buffer size by calling * #PSA_SIGN_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg) * where \c key_type and \c key_bits are the type and bit-size - * respectively of \p handle. + * respectively of \p key. * \retval #PSA_ERROR_NOT_SUPPORTED * \retval #PSA_ERROR_INVALID_ARGUMENT * \retval #PSA_ERROR_INSUFFICIENT_MEMORY @@ -2884,7 +2824,7 @@ psa_status_t psa_aead_abort(psa_aead_operation_t *operation); * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_sign_hash(psa_key_handle_t handle, +psa_status_t psa_sign_hash(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, @@ -2901,10 +2841,12 @@ psa_status_t psa_sign_hash(psa_key_handle_t handle, * parameter to this function. You can use #PSA_ALG_SIGN_GET_HASH(\p alg) * to determine the hash algorithm to use. * - * \param handle Handle to the key to use for the operation. - * It must be a public key or an asymmetric key pair. + * \param key Identifier of the key to use for the operation. It + * must be a public key or an asymmetric key pair. The + * key must allow the usage + * #PSA_KEY_USAGE_VERIFY_HASH. * \param alg A signature algorithm that is compatible with - * the type of \p handle. + * the type of \p key. * \param[in] hash The hash or message whose signature is to be * verified. * \param hash_length Size of the \p hash buffer in bytes. @@ -2930,7 +2872,7 @@ psa_status_t psa_sign_hash(psa_key_handle_t handle, * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_verify_hash(psa_key_handle_t handle, +psa_status_t psa_verify_hash(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, @@ -2940,11 +2882,12 @@ psa_status_t psa_verify_hash(psa_key_handle_t handle, /** * \brief Encrypt a short message with a public key. * - * \param handle Handle to the key to use for the operation. - * It must be a public key or an asymmetric - * key pair. + * \param key Identifer of the key to use for the operation. + * It must be a public key or an asymmetric key + * pair. It must allow the usage + * #PSA_KEY_USAGE_ENCRYPT. * \param alg An asymmetric encryption algorithm that is - * compatible with the type of \p handle. + * compatible with the type of \p key. * \param[in] input The message to encrypt. * \param input_length Size of the \p input buffer in bytes. * \param[in] salt A salt or label, if supported by the @@ -2973,7 +2916,7 @@ psa_status_t psa_verify_hash(psa_key_handle_t handle, * determine a sufficient buffer size by calling * #PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg) * where \c key_type and \c key_bits are the type and bit-size - * respectively of \p handle. + * respectively of \p key. * \retval #PSA_ERROR_NOT_SUPPORTED * \retval #PSA_ERROR_INVALID_ARGUMENT * \retval #PSA_ERROR_INSUFFICIENT_MEMORY @@ -2987,7 +2930,7 @@ psa_status_t psa_verify_hash(psa_key_handle_t handle, * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_asymmetric_encrypt(psa_key_handle_t handle, +psa_status_t psa_asymmetric_encrypt(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, @@ -3000,10 +2943,11 @@ psa_status_t psa_asymmetric_encrypt(psa_key_handle_t handle, /** * \brief Decrypt a short message with a private key. * - * \param handle Handle to the key to use for the operation. - * It must be an asymmetric key pair. + * \param key Identifier of the key to use for the operation. + * It must be an asymmetric key pair. It must + * allow the usage #PSA_KEY_USAGE_DECRYPT. * \param alg An asymmetric encryption algorithm that is - * compatible with the type of \p handle. + * compatible with the type of \p key. * \param[in] input The message to decrypt. * \param input_length Size of the \p input buffer in bytes. * \param[in] salt A salt or label, if supported by the @@ -3032,7 +2976,7 @@ psa_status_t psa_asymmetric_encrypt(psa_key_handle_t handle, * determine a sufficient buffer size by calling * #PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg) * where \c key_type and \c key_bits are the type and bit-size - * respectively of \p handle. + * respectively of \p key. * \retval #PSA_ERROR_NOT_SUPPORTED * \retval #PSA_ERROR_INVALID_ARGUMENT * \retval #PSA_ERROR_INSUFFICIENT_MEMORY @@ -3047,7 +2991,7 @@ psa_status_t psa_asymmetric_encrypt(psa_key_handle_t handle, * It is implementation-dependent whether a failure to initialize * results in this error code. */ -psa_status_t psa_asymmetric_decrypt(psa_key_handle_t handle, +psa_status_t psa_asymmetric_decrypt(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, @@ -3305,9 +3249,9 @@ psa_status_t psa_key_derivation_input_bytes( * psa_key_derivation_setup() and must not * have produced any output yet. * \param step Which step the input data is for. - * \param handle Handle to the key. It must have an - * appropriate type for \p step and must - * allow the usage #PSA_KEY_USAGE_DERIVE. + * \param key Identifier of the key. It must have an + * appropriate type for step and must allow the + * usage #PSA_KEY_USAGE_DERIVE. * * \retval #PSA_SUCCESS * Success. @@ -3333,7 +3277,7 @@ psa_status_t psa_key_derivation_input_bytes( psa_status_t psa_key_derivation_input_key( psa_key_derivation_operation_t *operation, psa_key_derivation_step_t step, - psa_key_handle_t handle); + psa_key_id_t key); /** Perform a key agreement and use the shared secret as input to a key * derivation. @@ -3358,7 +3302,8 @@ psa_status_t psa_key_derivation_input_key( * The operation must be ready for an * input of the type given by \p step. * \param step Which step the input data is for. - * \param private_key Handle to the private key to use. + * \param private_key Identifier of the private key to use. It must + * allow the usage #PSA_KEY_USAGE_DERIVE. * \param[in] peer_key Public key of the peer. The peer key must be in the * same format that psa_import_key() accepts for the * public key type corresponding to the type of @@ -3402,7 +3347,7 @@ psa_status_t psa_key_derivation_input_key( psa_status_t psa_key_derivation_key_agreement( psa_key_derivation_operation_t *operation, psa_key_derivation_step_t step, - psa_key_handle_t private_key, + psa_key_id_t private_key, const uint8_t *peer_key, size_t peer_key_length); @@ -3546,7 +3491,9 @@ psa_status_t psa_key_derivation_output_bytes( * * \param[in] attributes The attributes for the new key. * \param[in,out] operation The key derivation operation object to read from. - * \param[out] handle On success, a handle to the newly created key. + * \param[out] key On success, an identifier for the newly created + * key. For persistent keys, this is the key + * identifier defined in \p attributes. * \c 0 on failure. * * \retval #PSA_SUCCESS @@ -3586,7 +3533,7 @@ psa_status_t psa_key_derivation_output_bytes( psa_status_t psa_key_derivation_output_key( const psa_key_attributes_t *attributes, psa_key_derivation_operation_t *operation, - psa_key_handle_t *handle); + psa_key_id_t *key); /** Abort a key derivation operation. * @@ -3627,7 +3574,8 @@ psa_status_t psa_key_derivation_abort( * (\c PSA_ALG_XXX value such that * #PSA_ALG_IS_RAW_KEY_AGREEMENT(\p alg) * is true). - * \param private_key Handle to the private key to use. + * \param private_key Identifier of the private key to use. It must + * allow the usage #PSA_KEY_USAGE_DERIVE. * \param[in] peer_key Public key of the peer. It must be * in the same format that psa_import_key() * accepts. The standard formats for public @@ -3665,7 +3613,7 @@ psa_status_t psa_key_derivation_abort( * results in this error code. */ psa_status_t psa_raw_key_agreement(psa_algorithm_t alg, - psa_key_handle_t private_key, + psa_key_id_t private_key, const uint8_t *peer_key, size_t peer_key_length, uint8_t *output, @@ -3721,7 +3669,9 @@ psa_status_t psa_generate_random(uint8_t *output, * attributes. * * \param[in] attributes The attributes for the new key. - * \param[out] handle On success, a handle to the newly created key. + * \param[out] key On success, an identifier for the newly created + * key. For persistent keys, this is the key + * identifier defined in \p attributes. * \c 0 on failure. * * \retval #PSA_SUCCESS @@ -3746,7 +3696,7 @@ psa_status_t psa_generate_random(uint8_t *output, * results in this error code. */ psa_status_t psa_generate_key(const psa_key_attributes_t *attributes, - psa_key_handle_t *handle); + psa_key_id_t *key); /**@}*/ diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_client_struct.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_client_struct.h index ae92bdb3df..98f7bfe678 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_client_struct.h +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_client_struct.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Arm Limited. All rights reserved. + * Copyright (c) 2020-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -32,15 +32,14 @@ extern "C" { struct psa_client_key_attributes_s { uint32_t lifetime; - uint32_t id; + psa_key_id_t id; uint32_t alg; - uint32_t alg2; uint32_t usage; size_t bits; uint16_t type; }; -#define PSA_CLIENT_KEY_ATTRIBUTES_INIT {0, 0, 0, 0, 0, 0, 0} +#define PSA_CLIENT_KEY_ATTRIBUTES_INIT {0, 0, 0, 0, 0, 0} #ifdef __cplusplus } diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_compat.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_compat.h index 26c205ac9b..8ca1f6a687 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_compat.h +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_compat.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020, Arm Limited. All rights reserved. + * Copyright (c) 2019-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -24,6 +24,25 @@ extern "C" { #endif +/* + * To support both openless APIs and psa_open_key() temporarily, define + * psa_key_handle_t to be equal to psa_key_id_t. Do not mark the + * type and its utility macros and functions deprecated yet. This will be done + * in a subsequent phase. + */ +typedef psa_key_id_t psa_key_handle_t; + +/** Check whether an handle is null. + * + * \param handle Handle + * + * \return Non-zero if the handle is null, zero otherwise. + */ +static inline int psa_key_handle_is_null(psa_key_handle_t handle) +{ + return(handle == 0); +} + #if !defined(MBEDTLS_DEPRECATED_REMOVED) /* @@ -42,6 +61,7 @@ typedef MBEDTLS_PSA_DEPRECATED psa_ecc_family_t mbedtls_deprecated_psa_ecc_famil typedef MBEDTLS_PSA_DEPRECATED psa_dh_family_t mbedtls_deprecated_psa_dh_family_t; typedef MBEDTLS_PSA_DEPRECATED psa_ecc_family_t psa_ecc_curve_t; typedef MBEDTLS_PSA_DEPRECATED psa_dh_family_t psa_dh_group_t; +typedef MBEDTLS_PSA_DEPRECATED psa_algorithm_t mbedtls_deprecated_psa_algorithm_t; #define PSA_KEY_TYPE_GET_CURVE PSA_KEY_TYPE_ECC_GET_FAMILY #define PSA_KEY_TYPE_GET_GROUP PSA_KEY_TYPE_DH_GET_FAMILY @@ -97,7 +117,6 @@ MBEDTLS_PSA_DEPRECATED psa_status_t psa_asymmetric_verify( psa_key_handle_t key, const uint8_t *signature, size_t signature_length ); -#endif /* MBEDTLS_DEPRECATED_REMOVED */ /* * Size-specific elliptic curve families. @@ -205,6 +224,117 @@ MBEDTLS_PSA_DEPRECATED psa_status_t psa_asymmetric_verify( psa_key_handle_t key, #define PSA_DH_GROUP_CUSTOM \ MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_CUSTOM ) +/* + * Deprecated PSA Crypto stream cipher algorithms (PSA Crypto API <= 1.0 beta3) + */ +#define PSA_ALG_ARC4 \ + MBEDTLS_DEPRECATED_CONSTANT(psa_algorithm_t, PSA_ALG_STREAM_CIPHER) +#define PSA_ALG_CHACHA20 \ + MBEDTLS_DEPRECATED_CONSTANT(psa_algorithm_t, PSA_ALG_STREAM_CIPHER) + +#endif /* MBEDTLS_DEPRECATED_REMOVED */ + +/** Open a handle to an existing persistent key. + * + * Open a handle to a persistent key. A key is persistent if it was created + * with a lifetime other than #PSA_KEY_LIFETIME_VOLATILE. A persistent key + * always has a nonzero key identifier, set with psa_set_key_id() when + * creating the key. Implementations may provide additional pre-provisioned + * keys that can be opened with psa_open_key(). Such keys have an application + * key identifier in the vendor range, as documented in the description of + * #psa_key_id_t. + * + * The application must eventually close the handle with psa_close_key() or + * psa_destroy_key() to release associated resources. If the application dies + * without calling one of these functions, the implementation should perform + * the equivalent of a call to psa_close_key(). + * + * Some implementations permit an application to open the same key multiple + * times. If this is successful, each call to psa_open_key() will return a + * different key handle. + * + * \note This API is not part of the PSA Cryptography API Release 1.0.0 + * specification. It was defined in the 1.0 Beta 3 version of the + * specification but was removed in the 1.0.0 released version. This API is + * kept for the time being to not break applications relying on it. It is not + * deprecated yet but will be in the near future. + * + * \note Applications that rely on opening a key multiple times will not be + * portable to implementations that only permit a single key handle to be + * opened. See also :ref:\`key-handles\`. + * + * + * \param id The persistent identifier of the key. + * \param[out] key On success, a handle to the key. + * + * \retval #PSA_SUCCESS + * Success. The application can now use the value of `*handle` + * to access the key. + * \retval #PSA_ERROR_INSUFFICIENT_MEMORY + * The implementation does not have sufficient resources to open the + * key. This can be due to reaching an implementation limit on the + * number of open keys, the number of open key handles, or available + * memory. + * \retval #PSA_ERROR_DOES_NOT_EXIST + * There is no persistent key with key identifier \p id. + * \retval #PSA_ERROR_INVALID_ARGUMENT + * \p id is not a valid persistent key identifier. + * \retval #PSA_ERROR_NOT_PERMITTED + * The specified key exists, but the application does not have the + * permission to access it. Note that this specification does not + * define any way to create such a key, but it may be possible + * through implementation-specific means. + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_STORAGE_FAILURE + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_open_key(psa_key_id_t id, + psa_key_id_t *key); + +/** Close a key handle. + * + * If the handle designates a volatile key, this will destroy the key material + * and free all associated resources, just like psa_destroy_key(). + * + * If this is the last open handle to a persistent key, then closing the handle + * will free all resources associated with the key in volatile memory. The key + * data in persistent storage is not affected and can be opened again later + * with a call to psa_open_key(). + * + * Closing the key handle makes the handle invalid, and the key handle + * must not be used again by the application. + * + * \note This API is not part of the PSA Cryptography API Release 1.0.0 + * specification. It was defined in the 1.0 Beta 3 version of the + * specification but was removed in the 1.0.0 released version. This API is + * kept for the time being to not break applications relying on it. It is not + * deprecated yet but will be in the near future. + * + * \note If the key handle was used to set up an active + * :ref:\`multipart operation \`, then closing the + * key handle can cause the multipart operation to fail. Applications should + * maintain the key handle until after the multipart operation has finished. + * + * \param key The key to close. + * If this is \c 0, do nothing and return \c PSA_SUCCESS. + * + * \retval #PSA_SUCCESS + * \p handle was a valid handle or \c 0. It is now closed. + * \retval #PSA_ERROR_INVALID_HANDLE + * \p handle is not a valid handle nor \c 0. + * \retval #PSA_ERROR_COMMUNICATION_FAILURE + * \retval #PSA_ERROR_CORRUPTION_DETECTED + * \retval #PSA_ERROR_BAD_STATE + * The library has not been previously initialized by psa_crypto_init(). + * It is implementation-dependent whether a failure to initialize + * results in this error code. + */ +psa_status_t psa_close_key(psa_key_id_t key); + #ifdef __cplusplus } #endif diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_extra.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_extra.h index 7bdb49b86e..b8a4d7e36c 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_extra.h +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_extra.h @@ -20,8 +20,6 @@ #include "psa/crypto_compat.h" -#include "platform/mbed_toolchain.h" - #ifdef __cplusplus extern "C" { #endif @@ -59,118 +57,6 @@ extern "C" { /**@}*/ -#if defined(MBEDTLS_ECP_C) -#include - -/** Convert an ECC curve identifier from the Mbed TLS encoding to PSA. - * - * \note This function is provided solely for the convenience of - * Mbed TLS and may be removed at any time without notice. - * - * \param grpid An Mbed TLS elliptic curve identifier - * (`MBEDTLS_ECP_DP_xxx`). - * \param[out] bits On success, the bit size of the curve. - * - * \return The corresponding PSA elliptic curve identifier - * (`PSA_ECC_FAMILY_xxx`). - * \return \c 0 on failure (\p grpid is not recognized). - */ -static inline psa_ecc_family_t mbedtls_ecc_group_to_psa( mbedtls_ecp_group_id grpid, - size_t *bits ) -{ - switch( grpid ) - { - case MBEDTLS_ECP_DP_SECP192R1: - *bits = 192; - return( PSA_ECC_FAMILY_SECP_R1 ); - case MBEDTLS_ECP_DP_SECP224R1: - *bits = 224; - return( PSA_ECC_FAMILY_SECP_R1 ); - case MBEDTLS_ECP_DP_SECP256R1: - *bits = 256; - return( PSA_ECC_FAMILY_SECP_R1 ); - case MBEDTLS_ECP_DP_SECP384R1: - *bits = 384; - return( PSA_ECC_FAMILY_SECP_R1 ); - case MBEDTLS_ECP_DP_SECP521R1: - *bits = 521; - return( PSA_ECC_FAMILY_SECP_R1 ); - case MBEDTLS_ECP_DP_BP256R1: - *bits = 256; - return( PSA_ECC_FAMILY_BRAINPOOL_P_R1 ); - case MBEDTLS_ECP_DP_BP384R1: - *bits = 384; - return( PSA_ECC_FAMILY_BRAINPOOL_P_R1 ); - case MBEDTLS_ECP_DP_BP512R1: - *bits = 512; - return( PSA_ECC_FAMILY_BRAINPOOL_P_R1 ); - case MBEDTLS_ECP_DP_CURVE25519: - *bits = 255; - return( PSA_ECC_FAMILY_MONTGOMERY ); - case MBEDTLS_ECP_DP_SECP192K1: - *bits = 192; - return( PSA_ECC_FAMILY_SECP_K1 ); - case MBEDTLS_ECP_DP_SECP224K1: - *bits = 224; - return( PSA_ECC_FAMILY_SECP_K1 ); - case MBEDTLS_ECP_DP_SECP256K1: - *bits = 256; - return( PSA_ECC_FAMILY_SECP_K1 ); - case MBEDTLS_ECP_DP_CURVE448: - *bits = 448; - return( PSA_ECC_FAMILY_MONTGOMERY ); - default: - *bits = 0; - return( 0 ); - } -} - -#endif /* MBEDTLS_ECP_C */ - -/** \brief Declare the enrollment algorithm for a key. - * - * An operation on a key may indifferently use the algorithm set with - * psa_set_key_algorithm() or with this function. - * - * \param[out] attributes The attribute structure to write to. - * \param alg2 A second algorithm that the key may be used - * for, in addition to the algorithm set with - * psa_set_key_algorithm(). - * - * \deprecated This is for backward compatibility only. - * Setting an enrollment algorithm is not recommended, because - * using the same key with different algorithms can allow some - * attacks based on arithmetic relations between different - * computations made with the same key, or can escalate harmless - * side channels into exploitable ones. Use this function only - * if it is necessary to support a protocol for which it has been - * verified that the usage of the key with multiple algorithms - * is safe. - */ -MBED_DEPRECATED("Setting enrollment algorithm is for backward compatibility and not recommended.") -static inline void psa_set_key_enrollment_algorithm( - psa_key_attributes_t *attributes, - psa_algorithm_t alg2) -{ - attributes->alg2 = alg2; -} - -/** Retrieve the enrollment algorithm policy from key attributes. - * - * \param[in] attributes The key attribute structure to query. - * - * \return The enrollment algorithm stored in the attribute structure. - - * \deprecated This is for backward compatibility only. - * Deprecated along with psa_set_key_enrollment_algorithm(). - */ -MBED_DEPRECATED("Getting enrollment algorithm is for backward compatibility and not recommended.") -static inline psa_algorithm_t psa_get_key_enrollment_algorithm( - const psa_key_attributes_t *attributes) -{ - return attributes->alg2; -} - #ifdef __cplusplus } #endif diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_sizes.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_sizes.h index cbdf59716a..4d13e412af 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_sizes.h +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_sizes.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Arm Limited. All rights reserved. + * Copyright (c) 2018-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -605,4 +605,94 @@ PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(key_type) ? PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits) : \ 0) +/** The default nonce size for an AEAD algorithm, in bytes. + * + * This macro can be used to allocate a buffer of sufficient size to + * store the nonce output from #psa_aead_generate_nonce(). + * + * See also #PSA_AEAD_NONCE_MAX_SIZE. + * + * \note This is not the maximum size of nonce supported as input to #psa_aead_set_nonce(), + * #psa_aead_encrypt() or #psa_aead_decrypt(), just the default size that is generated by + * #psa_aead_generate_nonce(). + * + * \warning This macro may evaluate its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * \param key_type A symmetric key type that is compatible with algorithm \p alg. + * + * \param alg An AEAD algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_AEAD(\p alg) is true). + * + * \return The default nonce size for the specified key type and algorithm. + * If the key type or AEAD algorithm is not recognized, + * or the parameters are incompatible, return 0. + * An implementation can return either 0 or a correct size for a key type + * and AEAD algorithm that it recognizes, but does not support. + */ +#define PSA_AEAD_NONCE_LENGTH(key_type, alg) \ + (PSA_BLOCK_CIPHER_BLOCK_SIZE(key_type) == 16 && \ + (PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH(alg) == PSA_ALG_CCM || \ + PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH(alg) == PSA_ALG_GCM) ? 12 : \ + (key_type) == PSA_KEY_TYPE_CHACHA20 && \ + PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH(alg) == PSA_ALG_CHACHA20_POLY1305 ? 12 : \ + 0) + +/** The maximum default nonce size among all supported pairs of key types and + * AEAD algorithms, in bytes. + * + * This is equal to or greater than any value that #PSA_AEAD_NONCE_LENGTH() may return. + * + * \note This is not the maximum size of nonce supported as input to #psa_aead_set_nonce(), + * #psa_aead_encrypt() or #psa_aead_decrypt(), just the largest size that may be generated by + * #psa_aead_generate_nonce(). + */ +#define PSA_AEAD_NONCE_MAX_SIZE 12 + +/** The default IV size for a cipher algorithm, in bytes. + * + * The IV that is generated as part of a call to #psa_cipher_encrypt() is always + * the default IV length for the algorithm. + * + * This macro can be used to allocate a buffer of sufficient size to + * store the IV output from #psa_cipher_generate_iv() when using + * a multi-part cipher operation. + * + * See also #PSA_CIPHER_IV_MAX_SIZE. + * + * \warning This macro may evaluate its arguments multiple times or + * zero times, so you should not pass arguments that contain + * side effects. + * + * \param key_type A symmetric key type that is compatible with algorithm \p alg. + * + * \param alg A cipher algorithm (\c PSA_ALG_XXX value such that + * #PSA_ALG_IS_CIPHER(\p alg) is true). + * + * \return The default IV size for the specified key type and algorithm. + * If the algorithm does not use an IV, return 0. + * If the key type or cipher algorithm is not recognized, + * or the parameters are incompatible, return 0. + * An implementation can return either 0 or a correct size for a key type + * and cipher algorithm that it recognizes, but does not support. + */ +#define PSA_CIPHER_IV_LENGTH(key_type, alg) \ + (PSA_BLOCK_CIPHER_BLOCK_SIZE(key_type) > 1 && \ + ((alg) == PSA_ALG_CTR || \ + (alg) == PSA_ALG_CFB || \ + (alg) == PSA_ALG_OFB || \ + (alg) == PSA_ALG_XTS || \ + (alg) == PSA_ALG_CBC_NO_PADDING || \ + (alg) == PSA_ALG_CBC_PKCS7) ? PSA_BLOCK_CIPHER_BLOCK_SIZE(key_type) : \ + (key_type) == PSA_KEY_TYPE_CHACHA20 && \ + (alg) == PSA_ALG_STREAM_CIPHER ? 12 : \ + 0) + +/** The maximum IV size for all supported cipher algorithms, in bytes. + * + * See also #PSA_CIPHER_IV_LENGTH(). + */ +#define PSA_CIPHER_IV_MAX_SIZE 16 + #endif /* PSA_CRYPTO_SIZES_H */ diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_struct.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_struct.h index ac08987ca0..e0ceb2f924 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_struct.h +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_struct.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Arm Limited. All rights reserved. + * Copyright (c) 2018-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -126,11 +126,19 @@ static inline struct psa_client_key_attributes_s psa_key_attributes_init( void ) } static inline void psa_set_key_id(psa_key_attributes_t *attributes, - psa_key_id_t id) + psa_key_id_t key) { - attributes->id = id; - if( attributes->lifetime == PSA_KEY_LIFETIME_VOLATILE ) - attributes->lifetime = PSA_KEY_LIFETIME_PERSISTENT; + psa_key_lifetime_t lifetime = attributes->lifetime; + + attributes->id = key; + + if( PSA_KEY_LIFETIME_IS_VOLATILE(lifetime)) + { + attributes->lifetime = + PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION( + PSA_KEY_LIFETIME_PERSISTENT, + PSA_KEY_LIFETIME_GET_LOCATION(lifetime)); + } } static inline psa_key_id_t psa_get_key_id( @@ -143,7 +151,7 @@ static inline void psa_set_key_lifetime(psa_key_attributes_t *attributes, psa_key_lifetime_t lifetime) { attributes->lifetime = lifetime; - if( lifetime == PSA_KEY_LIFETIME_VOLATILE ) + if(PSA_KEY_LIFETIME_IS_VOLATILE(lifetime)) { attributes->id = 0; } diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_types.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_types.h index 540e49aead..bf51a2fa4e 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_types.h +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_types.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Arm Limited. All rights reserved. + * Copyright (c) 2018-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -49,10 +49,6 @@ typedef int32_t psa_status_t; * @{ */ -/* Integral type representing a key handle. */ -typedef uint16_t psa_key_handle_t; - - /** \brief Encoding of a key type. */ typedef uint16_t psa_key_type_t; @@ -328,7 +324,7 @@ typedef uint32_t psa_key_usage_t; * -# 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. + * outputs a key identifier 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 diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_values.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_values.h index 75e30505d4..9cca6b24cf 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_values.h +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_values.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Arm Limited. All rights reserved. + * Copyright (c) 2018-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -100,7 +100,7 @@ * as applicable. * * Implementations shall not return this error code to indicate that a - * key handle is invalid, but shall return #PSA_ERROR_INVALID_HANDLE + * key identifier is invalid, but shall return #PSA_ERROR_INVALID_HANDLE * instead. */ #define PSA_ERROR_BAD_STATE ((psa_status_t)-137) @@ -110,7 +110,7 @@ * combination of parameters are recognized as invalid. * * Implementations shall not return this error code to indicate that a - * key handle is invalid, but shall return #PSA_ERROR_INVALID_HANDLE + * key identifier is invalid, but shall return #PSA_ERROR_INVALID_HANDLE * instead. */ #define PSA_ERROR_INVALID_ARGUMENT ((psa_status_t)-135) @@ -258,7 +258,7 @@ * to read from a resource. */ #define PSA_ERROR_INSUFFICIENT_DATA ((psa_status_t)-143) -/** The key handle is not valid. See also :ref:\`key-handles\`. +/** The key identifier is not valid. See also :ref:\`key-handles\`. */ #define PSA_ERROR_INVALID_HANDLE ((psa_status_t)-136) @@ -601,14 +601,14 @@ #define PSA_ALG_VENDOR_FLAG ((psa_algorithm_t)0x80000000) #define PSA_ALG_CATEGORY_MASK ((psa_algorithm_t)0x7f000000) -#define PSA_ALG_CATEGORY_HASH ((psa_algorithm_t)0x01000000) -#define PSA_ALG_CATEGORY_MAC ((psa_algorithm_t)0x02000000) +#define PSA_ALG_CATEGORY_HASH ((psa_algorithm_t)0x02000000) +#define PSA_ALG_CATEGORY_MAC ((psa_algorithm_t)0x03000000) #define PSA_ALG_CATEGORY_CIPHER ((psa_algorithm_t)0x04000000) -#define PSA_ALG_CATEGORY_AEAD ((psa_algorithm_t)0x06000000) -#define PSA_ALG_CATEGORY_SIGN ((psa_algorithm_t)0x10000000) -#define PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION ((psa_algorithm_t)0x12000000) -#define PSA_ALG_CATEGORY_KEY_DERIVATION ((psa_algorithm_t)0x20000000) -#define PSA_ALG_CATEGORY_KEY_AGREEMENT ((psa_algorithm_t)0x30000000) +#define PSA_ALG_CATEGORY_AEAD ((psa_algorithm_t)0x05000000) +#define PSA_ALG_CATEGORY_SIGN ((psa_algorithm_t)0x06000000) +#define PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION ((psa_algorithm_t)0x07000000) +#define PSA_ALG_CATEGORY_KEY_DERIVATION ((psa_algorithm_t)0x08000000) +#define PSA_ALG_CATEGORY_KEY_AGREEMENT ((psa_algorithm_t)0x09000000) /** Whether an algorithm is vendor-defined. * @@ -710,35 +710,35 @@ #define PSA_ALG_HASH_MASK ((psa_algorithm_t)0x000000ff) /** MD2 */ -#define PSA_ALG_MD2 ((psa_algorithm_t)0x01000001) +#define PSA_ALG_MD2 ((psa_algorithm_t)0x02000001) /** MD4 */ -#define PSA_ALG_MD4 ((psa_algorithm_t)0x01000002) +#define PSA_ALG_MD4 ((psa_algorithm_t)0x02000002) /** MD5 */ -#define PSA_ALG_MD5 ((psa_algorithm_t)0x01000003) +#define PSA_ALG_MD5 ((psa_algorithm_t)0x02000003) /** PSA_ALG_RIPEMD160 */ -#define PSA_ALG_RIPEMD160 ((psa_algorithm_t)0x01000004) +#define PSA_ALG_RIPEMD160 ((psa_algorithm_t)0x02000004) /** SHA1 */ -#define PSA_ALG_SHA_1 ((psa_algorithm_t)0x01000005) +#define PSA_ALG_SHA_1 ((psa_algorithm_t)0x02000005) /** SHA2-224 */ -#define PSA_ALG_SHA_224 ((psa_algorithm_t)0x01000008) +#define PSA_ALG_SHA_224 ((psa_algorithm_t)0x02000008) /** SHA2-256 */ -#define PSA_ALG_SHA_256 ((psa_algorithm_t)0x01000009) +#define PSA_ALG_SHA_256 ((psa_algorithm_t)0x02000009) /** SHA2-384 */ -#define PSA_ALG_SHA_384 ((psa_algorithm_t)0x0100000a) +#define PSA_ALG_SHA_384 ((psa_algorithm_t)0x0200000a) /** SHA2-512 */ -#define PSA_ALG_SHA_512 ((psa_algorithm_t)0x0100000b) +#define PSA_ALG_SHA_512 ((psa_algorithm_t)0x0200000b) /** SHA2-512/224 */ -#define PSA_ALG_SHA_512_224 ((psa_algorithm_t)0x0100000c) +#define PSA_ALG_SHA_512_224 ((psa_algorithm_t)0x0200000c) /** SHA2-512/256 */ -#define PSA_ALG_SHA_512_256 ((psa_algorithm_t)0x0100000d) +#define PSA_ALG_SHA_512_256 ((psa_algorithm_t)0x0200000d) /** SHA3-224 */ -#define PSA_ALG_SHA3_224 ((psa_algorithm_t)0x01000010) +#define PSA_ALG_SHA3_224 ((psa_algorithm_t)0x02000010) /** SHA3-256 */ -#define PSA_ALG_SHA3_256 ((psa_algorithm_t)0x01000011) +#define PSA_ALG_SHA3_256 ((psa_algorithm_t)0x02000011) /** SHA3-384 */ -#define PSA_ALG_SHA3_384 ((psa_algorithm_t)0x01000012) +#define PSA_ALG_SHA3_384 ((psa_algorithm_t)0x02000012) /** SHA3-512 */ -#define PSA_ALG_SHA3_512 ((psa_algorithm_t)0x01000013) +#define PSA_ALG_SHA3_512 ((psa_algorithm_t)0x02000013) /** In a hash-and-sign algorithm policy, allow any hash algorithm. * @@ -761,9 +761,9 @@ * an algorithm built from `PSA_xxx_SIGNATURE` and a specific hash. Each * call to sign or verify a message may use a different hash. * ``` - * psa_sign_hash(handle, PSA_xxx_SIGNATURE(PSA_ALG_SHA_256), ...); - * psa_sign_hash(handle, PSA_xxx_SIGNATURE(PSA_ALG_SHA_512), ...); - * psa_sign_hash(handle, PSA_xxx_SIGNATURE(PSA_ALG_SHA3_256), ...); + * psa_sign_hash(key, PSA_xxx_SIGNATURE(PSA_ALG_SHA_256), ...); + * psa_sign_hash(key, PSA_xxx_SIGNATURE(PSA_ALG_SHA_512), ...); + * psa_sign_hash(key, PSA_xxx_SIGNATURE(PSA_ALG_SHA3_256), ...); * ``` * * This value may not be used to build other algorithms that are @@ -773,10 +773,10 @@ * This value may not be used to build an algorithm specification to * perform an operation. It is only valid to build policies. */ -#define PSA_ALG_ANY_HASH ((psa_algorithm_t)0x010000ff) +#define PSA_ALG_ANY_HASH ((psa_algorithm_t)0x020000ff) #define PSA_ALG_MAC_SUBCATEGORY_MASK ((psa_algorithm_t)0x00c00000) -#define PSA_ALG_HMAC_BASE ((psa_algorithm_t)0x02800000) +#define PSA_ALG_HMAC_BASE ((psa_algorithm_t)0x03800000) /** Macro to build an HMAC algorithm. * * For example, #PSA_ALG_HMAC(#PSA_ALG_SHA_256) is HMAC-SHA-256. @@ -815,8 +815,8 @@ * reach up to 63; the largest MAC is 64 bytes so its trivial truncation * to full length is correctly encoded as 0 and any non-trivial truncation * is correctly encoded as a value between 1 and 63. */ -#define PSA_ALG_MAC_TRUNCATION_MASK ((psa_algorithm_t)0x00003f00) -#define PSA_MAC_TRUNCATION_OFFSET 8 +#define PSA_ALG_MAC_TRUNCATION_MASK ((psa_algorithm_t)0x003f0000) +#define PSA_MAC_TRUNCATION_OFFSET 16 /** Macro to build a truncated MAC algorithm. * @@ -884,15 +884,15 @@ #define PSA_MAC_TRUNCATED_LENGTH(mac_alg) \ (((mac_alg) & PSA_ALG_MAC_TRUNCATION_MASK) >> PSA_MAC_TRUNCATION_OFFSET) -#define PSA_ALG_CIPHER_MAC_BASE ((psa_algorithm_t)0x02c00000) +#define PSA_ALG_CIPHER_MAC_BASE ((psa_algorithm_t)0x03c00000) /** The CBC-MAC construction over a block cipher * * \warning CBC-MAC is insecure in many cases. * A more secure mode, such as #PSA_ALG_CMAC, is recommended. */ -#define PSA_ALG_CBC_MAC ((psa_algorithm_t)0x02c00001) +#define PSA_ALG_CBC_MAC ((psa_algorithm_t)0x03c00100) /** The CMAC construction over a block cipher */ -#define PSA_ALG_CMAC ((psa_algorithm_t)0x02c00002) +#define PSA_ALG_CMAC ((psa_algorithm_t)0x03c00200) /** Whether the specified algorithm is a MAC algorithm based on a block cipher. * @@ -925,21 +925,13 @@ (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_CIPHER_STREAM_FLAG)) == \ (PSA_ALG_CATEGORY_CIPHER | PSA_ALG_CIPHER_STREAM_FLAG)) -/** The ARC4 stream cipher algorithm. +/** The stream cipher mode of a stream cipher algorithm. + * + * The underlying stream cipher is determined by the key type. + * - To use ChaCha20, use a key type of #PSA_KEY_TYPE_CHACHA20. + * - To use ARC4, use a key type of #PSA_KEY_TYPE_ARC4. */ -#define PSA_ALG_ARC4 ((psa_algorithm_t)0x04800001) - -/** The ChaCha20 stream cipher. - * - * ChaCha20 is defined in RFC 7539. - * - * The nonce size for psa_cipher_set_iv() or psa_cipher_generate_iv() - * must be 12. - * - * The initial block counter is always 0. - * - */ -#define PSA_ALG_CHACHA20 ((psa_algorithm_t)0x04800005) +#define PSA_ALG_STREAM_CIPHER ((psa_algorithm_t)0x04800100) /** The CTR stream cipher mode. * @@ -948,19 +940,19 @@ * For example, to use AES-128-CTR, use this algorithm with * a key of type #PSA_KEY_TYPE_AES and a length of 128 bits (16 bytes). */ -#define PSA_ALG_CTR ((psa_algorithm_t)0x04c00001) +#define PSA_ALG_CTR ((psa_algorithm_t)0x04c01000) /** The CFB stream cipher mode. * * The underlying block cipher is determined by the key type. */ -#define PSA_ALG_CFB ((psa_algorithm_t)0x04c00002) +#define PSA_ALG_CFB ((psa_algorithm_t)0x04c01100) /** The OFB stream cipher mode. * * The underlying block cipher is determined by the key type. */ -#define PSA_ALG_OFB ((psa_algorithm_t)0x04c00003) +#define PSA_ALG_OFB ((psa_algorithm_t)0x04c01200) /** The XTS cipher mode. * @@ -968,7 +960,27 @@ * least one full block of input, but beyond this minimum the input * does not need to be a whole number of blocks. */ -#define PSA_ALG_XTS ((psa_algorithm_t)0x044000ff) +#define PSA_ALG_XTS ((psa_algorithm_t)0x0440ff00) + +/** The Electronic Code Book (ECB) mode of a block cipher, with no padding. + * + * \warning ECB mode does not protect the confidentiality of the encrypted data + * except in extremely narrow circumstances. It is recommended that applications + * only use ECB if they need to construct an operating mode that the + * implementation does not provide. Implementations are encouraged to provide + * the modes that applications need in preference to supporting direct access + * to ECB. + * + * The underlying block cipher is determined by the key type. + * + * This symmetric cipher mode can only be used with messages whose lengths are a + * multiple of the block size of the chosen block cipher. + * + * ECB mode does not accept an initialization vector (IV). When using a + * multi-part cipher operation with this algorithm, psa_cipher_generate_iv() + * and psa_cipher_set_iv() must not be called. + */ +#define PSA_ALG_ECB_NO_PADDING ((psa_algorithm_t)0x04404400) /** The CBC block cipher chaining mode, with no padding. * @@ -977,7 +989,7 @@ * This symmetric cipher mode can only be used with messages whose lengths * are whole number of blocks for the chosen block cipher. */ -#define PSA_ALG_CBC_NO_PADDING ((psa_algorithm_t)0x04600100) +#define PSA_ALG_CBC_NO_PADDING ((psa_algorithm_t)0x04404000) /** The CBC block cipher chaining mode with PKCS#7 padding. * @@ -985,7 +997,7 @@ * * This is the padding method defined by PKCS#7 (RFC 2315) §10.3. */ -#define PSA_ALG_CBC_PKCS7 ((psa_algorithm_t)0x04600101) +#define PSA_ALG_CBC_PKCS7 ((psa_algorithm_t)0x04404100) #define PSA_ALG_AEAD_FROM_BLOCK_FLAG ((psa_algorithm_t)0x00400000) @@ -1006,13 +1018,13 @@ * * The underlying block cipher is determined by the key type. */ -#define PSA_ALG_CCM ((psa_algorithm_t)0x06401001) +#define PSA_ALG_CCM ((psa_algorithm_t)0x05500100) /** The GCM authenticated encryption algorithm. * * The underlying block cipher is determined by the key type. */ -#define PSA_ALG_GCM ((psa_algorithm_t)0x06401002) +#define PSA_ALG_GCM ((psa_algorithm_t)0x05500200) /** The Chacha20-Poly1305 AEAD algorithm. * @@ -1023,14 +1035,14 @@ * * Implementations must support 16-byte tags and should reject other sizes. */ -#define PSA_ALG_CHACHA20_POLY1305 ((psa_algorithm_t)0x06001005) +#define PSA_ALG_CHACHA20_POLY1305 ((psa_algorithm_t)0x05100500) /* In the encoding of a AEAD algorithm, the bits corresponding to * PSA_ALG_AEAD_TAG_LENGTH_MASK encode the length of the AEAD tag. * The constants for default lengths follow this encoding. */ -#define PSA_ALG_AEAD_TAG_LENGTH_MASK ((psa_algorithm_t)0x00003f00) -#define PSA_AEAD_TAG_LENGTH_OFFSET 8 +#define PSA_ALG_AEAD_TAG_LENGTH_MASK ((psa_algorithm_t)0x003f0000) +#define PSA_AEAD_TAG_LENGTH_OFFSET 16 /** Macro to build a shortened AEAD algorithm. * @@ -1074,7 +1086,7 @@ PSA_ALG_AEAD_WITH_TAG_LENGTH(ref, 0) ? \ ref : -#define PSA_ALG_RSA_PKCS1V15_SIGN_BASE ((psa_algorithm_t)0x10020000) +#define PSA_ALG_RSA_PKCS1V15_SIGN_BASE ((psa_algorithm_t)0x06000200) /** RSA PKCS#1 v1.5 signature with hashing. * * This is the signature scheme defined by RFC 8017 @@ -1102,7 +1114,7 @@ #define PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) \ (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PKCS1V15_SIGN_BASE) -#define PSA_ALG_RSA_PSS_BASE ((psa_algorithm_t)0x10030000) +#define PSA_ALG_RSA_PSS_BASE ((psa_algorithm_t)0x06000300) /** RSA PSS signature with hashing. * * This is the signature scheme defined by RFC 8017 @@ -1126,7 +1138,7 @@ #define PSA_ALG_IS_RSA_PSS(alg) \ (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PSS_BASE) -#define PSA_ALG_ECDSA_BASE ((psa_algorithm_t)0x10060000) +#define PSA_ALG_ECDSA_BASE ((psa_algorithm_t)0x06000600) /** ECDSA signature with hashing. * * This is the ECDSA signature scheme defined by ANSI X9.62, @@ -1159,7 +1171,7 @@ * the curve size. */ #define PSA_ALG_ECDSA_ANY PSA_ALG_ECDSA_BASE -#define PSA_ALG_DETERMINISTIC_ECDSA_BASE ((psa_algorithm_t)0x10070000) +#define PSA_ALG_DETERMINISTIC_ECDSA_BASE ((psa_algorithm_t)0x06000700) /** Deterministic ECDSA signature with hashing. * * This is the deterministic ECDSA signature scheme defined by RFC 6979. @@ -1184,7 +1196,7 @@ */ #define PSA_ALG_DETERMINISTIC_ECDSA(hash_alg) \ (PSA_ALG_DETERMINISTIC_ECDSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK)) -#define PSA_ALG_ECDSA_DETERMINISTIC_FLAG ((psa_algorithm_t)0x00010000) +#define PSA_ALG_ECDSA_DETERMINISTIC_FLAG ((psa_algorithm_t)0x00000100) #define PSA_ALG_IS_ECDSA(alg) \ (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_ECDSA_DETERMINISTIC_FLAG) == \ PSA_ALG_ECDSA_BASE) @@ -1238,9 +1250,9 @@ /** RSA PKCS#1 v1.5 encryption. */ -#define PSA_ALG_RSA_PKCS1V15_CRYPT ((psa_algorithm_t)0x12020000) +#define PSA_ALG_RSA_PKCS1V15_CRYPT ((psa_algorithm_t)0x07000200) -#define PSA_ALG_RSA_OAEP_BASE ((psa_algorithm_t)0x12030000) +#define PSA_ALG_RSA_OAEP_BASE ((psa_algorithm_t)0x07000300) /** RSA OAEP encryption. * * This is the encryption scheme defined by RFC 8017 @@ -1264,7 +1276,7 @@ ((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH : \ 0) -#define PSA_ALG_HKDF_BASE ((psa_algorithm_t)0x20000100) +#define PSA_ALG_HKDF_BASE ((psa_algorithm_t)0x08000100) /** Macro to build an HKDF algorithm. * * For example, `PSA_ALG_HKDF(PSA_ALG_SHA256)` is HKDF using HMAC-SHA-256. @@ -1303,7 +1315,7 @@ #define PSA_ALG_HKDF_GET_HASH(hkdf_alg) \ (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK)) -#define PSA_ALG_TLS12_PRF_BASE ((psa_algorithm_t)0x20000200) +#define PSA_ALG_TLS12_PRF_BASE ((psa_algorithm_t)0x08000200) /** Macro to build a TLS-1.2 PRF algorithm. * * TLS 1.2 uses a custom pseudorandom function (PRF) for key schedule, @@ -1346,7 +1358,7 @@ #define PSA_ALG_TLS12_PRF_GET_HASH(hkdf_alg) \ (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK)) -#define PSA_ALG_TLS12_PSK_TO_MS_BASE ((psa_algorithm_t)0x20000300) +#define PSA_ALG_TLS12_PSK_TO_MS_BASE ((psa_algorithm_t)0x08000300) /** Macro to build a TLS-1.2 PSK-to-MasterSecret algorithm. * * In a pure-PSK handshake in TLS 1.2, the master secret is derived @@ -1392,8 +1404,8 @@ #define PSA_ALG_TLS12_PSK_TO_MS_GET_HASH(hkdf_alg) \ (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK)) -#define PSA_ALG_KEY_DERIVATION_MASK ((psa_algorithm_t)0x0803ffff) -#define PSA_ALG_KEY_AGREEMENT_MASK ((psa_algorithm_t)0x10fc0000) +#define PSA_ALG_KEY_DERIVATION_MASK ((psa_algorithm_t)0xfe00ffff) +#define PSA_ALG_KEY_AGREEMENT_MASK ((psa_algorithm_t)0xffff0000) /** Macro to build a combined algorithm that chains a key agreement with * a key derivation. @@ -1424,7 +1436,7 @@ * a key derivation function. * Usually, raw key agreement algorithms are constructed directly with * a \c PSA_ALG_xxx macro while non-raw key agreement algorithms are - * constructed with PSA_ALG_KEY_AGREEMENT(). + * constructed with #PSA_ALG_KEY_AGREEMENT(). * * \param alg An algorithm identifier (value of type #psa_algorithm_t). * @@ -1446,7 +1458,7 @@ * It is `ceiling(m / 8)` bytes long where `m` is the size of the prime `p` * in bits. */ -#define PSA_ALG_FFDH ((psa_algorithm_t)0x30100000) +#define PSA_ALG_FFDH ((psa_algorithm_t)0x09010000) /** Whether the specified algorithm is a finite field Diffie-Hellman algorithm. * @@ -1488,7 +1500,7 @@ * in big-endian byte order. * The bit size is `m` for the field `F_{2^m}`. */ -#define PSA_ALG_ECDH ((psa_algorithm_t)0x30200000) +#define PSA_ALG_ECDH ((psa_algorithm_t)0x09020000) /** Whether the specified algorithm is an elliptic curve Diffie-Hellman * algorithm. @@ -1533,7 +1545,7 @@ /** The default lifetime for volatile keys. * - * A volatile key only exists as long as the handle to it is not closed. + * A volatile key only exists as long as the identifier to it is not destroyed. * The key material is guaranteed to be erased on a power reset. * * A key with this lifetime is typically stored in the RAM area of the @@ -1704,7 +1716,7 @@ * * For a key pair, this concerns the private key. */ -#define PSA_KEY_USAGE_SIGN_HASH ((psa_key_usage_t)0x00000400) +#define PSA_KEY_USAGE_SIGN_HASH ((psa_key_usage_t)0x00001000) /** Whether the key may be used to verify a message signature. * @@ -1714,11 +1726,11 @@ * * For a key pair, this concerns the public key. */ -#define PSA_KEY_USAGE_VERIFY_HASH ((psa_key_usage_t)0x00000800) +#define PSA_KEY_USAGE_VERIFY_HASH ((psa_key_usage_t)0x00002000) /** Whether the key may be used to derive other keys. */ -#define PSA_KEY_USAGE_DERIVE ((psa_key_usage_t)0x00001000) +#define PSA_KEY_USAGE_DERIVE ((psa_key_usage_t)0x00004000) /**@}*/ diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/error.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/error.h index 439dba4b70..e8903f0445 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/error.h +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/error.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Arm Limited. All rights reserved. + * Copyright (c) 2019-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -28,6 +28,8 @@ typedef int32_t psa_status_t; #endif #define PSA_SUCCESS ((psa_status_t)0) +#define PSA_SUCCESS_REBOOT ((psa_status_t)1) +#define PSA_SUCCESS_RESTART ((psa_status_t)2) #define PSA_ERROR_PROGRAMMER_ERROR ((psa_status_t)-129) #define PSA_ERROR_CONNECTION_REFUSED ((psa_status_t)-130) @@ -49,7 +51,8 @@ typedef int32_t psa_status_t; #define PSA_ERROR_STORAGE_FAILURE ((psa_status_t)-146) #define PSA_ERROR_HARDWARE_FAILURE ((psa_status_t)-147) #define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)-149) - +#define PSA_ERROR_DEPENDENCY_NEEDED ((psa_status_t)-156) +#define PSA_ERROR_CURRENTLY_INSTALLING ((psa_status_t)-157) #ifdef __cplusplus } #endif diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/update.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/update.h new file mode 100644 index 0000000000..65d7d2dd60 --- /dev/null +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/update.h @@ -0,0 +1,264 @@ +/* + * Copyright (c) 2021, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +#ifndef PSA_UPDATE_H +#define PSA_UPDATE_H + +#include +#include + +#include "psa/error.h" +#include "tfm_fwu_defs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PSA_FWU_MAX_BLOCK_SIZE 1024 +#define TFM_FWU_INVALID_IMAGE_ID 0 + +/* The maximum size of an image digest in bytes. This is dependent + * on the hash algorithm used. + */ +#define PSA_FWU_MAX_DIGEST_SIZE 32 +#define TFM_IMAGE_INFO_INVALID_DIGEST 0xFF + +/* The image ID macros. */ +#define FWU_IMAGE_ID_SLOT_POSITION 0U + +/* The area where the image is running. */ +#define FWU_IMAGE_ID_SLOT_ACTIVE 0x01U + +/* The area to stage the image. */ +#define FWU_IMAGE_ID_SLOT_STAGE 0x02U +#define FWU_IMAGE_ID_SLOT_MASK 0x00FF + +#define FWU_IMAGE_ID_TYPE_POSITION 8U +#define FWU_IMAGE_ID_SPECIFIC_ID_POSITION 16U + +#define FWU_CALCULATE_IMAGE_ID(slot, type, specific_id) \ + ((slot & FWU_IMAGE_ID_SLOT_MASK) | \ + (type << FWU_IMAGE_ID_TYPE_POSITION) | \ + (specific_id << FWU_IMAGE_ID_SPECIFIC_ID_POSITION)) +#define FWU_IMAGE_ID_GET_TYPE(image_id) (image_id >> FWU_IMAGE_ID_TYPE_POSITION) +#define FWU_IMAGE_ID_GET_SLOT(image_id) (image_id & FWU_IMAGE_ID_SLOT_MASK) + +/* Image state macros. */ +#define PSA_IMAGE_UNDEFINED 0 +#define PSA_IMAGE_CANDIDATE 1 +#define PSA_IMAGE_INSTALLED 2 +#define PSA_IMAGE_REJECTED 3 +#define PSA_IMAGE_PENDING_INSTALL 4 +#define PSA_IMAGE_REBOOT_NEEDED 5 + +/* + * image_id[7:0]: slot. + * image_id[15:8]: image type. + * image_id[31:16]: specific image ID. + */ +typedef uint32_t psa_image_id_t; + +typedef struct tfm_image_version_s { + uint8_t iv_major; + uint8_t iv_minor; + uint16_t iv_revision; + uint32_t iv_build_num; +} psa_image_version_t; + +typedef struct tfm_image_info_s { + psa_image_version_t version; + uint8_t state; + uint8_t digest[PSA_FWU_MAX_DIGEST_SIZE]; +} psa_image_info_t; + +typedef struct psa_hash_s { + uint8_t value[PSA_FWU_MAX_DIGEST_SIZE]; +} psa_hash_t; + +/** + * \brief Writes an image to its staging area. + * + * Writes the image data 'block' with length 'block_size' to its staging area. + * If the image size is less than or equal to PSA_FWU_MAX_BLOCK_SIZE, the + * caller can send the entire image in one call. + * If the image size is greater than PSA_FWU_MAX_BLOCK_SIZE, the caller must + * send parts of the image by calling this API multiple times with different + * data blocks. + * + * \param[in] image_id The identifier of the image + * \param[in] block_offset The offset of the block being passed into block, + * in bytes + * \param[in] block A buffer containing a block of image data. This + * might be a complete image or a subset. + * \param[in] block_size Size of block. The size must not be greater than + * PSA_FWU_MAX_BLOCK_SIZE. + * + * \return A status indicating the success/failure of the operation + * + * \retval PSA_SUCCESS The data in block has been + * successfully stored. + * \retval PSA_ERROR_INVALID_ARGUMENT One of the following error + * conditions occurred: + * The parameter size is greater than + * PSA_FWU_MAX_BLOCK_SIZE; + * The parameter size is 0; + * The combination of offset and size + * is out of bounds. + * + * \retval PSA_ERROR_INSUFFICIENT_MEMORY There is not enough memory to + * process the update + * \retval PSA_ERROR_INSUFFICIENT_STORAGE There is not enough storage to + * process the update + * \retval PSA_ERROR_GENERAL_ERROR A fatal error occurred + * \retval PSA_ERROR_CURRENTLY_INSTALLING The image is currently locked for + * writing. + */ +psa_status_t psa_fwu_write(psa_image_id_t image_id, + size_t block_offset, + const void *block, + size_t block_size); + + +/** + * \brief Starts the installation of an image. + * + * The authenticity and integrity of the image is checked during installation. + * If a reboot is required to complete installation then the implementation + * can choose to defer the authenticity checks to that point. + * + * \param[in] image_id The identifier of the image to install + * \param[out] dependency_uuid If PSA_ERROR_DEPENDENCY_NEEDED is returned, + * this parameter is filled with dependency + * information + * \param[out] dependency_version If PSA_ERROR_DEPENDENCY_NEEDED is returned, + * this parameter is filled with the minimum + * required version for the dependency + * + * \return A status indicating the success/failure of the operation + * + * \retval PSA_SUCCESS The image was successfully + * installed. The platform does not + * require a reboot. + * \retval PSA_SUCCESS_REBOOT A system reboot is needed to finish + * installation. + * \retval PSA_ERROR_INVALID_ARGUMENT Bad input parameter + * \retval PSA_ERROR_INVALID_SIGNATURE The signature is incorrect + * \retval PSA_ERROR_GENERAL_ERROR A fatal error occurred + * \retval PSA_ERROR_DEPENDENCY_NEEDED A different image requires + * installation first + * \retval PSA_ERROR_STORAGE_FAILURE Some persistent storage could not be + * read or written by the + * implementation + */ +psa_status_t psa_fwu_install(psa_image_id_t image_id, + psa_image_id_t *dependency_uuid, + psa_image_version_t *dependency_version); + +/** + * \brief Aborts an ongoing installation and erases the staging area of the + * image. + * + * \param[in] image_id The identifier of the image to abort installation + * + * \return A status indicating the success/failure of the operation + * + * \retval PSA_SUCCESS Installation of the provided image_id + * has been aborted + * \retval PSA_ERROR_INVALID_ARGUMENT No image with the provided image_id + * is currently being installed + * \retval PSA_ERROR_NOT_PERMITTED The caller is not authorized to + * abort an installation + */ +psa_status_t psa_fwu_abort(psa_image_id_t image_id); + +/** + * \brief Returns information for an image of a particular image_id. + * + * \param[in] image_id The image_id of the image to query + * + * \param[out] info Output parameter for image information + * related to the image_id + * + * \return A status indicating the success/failure of the operation + * + * \retval PSA_SUCCESS Image information has been returned + * \retval PSA_ERROR_NOT_PERMITTED The caller is not authorized to + * access platform version information + */ +psa_status_t psa_fwu_query(psa_image_id_t image_id, + psa_image_info_t *info); + +/** + * \brief Requests the platform to reboot. On success, the platform initiates + * a reboot, and might not return to the caller. + * + * \return A status indicating the success/failure of the operation + * + * \retval PSA_SUCCESS The platform will reboot soon + * \retval PSA_ERROR_NOT_PERMITTED The caller is not authorized to + * reboot the platform + */ +psa_status_t psa_fwu_request_reboot(void); + +/** + * \brief Indicates to the implementation that the upgrade was successful. + * + * \return A status indicating the success/failure of the operation + * + * \retval PSA_SUCCESS The image and its dependencies have + * transitioned into a PSA_IMAGE_INSTALLED + * state + * \retval PSA_ERROR_NOT_SUPPORTED The implementation does not support a + * PSA_IMAGE_PENDING_INSTALL state + * \retval PSA_ERROR_NOT_PERMITTED The caller is not permitted to make + * this call + */ +psa_status_t psa_fwu_accept(void); + +/** + * \brief Stores a manifest object and associates it with a particular image ID. + * + * \param[in] image_id The identifier of the image + * + * \param[in] manifest A pointer to a buffer containing a manifest + * object + * + * \param[in] manifest_size The size of the manifest parameter + * + * \param[in] manifest_dependency Output parameter containing the hash of a + * required manifest when + * PSA_ERROR_DEPENDENCY_NEEDED is returned + * + * \return A status indicating the success/failure of the operation + * + * \retval PSA_SUCCESS The manifest is persisted + * \retval PSA_ERROR_NOT_PERMITTED The manifest is too old to be + * installed + * \retval PSA_ERROR_WRONG_DEVICE The manifest is not intended for this + * device + * \retval PSA_ERROR_INVALID_SIGNATURE The manifest signature is not valid + * \retval PSA_ERROR_DEPENDENCY_NEEDED A different manifest is needed + * \retval PSA_ERROR_INVALID_ARGUMENT Parameter size is 0 or a pointer + * parameter is NULL + * \retval PSA_ERROR_COMMUNICATION_FAILURE The system could not communicate with + * the installer + * \retval PSA_ERROR_NOT_SUPPORTED This function is not implemented + * \retval PSA_ERROR_CURRENTLY_INSTALLING An existing manifest for image ID is + * currently being installed and is + * locked from writing + * \retval PSA_ERROR_GENERIC_ERROR A fatal error occurred + */ +psa_status_t psa_fwu_set_manifest(psa_image_id_t image_id, + const void *manifest, + size_t manifest_size, + psa_hash_t *manifest_dependency); + + +#ifdef __cplusplus +} +#endif +#endif /* PSA_UPDATE_H */ diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa_manifest/sid.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa_manifest/sid.h index 87d6186be3..b896486056 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa_manifest/sid.h +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa_manifest/sid.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020, Arm Limited. All rights reserved. + * Copyright (c) 2019-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -119,6 +119,8 @@ extern "C" { #define IPC_CLIENT_TEST_APP_ACCESS_PSA_MEM_VERSION (1U) #define IPC_CLIENT_TEST_MEM_CHECK_SID (0x0000F064U) #define IPC_CLIENT_TEST_MEM_CHECK_VERSION (1U) +#define IPC_CLIENT_TEST_RETRIEVE_APP_MEM_SID (0x0000F065U) +#define IPC_CLIENT_TEST_RETRIEVE_APP_MEM_VERSION (1U) /******** TFM_IRQ_TEST_1 ********/ #define SPM_CORE_IRQ_TEST_1_PREPARE_TEST_SCENARIO_SID (0x0000F0A0U) @@ -134,6 +136,65 @@ extern "C" { #define TFM_SECURE_CLIENT_2_SID (0x0000F0E0U) #define TFM_SECURE_CLIENT_2_VERSION (1U) +/******** TFM_SP_PSA_PROXY ********/ +#define TFM_CRYPTO_SID (0x00000080U) +#define TFM_CRYPTO_VERSION (1U) +#define TFM_ATTEST_GET_TOKEN_SID (0x00000020U) +#define TFM_ATTEST_GET_TOKEN_VERSION (1U) +#define TFM_ATTEST_GET_TOKEN_SIZE_SID (0x00000021U) +#define TFM_ATTEST_GET_TOKEN_SIZE_VERSION (1U) +#define TFM_ATTEST_GET_PUBLIC_KEY_SID (0x00000022U) +#define TFM_ATTEST_GET_PUBLIC_KEY_VERSION (1U) +#define TFM_ITS_SET_SID (0x00000070U) +#define TFM_ITS_SET_VERSION (1U) +#define TFM_ITS_GET_SID (0x00000071U) +#define TFM_ITS_GET_VERSION (1U) +#define TFM_ITS_GET_INFO_SID (0x00000072U) +#define TFM_ITS_GET_INFO_VERSION (1U) +#define TFM_ITS_REMOVE_SID (0x00000073U) +#define TFM_ITS_REMOVE_VERSION (1U) +#define TFM_SP_PLATFORM_SYSTEM_RESET_SID (0x00000040U) +#define TFM_SP_PLATFORM_SYSTEM_RESET_VERSION (1U) +#define TFM_SP_PLATFORM_IOCTL_SID (0x00000041U) +#define TFM_SP_PLATFORM_IOCTL_VERSION (1U) +#define TFM_SP_PLATFORM_NV_COUNTER_SID (0x00000042U) +#define TFM_SP_PLATFORM_NV_COUNTER_VERSION (1U) +#define TFM_PS_SET_SID (0x00000060U) +#define TFM_PS_SET_VERSION (1U) +#define TFM_PS_GET_SID (0x00000061U) +#define TFM_PS_GET_VERSION (1U) +#define TFM_PS_GET_INFO_SID (0x00000062U) +#define TFM_PS_GET_INFO_VERSION (1U) +#define TFM_PS_REMOVE_SID (0x00000063U) +#define TFM_PS_REMOVE_VERSION (1U) +#define TFM_PS_GET_SUPPORT_SID (0x00000064U) +#define TFM_PS_GET_SUPPORT_VERSION (1U) + +/******** TFM_SP_FWU ********/ +#define TFM_FWU_WRITE_SID (0x000000A0U) +#define TFM_FWU_WRITE_VERSION (1U) +#define TFM_FWU_INSTALL_SID (0x000000A1U) +#define TFM_FWU_INSTALL_VERSION (1U) +#define TFM_FWU_ABORT_SID (0x000000A2U) +#define TFM_FWU_ABORT_VERSION (1U) +#define TFM_FWU_QUERY_SID (0x000000A3U) +#define TFM_FWU_QUERY_VERSION (1U) +#define TFM_FWU_REQUEST_REBOOT_SID (0x000000A4U) +#define TFM_FWU_REQUEST_REBOOT_VERSION (1U) +#define TFM_FWU_ACCEPT_SID (0x000000A5U) +#define TFM_FWU_ACCEPT_VERSION (1U) + +/******** TFM_SP_FFM11 ********/ +#define TFM_FFM11_SERVICE1_SID (0x0000F120U) +#define TFM_FFM11_SERVICE1_VERSION (1U) +#define TFM_FFM11_SERVICE1_HANDLE (0x40000104U) +#define TFM_FFM11_SERVICE2_SID (0x0000F121U) +#define TFM_FFM11_SERVICE2_VERSION (1U) +#define TFM_FFM11_SERVICE2_HANDLE (0x40000101U) +#define TFM_FFM11_SERVICE3_SID (0x0000F122U) +#define TFM_FFM11_SERVICE3_VERSION (1U) +#define TFM_FFM11_SERVICE3_HANDLE (0x40000103U) + #ifdef __cplusplus } #endif diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/tfm_api.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/tfm_api.h index 883eb5b8c9..fea18cd59a 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/tfm_api.h +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/tfm_api.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020, Arm Limited. All rights reserved. + * Copyright (c) 2017-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -115,7 +115,7 @@ psa_handle_t tfm_psa_connect_veneer(uint32_t sid, uint32_t version); * \param[in] ctrl_param Parameter structure, includes request type, * in_num and out_num. * \param[in] in_vec Array of input \ref psa_invec structures. - * \param[in/out] out_vec Array of output \ref psa_outvec structures. + * \param[in,out] out_vec Array of output \ref psa_outvec structures. * * \return Returns \ref psa_status_t status code. */ @@ -128,8 +128,6 @@ psa_status_t tfm_psa_call_veneer(psa_handle_t handle, * \brief Close connection to secure function referenced by a connection handle. * * \param[in] handle Handle to connection - * - * \return void */ void tfm_psa_close_veneer(psa_handle_t handle); diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/tfm_crypto_defs.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/tfm_crypto_defs.h index dd45e3b62d..b4c771f2df 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/tfm_crypto_defs.h +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/tfm_crypto_defs.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Arm Limited. All rights reserved. + * Copyright (c) 2018-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -38,9 +38,8 @@ struct tfm_crypto_pack_iovec { * request */ uint16_t step; /*!< Key derivation step */ - psa_key_handle_t key_handle; /*!< Key handle */ + psa_key_id_t key_id; /*!< Key id */ psa_algorithm_t alg; /*!< Algorithm */ - psa_algorithm_t alg2; /*!< Enrollment Algorithm */ uint32_t op_handle; /*!< Frontend context handle associated to a * multipart operation */ @@ -65,6 +64,7 @@ enum { TFM_CRYPTO_DESTROY_KEY_SID, TFM_CRYPTO_EXPORT_KEY_SID, TFM_CRYPTO_EXPORT_PUBLIC_KEY_SID, + TFM_CRYPTO_PURGE_KEY_SID, TFM_CRYPTO_COPY_KEY_SID, TFM_CRYPTO_HASH_COMPUTE_SID, TFM_CRYPTO_HASH_COMPARE_SID, diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/tfm_fwu_defs.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/tfm_fwu_defs.h new file mode 100644 index 0000000000..9041fd3fc1 --- /dev/null +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/tfm_fwu_defs.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2021, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +#ifndef TFM_FWU_BOOTLOADER_DEFS_H +#define TFM_FWU_BOOTLOADER_DEFS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Image type identities. When porting a specific bootloader to FWU partition, + * the bootloader specific image types can be defined here. + */ +#define FWU_IMAGE_TYPE_NONSECURE 0x01U +#define FWU_IMAGE_TYPE_SECURE 0x02U +#define FWU_IMAGE_TYPE_FULL 0x03U + +#ifdef __cplusplus +} +#endif +#endif /* TFM_FWU_BOOTLOADER_DEFS_H */ diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/tfm_ns_interface.h b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/tfm_ns_interface.h index 21857bed6f..1dd0692571 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/tfm_ns_interface.h +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/tfm_ns_interface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019, Arm Limited. All rights reserved. + * Copyright (c) 2017-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -31,6 +31,10 @@ typedef int32_t (*veneer_fn) (uint32_t arg0, uint32_t arg1, * \param[in] arg3 Argument 3 * * \return Returns the same return value of the requested veneer function + * + * \note This API must ensure the return value is from the veneer function. + * Other unrecoverable errors must be considered as fatal error and should + * not return. */ int32_t tfm_ns_interface_dispatch(veneer_fn fn, uint32_t arg0, uint32_t arg1, diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/src/os_wrapper_cmsis_rtos_v2.c b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/src/os_wrapper_cmsis_rtos_v2.c index 9892290c73..810a244235 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/src/os_wrapper_cmsis_rtos_v2.c +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/src/os_wrapper_cmsis_rtos_v2.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020, Arm Limited. All rights reserved. + * Copyright (c) 2017-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -215,3 +215,38 @@ uint32_t os_wrapper_get_tick(void) { return osKernelGetTickCount(); } + +void *os_wrapper_msg_queue_create(size_t msg_size, uint8_t msg_count) +{ + osMessageQueueId_t mq_id; + + mq_id = osMessageQueueNew(msg_count, msg_size, NULL); + + return (void *)mq_id; +} + +int32_t os_wrapper_msg_queue_send(void *mq_handle, + const void *msg_ptr) +{ + osStatus_t status; + + status = osMessageQueuePut(mq_handle, msg_ptr, 0, 0); + if (status == osOK) { + return OS_WRAPPER_SUCCESS; + } + + return OS_WRAPPER_ERROR; +} + +int32_t os_wrapper_msg_queue_receive(void *mq_handle, + void *msg_ptr) +{ + osStatus_t status; + + status = osMessageQueueGet(mq_handle, msg_ptr, NULL, osWaitForever); + if (status == osOK) { + return OS_WRAPPER_SUCCESS; + } + + return OS_WRAPPER_ERROR; +} diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/src/tfm_crypto_ipc_api.c b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/src/tfm_crypto_ipc_api.c index 1e4df7c02d..a89dd2b9ca 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/src/tfm_crypto_ipc_api.c +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/src/tfm_crypto_ipc_api.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Arm Limited. All rights reserved. + * Copyright (c) 2018-2021, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause * @@ -41,11 +41,8 @@ psa_status_t psa_crypto_init(void) } psa_status_t psa_open_key(psa_key_id_t id, - psa_key_handle_t *handle) + psa_key_id_t *key) { -#ifdef TFM_CRYPTO_KEY_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; const struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_OPEN_KEY_SID, @@ -55,7 +52,7 @@ psa_status_t psa_open_key(psa_key_id_t id, {.base = &id, .len = sizeof(psa_key_id_t)}, }; psa_outvec out_vec[] = { - {.base = handle, .len = sizeof(psa_key_handle_t)}, + {.base = key, .len = sizeof(psa_key_id_t)}, }; PSA_CONNECT(TFM_CRYPTO); @@ -66,18 +63,14 @@ psa_status_t psa_open_key(psa_key_id_t id, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */ } -psa_status_t psa_close_key(psa_key_handle_t handle) +psa_status_t psa_close_key(psa_key_id_t key) { -#ifdef TFM_CRYPTO_KEY_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; const struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_CLOSE_KEY_SID, - .key_handle = handle, + .key_id = key, }; psa_invec in_vec[] = { {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)}, @@ -91,17 +84,13 @@ psa_status_t psa_close_key(psa_key_handle_t handle) PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */ } psa_status_t psa_import_key(const psa_key_attributes_t *attributes, const uint8_t *data, size_t data_length, - psa_key_handle_t *handle) + psa_key_id_t *key) { -#ifdef TFM_CRYPTO_KEY_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_IMPORT_KEY_SID, @@ -112,7 +101,7 @@ psa_status_t psa_import_key(const psa_key_attributes_t *attributes, {.base = data, .len = data_length} }; psa_outvec out_vec[] = { - {.base = handle, .len = sizeof(psa_key_handle_t)} + {.base = key, .len = sizeof(psa_key_id_t)} }; PSA_CONNECT(TFM_CRYPTO); @@ -122,18 +111,14 @@ psa_status_t psa_import_key(const psa_key_attributes_t *attributes, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */ } -psa_status_t psa_destroy_key(psa_key_handle_t handle) +psa_status_t psa_destroy_key(psa_key_id_t key) { -#ifdef TFM_CRYPTO_KEY_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_DESTROY_KEY_SID, - .key_handle = handle, + .key_id = key, }; psa_invec in_vec[] = { {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)}, @@ -146,19 +131,15 @@ psa_status_t psa_destroy_key(psa_key_handle_t handle) PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */ } -psa_status_t psa_get_key_attributes(psa_key_handle_t handle, +psa_status_t psa_get_key_attributes(psa_key_id_t key, psa_key_attributes_t *attributes) { -#ifdef TFM_CRYPTO_KEY_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_GET_KEY_ATTRIBUTES_SID, - .key_handle = handle, + .key_id = key, }; psa_invec in_vec[] = { {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)}, @@ -174,14 +155,10 @@ psa_status_t psa_get_key_attributes(psa_key_handle_t handle, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */ } void psa_reset_key_attributes(psa_key_attributes_t *attributes) { -#ifdef TFM_CRYPTO_KEY_MODULE_DISABLED - return; -#else struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_RESET_KEY_ATTRIBUTES_SID, }; @@ -203,21 +180,17 @@ void psa_reset_key_attributes(psa_key_attributes_t *attributes) PSA_CLOSE(); return; -#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */ } -psa_status_t psa_export_key(psa_key_handle_t handle, +psa_status_t psa_export_key(psa_key_id_t key, uint8_t *data, size_t data_size, size_t *data_length) { -#ifdef TFM_CRYPTO_KEY_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_EXPORT_KEY_SID, - .key_handle = handle, + .key_id = key, }; psa_invec in_vec[] = { {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)}, @@ -236,21 +209,17 @@ psa_status_t psa_export_key(psa_key_handle_t handle, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */ } -psa_status_t psa_export_public_key(psa_key_handle_t handle, +psa_status_t psa_export_public_key(psa_key_id_t key, uint8_t *data, size_t data_size, size_t *data_length) { -#ifdef TFM_CRYPTO_KEY_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_EXPORT_PUBLIC_KEY_SID, - .key_handle = handle, + .key_id = key, }; psa_invec in_vec[] = { @@ -270,20 +239,37 @@ psa_status_t psa_export_public_key(psa_key_handle_t handle, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */ } -psa_status_t psa_copy_key(psa_key_handle_t source_handle, - const psa_key_attributes_t *attributes, - psa_key_handle_t *target_handle) +psa_status_t psa_purge_key(psa_key_id_t key) +{ + psa_status_t status; + struct tfm_crypto_pack_iovec iov = { + .sfn_id = TFM_CRYPTO_PURGE_KEY_SID, + .key_id = key, + }; + psa_invec in_vec[] = { + {.base = &iov, .len = sizeof(struct tfm_crypto_pack_iovec)}, + }; + + PSA_CONNECT(TFM_CRYPTO); + + status = API_DISPATCH_NO_OUTVEC(tfm_crypto_purge_key, + TFM_CRYPTO_PURGE_KEY); + + PSA_CLOSE(); + + return status; +} + +psa_status_t psa_copy_key(psa_key_id_t source_key, + const psa_key_attributes_t *attributes, + psa_key_id_t *target_key) { -#ifdef TFM_CRYPTO_KEY_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_COPY_KEY_SID, - .key_handle = source_handle, + .key_id = source_key, }; psa_invec in_vec[] = { @@ -293,7 +279,7 @@ psa_status_t psa_copy_key(psa_key_handle_t source_handle, }; psa_outvec out_vec[] = { - {.base = target_handle, .len = sizeof(psa_key_handle_t)}, + {.base = target_key, .len = sizeof(psa_key_id_t)}, }; PSA_CONNECT(TFM_CRYPTO); @@ -304,7 +290,6 @@ psa_status_t psa_copy_key(psa_key_handle_t source_handle, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */ } psa_status_t psa_cipher_generate_iv(psa_cipher_operation_t *operation, @@ -312,9 +297,6 @@ psa_status_t psa_cipher_generate_iv(psa_cipher_operation_t *operation, size_t iv_size, size_t *iv_length) { -#ifdef TFM_CRYPTO_CIPHER_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_CIPHER_GENERATE_IV_SID, @@ -339,16 +321,12 @@ psa_status_t psa_cipher_generate_iv(psa_cipher_operation_t *operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */ } psa_status_t psa_cipher_set_iv(psa_cipher_operation_t *operation, const unsigned char *iv, size_t iv_length) { -#ifdef TFM_CRYPTO_CIPHER_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_CIPHER_SET_IV_SID, @@ -371,20 +349,16 @@ psa_status_t psa_cipher_set_iv(psa_cipher_operation_t *operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */ } psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation, - psa_key_handle_t handle, + psa_key_id_t key, psa_algorithm_t alg) { -#ifdef TFM_CRYPTO_CIPHER_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_CIPHER_ENCRYPT_SETUP_SID, - .key_handle = handle, + .key_id = key, .alg = alg, .op_handle = operation->handle, }; @@ -404,20 +378,16 @@ psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */ } psa_status_t psa_cipher_decrypt_setup(psa_cipher_operation_t *operation, - psa_key_handle_t handle, + psa_key_id_t key, psa_algorithm_t alg) { -#ifdef TFM_CRYPTO_CIPHER_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_CIPHER_DECRYPT_SETUP_SID, - .key_handle = handle, + .key_id = key, .alg = alg, .op_handle = operation->handle, }; @@ -437,7 +407,6 @@ psa_status_t psa_cipher_decrypt_setup(psa_cipher_operation_t *operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */ } psa_status_t psa_cipher_update(psa_cipher_operation_t *operation, @@ -447,9 +416,6 @@ psa_status_t psa_cipher_update(psa_cipher_operation_t *operation, size_t output_size, size_t *output_length) { -#ifdef TFM_CRYPTO_CIPHER_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_CIPHER_UPDATE_SID, @@ -475,14 +441,10 @@ psa_status_t psa_cipher_update(psa_cipher_operation_t *operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */ } psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation) { -#ifdef TFM_CRYPTO_CIPHER_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_CIPHER_ABORT_SID, @@ -504,7 +466,6 @@ psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation) PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */ } psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation, @@ -512,9 +473,6 @@ psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation, size_t output_size, size_t *output_length) { -#ifdef TFM_CRYPTO_CIPHER_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_CIPHER_FINISH_SID, @@ -539,15 +497,11 @@ psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_CIPHER_MODULE_DISABLED */ } psa_status_t psa_hash_setup(psa_hash_operation_t *operation, psa_algorithm_t alg) { -#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_HASH_SETUP_SID, @@ -570,16 +524,12 @@ psa_status_t psa_hash_setup(psa_hash_operation_t *operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */ } psa_status_t psa_hash_update(psa_hash_operation_t *operation, const uint8_t *input, size_t input_length) { -#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_HASH_UPDATE_SID, @@ -602,7 +552,6 @@ psa_status_t psa_hash_update(psa_hash_operation_t *operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */ } psa_status_t psa_hash_finish(psa_hash_operation_t *operation, @@ -610,9 +559,6 @@ psa_status_t psa_hash_finish(psa_hash_operation_t *operation, size_t hash_size, size_t *hash_length) { -#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_HASH_FINISH_SID, @@ -637,16 +583,12 @@ psa_status_t psa_hash_finish(psa_hash_operation_t *operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */ } psa_status_t psa_hash_verify(psa_hash_operation_t *operation, const uint8_t *hash, size_t hash_length) { -#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_HASH_VERIFY_SID, @@ -669,14 +611,10 @@ psa_status_t psa_hash_verify(psa_hash_operation_t *operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */ } psa_status_t psa_hash_abort(psa_hash_operation_t *operation) { -#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_HASH_ABORT_SID, @@ -698,15 +636,11 @@ psa_status_t psa_hash_abort(psa_hash_operation_t *operation) PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */ } psa_status_t psa_hash_clone(const psa_hash_operation_t *source_operation, psa_hash_operation_t *target_operation) { -#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_HASH_CLONE_SID, @@ -732,7 +666,6 @@ psa_status_t psa_hash_clone(const psa_hash_operation_t *source_operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */ } psa_status_t psa_hash_compute(psa_algorithm_t alg, @@ -742,9 +675,6 @@ psa_status_t psa_hash_compute(psa_algorithm_t alg, size_t hash_size, size_t *hash_length) { -#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_HASH_COMPUTE_SID, @@ -770,7 +700,6 @@ psa_status_t psa_hash_compute(psa_algorithm_t alg, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */ } psa_status_t psa_hash_compare(psa_algorithm_t alg, @@ -779,9 +708,6 @@ psa_status_t psa_hash_compare(psa_algorithm_t alg, const uint8_t *hash, size_t hash_length) { -#ifdef TFM_CRYPTO_HASH_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_HASH_COMPARE_SID, @@ -802,22 +728,16 @@ psa_status_t psa_hash_compare(psa_algorithm_t alg, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_HASH_MODULE_DISABLED */ } - - psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation, - psa_key_handle_t handle, + psa_key_id_t key, psa_algorithm_t alg) { -#ifdef TFM_CRYPTO_MAC_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_MAC_SIGN_SETUP_SID, - .key_handle = handle, + .key_id = key, .alg = alg, .op_handle = operation->handle, }; @@ -837,20 +757,16 @@ psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_MAC_MODULE_DISABLED */ } psa_status_t psa_mac_verify_setup(psa_mac_operation_t *operation, - psa_key_handle_t handle, + psa_key_id_t key, psa_algorithm_t alg) { -#ifdef TFM_CRYPTO_MAC_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_MAC_VERIFY_SETUP_SID, - .key_handle = handle, + .key_id = key, .alg = alg, .op_handle = operation->handle, }; @@ -870,16 +786,12 @@ psa_status_t psa_mac_verify_setup(psa_mac_operation_t *operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_MAC_MODULE_DISABLED */ } psa_status_t psa_mac_update(psa_mac_operation_t *operation, const uint8_t *input, size_t input_length) { -#ifdef TFM_CRYPTO_MAC_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_MAC_UPDATE_SID, @@ -902,7 +814,6 @@ psa_status_t psa_mac_update(psa_mac_operation_t *operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_MAC_MODULE_DISABLED */ } psa_status_t psa_mac_sign_finish(psa_mac_operation_t *operation, @@ -910,9 +821,6 @@ psa_status_t psa_mac_sign_finish(psa_mac_operation_t *operation, size_t mac_size, size_t *mac_length) { -#ifdef TFM_CRYPTO_MAC_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_MAC_SIGN_FINISH_SID, @@ -937,16 +845,12 @@ psa_status_t psa_mac_sign_finish(psa_mac_operation_t *operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_MAC_MODULE_DISABLED */ } psa_status_t psa_mac_verify_finish(psa_mac_operation_t *operation, const uint8_t *mac, size_t mac_length) { -#ifdef TFM_CRYPTO_MAC_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_MAC_VERIFY_FINISH_SID, @@ -969,14 +873,10 @@ psa_status_t psa_mac_verify_finish(psa_mac_operation_t *operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_MAC_MODULE_DISABLED */ } psa_status_t psa_mac_abort(psa_mac_operation_t *operation) { -#ifdef TFM_CRYPTO_MAC_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_MAC_ABORT_SID, @@ -998,10 +898,9 @@ psa_status_t psa_mac_abort(psa_mac_operation_t *operation) PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_MAC_MODULE_DISABLED */ } -psa_status_t psa_aead_encrypt(psa_key_handle_t handle, +psa_status_t psa_aead_encrypt(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *nonce, size_t nonce_length, @@ -1013,13 +912,10 @@ psa_status_t psa_aead_encrypt(psa_key_handle_t handle, size_t ciphertext_size, size_t *ciphertext_length) { -#ifdef TFM_CRYPTO_AEAD_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_AEAD_ENCRYPT_SID, - .key_handle = handle, + .key_id = key, .alg = alg, .aead_in = {.nonce = {0}, .nonce_length = nonce_length} }; @@ -1063,10 +959,9 @@ psa_status_t psa_aead_encrypt(psa_key_handle_t handle, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_AEAD_MODULE_DISABLED */ } -psa_status_t psa_aead_decrypt(psa_key_handle_t handle, +psa_status_t psa_aead_decrypt(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *nonce, size_t nonce_length, @@ -1078,13 +973,10 @@ psa_status_t psa_aead_decrypt(psa_key_handle_t handle, size_t plaintext_size, size_t *plaintext_length) { -#ifdef TFM_CRYPTO_AEAD_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_AEAD_DECRYPT_SID, - .key_handle = handle, + .key_id = key, .alg = alg, .aead_in = {.nonce = {0}, .nonce_length = nonce_length} }; @@ -1128,10 +1020,9 @@ psa_status_t psa_aead_decrypt(psa_key_handle_t handle, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_AEAD_MODULE_DISABLED */ } -psa_status_t psa_asymmetric_sign(psa_key_handle_t handle, +psa_status_t psa_asymmetric_sign(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, @@ -1139,10 +1030,10 @@ psa_status_t psa_asymmetric_sign(psa_key_handle_t handle, size_t signature_size, size_t *signature_length) { - return psa_sign_hash(handle, alg, hash, hash_length, signature, signature_size, signature_length); + return psa_sign_hash(key, alg, hash, hash_length, signature, signature_size, signature_length); } -psa_status_t psa_sign_hash(psa_key_handle_t handle, +psa_status_t psa_sign_hash(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, @@ -1150,13 +1041,10 @@ psa_status_t psa_sign_hash(psa_key_handle_t handle, size_t signature_size, size_t *signature_length) { -#ifdef TFM_CRYPTO_ASYMMETRIC_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_SIGN_HASH_SID, - .key_handle = handle, + .key_id = key, .alg = alg, }; @@ -1178,33 +1066,29 @@ psa_status_t psa_sign_hash(psa_key_handle_t handle, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_ASYMMETRIC_MODULE_DISABLED */ } -psa_status_t psa_asymmetric_verify(psa_key_handle_t handle, +psa_status_t psa_asymmetric_verify(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, const uint8_t *signature, size_t signature_length) { - return psa_verify_hash(handle, alg, hash, hash_length, signature, signature_length); + return psa_verify_hash(key, alg, hash, hash_length, signature, signature_length); } -psa_status_t psa_verify_hash(psa_key_handle_t handle, +psa_status_t psa_verify_hash(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, const uint8_t *signature, size_t signature_length) { -#ifdef TFM_CRYPTO_ASYMMETRIC_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_VERIFY_HASH_SID, - .key_handle = handle, + .key_id = key, .alg = alg }; @@ -1222,10 +1106,9 @@ psa_status_t psa_verify_hash(psa_key_handle_t handle, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_ASYMMETRIC_MODULE_DISABLED */ } -psa_status_t psa_asymmetric_encrypt(psa_key_handle_t handle, +psa_status_t psa_asymmetric_encrypt(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, @@ -1235,13 +1118,10 @@ psa_status_t psa_asymmetric_encrypt(psa_key_handle_t handle, size_t output_size, size_t *output_length) { -#ifdef TFM_CRYPTO_ASYMMETRIC_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_ASYMMETRIC_ENCRYPT_SID, - .key_handle = handle, + .key_id = key, .alg = alg }; @@ -1274,10 +1154,9 @@ psa_status_t psa_asymmetric_encrypt(psa_key_handle_t handle, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_ASYMMETRIC_MODULE_DISABLED */ } -psa_status_t psa_asymmetric_decrypt(psa_key_handle_t handle, +psa_status_t psa_asymmetric_decrypt(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, @@ -1287,13 +1166,10 @@ psa_status_t psa_asymmetric_decrypt(psa_key_handle_t handle, size_t output_size, size_t *output_length) { -#ifdef TFM_CRYPTO_ASYMMETRIC_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_ASYMMETRIC_DECRYPT_SID, - .key_handle = handle, + .key_id = key, .alg = alg }; @@ -1326,16 +1202,12 @@ psa_status_t psa_asymmetric_decrypt(psa_key_handle_t handle, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_ASYMMETRIC_MODULE_DISABLED */ } psa_status_t psa_key_derivation_get_capacity( const psa_key_derivation_operation_t *operation, size_t *capacity) { -#ifdef TFM_CRYPTO_GENERATOR_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_KEY_DERIVATION_GET_CAPACITY_SID, @@ -1358,7 +1230,6 @@ psa_status_t psa_key_derivation_get_capacity( PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_GENERATOR_MODULE_DISABLED */ } psa_status_t psa_key_derivation_output_bytes( @@ -1366,9 +1237,6 @@ psa_status_t psa_key_derivation_output_bytes( uint8_t *output, size_t output_length) { -#ifdef TFM_CRYPTO_GENERATOR_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES_SID, @@ -1391,21 +1259,17 @@ psa_status_t psa_key_derivation_output_bytes( PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_GENERATOR_MODULE_DISABLED */ } psa_status_t psa_key_derivation_input_key( psa_key_derivation_operation_t *operation, psa_key_derivation_step_t step, - psa_key_handle_t handle) + psa_key_id_t key) { -#ifdef TFM_CRYPTO_GENERATOR_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_KEY_DERIVATION_INPUT_KEY_SID, - .key_handle = handle, + .key_id = key, .step = step, .op_handle = operation->handle, }; @@ -1422,15 +1286,11 @@ psa_status_t psa_key_derivation_input_key( PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_GENERATOR_MODULE_DISABLED */ } psa_status_t psa_key_derivation_abort( psa_key_derivation_operation_t *operation) { -#ifdef TFM_CRYPTO_GENERATOR_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_KEY_DERIVATION_ABORT_SID, @@ -1453,23 +1313,19 @@ psa_status_t psa_key_derivation_abort( PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_GENERATOR_MODULE_DISABLED */ } psa_status_t psa_key_derivation_key_agreement( psa_key_derivation_operation_t *operation, psa_key_derivation_step_t step, - psa_key_handle_t private_key, + psa_key_id_t private_key, const uint8_t *peer_key, size_t peer_key_length) { -#ifdef TFM_CRYPTO_GENERATOR_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_KEY_DERIVATION_KEY_AGREEMENT_SID, - .key_handle = private_key, + .key_id = private_key, .step = step, .op_handle = operation->handle, }; @@ -1487,15 +1343,11 @@ psa_status_t psa_key_derivation_key_agreement( PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_GENERATOR_MODULE_DISABLED */ } psa_status_t psa_generate_random(uint8_t *output, size_t output_size) { -#ifdef TFM_CRYPTO_GENERATOR_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_GENERATE_RANDOM_SID, @@ -1521,15 +1373,11 @@ psa_status_t psa_generate_random(uint8_t *output, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_GENERATOR_MODULE_DISABLED */ } psa_status_t psa_generate_key(const psa_key_attributes_t *attributes, - psa_key_handle_t *handle) + psa_key_id_t *key) { -#ifdef TFM_CRYPTO_GENERATOR_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_GENERATE_KEY_SID, @@ -1541,7 +1389,7 @@ psa_status_t psa_generate_key(const psa_key_attributes_t *attributes, }; psa_outvec out_vec[] = { - {.base = handle, .len = sizeof(psa_key_handle_t)}, + {.base = key, .len = sizeof(psa_key_id_t)}, }; PSA_CONNECT(TFM_CRYPTO); @@ -1551,7 +1399,6 @@ psa_status_t psa_generate_key(const psa_key_attributes_t *attributes, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_GENERATOR_MODULE_DISABLED */ } psa_status_t psa_set_key_domain_parameters(psa_key_attributes_t *attributes, @@ -1628,7 +1475,7 @@ psa_status_t psa_aead_abort(psa_aead_operation_t *operation) return status; } -psa_status_t psa_mac_compute(psa_key_handle_t handle, +psa_status_t psa_mac_compute(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, @@ -1643,7 +1490,7 @@ psa_status_t psa_mac_compute(psa_key_handle_t handle, return status; } -psa_status_t psa_mac_verify(psa_key_handle_t handle, +psa_status_t psa_mac_verify(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, @@ -1657,7 +1504,7 @@ psa_status_t psa_mac_verify(psa_key_handle_t handle, return status; } -psa_status_t psa_cipher_encrypt(psa_key_handle_t handle, +psa_status_t psa_cipher_encrypt(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, @@ -1672,7 +1519,7 @@ psa_status_t psa_cipher_encrypt(psa_key_handle_t handle, return status; } -psa_status_t psa_cipher_decrypt(psa_key_handle_t handle, +psa_status_t psa_cipher_decrypt(psa_key_id_t key, psa_algorithm_t alg, const uint8_t *input, size_t input_length, @@ -1688,21 +1535,18 @@ psa_status_t psa_cipher_decrypt(psa_key_handle_t handle, } psa_status_t psa_raw_key_agreement(psa_algorithm_t alg, - psa_key_handle_t private_key, + psa_key_id_t private_key, const uint8_t *peer_key, size_t peer_key_length, uint8_t *output, size_t output_size, size_t *output_length) { -#ifdef TFM_CRYPTO_GENERATOR_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_RAW_KEY_AGREEMENT_SID, .alg = alg, - .key_handle = private_key + .key_id = private_key }; psa_invec in_vec[] = { @@ -1724,15 +1568,11 @@ psa_status_t psa_raw_key_agreement(psa_algorithm_t alg, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_GENERATOR_MODULE_DISABLED */ } psa_status_t psa_key_derivation_setup(psa_key_derivation_operation_t *operation, psa_algorithm_t alg) { -#ifdef TFM_CRYPTO_GENERATOR_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_KEY_DERIVATION_SETUP_SID, @@ -1754,16 +1594,12 @@ psa_status_t psa_key_derivation_setup(psa_key_derivation_operation_t *operation, PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_GENERATOR_MODULE_DISABLED */ } psa_status_t psa_key_derivation_set_capacity( psa_key_derivation_operation_t *operation, size_t capacity) { -#ifdef TFM_CRYPTO_GENERATOR_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_KEY_DERIVATION_SET_CAPACITY_SID, @@ -1782,7 +1618,6 @@ psa_status_t psa_key_derivation_set_capacity( PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_GENERATOR_MODULE_DISABLED */ } psa_status_t psa_key_derivation_input_bytes( @@ -1791,9 +1626,6 @@ psa_status_t psa_key_derivation_input_bytes( const uint8_t *data, size_t data_length) { -#ifdef TFM_CRYPTO_GENERATOR_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_KEY_DERIVATION_INPUT_BYTES_SID, @@ -1813,17 +1645,13 @@ psa_status_t psa_key_derivation_input_bytes( PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_GENERATOR_MODULE_DISABLED */ } psa_status_t psa_key_derivation_output_key( const psa_key_attributes_t *attributes, psa_key_derivation_operation_t *operation, - psa_key_handle_t *handle) + psa_key_id_t *key) { -#ifdef TFM_CRYPTO_GENERATOR_MODULE_DISABLED - return PSA_ERROR_NOT_SUPPORTED; -#else psa_status_t status; struct tfm_crypto_pack_iovec iov = { .sfn_id = TFM_CRYPTO_KEY_DERIVATION_OUTPUT_KEY_SID, @@ -1836,7 +1664,7 @@ psa_status_t psa_key_derivation_output_key( }; psa_outvec out_vec[] = { - {.base = handle, .len = sizeof(psa_key_handle_t)} + {.base = key, .len = sizeof(psa_key_id_t)} }; PSA_CONNECT(TFM_CRYPTO); @@ -1846,11 +1674,10 @@ psa_status_t psa_key_derivation_output_key( PSA_CLOSE(); return status; -#endif /* TFM_CRYPTO_GENERATOR_MODULE_DISABLED */ } psa_status_t psa_aead_encrypt_setup(psa_aead_operation_t *operation, - psa_key_handle_t handle, + psa_key_id_t key, psa_algorithm_t alg) { psa_status_t status; @@ -1861,7 +1688,7 @@ psa_status_t psa_aead_encrypt_setup(psa_aead_operation_t *operation, } psa_status_t psa_aead_decrypt_setup(psa_aead_operation_t *operation, - psa_key_handle_t handle, + psa_key_id_t key, psa_algorithm_t alg) { psa_status_t status; diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/src/tfm_its_ipc_api.c b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/src/tfm_its_ipc_api.c index 9326f7b8e3..8ad4a3bbb3 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/src/tfm_its_ipc_api.c +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/src/tfm_its_ipc_api.c @@ -36,10 +36,6 @@ psa_status_t psa_its_set(psa_storage_uid_t uid, psa_close(handle); - if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { - return PSA_ERROR_INVALID_ARGUMENT; - } - return status; } @@ -75,10 +71,6 @@ psa_status_t psa_its_get(psa_storage_uid_t uid, psa_close(handle); - if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { - return PSA_ERROR_INVALID_ARGUMENT; - } - *p_data_length = out_vec[0].len; return status; @@ -108,10 +100,6 @@ psa_status_t psa_its_get_info(psa_storage_uid_t uid, psa_close(handle); - if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { - return PSA_ERROR_INVALID_ARGUMENT; - } - return status; } diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/src/tfm_ps_ipc_api.c b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/src/tfm_ps_ipc_api.c index 7cc3a63fff..4f937db2d0 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/src/tfm_ps_ipc_api.c +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/src/tfm_ps_ipc_api.c @@ -36,14 +36,6 @@ psa_status_t psa_ps_set(psa_storage_uid_t uid, psa_close(handle); - /* A parameter with a buffer pointer pointer that has data length longer - * than maximum permitted is treated as a secure violation. - * TF-M framework rejects the request with TFM_ERROR_INVALID_PARAMETER. - */ - if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { - return PSA_ERROR_INVALID_ARGUMENT; - } - return status; }