1*b0563631STom Van Eyck /** \file psa_crypto_its.h 2*b0563631STom Van Eyck * \brief Interface of trusted storage that crypto is built on. 3*b0563631STom Van Eyck */ 4*b0563631STom Van Eyck /* 5*b0563631STom Van Eyck * Copyright The Mbed TLS Contributors 6*b0563631STom Van Eyck * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 7*b0563631STom Van Eyck */ 8*b0563631STom Van Eyck 9*b0563631STom Van Eyck #ifndef PSA_CRYPTO_ITS_H 10*b0563631STom Van Eyck #define PSA_CRYPTO_ITS_H 11*b0563631STom Van Eyck 12*b0563631STom Van Eyck #include <stddef.h> 13*b0563631STom Van Eyck #include <stdint.h> 14*b0563631STom Van Eyck 15*b0563631STom Van Eyck #include <psa/crypto_types.h> 16*b0563631STom Van Eyck #include <psa/crypto_values.h> 17*b0563631STom Van Eyck 18*b0563631STom Van Eyck #ifdef __cplusplus 19*b0563631STom Van Eyck extern "C" { 20*b0563631STom Van Eyck #endif 21*b0563631STom Van Eyck 22*b0563631STom Van Eyck /** \brief Flags used when creating a data entry 23*b0563631STom Van Eyck */ 24*b0563631STom Van Eyck typedef uint32_t psa_storage_create_flags_t; 25*b0563631STom Van Eyck 26*b0563631STom Van Eyck /** \brief A type for UIDs used for identifying data 27*b0563631STom Van Eyck */ 28*b0563631STom Van Eyck typedef uint64_t psa_storage_uid_t; 29*b0563631STom Van Eyck 30*b0563631STom Van Eyck #define PSA_STORAGE_FLAG_NONE 0 /**< No flags to pass */ 31*b0563631STom Van Eyck #define PSA_STORAGE_FLAG_WRITE_ONCE (1 << 0) /**< The data associated with the uid will not be able to be modified or deleted. Intended to be used to set bits in `psa_storage_create_flags_t`*/ 32*b0563631STom Van Eyck 33*b0563631STom Van Eyck /** 34*b0563631STom Van Eyck * \brief A container for metadata associated with a specific uid 35*b0563631STom Van Eyck */ 36*b0563631STom Van Eyck struct psa_storage_info_t { 37*b0563631STom Van Eyck uint32_t size; /**< The size of the data associated with a uid **/ 38*b0563631STom Van Eyck psa_storage_create_flags_t flags; /**< The flags set when the uid was created **/ 39*b0563631STom Van Eyck }; 40*b0563631STom Van Eyck 41*b0563631STom Van Eyck /** Flag indicating that \ref psa_storage_create and \ref psa_storage_set_extended are supported */ 42*b0563631STom Van Eyck #define PSA_STORAGE_SUPPORT_SET_EXTENDED (1 << 0) 43*b0563631STom Van Eyck 44*b0563631STom Van Eyck #define PSA_ITS_API_VERSION_MAJOR 1 /**< The major version number of the PSA ITS API. It will be incremented on significant updates that may include breaking changes */ 45*b0563631STom Van Eyck #define PSA_ITS_API_VERSION_MINOR 1 /**< The minor version number of the PSA ITS API. It will be incremented in small updates that are unlikely to include breaking changes */ 46*b0563631STom Van Eyck 47*b0563631STom Van Eyck /** 48*b0563631STom Van Eyck * \brief create a new or modify an existing uid/value pair 49*b0563631STom Van Eyck * 50*b0563631STom Van Eyck * \param[in] uid the identifier for the data 51*b0563631STom Van Eyck * \param[in] data_length The size in bytes of the data in `p_data` 52*b0563631STom Van Eyck * \param[in] p_data A buffer containing the data 53*b0563631STom Van Eyck * \param[in] create_flags The flags that the data will be stored with 54*b0563631STom Van Eyck * 55*b0563631STom Van Eyck * \return A status indicating the success/failure of the operation 56*b0563631STom Van Eyck * 57*b0563631STom Van Eyck * \retval #PSA_SUCCESS The operation completed successfully 58*b0563631STom Van Eyck * \retval #PSA_ERROR_NOT_PERMITTED The operation failed because the provided `uid` value was already created with PSA_STORAGE_FLAG_WRITE_ONCE 59*b0563631STom Van Eyck * \retval #PSA_ERROR_NOT_SUPPORTED The operation failed because one or more of the flags provided in `create_flags` is not supported or is not valid 60*b0563631STom Van Eyck * \retval #PSA_ERROR_INSUFFICIENT_STORAGE The operation failed because there was insufficient space on the storage medium 61*b0563631STom Van Eyck * \retval #PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error) 62*b0563631STom Van Eyck * \retval #PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the provided pointers(`p_data`) 63*b0563631STom Van Eyck * is invalid, for example is `NULL` or references memory the caller cannot access 64*b0563631STom Van Eyck */ 65*b0563631STom Van Eyck psa_status_t psa_its_set(psa_storage_uid_t uid, 66*b0563631STom Van Eyck uint32_t data_length, 67*b0563631STom Van Eyck const void *p_data, 68*b0563631STom Van Eyck psa_storage_create_flags_t create_flags); 69*b0563631STom Van Eyck 70*b0563631STom Van Eyck /** 71*b0563631STom Van Eyck * \brief Retrieve the value associated with a provided uid 72*b0563631STom Van Eyck * 73*b0563631STom Van Eyck * \param[in] uid The uid value 74*b0563631STom Van Eyck * \param[in] data_offset The starting offset of the data requested 75*b0563631STom Van Eyck * \param[in] data_length the amount of data requested (and the minimum allocated size of the `p_data` buffer) 76*b0563631STom Van Eyck * \param[out] p_data The buffer where the data will be placed upon successful completion 77*b0563631STom Van Eyck * \param[out] p_data_length The amount of data returned in the p_data buffer 78*b0563631STom Van Eyck * 79*b0563631STom Van Eyck * 80*b0563631STom Van Eyck * \return A status indicating the success/failure of the operation 81*b0563631STom Van Eyck * 82*b0563631STom Van Eyck * \retval #PSA_SUCCESS The operation completed successfully 83*b0563631STom Van Eyck * \retval #PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided `uid` value was not found in the storage 84*b0563631STom Van Eyck * \retval #PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error) 85*b0563631STom Van Eyck * \retval #PSA_ERROR_DATA_CORRUPT The operation failed because stored data has been corrupted 86*b0563631STom Van Eyck * \retval #PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the provided pointers(`p_data`, `p_data_length`) 87*b0563631STom Van Eyck * is invalid. For example is `NULL` or references memory the caller cannot access. 88*b0563631STom Van Eyck * In addition, this can also happen if an invalid offset was provided. 89*b0563631STom Van Eyck */ 90*b0563631STom Van Eyck psa_status_t psa_its_get(psa_storage_uid_t uid, 91*b0563631STom Van Eyck uint32_t data_offset, 92*b0563631STom Van Eyck uint32_t data_length, 93*b0563631STom Van Eyck void *p_data, 94*b0563631STom Van Eyck size_t *p_data_length); 95*b0563631STom Van Eyck 96*b0563631STom Van Eyck /** 97*b0563631STom Van Eyck * \brief Retrieve the metadata about the provided uid 98*b0563631STom Van Eyck * 99*b0563631STom Van Eyck * \param[in] uid The uid value 100*b0563631STom Van Eyck * \param[out] p_info A pointer to the `psa_storage_info_t` struct that will be populated with the metadata 101*b0563631STom Van Eyck * 102*b0563631STom Van Eyck * \return A status indicating the success/failure of the operation 103*b0563631STom Van Eyck * 104*b0563631STom Van Eyck * \retval #PSA_SUCCESS The operation completed successfully 105*b0563631STom Van Eyck * \retval #PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided uid value was not found in the storage 106*b0563631STom Van Eyck * \retval #PSA_ERROR_DATA_CORRUPT The operation failed because stored data has been corrupted 107*b0563631STom Van Eyck * \retval #PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the provided pointers(`p_info`) 108*b0563631STom Van Eyck * is invalid, for example is `NULL` or references memory the caller cannot access 109*b0563631STom Van Eyck */ 110*b0563631STom Van Eyck psa_status_t psa_its_get_info(psa_storage_uid_t uid, 111*b0563631STom Van Eyck struct psa_storage_info_t *p_info); 112*b0563631STom Van Eyck 113*b0563631STom Van Eyck /** 114*b0563631STom Van Eyck * \brief Remove the provided key and its associated data from the storage 115*b0563631STom Van Eyck * 116*b0563631STom Van Eyck * \param[in] uid The uid value 117*b0563631STom Van Eyck * 118*b0563631STom Van Eyck * \return A status indicating the success/failure of the operation 119*b0563631STom Van Eyck * 120*b0563631STom Van Eyck * \retval #PSA_SUCCESS The operation completed successfully 121*b0563631STom Van Eyck * \retval #PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided key value was not found in the storage 122*b0563631STom Van Eyck * \retval #PSA_ERROR_NOT_PERMITTED The operation failed because the provided key value was created with PSA_STORAGE_FLAG_WRITE_ONCE 123*b0563631STom Van Eyck * \retval #PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error) 124*b0563631STom Van Eyck */ 125*b0563631STom Van Eyck psa_status_t psa_its_remove(psa_storage_uid_t uid); 126*b0563631STom Van Eyck 127*b0563631STom Van Eyck #ifdef __cplusplus 128*b0563631STom Van Eyck } 129*b0563631STom Van Eyck #endif 130*b0563631STom Van Eyck 131*b0563631STom Van Eyck #endif /* PSA_CRYPTO_ITS_H */ 132