TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tfm_secure_client_2.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
10 #include "psa/crypto.h"
11 
12 #ifdef TFM_PSA_API
13 #include "psa/service.h"
15 #else
16 #include "psa/client.h"
17 #endif
18 
19 #ifdef TFM_PARTITION_CRYPTO
20 
28 static psa_status_t secure_client_2_test_crypto_access_ctrl(const void *arg,
29  size_t arg_len)
30 {
31  psa_key_handle_t key_handle;
32 
33  if (arg_len != sizeof(key_handle)) {
35  }
36 
37  key_handle = *((psa_key_handle_t *)arg);
38 
39  /* Attempt to destroy the key handle */
40  return psa_destroy_key(key_handle);
41 }
42 #endif /* TFM_PARTITION_CRYPTO */
43 
44 #ifdef TFM_PARTITION_INTERNAL_TRUSTED_STORAGE
45 
53 static psa_status_t secure_client_2_test_its_access_ctrl(const void *arg,
54  size_t arg_len)
55 {
57  size_t p_data_length;
58  uint8_t data[1];
59 
60  if (arg_len != sizeof(uid)) {
62  }
63 
64  uid = *((psa_storage_uid_t *)arg);
65 
66  /* Attempt to get one byte from the UID and return the resulting status */
67  return psa_its_get(uid, 0, sizeof(data), data, &p_data_length);
68 }
69 #endif /* TFM_PARTITION_INTERNAL_TRUSTED_STORAGE */
70 
81 static psa_status_t secure_client_2_dispatch(int32_t id, const void *arg,
82  size_t arg_len)
83 {
84  switch (id) {
85 #ifdef TFM_PARTITION_INTERNAL_TRUSTED_STORAGE
87  return secure_client_2_test_its_access_ctrl(arg, arg_len);
88 #endif
89 #ifdef TFM_PARTITION_CRYPTO
91  return secure_client_2_test_crypto_access_ctrl(arg, arg_len);
92 #endif
93  default:
95  }
96 }
97 
98 #ifdef TFM_PSA_API
99 #define SECURE_CLIENT_2_MAX_ARG_LEN 8U
100 
101 void tfm_secure_client_2_init(void)
102 {
103  psa_msg_t msg;
104  size_t len;
105  char arg[SECURE_CLIENT_2_MAX_ARG_LEN] __attribute__((__aligned__(8)));
106 
107  while (1) {
110  continue;
111  }
112  switch (msg.type) {
113  case PSA_IPC_CONNECT:
114  case PSA_IPC_DISCONNECT:
116  break;
117  default:
118  len = psa_read(msg.handle, 0, arg, SECURE_CLIENT_2_MAX_ARG_LEN);
119  psa_reply(msg.handle, secure_client_2_dispatch(msg.type, arg, len));
120  break;
121  }
122  }
123 }
124 #else /* TFM_PSA_API */
126 {
127  return PSA_SUCCESS;
128 }
129 
131  psa_outvec *out_vec, size_t out_len)
132 {
133  int32_t id;
134 
135  (void)out_vec;
136 
137  if (in_len != 2 || out_len != 0 || in_vec[0].len != sizeof(id)) {
139  }
140 
141  id = *((int32_t *)in_vec[0].base);
142 
143  return secure_client_2_dispatch(id, in_vec[1].base, in_vec[1].len);
144 }
145 #endif /* TFM_PSA_API */
#define PSA_BLOCK
Definition: service.h:31
int32_t type
Definition: service.h:56
#define PSA_SUCCESS
Definition: crypto_values.h:35
Platform Security Architecture cryptography module.
psa_status_t tfm_secure_client_2_call(psa_invec *in_vec, size_t in_len, psa_outvec *out_vec, size_t out_len)
psa_status_t psa_its_get(psa_storage_uid_t uid, size_t data_offset, size_t data_size, void *p_data, size_t *p_data_length)
Retrieve data associated with a provided UID.
size_t psa_read(psa_handle_t msg_handle, uint32_t invec_idx, void *buffer, size_t num_bytes)
Read a message parameter or part of a message parameter from a client input vector.
Definition: psa_service.c:40
psa_handle_t handle
Definition: service.h:61
#define TFM_SECURE_CLIENT_2_SIGNAL
#define PSA_IPC_DISCONNECT
Definition: service.h:47
#define PSA_ERROR_PROGRAMMER_ERROR
Definition: error.h:32
psa_status_t tfm_secure_client_2_init(void)
_unsigned_integral_type_ psa_key_handle_t
Key handle.
Definition: crypto.h:35
#define TFM_SECURE_CLIENT_2_ID_CRYPTO_ACCESS_CTRL
void psa_reply(psa_handle_t msg_handle, psa_status_t status)
Complete handling of a specific message and unblock the client.
Definition: psa_service.c:67
psa_signal_t psa_wait(psa_signal_t signal_mask, uint32_t timeout)
Return the Secure Partition interrupt signals that have been asserted from a subset of signals provid...
Definition: psa_service.c:15
uint64_t psa_storage_uid_t
#define psa_destroy_key
Definition: crypto_spe.h:59
#define PSA_IPC_CONNECT
Definition: service.h:45
#define TFM_SECURE_CLIENT_2_ID_ITS_ACCESS_CTRL
psa_status_t psa_get(psa_signal_t signal, psa_msg_t *msg)
Retrieve the message which corresponds to a given RoT Service signal and remove the message from the ...
Definition: psa_service.c:24
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:43