blob: 7d90bfce2842dc1095f2beb2ef5e843ed375d65d [file] [log] [blame]
laurenw-arm4fc77a72022-08-11 15:29:56 -05001/*
2 * Copyright (c) 2023, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
laurenw-arm4fc77a72022-08-11 15:29:56 -05008#include <psa/client.h>
9#include <psa_manifest/sid.h>
laurenw-arm6c4d0412023-06-13 16:40:51 -050010#include <rss_crypto_defs.h>
laurenw-arm4fc77a72022-08-11 15:29:56 -050011#include <rss_platform_api.h>
12
13psa_status_t
14rss_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
26psa_status_t
27rss_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-arm6c4d0412023-06-13 16:40:51 -050043
44psa_status_t
45rss_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}