Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 1 | /* |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020, 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 | |
| 14 | #define IOVEC_LEN(x) (sizeof(x)/sizeof(x[0])) |
| 15 | |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 16 | psa_status_t |
Raef Coles | 70a02da | 2019-10-09 11:32:04 +0100 | [diff] [blame] | 17 | psa_initial_attest_get_token(const uint8_t *auth_challenge, |
| 18 | size_t challenge_size, |
| 19 | uint8_t *token_buf, |
| 20 | size_t token_buf_size, |
| 21 | size_t *token_size) |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 22 | { |
| 23 | |
| 24 | int32_t res; |
| 25 | |
| 26 | psa_invec in_vec[] = { |
Raef Coles | 70a02da | 2019-10-09 11:32:04 +0100 | [diff] [blame] | 27 | {auth_challenge, challenge_size} |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 28 | }; |
| 29 | psa_outvec out_vec[] = { |
Raef Coles | 70a02da | 2019-10-09 11:32:04 +0100 | [diff] [blame] | 30 | {token_buf, token_buf_size} |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | res = tfm_ns_interface_dispatch( |
| 34 | (veneer_fn)tfm_initial_attest_get_token_veneer, |
| 35 | (uint32_t)in_vec, IOVEC_LEN(in_vec), |
| 36 | (uint32_t)out_vec, IOVEC_LEN(out_vec)); |
| 37 | |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 38 | if (res == (int32_t)PSA_SUCCESS) { |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 39 | *token_size = out_vec[0].len; |
| 40 | } |
| 41 | |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 42 | return res; |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 43 | } |
| 44 | |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 45 | psa_status_t |
Raef Coles | 70a02da | 2019-10-09 11:32:04 +0100 | [diff] [blame] | 46 | psa_initial_attest_get_token_size(size_t challenge_size, |
| 47 | size_t *token_size) |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 48 | { |
| 49 | psa_invec in_vec[] = { |
| 50 | {&challenge_size, sizeof(challenge_size)} |
| 51 | }; |
| 52 | psa_outvec out_vec[] = { |
Raef Coles | 70a02da | 2019-10-09 11:32:04 +0100 | [diff] [blame] | 53 | {token_size, sizeof(size_t)} |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 54 | }; |
| 55 | |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 56 | return tfm_ns_interface_dispatch( |
Kevin Peng | 9449a36 | 2019-07-29 16:05:42 +0800 | [diff] [blame] | 57 | (veneer_fn)tfm_initial_attest_get_token_size_veneer, |
| 58 | (uint32_t)in_vec, IOVEC_LEN(in_vec), |
| 59 | (uint32_t)out_vec, IOVEC_LEN(out_vec)); |
| 60 | } |
David Vincze | ff6da53 | 2019-11-21 00:19:50 +0100 | [diff] [blame] | 61 | |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 62 | psa_status_t |
Summer Qin | 0e5b2e0 | 2020-10-22 11:23:39 +0800 | [diff] [blame^] | 63 | tfm_initial_attest_get_public_key(uint8_t *public_key, |
| 64 | size_t public_key_buf_size, |
| 65 | size_t *public_key_len, |
| 66 | psa_ecc_family_t *elliptic_curve_type) |
David Vincze | ff6da53 | 2019-11-21 00:19:50 +0100 | [diff] [blame] | 67 | { |
| 68 | int32_t res; |
| 69 | |
| 70 | psa_outvec out_vec[] = { |
| 71 | {.base = public_key, .len = public_key_buf_size}, |
| 72 | {.base = elliptic_curve_type, .len = sizeof(*elliptic_curve_type)}, |
| 73 | {.base = public_key_len, .len = sizeof(*public_key_len)} |
| 74 | }; |
| 75 | |
| 76 | res = tfm_ns_interface_dispatch( |
| 77 | (veneer_fn)tfm_initial_attest_get_public_key_veneer, |
| 78 | (uint32_t)NULL, 0, |
| 79 | (uint32_t)out_vec, IOVEC_LEN(out_vec)); |
| 80 | |
Raef Coles | 793574c | 2019-10-09 10:59:42 +0100 | [diff] [blame] | 81 | return (psa_status_t) res; |
David Vincze | ff6da53 | 2019-11-21 00:19:50 +0100 | [diff] [blame] | 82 | } |