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