blob: cf82498c5397b33856bccf2c9f27f3883f099a3b [file] [log] [blame]
Kevin Peng9449a362019-07-29 16:05:42 +08001/*
Raef Coles793574c2019-10-09 10:59:42 +01002 * Copyright (c) 2018-2020, 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
14#define IOVEC_LEN(x) (sizeof(x)/sizeof(x[0]))
15
Raef Coles793574c2019-10-09 10:59:42 +010016psa_status_t
Kevin Peng9449a362019-07-29 16:05:42 +080017psa_initial_attest_get_token(const uint8_t *challenge_obj,
18 uint32_t challenge_size,
19 uint8_t *token,
20 uint32_t *token_size)
21{
22
23 int32_t res;
24
25 psa_invec in_vec[] = {
26 {challenge_obj, challenge_size}
27 };
28 psa_outvec out_vec[] = {
29 {token, *token_size}
30 };
31
32 res = tfm_ns_interface_dispatch(
33 (veneer_fn)tfm_initial_attest_get_token_veneer,
34 (uint32_t)in_vec, IOVEC_LEN(in_vec),
35 (uint32_t)out_vec, IOVEC_LEN(out_vec));
36
Raef Coles793574c2019-10-09 10:59:42 +010037 if (res == (int32_t)PSA_SUCCESS) {
Kevin Peng9449a362019-07-29 16:05:42 +080038 *token_size = out_vec[0].len;
39 }
40
Raef Coles793574c2019-10-09 10:59:42 +010041 return res;
Kevin Peng9449a362019-07-29 16:05:42 +080042}
43
Raef Coles793574c2019-10-09 10:59:42 +010044psa_status_t
Kevin Peng9449a362019-07-29 16:05:42 +080045psa_initial_attest_get_token_size(uint32_t challenge_size,
46 uint32_t *token_size)
47{
48 psa_invec in_vec[] = {
49 {&challenge_size, sizeof(challenge_size)}
50 };
51 psa_outvec out_vec[] = {
52 {token_size, sizeof(uint32_t)}
53 };
54
Raef Coles793574c2019-10-09 10:59:42 +010055 return tfm_ns_interface_dispatch(
Kevin Peng9449a362019-07-29 16:05:42 +080056 (veneer_fn)tfm_initial_attest_get_token_size_veneer,
57 (uint32_t)in_vec, IOVEC_LEN(in_vec),
58 (uint32_t)out_vec, IOVEC_LEN(out_vec));
59}
David Vinczeff6da532019-11-21 00:19:50 +010060
Raef Coles793574c2019-10-09 10:59:42 +010061psa_status_t
David Vinczeff6da532019-11-21 00:19:50 +010062tfm_initial_attest_get_public_key(uint8_t *public_key,
63 size_t public_key_buf_size,
64 size_t *public_key_len,
65 psa_ecc_curve_t *elliptic_curve_type)
66{
67 int32_t res;
68
69 psa_outvec out_vec[] = {
70 {.base = public_key, .len = public_key_buf_size},
71 {.base = elliptic_curve_type, .len = sizeof(*elliptic_curve_type)},
72 {.base = public_key_len, .len = sizeof(*public_key_len)}
73 };
74
75 res = tfm_ns_interface_dispatch(
76 (veneer_fn)tfm_initial_attest_get_public_key_veneer,
77 (uint32_t)NULL, 0,
78 (uint32_t)out_vec, IOVEC_LEN(out_vec));
79
Raef Coles793574c2019-10-09 10:59:42 +010080 return (psa_status_t) res;
David Vinczeff6da532019-11-21 00:19:50 +010081}