2018-12-07 18:24:41 +01:00
|
|
|
/*
|
|
|
|
* PSA crypto core internal interfaces
|
|
|
|
*/
|
2020-06-15 11:59:37 +02:00
|
|
|
/*
|
2020-08-07 13:07:28 +02:00
|
|
|
* Copyright The Mbed TLS Contributors
|
2023-11-02 20:47:20 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
2018-12-07 18:24:41 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PSA_CRYPTO_CORE_H
|
|
|
|
#define PSA_CRYPTO_CORE_H
|
|
|
|
|
2023-10-10 08:51:39 +02:00
|
|
|
/*
|
|
|
|
* Include the build-time configuration information header. Here, we do not
|
|
|
|
* include `"mbedtls/build_info.h"` directly but `"psa/build_info.h"`, which
|
|
|
|
* is basically just an alias to it. This is to ease the maintenance of the
|
|
|
|
* TF-PSA-Crypto repository which has a different build system and
|
|
|
|
* configuration.
|
|
|
|
*/
|
|
|
|
#include "psa/build_info.h"
|
2018-12-07 18:24:41 +01:00
|
|
|
|
|
|
|
#include "psa/crypto.h"
|
2019-07-12 23:44:37 +02:00
|
|
|
#include "psa/crypto_se_driver.h"
|
2024-01-23 19:24:21 +01:00
|
|
|
#if defined(MBEDTLS_THREADING_C)
|
|
|
|
#include "mbedtls/threading.h"
|
|
|
|
#endif
|
2018-12-07 18:24:41 +01:00
|
|
|
|
2023-03-09 11:17:43 +01:00
|
|
|
/**
|
|
|
|
* Tell if PSA is ready for this hash.
|
|
|
|
*
|
|
|
|
* \note For now, only checks the state of the driver subsystem,
|
|
|
|
* not the algorithm. Might do more in the future.
|
|
|
|
*
|
|
|
|
* \param hash_alg The hash algorithm (ignored for now).
|
|
|
|
*
|
|
|
|
* \return 1 if the driver subsytem is ready, 0 otherwise.
|
|
|
|
*/
|
|
|
|
int psa_can_do_hash(psa_algorithm_t hash_alg);
|
|
|
|
|
2023-12-12 11:27:36 +01:00
|
|
|
/**
|
|
|
|
* Tell if PSA is ready for this cipher.
|
|
|
|
*
|
|
|
|
* \note For now, only checks the state of the driver subsystem,
|
|
|
|
* not the algorithm. Might do more in the future.
|
|
|
|
*
|
|
|
|
* \param cipher_alg The cipher algorithm (ignored for now).
|
|
|
|
*
|
|
|
|
* \return 1 if the driver subsytem is ready, 0 otherwise.
|
|
|
|
*/
|
2023-12-28 14:19:34 +01:00
|
|
|
int psa_can_do_cipher(psa_key_type_t key_type, psa_algorithm_t cipher_alg);
|
2023-12-12 11:27:36 +01:00
|
|
|
|
2023-11-13 10:52:12 +01:00
|
|
|
typedef enum {
|
|
|
|
PSA_SLOT_EMPTY = 0,
|
2023-12-21 17:40:43 +01:00
|
|
|
PSA_SLOT_FILLING,
|
|
|
|
PSA_SLOT_FULL,
|
|
|
|
PSA_SLOT_PENDING_DELETION,
|
|
|
|
} psa_key_slot_state_t;
|
2023-11-13 10:52:12 +01:00
|
|
|
|
2018-12-07 18:24:41 +01:00
|
|
|
/** The data structure representing a key slot, containing key material
|
|
|
|
* and metadata for one key.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
typedef struct {
|
2019-07-30 20:06:31 +02:00
|
|
|
psa_core_key_attributes_t attr;
|
2020-10-22 15:24:49 +02:00
|
|
|
|
2023-12-21 17:40:43 +01:00
|
|
|
/*
|
|
|
|
* The current state of the key slot, as described in
|
|
|
|
* docs/architecture/psa-thread-safety/psa-thread-safety.md.
|
|
|
|
*
|
|
|
|
* Library functions can modify the state of a key slot by calling
|
|
|
|
* psa_key_slot_state_transition.
|
|
|
|
*
|
|
|
|
* The state variable is used to help determine whether library functions
|
|
|
|
* which operate on the slot succeed. For example, psa_finish_key_creation,
|
|
|
|
* which transfers the state of a slot from PSA_SLOT_FILLING to
|
2024-01-12 18:45:05 +01:00
|
|
|
* PSA_SLOT_FULL, must fail with error code PSA_ERROR_CORRUPTION_DETECTED
|
2023-12-21 17:40:43 +01:00
|
|
|
* if the state of the slot is not PSA_SLOT_FILLING.
|
|
|
|
*
|
|
|
|
* Library functions which traverse the array of key slots only consider
|
|
|
|
* slots that are in a suitable state for the function.
|
|
|
|
* For example, psa_get_and_lock_key_slot_in_memory, which finds a slot
|
|
|
|
* containing a given key ID, will only check slots whose state variable is
|
|
|
|
* PSA_SLOT_FULL. */
|
|
|
|
psa_key_slot_state_t state;
|
2023-11-08 14:28:20 +01:00
|
|
|
|
2020-10-22 15:24:49 +02:00
|
|
|
/*
|
2023-12-21 17:40:43 +01:00
|
|
|
* Number of functions registered as reading the material in the key slot.
|
2020-10-22 15:24:49 +02:00
|
|
|
*
|
2023-12-21 17:40:43 +01:00
|
|
|
* Library functions must not write directly to registered_readers
|
2020-10-22 15:24:49 +02:00
|
|
|
*
|
2023-12-21 17:40:43 +01:00
|
|
|
* A function must call psa_register_read(slot) before reading the current
|
|
|
|
* contents of the slot for an operation.
|
|
|
|
* They then must call psa_unregister_read(slot) once they have finished
|
2024-02-20 19:01:29 +01:00
|
|
|
* reading the current contents of the slot. If the key slot mutex is not
|
|
|
|
* held (when mutexes are enabled), this call must be done via a call to
|
|
|
|
* psa_unregister_read_under_mutex(slot).
|
2023-12-21 17:40:43 +01:00
|
|
|
* A function must call psa_key_slot_has_readers(slot) to check if
|
|
|
|
* the slot is in use for reading.
|
2020-10-22 15:24:49 +02:00
|
|
|
*
|
|
|
|
* This counter is used to prevent resetting the key slot while the library
|
|
|
|
* may access it. For example, such control is needed in the following
|
|
|
|
* scenarios:
|
|
|
|
* . In case of key slot starvation, all key slots contain the description
|
2020-11-10 18:08:03 +01:00
|
|
|
* of a key, and the library asks for the description of a persistent
|
2020-10-22 15:24:49 +02:00
|
|
|
* key not present in the key slots, the key slots currently accessed by
|
|
|
|
* the library cannot be reclaimed to free a key slot to load the
|
2020-11-10 18:08:03 +01:00
|
|
|
* persistent key.
|
2020-10-22 15:24:49 +02:00
|
|
|
* . In case of a multi-threaded application where one thread asks to close
|
2023-12-21 17:40:43 +01:00
|
|
|
* or purge or destroy a key while it is in use by the library through
|
|
|
|
* another thread. */
|
|
|
|
size_t registered_readers;
|
2020-10-22 15:24:49 +02:00
|
|
|
|
2020-11-25 17:52:23 +01:00
|
|
|
/* Dynamically allocated key data buffer.
|
|
|
|
* Format as specified in psa_export_key(). */
|
2023-01-11 14:50:10 +01:00
|
|
|
struct key_data {
|
2020-11-25 17:52:23 +01:00
|
|
|
uint8_t *data;
|
|
|
|
size_t bytes;
|
|
|
|
} key;
|
2018-12-07 18:24:41 +01:00
|
|
|
} psa_key_slot_t;
|
|
|
|
|
2024-01-24 14:26:26 +01:00
|
|
|
#if defined(MBEDTLS_THREADING_C)
|
|
|
|
|
|
|
|
/** Perform a mutex operation and return immediately upon failure.
|
|
|
|
*
|
2024-01-23 19:24:21 +01:00
|
|
|
* Returns PSA_ERROR_SERVICE_FAILURE if the operation fails
|
|
|
|
* and status was PSA_SUCCESS.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* psa_status_t status exists.
|
2024-01-24 14:26:26 +01:00
|
|
|
* f is a mutex operation which returns 0 upon success.
|
2024-01-23 19:24:21 +01:00
|
|
|
*/
|
2024-01-24 14:26:26 +01:00
|
|
|
#define PSA_THREADING_CHK_RET(f) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if ((f) != 0) { \
|
|
|
|
if (status == PSA_SUCCESS) { \
|
|
|
|
return PSA_ERROR_SERVICE_FAILURE; \
|
|
|
|
} \
|
|
|
|
return status; \
|
|
|
|
} \
|
2024-01-23 19:24:21 +01:00
|
|
|
} while (0);
|
|
|
|
|
2024-01-24 14:26:26 +01:00
|
|
|
/** Perform a mutex operation and goto exit on failure.
|
|
|
|
*
|
|
|
|
* Sets status to PSA_ERROR_SERVICE_FAILURE if status was PSA_SUCCESS.
|
2024-01-23 19:24:36 +01:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* psa_status_t status exists.
|
|
|
|
* Label exit: exists.
|
2024-01-24 14:26:26 +01:00
|
|
|
* f is a mutex operation which returns 0 upon success.
|
2024-01-23 19:24:36 +01:00
|
|
|
*/
|
2024-01-24 14:26:26 +01:00
|
|
|
#define PSA_THREADING_CHK_GOTO_EXIT(f) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if ((f) != 0) { \
|
|
|
|
if (status == PSA_SUCCESS) { \
|
|
|
|
status = PSA_ERROR_SERVICE_FAILURE; \
|
|
|
|
} \
|
|
|
|
goto exit; \
|
|
|
|
} \
|
2024-01-23 19:24:36 +01:00
|
|
|
} while (0);
|
|
|
|
#endif
|
|
|
|
|
2019-08-02 19:19:39 +02:00
|
|
|
/* A mask of key attribute flags used only internally.
|
|
|
|
* Currently there aren't any. */
|
2019-08-05 17:32:13 +02:00
|
|
|
#define PSA_KA_MASK_INTERNAL_ONLY ( \
|
2023-01-11 14:50:10 +01:00
|
|
|
0)
|
2019-08-02 19:19:39 +02:00
|
|
|
|
2024-01-02 17:21:03 +01:00
|
|
|
/** Test whether a key slot has any registered readers.
|
2024-01-08 12:13:03 +01:00
|
|
|
* If multi-threading is enabled, the caller must hold the
|
|
|
|
* global key slot mutex.
|
2019-07-31 15:01:55 +02:00
|
|
|
*
|
|
|
|
* \param[in] slot The key slot to test.
|
|
|
|
*
|
2024-01-02 17:21:03 +01:00
|
|
|
* \return 1 if the slot has any registered readers, 0 otherwise.
|
2020-10-22 15:24:49 +02:00
|
|
|
*/
|
2024-01-02 17:21:03 +01:00
|
|
|
static inline int psa_key_slot_has_readers(const psa_key_slot_t *slot)
|
2020-10-22 15:24:49 +02:00
|
|
|
{
|
2024-01-02 17:21:03 +01:00
|
|
|
return slot->registered_readers > 0;
|
2020-10-22 15:24:49 +02:00
|
|
|
}
|
|
|
|
|
2019-07-30 20:06:31 +02:00
|
|
|
/** Retrieve flags from psa_key_slot_t::attr::core::flags.
|
|
|
|
*
|
|
|
|
* \param[in] slot The key slot to query.
|
|
|
|
* \param mask The mask of bits to extract.
|
|
|
|
*
|
|
|
|
* \return The key attribute flags in the given slot,
|
|
|
|
* bitwise-anded with \p mask.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline uint16_t psa_key_slot_get_flags(const psa_key_slot_t *slot,
|
|
|
|
uint16_t mask)
|
2019-07-30 20:06:31 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return slot->attr.flags & mask;
|
2019-07-30 20:06:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Set flags in psa_key_slot_t::attr::core::flags.
|
|
|
|
*
|
|
|
|
* \param[in,out] slot The key slot to modify.
|
|
|
|
* \param mask The mask of bits to modify.
|
|
|
|
* \param value The new value of the selected bits.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline void psa_key_slot_set_flags(psa_key_slot_t *slot,
|
|
|
|
uint16_t mask,
|
|
|
|
uint16_t value)
|
2019-07-30 20:06:31 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
slot->attr.flags = ((~mask & slot->attr.flags) |
|
|
|
|
(mask & value));
|
2019-07-30 20:06:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Turn on flags in psa_key_slot_t::attr::core::flags.
|
|
|
|
*
|
|
|
|
* \param[in,out] slot The key slot to modify.
|
|
|
|
* \param mask The mask of bits to set.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline void psa_key_slot_set_bits_in_flags(psa_key_slot_t *slot,
|
|
|
|
uint16_t mask)
|
2019-07-30 20:06:31 +02:00
|
|
|
{
|
|
|
|
slot->attr.flags |= mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Turn off flags in psa_key_slot_t::attr::core::flags.
|
|
|
|
*
|
|
|
|
* \param[in,out] slot The key slot to modify.
|
|
|
|
* \param mask The mask of bits to clear.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline void psa_key_slot_clear_bits(psa_key_slot_t *slot,
|
|
|
|
uint16_t mask)
|
2019-07-30 20:06:31 +02:00
|
|
|
{
|
|
|
|
slot->attr.flags &= ~mask;
|
|
|
|
}
|
|
|
|
|
2020-11-25 17:52:23 +01:00
|
|
|
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
|
|
|
/** Get the SE slot number of a key from the key slot storing its description.
|
|
|
|
*
|
|
|
|
* \param[in] slot The key slot to query. This must be a key slot storing
|
|
|
|
* the description of a key of a dynamically registered
|
|
|
|
* secure element, otherwise the behaviour is undefined.
|
|
|
|
*/
|
|
|
|
static inline psa_key_slot_number_t psa_key_slot_get_slot_number(
|
2023-01-11 14:50:10 +01:00
|
|
|
const psa_key_slot_t *slot)
|
2020-11-25 17:52:23 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return *((psa_key_slot_number_t *) (slot->key.data));
|
2020-11-25 17:52:23 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-12-10 16:29:04 +01:00
|
|
|
/** Completely wipe a slot in memory, including its policy.
|
2018-12-10 17:00:38 +01:00
|
|
|
*
|
|
|
|
* Persistent storage is not affected.
|
2023-12-21 18:32:07 +01:00
|
|
|
* Sets the slot's state to PSA_SLOT_EMPTY.
|
2024-01-08 12:13:03 +01:00
|
|
|
* If multi-threading is enabled, the caller must hold the
|
|
|
|
* global key slot mutex.
|
2018-12-10 17:00:38 +01:00
|
|
|
*
|
|
|
|
* \param[in,out] slot The key slot to wipe.
|
|
|
|
*
|
2020-10-19 12:06:30 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
2023-12-21 18:32:07 +01:00
|
|
|
* The slot has been successfully wiped.
|
|
|
|
* \retval #PSA_ERROR_CORRUPTION_DETECTED
|
2024-01-12 17:35:59 +01:00
|
|
|
* The slot's state was PSA_SLOT_FULL or PSA_SLOT_PENDING_DELETION, and
|
2024-01-17 12:45:44 +01:00
|
|
|
* the amount of registered readers was not equal to 1. Or,
|
|
|
|
* the slot's state was PSA_SLOT_EMPTY. Or,
|
|
|
|
* the slot's state was PSA_SLOT_FILLING, and the amount
|
|
|
|
* of registered readers was not equal to 0.
|
2018-12-10 17:00:38 +01:00
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_status_t psa_wipe_key_slot(psa_key_slot_t *slot);
|
2018-12-10 16:29:04 +01:00
|
|
|
|
2021-04-06 16:45:06 +02:00
|
|
|
/** Try to allocate a buffer to an empty key slot.
|
|
|
|
*
|
|
|
|
* \param[in,out] slot Key slot to attach buffer to.
|
|
|
|
* \param[in] buffer_length Requested size of the buffer.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* The buffer has been successfully allocated.
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* Not enough memory was available for allocation.
|
|
|
|
* \retval #PSA_ERROR_ALREADY_EXISTS
|
|
|
|
* Trying to allocate a buffer to a non-empty key slot.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_status_t psa_allocate_buffer_to_slot(psa_key_slot_t *slot,
|
|
|
|
size_t buffer_length);
|
2021-04-06 16:45:06 +02:00
|
|
|
|
2021-04-07 18:08:30 +02:00
|
|
|
/** Wipe key data from a slot. Preserves metadata such as the policy. */
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_status_t psa_remove_key_data_from_memory(psa_key_slot_t *slot);
|
2021-04-07 18:08:30 +02:00
|
|
|
|
2020-10-13 20:27:40 +02:00
|
|
|
/** Copy key data (in export format) into an empty key slot.
|
|
|
|
*
|
|
|
|
* This function assumes that the slot does not contain
|
|
|
|
* any key material yet. On failure, the slot content is unchanged.
|
|
|
|
*
|
|
|
|
* \param[in,out] slot Key slot to copy the key into.
|
|
|
|
* \param[in] data Buffer containing the key material.
|
|
|
|
* \param data_length Size of the key buffer.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* The key has been copied successfully.
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
|
|
|
* Not enough memory was available for allocation of the
|
|
|
|
* copy buffer.
|
|
|
|
* \retval #PSA_ERROR_ALREADY_EXISTS
|
|
|
|
* There was other key material already present in the slot.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_status_t psa_copy_key_material_into_slot(psa_key_slot_t *slot,
|
|
|
|
const uint8_t *data,
|
|
|
|
size_t data_length);
|
2020-10-13 20:27:40 +02:00
|
|
|
|
2023-08-03 17:45:20 +02:00
|
|
|
/** Convert an Mbed TLS error code to a PSA error code
|
2020-09-04 13:05:23 +02:00
|
|
|
*
|
|
|
|
* \note This function is provided solely for the convenience of
|
|
|
|
* Mbed TLS and may be removed at any time without notice.
|
|
|
|
*
|
2023-08-03 17:45:20 +02:00
|
|
|
* \param ret An Mbed TLS-thrown error code
|
2020-09-04 13:05:23 +02:00
|
|
|
*
|
|
|
|
* \return The corresponding PSA error code
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_status_t mbedtls_to_psa_error(int ret);
|
2020-09-04 13:05:23 +02:00
|
|
|
|
2020-11-29 11:14:53 +01:00
|
|
|
/** Import a key in binary format.
|
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver
|
|
|
|
* import_key entry point. This function behaves as an import_key
|
|
|
|
* entry point as defined in the PSA driver interface specification for
|
|
|
|
* transparent drivers.
|
|
|
|
*
|
|
|
|
* \param[in] attributes The attributes for the key to import.
|
|
|
|
* \param[in] data The buffer containing the key data in import
|
|
|
|
* format.
|
|
|
|
* \param[in] data_length Size of the \p data buffer in bytes.
|
2021-02-01 11:37:53 +01:00
|
|
|
* \param[out] key_buffer The buffer to contain the key data in output
|
|
|
|
* format upon successful return.
|
2020-11-29 11:14:53 +01:00
|
|
|
* \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes. This
|
|
|
|
* size is greater or equal to \p data_length.
|
|
|
|
* \param[out] key_buffer_length The length of the data written in \p
|
|
|
|
* key_buffer in bytes.
|
|
|
|
* \param[out] bits The key size in number of bits.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS The key was imported successfully.
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* The key data is not correctly formatted.
|
2023-02-14 19:21:09 +01:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
|
|
|
|
* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
|
2020-11-29 11:14:53 +01:00
|
|
|
*/
|
|
|
|
psa_status_t psa_import_key_into_slot(
|
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *data, size_t data_length,
|
|
|
|
uint8_t *key_buffer, size_t key_buffer_size,
|
2023-01-11 14:50:10 +01:00
|
|
|
size_t *key_buffer_length, size_t *bits);
|
2020-11-29 11:14:53 +01:00
|
|
|
|
2020-11-26 14:46:37 +01:00
|
|
|
/** Export a key in binary format
|
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver export_key
|
|
|
|
* entry point. This function behaves as an export_key entry point as
|
|
|
|
* defined in the PSA driver interface specification.
|
|
|
|
*
|
|
|
|
* \param[in] attributes The attributes for the key to export.
|
|
|
|
* \param[in] key_buffer Material or context of the key to export.
|
|
|
|
* \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
|
|
|
|
* \param[out] data Buffer where the key data is to be written.
|
|
|
|
* \param[in] data_size Size of the \p data buffer in bytes.
|
|
|
|
* \param[out] data_length On success, the number of bytes written in
|
|
|
|
* \p data
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS The key was exported successfully.
|
2023-02-14 19:21:09 +01:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE \emptydescription
|
|
|
|
* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
|
|
|
|
* \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
|
2020-11-26 14:46:37 +01:00
|
|
|
*/
|
|
|
|
psa_status_t psa_export_key_internal(
|
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
2023-01-11 14:50:10 +01:00
|
|
|
uint8_t *data, size_t data_size, size_t *data_length);
|
2020-11-26 14:46:37 +01:00
|
|
|
|
|
|
|
/** Export a public key or the public part of a key pair in binary format.
|
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver
|
|
|
|
* export_public_key entry point. This function behaves as an
|
|
|
|
* export_public_key entry point as defined in the PSA driver interface
|
|
|
|
* specification.
|
|
|
|
*
|
|
|
|
* \param[in] attributes The attributes for the key to export.
|
|
|
|
* \param[in] key_buffer Material or context of the key to export.
|
|
|
|
* \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
|
|
|
|
* \param[out] data Buffer where the key data is to be written.
|
|
|
|
* \param[in] data_size Size of the \p data buffer in bytes.
|
|
|
|
* \param[out] data_length On success, the number of bytes written in
|
|
|
|
* \p data
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS The public key was exported successfully.
|
2023-02-14 19:21:09 +01:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE \emptydescription
|
|
|
|
* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
|
|
|
|
* \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
|
2020-11-26 14:46:37 +01:00
|
|
|
*/
|
|
|
|
psa_status_t psa_export_public_key_internal(
|
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
2023-01-11 14:50:10 +01:00
|
|
|
uint8_t *data, size_t data_size, size_t *data_length);
|
2020-11-26 14:46:37 +01:00
|
|
|
|
2024-02-20 12:31:24 +01:00
|
|
|
/** Whether a key production parameters structure is the default.
|
2024-02-14 23:07:33 +01:00
|
|
|
*
|
2024-02-20 12:31:24 +01:00
|
|
|
* Calls to a key generation driver with non-default production parameters
|
|
|
|
* require a driver supporting custom production parameters.
|
2024-02-14 23:07:33 +01:00
|
|
|
*
|
2024-02-20 12:31:24 +01:00
|
|
|
* \param[in] params The key production parameters to check.
|
|
|
|
* \param params_data_length Size of `params->data` in bytes.
|
2024-02-14 23:07:33 +01:00
|
|
|
*/
|
2024-02-20 12:31:24 +01:00
|
|
|
int psa_key_production_parameters_are_default(
|
|
|
|
const psa_key_production_parameters_t *params,
|
|
|
|
size_t params_data_length);
|
2024-02-14 23:07:33 +01:00
|
|
|
|
2020-10-05 10:30:40 +02:00
|
|
|
/**
|
|
|
|
* \brief Generate a key.
|
|
|
|
*
|
|
|
|
* \note The signature of the function is that of a PSA driver generate_key
|
|
|
|
* entry point.
|
|
|
|
*
|
|
|
|
* \param[in] attributes The attributes for the key to generate.
|
2024-02-20 12:31:24 +01:00
|
|
|
* \param[in] params The production parameters from
|
2024-02-12 16:48:11 +01:00
|
|
|
* psa_generate_key_ext().
|
2024-02-20 12:31:24 +01:00
|
|
|
* \param params_data_length The size of `params->data` in bytes.
|
2020-10-05 10:30:40 +02:00
|
|
|
* \param[out] key_buffer Buffer where the key data is to be written.
|
|
|
|
* \param[in] key_buffer_size Size of \p key_buffer in bytes.
|
|
|
|
* \param[out] key_buffer_length On success, the number of bytes written in
|
|
|
|
* \p key_buffer.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* The key was generated successfully.
|
2023-02-14 19:21:09 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT \emptydescription
|
2020-10-05 10:30:40 +02:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* Key size in bits or type not supported.
|
|
|
|
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
|
|
|
* The size of \p key_buffer is too small.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_status_t psa_generate_key_internal(const psa_key_attributes_t *attributes,
|
2024-02-20 12:31:24 +01:00
|
|
|
const psa_key_production_parameters_t *params,
|
|
|
|
size_t params_data_length,
|
2023-01-11 14:50:10 +01:00
|
|
|
uint8_t *key_buffer,
|
|
|
|
size_t key_buffer_size,
|
|
|
|
size_t *key_buffer_length);
|
2021-04-29 16:53:31 +02:00
|
|
|
|
2021-04-22 11:32:19 +02:00
|
|
|
/** Sign a message with a private key. For hash-and-sign algorithms,
|
|
|
|
* this includes the hashing step.
|
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver
|
|
|
|
* sign_message entry point. This function behaves as a sign_message
|
|
|
|
* entry point as defined in the PSA driver interface specification for
|
|
|
|
* transparent drivers.
|
|
|
|
*
|
2021-05-12 10:49:27 +02:00
|
|
|
* \note This function will call the driver for psa_sign_hash
|
|
|
|
* and go through driver dispatch again.
|
|
|
|
*
|
2021-04-22 11:32:19 +02:00
|
|
|
* \param[in] attributes The attributes of the key to use for the
|
|
|
|
* operation.
|
|
|
|
* \param[in] key_buffer The buffer containing the key context.
|
|
|
|
* \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
|
|
|
|
* \param[in] alg A signature algorithm that is compatible with
|
|
|
|
* the type of the key.
|
|
|
|
* \param[in] input The input message to sign.
|
|
|
|
* \param[in] input_length Size of the \p input buffer in bytes.
|
|
|
|
* \param[out] signature Buffer where the signature is to be written.
|
|
|
|
* \param[in] signature_size Size of the \p signature buffer in bytes.
|
|
|
|
* \param[out] signature_length On success, the number of bytes
|
|
|
|
* that make up the returned signature value.
|
|
|
|
*
|
2023-02-14 19:21:09 +01:00
|
|
|
* \retval #PSA_SUCCESS \emptydescription
|
2021-04-22 11:32:19 +02:00
|
|
|
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
|
|
|
* The size of the \p signature buffer is too small. You can
|
|
|
|
* 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 the key.
|
2023-02-14 19:21:09 +01:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
|
|
|
|
* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_ENTROPY \emptydescription
|
2021-04-22 11:32:19 +02:00
|
|
|
*/
|
2021-05-05 14:18:36 +02:00
|
|
|
psa_status_t psa_sign_message_builtin(
|
2021-04-22 11:32:19 +02:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
|
|
psa_algorithm_t alg, const uint8_t *input, size_t input_length,
|
2023-01-11 14:50:10 +01:00
|
|
|
uint8_t *signature, size_t signature_size, size_t *signature_length);
|
2021-04-22 11:32:19 +02:00
|
|
|
|
|
|
|
/** Verify the signature of a message with a public key, using
|
|
|
|
* a hash-and-sign verification algorithm.
|
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver
|
|
|
|
* verify_message entry point. This function behaves as a verify_message
|
|
|
|
* entry point as defined in the PSA driver interface specification for
|
|
|
|
* transparent drivers.
|
|
|
|
*
|
2021-05-12 10:49:27 +02:00
|
|
|
* \note This function will call the driver for psa_verify_hash
|
|
|
|
* and go through driver dispatch again.
|
|
|
|
*
|
2021-04-22 11:32:19 +02:00
|
|
|
* \param[in] attributes The attributes of the key to use for the
|
|
|
|
* operation.
|
|
|
|
* \param[in] key_buffer The buffer containing the key context.
|
|
|
|
* \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
|
|
|
|
* \param[in] alg A signature algorithm that is compatible with
|
|
|
|
* the type of the key.
|
|
|
|
* \param[in] input The message whose signature is to be verified.
|
|
|
|
* \param[in] input_length Size of the \p input buffer in bytes.
|
|
|
|
* \param[in] signature Buffer containing the signature to verify.
|
|
|
|
* \param[in] signature_length Size of the \p signature buffer in bytes.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* The signature is valid.
|
|
|
|
* \retval #PSA_ERROR_INVALID_SIGNATURE
|
|
|
|
* The calculation was performed successfully, but the passed
|
|
|
|
* signature is not a valid signature.
|
2023-02-14 19:21:09 +01:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
|
2021-04-22 11:32:19 +02:00
|
|
|
*/
|
2021-05-05 14:18:36 +02:00
|
|
|
psa_status_t psa_verify_message_builtin(
|
2021-04-22 11:32:19 +02:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
|
|
psa_algorithm_t alg, const uint8_t *input, size_t input_length,
|
2023-01-11 14:50:10 +01:00
|
|
|
const uint8_t *signature, size_t signature_length);
|
2020-10-05 10:30:40 +02:00
|
|
|
|
2020-12-08 17:37:27 +01:00
|
|
|
/** Sign an already-calculated hash with a private key.
|
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver
|
|
|
|
* sign_hash entry point. This function behaves as a sign_hash
|
|
|
|
* entry point as defined in the PSA driver interface specification for
|
|
|
|
* transparent drivers.
|
|
|
|
*
|
|
|
|
* \param[in] attributes The attributes of the key to use for the
|
|
|
|
* operation.
|
|
|
|
* \param[in] key_buffer The buffer containing the key context.
|
|
|
|
* \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
|
|
|
|
* \param[in] alg A signature algorithm that is compatible with
|
|
|
|
* the type of the key.
|
|
|
|
* \param[in] hash The hash or message to sign.
|
|
|
|
* \param[in] hash_length Size of the \p hash buffer in bytes.
|
|
|
|
* \param[out] signature Buffer where the signature is to be written.
|
|
|
|
* \param[in] signature_size Size of the \p signature buffer in bytes.
|
|
|
|
* \param[out] signature_length On success, the number of bytes
|
|
|
|
* that make up the returned signature value.
|
|
|
|
*
|
2023-02-14 19:21:09 +01:00
|
|
|
* \retval #PSA_SUCCESS \emptydescription
|
2020-12-08 17:37:27 +01:00
|
|
|
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
|
|
|
* The size of the \p signature buffer is too small. You can
|
|
|
|
* 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 the key.
|
2023-02-14 19:21:09 +01:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
|
|
|
|
* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_ENTROPY \emptydescription
|
2020-12-08 17:37:27 +01:00
|
|
|
*/
|
2021-05-05 14:18:36 +02:00
|
|
|
psa_status_t psa_sign_hash_builtin(
|
2020-12-08 17:37:27 +01:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
|
|
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
2023-01-11 14:50:10 +01:00
|
|
|
uint8_t *signature, size_t signature_size, size_t *signature_length);
|
2020-12-08 17:37:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Verify the signature a hash or short message using a public key.
|
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver
|
|
|
|
* verify_hash entry point. This function behaves as a verify_hash
|
|
|
|
* entry point as defined in the PSA driver interface specification for
|
|
|
|
* transparent drivers.
|
|
|
|
*
|
|
|
|
* \param[in] attributes The attributes of the key to use for the
|
|
|
|
* operation.
|
|
|
|
* \param[in] key_buffer The buffer containing the key context.
|
|
|
|
* \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
|
|
|
|
* \param[in] alg A signature algorithm that is compatible with
|
|
|
|
* the type of the key.
|
|
|
|
* \param[in] hash The hash or message whose signature is to be
|
|
|
|
* verified.
|
|
|
|
* \param[in] hash_length Size of the \p hash buffer in bytes.
|
|
|
|
* \param[in] signature Buffer containing the signature to verify.
|
|
|
|
* \param[in] signature_length Size of the \p signature buffer in bytes.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* The signature is valid.
|
|
|
|
* \retval #PSA_ERROR_INVALID_SIGNATURE
|
|
|
|
* The calculation was performed successfully, but the passed
|
|
|
|
* signature is not a valid signature.
|
2023-02-14 19:21:09 +01:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
|
2020-12-08 17:37:27 +01:00
|
|
|
*/
|
2021-05-05 14:18:36 +02:00
|
|
|
psa_status_t psa_verify_hash_builtin(
|
2020-12-08 17:37:27 +01:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
|
|
psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
|
2023-01-11 14:50:10 +01:00
|
|
|
const uint8_t *signature, size_t signature_length);
|
2020-12-08 17:37:27 +01:00
|
|
|
|
2021-07-06 23:20:22 +02:00
|
|
|
/**
|
|
|
|
* \brief Validate the key bit size for unstructured keys.
|
|
|
|
*
|
|
|
|
* \note Check that the bit size is acceptable for a given key type for
|
|
|
|
* unstructured keys.
|
|
|
|
*
|
|
|
|
* \param[in] type The key type
|
|
|
|
* \param[in] bits The number of bits of the key
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* The key type and size are valid.
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* The size in bits of the key is not valid.
|
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* The type and/or the size in bits of the key or the combination of
|
|
|
|
* the two is not supported.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_status_t psa_validate_unstructured_key_bit_size(psa_key_type_t type,
|
|
|
|
size_t bits);
|
2022-10-13 18:21:01 +02:00
|
|
|
|
2022-10-14 17:41:40 +02:00
|
|
|
/** Perform a key agreement and return the raw shared secret, using
|
2022-10-13 18:21:01 +02:00
|
|
|
built-in raw key agreement functions.
|
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver
|
|
|
|
* key_agreement entry point. This function behaves as a key_agreement
|
|
|
|
* entry point as defined in the PSA driver interface specification for
|
|
|
|
* transparent drivers.
|
|
|
|
*
|
2022-10-14 17:41:40 +02:00
|
|
|
* \param[in] attributes The attributes of the key to use for the
|
|
|
|
* operation.
|
|
|
|
* \param[in] key_buffer The buffer containing the private key
|
|
|
|
* context.
|
|
|
|
* \param[in] key_buffer_size Size of the \p key_buffer buffer in
|
|
|
|
* bytes.
|
|
|
|
* \param[in] alg A key agreement algorithm that is
|
|
|
|
* compatible with the type of the key.
|
|
|
|
* \param[in] peer_key The buffer containing the key context
|
|
|
|
* of the peer's public key.
|
|
|
|
* \param[in] peer_key_length Size of the \p peer_key buffer in
|
|
|
|
* bytes.
|
|
|
|
* \param[out] shared_secret The buffer to which the shared secret
|
|
|
|
* is to be written.
|
|
|
|
* \param[in] shared_secret_size Size of the \p shared_secret buffer in
|
|
|
|
* bytes.
|
|
|
|
* \param[out] shared_secret_length On success, the number of bytes that make
|
|
|
|
* up the returned shared secret.
|
2022-10-13 18:21:01 +02:00
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Success. Shared secret successfully calculated.
|
2023-02-14 19:21:09 +01:00
|
|
|
* \retval #PSA_ERROR_INVALID_HANDLE \emptydescription
|
|
|
|
* \retval #PSA_ERROR_NOT_PERMITTED \emptydescription
|
2022-10-13 18:21:01 +02:00
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* \p alg is not a key agreement algorithm, or
|
|
|
|
* \p private_key is not compatible with \p alg,
|
|
|
|
* or \p peer_key is not valid for \p alg or not compatible with
|
|
|
|
* \p private_key.
|
|
|
|
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
|
|
|
* \p shared_secret_size is too small
|
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* \p alg is not a supported key agreement algorithm.
|
2023-02-14 19:21:09 +01:00
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
|
|
|
|
* \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
|
|
|
|
* \retval #PSA_ERROR_HARDWARE_FAILURE \emptydescription
|
|
|
|
* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
|
|
|
|
* \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
|
|
|
|
* \retval #PSA_ERROR_BAD_STATE \emptydescription
|
2022-10-13 18:21:01 +02:00
|
|
|
*/
|
2022-10-14 17:41:40 +02:00
|
|
|
psa_status_t psa_key_agreement_raw_builtin(
|
2022-10-13 18:21:01 +02:00
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key_buffer,
|
|
|
|
size_t key_buffer_size,
|
|
|
|
psa_algorithm_t alg,
|
|
|
|
const uint8_t *peer_key,
|
|
|
|
size_t peer_key_length,
|
|
|
|
uint8_t *shared_secret,
|
|
|
|
size_t shared_secret_size,
|
2023-01-11 14:50:10 +01:00
|
|
|
size_t *shared_secret_length);
|
2022-10-14 17:41:40 +02:00
|
|
|
|
2022-12-02 19:10:26 +01:00
|
|
|
/**
|
|
|
|
* \brief Set the maximum number of ops allowed to be executed by an
|
|
|
|
* interruptible function in a single call.
|
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver
|
|
|
|
* interruptible_set_max_ops entry point. This function behaves as an
|
|
|
|
* interruptible_set_max_ops entry point as defined in the PSA driver
|
|
|
|
* interface specification for transparent drivers.
|
|
|
|
*
|
|
|
|
* \param[in] max_ops The maximum number of ops to be executed in a
|
|
|
|
* single call, this can be a number from 0 to
|
|
|
|
* #PSA_INTERRUPTIBLE_MAX_OPS_UNLIMITED, where 0
|
|
|
|
* is obviously the least amount of work done per
|
|
|
|
* call.
|
|
|
|
*/
|
|
|
|
void mbedtls_psa_interruptible_set_max_ops(uint32_t max_ops);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get the maximum number of ops allowed to be executed by an
|
|
|
|
* interruptible function in a single call.
|
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver
|
|
|
|
* interruptible_get_max_ops entry point. This function behaves as an
|
|
|
|
* interruptible_get_max_ops entry point as defined in the PSA driver
|
|
|
|
* interface specification for transparent drivers.
|
|
|
|
*
|
|
|
|
* \return Maximum number of ops allowed to be executed
|
|
|
|
* by an interruptible function in a single call.
|
|
|
|
*/
|
|
|
|
uint32_t mbedtls_psa_interruptible_get_max_ops(void);
|
|
|
|
|
|
|
|
/**
|
2023-02-07 13:43:11 +01:00
|
|
|
* \brief Get the number of ops that a hash signing operation has taken for the
|
|
|
|
* previous call. If no call or work has taken place, this will return
|
|
|
|
* zero.
|
2022-12-02 19:10:26 +01:00
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver
|
2023-02-15 19:14:21 +01:00
|
|
|
* sign_hash_get_num_ops entry point. This function behaves as an
|
|
|
|
* sign_hash_get_num_ops entry point as defined in the PSA driver
|
|
|
|
* interface specification for transparent drivers.
|
2022-12-02 19:10:26 +01:00
|
|
|
*
|
2023-02-15 19:14:21 +01:00
|
|
|
* \param operation The \c
|
2022-12-02 19:10:26 +01:00
|
|
|
* mbedtls_psa_sign_hash_interruptible_operation_t
|
|
|
|
* to use. This must be initialized first.
|
|
|
|
*
|
2023-02-07 13:43:11 +01:00
|
|
|
* \return Number of ops that were completed
|
|
|
|
* in the last call to \c
|
|
|
|
* mbedtls_psa_sign_hash_complete().
|
2022-12-02 19:10:26 +01:00
|
|
|
*/
|
|
|
|
uint32_t mbedtls_psa_sign_hash_get_num_ops(
|
2023-02-19 19:43:45 +01:00
|
|
|
const mbedtls_psa_sign_hash_interruptible_operation_t *operation);
|
2022-12-02 19:10:26 +01:00
|
|
|
|
|
|
|
/**
|
2023-02-07 13:43:11 +01:00
|
|
|
* \brief Get the number of ops that a hash verification operation has taken for
|
|
|
|
* the previous call. If no call or work has taken place, this will
|
|
|
|
* return zero.
|
2022-12-02 19:10:26 +01:00
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver
|
2023-02-15 19:14:21 +01:00
|
|
|
* verify_hash_get_num_ops entry point. This function behaves as an
|
|
|
|
* verify_hash_get_num_ops entry point as defined in the PSA driver
|
|
|
|
* interface specification for transparent drivers.
|
2022-12-02 19:10:26 +01:00
|
|
|
*
|
2023-02-15 19:14:21 +01:00
|
|
|
* \param operation The \c
|
2022-12-02 19:10:26 +01:00
|
|
|
* mbedtls_psa_verify_hash_interruptible_operation_t
|
|
|
|
* to use. This must be initialized first.
|
|
|
|
*
|
2023-02-07 13:43:11 +01:00
|
|
|
* \return Number of ops that were completed
|
|
|
|
* in the last call to \c
|
|
|
|
* mbedtls_psa_verify_hash_complete().
|
2022-12-02 19:10:26 +01:00
|
|
|
*/
|
|
|
|
uint32_t mbedtls_psa_verify_hash_get_num_ops(
|
2023-02-19 19:43:45 +01:00
|
|
|
const mbedtls_psa_verify_hash_interruptible_operation_t *operation);
|
2022-12-02 19:10:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Start signing a hash or short message with a private key, in an
|
|
|
|
* interruptible manner.
|
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver
|
|
|
|
* sign_hash_start entry point. This function behaves as a
|
|
|
|
* sign_hash_start entry point as defined in the PSA driver interface
|
|
|
|
* specification for transparent drivers.
|
|
|
|
*
|
|
|
|
* \param[in] operation The \c
|
|
|
|
* mbedtls_psa_sign_hash_interruptible_operation_t
|
|
|
|
* to use. This must be initialized first.
|
|
|
|
* \param[in] attributes The attributes of the key to use for the
|
|
|
|
* operation.
|
|
|
|
* \param[in] key_buffer The buffer containing the key context.
|
|
|
|
* \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
|
|
|
|
* \param[in] alg A signature algorithm that is compatible with
|
|
|
|
* the type of the key.
|
|
|
|
* \param[in] hash The hash or message to sign.
|
|
|
|
* \param hash_length Size of the \p hash buffer in bytes.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* The operation started successfully - call \c psa_sign_hash_complete()
|
|
|
|
* with the same context to complete the operation
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* An unsupported, incorrectly formatted or incorrect type of key was
|
|
|
|
* used.
|
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED Either no internal interruptible operations
|
|
|
|
* are currently supported, or the key type is currently unsupported.
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
2023-02-15 17:45:20 +01:00
|
|
|
* There was insufficient memory to load the key representation.
|
2022-12-02 19:10:26 +01:00
|
|
|
*/
|
|
|
|
psa_status_t mbedtls_psa_sign_hash_start(
|
|
|
|
mbedtls_psa_sign_hash_interruptible_operation_t *operation,
|
|
|
|
const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
|
|
|
|
size_t key_buffer_size, psa_algorithm_t alg,
|
|
|
|
const uint8_t *hash, size_t hash_length);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Continue and eventually complete the action of signing a hash or
|
|
|
|
* short message with a private key, in an interruptible manner.
|
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver
|
|
|
|
* sign_hash_complete entry point. This function behaves as a
|
|
|
|
* sign_hash_complete entry point as defined in the PSA driver interface
|
|
|
|
* specification for transparent drivers.
|
|
|
|
*
|
|
|
|
* \param[in] operation The \c
|
|
|
|
* mbedtls_psa_sign_hash_interruptible_operation_t
|
|
|
|
* to use. This must be initialized first.
|
|
|
|
*
|
|
|
|
* \param[out] signature Buffer where the signature is to be written.
|
|
|
|
* \param signature_size Size of the \p signature buffer in bytes. This
|
|
|
|
* must be appropriate for the selected
|
|
|
|
* algorithm and key.
|
|
|
|
* \param[out] signature_length On success, the number of bytes that make up
|
|
|
|
* the returned signature value.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Operation completed successfully
|
|
|
|
*
|
|
|
|
* \retval #PSA_OPERATION_INCOMPLETE
|
|
|
|
* Operation was interrupted due to the setting of \c
|
|
|
|
* psa_interruptible_set_max_ops(), there is still work to be done,
|
|
|
|
* please call this function again with the same operation object.
|
|
|
|
*
|
|
|
|
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
|
|
|
|
* The size of the \p signature buffer is too small. You can
|
|
|
|
* 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 key.
|
|
|
|
*
|
2023-02-27 18:17:56 +01:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
|
|
|
|
* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_ENTROPY \emptydescription
|
2022-12-02 19:10:26 +01:00
|
|
|
*/
|
|
|
|
psa_status_t mbedtls_psa_sign_hash_complete(
|
|
|
|
mbedtls_psa_sign_hash_interruptible_operation_t *operation,
|
|
|
|
uint8_t *signature, size_t signature_size,
|
|
|
|
size_t *signature_length);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Abort a sign hash operation.
|
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver sign_hash_abort
|
|
|
|
* entry point. This function behaves as a sign_hash_abort entry point as
|
|
|
|
* defined in the PSA driver interface specification for transparent
|
|
|
|
* drivers.
|
|
|
|
*
|
|
|
|
* \param[in] operation The \c
|
|
|
|
* mbedtls_psa_sign_hash_interruptible_operation_t
|
|
|
|
* to abort.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* The operation was aborted successfully.
|
|
|
|
*/
|
|
|
|
psa_status_t mbedtls_psa_sign_hash_abort(
|
|
|
|
mbedtls_psa_sign_hash_interruptible_operation_t *operation);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Start reading and verifying a hash or short message, in an
|
|
|
|
* interruptible manner.
|
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver
|
|
|
|
* verify_hash_start entry point. This function behaves as a
|
|
|
|
* verify_hash_start entry point as defined in the PSA driver interface
|
|
|
|
* specification for transparent drivers.
|
|
|
|
*
|
|
|
|
* \param[in] operation The \c
|
|
|
|
* mbedtls_psa_verify_hash_interruptible_operation_t
|
|
|
|
* to use. This must be initialized first.
|
|
|
|
* \param[in] attributes The attributes of the key to use for the
|
|
|
|
* operation.
|
|
|
|
* \param[in] key_buffer The buffer containing the key context.
|
|
|
|
* \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
|
|
|
|
* \param[in] alg A signature algorithm that is compatible with
|
|
|
|
* the type of the key.
|
|
|
|
* \param[in] hash The hash whose signature is to be verified.
|
|
|
|
* \param hash_length Size of the \p hash buffer in bytes.
|
|
|
|
* \param[in] signature Buffer containing the signature to verify.
|
|
|
|
* \param signature_length Size of the \p signature buffer in bytes.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* The operation started successfully - call \c psa_sign_hash_complete()
|
|
|
|
* with the same context to complete the operation
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
|
|
|
* An unsupported or incorrect type of key was used.
|
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED
|
|
|
|
* Either no internal interruptible operations are currently supported,
|
|
|
|
* or the key type is currently unsupported.
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
|
2023-02-05 19:06:38 +01:00
|
|
|
* There was insufficient memory either to load the key representation,
|
2023-02-15 17:45:20 +01:00
|
|
|
* or to prepare the operation.
|
2022-12-02 19:10:26 +01:00
|
|
|
*/
|
|
|
|
psa_status_t mbedtls_psa_verify_hash_start(
|
|
|
|
mbedtls_psa_verify_hash_interruptible_operation_t *operation,
|
|
|
|
const psa_key_attributes_t *attributes,
|
|
|
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
|
|
psa_algorithm_t alg,
|
|
|
|
const uint8_t *hash, size_t hash_length,
|
|
|
|
const uint8_t *signature, size_t signature_length);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Continue and eventually complete the action of signing a hash or
|
|
|
|
* short message with a private key, in an interruptible manner.
|
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver
|
|
|
|
* sign_hash_complete entry point. This function behaves as a
|
|
|
|
* sign_hash_complete entry point as defined in the PSA driver interface
|
|
|
|
* specification for transparent drivers.
|
|
|
|
*
|
|
|
|
* \param[in] operation The \c
|
|
|
|
* mbedtls_psa_sign_hash_interruptible_operation_t
|
|
|
|
* to use. This must be initialized first.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* Operation completed successfully, and the passed signature is valid.
|
|
|
|
*
|
|
|
|
* \retval #PSA_OPERATION_INCOMPLETE
|
|
|
|
* Operation was interrupted due to the setting of \c
|
|
|
|
* psa_interruptible_set_max_ops(), there is still work to be done,
|
|
|
|
* please call this function again with the same operation object.
|
|
|
|
*
|
|
|
|
* \retval #PSA_ERROR_INVALID_SIGNATURE
|
|
|
|
* The calculation was performed successfully, but the passed
|
|
|
|
* signature is not a valid signature.
|
|
|
|
*
|
2023-02-27 18:17:56 +01:00
|
|
|
* \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INVALID_ARGUMENT \emptydescription
|
|
|
|
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
|
2022-12-02 19:10:26 +01:00
|
|
|
*/
|
|
|
|
psa_status_t mbedtls_psa_verify_hash_complete(
|
|
|
|
mbedtls_psa_verify_hash_interruptible_operation_t *operation);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Abort a verify signed hash operation.
|
|
|
|
*
|
|
|
|
* \note The signature of this function is that of a PSA driver
|
|
|
|
* verify_hash_abort entry point. This function behaves as a
|
|
|
|
* verify_hash_abort entry point as defined in the PSA driver interface
|
|
|
|
* specification for transparent drivers.
|
|
|
|
*
|
|
|
|
* \param[in] operation The \c
|
|
|
|
* mbedtls_psa_verify_hash_interruptible_operation_t
|
|
|
|
* to abort.
|
|
|
|
*
|
|
|
|
* \retval #PSA_SUCCESS
|
|
|
|
* The operation was aborted successfully.
|
|
|
|
*/
|
|
|
|
psa_status_t mbedtls_psa_verify_hash_abort(
|
|
|
|
mbedtls_psa_verify_hash_interruptible_operation_t *operation);
|
|
|
|
|
2018-12-07 18:24:41 +01:00
|
|
|
#endif /* PSA_CRYPTO_CORE_H */
|