Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 1 | ########################################### |
| 2 | Protected Storage Service Integration Guide |
| 3 | ########################################### |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 4 | |
| 5 | ************ |
| 6 | Introduction |
| 7 | ************ |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 8 | TF-M Protected Storage (PS) service implements PSA Protected Storage APIs. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 9 | |
| 10 | The service is backed by hardware isolation of the flash access domain and, in |
| 11 | the current version, relies on hardware to isolate the flash area from |
| 12 | non-secure access. In absence of hardware level isolation, the secrecy and |
| 13 | integrity of data is still maintained. |
| 14 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 15 | The PS service implements an AES-GCM based AEAD encryption policy, as a |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 16 | reference, to protect data integrity and authenticity. |
| 17 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 18 | PS reuses the non-hierarchical filesystem provided by the TF-M Internal Trusted |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 19 | Storage service to store encrypted, authenticated objects on the external flash |
| 20 | device. |
| 21 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 22 | The design addresses the following high level requirements as well: |
| 23 | |
| 24 | - **Confidentiality** - Resistance to unauthorised accesses through |
| 25 | hardware/software attacks. |
Antonio de Angelis | ee774c2 | 2019-05-03 13:44:01 +0100 | [diff] [blame] | 26 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 27 | - **Access Authentication** - Mechanism to establish requester's identity (a |
| 28 | non-secure entity, secure entity, or a remote server). |
Antonio de Angelis | ee774c2 | 2019-05-03 13:44:01 +0100 | [diff] [blame] | 29 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 30 | - **Integrity** - Resistant to tampering by either the normal users of a product, |
| 31 | package, or system or others with physical access to it. If the content of the |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 32 | protected storage is changed maliciously, the service is able to detect it. |
Antonio de Angelis | ee774c2 | 2019-05-03 13:44:01 +0100 | [diff] [blame] | 33 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 34 | - **Reliability** - Resistant to power failure scenarios and incomplete write |
| 35 | cycles. |
Antonio de Angelis | ee774c2 | 2019-05-03 13:44:01 +0100 | [diff] [blame] | 36 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 37 | - **Configurability** - High level configurability to scale up/down memory |
| 38 | footprint to cater for a variety of devices with varying security |
| 39 | requirements. |
Antonio de Angelis | ee774c2 | 2019-05-03 13:44:01 +0100 | [diff] [blame] | 40 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 41 | - **Performance** - Optimized to be used for resource constrained devices with |
| 42 | very small silicon footprint, the PPA (power, performance, area) should be |
| 43 | optimal. |
| 44 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 45 | ****************************** |
| 46 | Current PS Service Limitations |
| 47 | ****************************** |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 48 | - **Fragmentation** - The current design does not support fragmentation, as an |
| 49 | asset is stored in a contiguous space in a block. This means that the maximum |
| 50 | asset size can only be up-to a block size. Detailed information about the |
| 51 | maximum asset size can be found in the section `Maximum asset size` below. |
| 52 | Each block can potentially store multiple assets. |
| 53 | A delete operation implicitly moves all the assets towards the top of the block |
| 54 | to avoid fragmentation within block. However, this may also result in |
| 55 | unutilized space at the end of each block. |
Antonio de Angelis | ee774c2 | 2019-05-03 13:44:01 +0100 | [diff] [blame] | 56 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 57 | - **Asset size limitation** - An asset is stored in a contiguous space in a |
| 58 | block/sector. Hence, the maximum asset size can be up-to the size of the |
| 59 | data block/sector. Detailed information about the maximum asset size can be |
| 60 | found in the section `Maximum asset size` below. |
Antonio de Angelis | ee774c2 | 2019-05-03 13:44:01 +0100 | [diff] [blame] | 61 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 62 | - **Non-hierarchical storage model** - The current design uses a |
| 63 | non-hierarchical storage model, as a filesystem, where all the assets are |
| 64 | managed by a linearly indexed list of metadata. This model locates the |
| 65 | metadata in blocks which are always stored in the same flash location. That |
| 66 | increases the number of writes in a specific flash location as every change in |
| 67 | the storage area requires a metadata update. |
Antonio de Angelis | ee774c2 | 2019-05-03 13:44:01 +0100 | [diff] [blame] | 68 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 69 | - **PSA internal trusted storage API** - In the current design, the service does |
| 70 | not use the PSA Internal Trusted Storage API to write the rollback protection |
TudorCretu | c0e4bee | 2019-07-23 11:38:21 +0100 | [diff] [blame] | 71 | values stored in the internal storage. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 72 | |
| 73 | - **Protection against physical storage medium failure** - Complete handling of |
| 74 | inherent failures of storage mediums (e.g. bad blocks in a NAND based device) |
| 75 | is not supported by the current design. |
| 76 | |
| 77 | - **Key diversification** - In a more robust design, each asset would be |
| 78 | encrypted through a different key. |
| 79 | |
| 80 | - **Lifecycle management** - Currently, it does not support any subscription |
| 81 | based keys and certificates required in a secure lifecycle management. Hence, |
| 82 | an asset's validity time-stamp can not be invalidated based on the system |
| 83 | time. |
| 84 | |
| 85 | - **Provisioning vs user/device data** - In the current design, all assets are |
| 86 | treated in the same manner. In an alternative design, it may be required to |
| 87 | create separate partitions for provisioning content and user/device generated |
| 88 | content. This is to allow safe update of provisioning data during firmware |
| 89 | updates without the need to wipe out the user/device generated data. |
| 90 | |
| 91 | ************** |
| 92 | Code Structure |
| 93 | ************** |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 94 | Protected storage service code is located in |
| 95 | ``secure_fw/partitions/protected_storage/`` and is divided as follows: |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 96 | |
| 97 | - Core files |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 98 | - Cryptographic interfaces |
| 99 | - Non-volatile (NV) counters interfaces |
| 100 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 101 | The PSA PS interfaces for PS service are located in ``interface/include/psa`` |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 102 | |
| 103 | PSA Protected Storage Interfaces |
| 104 | ================================ |
| 105 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 106 | The PS service exposes the following mandatory PSA PS interfaces, version 1.0: |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 107 | |
| 108 | .. code-block:: c |
| 109 | |
Minos Galanakis | e06c6f6 | 2020-03-10 15:44:32 +0000 | [diff] [blame] | 110 | psa_status_t psa_ps_set(psa_storage_uid_t uid, size_t data_length, const void *p_data, psa_storage_create_flags_t create_flags); |
| 111 | psa_status_t psa_ps_get(psa_storage_uid_t uid, size_t data_offset, size_t data_size, void *p_data, size_t *p_data_length); |
| 112 | psa_status_t psa_ps_get_info(psa_storage_uid_t uid, struct psa_storage_info_t *p_info); |
| 113 | psa_status_t psa_ps_remove(psa_storage_uid_t uid); |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 114 | uint32_t psa_ps_get_support(void); |
| 115 | |
| 116 | For the moment, it does not support the extended version of those APIs. |
| 117 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 118 | These PSA PS interfaces and PS TF-M types are defined and documented in |
Minos Galanakis | e06c6f6 | 2020-03-10 15:44:32 +0000 | [diff] [blame] | 119 | ``interface/include/psa/protected_storage.h``, |
| 120 | ``interface/include/psa/storage_common.h`` and |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 121 | ``interface/include/tfm_ps_defs.h`` |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 122 | |
| 123 | Core Files |
| 124 | ========== |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 125 | - ``tfm_ps_req_mngr.c`` - Contains the PS request manager implementation which |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 126 | handles all requests which arrive to the service. This layer extracts the |
| 127 | arguments from the input and output vectors, and it calls the protected |
| 128 | storage layer with the provided parameters. |
| 129 | |
| 130 | - ``tfm_protected_storage.c`` - Contains the TF-M protected storage API |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 131 | implementations which are the entry points to the PS service. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 132 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 133 | - ``ps_object_system.c`` - Contains the object system implementation to manage |
| 134 | all objects in PS area. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 135 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 136 | - ``ps_object_table.c`` - Contains the object system table implementation which |
| 137 | complements the object system to manage all object in the PS area. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 138 | The object table has an entry for each object stored in the object system |
| 139 | and keeps track of its version and owner. |
| 140 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 141 | - ``ps_encrypted_object.c`` - Contains an implementation to manipulate |
| 142 | encrypted objects in the PS object system. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 143 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 144 | - ``ps_utils.c`` - Contains common and basic functionalities used across the |
| 145 | PS service code. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 146 | |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 147 | Flash Filesystem and Flash Interfaces |
| 148 | ===================================== |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 149 | The PS service reuses the non-hierarchical filesystem and flash interfaces |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 150 | provided by the TF-M Internal Trusted Storage service. It stores encrypted, |
| 151 | authenticated objects on the external flash device by making service calls to |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 152 | the ITS service. When the ITS service receives requests from the PS partition, |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 153 | it handles the request by using a separate filesystem context initialised to use |
| 154 | the external flash device. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 155 | |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 156 | The ITS filesystem and flash interfaces and their implementation can be found in |
Ken Liu | 738a4b0 | 2020-06-04 14:52:38 +0800 | [diff] [blame] | 157 | ``secure_fw/partitions/internal_trusted_storage/flash_fs`` and |
| 158 | ``secure_fw/partitions/internal_trusted_storage/flash`` respectively. More |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 159 | information about the filesystem and flash interfaces can be found in the |
| 160 | :doc:`ITS integration guide |
Minos Galanakis | e409401 | 2020-06-12 14:25:34 +0100 | [diff] [blame] | 161 | </docs/reference/services/tfm_its_integration_guide>`. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 162 | |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 163 | The structure containing info about the external flash device, used by the ITS |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 164 | service to handle requests from the PS partition, is defined in |
Ken Liu | 738a4b0 | 2020-06-04 14:52:38 +0800 | [diff] [blame] | 165 | ``secure_fw/partitions/internal_trusted_storage/flash/its_flash_info_external.c``, |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 166 | which depends on target-specific definitions from |
| 167 | ``platform/ext/target/<TARGET_NAME>/partition/flash_layout.h``. Please see the |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 168 | `Protected Storage Service Definitions` section for details. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 169 | |
| 170 | Cryptographic Interface |
| 171 | ======================= |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 172 | - ``crypto/ps_crypto_interface.h`` - Abstracts the cryptographic operations for |
| 173 | the protected storage service. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 174 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 175 | - ``crypto/ps_crypto_interface.c`` - Implements the PS service cryptographic |
Antonio de Angelis | ee774c2 | 2019-05-03 13:44:01 +0100 | [diff] [blame] | 176 | operations with calls to the TF-M Crypto service. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 177 | |
| 178 | Non-volatile (NV) Counters Interface |
| 179 | ==================================== |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 180 | The current PS service provides rollback protection based on NV |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 181 | counters. |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 182 | PS defines and implements the following NV counters functionalities: |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 183 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 184 | - ``nv_counters/ps_nv_counters.h`` - Abstracts PS non-volatile |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 185 | counters operations. This API detaches the use of NV counters from the TF-M NV |
| 186 | counters implementation, provided by the platform, and provides a mechanism to |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 187 | compile in a different API implementation for test purposes. A PS test suite |
| 188 | **may** provide its own custom implementation to be able to test different PS |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 189 | service use cases. |
| 190 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 191 | - ``nv_counters/ps_nv_counters.c`` - Implements the PS NV counters interfaces |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 192 | based on TF-M NV counters implementation provided by the platform. |
| 193 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 194 | **************************** |
| 195 | PS Service Integration Guide |
| 196 | **************************** |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 197 | This section describes mandatory (i.e. **must** implement) or optional |
| 198 | (i.e. **may** implement) interfaces which the system integrator have to take |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 199 | in to account in order to integrate the protected storage service in a new |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 200 | platform. |
| 201 | |
| 202 | Maximum Asset Size |
| 203 | ================== |
| 204 | An asset is stored in a contiguous space in a block/sector. The maximum |
| 205 | size of an asset can be up-to the size of the data block/sector minus the object |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 206 | header size (``PS_OBJECT_HEADER_SIZE``) which is defined in |
| 207 | ``ps_object_defs.h``. The ``PS_OBJECT_HEADER_SIZE`` changes based on the |
| 208 | ``PS_ENCRYPTION`` flag status. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 209 | |
Jamie Fox | 865778b | 2020-10-23 19:52:51 +0100 | [diff] [blame^] | 210 | Protected Storage Service Platform Definitions |
| 211 | ============================================== |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 212 | The PS service requires the following platform definitions: |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 213 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 214 | - ``PS_SECTOR_SIZE`` - Defines the size of the flash sectors (the smallest |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 215 | erasable unit) in bytes. |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 216 | - ``PS_SECTORS_PER_BLOCK`` - Defines the number of contiguous PS_SECTOR_SIZE |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 217 | to form a logical block in the filesystem. |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 218 | - ``PS_FLASH_DEV_NAME`` - Specifies the flash device used by PS to store the |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 219 | data. |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 220 | - ``PS_FLASH_PROGRAM_UNIT`` - Defines the smallest flash programmable unit in |
| 221 | bytes. Valid values are powers of two between 1 and ``PS_SECTOR_SIZE`` |
Jamie Fox | d70da21 | 2019-11-28 14:41:45 +0000 | [diff] [blame] | 222 | inclusive. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 223 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 224 | The sectors reserved to be used as protected storage **must** be contiguous |
| 225 | sectors starting at ``PS_FLASH_AREA_ADDR``. |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 226 | |
| 227 | The design requires either 2 blocks, or any number of blocks greater than or |
| 228 | equal to 4. Total number of blocks can not be 0, 1 or 3. This is a design choice |
| 229 | limitation to provide power failure safe update operations. |
Vikas Katariya | 7d74ddb | 2019-09-19 11:59:57 +0100 | [diff] [blame] | 230 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 231 | Target must provide a header file, called ``flash_layout.h``, which defines the |
| 232 | information explained above. The defines must be named as they are specified |
| 233 | above. |
| 234 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 235 | More information about the ``flash_layout.h`` content, not PS related, is |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 236 | available in :doc:`platform readme </platform/ext/readme>` along with other |
| 237 | platform information. |
| 238 | |
Chris Brand | c47d710 | 2020-02-20 11:12:18 -0800 | [diff] [blame] | 239 | The following optional platform definitions may also be defined in |
| 240 | ``flash_layout.h`` or set at build time in ``platform/ext/<TARGET_NAME>.cmake``: |
| 241 | |
| 242 | - ``PS_FLASH_AREA_ADDR`` - Defines the flash address where the protected storage |
| 243 | area starts. |
| 244 | If not defined, the platform must implement ``tfm_hal_ps_fs_info()``. |
| 245 | - ``PS_FLASH_AREA_SIZE`` - Defines the size of the dedicated flash area |
| 246 | for protected storage in bytes. |
| 247 | If not defined, the platform must implement ``tfm_hal_ps_fs_info()``. |
| 248 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 249 | TF-M NV Counter Interface |
| 250 | ========================= |
| 251 | To have a platform independent way to access the NV counters, TF-M defines a |
| 252 | platform NV counter interface. For API specification, please check: |
| 253 | ``platform/include/tfm_plat_nv_counters.h`` |
| 254 | |
| 255 | The system integrators **may** implement this interface based on the target |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 256 | capabilities and set the ``PS_ROLLBACK_PROTECTION`` flag to compile in |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 257 | the rollback protection code. |
| 258 | |
| 259 | Secret Platform Unique Key |
| 260 | ========================== |
| 261 | The encryption policy relies on a secret hardware unique key (HUK) per device. |
| 262 | It is system integrator's responsibility to provide an implementation which |
| 263 | **must** be a non-mutable target implementation. |
| 264 | For API specification, please check: |
| 265 | ``platform/include/tfm_plat_crypto_keys.h`` |
| 266 | |
| 267 | A stub implementation is provided in |
David Hu | 31c574dc | 2019-12-05 18:25:44 +0800 | [diff] [blame] | 268 | ``platform/ext/common/template/crypto_keys.c`` |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 269 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 270 | Non-Secure Identity Manager |
| 271 | =========================== |
| 272 | TF-M core tracks the current client IDs running in the secure or non-secure |
| 273 | processing environment. It provides a dedicated API to retrieve the client ID |
| 274 | which performs the service request. |
| 275 | |
Minos Galanakis | e409401 | 2020-06-12 14:25:34 +0100 | [diff] [blame] | 276 | :doc:`NS client identification documentation </docs/getting_started/tfm_ns_client_identification>` |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 277 | provides further details on how client identification works. |
| 278 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 279 | PS service uses that TF-M core API to retrieve the client ID and associate it |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 280 | as the owner of an asset. Only the owner can read, write or delete that asset |
| 281 | based on the creation flags. |
| 282 | |
Minos Galanakis | e409401 | 2020-06-12 14:25:34 +0100 | [diff] [blame] | 283 | The :doc:`integration guide </docs/getting_started/tfm_integration_guide>` provides further |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 284 | details of non-secure implementation requirements for TF-M. |
| 285 | |
| 286 | Cryptographic Interface |
| 287 | ======================= |
| 288 | The reference encryption policy is built on AES-GCM, and it **may** be replaced |
| 289 | by a vendor specific implementation. |
| 290 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 291 | The PS service abstracts all the cryptographic requirements and specifies the |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 292 | required cryptographic interface in |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 293 | ``secure_fw/partitions/protected_storage/crypto/ps_crypto_interface.h`` |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 294 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 295 | The PS service cryptographic operations are implemented in |
| 296 | ``secure_fw/partitions/protected_storage/crypto/ps_crypto_interface.c``, using |
| 297 | calls to the TF-M Crypto service. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 298 | |
Jamie Fox | 865778b | 2020-10-23 19:52:51 +0100 | [diff] [blame^] | 299 | PS Service Build Definitions |
| 300 | ============================ |
| 301 | The PS service uses a set of C definitions to compile in/out certain features, |
| 302 | as well as to configure certain service parameters. When using the TF-M build |
| 303 | system, these definitions are controlled by build flags of the same name. The |
| 304 | ``config/config_default.cmake`` file sets the default values of those flags, but |
| 305 | they can be overwritten based on platform capabilities by setting them in |
| 306 | ``platform/ext/target/<TARGET_NAME>/config.cmake``. The list of PS service build |
| 307 | definitions is: |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 308 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 309 | - ``PS_ENCRYPTION``- this flag allows to enable/disable encryption |
| 310 | option to encrypt the protected storage data. |
| 311 | - ``PS_CREATE_FLASH_LAYOUT``- this flag indicates that it is required |
| 312 | to create a PS flash layout. If this flag is set, PS service will |
| 313 | generate an empty and valid PS flash layout to store assets. It will |
| 314 | erase all data located in the assigned PS memory area before generating |
| 315 | the PS layout. This flag is required to be set if the PS memory area |
| 316 | is located in a non-persistent memory. This flag can be set if the PS |
| 317 | memory area is located in a persistent memory without a valid PS flash |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 318 | layout in it. That is the case when it is the first time in the device |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 319 | life that the PS service is executed. |
| 320 | - ``PS_VALIDATE_METADATA_FROM_FLASH``- this flag allows to |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 321 | enable/disable the validation mechanism to check the metadata store in flash |
| 322 | every time the flash data is read from flash. This validation is required |
| 323 | if the flash is not hardware protected against malicious writes. In case |
| 324 | the flash is protected against malicious writes (i.e embedded flash, etc), |
| 325 | this validation can be disabled in order to reduce the validation overhead. |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 326 | - ``PS_ROLLBACK_PROTECTION``- this flag allows to enable/disable |
| 327 | rollback protection in protected storage service. This flag takes effect only |
| 328 | if the target has non-volatile counters and ``PS_ENCRYPTION`` flag is on. |
Jamie Fox | f58bd22 | 2020-06-12 18:21:25 +0100 | [diff] [blame] | 329 | - ``PS_RAM_FS``- setting this flag to ``ON`` enables the use of RAM instead of |
| 330 | the persistent storage device to store the FS in the Protected Storage |
| 331 | service. This flag is ``OFF`` by default. The PS regression tests write/erase |
| 332 | storage multiple time, so enabling this flag can increase the life of flash |
| 333 | memory when testing. |
Chris Brand | c47d710 | 2020-02-20 11:12:18 -0800 | [diff] [blame] | 334 | If this flag is set to ``ON``, PS_RAM_FS_SIZE must also be provided. This |
| 335 | specifies the size of the block of RAM to be used to simulate the flash. |
Soby Mathew | 728a20a | 2020-03-25 13:33:35 +0000 | [diff] [blame] | 336 | |
| 337 | .. Note:: |
Jamie Fox | f58bd22 | 2020-06-12 18:21:25 +0100 | [diff] [blame] | 338 | If this flag is disabled when running the regression tests, then it is |
| 339 | recommended that the persistent storage area is erased before running the |
| 340 | tests to ensure that all tests can run to completion. The type of persistent |
| 341 | storage area is platform specific (eFlash, MRAM, etc.) and it is described |
| 342 | in corresponding flash_layout.h |
Soby Mathew | 728a20a | 2020-03-25 13:33:35 +0000 | [diff] [blame] | 343 | |
Jamie Fox | 865778b | 2020-10-23 19:52:51 +0100 | [diff] [blame^] | 344 | - ``PS_MAX_ASSET_SIZE`` - Defines the maximum asset size to be stored in the |
| 345 | PS area. This size is used to define the temporary buffers used by PS to |
| 346 | read/write the asset content from/to flash. The memory used by the temporary |
| 347 | buffers is allocated statically as PS does not use dynamic memory allocation. |
| 348 | - ``PS_NUM_ASSETS`` - Defines the maximum number of assets to be stored in the |
| 349 | PS area. This number is used to dimension statically the object table size in |
| 350 | RAM (fast access) and flash (persistent storage). The memory used by the |
| 351 | object table is allocated statically as PS does not use dynamic memory |
| 352 | allocation. |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 353 | - ``PS_TEST_NV_COUNTERS``- this flag enables the virtual |
| 354 | implementation of the PS NV counters interface in |
| 355 | ``test/suites/ps/secure/nv_counters``, which emulates NV counters in |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 356 | RAM, and disables the hardware implementation of NV counters provided by |
| 357 | the secure service. This flag is enabled by default when building the |
| 358 | regression tests and disabled by default otherwise. This flag can be |
| 359 | overridden to ``OFF`` when building the regression tests. In this case, |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 360 | the PS rollback protection test suite will not be built, as it relies |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 361 | on extra functionality provided by the virtual NV counters to simulate |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 362 | different rollback scenarios. The remainder of the PS test suites will |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 363 | run using the hardware NV counters. Please note that running the tests in |
| 364 | this configuration will quickly increase the hardware NV counter values, |
| 365 | which cannot be decreased again. |
| 366 | Overriding this flag from its default value of ``OFF`` when not |
| 367 | building the regression tests is not currently supported. |
| 368 | |
| 369 | -------------- |
| 370 | |
Jamie Fox | dd3de95 | 2019-11-25 17:45:40 +0000 | [diff] [blame] | 371 | *Copyright (c) 2018-2020, Arm Limited. All rights reserved.* |
Chris Brand | c47d710 | 2020-02-20 11:12:18 -0800 | [diff] [blame] | 372 | *Copyright (c) 2020, Cypress Semiconductor Corporation. All rights reserved.* |