blob: 534572207c301d7fc08c002883efa229a9a252de [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
Jamie Fox93319602019-06-07 18:12:15 +01007
8Background
9==========
10The PSA Protected Storage API requires confidentiality for external storage to
11be 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
17A TBSA-M-compliant device must embed a Hardware Unique Key (HUK), which provides
18the root of trust (RoT) for confidentiality in the system. It must have at least
19128 bits of entropy (and a 128 bit data size), and be accessible only to Trusted
20code or Trusted hardware that acts on behalf of Trusted code. [TBSA-M]_
21
Jianliang Shenfa9235b2022-04-12 11:22:32 +080022Design description
23==================
Kevin Pengc6d74502020-03-04 16:55:37 +080024Each time the system boots, PS will request that the Crypto service uses a key
Raef Coles81c16192022-03-02 14:00:10 +000025derivation function (KDF) to derive a storage key from the HUK, by referring to
26the builtin key handle for the HUK. The storage key could be kept in on-chip
27volatile memory private to the Crypto partition, or it could remain inside a
28secure element. Either way it will not be returned to PS.
Jamie Fox93319602019-06-07 18:12:15 +010029
Kevin Pengc6d74502020-03-04 16:55:37 +080030For each call to the PSA Protected Storage APIs, PS will make requests to the
Jamie Fox93319602019-06-07 18:12:15 +010031Crypto service to perform AEAD encryption and/or decryption operations using the
32storage key (providing a fresh nonce for each encryption).
33
Kevin Pengc6d74502020-03-04 16:55:37 +080034At no point will PS access the key material itself, only referring to the HUK
Jamie Fox93319602019-06-07 18:12:15 +010035and storage key by their handles in the Crypto service.
36
37Key derivation
38==============
Kevin Pengc6d74502020-03-04 16:55:37 +080039PS will make key derivation requests to the Crypto service with calls to the
Jianliang Shenfa9235b2022-04-12 11:22:32 +080040PSA Crypto APIs. In order to derive the storage key, the following calls are
41required:
Jamie Fox93319602019-06-07 18:12:15 +010042
Jianliang Shenfa9235b2022-04-12 11:22:32 +080043.. code-block:: c
Jamie Fox93319602019-06-07 18:12:15 +010044
Raef Coles81c16192022-03-02 14:00:10 +000045 status = psa_key_derivation_setup(&op, PSA_ALG_HKDF(PSA_ALG_SHA_256));
Jamie Fox93319602019-06-07 18:12:15 +010046
Raef Coles81c16192022-03-02 14:00:10 +000047 /* 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 Fox93319602019-06-07 18:12:15 +010050
Jianliang Shenfa9235b2022-04-12 11:22:32 +080051 /* Supply the PS key label as an input to the key derivation */
Raef Coles81c16192022-03-02 14:00:10 +000052 status = psa_key_derivation_input_bytes(&op, PSA_KEY_DERIVATION_INPUT_INFO,
Jianliang Shenfa9235b2022-04-12 11:22:32 +080053 key_label,
54 key_label_len);
Jamie Fox93319602019-06-07 18:12:15 +010055
Jianliang Shenfa9235b2022-04-12 11:22:32 +080056 /* Create the storage key from the key derivation operation */
Raef Coles81c16192022-03-02 14:00:10 +000057 status = psa_key_derivation_output_key(&attributes, &op, &ps_key);
Jamie Fox93319602019-06-07 18:12:15 +010058
Jianliang Shenfa9235b2022-04-12 11:22:32 +080059.. note::
Raef Coles81c16192022-03-02 14:00:10 +000060 ``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 Shenfa9235b2022-04-12 11:22:32 +080062
Raef Coles81c16192022-03-02 14:00:10 +000063 ``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 Fox93319602019-06-07 18:12:15 +010066
Raef Coles81c16192022-03-02 14:00:10 +000067 ``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
72The key derivation function used by the crypto service to derive the storage key
73will be HKDF, with SHA-256 as the underlying hash function. HKDF is suitable
74because:
Jamie Fox93319602019-06-07 18:12:15 +010075
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 Pengc6d74502020-03-04 16:55:37 +080081 case here, as the HUK has 128 bits of entropy, the same as required by PS.
Jamie Fox93319602019-06-07 18:12:15 +010082- 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
86The choice of underlying hash function is fairly straightforward: it needs to be
87a modern standardised algorithm, considered to be secure and supported by TF-M
88Crypto. This narrows it down to just the SHA-2 family. Of the hash functions in
89the family, SHA-256 is the simplest and provides more than enough output length.
90
Kevin Pengc6d74502020-03-04 16:55:37 +080091Keeping the storage key private to PS
92-------------------------------------
Jamie Fox93319602019-06-07 18:12:15 +010093
Raef Coles81c16192022-03-02 14:00:10 +000094The Crypto service derives a platform key from the HUK, using the partition ID
95as the input to that derivation, and that platform key is used for the key
96derivation by PS. This happens transparently, and to PS is indistinguishable
97from deriving from the HUK except that other partitions cannot derive the
98storage key even if they know the derivation parameters.
Jamie Fox93319602019-06-07 18:12:15 +010099
100Key use
101=======
Kevin Pengc6d74502020-03-04 16:55:37 +0800102To encrypt and decrypt data, PS will call the PSA Crypto AEAD APIs in the same
Jianliang Shenfa9235b2022-04-12 11:22:32 +0800103way as the current implementation, but ``ps_key`` will refer to the storage key,
104rather than the imported HUK. For each encryption operation, the following call
105is made (and analogously for decryption):
Jamie Fox93319602019-06-07 18:12:15 +0100106
Jianliang Shenfa9235b2022-04-12 11:22:32 +0800107.. code-block:: c
108
109 psa_aead_encrypt(ps_key, PS_CRYPTO_ALG,
Kevin Pengc6d74502020-03-04 16:55:37 +0800110 crypto->ref.iv, PS_IV_LEN_BYTES,
Jamie Fox93319602019-06-07 18:12:15 +0100111 add, add_len,
112 in, in_len,
Jianliang Shenfa9235b2022-04-12 11:22:32 +0800113 out, out_size, out_len);
Jamie Fox93319602019-06-07 18:12:15 +0100114
115References
116==========
Matthew Dalzell988bbd62025-06-05 15:49:26 +0100117.. [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 Fox93319602019-06-07 18:12:15 +0100122
123--------------
124
Jianliang Shenfa9235b2022-04-12 11:22:32 +0800125*Copyright (c) 2019-2022, Arm Limited. All rights reserved.*