Tamas Ban | 48a0eb5 | 2018-08-17 12:48:05 +0100 | [diff] [blame] | 1 | /* |
David Vincze | 6ec7c65 | 2025-03-07 17:46:28 +0000 | [diff] [blame] | 2 | * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors |
Tamas Ban | 48a0eb5 | 2018-08-17 12:48:05 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 8 | #include "psa/initial_attestation.h" |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 9 | #include "psa/client.h" |
Edison Ai | 870abb4 | 2019-06-21 11:14:08 +0800 | [diff] [blame] | 10 | #include "psa_manifest/sid.h" |
Shawn Shan | 40a0dce | 2021-07-09 10:13:35 +0800 | [diff] [blame] | 11 | #include "tfm_attest_defs.h" |
Kevin Peng | 2ed3022 | 2019-04-30 09:26:11 +0800 | [diff] [blame] | 12 | |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 13 | psa_status_t |
Raef Coles | 70a02da | 2019-10-09 11:32:04 +0100 | [diff] [blame] | 14 | psa_initial_attest_get_token(const uint8_t *auth_challenge, |
| 15 | size_t challenge_size, |
| 16 | uint8_t *token_buf, |
| 17 | size_t token_buf_size, |
| 18 | size_t *token_size) |
Tamas Ban | 48a0eb5 | 2018-08-17 12:48:05 +0100 | [diff] [blame] | 19 | { |
Kevin Peng | 2ed3022 | 2019-04-30 09:26:11 +0800 | [diff] [blame] | 20 | psa_status_t status; |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 21 | |
Kevin Peng | 2ed3022 | 2019-04-30 09:26:11 +0800 | [diff] [blame] | 22 | psa_invec in_vec[] = { |
Raef Coles | 70a02da | 2019-10-09 11:32:04 +0100 | [diff] [blame] | 23 | {auth_challenge, challenge_size} |
Kevin Peng | 2ed3022 | 2019-04-30 09:26:11 +0800 | [diff] [blame] | 24 | }; |
| 25 | psa_outvec out_vec[] = { |
Raef Coles | 70a02da | 2019-10-09 11:32:04 +0100 | [diff] [blame] | 26 | {token_buf, token_buf_size} |
Kevin Peng | 2ed3022 | 2019-04-30 09:26:11 +0800 | [diff] [blame] | 27 | }; |
Tamas Ban | 48a0eb5 | 2018-08-17 12:48:05 +0100 | [diff] [blame] | 28 | |
Shawn Shan | 40a0dce | 2021-07-09 10:13:35 +0800 | [diff] [blame] | 29 | status = psa_call(TFM_ATTESTATION_SERVICE_HANDLE, TFM_ATTEST_GET_TOKEN, |
Kevin Peng | 2ed3022 | 2019-04-30 09:26:11 +0800 | [diff] [blame] | 30 | in_vec, IOVEC_LEN(in_vec), |
| 31 | out_vec, IOVEC_LEN(out_vec)); |
Tamas Ban | 48a0eb5 | 2018-08-17 12:48:05 +0100 | [diff] [blame] | 32 | |
Kevin Peng | 2ed3022 | 2019-04-30 09:26:11 +0800 | [diff] [blame] | 33 | if (status == PSA_SUCCESS) { |
| 34 | *token_size = out_vec[0].len; |
| 35 | } |
| 36 | |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 37 | return status; |
Tamas Ban | b6b8056 | 2019-01-04 22:49:24 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 40 | psa_status_t |
Raef Coles | 70a02da | 2019-10-09 11:32:04 +0100 | [diff] [blame] | 41 | psa_initial_attest_get_token_size(size_t challenge_size, |
| 42 | size_t *token_size) |
Tamas Ban | b6b8056 | 2019-01-04 22:49:24 +0000 | [diff] [blame] | 43 | { |
Kevin Peng | 2ed3022 | 2019-04-30 09:26:11 +0800 | [diff] [blame] | 44 | psa_status_t status; |
David Vincze | 6ec7c65 | 2025-03-07 17:46:28 +0000 | [diff] [blame] | 45 | rot_size_t challenge_size_param; |
| 46 | rot_size_t token_size_param = 0; |
| 47 | |
Kevin Peng | 2ed3022 | 2019-04-30 09:26:11 +0800 | [diff] [blame] | 48 | psa_invec in_vec[] = { |
David Vincze | 6ec7c65 | 2025-03-07 17:46:28 +0000 | [diff] [blame] | 49 | {&challenge_size_param, sizeof(challenge_size_param)} |
Kevin Peng | 2ed3022 | 2019-04-30 09:26:11 +0800 | [diff] [blame] | 50 | }; |
| 51 | psa_outvec out_vec[] = { |
David Vincze | 6ec7c65 | 2025-03-07 17:46:28 +0000 | [diff] [blame] | 52 | {&token_size_param, sizeof(token_size_param)} |
Kevin Peng | 2ed3022 | 2019-04-30 09:26:11 +0800 | [diff] [blame] | 53 | }; |
Tamas Ban | b6b8056 | 2019-01-04 22:49:24 +0000 | [diff] [blame] | 54 | |
David Vincze | 6ec7c65 | 2025-03-07 17:46:28 +0000 | [diff] [blame] | 55 | if (challenge_size > ROT_SIZE_MAX) { |
| 56 | return PSA_ERROR_INVALID_ARGUMENT; |
| 57 | } |
| 58 | challenge_size_param = (rot_size_t)challenge_size; |
| 59 | |
| 60 | if (token_size == NULL) { |
| 61 | return PSA_ERROR_INVALID_ARGUMENT; |
| 62 | } |
| 63 | |
Shawn Shan | 40a0dce | 2021-07-09 10:13:35 +0800 | [diff] [blame] | 64 | status = psa_call(TFM_ATTESTATION_SERVICE_HANDLE, TFM_ATTEST_GET_TOKEN_SIZE, |
Kevin Peng | 2ed3022 | 2019-04-30 09:26:11 +0800 | [diff] [blame] | 65 | in_vec, IOVEC_LEN(in_vec), |
| 66 | out_vec, IOVEC_LEN(out_vec)); |
Tamas Ban | b6b8056 | 2019-01-04 22:49:24 +0000 | [diff] [blame] | 67 | |
David Vincze | 6ec7c65 | 2025-03-07 17:46:28 +0000 | [diff] [blame] | 68 | *token_size = token_size_param; |
| 69 | |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 70 | return status; |
Tamas Ban | 48a0eb5 | 2018-08-17 12:48:05 +0100 | [diff] [blame] | 71 | } |