blob: c0881fe28281b1fb5622796015cf7acb993f0531 [file] [log] [blame]
Tamas Ban28aeec32019-01-09 16:53:26 +00001/*
Tamas Bane66b2312020-01-15 11:25:24 +00002 * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
Tamas Ban28aeec32019-01-09 16:53:26 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef __ATTESTATION_KEY_H__
9#define __ATTESTATION_KEY_H__
10
David Hu10eddf62020-01-17 15:12:13 +080011#include "attestation.h"
Jamie Foxcc31d402019-01-28 17:13:52 +000012#include "psa/initial_attestation.h"
13#include "psa/crypto.h"
Tamas Bane66b2312020-01-15 11:25:24 +000014#include "q_useful_buf.h"
Tamas Ban28aeec32019-01-09 16:53:26 +000015
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20/**
Raef Colesbfe47622019-10-22 10:15:41 +010021 * \brief Register the initial attestation private key to Crypto service. Loads
22 * the public key if the key has not already been loaded.
Tamas Ban28aeec32019-01-09 16:53:26 +000023 *
Raef Colesbfe47622019-10-22 10:15:41 +010024 * \note Private key MUST be present on the device, otherwise initial
25 * attestation token cannot be signed.
Tamas Ban28aeec32019-01-09 16:53:26 +000026 *
27 * \retval PSA_ATTEST_ERR_SUCCESS Key(s) was registered.
28 * \retval PSA_ATTEST_ERR_GENERAL Key(s) could not be registered.
29 */
Raef Colesbfe47622019-10-22 10:15:41 +010030enum psa_attest_err_t
31attest_register_initial_attestation_key();
Tamas Ban6c08f9d2019-05-09 08:43:29 +010032
Tamas Ban28aeec32019-01-09 16:53:26 +000033/**
Tamas Ban6c08f9d2019-05-09 08:43:29 +010034 * \brief Unregister the initial attestation private key from Crypto service
35 * to do not occupy key slot.
Tamas Ban28aeec32019-01-09 16:53:26 +000036 *
37 * \retval PSA_ATTEST_ERR_SUCCESS Key(s) was unregistered.
38 * \retval PSA_ATTEST_ERR_GENERAL Key(s) could not be unregistered.
39 */
Raef Colesbfe47622019-10-22 10:15:41 +010040enum psa_attest_err_t
41attest_unregister_initial_attestation_key();
42
43/**
David Hu10eddf62020-01-17 15:12:13 +080044 * \brief Get the handle of the key for signing token
45 * In asymmetric key algorithm based initial attestation, it is the
46 * handle of the initial attestation private key.
47 * In symmetric key algorithm based initial attestation, it is the
48 * handle of symmetric initial attestation key.
Raef Colesbfe47622019-10-22 10:15:41 +010049 *
David Hu10eddf62020-01-17 15:12:13 +080050 * \param[out] key_handle The handle of the key for signing token.
Raef Colesbfe47622019-10-22 10:15:41 +010051 *
David Hu10eddf62020-01-17 15:12:13 +080052 * \retval PSA_ATTEST_ERR_SUCCESS Key handle was successfully returned.
53 * \retval PSA_ATTEST_ERR_GENERAL Key handle could not be returned.
Raef Colesbfe47622019-10-22 10:15:41 +010054 */
Raef Colesbfe47622019-10-22 10:15:41 +010055enum psa_attest_err_t
David Hu10eddf62020-01-17 15:12:13 +080056attest_get_signing_key_handle(psa_key_handle_t *key_handle);
Raef Colesbfe47622019-10-22 10:15:41 +010057
58/**
David Hu574f7132020-03-20 16:53:19 +080059 * \brief Get the buffer of Instance ID data
60 *
61 * \param[out] id_buf Address and length of Instance ID buffer
62 *
63 * \retval PSA_ATTEST_ERR_SUCCESS Instance ID was successfully
64 * returned.
65 * \retval PSA_ATTEST_ERR_CLAIM_UNAVAILABLE Instance ID is unavailable
66 * \retval PSA_ATTEST_ERR_GENERAL Instance ID could not be returned.
67 */
68enum psa_attest_err_t
69attest_get_instance_id(struct q_useful_buf_c *id_buf);
70
71/**
Raef Colesbfe47622019-10-22 10:15:41 +010072 * \brief Get the public key derived from the initial attestation private key.
73 *
74 * \param[out] public_key Pointer to public key buffer.
75 * \param[out] public_key_len Size of public key in bytes.
76 * \param[out] public_key_curve Type of the curve that is used in the public
77 * key.
78 *
79 * \retval PSA_ATTEST_ERR_SUCCESS Public key was successfully returned.
80 * \retval PSA_ATTEST_ERR_GENERAL Public key could not be returned.
81 */
82
83enum psa_attest_err_t
84attest_get_initial_attestation_public_key(uint8_t **public_key,
85 size_t *public_key_len,
86 psa_ecc_curve_t *public_key_curve);
Tamas Bane66b2312020-01-15 11:25:24 +000087
David Hu6d2bc652020-03-25 15:48:53 +080088#ifdef INCLUDE_COSE_KEY_ID
Tamas Bane66b2312020-01-15 11:25:24 +000089/**
David Hu6d2bc652020-03-25 15:48:53 +080090 * \brief Get the attestation key ID.
91 * In asymmetric key algorithm based Initial Attestation, it is the hash
92 * (SHA256) of the COSE_Key encoded attestation public key.
93 * In symmetric key algorithm based Initial Attestation, the key ID raw
94 * data is fetched from from device.
Tamas Bane66b2312020-01-15 11:25:24 +000095 *
96 * \param[out] attest_key_id Pointer and length of the key id.
97 *
David Hu6d2bc652020-03-25 15:48:53 +080098 * \retval PSA_ATTEST_ERR_SUCCESS Got key id successfully.
99 * \retval PSA_ATTEST_ERR_GENERAL Failed to get key id.
Tamas Bane66b2312020-01-15 11:25:24 +0000100
101 */
102enum psa_attest_err_t
103attest_get_initial_attestation_key_id(struct q_useful_buf_c *attest_key_id);
David Hu6d2bc652020-03-25 15:48:53 +0800104#else /* INCLUDE_COSE_KEY_ID */
105static inline enum psa_attest_err_t
106attest_get_initial_attestation_key_id(struct q_useful_buf_c *attest_key_id)
107{
108 (void)attest_key_id;
109
110 return PSA_ATTEST_ERR_SUCCESS;
111}
112#endif /* INCLUDE_COSE_KEY_ID */
Tamas Bane66b2312020-01-15 11:25:24 +0000113
Tamas Ban28aeec32019-01-09 16:53:26 +0000114#ifdef __cplusplus
115}
116#endif
117
118#endif /* __ATTESTATION_KEY_H__ */