blob: 7ee9570fc97e6f571872211430520389927930ff [file] [log] [blame]
Marc Moreno Berengue20dab392017-11-29 13:18:58 +00001/*
Tamas Banc1630532020-01-15 11:46:14 +00002 * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
Marc Moreno Berengue20dab392017-11-29 13:18:58 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Marc Moreno Berengueef202722018-08-10 13:43:43 +01008#ifndef __TFM_PLAT_CRYPTO_KEYS_H__
9#define __TFM_PLAT_CRYPTO_KEYS_H__
Marc Moreno Berengue20dab392017-11-29 13:18:58 +000010/**
11 * \note The interfaces defined in this file must be implemented for each
12 * SoC.
13 */
Marc Moreno Berengueef202722018-08-10 13:43:43 +010014
Jamie Fox104f7502019-09-25 18:56:48 +010015#include <stddef.h>
Marc Moreno Berengueef202722018-08-10 13:43:43 +010016#include <stdint.h>
17#include "tfm_plat_defs.h"
Raef Coles4d6ea2f2019-10-15 14:30:40 +010018#include "psa/crypto.h"
Marc Moreno Berengueef202722018-08-10 13:43:43 +010019
Marc Moreno Berengue20dab392017-11-29 13:18:58 +000020#ifdef __cplusplus
21extern "C" {
22#endif
23
Marc Moreno Berengue20dab392017-11-29 13:18:58 +000024/**
Tamas Ban8f336232018-12-21 14:54:11 +000025 * 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 */
42struct 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 Ban5db57532019-07-17 10:59:02 +010051#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 */
60struct tfm_plat_rotpk_t {
61 const uint8_t *key_hash;
62 const uint8_t hash_len;
63};
64
Tamas Ban8f336232018-12-21 14:54:11 +000065/**
Jamie Fox104f7502019-09-25 18:56:48 +010066 * \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 */
78enum 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 Ban8f336232018-12-21 14:54:11 +000086 * \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 Coles4d6ea2f2019-10-15 14:30:40 +0100109 * to according to \ref psa_ecc_curve_t
Tamas Ban8f336232018-12-21 14:54:11 +0000110 *
111 * \return Returns error code specified in \ref tfm_plat_err_t
112 */
113enum tfm_plat_err_t
114tfm_plat_get_initial_attest_key(uint8_t *key_buf,
115 uint32_t size,
116 struct ecc_key_t *ecc_key,
Raef Coles4d6ea2f2019-10-15 14:30:40 +0100117 psa_ecc_curve_t *curve_type);
Tamas Ban8f336232018-12-21 14:54:11 +0000118
Tamas Ban24f55982019-07-17 10:51:15 +0100119/**
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 */
128enum tfm_plat_err_t
129tfm_plat_get_rotpk_hash(uint8_t image_id,
130 uint8_t *rotpk_hash,
131 uint32_t *rotpk_hash_size);
132
Marc Moreno Berengue20dab392017-11-29 13:18:58 +0000133#ifdef __cplusplus
134}
135#endif
136
Marc Moreno Berengueef202722018-08-10 13:43:43 +0100137#endif /* __TFM_PLAT_CRYPTO_KEYS_H__ */