blob: b4334f0192a518e2e4f2268ca2700412e8f6badf [file] [log] [blame]
Tamas Ban48a0eb52018-08-17 12:48:05 +01001/*
Summer Qind23bbb32022-10-18 15:30:06 +08002 * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
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"
David Vinczeff6da532019-11-21 00:19:50 +010010#include "psa/crypto_types.h"
Edison Ai870abb42019-06-21 11:14:08 +080011#include "psa_manifest/sid.h"
Shawn Shan40a0dce2021-07-09 10:13:35 +080012#include "tfm_attest_defs.h"
Kevin Peng2ed30222019-04-30 09:26:11 +080013
Raef Coles793574c2019-10-09 10:59:42 +010014psa_status_t
Raef Coles70a02da2019-10-09 11:32:04 +010015psa_initial_attest_get_token(const uint8_t *auth_challenge,
16 size_t challenge_size,
17 uint8_t *token_buf,
18 size_t token_buf_size,
19 size_t *token_size)
Tamas Ban48a0eb52018-08-17 12:48:05 +010020{
Kevin Peng2ed30222019-04-30 09:26:11 +080021 psa_status_t status;
Kevin Peng9449a362019-07-29 16:05:42 +080022
Kevin Peng2ed30222019-04-30 09:26:11 +080023 psa_invec in_vec[] = {
Raef Coles70a02da2019-10-09 11:32:04 +010024 {auth_challenge, challenge_size}
Kevin Peng2ed30222019-04-30 09:26:11 +080025 };
26 psa_outvec out_vec[] = {
Raef Coles70a02da2019-10-09 11:32:04 +010027 {token_buf, token_buf_size}
Kevin Peng2ed30222019-04-30 09:26:11 +080028 };
Tamas Ban48a0eb52018-08-17 12:48:05 +010029
Shawn Shan40a0dce2021-07-09 10:13:35 +080030 status = psa_call(TFM_ATTESTATION_SERVICE_HANDLE, TFM_ATTEST_GET_TOKEN,
Kevin Peng2ed30222019-04-30 09:26:11 +080031 in_vec, IOVEC_LEN(in_vec),
32 out_vec, IOVEC_LEN(out_vec));
Tamas Ban48a0eb52018-08-17 12:48:05 +010033
Kevin Peng2ed30222019-04-30 09:26:11 +080034 if (status == PSA_SUCCESS) {
35 *token_size = out_vec[0].len;
36 }
37
Raef Coles793574c2019-10-09 10:59:42 +010038 return status;
Tamas Banb6b80562019-01-04 22:49:24 +000039}
40
Raef Coles793574c2019-10-09 10:59:42 +010041psa_status_t
Raef Coles70a02da2019-10-09 11:32:04 +010042psa_initial_attest_get_token_size(size_t challenge_size,
43 size_t *token_size)
Tamas Banb6b80562019-01-04 22:49:24 +000044{
Kevin Peng2ed30222019-04-30 09:26:11 +080045 psa_status_t status;
Kevin Peng2ed30222019-04-30 09:26:11 +080046 psa_invec in_vec[] = {
47 {&challenge_size, sizeof(challenge_size)}
48 };
49 psa_outvec out_vec[] = {
Raef Coles70a02da2019-10-09 11:32:04 +010050 {token_size, sizeof(size_t)}
Kevin Peng2ed30222019-04-30 09:26:11 +080051 };
Tamas Banb6b80562019-01-04 22:49:24 +000052
Shawn Shan40a0dce2021-07-09 10:13:35 +080053 status = psa_call(TFM_ATTESTATION_SERVICE_HANDLE, TFM_ATTEST_GET_TOKEN_SIZE,
Kevin Peng2ed30222019-04-30 09:26:11 +080054 in_vec, IOVEC_LEN(in_vec),
55 out_vec, IOVEC_LEN(out_vec));
Tamas Banb6b80562019-01-04 22:49:24 +000056
Raef Coles793574c2019-10-09 10:59:42 +010057 return status;
Tamas Ban48a0eb52018-08-17 12:48:05 +010058}