xref: /optee_os/lib/libmbedtls/mbedtls/library/psa_crypto_storage.h (revision c3deb3d6f3b13d0e17fc9efe5880aec039e47594)
1b0563631STom Van Eyck /**
2b0563631STom Van Eyck  * \file psa_crypto_storage.h
3b0563631STom Van Eyck  *
4b0563631STom Van Eyck  * \brief PSA cryptography module: Mbed TLS key storage
5b0563631STom Van Eyck  */
6b0563631STom Van Eyck /*
7b0563631STom Van Eyck  *  Copyright The Mbed TLS Contributors
8b0563631STom Van Eyck  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9b0563631STom Van Eyck  */
10b0563631STom Van Eyck 
11b0563631STom Van Eyck #ifndef PSA_CRYPTO_STORAGE_H
12b0563631STom Van Eyck #define PSA_CRYPTO_STORAGE_H
13b0563631STom Van Eyck 
14b0563631STom Van Eyck #ifdef __cplusplus
15b0563631STom Van Eyck extern "C" {
16b0563631STom Van Eyck #endif
17b0563631STom Van Eyck 
18b0563631STom Van Eyck #include "psa/crypto.h"
19b0563631STom Van Eyck #include "psa/crypto_se_driver.h"
20b0563631STom Van Eyck 
21b0563631STom Van Eyck #include <stdint.h>
22b0563631STom Van Eyck #include <string.h>
23b0563631STom Van Eyck 
24*c3deb3d6SEtienne Carriere /* Limit the maximum key size in storage. */
25*c3deb3d6SEtienne Carriere #if defined(MBEDTLS_PSA_STATIC_KEY_SLOTS)
26*c3deb3d6SEtienne Carriere /* Reflect the maximum size for the key buffer. */
27*c3deb3d6SEtienne Carriere #define PSA_CRYPTO_MAX_STORAGE_SIZE (MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE)
28*c3deb3d6SEtienne Carriere #else
29*c3deb3d6SEtienne Carriere /* Just set an upper boundary but it should have no effect since the key size
30*c3deb3d6SEtienne Carriere  * is limited in memory. */
31b0563631STom Van Eyck #define PSA_CRYPTO_MAX_STORAGE_SIZE (PSA_BITS_TO_BYTES(PSA_MAX_KEY_BITS))
32*c3deb3d6SEtienne Carriere #endif
33*c3deb3d6SEtienne Carriere 
34b0563631STom Van Eyck /* Sanity check: a file size must fit in 32 bits. Allow a generous
35b0563631STom Van Eyck  * 64kB of metadata. */
36b0563631STom Van Eyck #if PSA_CRYPTO_MAX_STORAGE_SIZE > 0xffff0000
37b0563631STom Van Eyck #error "PSA_CRYPTO_MAX_STORAGE_SIZE > 0xffff0000"
38b0563631STom Van Eyck #endif
39b0563631STom Van Eyck 
40b0563631STom Van Eyck /** The maximum permitted persistent slot number.
41b0563631STom Van Eyck  *
42b0563631STom Van Eyck  * In Mbed Crypto 0.1.0b:
43b0563631STom Van Eyck  * - Using the file backend, all key ids are ok except 0.
44b0563631STom Van Eyck  * - Using the ITS backend, all key ids are ok except 0xFFFFFF52
45b0563631STom Van Eyck  *   (#PSA_CRYPTO_ITS_RANDOM_SEED_UID) for which the file contains the
46b0563631STom Van Eyck  *   device's random seed (if this feature is enabled).
47b0563631STom Van Eyck  * - Only key ids from 1 to #MBEDTLS_PSA_KEY_SLOT_COUNT are actually used.
48b0563631STom Van Eyck  *
49b0563631STom Van Eyck  * Since we need to preserve the random seed, avoid using that key slot.
50b0563631STom Van Eyck  * Reserve a whole range of key slots just in case something else comes up.
51b0563631STom Van Eyck  *
52b0563631STom Van Eyck  * This limitation will probably become moot when we implement client
53b0563631STom Van Eyck  * separation for key storage.
54b0563631STom Van Eyck  */
55b0563631STom Van Eyck #define PSA_MAX_PERSISTENT_KEY_IDENTIFIER PSA_KEY_ID_VENDOR_MAX
56b0563631STom Van Eyck 
57b0563631STom Van Eyck /**
58b0563631STom Van Eyck  * \brief Checks if persistent data is stored for the given key slot number
59b0563631STom Van Eyck  *
60b0563631STom Van Eyck  * This function checks if any key data or metadata exists for the key slot in
61b0563631STom Van Eyck  * the persistent storage.
62b0563631STom Van Eyck  *
63b0563631STom Van Eyck  * \param key           Persistent identifier to check.
64b0563631STom Van Eyck  *
65b0563631STom Van Eyck  * \retval 0
66b0563631STom Van Eyck  *         No persistent data present for slot number
67b0563631STom Van Eyck  * \retval 1
68b0563631STom Van Eyck  *         Persistent data present for slot number
69b0563631STom Van Eyck  */
70b0563631STom Van Eyck int psa_is_key_present_in_storage(const mbedtls_svc_key_id_t key);
71b0563631STom Van Eyck 
72b0563631STom Van Eyck /**
73b0563631STom Van Eyck  * \brief Format key data and metadata and save to a location for given key
74b0563631STom Van Eyck  *        slot.
75b0563631STom Van Eyck  *
76b0563631STom Van Eyck  * This function formats the key data and metadata and saves it to a
77b0563631STom Van Eyck  * persistent storage backend. The storage location corresponding to the
78b0563631STom Van Eyck  * key slot must be empty, otherwise this function will fail. This function
79b0563631STom Van Eyck  * should be called after loading the key into an internal slot to ensure the
80b0563631STom Van Eyck  * persistent key is not saved into a storage location corresponding to an
81b0563631STom Van Eyck  * already occupied non-persistent key, as well as ensuring the key data is
82b0563631STom Van Eyck  * validated.
83b0563631STom Van Eyck  *
84b0563631STom Van Eyck  * Note: This function will only succeed for key buffers which are not
85b0563631STom Van Eyck  * empty. If passed a NULL pointer or zero-length, the function will fail
86b0563631STom Van Eyck  * with #PSA_ERROR_INVALID_ARGUMENT.
87b0563631STom Van Eyck  *
88b0563631STom Van Eyck  * \param[in] attr          The attributes of the key to save.
89b0563631STom Van Eyck  *                          The key identifier field in the attributes
90b0563631STom Van Eyck  *                          determines the key's location.
91b0563631STom Van Eyck  * \param[in] data          Buffer containing the key data.
92b0563631STom Van Eyck  * \param data_length       The number of bytes that make up the key data.
93b0563631STom Van Eyck  *
94b0563631STom Van Eyck  * \retval #PSA_SUCCESS \emptydescription
95b0563631STom Van Eyck  * \retval #PSA_ERROR_INVALID_ARGUMENT \emptydescription
96b0563631STom Van Eyck  * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
97b0563631STom Van Eyck  * \retval #PSA_ERROR_INSUFFICIENT_STORAGE \emptydescription
98b0563631STom Van Eyck  * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
99b0563631STom Van Eyck  * \retval #PSA_ERROR_ALREADY_EXISTS \emptydescription
100b0563631STom Van Eyck  * \retval #PSA_ERROR_DATA_INVALID \emptydescription
101b0563631STom Van Eyck  * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
102b0563631STom Van Eyck  */
103b0563631STom Van Eyck psa_status_t psa_save_persistent_key(const psa_key_attributes_t *attr,
104b0563631STom Van Eyck                                      const uint8_t *data,
105b0563631STom Van Eyck                                      const size_t data_length);
106b0563631STom Van Eyck 
107b0563631STom Van Eyck /**
108b0563631STom Van Eyck  * \brief Parses key data and metadata and load persistent key for given
109b0563631STom Van Eyck  * key slot number.
110b0563631STom Van Eyck  *
111b0563631STom Van Eyck  * This function reads from a storage backend, parses the key data and
112b0563631STom Van Eyck  * metadata and writes them to the appropriate output parameters.
113b0563631STom Van Eyck  *
114b0563631STom Van Eyck  * Note: This function allocates a buffer and returns a pointer to it through
115b0563631STom Van Eyck  * the data parameter. On successful return, the pointer is guaranteed to be
116b0563631STom Van Eyck  * valid and the buffer contains at least one byte of data.
117b0563631STom Van Eyck  * psa_free_persistent_key_data() must be called on the data buffer
118b0563631STom Van Eyck  * afterwards to zeroize and free this buffer.
119b0563631STom Van Eyck  *
120b0563631STom Van Eyck  * \param[in,out] attr      On input, the key identifier field identifies
121b0563631STom Van Eyck  *                          the key to load. Other fields are ignored.
122b0563631STom Van Eyck  *                          On success, the attribute structure contains
123b0563631STom Van Eyck  *                          the key metadata that was loaded from storage.
124b0563631STom Van Eyck  * \param[out] data         Pointer to an allocated key data buffer on return.
125b0563631STom Van Eyck  * \param[out] data_length  The number of bytes that make up the key data.
126b0563631STom Van Eyck  *
127b0563631STom Van Eyck  * \retval #PSA_SUCCESS \emptydescription
128b0563631STom Van Eyck  * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
129b0563631STom Van Eyck  * \retval #PSA_ERROR_DATA_INVALID \emptydescription
130b0563631STom Van Eyck  * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
131b0563631STom Van Eyck  * \retval #PSA_ERROR_DOES_NOT_EXIST \emptydescription
132b0563631STom Van Eyck  */
133b0563631STom Van Eyck psa_status_t psa_load_persistent_key(psa_key_attributes_t *attr,
134b0563631STom Van Eyck                                      uint8_t **data,
135b0563631STom Van Eyck                                      size_t *data_length);
136b0563631STom Van Eyck 
137b0563631STom Van Eyck /**
138b0563631STom Van Eyck  * \brief Remove persistent data for the given key slot number.
139b0563631STom Van Eyck  *
140b0563631STom Van Eyck  * \param key           Persistent identifier of the key to remove
141b0563631STom Van Eyck  *                      from persistent storage.
142b0563631STom Van Eyck  *
143b0563631STom Van Eyck  * \retval #PSA_SUCCESS
144b0563631STom Van Eyck  *         The key was successfully removed,
145b0563631STom Van Eyck  *         or the key did not exist.
146b0563631STom Van Eyck  * \retval #PSA_ERROR_DATA_INVALID \emptydescription
147b0563631STom Van Eyck  */
148b0563631STom Van Eyck psa_status_t psa_destroy_persistent_key(const mbedtls_svc_key_id_t key);
149b0563631STom Van Eyck 
150b0563631STom Van Eyck /**
151b0563631STom Van Eyck  * \brief Free the temporary buffer allocated by psa_load_persistent_key().
152b0563631STom Van Eyck  *
153b0563631STom Van Eyck  * This function must be called at some point after psa_load_persistent_key()
154b0563631STom Van Eyck  * to zeroize and free the memory allocated to the buffer in that function.
155b0563631STom Van Eyck  *
156b0563631STom Van Eyck  * \param key_data        Buffer for the key data.
157b0563631STom Van Eyck  * \param key_data_length Size of the key data buffer.
158b0563631STom Van Eyck  *
159b0563631STom Van Eyck  */
160b0563631STom Van Eyck void psa_free_persistent_key_data(uint8_t *key_data, size_t key_data_length);
161b0563631STom Van Eyck 
162b0563631STom Van Eyck /**
163b0563631STom Van Eyck  * \brief Formats key data and metadata for persistent storage
164b0563631STom Van Eyck  *
165b0563631STom Van Eyck  * \param[in] data          Buffer containing the key data.
166b0563631STom Van Eyck  * \param data_length       Length of the key data buffer.
167b0563631STom Van Eyck  * \param[in] attr          The core attributes of the key.
168b0563631STom Van Eyck  * \param[out] storage_data Output buffer for the formatted data.
169b0563631STom Van Eyck  *
170b0563631STom Van Eyck  */
171b0563631STom Van Eyck void psa_format_key_data_for_storage(const uint8_t *data,
172b0563631STom Van Eyck                                      const size_t data_length,
173b0563631STom Van Eyck                                      const psa_key_attributes_t *attr,
174b0563631STom Van Eyck                                      uint8_t *storage_data);
175b0563631STom Van Eyck 
176b0563631STom Van Eyck /**
177b0563631STom Van Eyck  * \brief Parses persistent storage data into key data and metadata
178b0563631STom Van Eyck  *
179b0563631STom Van Eyck  * \param[in] storage_data     Buffer for the storage data.
180b0563631STom Van Eyck  * \param storage_data_length  Length of the storage data buffer
181b0563631STom Van Eyck  * \param[out] key_data        On output, pointer to a newly allocated buffer
182b0563631STom Van Eyck  *                             containing the key data. This must be freed
183b0563631STom Van Eyck  *                             using psa_free_persistent_key_data()
184b0563631STom Van Eyck  * \param[out] key_data_length Length of the key data buffer
185b0563631STom Van Eyck  * \param[out] attr            On success, the attribute structure is filled
186b0563631STom Van Eyck  *                             with the loaded key metadata.
187b0563631STom Van Eyck  *
188b0563631STom Van Eyck  * \retval #PSA_SUCCESS \emptydescription
189b0563631STom Van Eyck  * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
190b0563631STom Van Eyck  * \retval #PSA_ERROR_DATA_INVALID \emptydescription
191b0563631STom Van Eyck  */
192b0563631STom Van Eyck psa_status_t psa_parse_key_data_from_storage(const uint8_t *storage_data,
193b0563631STom Van Eyck                                              size_t storage_data_length,
194b0563631STom Van Eyck                                              uint8_t **key_data,
195b0563631STom Van Eyck                                              size_t *key_data_length,
196b0563631STom Van Eyck                                              psa_key_attributes_t *attr);
197b0563631STom Van Eyck 
198b0563631STom Van Eyck #if defined(MBEDTLS_PSA_CRYPTO_SE_C)
199b0563631STom Van Eyck /** This symbol is defined if transaction support is required. */
200b0563631STom Van Eyck #define PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS 1
201b0563631STom Van Eyck #endif
202b0563631STom Van Eyck 
203b0563631STom Van Eyck #if defined(PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS)
204b0563631STom Van Eyck 
205b0563631STom Van Eyck /** The type of transaction that is in progress.
206b0563631STom Van Eyck  */
207b0563631STom Van Eyck /* This is an integer type rather than an enum for two reasons: to support
208b0563631STom Van Eyck  * unknown values when loading a transaction file, and to ensure that the
209b0563631STom Van Eyck  * type has a known size.
210b0563631STom Van Eyck  */
211b0563631STom Van Eyck typedef uint16_t psa_crypto_transaction_type_t;
212b0563631STom Van Eyck 
213b0563631STom Van Eyck /** No transaction is in progress.
214b0563631STom Van Eyck  *
215b0563631STom Van Eyck  * This has the value 0, so zero-initialization sets a transaction's type to
216b0563631STom Van Eyck  * this value.
217b0563631STom Van Eyck  */
218b0563631STom Van Eyck #define PSA_CRYPTO_TRANSACTION_NONE             ((psa_crypto_transaction_type_t) 0x0000)
219b0563631STom Van Eyck 
220b0563631STom Van Eyck /** A key creation transaction.
221b0563631STom Van Eyck  *
222b0563631STom Van Eyck  * This is only used for keys in an external cryptoprocessor (secure element).
223b0563631STom Van Eyck  * Keys in RAM or in internal storage are created atomically in storage
224b0563631STom Van Eyck  * (simple file creation), so they do not need a transaction mechanism.
225b0563631STom Van Eyck  */
226b0563631STom Van Eyck #define PSA_CRYPTO_TRANSACTION_CREATE_KEY       ((psa_crypto_transaction_type_t) 0x0001)
227b0563631STom Van Eyck 
228b0563631STom Van Eyck /** A key destruction transaction.
229b0563631STom Van Eyck  *
230b0563631STom Van Eyck  * This is only used for keys in an external cryptoprocessor (secure element).
231b0563631STom Van Eyck  * Keys in RAM or in internal storage are destroyed atomically in storage
232b0563631STom Van Eyck  * (simple file deletion), so they do not need a transaction mechanism.
233b0563631STom Van Eyck  */
234b0563631STom Van Eyck #define PSA_CRYPTO_TRANSACTION_DESTROY_KEY      ((psa_crypto_transaction_type_t) 0x0002)
235b0563631STom Van Eyck 
236b0563631STom Van Eyck /** Transaction data.
237b0563631STom Van Eyck  *
238b0563631STom Van Eyck  * This type is designed to be serialized by writing the memory representation
239b0563631STom Van Eyck  * and reading it back on the same device.
240b0563631STom Van Eyck  *
241b0563631STom Van Eyck  * \note The transaction mechanism is not thread-safe. There can only be one
242b0563631STom Van Eyck  *       single active transaction at a time.
243b0563631STom Van Eyck  *       The transaction object is #psa_crypto_transaction.
244b0563631STom Van Eyck  *
245b0563631STom Van Eyck  * \note If an API call starts a transaction, it must complete this transaction
246b0563631STom Van Eyck  *       before returning to the application.
247b0563631STom Van Eyck  *
248b0563631STom Van Eyck  * The lifetime of a transaction is the following (note that only one
249b0563631STom Van Eyck  * transaction may be active at a time):
250b0563631STom Van Eyck  *
251b0563631STom Van Eyck  * -# Call psa_crypto_prepare_transaction() to initialize the transaction
252b0563631STom Van Eyck  *    object in memory and declare the type of transaction that is starting.
253b0563631STom Van Eyck  * -# Fill in the type-specific fields of #psa_crypto_transaction.
254b0563631STom Van Eyck  * -# Call psa_crypto_save_transaction() to start the transaction. This
255b0563631STom Van Eyck  *    saves the transaction data to internal storage.
256b0563631STom Van Eyck  * -# Perform the work of the transaction by modifying files, contacting
257b0563631STom Van Eyck  *    external entities, or whatever needs doing. Note that the transaction
258b0563631STom Van Eyck  *    may be interrupted by a power failure, so you need to have a way
259b0563631STom Van Eyck  *    recover from interruptions either by undoing what has been done
260b0563631STom Van Eyck  *    so far or by resuming where you left off.
261b0563631STom Van Eyck  * -# If there are intermediate stages in the transaction, update
262b0563631STom Van Eyck  *    the fields of #psa_crypto_transaction and call
263b0563631STom Van Eyck  *    psa_crypto_save_transaction() again when each stage is reached.
264b0563631STom Van Eyck  * -# When the transaction is over, call psa_crypto_stop_transaction() to
265b0563631STom Van Eyck  *    remove the transaction data in storage and in memory.
266b0563631STom Van Eyck  *
267b0563631STom Van Eyck  * If the system crashes while a transaction is in progress, psa_crypto_init()
268b0563631STom Van Eyck  * calls psa_crypto_load_transaction() and takes care of completing or
269b0563631STom Van Eyck  * rewinding the transaction. This is done in psa_crypto_recover_transaction()
270b0563631STom Van Eyck  * in psa_crypto.c. If you add a new type of transaction, be
271b0563631STom Van Eyck  * sure to add code for it in psa_crypto_recover_transaction().
272b0563631STom Van Eyck  */
273b0563631STom Van Eyck typedef union {
274b0563631STom Van Eyck     /* Each element of this union must have the following properties
275b0563631STom Van Eyck      * to facilitate serialization and deserialization:
276b0563631STom Van Eyck      *
277b0563631STom Van Eyck      * - The element is a struct.
278b0563631STom Van Eyck      * - The first field of the struct is `psa_crypto_transaction_type_t type`.
279b0563631STom Van Eyck      * - Elements of the struct are arranged such a way that there is
280b0563631STom Van Eyck      *   no padding.
281b0563631STom Van Eyck      */
282b0563631STom Van Eyck     struct psa_crypto_transaction_unknown_s {
283b0563631STom Van Eyck         psa_crypto_transaction_type_t type;
284b0563631STom Van Eyck         uint16_t unused1;
285b0563631STom Van Eyck         uint32_t unused2;
286b0563631STom Van Eyck         uint64_t unused3;
287b0563631STom Van Eyck         uint64_t unused4;
288b0563631STom Van Eyck     } unknown;
289b0563631STom Van Eyck     /* ::type is #PSA_CRYPTO_TRANSACTION_CREATE_KEY or
290b0563631STom Van Eyck      * #PSA_CRYPTO_TRANSACTION_DESTROY_KEY. */
291b0563631STom Van Eyck     struct psa_crypto_transaction_key_s {
292b0563631STom Van Eyck         psa_crypto_transaction_type_t type;
293b0563631STom Van Eyck         uint16_t unused1;
294b0563631STom Van Eyck         psa_key_lifetime_t lifetime;
295b0563631STom Van Eyck         psa_key_slot_number_t slot;
296b0563631STom Van Eyck         mbedtls_svc_key_id_t id;
297b0563631STom Van Eyck     } key;
298b0563631STom Van Eyck } psa_crypto_transaction_t;
299b0563631STom Van Eyck 
300b0563631STom Van Eyck /** The single active transaction.
301b0563631STom Van Eyck  */
302b0563631STom Van Eyck extern psa_crypto_transaction_t psa_crypto_transaction;
303b0563631STom Van Eyck 
304b0563631STom Van Eyck /** Prepare for a transaction.
305b0563631STom Van Eyck  *
306b0563631STom Van Eyck  * There must not be an ongoing transaction.
307b0563631STom Van Eyck  *
308b0563631STom Van Eyck  * \param type          The type of transaction to start.
309b0563631STom Van Eyck  */
psa_crypto_prepare_transaction(psa_crypto_transaction_type_t type)310b0563631STom Van Eyck static inline void psa_crypto_prepare_transaction(
311b0563631STom Van Eyck     psa_crypto_transaction_type_t type)
312b0563631STom Van Eyck {
313b0563631STom Van Eyck     psa_crypto_transaction.unknown.type = type;
314b0563631STom Van Eyck }
315b0563631STom Van Eyck 
316b0563631STom Van Eyck /** Save the transaction data to storage.
317b0563631STom Van Eyck  *
318b0563631STom Van Eyck  * You may call this function multiple times during a transaction to
319b0563631STom Van Eyck  * atomically update the transaction state.
320b0563631STom Van Eyck  *
321b0563631STom Van Eyck  * \retval #PSA_SUCCESS \emptydescription
322b0563631STom Van Eyck  * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
323b0563631STom Van Eyck  * \retval #PSA_ERROR_INSUFFICIENT_STORAGE \emptydescription
324b0563631STom Van Eyck  * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
325b0563631STom Van Eyck  */
326b0563631STom Van Eyck psa_status_t psa_crypto_save_transaction(void);
327b0563631STom Van Eyck 
328b0563631STom Van Eyck /** Load the transaction data from storage, if any.
329b0563631STom Van Eyck  *
330b0563631STom Van Eyck  * This function is meant to be called from psa_crypto_init() to recover
331b0563631STom Van Eyck  * in case a transaction was interrupted by a system crash.
332b0563631STom Van Eyck  *
333b0563631STom Van Eyck  * \retval #PSA_SUCCESS
334b0563631STom Van Eyck  *         The data about the ongoing transaction has been loaded to
335b0563631STom Van Eyck  *         #psa_crypto_transaction.
336b0563631STom Van Eyck  * \retval #PSA_ERROR_DOES_NOT_EXIST
337b0563631STom Van Eyck  *         There is no ongoing transaction.
338b0563631STom Van Eyck  * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
339b0563631STom Van Eyck  * \retval #PSA_ERROR_DATA_INVALID \emptydescription
340b0563631STom Van Eyck  * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
341b0563631STom Van Eyck  */
342b0563631STom Van Eyck psa_status_t psa_crypto_load_transaction(void);
343b0563631STom Van Eyck 
344b0563631STom Van Eyck /** Indicate that the current transaction is finished.
345b0563631STom Van Eyck  *
346b0563631STom Van Eyck  * Call this function at the very end of transaction processing.
347b0563631STom Van Eyck  * This function does not "commit" or "abort" the transaction: the storage
348b0563631STom Van Eyck  * subsystem has no concept of "commit" and "abort", just saving and
349b0563631STom Van Eyck  * removing the transaction information in storage.
350b0563631STom Van Eyck  *
351b0563631STom Van Eyck  * This function erases the transaction data in storage (if any) and
352b0563631STom Van Eyck  * resets the transaction data in memory.
353b0563631STom Van Eyck  *
354b0563631STom Van Eyck  * \retval #PSA_SUCCESS
355b0563631STom Van Eyck  *         There was transaction data in storage.
356b0563631STom Van Eyck  * \retval #PSA_ERROR_DOES_NOT_EXIST
357b0563631STom Van Eyck  *         There was no transaction data in storage.
358b0563631STom Van Eyck  * \retval #PSA_ERROR_STORAGE_FAILURE
359b0563631STom Van Eyck  *         It was impossible to determine whether there was transaction data
360b0563631STom Van Eyck  *         in storage, or the transaction data could not be erased.
361b0563631STom Van Eyck  */
362b0563631STom Van Eyck psa_status_t psa_crypto_stop_transaction(void);
363b0563631STom Van Eyck 
364b0563631STom Van Eyck /** The ITS file identifier for the transaction data.
365b0563631STom Van Eyck  *
366b0563631STom Van Eyck  * 0xffffffNN = special file; 0x74 = 't' for transaction.
367b0563631STom Van Eyck  */
368b0563631STom Van Eyck #define PSA_CRYPTO_ITS_TRANSACTION_UID ((psa_key_id_t) 0xffffff74)
369b0563631STom Van Eyck 
370b0563631STom Van Eyck #endif /* PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS */
371b0563631STom Van Eyck 
372b0563631STom Van Eyck #if defined(MBEDTLS_PSA_INJECT_ENTROPY)
373b0563631STom Van Eyck /** Backend side of mbedtls_psa_inject_entropy().
374b0563631STom Van Eyck  *
375b0563631STom Van Eyck  * This function stores the supplied data into the entropy seed file.
376b0563631STom Van Eyck  *
377b0563631STom Van Eyck  * \retval #PSA_SUCCESS
378b0563631STom Van Eyck  *         Success
379b0563631STom Van Eyck  * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
380b0563631STom Van Eyck  * \retval #PSA_ERROR_INSUFFICIENT_STORAGE \emptydescription
381b0563631STom Van Eyck  * \retval #PSA_ERROR_NOT_PERMITTED
382b0563631STom Van Eyck  *         The entropy seed file already exists.
383b0563631STom Van Eyck  */
384b0563631STom Van Eyck psa_status_t mbedtls_psa_storage_inject_entropy(const unsigned char *seed,
385b0563631STom Van Eyck                                                 size_t seed_size);
386b0563631STom Van Eyck #endif /* MBEDTLS_PSA_INJECT_ENTROPY */
387b0563631STom Van Eyck 
388b0563631STom Van Eyck #ifdef __cplusplus
389b0563631STom Van Eyck }
390b0563631STom Van Eyck #endif
391b0563631STom Van Eyck 
392b0563631STom Van Eyck #endif /* PSA_CRYPTO_STORAGE_H */
393