1 /* Copyright (c) 2024 Nordic Semiconductor
2  * SPDX-License-Identifier: Apache-2.0
3  */
4 #ifndef SECURE_STORAGE_ITS_COMMON_H
5 #define SECURE_STORAGE_ITS_COMMON_H
6 
7 /** @file zephyr/secure_storage/its/common.h
8  * @brief Common definitions of the secure storage subsystem's ITS APIs.
9  */
10 #include "../common.h"
11 #include <zephyr/toolchain.h>
12 #include <psa/storage_common.h>
13 
14 /** @brief The ID of the caller from which the ITS API call originates.
15  * This is used to prevent ID collisions between different callers that are not aware
16  * of each other and so might use the same numerical IDs, e.g. PSA Crypto and PSA ITS.
17  */
18 typedef enum {
19 	SECURE_STORAGE_ITS_CALLER_PSA_ITS,
20 	SECURE_STORAGE_ITS_CALLER_PSA_PS,
21 	SECURE_STORAGE_ITS_CALLER_MBEDTLS,
22 	SECURE_STORAGE_ITS_CALLER_COUNT
23 } secure_storage_its_caller_id_t;
24 
25 /** The UID (caller + entry IDs) of an ITS entry. */
26 typedef struct {
27 	psa_storage_uid_t uid;
28 	secure_storage_its_caller_id_t caller_id;
29 } __packed secure_storage_its_uid_t;
30 
31 #ifdef CONFIG_SECURE_STORAGE_ITS_TRANSFORM_MODULE
32 
33 /** The maximum size, in bytes, of an entry's data after it has been transformed for storage. */
34 enum { SECURE_STORAGE_ITS_TRANSFORM_MAX_STORED_DATA_SIZE
35 	= CONFIG_SECURE_STORAGE_ITS_MAX_DATA_SIZE
36 	  + sizeof(secure_storage_packed_create_flags_t)
37 	  + CONFIG_SECURE_STORAGE_ITS_TRANSFORM_OUTPUT_OVERHEAD };
38 
39 /** The size, in bytes, of an entry's data given its size once transformed for storage. */
40 #define SECURE_STORAGE_ITS_TRANSFORM_DATA_SIZE(transformed_data_size) \
41 	(transformed_data_size - (SECURE_STORAGE_ITS_TRANSFORM_MAX_STORED_DATA_SIZE \
42 				  - CONFIG_SECURE_STORAGE_ITS_MAX_DATA_SIZE))
43 
44 #endif /* CONFIG_SECURE_STORAGE_ITS_TRANSFORM_MODULE */
45 
46 #endif
47