XenevaOS
Loading...
Searching...
No Matches
psa_crypto_storage.h
Go to the documentation of this file.
1
6/*
7 * Copyright The Mbed TLS Contributors
8 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9 */
10
11#ifndef PSA_CRYPTO_STORAGE_H
12#define PSA_CRYPTO_STORAGE_H
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#include "psa/crypto.h"
20
21#include <stdint.h>
22#include <string.h>
23
24/* Limit the maximum key size in storage. */
25#if defined(MBEDTLS_PSA_STATIC_KEY_SLOTS)
26/* Reflect the maximum size for the key buffer. */
27#define PSA_CRYPTO_MAX_STORAGE_SIZE (MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE)
28#else
29/* Just set an upper boundary but it should have no effect since the key size
30 * is limited in memory. */
31#define PSA_CRYPTO_MAX_STORAGE_SIZE (PSA_BITS_TO_BYTES(PSA_MAX_KEY_BITS))
32#endif
33
34/* Sanity check: a file size must fit in 32 bits. Allow a generous
35 * 64kB of metadata. */
36#if PSA_CRYPTO_MAX_STORAGE_SIZE > 0xffff0000
37#error "PSA_CRYPTO_MAX_STORAGE_SIZE > 0xffff0000"
38#endif
39
55#define PSA_MAX_PERSISTENT_KEY_IDENTIFIER PSA_KEY_ID_VENDOR_MAX
56
71
104 const uint8_t *data,
105 const size_t data_length);
106
134 uint8_t **data,
135 size_t *data_length);
136
149
160void psa_free_persistent_key_data(uint8_t *key_data, size_t key_data_length);
161
172 const size_t data_length,
173 const psa_key_attributes_t *attr,
174 uint8_t *storage_data);
175
193 size_t storage_data_length,
194 uint8_t **key_data,
195 size_t *key_data_length,
197
198#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
200#define PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS 1
201#endif
202
203#if defined(PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS)
204
207/* This is an integer type rather than an enum for two reasons: to support
208 * unknown values when loading a transaction file, and to ensure that the
209 * type has a known size.
210 */
211typedef uint16_t psa_crypto_transaction_type_t;
212
218#define PSA_CRYPTO_TRANSACTION_NONE ((psa_crypto_transaction_type_t) 0x0000)
219
226#define PSA_CRYPTO_TRANSACTION_CREATE_KEY ((psa_crypto_transaction_type_t) 0x0001)
227
234#define PSA_CRYPTO_TRANSACTION_DESTROY_KEY ((psa_crypto_transaction_type_t) 0x0002)
235
273typedef union {
274 /* Each element of this union must have the following properties
275 * to facilitate serialization and deserialization:
276 *
277 * - The element is a struct.
278 * - The first field of the struct is `psa_crypto_transaction_type_t type`.
279 * - Elements of the struct are arranged such a way that there is
280 * no padding.
281 */
282 struct psa_crypto_transaction_unknown_s {
283 psa_crypto_transaction_type_t type;
284 uint16_t unused1;
285 uint32_t unused2;
286 uint64_t unused3;
287 uint64_t unused4;
288 } unknown;
289 /* ::type is #PSA_CRYPTO_TRANSACTION_CREATE_KEY or
290 * #PSA_CRYPTO_TRANSACTION_DESTROY_KEY. */
291 struct psa_crypto_transaction_key_s {
292 psa_crypto_transaction_type_t type;
293 uint16_t unused1;
294 psa_key_lifetime_t lifetime;
297 } key;
298} psa_crypto_transaction_t;
299
302extern psa_crypto_transaction_t psa_crypto_transaction;
303
310static inline void psa_crypto_prepare_transaction(
311 psa_crypto_transaction_type_t type)
312{
313 psa_crypto_transaction.unknown.type = type;
314}
315
326psa_status_t psa_crypto_save_transaction(void);
327
342psa_status_t psa_crypto_load_transaction(void);
343
362psa_status_t psa_crypto_stop_transaction(void);
363
368#define PSA_CRYPTO_ITS_TRANSACTION_UID ((psa_key_id_t) 0xffffff74)
369
370#endif /* PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS */
371
372#if defined(MBEDTLS_PSA_INJECT_ENTROPY)
384psa_status_t mbedtls_psa_storage_inject_entropy(const unsigned char *seed,
385 size_t seed_size);
386#endif /* MBEDTLS_PSA_INJECT_ENTROPY */
387
388#ifdef __cplusplus
389}
390#endif
391
392#endif /* PSA_CRYPTO_STORAGE_H */
Platform Security Architecture cryptography module.
unsigned int uint32_t
Definition acefiex.h:163
unsigned char uint8_t
Definition acefiex.h:161
COMPILER_DEPENDENT_UINT64 uint64_t
Definition acefiex.h:165
unsigned short int uint16_t
Definition acefiex.h:162
PSA external cryptoprocessor driver module.
int32_t psa_status_t
Function return status.
Definition crypto_types.h:59
uint32_t psa_key_lifetime_t
Definition crypto_types.h:183
psa_key_id_t mbedtls_svc_key_id_t
Definition crypto_types.h:292
uint64_t psa_key_slot_number_t
Definition crypto_se_driver.h:137
void * data
Definition kthread.h:30
psa_status_t psa_destroy_persistent_key(const mbedtls_svc_key_id_t key)
Remove persistent data for the given key slot number.
psa_status_t psa_load_persistent_key(psa_key_attributes_t *attr, uint8_t **data, size_t *data_length)
Parses key data and metadata and load persistent key for given key slot number.
psa_status_t psa_save_persistent_key(const psa_key_attributes_t *attr, const uint8_t *data, const size_t data_length)
Format key data and metadata and save to a location for given key slot.
void psa_format_key_data_for_storage(const uint8_t *data, const size_t data_length, const psa_key_attributes_t *attr, uint8_t *storage_data)
Formats key data and metadata for persistent storage.
int psa_is_key_present_in_storage(const mbedtls_svc_key_id_t key)
Checks if persistent data is stored for the given key slot number.
psa_status_t psa_parse_key_data_from_storage(const uint8_t *storage_data, size_t storage_data_length, uint8_t **key_data, size_t *key_data_length, psa_key_attributes_t *attr)
Parses persistent storage data into key data and metadata.
void psa_free_persistent_key_data(uint8_t *key_data, size_t key_data_length)
Free the temporary buffer allocated by psa_load_persistent_key().
Definition crypto_struct.h:295