blob: ba9e8128aad4dec2deadef1b453a754d09aef4d9 [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
88/**
89 * \brief Get the attestation key ID. It is the hash (SHA256) of the COSE_Key
90 * encoded attestation public key.
91 *
92 * \param[out] attest_key_id Pointer and length of the key id.
93 *
94 * \retval PSA_ATTEST_ERR_SUCCESS Key id calculated successfully.
95 * \retval PSA_ATTEST_ERR_GENERAL Key id calculation failed.
96
97 */
98enum psa_attest_err_t
99attest_get_initial_attestation_key_id(struct q_useful_buf_c *attest_key_id);
100
Tamas Ban28aeec32019-01-09 16:53:26 +0000101#ifdef __cplusplus
102}
103#endif
104
105#endif /* __ATTESTATION_KEY_H__ */