1 /*
2  * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
3  * Copyright (c) 2024 Cypress Semiconductor Corporation (an Infineon company)
4  * or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  */
9 
10 #ifndef __PS_OBJECT_DEFS_H__
11 #define __PS_OBJECT_DEFS_H__
12 
13 #include <stdint.h>
14 
15 #include "config_tfm.h"
16 #include "psa/protected_storage.h"
17 
18 #ifdef PS_ENCRYPTION
19 #include "crypto/ps_crypto_interface.h"
20 #endif
21 
22 /*!
23  * \struct ps_object_info_t
24  *
25  * \brief Object information.
26  */
27 struct ps_object_info_t {
28     uint32_t current_size; /*!< Current size of the object content in bytes */
29     uint32_t max_size;     /*!< Maximum size of the object content in bytes */
30     psa_storage_create_flags_t create_flags; /*!< Object creation flags */
31 };
32 
33 /*!
34  * \struct ps_obj_header_t
35  *
36  * \brief Metadata attached as a header to object data before storage.
37  */
38 struct ps_obj_header_t {
39 #ifdef PS_ENCRYPTION
40     union ps_crypto_t crypto;     /*!< Crypto metadata */
41 #else
42     uint32_t version;              /*!< Object version */
43     uint32_t fid;                  /*!< File ID */
44 #endif
45     struct ps_object_info_t info; /*!< Object information */
46 };
47 
48 
49 #define PS_MAX_OBJECT_DATA_SIZE  PS_MAX_ASSET_SIZE
50 
51 #ifdef PS_ENCRYPTION
52 #define PS_OBJECT_BUF_SIZE (PS_MAX_OBJECT_DATA_SIZE + PS_TAG_LEN_BYTES)
53 #else
54 #define PS_OBJECT_BUF_SIZE PS_MAX_OBJECT_DATA_SIZE
55 #endif
56 
57 
58 /*!
59  * \struct ps_object_t
60  *
61  * \brief The object to be written to the file system below. Made up of the
62  *        object header and the object data.
63  */
64 struct ps_object_t {
65     struct ps_obj_header_t header;    /*!< Object header */
66     uint8_t data[PS_OBJECT_BUF_SIZE]; /*!< Object data (and tag if encrypted) */
67 };
68 
69 
70 #define PS_OBJECT_HEADER_SIZE    sizeof(struct ps_obj_header_t)
71 #define PS_MAX_OBJECT_SIZE       sizeof(struct ps_object_t)
72 
73 /*!
74  * \def PS_MAX_NUM_OBJECTS
75  *
76  * \brief Specifies the maximum number of objects in the system, which is the
77  *        number of defined assets, the object table and 2 temporary objects to
78  *        store the temporary object table and temporary updated object.
79  */
80 #define PS_MAX_NUM_OBJECTS (PS_NUM_ASSETS + 3)
81 
82 #endif /* __PS_OBJECT_DEFS_H__ */
83