blob: dee30225c3b4e20d50fec69b3cb1cdfa4abbba58 [file] [log] [blame]
Ashutosh Singhf4d88672017-11-29 13:35:43 +00001/*
Marc Moreno Berengue675b6e92018-06-14 17:31:01 +01002 * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
Ashutosh Singhf4d88672017-11-29 13:35:43 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +01008/**
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 Singhf4d88672017-11-29 13:35:43 +000021
22#ifdef __cplusplus
23extern "C" {
24#endif
25
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +010026/*
27 * PSA SST API version
28 */
29#define PSA_SST_API_VERSION_MAJOR 0
Marc Moreno Berengue092aaf02018-07-12 11:30:33 +010030#define PSA_SST_API_VERSION_MINOR 2
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +010031
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 */
43enum 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 Angeliseba14e12018-03-27 11:03:20 +010053
Ashutosh Singhf4d88672017-11-29 13:35:43 +000054/**
Marc Moreno Berengue4258e542018-06-18 13:55:59 +010055 * \brief Allocates space for the asset, referenced by asset UUID,
Ashutosh Singhf4d88672017-11-29 13:35:43 +000056 * without setting any data in the asset.
57 *
58 * \param[in] asset_uuid Asset UUID
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010059 * \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 Singhf4d88672017-11-29 13:35:43 +000067 *
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +010068 * \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 Singhf4d88672017-11-29 13:35:43 +000070 */
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +010071enum psa_sst_err_t psa_sst_create(uint32_t asset_uuid,
Marc Moreno Berenguec304f922018-07-12 11:39:11 +010072 const uint8_t *token,
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010073 uint32_t token_size);
Ashutosh Singhf4d88672017-11-29 13:35:43 +000074
75/**
Marc Moreno Berengue4258e542018-06-18 13:55:59 +010076 * \brief Gets asset's information referenced by asset UUID.
Ashutosh Singhf4d88672017-11-29 13:35:43 +000077 *
Marc Moreno Berengue4258e542018-06-18 13:55:59 +010078 * \param[in] asset_uuid Asset UUID
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010079 * \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 Berengue4258e542018-06-18 13:55:59 +010087 * \param[out] info Pointer to store the asset's information
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +010088 * \ref psa_sst_asset_info_t
Ashutosh Singhf4d88672017-11-29 13:35:43 +000089 *
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +010090 * \return Returns error code as specified in \ref psa_sst_err_t
Ashutosh Singhf4d88672017-11-29 13:35:43 +000091 */
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +010092enum psa_sst_err_t psa_sst_get_info(uint32_t asset_uuid,
Marc Moreno Berenguec304f922018-07-12 11:39:11 +010093 const uint8_t *token,
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +010094 uint32_t token_size,
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +010095 struct psa_sst_asset_info_t *info);
Ashutosh Singhf4d88672017-11-29 13:35:43 +000096
97/**
Marc Moreno Berengue4258e542018-06-18 13:55:59 +010098 * \brief Gets asset's attributes referenced by asset UUID.
Marc Moreno Berengue51af9512018-06-14 18:28:14 +010099 *
Marc Moreno Berengue4258e542018-06-18 13:55:59 +0100100 * \param[in] asset_uuid Asset UUID
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +0100101 * \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 Berengue4258e542018-06-18 13:55:59 +0100109 * \param[out] attrs Pointer to store the asset's attributes
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100110 * \ref psa_sst_asset_attrs_t
Marc Moreno Berengue51af9512018-06-14 18:28:14 +0100111 *
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100112 * \return Returns error code as specified in \ref psa_sst_err_t
Marc Moreno Berengue51af9512018-06-14 18:28:14 +0100113 */
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100114enum psa_sst_err_t psa_sst_get_attributes(uint32_t asset_uuid,
Marc Moreno Berenguec304f922018-07-12 11:39:11 +0100115 const uint8_t *token,
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +0100116 uint32_t token_size,
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100117 struct psa_sst_asset_attrs_t *attrs);
Marc Moreno Berengue51af9512018-06-14 18:28:14 +0100118
119/**
Marc Moreno Berengue4258e542018-06-18 13:55:59 +0100120 * \brief Sets asset's attributes referenced by asset UUID.
Marc Moreno Berengue51af9512018-06-14 18:28:14 +0100121 *
Marc Moreno Berengue4258e542018-06-18 13:55:59 +0100122 * \param[in] asset_uuid Asset UUID
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +0100123 * \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 Berengue4258e542018-06-18 13:55:59 +0100131 * \param[in] attrs Pointer to new the asset's attributes
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100132 * \ref psa_sst_asset_attrs_t
Marc Moreno Berengue51af9512018-06-14 18:28:14 +0100133 *
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100134 * \return Returns error code as specified in \ref psa_sst_err_t
Marc Moreno Berengue51af9512018-06-14 18:28:14 +0100135 */
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100136enum psa_sst_err_t psa_sst_set_attributes(
Marc Moreno Berengue4258e542018-06-18 13:55:59 +0100137 uint32_t asset_uuid,
Marc Moreno Berenguec304f922018-07-12 11:39:11 +0100138 const uint8_t *token,
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +0100139 uint32_t token_size,
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100140 const struct psa_sst_asset_attrs_t *attrs);
Marc Moreno Berengue51af9512018-06-14 18:28:14 +0100141
142/**
Marc Moreno Berengue4258e542018-06-18 13:55:59 +0100143 * \brief Reads asset's data from asset referenced by asset UUID.
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000144 *
Marc Moreno Berengue4258e542018-06-18 13:55:59 +0100145 * \param[in] asset_uuid Asset UUID
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +0100146 * \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 Berengue79032942018-06-26 15:34:05 +0100154 * \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 Singhf4d88672017-11-29 13:35:43 +0000157 *
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100158 * \return Returns error code as specified in \ref psa_sst_err_t
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000159 */
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100160enum psa_sst_err_t psa_sst_read(uint32_t asset_uuid,
Marc Moreno Berenguec304f922018-07-12 11:39:11 +0100161 const uint8_t *token,
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +0100162 uint32_t token_size,
Marc Moreno Berengue79032942018-06-26 15:34:05 +0100163 uint32_t size,
164 uint32_t offset,
165 uint8_t *data);
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000166
167/**
Marc Moreno Berengue092aaf02018-07-12 11:30:33 +0100168 * \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 */
190enum psa_sst_err_t psa_sst_reference_read(int32_t client_id,
191 uint32_t asset_uuid,
Marc Moreno Berenguec304f922018-07-12 11:39:11 +0100192 const uint8_t *token,
Marc Moreno Berengue092aaf02018-07-12 11:30:33 +0100193 uint32_t token_size,
194 uint32_t size,
195 uint32_t offset,
196 uint8_t *data);
197
198/**
Marc Moreno Berengue4258e542018-06-18 13:55:59 +0100199 * \brief Writes data into an asset referenced by asset UUID.
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000200 *
Marc Moreno Berengue4258e542018-06-18 13:55:59 +0100201 * \param[in] asset_uuid Asset UUID
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +0100202 * \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 Berengue79032942018-06-26 15:34:05 +0100210 * \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 Singhf4d88672017-11-29 13:35:43 +0000214 *
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100215 * \return Returns error code as specified in \ref psa_sst_err_t
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000216 */
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100217enum psa_sst_err_t psa_sst_write(uint32_t asset_uuid,
Marc Moreno Berenguec304f922018-07-12 11:39:11 +0100218 const uint8_t *token,
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +0100219 uint32_t token_size,
Marc Moreno Berengue79032942018-06-26 15:34:05 +0100220 uint32_t size,
221 uint32_t offset,
222 const uint8_t *data);
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000223
224/**
Marc Moreno Berengue4258e542018-06-18 13:55:59 +0100225 * \brief Deletes the asset referenced by the asset UUID.
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000226 *
Marc Moreno Berengue4258e542018-06-18 13:55:59 +0100227 * \param[in] asset_uuid Asset UUID
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +0100228 * \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 Singhf4d88672017-11-29 13:35:43 +0000236 *
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100237 * \return Returns error code as specified in \ref psa_sst_err_t
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000238 */
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100239enum psa_sst_err_t psa_sst_delete(uint32_t asset_uuid,
Marc Moreno Berenguec304f922018-07-12 11:39:11 +0100240 const uint8_t *token,
Marc Moreno Berengue10d0d362018-06-18 14:15:56 +0100241 uint32_t token_size);
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000242
243#ifdef __cplusplus
244}
245#endif
246
Marc Moreno Berengue7d053a32018-06-27 18:22:14 +0100247#endif /* __PSA_SST_API__ */