Marc Moreno Berengue | 20dab39 | 2017-11-29 13:18:58 +0000 | [diff] [blame] | 1 | /* |
Tamas Ban | c163053 | 2020-01-15 11:46:14 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2020, Arm Limited. All rights reserved. |
Marc Moreno Berengue | 20dab39 | 2017-11-29 13:18:58 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
Marc Moreno Berengue | ef20272 | 2018-08-10 13:43:43 +0100 | [diff] [blame] | 8 | #ifndef __TFM_PLAT_CRYPTO_KEYS_H__ |
| 9 | #define __TFM_PLAT_CRYPTO_KEYS_H__ |
Marc Moreno Berengue | 20dab39 | 2017-11-29 13:18:58 +0000 | [diff] [blame] | 10 | /** |
| 11 | * \note The interfaces defined in this file must be implemented for each |
| 12 | * SoC. |
| 13 | */ |
Marc Moreno Berengue | ef20272 | 2018-08-10 13:43:43 +0100 | [diff] [blame] | 14 | |
Jamie Fox | 104f750 | 2019-09-25 18:56:48 +0100 | [diff] [blame] | 15 | #include <stddef.h> |
Marc Moreno Berengue | ef20272 | 2018-08-10 13:43:43 +0100 | [diff] [blame] | 16 | #include <stdint.h> |
| 17 | #include "tfm_plat_defs.h" |
Raef Coles | 4d6ea2f | 2019-10-15 14:30:40 +0100 | [diff] [blame] | 18 | #include "psa/crypto.h" |
Marc Moreno Berengue | ef20272 | 2018-08-10 13:43:43 +0100 | [diff] [blame] | 19 | |
Marc Moreno Berengue | 20dab39 | 2017-11-29 13:18:58 +0000 | [diff] [blame] | 20 | #ifdef __cplusplus |
| 21 | extern "C" { |
| 22 | #endif |
| 23 | |
Marc Moreno Berengue | 20dab39 | 2017-11-29 13:18:58 +0000 | [diff] [blame] | 24 | /** |
Tamas Ban | 8f33623 | 2018-12-21 14:54:11 +0000 | [diff] [blame] | 25 | * Structure definition to carry pointer and size information about an Elliptic |
| 26 | * curve key which is stored in a buffer(key_buf) in raw format (without |
| 27 | * encoding): |
| 28 | * - priv_key Base address of the private key in key_buf. It must be |
| 29 | * present on the device. |
| 30 | * - priv_key_size Size of the private key in bytes. |
| 31 | * - pubx_key Base address of x-coordinate of the public key in key_buf. |
| 32 | * It can be empty, because it can be recomputed based on |
| 33 | * private key. |
| 34 | * - pubx_key_size Length of x-coordinate of the public key in key_buf. |
| 35 | * It can be empty, because it can be recomputed based on |
| 36 | * private key. |
| 37 | * - puby_key Base address of y-coordinate of the public key in key_buf. |
| 38 | * It can be empty, because either it can be recomputed based |
| 39 | * on private key or some curve type works without it. |
| 40 | * - puby_key_size Length of y-coordinate of the public key in key_buf. |
| 41 | */ |
| 42 | struct ecc_key_t { |
| 43 | uint8_t *priv_key; |
| 44 | uint32_t priv_key_size; |
| 45 | uint8_t *pubx_key; |
| 46 | uint32_t pubx_key_size; |
| 47 | uint8_t *puby_key; |
| 48 | uint32_t puby_key_size; |
| 49 | }; |
| 50 | |
Tamas Ban | 5db5753 | 2019-07-17 10:59:02 +0100 | [diff] [blame] | 51 | #define ROTPK_HASH_LEN (32u) /* SHA256 */ |
| 52 | |
| 53 | /** |
| 54 | * Structure to store the hard-coded (embedded in secure firmware) hash of ROTPK |
| 55 | * for firmware authentication. |
| 56 | * |
| 57 | * \note Just temporary solution, hard-coded key-hash values in firmware is not |
| 58 | * suited for use in production! |
| 59 | */ |
| 60 | struct tfm_plat_rotpk_t { |
| 61 | const uint8_t *key_hash; |
| 62 | const uint8_t hash_len; |
| 63 | }; |
| 64 | |
Tamas Ban | 8f33623 | 2018-12-21 14:54:11 +0000 | [diff] [blame] | 65 | /** |
Jamie Fox | 104f750 | 2019-09-25 18:56:48 +0100 | [diff] [blame] | 66 | * \brief Gets key material derived from the hardware unique key. |
| 67 | * |
| 68 | * \param[in] label Label for KDF |
| 69 | * \param[in] label_size Size of the label |
| 70 | * \param[in] context Context for KDF |
| 71 | * \param[in] context_size Size of the context |
| 72 | * \param[out] key Buffer to output the derived key material |
| 73 | * \param[in] key_size Requested size of the derived key material and |
| 74 | * minimum size of the key buffer |
| 75 | * |
| 76 | * \return Returns error code specified in \ref tfm_plat_err_t |
| 77 | */ |
| 78 | enum tfm_plat_err_t tfm_plat_get_huk_derived_key(const uint8_t *label, |
| 79 | size_t label_size, |
| 80 | const uint8_t *context, |
| 81 | size_t context_size, |
| 82 | uint8_t *key, |
| 83 | size_t key_size); |
| 84 | |
| 85 | /** |
Tamas Ban | 8f33623 | 2018-12-21 14:54:11 +0000 | [diff] [blame] | 86 | * \brief Get the initial attestation key |
| 87 | * |
| 88 | * The device MUST contain an initial attestation key, which is used to sign the |
| 89 | * token. Initial attestation service supports elliptic curve signing |
| 90 | * algorithms. Device maker can decide whether store only the private key on the |
| 91 | * device or store both (public and private) key. Public key can be recomputed |
| 92 | * based on private key. Keys must be provided in raw format, just binary data |
| 93 | * without any encoding (DER, COSE). Caller provides a buffer to copy all the |
| 94 | * available key components to there. Key components must be copied after |
| 95 | * each other to the buffer. The base address and the length of each key |
| 96 | * component must be indicating in the corresponding field of ecc_key |
| 97 | * (\ref struct ecc_key_t). |
| 98 | * Curve_type indicates to which curve belongs the key. |
| 99 | * |
| 100 | * |
| 101 | * Keys must be provided in |
| 102 | * |
| 103 | * \param[in/out] key_buf Buffer to store the initial attestation key. |
| 104 | * \param[in] size Size of the buffer. |
| 105 | * \param[out] ecc_key A structure to carry pointer and size information |
| 106 | * about the initial attestation key, which is |
| 107 | * stored in key_buf. |
| 108 | * \param[out] curve_type The type of the EC curve, which the key belongs |
Raef Coles | 4d6ea2f | 2019-10-15 14:30:40 +0100 | [diff] [blame] | 109 | * to according to \ref psa_ecc_curve_t |
Tamas Ban | 8f33623 | 2018-12-21 14:54:11 +0000 | [diff] [blame] | 110 | * |
| 111 | * \return Returns error code specified in \ref tfm_plat_err_t |
| 112 | */ |
| 113 | enum tfm_plat_err_t |
| 114 | tfm_plat_get_initial_attest_key(uint8_t *key_buf, |
| 115 | uint32_t size, |
| 116 | struct ecc_key_t *ecc_key, |
Raef Coles | 4d6ea2f | 2019-10-15 14:30:40 +0100 | [diff] [blame] | 117 | psa_ecc_curve_t *curve_type); |
Tamas Ban | 8f33623 | 2018-12-21 14:54:11 +0000 | [diff] [blame] | 118 | |
Tamas Ban | 24f5598 | 2019-07-17 10:51:15 +0100 | [diff] [blame] | 119 | /** |
| 120 | * \brief Get the hash of the corresponding Root of Trust Public Key for |
| 121 | * firmware authentication. |
| 122 | * |
| 123 | * \param[in] image_id The identifier of firmware image |
| 124 | * \param[out] rotpk_hash Buffer to store the key-hash in |
| 125 | * \param[in,out] rotpk_hash_size As input the size of the buffer. As output |
| 126 | * the actual key-hash length. |
| 127 | */ |
| 128 | enum tfm_plat_err_t |
| 129 | tfm_plat_get_rotpk_hash(uint8_t image_id, |
| 130 | uint8_t *rotpk_hash, |
| 131 | uint32_t *rotpk_hash_size); |
| 132 | |
Marc Moreno Berengue | 20dab39 | 2017-11-29 13:18:58 +0000 | [diff] [blame] | 133 | #ifdef __cplusplus |
| 134 | } |
| 135 | #endif |
| 136 | |
Marc Moreno Berengue | ef20272 | 2018-08-10 13:43:43 +0100 | [diff] [blame] | 137 | #endif /* __TFM_PLAT_CRYPTO_KEYS_H__ */ |