blob: e55c3cb1a3f7b8d9888202312767e8ed3f27e374 [file] [log] [blame]
Tamas Ban48a0eb52018-08-17 12:48:05 +01001/*
David Vincze6ec7c652025-03-07 17:46:28 +00002 * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
Tamas Ban48a0eb52018-08-17 12:48:05 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Jamie Foxcc31d402019-01-28 17:13:52 +00008#include "psa/initial_attestation.h"
Jamie Foxcc31d402019-01-28 17:13:52 +00009#include "psa/client.h"
Edison Ai870abb42019-06-21 11:14:08 +080010#include "psa_manifest/sid.h"
Shawn Shan40a0dce2021-07-09 10:13:35 +080011#include "tfm_attest_defs.h"
Kevin Peng2ed30222019-04-30 09:26:11 +080012
Raef Coles793574c2019-10-09 10:59:42 +010013psa_status_t
Raef Coles70a02da2019-10-09 11:32:04 +010014psa_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 Ban48a0eb52018-08-17 12:48:05 +010019{
Kevin Peng2ed30222019-04-30 09:26:11 +080020 psa_status_t status;
Kevin Peng9449a362019-07-29 16:05:42 +080021
Kevin Peng2ed30222019-04-30 09:26:11 +080022 psa_invec in_vec[] = {
Raef Coles70a02da2019-10-09 11:32:04 +010023 {auth_challenge, challenge_size}
Kevin Peng2ed30222019-04-30 09:26:11 +080024 };
25 psa_outvec out_vec[] = {
Raef Coles70a02da2019-10-09 11:32:04 +010026 {token_buf, token_buf_size}
Kevin Peng2ed30222019-04-30 09:26:11 +080027 };
Tamas Ban48a0eb52018-08-17 12:48:05 +010028
Shawn Shan40a0dce2021-07-09 10:13:35 +080029 status = psa_call(TFM_ATTESTATION_SERVICE_HANDLE, TFM_ATTEST_GET_TOKEN,
Kevin Peng2ed30222019-04-30 09:26:11 +080030 in_vec, IOVEC_LEN(in_vec),
31 out_vec, IOVEC_LEN(out_vec));
Tamas Ban48a0eb52018-08-17 12:48:05 +010032
Kevin Peng2ed30222019-04-30 09:26:11 +080033 if (status == PSA_SUCCESS) {
34 *token_size = out_vec[0].len;
35 }
36
Raef Coles793574c2019-10-09 10:59:42 +010037 return status;
Tamas Banb6b80562019-01-04 22:49:24 +000038}
39
Raef Coles793574c2019-10-09 10:59:42 +010040psa_status_t
Raef Coles70a02da2019-10-09 11:32:04 +010041psa_initial_attest_get_token_size(size_t challenge_size,
42 size_t *token_size)
Tamas Banb6b80562019-01-04 22:49:24 +000043{
Kevin Peng2ed30222019-04-30 09:26:11 +080044 psa_status_t status;
David Vincze6ec7c652025-03-07 17:46:28 +000045 rot_size_t challenge_size_param;
46 rot_size_t token_size_param = 0;
47
Kevin Peng2ed30222019-04-30 09:26:11 +080048 psa_invec in_vec[] = {
David Vincze6ec7c652025-03-07 17:46:28 +000049 {&challenge_size_param, sizeof(challenge_size_param)}
Kevin Peng2ed30222019-04-30 09:26:11 +080050 };
51 psa_outvec out_vec[] = {
David Vincze6ec7c652025-03-07 17:46:28 +000052 {&token_size_param, sizeof(token_size_param)}
Kevin Peng2ed30222019-04-30 09:26:11 +080053 };
Tamas Banb6b80562019-01-04 22:49:24 +000054
David Vincze6ec7c652025-03-07 17:46:28 +000055 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 Shan40a0dce2021-07-09 10:13:35 +080064 status = psa_call(TFM_ATTESTATION_SERVICE_HANDLE, TFM_ATTEST_GET_TOKEN_SIZE,
Kevin Peng2ed30222019-04-30 09:26:11 +080065 in_vec, IOVEC_LEN(in_vec),
66 out_vec, IOVEC_LEN(out_vec));
Tamas Banb6b80562019-01-04 22:49:24 +000067
David Vincze6ec7c652025-03-07 17:46:28 +000068 *token_size = token_size_param;
69
Raef Coles793574c2019-10-09 10:59:42 +010070 return status;
Tamas Ban48a0eb52018-08-17 12:48:05 +010071}