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