Tamas Ban | 3ae52c6 | 2022-08-31 14:50:27 +0200 | [diff] [blame] | 1 | /* |
Manish V Badarkhe | 37f9ac2 | 2023-03-12 21:34:44 +0000 | [diff] [blame] | 2 | * Copyright (c) 2022-2023, Arm Limited. All rights reserved. |
Tamas Ban | 3ae52c6 | 2022-08-31 14:50:27 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
Tamas Ban | 3ae52c6 | 2022-08-31 14:50:27 +0200 | [diff] [blame] | 8 | #include <delegated_attestation.h> |
| 9 | #include <psa/client.h> |
| 10 | #include <psa_manifest/sid.h> |
| 11 | |
Tamas Ban | 3ae52c6 | 2022-08-31 14:50:27 +0200 | [diff] [blame] | 12 | psa_status_t |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 13 | rse_delegated_attest_get_delegated_key(uint8_t ecc_curve, |
Tamas Ban | 3ae52c6 | 2022-08-31 14:50:27 +0200 | [diff] [blame] | 14 | uint32_t key_bits, |
| 15 | uint8_t *key_buf, |
| 16 | size_t key_buf_size, |
| 17 | size_t *key_size, |
| 18 | uint32_t hash_algo) |
| 19 | { |
| 20 | psa_status_t status; |
| 21 | psa_invec in_vec[] = { |
| 22 | {&ecc_curve, sizeof(ecc_curve)}, |
| 23 | {&key_bits, sizeof(key_bits)}, |
| 24 | {&hash_algo, sizeof(hash_algo)} |
| 25 | }; |
| 26 | psa_outvec out_vec[] = { |
| 27 | {key_buf, key_buf_size} |
| 28 | }; |
| 29 | |
| 30 | if (key_size == NULL) { |
| 31 | return PSA_ERROR_INVALID_ARGUMENT; |
| 32 | } |
| 33 | |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 34 | status = psa_call(RSE_DELEGATED_SERVICE_HANDLE, |
| 35 | RSE_DELEGATED_ATTEST_GET_DELEGATED_KEY, |
Tamas Ban | 3ae52c6 | 2022-08-31 14:50:27 +0200 | [diff] [blame] | 36 | in_vec, IOVEC_LEN(in_vec), |
| 37 | out_vec, IOVEC_LEN(out_vec)); |
| 38 | if (status == PSA_SUCCESS) { |
| 39 | *key_size = out_vec[0].len; |
| 40 | } |
| 41 | |
| 42 | return status; |
| 43 | } |
| 44 | |
| 45 | psa_status_t |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 46 | rse_delegated_attest_get_token(const uint8_t *dak_pub_hash, |
Tamas Ban | 3ae52c6 | 2022-08-31 14:50:27 +0200 | [diff] [blame] | 47 | size_t dak_pub_hash_size, |
| 48 | uint8_t *token_buf, |
| 49 | size_t token_buf_size, |
| 50 | size_t *token_size) |
| 51 | { |
| 52 | psa_status_t status; |
| 53 | psa_invec in_vec[] = { |
| 54 | {dak_pub_hash, dak_pub_hash_size} |
| 55 | }; |
| 56 | psa_outvec out_vec[] = { |
| 57 | {token_buf, token_buf_size} |
| 58 | }; |
| 59 | |
| 60 | if (token_size == NULL) { |
| 61 | return PSA_ERROR_INVALID_ARGUMENT; |
| 62 | } |
| 63 | |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 64 | status = psa_call(RSE_DELEGATED_SERVICE_HANDLE, |
| 65 | RSE_DELEGATED_ATTEST_GET_PLATFORM_TOKEN, |
Tamas Ban | 3ae52c6 | 2022-08-31 14:50:27 +0200 | [diff] [blame] | 66 | in_vec, IOVEC_LEN(in_vec), |
| 67 | out_vec, IOVEC_LEN(out_vec)); |
| 68 | if (status == PSA_SUCCESS) { |
| 69 | *token_size = out_vec[0].len; |
| 70 | } |
| 71 | |
| 72 | return status; |
| 73 | } |