Tamas Ban | 28aeec3 | 2019-01-09 16:53:26 +0000 | [diff] [blame] | 1 | /* |
Tamas Ban | e66b231 | 2020-01-15 11:25:24 +0000 | [diff] [blame] | 2 | * Copyright (c) 2019-2020, Arm Limited. All rights reserved. |
Tamas Ban | 28aeec3 | 2019-01-09 16:53:26 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
Tamas Ban | c3c0849 | 2020-08-27 10:15:42 +0100 | [diff] [blame] | 8 | #ifndef __ATTEST_KEY_H__ |
| 9 | #define __ATTEST_KEY_H__ |
Tamas Ban | 28aeec3 | 2019-01-09 16:53:26 +0000 | [diff] [blame] | 10 | |
Tamas Ban | c3c0849 | 2020-08-27 10:15:42 +0100 | [diff] [blame] | 11 | #include "attest.h" |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 12 | #include "psa/initial_attestation.h" |
| 13 | #include "psa/crypto.h" |
Tamas Ban | e66b231 | 2020-01-15 11:25:24 +0000 | [diff] [blame] | 14 | #include "q_useful_buf.h" |
Tamas Ban | 28aeec3 | 2019-01-09 16:53:26 +0000 | [diff] [blame] | 15 | |
| 16 | #ifdef __cplusplus |
| 17 | extern "C" { |
| 18 | #endif |
| 19 | |
| 20 | /** |
Raef Coles | bfe4762 | 2019-10-22 10:15:41 +0100 | [diff] [blame] | 21 | * \brief Register the initial attestation private key to Crypto service. Loads |
| 22 | * the public key if the key has not already been loaded. |
Tamas Ban | 28aeec3 | 2019-01-09 16:53:26 +0000 | [diff] [blame] | 23 | * |
Raef Coles | bfe4762 | 2019-10-22 10:15:41 +0100 | [diff] [blame] | 24 | * \note Private key MUST be present on the device, otherwise initial |
| 25 | * attestation token cannot be signed. |
Tamas Ban | 28aeec3 | 2019-01-09 16:53:26 +0000 | [diff] [blame] | 26 | * |
| 27 | * \retval PSA_ATTEST_ERR_SUCCESS Key(s) was registered. |
| 28 | * \retval PSA_ATTEST_ERR_GENERAL Key(s) could not be registered. |
| 29 | */ |
Raef Coles | bfe4762 | 2019-10-22 10:15:41 +0100 | [diff] [blame] | 30 | enum psa_attest_err_t |
| 31 | attest_register_initial_attestation_key(); |
Tamas Ban | 6c08f9d | 2019-05-09 08:43:29 +0100 | [diff] [blame] | 32 | |
Tamas Ban | 28aeec3 | 2019-01-09 16:53:26 +0000 | [diff] [blame] | 33 | /** |
Tamas Ban | 6c08f9d | 2019-05-09 08:43:29 +0100 | [diff] [blame] | 34 | * \brief Unregister the initial attestation private key from Crypto service |
| 35 | * to do not occupy key slot. |
Tamas Ban | 28aeec3 | 2019-01-09 16:53:26 +0000 | [diff] [blame] | 36 | * |
| 37 | * \retval PSA_ATTEST_ERR_SUCCESS Key(s) was unregistered. |
| 38 | * \retval PSA_ATTEST_ERR_GENERAL Key(s) could not be unregistered. |
| 39 | */ |
Raef Coles | bfe4762 | 2019-10-22 10:15:41 +0100 | [diff] [blame] | 40 | enum psa_attest_err_t |
| 41 | attest_unregister_initial_attestation_key(); |
| 42 | |
| 43 | /** |
David Hu | 10eddf6 | 2020-01-17 15:12:13 +0800 | [diff] [blame] | 44 | * \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 Coles | bfe4762 | 2019-10-22 10:15:41 +0100 | [diff] [blame] | 49 | * |
David Hu | 10eddf6 | 2020-01-17 15:12:13 +0800 | [diff] [blame] | 50 | * \param[out] key_handle The handle of the key for signing token. |
Raef Coles | bfe4762 | 2019-10-22 10:15:41 +0100 | [diff] [blame] | 51 | * |
David Hu | 10eddf6 | 2020-01-17 15:12:13 +0800 | [diff] [blame] | 52 | * \retval PSA_ATTEST_ERR_SUCCESS Key handle was successfully returned. |
| 53 | * \retval PSA_ATTEST_ERR_GENERAL Key handle could not be returned. |
Raef Coles | bfe4762 | 2019-10-22 10:15:41 +0100 | [diff] [blame] | 54 | */ |
Raef Coles | bfe4762 | 2019-10-22 10:15:41 +0100 | [diff] [blame] | 55 | enum psa_attest_err_t |
David Hu | 10eddf6 | 2020-01-17 15:12:13 +0800 | [diff] [blame] | 56 | attest_get_signing_key_handle(psa_key_handle_t *key_handle); |
Raef Coles | bfe4762 | 2019-10-22 10:15:41 +0100 | [diff] [blame] | 57 | |
| 58 | /** |
David Hu | 574f713 | 2020-03-20 16:53:19 +0800 | [diff] [blame] | 59 | * \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 | */ |
| 68 | enum psa_attest_err_t |
| 69 | attest_get_instance_id(struct q_useful_buf_c *id_buf); |
| 70 | |
| 71 | /** |
Raef Coles | bfe4762 | 2019-10-22 10:15:41 +0100 | [diff] [blame] | 72 | * \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 | |
| 83 | enum psa_attest_err_t |
| 84 | attest_get_initial_attestation_public_key(uint8_t **public_key, |
| 85 | size_t *public_key_len, |
| 86 | psa_ecc_curve_t *public_key_curve); |
Tamas Ban | e66b231 | 2020-01-15 11:25:24 +0000 | [diff] [blame] | 87 | |
David Hu | 6d2bc65 | 2020-03-25 15:48:53 +0800 | [diff] [blame] | 88 | #ifdef INCLUDE_COSE_KEY_ID |
Tamas Ban | e66b231 | 2020-01-15 11:25:24 +0000 | [diff] [blame] | 89 | /** |
David Hu | 6d2bc65 | 2020-03-25 15:48:53 +0800 | [diff] [blame] | 90 | * \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 Ban | e66b231 | 2020-01-15 11:25:24 +0000 | [diff] [blame] | 95 | * |
| 96 | * \param[out] attest_key_id Pointer and length of the key id. |
| 97 | * |
David Hu | 6d2bc65 | 2020-03-25 15:48:53 +0800 | [diff] [blame] | 98 | * \retval PSA_ATTEST_ERR_SUCCESS Got key id successfully. |
| 99 | * \retval PSA_ATTEST_ERR_GENERAL Failed to get key id. |
Tamas Ban | e66b231 | 2020-01-15 11:25:24 +0000 | [diff] [blame] | 100 | |
| 101 | */ |
| 102 | enum psa_attest_err_t |
| 103 | attest_get_initial_attestation_key_id(struct q_useful_buf_c *attest_key_id); |
David Hu | 6d2bc65 | 2020-03-25 15:48:53 +0800 | [diff] [blame] | 104 | #else /* INCLUDE_COSE_KEY_ID */ |
| 105 | static inline enum psa_attest_err_t |
| 106 | attest_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 Ban | e66b231 | 2020-01-15 11:25:24 +0000 | [diff] [blame] | 113 | |
Tamas Ban | 28aeec3 | 2019-01-09 16:53:26 +0000 | [diff] [blame] | 114 | #ifdef __cplusplus |
| 115 | } |
| 116 | #endif |
| 117 | |
Tamas Ban | c3c0849 | 2020-08-27 10:15:42 +0100 | [diff] [blame] | 118 | #endif /* __ATTEST_KEY_H__ */ |