blob: 9a044aa50359c9a6ff921dcbd0f215c33e25fc43 [file] [log] [blame]
Gilles Peskine601bd532019-02-24 11:34:28 +01001/** \file psa_crypto_its.h
2 * \brief Interface of trusted storage that crypto is built on.
3 */
Bence Szépkúti86974652020-06-15 11:59:37 +02004/*
Bence Szépkúti1e148272020-08-07 13:07:28 +02005 * Copyright The Mbed TLS Contributors
Gilles Peskine5f544972019-02-24 11:26:36 +01006 * SPDX-License-Identifier: Apache-2.0
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may
9 * not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
Gilles Peskine5f544972019-02-24 11:26:36 +010020
Gilles Peskine601bd532019-02-24 11:34:28 +010021#ifndef PSA_CRYPTO_ITS_H
22#define PSA_CRYPTO_ITS_H
Gilles Peskine5f544972019-02-24 11:26:36 +010023
24#include <stddef.h>
25#include <stdint.h>
26
Gilles Peskine601bd532019-02-24 11:34:28 +010027#include <psa/crypto_types.h>
28#include <psa/crypto_values.h>
Gilles Peskine5f544972019-02-24 11:26:36 +010029
30#ifdef __cplusplus
31extern "C" {
32#endif
Gilles Peskine601bd532019-02-24 11:34:28 +010033
34/** \brief Flags used when creating a data entry
35 */
36typedef uint32_t psa_storage_create_flags_t;
37
38/** \brief A type for UIDs used for identifying data
39 */
40typedef uint64_t psa_storage_uid_t;
41
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020042#define PSA_STORAGE_FLAG_NONE 0 /**< No flags to pass */
43#define PSA_STORAGE_FLAG_WRITE_ONCE \
44 (1 << 0) /**< The data associated with the uid will not be able to be \
45 modified or deleted. Intended to be used to set bits in \
46 `psa_storage_create_flags_t`*/
Gilles Peskine601bd532019-02-24 11:34:28 +010047
48/**
49 * \brief A container for metadata associated with a specific uid
50 */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020051struct psa_storage_info_t {
52 uint32_t size; /**< The size of the data associated with a uid **/
53 psa_storage_create_flags_t flags; /**< The flags set when the uid was
54 created **/
Gilles Peskine601bd532019-02-24 11:34:28 +010055};
56
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020057/** Flag indicating that \ref psa_storage_create and \ref
58 * psa_storage_set_extended are supported */
Gilles Peskine601bd532019-02-24 11:34:28 +010059#define PSA_STORAGE_SUPPORT_SET_EXTENDED (1 << 0)
60
61/** \brief PSA storage specific error codes
62 */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020063#define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)-149)
64#define PSA_ERROR_DATA_CORRUPT ((psa_status_t)-152)
Gilles Peskine601bd532019-02-24 11:34:28 +010065
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020066#define PSA_ITS_API_VERSION_MAJOR \
67 1 /**< The major version number of the PSA ITS API. It will be incremented \
68 on significant updates that may include breaking changes */
69#define PSA_ITS_API_VERSION_MINOR \
70 1 /**< The minor version number of the PSA ITS API. It will be incremented \
71 in small updates that are unlikely to include breaking changes */
Gilles Peskine5f544972019-02-24 11:26:36 +010072
73/**
74 * \brief create a new or modify an existing uid/value pair
75 *
76 * \param[in] uid the identifier for the data
77 * \param[in] data_length The size in bytes of the data in `p_data`
78 * \param[in] p_data A buffer containing the data
79 * \param[in] create_flags The flags that the data will be stored with
Gilles Peskine601bd532019-02-24 11:34:28 +010080 *
Gilles Peskine5f544972019-02-24 11:26:36 +010081 * \return A status indicating the success/failure of the operation
Gilles Peskine601bd532019-02-24 11:34:28 +010082 *
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020083 * \retval #PSA_SUCCESS The operation completed
84 * successfully \retval #PSA_ERROR_NOT_PERMITTED The operation
85 * failed because the provided `uid` value was already created with
86 * PSA_STORAGE_WRITE_ONCE_FLAG \retval #PSA_ERROR_NOT_SUPPORTED The
87 * operation failed because one or more of the flags provided in `create_flags`
88 * is not supported or is not valid \retval #PSA_ERROR_INSUFFICIENT_STORAGE
89 * The operation failed because there was insufficient space on the storage
90 * medium \retval #PSA_ERROR_STORAGE_FAILURE The operation failed
91 * because the physical storage has failed (Fatal error) \retval
92 * #PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the
93 * provided pointers(`p_data`)
Gilles Peskine5f544972019-02-24 11:26:36 +010094 * is invalid, for example is `NULL` or references memory the caller cannot access
95 */
96psa_status_t psa_its_set(psa_storage_uid_t uid,
97 uint32_t data_length,
98 const void *p_data,
99 psa_storage_create_flags_t create_flags);
100
101/**
102 * \brief Retrieve the value associated with a provided uid
103 *
104 * \param[in] uid The uid value
105 * \param[in] data_offset The starting offset of the data requested
106 * \param[in] data_length the amount of data requested (and the minimum allocated size of the `p_data` buffer)
107 * \param[out] p_data The buffer where the data will be placed upon successful completion
Simon D Hughesbda5a212019-07-10 16:34:21 +0100108 * \param[out] p_data_length The amount of data returned in the p_data buffer
Gilles Peskine601bd532019-02-24 11:34:28 +0100109 *
110 *
Gilles Peskine5f544972019-02-24 11:26:36 +0100111 * \return A status indicating the success/failure of the operation
112 *
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200113 * \retval #PSA_SUCCESS The operation completed
114 * successfully \retval #PSA_ERROR_DOES_NOT_EXIST The operation failed
115 * because the provided `uid` value was not found in the storage \retval
116 * #PSA_ERROR_STORAGE_FAILURE The operation failed because the physical
117 * storage has failed (Fatal error) \retval #PSA_ERROR_DATA_CORRUPT The
118 * operation failed because stored data has been corrupted \retval
119 * #PSA_ERROR_INVALID_ARGUMENT The operation failed because one of the provided
120 * pointers(`p_data`, `p_data_length`)
Gilles Peskine5f544972019-02-24 11:26:36 +0100121 * is invalid. For example is `NULL` or references memory the caller cannot access.
122 * In addition, this can also happen if an invalid offset was provided.
123 */
124psa_status_t psa_its_get(psa_storage_uid_t uid,
125 uint32_t data_offset,
126 uint32_t data_length,
Simon D Hughesbda5a212019-07-10 16:34:21 +0100127 void *p_data,
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200128 size_t *p_data_length);
Gilles Peskine5f544972019-02-24 11:26:36 +0100129
130/**
131 * \brief Retrieve the metadata about the provided uid
Gilles Peskine601bd532019-02-24 11:34:28 +0100132 *
Gilles Peskine5f544972019-02-24 11:26:36 +0100133 * \param[in] uid The uid value
134 * \param[out] p_info A pointer to the `psa_storage_info_t` struct that will be populated with the metadata
Gilles Peskine601bd532019-02-24 11:34:28 +0100135 *
Gilles Peskine5f544972019-02-24 11:26:36 +0100136 * \return A status indicating the success/failure of the operation
Gilles Peskine601bd532019-02-24 11:34:28 +0100137 *
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200138 * \retval #PSA_SUCCESS The operation completed
139 * successfully \retval #PSA_ERROR_DOES_NOT_EXIST The operation failed
140 * because the provided uid value was not found in the storage \retval
141 * #PSA_ERROR_DATA_CORRUPT The operation failed because stored data has
142 * been corrupted \retval #PSA_ERROR_INVALID_ARGUMENT The operation failed
143 * because one of the provided pointers(`p_info`)
Gilles Peskine5f544972019-02-24 11:26:36 +0100144 * is invalid, for example is `NULL` or references memory the caller cannot access
145 */
146psa_status_t psa_its_get_info(psa_storage_uid_t uid,
147 struct psa_storage_info_t *p_info);
148
149/**
150 * \brief Remove the provided key and its associated data from the storage
Gilles Peskine601bd532019-02-24 11:34:28 +0100151 *
Gilles Peskine5f544972019-02-24 11:26:36 +0100152 * \param[in] uid The uid value
Gilles Peskine601bd532019-02-24 11:34:28 +0100153 *
Gilles Peskine5f544972019-02-24 11:26:36 +0100154 * \return A status indicating the success/failure of the operation
Gilles Peskine601bd532019-02-24 11:34:28 +0100155 *
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200156 * \retval #PSA_SUCCESS The operation completed
157 * successfully \retval #PSA_ERROR_DOES_NOT_EXIST The operation failed
158 * because the provided key value was not found in the storage \retval
159 * #PSA_ERROR_NOT_PERMITTED The operation failed because the provided key
160 * value was created with PSA_STORAGE_WRITE_ONCE_FLAG \retval
161 * #PSA_ERROR_STORAGE_FAILURE The operation failed because the physical
162 * storage has failed (Fatal error)
Gilles Peskine5f544972019-02-24 11:26:36 +0100163 */
164psa_status_t psa_its_remove(psa_storage_uid_t uid);
165
Steven Cooreman8c310252020-10-22 10:43:45 +0200166#ifdef __cplusplus
167}
168#endif
169
Gilles Peskine601bd532019-02-24 11:34:28 +0100170#endif /* PSA_CRYPTO_ITS_H */