Mistake on this page?
Report an issue in GitHub or email us
protected_storage.h
Go to the documentation of this file.
1 /* Copyright (C) 2019, ARM Limited, All Rights Reserved
2  * SPDX-License-Identifier: Apache-2.0
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may
5  * not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /** @file
18 @brief This file describes the PSA Protected Storage API
19 */
20 
21 #ifndef __PSA_PROTECTED_STORAGE_H__
22 #define __PSA_PROTECTED_STORAGE_H__
23 
24 #include <stddef.h>
25 #include <stdint.h>
26 
27 #include "psa/error.h"
28 #include "psa/storage_common.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #define PSA_PS_API_VERSION_MAJOR 1 /**< The major version number of the PSA PS API. It will be incremented on significant updates that may include breaking changes */
35 #define PSA_PS_API_VERSION_MINOR 1 /**< The minor version number of the PSA PS API. It will be incremented in small updates that are unlikely to include breaking changes */
36 
37 
38 /**
39  * \brief create a new or modify an existing key/value pair
40  *
41  * \param[in] uid the identifier for the data
42  * \param[in] data_length The size in bytes of the data in `p_data`
43  * \param[in] p_data A buffer containing the data
44  * \param[in] create_flags The flags indicating the properties of the data
45  *
46  * \return A status indicating the success/failure of the operation
47 
48  * \retval PSA_SUCCESS The operation completed successfully
49  * \retval PSA_ERROR_NOT_PERMITTED The operation failed because the provided uid value was already created with PSA_STORAGE_WRITE_ONCE_FLAG
50  * \retval PSA_ERROR_INVALID_ARGUMENT The operation failed because one or more of the given arguments were invalid.
51  * \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
52  * \retval PSA_ERROR_INSUFFICIENT_STORAGE The operation failed because there was insufficient space on the storage medium
53  * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
54  * \retval PSA_ERROR_GENERIC_ERROR The operation failed because of an unspecified internal failure
55  */
56 psa_status_t psa_ps_set(psa_storage_uid_t uid,
57  uint32_t data_length,
58  const void *p_data,
59  psa_storage_create_flags_t create_flags);
60 
61 /**
62  * \brief Retrieve the value for a provided uid
63  *
64  * \param[in] uid The identifier for the data
65  * \param[in] data_offset The offset within the data associated with the `uid` to start retrieving data
66  * \param[in] data_length The amount of data to read (and the minimum allocated size of the `p_data` buffer)
67  * \param[out] p_data The buffer where the data will be placed upon successful completion
68  *
69  * \return A status indicating the success/failure of the operation
70  *
71  * \retval PSA_SUCCESS The operation completed successfully
72  * \retval PSA_ERROR_INVALID_ARGUMENT The operation failed because one or more of the given arguments were invalid (null pointer, wrong flags etc.)
73  * \retval PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided uid value was not found in the storage
74  * \retval PSA_ERROR_BUFFER_TOO_SMALL The operation failed because the data associated with provided uid is not the same size as `data_size`
75  * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
76  * \retval PSA_ERROR_GENERIC_ERROR The operation failed because of an unspecified internal failure
77  * \retval PSA_ERROR_DATA_CORRUPT The operation failed because of an authentication failure when attempting to get the key
78  * \retval PSA_ERROR_INVALID_SIGNATURE The operation failed because the data associated with the UID failed authentication
79  */
80 psa_status_t psa_ps_get(psa_storage_uid_t uid,
81  uint32_t data_offset,
82  uint32_t data_length,
83  void *p_data);
84 
85 /**
86  * \brief Retrieve the metadata about the provided uid
87  *
88  * \param[in] uid The identifier for the data
89  * \param[out] p_info A pointer to the `psa_storage_info_t` struct that will be populated with the metadata
90  *
91  * \return A status indicating the success/failure of the operation
92  *
93  * \retval PSA_SUCCESS The operation completed successfully
94  * \retval PSA_ERROR_INVALID_ARGUMENT The operation failed because one or more of the given arguments were invalid (null pointer, wrong flags etc.)
95  * \retval PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided uid value was not found in the storage
96  * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
97  * \retval PSA_ERROR_GENERIC_ERROR The operation failed because of an unspecified internal failure
98  * \retval PSA_ERROR_DATA_CORRUPT The operation failed because of an authentication failure when attempting to get the key
99  * \retval PSA_ERROR_INVALID_SIGNATURE The operation failed because the data associated with the UID failed authentication
100  */
101 psa_status_t psa_ps_get_info(psa_storage_uid_t uid, struct psa_storage_info_t *p_info);
102 
103 /**
104  * \brief Remove the provided uid and its associated data from the storage
105  *
106  * \param[in] uid The identifier for the data to be removed
107  *
108  * \return A status indicating the success/failure of the operation
109  *
110  * \retval PSA_SUCCESS The operation completed successfully
111  * \retval PSA_ERROR_INVALID_ARGUMENT The operation failed because one or more of the given arguments were invalid (null pointer, wrong flags etc.)
112  * \retval PSA_ERROR_DOES_NOT_EXIST The operation failed because the provided uid value was not found in the storage
113  * \retval PSA_ERROR_NOT_PERMITTED The operation failed because the provided uid value was created with psa_eps_WRITE_ONCE_FLAG
114  * \retval PSA_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
115  * \retval PSA_ERROR_GENERIC_ERROR The operation failed because of an unspecified internal failure
116  */
117 psa_status_t psa_ps_remove(psa_storage_uid_t uid);
118 
119 /**
120  * Creates an asset based on the given identifier, the maximum size and
121  * creation flags. This create allocates the space in the secure storage
122  * area without setting any data in the asset.
123  *
124  * It is only necessary to call this function for items that will be written
125  * with the \ref psa_ps_set_extended function. If only the \ref psa_ps_set function
126  * is needed, calls to this function are redundant.
127  *
128  * If the \ref PSA_STORAGE_FLAG_WRITE_ONCE flag is passed, implementations should
129  * return \ref PSA_ERROR_NOT_SUPPORTED.
130  *
131  * This function is optional. Not all PSA Protected Storage Implementations
132  * will implement this function. Consult the documentation of your chosen
133  * platform to determine if it is present.
134  *
135  * \param[in] uid A unique identifier for the asset.
136  * \param[in] size The maximum size in bytes of the asset.
137  * \param[in] create_flags Create flags \ref psa_storage_create_flags_t.
138  *
139  * \retval PSA_SUCCESS The assest does not exist and the input parameters are correct or
140  * the asset already exists, the input parameters are the same that
141  * have been used to create the asset and the owner is the same and the current asset content is kept
142  * TDB: "Owner is the same" doesn't really make sense from a PSA perspective, as each partition
143  * has its own UID space, making other partitions' data unadressable
144  * \retval PSA_ERROR_STORAGE_FAILURE The create action has a physical storage error
145  * \retval PSA_ERROR_INSUFFICIENT_STORAGE The maximum size is bigger of the current available space
146  * \retval PSA_ERROR_NOT_SUPPORTED One or more create_flags are not valid or supported
147  * \retval PSA_ERROR_INVALID_ARGUMENT The asset exists and the input paramters are not the same as the existing asset
148  * \retval PSA_ERROR_NOT_SUPPORTED The implementation of the API does not support this function
149  * \retval PSA_ERROR_GENERIC_ERROR The operation has failed due to an unspecified error
150  */
151 psa_status_t psa_ps_create(psa_storage_uid_t uid,
152  uint32_t size,
153  psa_storage_create_flags_t create_flags);
154 
155 /**
156  * Sets partial data into an asset based on the given identifier, data_offset,
157  * data length and p_data.
158  *
159  * Before calling this function, the asset must have been created with a call
160  * to \ref psa_ps_create.
161  *
162  * This function is optional. Not all PSA Protected Storage Implementations
163  * will implement this function. Consult the documentation of your chosen
164  * platform to determine if it is present.
165  *
166  * \param[in] uid The unique identifier for the asset.
167  * \param[in] data_offset Offset within the asset to start the write.
168  * \param[in] data_length The size in bytes of the data in p_data to write.
169  * \param[in] p_data Pointer to a buffer which contains the data to write.
170  *
171  * \retval PSA_SUCCESS If the asset exists, the input parameters are correct and the data
172  * is correctly written in the physical storage
173  * \retval PSA_ERROR_STORAGE_FAILURE If the data is not written correctly in the physical storage
174  * \retval PSA_ERROR_INVALID_ARGUMENT The operation failed because one or more of the given arguments were invalid (null pointer, wrong flags, etc)
175  * \retval PSA_ERROR_DOES_NOT_EXIST The specified UID was not found
176  * \retval PSA_ERROR_NOT_SUPPORTED The implementation of the API does not support this function
177  * \retval PSA_ERROR_GENERIC_ERROR The operation failed due to an unspecified error
178  * \retval PSA_ERROR_DATA_CORRUPT The operation failed because the existing data has been corrupted
179  * \retval PSA_ERROR_INVALID_SIGNATURE The operation failed because the existing data failed authentication (MAC check failed)
180  */
181 psa_status_t psa_ps_set_extended(psa_storage_uid_t uid,
182  uint32_t data_offset,
183  uint32_t data_length,
184  const void *p_data);
185 
186 /**
187  * Returns a bitmask with flags set for all of the optional features supported
188  * by the implementation.
189  *
190  * Currently defined flags are limited to:
191  * - \ref PSA_STORAGE_SUPPORT_SET_EXTENDED
192  */
193 uint32_t psa_ps_get_support(void);
194 
195 #ifdef __cplusplus
196 }
197 #endif
198 
199 
200 #endif // __PSA_PROTECTED_STORAGE_H__
psa_status_t psa_ps_set(psa_storage_uid_t uid, uint32_t data_length, const void *p_data, psa_storage_create_flags_t create_flags)
create a new or modify an existing key/value pair
This file includes common definitions for PSA storage.
psa_status_t psa_ps_get_info(psa_storage_uid_t uid, struct psa_storage_info_t *p_info)
Retrieve the metadata about the provided uid.
psa_status_t psa_ps_create(psa_storage_uid_t uid, uint32_t size, psa_storage_create_flags_t create_flags)
Creates an asset based on the given identifier, the maximum size and creation flags.
psa_status_t psa_ps_remove(psa_storage_uid_t uid)
Remove the provided uid and its associated data from the storage.
psa_status_t psa_ps_get(psa_storage_uid_t uid, uint32_t data_offset, uint32_t data_length, void *p_data)
Retrieve the value for a provided uid.
uint32_t psa_ps_get_support(void)
Returns a bitmask with flags set for all of the optional features supported by the implementation...
uint64_t psa_storage_uid_t
A type for UIDs used for identifying data.
A container for metadata associated with a specific uid.
psa_status_t psa_ps_set_extended(psa_storage_uid_t uid, uint32_t data_offset, uint32_t data_length, const void *p_data)
Sets partial data into an asset based on the given identifier, data_offset, data length and p_data...
uint32_t psa_storage_create_flags_t
Flags used when creating a data entry.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.