blob: 4aa8bda144eb5a9f06c3fd3f84ca70952f81a060 [file] [log] [blame]
Karl Zhang3de5ab12021-05-31 11:45:48 +08001/*
Nik Dewallybacae6c2024-07-30 16:58:14 +01002 * Copyright (c) 2019-2024, Arm Limited. All rights reserved.
Karl Zhang3de5ab12021-05-31 11:45:48 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef PSA_CALL_HPP
9#define PSA_CALL_HPP
10
11#include <string>
Nik Dewallybacae6c2024-07-30 16:58:14 +010012#include <iosfwd>
13#include <vector>
Karl Zhang3de5ab12021-05-31 11:45:48 +080014
Nik Dewallybacae6c2024-07-30 16:58:14 +010015#include "data_blocks.hpp"
Karl Zhang3de5ab12021-05-31 11:45:48 +080016
Nik Dewallybacae6c2024-07-30 16:58:14 +010017class psa_asset;
18enum class psa_asset_usage;
19class tf_fuzz_info;
Karl Zhang3de5ab12021-05-31 11:45:48 +080020
21using namespace std;
22
23class psa_call
24{
25public:
26 /* Data members -- not all PSA calls have/need these, but they need to be acces-
27 sible polymorphically via a psa_call iterator: */
28 string call_description; // description of the call, just for tracing
29 expect_info exp_data; // everything about expected results
30 set_data_info set_data; // everything about setting PSA-asset-data values
31 asset_name_id_info asset_info; // everything about the asset(s) for this line
32 key_policy_info policy; // (specific to crypto, but have to put this here)
33 string asset_2_name; // if there's a 2nd asset, then this is its name
34 string asset_3_name; // if there's a 3rd asset, then this is its name
35 psa_asset_usage random_asset;
36 /* if asked to use some random asset from active or deleted, this says
37 which. psa_asset_usage::all if not using this feature. */
38 bool assign_data_var_specified; // asset data to/from named variable
39 string assign_data_var; // name of variable to dump (assign) data into
40 // Expected-result info:
41 bool print_data; // true to print asset data to test log
42 bool hash_data; // true to hash data for later comparison
43 string id_string; // not all PSA calls involve an ID, but a diverse set do
44 long call_ser_no; // unique serial# for this psa_call (see note in tf_fuzz.hpp)
45 tf_fuzz_info *test_state; // the big blob with pointers to everything going on
46 string barrier;
47 /* "barrier" is used for template-line operations that resolve a series of
48 PSA calls. In particular, with respect to the fact that TF-Fuzz strives
49 to randomize these multiple calls where possible, meaning interspersing
50 them among other, earlier commands. However, for example, calls to set
51 the aspects of a policy can't be pushed too far back, such as in among
52 calls setting that same policy for a previous operation! "barrier" is
53 either "", in which case this call does not care whether you place calls
54 before it, or it contains the name of an asset that, calls related to
55 which must be placed *after* this call. */
56 string target_barrier;
57 /* asset to tell the psa_call objects to set and search barrier to when
58 re-ordering PSA calls. For key policies, this is not necessarily the
59 nominal asset of that call. For a policy call, it is that policy asset,
60 so that later re-settings of the same policy don't pollute the current
61 setting of that policy. However, for key sets and reads, it is not the
62 key asset, but its policy. */
63 // Methods:
64 virtual vector<psa_asset*>::iterator resolve_asset (bool create_asset_bool,
65 psa_asset_usage where) = 0;
66 virtual bool copy_call_to_asset (void) = 0;
67 virtual bool copy_asset_to_call (void) = 0;
68 virtual void fill_in_prep_code (void) = 0;
69 virtual void fill_in_command (void) = 0;
70 void write_out_prep_code (ofstream &test_file);
71 void write_out_command (ofstream &test_file);
72 void write_out_check_code (ofstream &test_file);
73 psa_call (tf_fuzz_info *test_state, long &asset_ser_no,
74 asset_search how_asset_found); // (constructor)
75 ~psa_call (void);
76
77protected:
78 // Data members:
79 string prep_code; // declarations and such prior to all of the calls
80 string call_code; // for the call itself
81 string check_code; // for the code to check success of the call
82 static long unique_id_counter; // counts off unique IDs for assets
83 // Methods:
84 virtual void calc_result_code (void) = 0;
85
86private:
87 // Data members:
88 // Methods:
89};
90
91
92class sst_call : public psa_call
93{
94public:
95 // Data members: // (low value in hiding these behind setters and getters)
96 // Methods:
97 vector<psa_asset*>::iterator resolve_asset (bool create_asset_bool,
98 psa_asset_usage where);
99 sst_call (tf_fuzz_info *test_state, long &asset_ser_no,
100 asset_search how_asset_found); // (constructor)
101 ~sst_call (void);
102
103protected:
104 // Data members:
105 // Methods:
106 void calc_result_code (void);
107
108private:
109 // Data members:
110 // Methods:
111};
112
113class crypto_call : public psa_call
114{
115public:
116 // Data members: // (low value in hiding these behind setters and getters)
117 // Methods:
118 bool copy_asset_to_call (void);
119 crypto_call (tf_fuzz_info *test_state, long &asset_ser_no,
120 asset_search how_asset_found); // (constructor)
121 ~crypto_call (void);
122
123protected:
124 // Data members:
125 // Methods:
126 void calc_result_code (void);
127 // for now, the method-overide buck stops here, but that'll probably change
128
129private:
130 // Data members:
131 // Methods:
132};
133
134class security_call : public psa_call
135 /* Strictly speaking, these don't really correspond to PSA calls, so it's a little
136 iffy to subclass them from psa_call. However, the calling patterns work out
137 right. */
138{
139public:
140 // Data members: // (low value in hiding these behind setters and getters)
141 // Methods:
142 vector<psa_asset*>::iterator resolve_asset (bool create_asset_bool,
143 psa_asset_usage where);
144 security_call (tf_fuzz_info *test_state, long &asset_ser_no,
145 asset_search how_asset_found); // (constructor)
146 ~security_call (void);
147
148protected:
149 // Data members:
150 // Methods:
151 void calc_result_code (void);
152 // Should never be invoked, since security calls generate no PSA calls.
153
154private:
155 // Data members:
156 // Methods:
157};
158
159#endif // PSA_CALL_HPP