blob: 7fc23820645923f9c7a9760a8fc50368e3077b60 [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>
Tamas Bandc2a2862024-02-22 11:41:25 +010010#include <rse_crypto_defs.h>
11#include <rse_platform_api.h>
laurenw-arm4fc77a72022-08-11 15:29:56 -050012
13psa_status_t
Tamas Bandc2a2862024-02-22 11:41:25 +010014rse_platform_nv_counter_increment(uint32_t counter_id)
laurenw-arm4fc77a72022-08-11 15:29:56 -050015{
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 Bandc2a2862024-02-22 11:41:25 +010021 return psa_call(RSE_PLATFORM_SERVICE_HANDLE,
22 RSE_PLATFORM_API_ID_NV_INCREMENT,
laurenw-arm4fc77a72022-08-11 15:29:56 -050023 in_vec, 1, NULL, 0);
24}
25
26psa_status_t
Tamas Bandc2a2862024-02-22 11:41:25 +010027rse_platform_nv_counter_read(uint32_t counter_id,
laurenw-arm4fc77a72022-08-11 15:29:56 -050028 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 Bandc2a2862024-02-22 11:41:25 +010039 return psa_call(RSE_PLATFORM_SERVICE_HANDLE,
40 RSE_PLATFORM_API_ID_NV_READ,
laurenw-arm4fc77a72022-08-11 15:29:56 -050041 in_vec, 1, out_vec, 1);
42}
laurenw-arm6c4d0412023-06-13 16:40:51 -050043
44psa_status_t
Tamas Bandc2a2862024-02-22 11:41:25 +010045rse_platform_key_read(enum rse_key_id_builtin_t key, uint8_t *data,
laurenw-arm6c4d0412023-06-13 16:40:51 -050046 size_t data_size, size_t *data_length)
47{
48 psa_status_t status;
49
Tamas Bandc2a2862024-02-22 11:41:25 +010050 struct rse_crypto_pack_iovec iov = {
51 .function_id = RSE_CRYPTO_EXPORT_PUBLIC_KEY_SID,
laurenw-arm6c4d0412023-06-13 16:40:51 -050052 .key_id = key,
53 };
54
55 psa_invec in_vec[] = {
Tamas Bandc2a2862024-02-22 11:41:25 +010056 {.base = &iov, .len = sizeof(struct rse_crypto_pack_iovec)},
laurenw-arm6c4d0412023-06-13 16:40:51 -050057 };
58 psa_outvec out_vec[] = {
59 {.base = data, .len = data_size}
60 };
61
Tamas Bandc2a2862024-02-22 11:41:25 +010062 status = psa_call(RSE_CRYPTO_HANDLE, PSA_IPC_CALL,
laurenw-arm6c4d0412023-06-13 16:40:51 -050063 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}