blob: 59b438bbb6851fab6cde82b012d7381f9c1246b0 [file] [log] [blame]
Marc Moreno Berengue20dab392017-11-29 13:18:58 +00001/*
Tamas Ban8f336232018-12-21 14:54:11 +00002 * Copyright (c) 2017-2019, 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
15#include <stdint.h>
16#include "tfm_plat_defs.h"
17
Marc Moreno Berengue20dab392017-11-29 13:18:58 +000018#ifdef __cplusplus
19extern "C" {
20#endif
21
Marc Moreno Berengue20dab392017-11-29 13:18:58 +000022/**
Tamas Ban8f336232018-12-21 14:54:11 +000023 * Elliptic curve key type identifiers according to RFC8152 (COSE encoding)
24 * https://www.iana.org/assignments/cose/cose.xhtml#elliptic-curves
25 */
26enum ecc_curve_t {
27 P_256 = 1, /* NIST P-256 also known as secp256r1 */
28 P_384 = 2, /* NIST P-384 also known as secp384r1 */
29 P_521 = 3, /* NIST P-521 also known as secp521r1 */
30 X25519 = 4, /* X25519 for use with ECDH only */
31 X448 = 5, /* X448 for use with ECDH only */
32 ED25519 = 6, /* Ed25519 for use with EdDSA only */
33 ED448 = 7, /* Ed448 for use with EdDSA only */
34};
35
36/**
37 * Structure definition to carry pointer and size information about an Elliptic
38 * curve key which is stored in a buffer(key_buf) in raw format (without
39 * encoding):
40 * - priv_key Base address of the private key in key_buf. It must be
41 * present on the device.
42 * - priv_key_size Size of the private key in bytes.
43 * - pubx_key Base address of x-coordinate of the public key in key_buf.
44 * It can be empty, because it can be recomputed based on
45 * private key.
46 * - pubx_key_size Length of x-coordinate of the public key in key_buf.
47 * It can be empty, because it can be recomputed based on
48 * private key.
49 * - puby_key Base address of y-coordinate of the public key in key_buf.
50 * It can be empty, because either it can be recomputed based
51 * on private key or some curve type works without it.
52 * - puby_key_size Length of y-coordinate of the public key in key_buf.
53 */
54struct ecc_key_t {
55 uint8_t *priv_key;
56 uint32_t priv_key_size;
57 uint8_t *pubx_key;
58 uint32_t pubx_key_size;
59 uint8_t *puby_key;
60 uint32_t puby_key_size;
61};
62
63#define ECC_P_256_KEY_SIZE (96u) /* 3 x 32 = 96 bytes priv + pub-x + pub-y */
64
Tamas Ban5db57532019-07-17 10:59:02 +010065#define ROTPK_HASH_LEN (32u) /* SHA256 */
66
67/**
68 * Structure to store the hard-coded (embedded in secure firmware) hash of ROTPK
69 * for firmware authentication.
70 *
71 * \note Just temporary solution, hard-coded key-hash values in firmware is not
72 * suited for use in production!
73 */
74struct tfm_plat_rotpk_t {
75 const uint8_t *key_hash;
76 const uint8_t hash_len;
77};
78
Tamas Ban8f336232018-12-21 14:54:11 +000079/**
Marc Moreno Berengue20dab392017-11-29 13:18:58 +000080 * \brief Gets hardware unique key for encryption
81 *
82 * \param[out] key Buf to store the key in
83 * \param[in] size Size of the buffer
84 *
Marc Moreno Berengue8e0fa7a2018-10-04 18:25:13 +010085 * \return Returns error code specified in \ref tfm_plat_err_t
Marc Moreno Berengue20dab392017-11-29 13:18:58 +000086 */
Marc Moreno Berengue9926df82018-08-10 13:45:52 +010087enum tfm_plat_err_t tfm_plat_get_crypto_huk(uint8_t *key, uint32_t size);
Marc Moreno Berengue20dab392017-11-29 13:18:58 +000088
Tamas Ban8f336232018-12-21 14:54:11 +000089/**
90 * \brief Get the initial attestation key
91 *
92 * The device MUST contain an initial attestation key, which is used to sign the
93 * token. Initial attestation service supports elliptic curve signing
94 * algorithms. Device maker can decide whether store only the private key on the
95 * device or store both (public and private) key. Public key can be recomputed
96 * based on private key. Keys must be provided in raw format, just binary data
97 * without any encoding (DER, COSE). Caller provides a buffer to copy all the
98 * available key components to there. Key components must be copied after
99 * each other to the buffer. The base address and the length of each key
100 * component must be indicating in the corresponding field of ecc_key
101 * (\ref struct ecc_key_t).
102 * Curve_type indicates to which curve belongs the key.
103 *
104 *
105 * Keys must be provided in
106 *
107 * \param[in/out] key_buf Buffer to store the initial attestation key.
108 * \param[in] size Size of the buffer.
109 * \param[out] ecc_key A structure to carry pointer and size information
110 * about the initial attestation key, which is
111 * stored in key_buf.
112 * \param[out] curve_type The type of the EC curve, which the key belongs
113 * to according to \ref ecc_curve_t
114 *
115 * \return Returns error code specified in \ref tfm_plat_err_t
116 */
117enum tfm_plat_err_t
118tfm_plat_get_initial_attest_key(uint8_t *key_buf,
119 uint32_t size,
120 struct ecc_key_t *ecc_key,
121 enum ecc_curve_t *curve_type);
122
Tamas Ban24f55982019-07-17 10:51:15 +0100123/**
124 * \brief Get the hash of the corresponding Root of Trust Public Key for
125 * firmware authentication.
126 *
127 * \param[in] image_id The identifier of firmware image
128 * \param[out] rotpk_hash Buffer to store the key-hash in
129 * \param[in,out] rotpk_hash_size As input the size of the buffer. As output
130 * the actual key-hash length.
131 */
132enum tfm_plat_err_t
133tfm_plat_get_rotpk_hash(uint8_t image_id,
134 uint8_t *rotpk_hash,
135 uint32_t *rotpk_hash_size);
136
Marc Moreno Berengue20dab392017-11-29 13:18:58 +0000137#ifdef __cplusplus
138}
139#endif
140
Marc Moreno Berengueef202722018-08-10 13:43:43 +0100141#endif /* __TFM_PLAT_CRYPTO_KEYS_H__ */