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> |
laurenw-arm | 6c4d041 | 2023-06-13 16:40:51 -0500 | [diff] [blame] | 10 | #include <rss_crypto_defs.h> |
laurenw-arm | 4fc77a7 | 2022-08-11 15:29:56 -0500 | [diff] [blame] | 11 | #include <rss_platform_api.h> |
| 12 | |
| 13 | psa_status_t |
| 14 | rss_platform_nv_counter_increment(uint32_t counter_id) |
| 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 | |
| 21 | return psa_call(RSS_PLATFORM_SERVICE_HANDLE, |
| 22 | RSS_PLATFORM_API_ID_NV_INCREMENT, |
| 23 | in_vec, 1, NULL, 0); |
| 24 | } |
| 25 | |
| 26 | psa_status_t |
| 27 | rss_platform_nv_counter_read(uint32_t counter_id, |
| 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 | |
| 39 | return psa_call(RSS_PLATFORM_SERVICE_HANDLE, |
| 40 | RSS_PLATFORM_API_ID_NV_READ, |
| 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 |
| 45 | rss_platform_key_read(enum rss_key_id_builtin_t key, uint8_t *data, |
| 46 | size_t data_size, size_t *data_length) |
| 47 | { |
| 48 | psa_status_t status; |
| 49 | |
| 50 | struct rss_crypto_pack_iovec iov = { |
| 51 | .function_id = RSS_CRYPTO_EXPORT_PUBLIC_KEY_SID, |
| 52 | .key_id = key, |
| 53 | }; |
| 54 | |
| 55 | psa_invec in_vec[] = { |
| 56 | {.base = &iov, .len = sizeof(struct rss_crypto_pack_iovec)}, |
| 57 | }; |
| 58 | psa_outvec out_vec[] = { |
| 59 | {.base = data, .len = data_size} |
| 60 | }; |
| 61 | |
| 62 | status = psa_call(RSS_CRYPTO_HANDLE, PSA_IPC_CALL, |
| 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 | } |