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