laurenw-arm | 4fc77a7 | 2022-08-11 15:29:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
laurenw-arm | 4fc77a7 | 2022-08-11 15:29:56 -0500 | [diff] [blame] | 8 | #include <psa/client.h> |
| 9 | #include <psa_manifest/sid.h> |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 10 | #include <rse_crypto_defs.h> |
| 11 | #include <rse_platform_api.h> |
laurenw-arm | 4fc77a7 | 2022-08-11 15:29:56 -0500 | [diff] [blame] | 12 | |
| 13 | psa_status_t |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 14 | rse_platform_nv_counter_increment(uint32_t counter_id) |
laurenw-arm | 4fc77a7 | 2022-08-11 15:29:56 -0500 | [diff] [blame] | 15 | { |
| 16 | struct psa_invec in_vec[1]; |
| 17 | |
| 18 | in_vec[0].base = &counter_id; |
| 19 | in_vec[0].len = sizeof(counter_id); |
| 20 | |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 21 | return psa_call(RSE_PLATFORM_SERVICE_HANDLE, |
| 22 | RSE_PLATFORM_API_ID_NV_INCREMENT, |
laurenw-arm | 4fc77a7 | 2022-08-11 15:29:56 -0500 | [diff] [blame] | 23 | in_vec, 1, NULL, 0); |
| 24 | } |
| 25 | |
| 26 | psa_status_t |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 27 | rse_platform_nv_counter_read(uint32_t counter_id, |
laurenw-arm | 4fc77a7 | 2022-08-11 15:29:56 -0500 | [diff] [blame] | 28 | uint32_t size, uint8_t *val) |
| 29 | { |
| 30 | struct psa_invec in_vec[1]; |
| 31 | struct psa_outvec out_vec[1]; |
| 32 | |
| 33 | in_vec[0].base = &counter_id; |
| 34 | in_vec[0].len = sizeof(counter_id); |
| 35 | |
| 36 | out_vec[0].base = val; |
| 37 | out_vec[0].len = size; |
| 38 | |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 39 | return psa_call(RSE_PLATFORM_SERVICE_HANDLE, |
| 40 | RSE_PLATFORM_API_ID_NV_READ, |
laurenw-arm | 4fc77a7 | 2022-08-11 15:29:56 -0500 | [diff] [blame] | 41 | in_vec, 1, out_vec, 1); |
| 42 | } |
laurenw-arm | 6c4d041 | 2023-06-13 16:40:51 -0500 | [diff] [blame] | 43 | |
| 44 | psa_status_t |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 45 | rse_platform_key_read(enum rse_key_id_builtin_t key, uint8_t *data, |
laurenw-arm | 6c4d041 | 2023-06-13 16:40:51 -0500 | [diff] [blame] | 46 | size_t data_size, size_t *data_length) |
| 47 | { |
| 48 | psa_status_t status; |
| 49 | |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 50 | struct rse_crypto_pack_iovec iov = { |
| 51 | .function_id = RSE_CRYPTO_EXPORT_PUBLIC_KEY_SID, |
laurenw-arm | 6c4d041 | 2023-06-13 16:40:51 -0500 | [diff] [blame] | 52 | .key_id = key, |
| 53 | }; |
| 54 | |
| 55 | psa_invec in_vec[] = { |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 56 | {.base = &iov, .len = sizeof(struct rse_crypto_pack_iovec)}, |
laurenw-arm | 6c4d041 | 2023-06-13 16:40:51 -0500 | [diff] [blame] | 57 | }; |
| 58 | psa_outvec out_vec[] = { |
| 59 | {.base = data, .len = data_size} |
| 60 | }; |
| 61 | |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 62 | status = psa_call(RSE_CRYPTO_HANDLE, PSA_IPC_CALL, |
laurenw-arm | 6c4d041 | 2023-06-13 16:40:51 -0500 | [diff] [blame] | 63 | in_vec, IOVEC_LEN(in_vec), |
| 64 | out_vec, IOVEC_LEN(out_vec)); |
| 65 | |
| 66 | *data_length = out_vec[0].len; |
| 67 | |
| 68 | return status; |
| 69 | } |