Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 1 | ======================================== |
| 2 | Protected Storage service key management |
| 3 | ======================================== |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 4 | |
| 5 | :Author: Jamie Fox |
| 6 | :Organization: Arm Limited |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 7 | |
| 8 | Background |
| 9 | ========== |
| 10 | The PSA Protected Storage API requires confidentiality for external storage to |
| 11 | be provided by: |
| 12 | |
| 13 | **cryptographic ciphers using device-bound keys**, a tamper resistant |
| 14 | enclosure, or an inaccessible deployment location, depending on the threat |
| 15 | model of the deployed system. |
| 16 | |
| 17 | A TBSA-M-compliant device must embed a Hardware Unique Key (HUK), which provides |
| 18 | the root of trust (RoT) for confidentiality in the system. It must have at least |
| 19 | 128 bits of entropy (and a 128 bit data size), and be accessible only to Trusted |
| 20 | code or Trusted hardware that acts on behalf of Trusted code. [TBSA-M]_ |
| 21 | |
Jianliang Shen | fa9235b | 2022-04-12 11:22:32 +0800 | [diff] [blame] | 22 | Design description |
| 23 | ================== |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 24 | Each time the system boots, PS will request that the Crypto service uses a key |
Raef Coles | 81c1619 | 2022-03-02 14:00:10 +0000 | [diff] [blame] | 25 | derivation function (KDF) to derive a storage key from the HUK, by referring to |
| 26 | the builtin key handle for the HUK. The storage key could be kept in on-chip |
| 27 | volatile memory private to the Crypto partition, or it could remain inside a |
| 28 | secure element. Either way it will not be returned to PS. |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 29 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 30 | For each call to the PSA Protected Storage APIs, PS will make requests to the |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 31 | Crypto service to perform AEAD encryption and/or decryption operations using the |
| 32 | storage key (providing a fresh nonce for each encryption). |
| 33 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 34 | At no point will PS access the key material itself, only referring to the HUK |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 35 | and storage key by their handles in the Crypto service. |
| 36 | |
| 37 | Key derivation |
| 38 | ============== |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 39 | PS will make key derivation requests to the Crypto service with calls to the |
Jianliang Shen | fa9235b | 2022-04-12 11:22:32 +0800 | [diff] [blame] | 40 | PSA Crypto APIs. In order to derive the storage key, the following calls are |
| 41 | required: |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 42 | |
Jianliang Shen | fa9235b | 2022-04-12 11:22:32 +0800 | [diff] [blame] | 43 | .. code-block:: c |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 44 | |
Raef Coles | 81c1619 | 2022-03-02 14:00:10 +0000 | [diff] [blame] | 45 | status = psa_key_derivation_setup(&op, PSA_ALG_HKDF(PSA_ALG_SHA_256)); |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 46 | |
Raef Coles | 81c1619 | 2022-03-02 14:00:10 +0000 | [diff] [blame] | 47 | /* Set up a key derivation operation with HUK */ |
| 48 | status = psa_key_derivation_input_key(&op, PSA_KEY_DERIVATION_INPUT_SECRET, |
| 49 | TFM_BUILTIN_KEY_ID_HUK); |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 50 | |
Jianliang Shen | fa9235b | 2022-04-12 11:22:32 +0800 | [diff] [blame] | 51 | /* Supply the PS key label as an input to the key derivation */ |
Raef Coles | 81c1619 | 2022-03-02 14:00:10 +0000 | [diff] [blame] | 52 | status = psa_key_derivation_input_bytes(&op, PSA_KEY_DERIVATION_INPUT_INFO, |
Jianliang Shen | fa9235b | 2022-04-12 11:22:32 +0800 | [diff] [blame] | 53 | key_label, |
| 54 | key_label_len); |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 55 | |
Jianliang Shen | fa9235b | 2022-04-12 11:22:32 +0800 | [diff] [blame] | 56 | /* Create the storage key from the key derivation operation */ |
Raef Coles | 81c1619 | 2022-03-02 14:00:10 +0000 | [diff] [blame] | 57 | status = psa_key_derivation_output_key(&attributes, &op, &ps_key); |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 58 | |
Jianliang Shen | fa9235b | 2022-04-12 11:22:32 +0800 | [diff] [blame] | 59 | .. note:: |
Raef Coles | 81c1619 | 2022-03-02 14:00:10 +0000 | [diff] [blame] | 60 | ``TFM_BUILTIN_KEY_ID_HUK`` is a static key ID that is used to identify the |
| 61 | HUK. It has an arbitrary value defined in ``tfm_crypto_defs.h`` |
Jianliang Shen | fa9235b | 2022-04-12 11:22:32 +0800 | [diff] [blame] | 62 | |
Raef Coles | 81c1619 | 2022-03-02 14:00:10 +0000 | [diff] [blame] | 63 | ``ps_key`` is a PSA Crypto key handle to a volatile key, set by the |
| 64 | derivation operation. After the call to ``psa_key_derivation_output_key``, |
| 65 | it can be used to refer the storage key. |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 66 | |
Raef Coles | 81c1619 | 2022-03-02 14:00:10 +0000 | [diff] [blame] | 67 | ``key_label`` can be any string that is independent of the input key |
| 68 | material and different to the label used in any other derivation from the |
| 69 | same input key. It prevents two different contexts from deriving the same |
| 70 | output key from the same input key. |
| 71 | |
| 72 | The key derivation function used by the crypto service to derive the storage key |
| 73 | will be HKDF, with SHA-256 as the underlying hash function. HKDF is suitable |
| 74 | because: |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 75 | |
| 76 | - It is simple and efficient, requiring only two HMAC operations when the length |
| 77 | of the output key material is less than or equal to the hash length (as is the |
| 78 | case here). |
| 79 | - The trade-off is that HKDF is only suitable when the input key material has at |
| 80 | least as much entropy as required for the output key material. But this is the |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 81 | case here, as the HUK has 128 bits of entropy, the same as required by PS. |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 82 | - HKDF is standardised in RFC 5869 [RFC5869]_ and its security has been formally |
| 83 | analysed. [HKDF]_ |
| 84 | - It is supported by the TF-M Crypto service. |
| 85 | |
| 86 | The choice of underlying hash function is fairly straightforward: it needs to be |
| 87 | a modern standardised algorithm, considered to be secure and supported by TF-M |
| 88 | Crypto. This narrows it down to just the SHA-2 family. Of the hash functions in |
| 89 | the family, SHA-256 is the simplest and provides more than enough output length. |
| 90 | |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 91 | Keeping the storage key private to PS |
| 92 | ------------------------------------- |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 93 | |
Raef Coles | 81c1619 | 2022-03-02 14:00:10 +0000 | [diff] [blame] | 94 | The Crypto service derives a platform key from the HUK, using the partition ID |
| 95 | as the input to that derivation, and that platform key is used for the key |
| 96 | derivation by PS. This happens transparently, and to PS is indistinguishable |
| 97 | from deriving from the HUK except that other partitions cannot derive the |
| 98 | storage key even if they know the derivation parameters. |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 99 | |
| 100 | Key use |
| 101 | ======= |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 102 | To encrypt and decrypt data, PS will call the PSA Crypto AEAD APIs in the same |
Jianliang Shen | fa9235b | 2022-04-12 11:22:32 +0800 | [diff] [blame] | 103 | way as the current implementation, but ``ps_key`` will refer to the storage key, |
| 104 | rather than the imported HUK. For each encryption operation, the following call |
| 105 | is made (and analogously for decryption): |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 106 | |
Jianliang Shen | fa9235b | 2022-04-12 11:22:32 +0800 | [diff] [blame] | 107 | .. code-block:: c |
| 108 | |
| 109 | psa_aead_encrypt(ps_key, PS_CRYPTO_ALG, |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 110 | crypto->ref.iv, PS_IV_LEN_BYTES, |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 111 | add, add_len, |
| 112 | in, in_len, |
Jianliang Shen | fa9235b | 2022-04-12 11:22:32 +0800 | [diff] [blame] | 113 | out, out_size, out_len); |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 114 | |
| 115 | References |
| 116 | ========== |
Matthew Dalzell | 988bbd6 | 2025-06-05 15:49:26 +0100 | [diff] [blame] | 117 | .. [TBSA-M] `Arm Platform Security Architecture Trusted Base System Architecture for Armv6-M, Armv7-M and Armv8-M, version 1.0 <https://developer.arm.com/-/media/Arm%20Developer%20Community/PDF/PSA/DEN0083_PSA_TBSA-M_1.0-bet2.pdf?revision=5f9de99f-a7b5-4851-b041-f698521bf6bf>`_ |
| 118 | |
| 119 | .. [HKDF] `Hugo Krawczyk. 2010. Cryptographic extraction and key derivation: the HKDF scheme. In Proceedings of the 30th annual conference on Advances in cryptology (CRYPTO'10) <https://eprint.iacr.org/2010/264.pdf>`_ |
| 120 | |
| 121 | .. [RFC5869] `IETF RFC 5869: HMAC-based Extract-and-Expand Key Derivation Function (HKDF) <https://datatracker.ietf.org/doc/html/rfc5869>`_ |
Jamie Fox | 9331960 | 2019-06-07 18:12:15 +0100 | [diff] [blame] | 122 | |
| 123 | -------------- |
| 124 | |
Jianliang Shen | fa9235b | 2022-04-12 11:22:32 +0800 | [diff] [blame] | 125 | *Copyright (c) 2019-2022, Arm Limited. All rights reserved.* |