Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 1 | /* |
Xinyu Zhang | ade2e0a | 2021-03-18 16:20:54 +0800 | [diff] [blame^] | 2 | * Copyright (c) 2018-2021, Arm Limited. All rights reserved. |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 3 | * |
| 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 Vincze | ff6da53 | 2019-11-21 00:19:50 +0100 | [diff] [blame] | 12 | #include "psa/crypto_types.h" |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 13 | |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 14 | psa_status_t |
Raef Coles | 70a02da | 2019-10-09 11:32:04 +0100 | [diff] [blame] | 15 | psa_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 Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 20 | { |
| 21 | |
| 22 | int32_t res; |
| 23 | |
| 24 | psa_invec in_vec[] = { |
Raef Coles | 70a02da | 2019-10-09 11:32:04 +0100 | [diff] [blame] | 25 | {auth_challenge, challenge_size} |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 26 | }; |
| 27 | psa_outvec out_vec[] = { |
Raef Coles | 70a02da | 2019-10-09 11:32:04 +0100 | [diff] [blame] | 28 | {token_buf, token_buf_size} |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 29 | }; |
| 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 Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 36 | if (res == (int32_t)PSA_SUCCESS) { |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 37 | *token_size = out_vec[0].len; |
| 38 | } |
| 39 | |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 40 | return res; |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 41 | } |
| 42 | |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 43 | psa_status_t |
Raef Coles | 70a02da | 2019-10-09 11:32:04 +0100 | [diff] [blame] | 44 | psa_initial_attest_get_token_size(size_t challenge_size, |
| 45 | size_t *token_size) |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 46 | { |
| 47 | psa_invec in_vec[] = { |
| 48 | {&challenge_size, sizeof(challenge_size)} |
| 49 | }; |
| 50 | psa_outvec out_vec[] = { |
Raef Coles | 70a02da | 2019-10-09 11:32:04 +0100 | [diff] [blame] | 51 | {token_size, sizeof(size_t)} |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 52 | }; |
| 53 | |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 54 | return tfm_ns_interface_dispatch( |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 55 | (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 Vincze | ff6da53 | 2019-11-21 00:19:50 +0100 | [diff] [blame] | 59 | |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 60 | psa_status_t |
Summer Qin | 0e5b2e0 | 2020-10-22 11:23:39 +0800 | [diff] [blame] | 61 | tfm_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 Vincze | ff6da53 | 2019-11-21 00:19:50 +0100 | [diff] [blame] | 65 | { |
| 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 Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 79 | return (psa_status_t) res; |
David Vincze | ff6da53 | 2019-11-21 00:19:50 +0100 | [diff] [blame] | 80 | } |