blob: 44e18daa86e4bc7ca40272d66826ac40e59b26cd [file] [log] [blame]
Tamas Ban48a0eb52018-08-17 12:48:05 +01001/*
Xinyu Zhangade2e0a2021-03-18 16:20:54 +08002 * Copyright (c) 2018-2021, 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"
Antonio de Angelis05b24192019-07-04 15:28:46 +01009#include "tfm_ns_interface.h"
Jamie Foxcc31d402019-01-28 17:13:52 +000010#include "psa/client.h"
David Vinczeff6da532019-11-21 00:19:50 +010011#include "psa/crypto_types.h"
Edison Ai870abb42019-06-21 11:14:08 +080012#include "psa_manifest/sid.h"
Shawn Shan40a0dce2021-07-09 10:13:35 +080013#include "tfm_attest_defs.h"
Kevin Peng2ed30222019-04-30 09:26:11 +080014
Raef Coles793574c2019-10-09 10:59:42 +010015psa_status_t
Raef Coles70a02da2019-10-09 11:32:04 +010016psa_initial_attest_get_token(const uint8_t *auth_challenge,
17 size_t challenge_size,
18 uint8_t *token_buf,
19 size_t token_buf_size,
20 size_t *token_size)
Tamas Ban48a0eb52018-08-17 12:48:05 +010021{
Kevin Peng2ed30222019-04-30 09:26:11 +080022 psa_status_t status;
Kevin Peng9449a362019-07-29 16:05:42 +080023
Kevin Peng2ed30222019-04-30 09:26:11 +080024 psa_invec in_vec[] = {
Raef Coles70a02da2019-10-09 11:32:04 +010025 {auth_challenge, challenge_size}
Kevin Peng2ed30222019-04-30 09:26:11 +080026 };
27 psa_outvec out_vec[] = {
Raef Coles70a02da2019-10-09 11:32:04 +010028 {token_buf, token_buf_size}
Kevin Peng2ed30222019-04-30 09:26:11 +080029 };
Tamas Ban48a0eb52018-08-17 12:48:05 +010030
Shawn Shan40a0dce2021-07-09 10:13:35 +080031 status = psa_call(TFM_ATTESTATION_SERVICE_HANDLE, TFM_ATTEST_GET_TOKEN,
Kevin Peng2ed30222019-04-30 09:26:11 +080032 in_vec, IOVEC_LEN(in_vec),
33 out_vec, IOVEC_LEN(out_vec));
Tamas Ban48a0eb52018-08-17 12:48:05 +010034
Kevin Peng2ed30222019-04-30 09:26:11 +080035 if (status == PSA_SUCCESS) {
36 *token_size = out_vec[0].len;
37 }
38
Raef Coles793574c2019-10-09 10:59:42 +010039 return status;
Tamas Banb6b80562019-01-04 22:49:24 +000040}
41
Raef Coles793574c2019-10-09 10:59:42 +010042psa_status_t
Raef Coles70a02da2019-10-09 11:32:04 +010043psa_initial_attest_get_token_size(size_t challenge_size,
44 size_t *token_size)
Tamas Banb6b80562019-01-04 22:49:24 +000045{
Kevin Peng2ed30222019-04-30 09:26:11 +080046 psa_status_t status;
Kevin Peng2ed30222019-04-30 09:26:11 +080047 psa_invec in_vec[] = {
48 {&challenge_size, sizeof(challenge_size)}
49 };
50 psa_outvec out_vec[] = {
Raef Coles70a02da2019-10-09 11:32:04 +010051 {token_size, sizeof(size_t)}
Kevin Peng2ed30222019-04-30 09:26:11 +080052 };
Tamas Banb6b80562019-01-04 22:49:24 +000053
Shawn Shan40a0dce2021-07-09 10:13:35 +080054 status = psa_call(TFM_ATTESTATION_SERVICE_HANDLE, TFM_ATTEST_GET_TOKEN_SIZE,
Kevin Peng2ed30222019-04-30 09:26:11 +080055 in_vec, IOVEC_LEN(in_vec),
56 out_vec, IOVEC_LEN(out_vec));
Tamas Banb6b80562019-01-04 22:49:24 +000057
Raef Coles793574c2019-10-09 10:59:42 +010058 return status;
Tamas Ban48a0eb52018-08-17 12:48:05 +010059}