blob: 80a39be492f6455167238450102ce027240f1eda [file] [log] [blame]
Kevin Pengc6d74502020-03-04 16:55:37 +08001========================================
2Protected Storage service key management
3========================================
Jamie Fox93319602019-06-07 18:12:15 +01004
5:Author: Jamie Fox
6:Organization: Arm Limited
7:Contact: Jamie Fox <jamie.fox@arm.com>
Jamie Fox4c968632020-01-22 11:10:11 +00008:Status: Accepted
Jamie Fox93319602019-06-07 18:12:15 +01009
10Background
11==========
12The PSA Protected Storage API requires confidentiality for external storage to
13be provided by:
14
15 **cryptographic ciphers using device-bound keys**, a tamper resistant
16 enclosure, or an inaccessible deployment location, depending on the threat
17 model of the deployed system.
18
19A TBSA-M-compliant device must embed a Hardware Unique Key (HUK), which provides
20the root of trust (RoT) for confidentiality in the system. It must have at least
21128 bits of entropy (and a 128 bit data size), and be accessible only to Trusted
22code or Trusted hardware that acts on behalf of Trusted code. [TBSA-M]_
23
Kevin Pengc6d74502020-03-04 16:55:37 +080024In the current implementation, the Protected Storage (PS) service reads the HUK
Jamie Fox93319602019-06-07 18:12:15 +010025directly and imports it into the Crypto partition for further use. This has
26multiple drawbacks:
27
Kevin Pengc6d74502020-03-04 16:55:37 +080028- If there were a flaw in PS that allowed an attacker to obtain its key, then
Jamie Fox93319602019-06-07 18:12:15 +010029 the HUK would be exposed, and so the attacker would be able to decrypt not
Kevin Pengc6d74502020-03-04 16:55:37 +080030 just protected storage but also anything else encrypted with the HUK or a key
Jamie Fox93319602019-06-07 18:12:15 +010031 derived from the HUK.
32- Using the same key for two or more different cryptographic algorithms may
33 reduce the security provided by one or more of them.
34- It is not possible to re-key if the HUK is used directly, for example in the
35 case of a lost key.
36- It is incompatible with devices where the HUK is in an enclave and cannot be
37 read directly.
38
39Proposal
40========
Kevin Pengc6d74502020-03-04 16:55:37 +080041Each time the system boots, PS will request that the Crypto service uses a key
Jamie Fox93319602019-06-07 18:12:15 +010042derivation function (KDF) to derive a storage key from the HUK. The storage key
43could be kept in on-chip volatile memory private to the Crypto partition, or it
Kevin Pengc6d74502020-03-04 16:55:37 +080044could remain inside a secure element. Either way it will not be returned to PS.
Jamie Fox93319602019-06-07 18:12:15 +010045
Kevin Pengc6d74502020-03-04 16:55:37 +080046For each call to the PSA Protected Storage APIs, PS will make requests to the
Jamie Fox93319602019-06-07 18:12:15 +010047Crypto service to perform AEAD encryption and/or decryption operations using the
48storage key (providing a fresh nonce for each encryption).
49
Kevin Pengc6d74502020-03-04 16:55:37 +080050At no point will PS access the key material itself, only referring to the HUK
Jamie Fox93319602019-06-07 18:12:15 +010051and storage key by their handles in the Crypto service.
52
53Key derivation
54==============
Kevin Pengc6d74502020-03-04 16:55:37 +080055PS will make key derivation requests to the Crypto service with calls to the
Jamie Fox93319602019-06-07 18:12:15 +010056PSA Crypto APIs. In order to derive the storage key, the following calls will be
57made::
58
59 /* Open a handle to the HUK */
60 psa_open_key(PSA_KEY_LIFETIME_PERSISTENT,
61 TFM_CRYPTO_KEY_ID_HUK,
62 &huk_key_handle)
63
64 /* Set up a key derivation operation with the HUK as the input key */
Kevin Pengc6d74502020-03-04 16:55:37 +080065 psa_key_derivation(&ps_key_generator,
Jamie Fox93319602019-06-07 18:12:15 +010066 huk_key_handle,
67 TFM_CRYPTO_ALG_HUK_DERIVATION,
Kevin Pengc6d74502020-03-04 16:55:37 +080068 PS_KEY_SALT, PS_KEY_SALT_LEN_BYTES,
69 PS_KEY_LABEL, PS_KEY_LABEL_LEN_BYTES,
70 PS_KEY_LEN_BYTES)
Jamie Fox93319602019-06-07 18:12:15 +010071
72 /* Create the storage key from the key generator */
Kevin Pengc6d74502020-03-04 16:55:37 +080073 psa_generator_import_key(ps_key_handle,
74 PS_KEY_TYPE,
75 PSA_BYTES_TO_BITS(PS_KEY_LEN_BYTES),
76 &ps_key_generator)
Jamie Fox93319602019-06-07 18:12:15 +010077
78.. note:: ``TFM_CRYPTO_KEY_ID_HUK`` is a PSA Crypto key ID that is assumed in
79 this design to identify the hardware unique key.
80
Kevin Pengc6d74502020-03-04 16:55:37 +080081 ``ps_key_handle`` is a PSA Crypto key handle to a volatile key, set
Jamie Fox93319602019-06-07 18:12:15 +010082 up in the normal way. After the call to ``psa_generator_import_key``,
83 it contains the storage key.
84
Kevin Pengc6d74502020-03-04 16:55:37 +080085 ``PS_KEY_SALT`` can be ``NULL``, as it is only used in the 'extract'
Jamie Fox93319602019-06-07 18:12:15 +010086 step of HKDF, which is redundant when the input key material is a
87 cryptographically strong key. [RFC5869]_ It must be constant so that
88 the same key can be derived each boot, to decrypt previously-stored
89 data.
90
Kevin Pengc6d74502020-03-04 16:55:37 +080091 ``PS_KEY_LABEL`` can be any string that is independent of the input
Jamie Fox93319602019-06-07 18:12:15 +010092 key material and different to the label used in any other derivation
93 from the same input key. It prevents two different contexts from
94 deriving the same output key from the same input key.
95
96In the call to ``psa_key_derivation()``, ``TFM_CRYPTO_ALG_HUK_DERIVATION`` is
97supplied as the key derivation algorithm argument. This indicates that the key
98derivation should be done from the HUK, and allows it to be implemented in a
99platform-defined way (e.g. using a crypto accelerator). The system integrator
100should choose the most optimal algorithm for the platform, or fall back to the
101software implementation if none is available.
102
103When implemented in software, the key derivation function used by the crypto
104service to derive the storage key will be HKDF, with SHA-256 as the underlying
105hash function. HKDF is suitable because:
106
107- It is simple and efficient, requiring only two HMAC operations when the length
108 of the output key material is less than or equal to the hash length (as is the
109 case here).
110- The trade-off is that HKDF is only suitable when the input key material has at
111 least as much entropy as required for the output key material. But this is the
Kevin Pengc6d74502020-03-04 16:55:37 +0800112 case here, as the HUK has 128 bits of entropy, the same as required by PS.
Jamie Fox93319602019-06-07 18:12:15 +0100113- HKDF is standardised in RFC 5869 [RFC5869]_ and its security has been formally
114 analysed. [HKDF]_
115- It is supported by the TF-M Crypto service.
116
117The choice of underlying hash function is fairly straightforward: it needs to be
118a modern standardised algorithm, considered to be secure and supported by TF-M
119Crypto. This narrows it down to just the SHA-2 family. Of the hash functions in
120the family, SHA-256 is the simplest and provides more than enough output length.
121
Kevin Pengc6d74502020-03-04 16:55:37 +0800122Keeping the storage key private to PS
123-------------------------------------
Jamie Fox93319602019-06-07 18:12:15 +0100124The salt and label fields are not generally secret, so an Application RoT
125service could request the Crypto service to derive the same storage key from the
126HUK, which violates isolation between Application RoT partitions to some extent.
127This could be fixed in a number of ways:
128
129- Only PSA RoT partitions can request Crypto to derive keys from the HUK.
130
Kevin Pengc6d74502020-03-04 16:55:37 +0800131 - But then either PS has to be in the PSA RoT or request a service in the PSA
Jamie Fox93319602019-06-07 18:12:15 +0100132 RoT to do the derivation on its behalf.
133
Kevin Pengc6d74502020-03-04 16:55:37 +0800134- PS has a secret (pseudo)random salt, accessible only to it, that it uses to
Jamie Fox93319602019-06-07 18:12:15 +0100135 derive the storage key.
136
137 - Where would this salt be stored? It cannot be generated fresh each boot
138 because the storage key must stay the same across reboots.
139
140- The Crypto service appends the partition ID to the label, so that no two
141 partitions can derive the same key.
142
143 - Still need to make sure only PSA RoT partitions can directly access the HUK
144 or Secure Enclave. The label is not secret, so any actor that can access the
145 HUK could simply perform the derivation itself, rather than making a request
146 to the Crypto service.
147
148The third option would solve the issue with the fewest drawbacks, so this option
149is the one that is proposed.
150
151Key use
152=======
Kevin Pengc6d74502020-03-04 16:55:37 +0800153To encrypt and decrypt data, PS will call the PSA Crypto AEAD APIs in the same
154way as the current implementation, but ``ps_key_handle`` will refer to the
Jamie Fox93319602019-06-07 18:12:15 +0100155storage key, rather than the imported HUK. For each encryption operation, the
156following call is made (and analogously for decryption)::
157
Kevin Pengc6d74502020-03-04 16:55:37 +0800158 psa_aead_encrypt(ps_key_handle, PS_CRYPTO_ALG,
159 crypto->ref.iv, PS_IV_LEN_BYTES,
Jamie Fox93319602019-06-07 18:12:15 +0100160 add, add_len,
161 in, in_len,
162 out, out_size, out_len)
163
164Future changes
165==============
166In the future, the client's partition ID and the asset's UID could be used to
167derive a key that is unique to that asset, each time the Protected Storage APIs
168are called (*key diversification*). To achieve this, the key derivation must use
169a ``label`` parameter that is unique to each client ID, UID pair.
170
171References
172==========
173.. [TBSA-M] Arm Platform Security Architecture Trusted Base System Architecture
174 for Armv6-M, Armv7-M and Armv8-M, version 1.0
175.. [HKDF] Hugo Krawczyk. 2010. Cryptographic extraction and key derivation: the
176 HKDF scheme. In Proceedings of the 30th annual conference on Advances in
177 cryptology (CRYPTO'10)
178.. [RFC5869] IETF RFC 5869: HMAC-based Extract-and-Expand Key Derivation
179 Function (HKDF)
180
181--------------
182
Jamie Fox4c968632020-01-22 11:10:11 +0000183*Copyright (c) 2019-2020, Arm Limited. All rights reserved.*