blob: 5bde82fa22abf11fa936057a2b4c76ad46e2352b [file] [log] [blame]
Valerio Setti4f4ade92024-05-03 17:28:04 +02001/* psasim test client */
2
3/*
4 * Copyright The Mbed TLS Contributors
5 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
6 */
7
8#include <psa/client.h>
9#include <psa/util.h>
10#include "psa_manifest/sid.h"
11#include <stdio.h>
12#include <unistd.h>
13
14#define CLIENT_PRINT(fmt, ...) \
15 PRINT("Client: " fmt, ##__VA_ARGS__)
16
17int main()
18{
19 const char *text = "FOOBARCOOL!!";
20 char output[100] = { 0 };
21 CLIENT_PRINT("My PID: %d", getpid());
22
23 CLIENT_PRINT("PSA version: %u", psa_version(PSA_SID_SHA256_SID));
24 psa_handle_t h = psa_connect(PSA_SID_SHA256_SID, 1);
25
26 if (h < 0) {
27 CLIENT_PRINT("Couldn't connect %d", h);
28 return 1;
29 } else {
30 int type = 2;
31 CLIENT_PRINT("psa_call() w/o invec returned: %d", psa_call(h, type, NULL, 0, NULL, 0));
32 psa_invec invecs[1];
33 psa_outvec outvecs[1];
34 invecs[0].base = text;
35 invecs[0].len = sizeof(text);
36 outvecs[0].base = output;
37 outvecs[0].len = sizeof(output);
38
39 CLIENT_PRINT("invec len: %lu", invecs[0].len);
40 CLIENT_PRINT("psa_call() w/ invec returned: %d", psa_call(h, type, invecs, 1, outvecs, 1));
41 CLIENT_PRINT("Received payload len: %ld", outvecs[0].len);
42 CLIENT_PRINT("Received payload content: %s", output);
43 CLIENT_PRINT("Closing handle");
44 psa_close(h);
45 }
46
47 return 0;
48}