Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 1 | /* |
Marc Moreno Berengue | 675b6e9 | 2018-06-14 17:31:01 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, Arm Limited. All rights reserved. |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 8 | /** |
| 9 | * \file psa_sst_api.h |
| 10 | * |
| 11 | * \brief Platform security architecture (PSA) API for secure storage partition |
| 12 | */ |
| 13 | |
| 14 | #ifndef __PSA_SST_API__ |
| 15 | #define __PSA_SST_API__ |
| 16 | |
| 17 | #include "psa_sst_asset_defs.h" |
| 18 | #include "psa_sst_asset_macros.h" |
| 19 | |
| 20 | #include "tfm_api.h" |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 21 | |
| 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 26 | /* |
| 27 | * PSA SST API version |
| 28 | */ |
| 29 | #define PSA_SST_API_VERSION_MAJOR 0 |
Marc Moreno Berengue | 092aaf0 | 2018-07-12 11:30:33 +0100 | [diff] [blame] | 30 | #define PSA_SST_API_VERSION_MINOR 2 |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 31 | |
| 32 | /* The return value is shared with the TF-M partition status value. |
| 33 | * The SST return codes shouldn't overlap with predefined TFM status values. |
| 34 | */ |
| 35 | #define PSA_SST_ERR_OFFSET (TFM_PARTITION_SPECIFIC_ERROR_MIN) |
| 36 | |
| 37 | /*! |
| 38 | * \enum psa_sst_err_t |
| 39 | * |
| 40 | * \brief Secure storage service error types |
| 41 | * |
| 42 | */ |
| 43 | enum psa_sst_err_t { |
| 44 | PSA_SST_ERR_SUCCESS = 0, |
| 45 | PSA_SST_ERR_ASSET_NOT_PREPARED = PSA_SST_ERR_OFFSET, |
| 46 | PSA_SST_ERR_ASSET_NOT_FOUND, |
| 47 | PSA_SST_ERR_PARAM_ERROR, |
| 48 | PSA_SST_ERR_STORAGE_SYSTEM_FULL, |
| 49 | PSA_SST_ERR_SYSTEM_ERROR, |
| 50 | /* Following entry is only to ensure the error code of int size */ |
| 51 | PSA_SST_ERR_FORCE_INT_SIZE = INT_MAX |
| 52 | }; |
Antonio de Angelis | eba14e1 | 2018-03-27 11:03:20 +0100 | [diff] [blame] | 53 | |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 54 | /** |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 55 | * \brief Allocates space for the asset, referenced by asset UUID, |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 56 | * without setting any data in the asset. |
| 57 | * |
| 58 | * \param[in] asset_uuid Asset UUID |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 59 | * \param[in] token Must be set to NULL, reserved for future use. |
| 60 | * Pointer to the asset token to be used to generate |
| 61 | * the asset key to encrypt and decrypt the asset |
| 62 | * data. This is an optional parameter that has to |
| 63 | * be NULL in case the token is not provied. |
| 64 | * \param[in] token_size Must be set to 0, reserved for future use. |
| 65 | * Token size. In case the token is not provided |
| 66 | * the token size has to be 0. |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 67 | * |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 68 | * \return Returns an PSA_SST_ERR_SUCCESS if asset is created correctly. |
| 69 | * Otherwise, error code as specified in \ref psa_sst_err_t |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 70 | */ |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 71 | enum psa_sst_err_t psa_sst_create(uint32_t asset_uuid, |
Marc Moreno Berengue | c304f92 | 2018-07-12 11:39:11 +0100 | [diff] [blame] | 72 | const uint8_t *token, |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 73 | uint32_t token_size); |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 74 | |
| 75 | /** |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 76 | * \brief Gets asset's information referenced by asset UUID. |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 77 | * |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 78 | * \param[in] asset_uuid Asset UUID |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 79 | * \param[in] token Must be set to NULL, reserved for future use. |
| 80 | * Pointer to the asset token to be used to generate |
| 81 | * the asset key to encrypt and decrypt the asset |
| 82 | * data. This is an optional parameter that has to |
| 83 | * be NULL in case the token is not provied. |
| 84 | * \param[in] token_size Must be set to 0, reserved for future use. |
| 85 | * Token size. In case the token is not provided |
| 86 | * the token size has to be 0. |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 87 | * \param[out] info Pointer to store the asset's information |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 88 | * \ref psa_sst_asset_info_t |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 89 | * |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 90 | * \return Returns error code as specified in \ref psa_sst_err_t |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 91 | */ |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 92 | enum psa_sst_err_t psa_sst_get_info(uint32_t asset_uuid, |
Marc Moreno Berengue | c304f92 | 2018-07-12 11:39:11 +0100 | [diff] [blame] | 93 | const uint8_t *token, |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 94 | uint32_t token_size, |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 95 | struct psa_sst_asset_info_t *info); |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 96 | |
| 97 | /** |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 98 | * \brief Gets asset's attributes referenced by asset UUID. |
Marc Moreno Berengue | 51af951 | 2018-06-14 18:28:14 +0100 | [diff] [blame] | 99 | * |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 100 | * \param[in] asset_uuid Asset UUID |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 101 | * \param[in] token Must be set to NULL, reserved for future use. |
| 102 | * Pointer to the asset token to be used to generate |
| 103 | * the asset key to encrypt and decrypt the asset |
| 104 | * data. This is an optional parameter that has to |
| 105 | * be NULL in case the token is not provied. |
| 106 | * \param[in] token_size Must be set to 0, reserved for future use. |
| 107 | * Token size. In case the token is not provided |
| 108 | * the token size has to be 0. |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 109 | * \param[out] attrs Pointer to store the asset's attributes |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 110 | * \ref psa_sst_asset_attrs_t |
Marc Moreno Berengue | 51af951 | 2018-06-14 18:28:14 +0100 | [diff] [blame] | 111 | * |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 112 | * \return Returns error code as specified in \ref psa_sst_err_t |
Marc Moreno Berengue | 51af951 | 2018-06-14 18:28:14 +0100 | [diff] [blame] | 113 | */ |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 114 | enum psa_sst_err_t psa_sst_get_attributes(uint32_t asset_uuid, |
Marc Moreno Berengue | c304f92 | 2018-07-12 11:39:11 +0100 | [diff] [blame] | 115 | const uint8_t *token, |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 116 | uint32_t token_size, |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 117 | struct psa_sst_asset_attrs_t *attrs); |
Marc Moreno Berengue | 51af951 | 2018-06-14 18:28:14 +0100 | [diff] [blame] | 118 | |
| 119 | /** |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 120 | * \brief Sets asset's attributes referenced by asset UUID. |
Marc Moreno Berengue | 51af951 | 2018-06-14 18:28:14 +0100 | [diff] [blame] | 121 | * |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 122 | * \param[in] asset_uuid Asset UUID |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 123 | * \param[in] token Must be set to NULL, reserved for future use. |
| 124 | * Pointer to the asset token to be used to generate |
| 125 | * the asset key to encrypt and decrypt the asset |
| 126 | * data. This is an optional parameter that has to |
| 127 | * be NULL in case the token is not provied. |
| 128 | * \param[in] token_size Must be set to 0, reserved for future use. |
| 129 | * Token size. In case the token is not provided |
| 130 | * the token size has to be 0. |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 131 | * \param[in] attrs Pointer to new the asset's attributes |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 132 | * \ref psa_sst_asset_attrs_t |
Marc Moreno Berengue | 51af951 | 2018-06-14 18:28:14 +0100 | [diff] [blame] | 133 | * |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 134 | * \return Returns error code as specified in \ref psa_sst_err_t |
Marc Moreno Berengue | 51af951 | 2018-06-14 18:28:14 +0100 | [diff] [blame] | 135 | */ |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 136 | enum psa_sst_err_t psa_sst_set_attributes( |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 137 | uint32_t asset_uuid, |
Marc Moreno Berengue | c304f92 | 2018-07-12 11:39:11 +0100 | [diff] [blame] | 138 | const uint8_t *token, |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 139 | uint32_t token_size, |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 140 | const struct psa_sst_asset_attrs_t *attrs); |
Marc Moreno Berengue | 51af951 | 2018-06-14 18:28:14 +0100 | [diff] [blame] | 141 | |
| 142 | /** |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 143 | * \brief Reads asset's data from asset referenced by asset UUID. |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 144 | * |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 145 | * \param[in] asset_uuid Asset UUID |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 146 | * \param[in] token Must be set to NULL, reserved for future use. |
| 147 | * Pointer to the asset token to be used to generate |
| 148 | * the asset key to encrypt and decrypt the asset |
| 149 | * data. This is an optional parameter that has to |
| 150 | * be NULL in case the token is not provied. |
| 151 | * \param[in] token_size Must be set to 0, reserved for future use. |
| 152 | * Token size. In case the token is not provided |
| 153 | * the token size has to be 0. |
Marc Moreno Berengue | 7903294 | 2018-06-26 15:34:05 +0100 | [diff] [blame] | 154 | * \param[in] size Size of the data to read |
| 155 | * \param[in] offset Offset within asset to start to read |
| 156 | * \param[out] data Pointer to data vector to store data |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 157 | * |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 158 | * \return Returns error code as specified in \ref psa_sst_err_t |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 159 | */ |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 160 | enum psa_sst_err_t psa_sst_read(uint32_t asset_uuid, |
Marc Moreno Berengue | c304f92 | 2018-07-12 11:39:11 +0100 | [diff] [blame] | 161 | const uint8_t *token, |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 162 | uint32_t token_size, |
Marc Moreno Berengue | 7903294 | 2018-06-26 15:34:05 +0100 | [diff] [blame] | 163 | uint32_t size, |
| 164 | uint32_t offset, |
| 165 | uint8_t *data); |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 166 | |
| 167 | /** |
Marc Moreno Berengue | 092aaf0 | 2018-07-12 11:30:33 +0100 | [diff] [blame] | 168 | * \brief Reads asset's data on behalf of the given client ID if the |
| 169 | * client has reference permissions. |
| 170 | * This function is only accessible for secure partition with specific |
| 171 | * permissions. Hence, It must not be accessible from the Non-secure |
| 172 | * Processing Environment (NSPE). |
| 173 | * |
| 174 | * \param[in] client_id Client ID which is referenced in the read |
| 175 | * \param[in] asset_uuid Asset UUID |
| 176 | * \param[in] token Must be set to NULL, reserved for future use. |
| 177 | * Pointer to the asset token to be used to generate |
| 178 | * the asset key to encrypt and decrypt the asset |
| 179 | * data. This is an optional parameter that has to |
| 180 | * be NULL in case the token is not provied. |
| 181 | * \param[in] token_size Must be set to 0, reserved for future use. |
| 182 | * Token size. In case the token is not provided |
| 183 | * the token size has to be 0. |
| 184 | * \param[in] size Size of the data to read |
| 185 | * \param[in] offset Offset within asset to start to read |
| 186 | * \param[out] data Pointer to data vector to store data |
| 187 | * |
| 188 | * \return Returns error code as specified in \ref psa_sst_err_t |
| 189 | */ |
| 190 | enum psa_sst_err_t psa_sst_reference_read(int32_t client_id, |
| 191 | uint32_t asset_uuid, |
Marc Moreno Berengue | c304f92 | 2018-07-12 11:39:11 +0100 | [diff] [blame] | 192 | const uint8_t *token, |
Marc Moreno Berengue | 092aaf0 | 2018-07-12 11:30:33 +0100 | [diff] [blame] | 193 | uint32_t token_size, |
| 194 | uint32_t size, |
| 195 | uint32_t offset, |
| 196 | uint8_t *data); |
| 197 | |
| 198 | /** |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 199 | * \brief Writes data into an asset referenced by asset UUID. |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 200 | * |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 201 | * \param[in] asset_uuid Asset UUID |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 202 | * \param[in] token Must be set to NULL, reserved for future use. |
| 203 | * Pointer to the asset token to be used to generate |
| 204 | * the asset key to encrypt and decrypt the asset |
| 205 | * data. This is an optional parameter that has to |
| 206 | * be NULL in case the token is not provied. |
| 207 | * \param[in] token_size Must be set to 0, reserved for future use. |
| 208 | * Token size. In case the token is not provided |
| 209 | * the token size has to be 0. |
Marc Moreno Berengue | 7903294 | 2018-06-26 15:34:05 +0100 | [diff] [blame] | 210 | * \param[in] size Size of the data to start to write |
| 211 | * \param[in] offset Offset within asset to write the data |
| 212 | * \param[in] data Pointer to data vector which contains the data to |
| 213 | * write |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 214 | * |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 215 | * \return Returns error code as specified in \ref psa_sst_err_t |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 216 | */ |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 217 | enum psa_sst_err_t psa_sst_write(uint32_t asset_uuid, |
Marc Moreno Berengue | c304f92 | 2018-07-12 11:39:11 +0100 | [diff] [blame] | 218 | const uint8_t *token, |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 219 | uint32_t token_size, |
Marc Moreno Berengue | 7903294 | 2018-06-26 15:34:05 +0100 | [diff] [blame] | 220 | uint32_t size, |
| 221 | uint32_t offset, |
| 222 | const uint8_t *data); |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 223 | |
| 224 | /** |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 225 | * \brief Deletes the asset referenced by the asset UUID. |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 226 | * |
Marc Moreno Berengue | 4258e54 | 2018-06-18 13:55:59 +0100 | [diff] [blame] | 227 | * \param[in] asset_uuid Asset UUID |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 228 | * \param[in] token Must be set to NULL, reserved for future use. |
| 229 | * Pointer to the asset token to be used to generate |
| 230 | * the asset key to encrypt and decrypt the asset |
| 231 | * data. This is an optional parameter that has to |
| 232 | * be NULL in case the token is not provied. |
| 233 | * \param[in] token_size Must be set to 0, reserved for future use. |
| 234 | * Token size. In case the token is not provided |
| 235 | * the token size has to be 0. |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 236 | * |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 237 | * \return Returns error code as specified in \ref psa_sst_err_t |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 238 | */ |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 239 | enum psa_sst_err_t psa_sst_delete(uint32_t asset_uuid, |
Marc Moreno Berengue | c304f92 | 2018-07-12 11:39:11 +0100 | [diff] [blame] | 240 | const uint8_t *token, |
Marc Moreno Berengue | 10d0d36 | 2018-06-18 14:15:56 +0100 | [diff] [blame] | 241 | uint32_t token_size); |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 242 | |
| 243 | #ifdef __cplusplus |
| 244 | } |
| 245 | #endif |
| 246 | |
Marc Moreno Berengue | 7d053a3 | 2018-06-27 18:22:14 +0100 | [diff] [blame] | 247 | #endif /* __PSA_SST_API__ */ |