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> |
Leo Yan | 4226942 | 2025-01-31 17:16:34 +0000 | [diff] [blame^] | 10 | #if CRYPTO_SUPPORT |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 11 | #include <rse_crypto_defs.h> |
Leo Yan | 4226942 | 2025-01-31 17:16:34 +0000 | [diff] [blame^] | 12 | #endif |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 13 | #include <rse_platform_api.h> |
laurenw-arm | 4fc77a7 | 2022-08-11 15:29:56 -0500 | [diff] [blame] | 14 | |
| 15 | psa_status_t |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 16 | rse_platform_nv_counter_increment(uint32_t counter_id) |
laurenw-arm | 4fc77a7 | 2022-08-11 15:29:56 -0500 | [diff] [blame] | 17 | { |
| 18 | struct psa_invec in_vec[1]; |
| 19 | |
| 20 | in_vec[0].base = &counter_id; |
| 21 | in_vec[0].len = sizeof(counter_id); |
| 22 | |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 23 | return psa_call(RSE_PLATFORM_SERVICE_HANDLE, |
| 24 | RSE_PLATFORM_API_ID_NV_INCREMENT, |
laurenw-arm | 4fc77a7 | 2022-08-11 15:29:56 -0500 | [diff] [blame] | 25 | in_vec, 1, NULL, 0); |
| 26 | } |
| 27 | |
| 28 | psa_status_t |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 29 | rse_platform_nv_counter_read(uint32_t counter_id, |
laurenw-arm | 4fc77a7 | 2022-08-11 15:29:56 -0500 | [diff] [blame] | 30 | uint32_t size, uint8_t *val) |
| 31 | { |
| 32 | struct psa_invec in_vec[1]; |
| 33 | struct psa_outvec out_vec[1]; |
| 34 | |
| 35 | in_vec[0].base = &counter_id; |
| 36 | in_vec[0].len = sizeof(counter_id); |
| 37 | |
| 38 | out_vec[0].base = val; |
| 39 | out_vec[0].len = size; |
| 40 | |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 41 | return psa_call(RSE_PLATFORM_SERVICE_HANDLE, |
| 42 | RSE_PLATFORM_API_ID_NV_READ, |
laurenw-arm | 4fc77a7 | 2022-08-11 15:29:56 -0500 | [diff] [blame] | 43 | in_vec, 1, out_vec, 1); |
| 44 | } |
laurenw-arm | 6c4d041 | 2023-06-13 16:40:51 -0500 | [diff] [blame] | 45 | |
Leo Yan | 4226942 | 2025-01-31 17:16:34 +0000 | [diff] [blame^] | 46 | #if CRYPTO_SUPPORT |
laurenw-arm | 6c4d041 | 2023-06-13 16:40:51 -0500 | [diff] [blame] | 47 | psa_status_t |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 48 | 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] | 49 | size_t data_size, size_t *data_length) |
| 50 | { |
| 51 | psa_status_t status; |
| 52 | |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 53 | struct rse_crypto_pack_iovec iov = { |
| 54 | .function_id = RSE_CRYPTO_EXPORT_PUBLIC_KEY_SID, |
laurenw-arm | 6c4d041 | 2023-06-13 16:40:51 -0500 | [diff] [blame] | 55 | .key_id = key, |
| 56 | }; |
| 57 | |
| 58 | psa_invec in_vec[] = { |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 59 | {.base = &iov, .len = sizeof(struct rse_crypto_pack_iovec)}, |
laurenw-arm | 6c4d041 | 2023-06-13 16:40:51 -0500 | [diff] [blame] | 60 | }; |
| 61 | psa_outvec out_vec[] = { |
| 62 | {.base = data, .len = data_size} |
| 63 | }; |
| 64 | |
Tamas Ban | dc2a286 | 2024-02-22 11:41:25 +0100 | [diff] [blame] | 65 | status = psa_call(RSE_CRYPTO_HANDLE, PSA_IPC_CALL, |
laurenw-arm | 6c4d041 | 2023-06-13 16:40:51 -0500 | [diff] [blame] | 66 | in_vec, IOVEC_LEN(in_vec), |
| 67 | out_vec, IOVEC_LEN(out_vec)); |
| 68 | |
| 69 | *data_length = out_vec[0].len; |
| 70 | |
| 71 | return status; |
| 72 | } |
Leo Yan | 4226942 | 2025-01-31 17:16:34 +0000 | [diff] [blame^] | 73 | #endif |