blob: 48dbbe183fcc1bc96fcd68438b789f21eb4a9c3e [file] [log] [blame]
Kevin Peng9449a362019-07-29 16:05:42 +08001/*
Xinyu Zhangade2e0a2021-03-18 16:20:54 +08002 * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
Kevin Peng9449a362019-07-29 16:05:42 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include "psa/initial_attestation.h"
9#include "tfm_veneers.h"
10#include "tfm_ns_interface.h"
11#include "psa/client.h"
David Vinczeff6da532019-11-21 00:19:50 +010012#include "psa/crypto_types.h"
Kevin Peng9449a362019-07-29 16:05:42 +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)
Kevin Peng9449a362019-07-29 16:05:42 +080020{
21
22 int32_t res;
23
24 psa_invec in_vec[] = {
Raef Coles70a02da2019-10-09 11:32:04 +010025 {auth_challenge, challenge_size}
Kevin Peng9449a362019-07-29 16:05:42 +080026 };
27 psa_outvec out_vec[] = {
Raef Coles70a02da2019-10-09 11:32:04 +010028 {token_buf, token_buf_size}
Kevin Peng9449a362019-07-29 16:05:42 +080029 };
30
31 res = tfm_ns_interface_dispatch(
32 (veneer_fn)tfm_initial_attest_get_token_veneer,
33 (uint32_t)in_vec, IOVEC_LEN(in_vec),
34 (uint32_t)out_vec, IOVEC_LEN(out_vec));
35
Raef Coles793574c2019-10-09 10:59:42 +010036 if (res == (int32_t)PSA_SUCCESS) {
Kevin Peng9449a362019-07-29 16:05:42 +080037 *token_size = out_vec[0].len;
38 }
39
Raef Coles793574c2019-10-09 10:59:42 +010040 return res;
Kevin Peng9449a362019-07-29 16:05:42 +080041}
42
Raef Coles793574c2019-10-09 10:59:42 +010043psa_status_t
Raef Coles70a02da2019-10-09 11:32:04 +010044psa_initial_attest_get_token_size(size_t challenge_size,
45 size_t *token_size)
Kevin Peng9449a362019-07-29 16:05:42 +080046{
47 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 Peng9449a362019-07-29 16:05:42 +080052 };
53
Raef Coles793574c2019-10-09 10:59:42 +010054 return tfm_ns_interface_dispatch(
Kevin Peng9449a362019-07-29 16:05:42 +080055 (veneer_fn)tfm_initial_attest_get_token_size_veneer,
56 (uint32_t)in_vec, IOVEC_LEN(in_vec),
57 (uint32_t)out_vec, IOVEC_LEN(out_vec));
58}
David Vinczeff6da532019-11-21 00:19:50 +010059
Raef Coles793574c2019-10-09 10:59:42 +010060psa_status_t
Summer Qin0e5b2e02020-10-22 11:23:39 +080061tfm_initial_attest_get_public_key(uint8_t *public_key,
62 size_t public_key_buf_size,
63 size_t *public_key_len,
64 psa_ecc_family_t *elliptic_curve_type)
David Vinczeff6da532019-11-21 00:19:50 +010065{
66 int32_t res;
67
68 psa_outvec out_vec[] = {
69 {.base = public_key, .len = public_key_buf_size},
70 {.base = elliptic_curve_type, .len = sizeof(*elliptic_curve_type)},
71 {.base = public_key_len, .len = sizeof(*public_key_len)}
72 };
73
74 res = tfm_ns_interface_dispatch(
75 (veneer_fn)tfm_initial_attest_get_public_key_veneer,
76 (uint32_t)NULL, 0,
77 (uint32_t)out_vec, IOVEC_LEN(out_vec));
78
Raef Coles793574c2019-10-09 10:59:42 +010079 return (psa_status_t) res;
David Vinczeff6da532019-11-21 00:19:50 +010080}