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 | /* Objects typed to subclasses of the these classes are constructed and filled in by |
| 9 | the parser as it parses test-template lines. There is not necessarily a one-to-one |
| 10 | correspondence between the template lines and either the PSA commands generated nor |
| 11 | PSA assets they manipulate. PSA assets (which persist through the test) and PSA |
| 12 | commands are therefore tracked in separate objects, but referenced here. */ |
| 13 | |
| 14 | #include <vector> |
| 15 | #include <algorithm> // for STL find() |
| 16 | |
| 17 | #include "class_forwards.hpp" |
| 18 | |
| 19 | #include "data_blocks.hpp" |
| 20 | #include "boilerplate.hpp" |
| 21 | #include "randomization.hpp" |
| 22 | #include "gibberish.hpp" |
| 23 | #include "compute.hpp" |
| 24 | #include "psa_asset.hpp" |
| 25 | #include "find_or_create_asset.hpp" |
| 26 | #include "template_line.hpp" |
| 27 | #include "tf_fuzz.hpp" |
| 28 | #include "crypto_asset.hpp" |
| 29 | #include "psa_call.hpp" |
| 30 | #include "crypto_call.hpp" |
| 31 | #include "sst_asset.hpp" |
| 32 | #include "crypto_asset.hpp" |
| 33 | |
| 34 | |
| 35 | |
| 36 | /********************************************************************************** |
| 37 | Methods of class template_line follow: |
| 38 | **********************************************************************************/ |
| 39 | |
| 40 | // Constructor, passing in the tf_fuzz object for reference to all objects: |
| 41 | template_line::template_line (tf_fuzz_info *resources) : test_state(resources) |
| 42 | { |
| 43 | set_data.file_path.assign (""); |
| 44 | assign_data_var_specified = false; |
| 45 | set_data.flags_string.assign (""); |
| 46 | random_asset = psa_asset_usage::all; |
| 47 | // if not deleting a random asset of a certain type, then search all as usual |
| 48 | target_barrier = ""; |
| 49 | set_data.file_specified = false; |
| 50 | print_data = hash_data = false; |
| 51 | call_ser_no = -1; |
| 52 | asset_2_name.assign (""); asset_3_name.assign (""); |
| 53 | is_remove = false; // will correct this in the remove case |
| 54 | } |
| 55 | |
| 56 | /********************************************************************************** |
| 57 | Class template_line methods regarding setting and getting asset-names follow: |
| 58 | **********************************************************************************/ |
| 59 | |
| 60 | // Default destructor: |
| 61 | template_line::~template_line (void) |
| 62 | { |
| 63 | // Destruct the vectors of asset names/IDs: |
| 64 | asset_info.asset_name_vector.erase (asset_info.asset_name_vector.begin(), |
| 65 | asset_info.asset_name_vector.end()); |
| 66 | asset_info.asset_id_n_vector.erase (asset_info.asset_id_n_vector.begin(), |
| 67 | asset_info.asset_id_n_vector.end()); |
| 68 | } |
| 69 | |
| 70 | // (Default constructor not used) |
| 71 | |
| 72 | /********************************************************************************** |
| 73 | End of methods of class template_line. |
| 74 | **********************************************************************************/ |
| 75 | |
| 76 | |
| 77 | /********************************************************************************** |
| 78 | Methods of class sst_template_line follow: |
| 79 | **********************************************************************************/ |
| 80 | |
| 81 | // (Currently, no need to specialize copy_template_to_call() for individual SST ops.) |
| 82 | bool sst_template_line::copy_template_to_call (psa_call *call) |
| 83 | { |
| 84 | // Copy asset info to call object for creation code: |
| 85 | call->asset_info = asset_info; |
| 86 | call->set_data = set_data; |
| 87 | call->set_data.string_specified = set_data.string_specified |
| 88 | || set_data.random_data; |
| 89 | // not really right, but more convenient to combine these two cases |
| 90 | call->assign_data_var_specified = assign_data_var_specified; |
| 91 | call->assign_data_var = assign_data_var; |
| 92 | call->random_asset = random_asset; |
| 93 | if (target_barrier == "") { // barriers are probably not used for SST, but... |
| 94 | call->target_barrier = asset_info.get_name(); |
| 95 | } else { |
| 96 | call->target_barrier = target_barrier; |
| 97 | } |
| 98 | call->set_data.flags_string.assign (set_data.flags_string); |
| 99 | call->exp_data = expect; |
| 100 | call->exp_data.pf_info_incomplete = true; |
| 101 | call->id_string = asset_name; // data = expected |
| 102 | call->print_data = print_data; |
| 103 | call->hash_data = hash_data; |
| 104 | return true; |
| 105 | } |
| 106 | |
| 107 | sst_template_line::sst_template_line (tf_fuzz_info *resources) |
| 108 | : template_line (resources) |
| 109 | { |
| 110 | asset_info.asset_type = psa_asset_type::sst; |
| 111 | } |
| 112 | |
| 113 | // Default destructor: |
| 114 | sst_template_line::~sst_template_line (void) |
| 115 | { |
| 116 | // No real clean-up needed. |
| 117 | return; // just to have something to pin a breakpoint onto |
| 118 | } |
| 119 | |
| 120 | // (Default constructor not used) |
| 121 | |
| 122 | |
| 123 | |
| 124 | /********************************************************************************** |
| 125 | End of methods of class sst_template_line. |
| 126 | **********************************************************************************/ |
| 127 | |
| 128 | |
| 129 | /********************************************************************************** |
| 130 | Methods of class key_template_line follow: |
| 131 | **********************************************************************************/ |
| 132 | |
| 133 | key_template_line::key_template_line (tf_fuzz_info *resources) |
| 134 | : template_line (resources) |
| 135 | { |
| 136 | asset_info.asset_type = psa_asset_type::key; |
| 137 | } |
| 138 | |
| 139 | bool key_template_line::copy_template_to_call (psa_call *call) |
| 140 | { |
| 141 | // Copy asset info to call object for creation code: |
| 142 | call->asset_info = asset_info; |
| 143 | call->set_data = set_data; |
| 144 | call->set_data = set_data; |
| 145 | call->policy = policy_info; |
| 146 | call->asset_2_name = asset_2_name; |
| 147 | call->asset_3_name = asset_3_name; |
| 148 | call->set_data.string_specified = set_data.string_specified |
| 149 | || set_data.random_data; |
| 150 | // not really right, but more convenient to combine these two cases |
| 151 | call->assign_data_var_specified = assign_data_var_specified; |
| 152 | call->assign_data_var = assign_data_var; |
| 153 | call->random_asset = random_asset; |
| 154 | if (target_barrier == "") { // barriers are probably not used for SST, but... |
| 155 | call->target_barrier = asset_info.get_name(); |
| 156 | } else { |
| 157 | call->target_barrier = target_barrier; |
| 158 | } |
| 159 | call->set_data.flags_string.assign (set_data.flags_string); |
| 160 | call->exp_data = expect; |
| 161 | call->exp_data.pf_info_incomplete = true; |
| 162 | call->id_string = asset_name; // data = expected |
| 163 | call->print_data = print_data; |
| 164 | call->hash_data = hash_data; |
| 165 | return true; |
| 166 | } |
| 167 | |
| 168 | // Create ID-based name: |
| 169 | string key_template_line::make_id_based_name (uint64_t id_n, string &name) |
| 170 | { |
| 171 | string result = "Key_ID_"; |
| 172 | result.append(to_string(id_n)); |
| 173 | return result; |
| 174 | } |
| 175 | |
| 176 | // Default destructor: |
| 177 | key_template_line::~key_template_line (void) |
| 178 | { |
| 179 | // No real clean-up needed. |
| 180 | return; // just to have something to pin a breakpoint onto |
| 181 | } |
| 182 | |
| 183 | // (Default constructor not used) |
| 184 | |
| 185 | |
| 186 | |
| 187 | /********************************************************************************** |
| 188 | End of methods of class key_template_line. |
| 189 | **********************************************************************************/ |
| 190 | |
| 191 | |
| 192 | /********************************************************************************** |
| 193 | Methods of class policy_template_line follow: |
| 194 | **********************************************************************************/ |
| 195 | |
| 196 | policy_template_line::policy_template_line (tf_fuzz_info *resources) |
| 197 | : template_line (resources) |
| 198 | { |
| 199 | asset_info.asset_type = psa_asset_type::policy; |
| 200 | } |
| 201 | |
| 202 | bool policy_template_line::copy_template_to_call (psa_call *call) |
| 203 | { |
| 204 | // Copy asset info to call object for creation code: |
| 205 | call->asset_info = asset_info; |
| 206 | call->set_data = set_data; |
| 207 | call->set_data = set_data; |
| 208 | call->policy = policy_info; |
| 209 | call->asset_2_name = asset_2_name; |
| 210 | call->asset_3_name = asset_3_name; |
| 211 | call->set_data.string_specified = set_data.string_specified |
| 212 | || set_data.random_data; |
| 213 | // not really right, but more convenient to combine these two cases |
| 214 | call->assign_data_var_specified = assign_data_var_specified; |
| 215 | call->assign_data_var = assign_data_var; |
| 216 | call->random_asset = random_asset; |
| 217 | if (target_barrier == "") { // barriers are probably not used for SST, but... |
| 218 | call->target_barrier = asset_info.get_name(); |
| 219 | } else { |
| 220 | call->target_barrier = target_barrier; |
| 221 | } |
| 222 | call->set_data.flags_string.assign (set_data.flags_string); |
| 223 | call->exp_data = expect; |
| 224 | call->exp_data.pf_info_incomplete = true; |
| 225 | call->id_string = asset_name; // data = expected |
| 226 | call->print_data = print_data; |
| 227 | call->hash_data = hash_data; |
| 228 | return true; |
| 229 | } |
| 230 | |
| 231 | // Create ID-based name: |
| 232 | string policy_template_line::make_id_based_name (uint64_t id_n, string &name) |
| 233 | { |
| 234 | string result = "Policy_ID_"; |
| 235 | result.append(to_string(id_n)); |
| 236 | // |
| 237 | return result; |
| 238 | } |
| 239 | |
| 240 | // Default destructor: |
| 241 | policy_template_line::~policy_template_line (void) |
| 242 | { |
| 243 | // No real clean-up needed. |
| 244 | return; // just to have something to pin a breakpoint onto |
| 245 | } |
| 246 | |
| 247 | // (Default constructor not used) |
| 248 | |
| 249 | |
| 250 | |
| 251 | /********************************************************************************** |
| 252 | End of methods of class policy_template_line. |
| 253 | **********************************************************************************/ |
| 254 | |
| 255 | |
| 256 | /********************************************************************************** |
| 257 | Methods of class security_template_line follow: |
| 258 | **********************************************************************************/ |
| 259 | |
| 260 | security_template_line::security_template_line (tf_fuzz_info *resources) |
| 261 | : template_line (resources) |
| 262 | { |
| 263 | } |
| 264 | |
| 265 | // Default destructor: |
| 266 | security_template_line::~security_template_line (void) |
| 267 | { |
| 268 | // No real clean-up needed. |
| 269 | return; // just to have something to pin a breakpoint onto |
| 270 | } |
| 271 | |
| 272 | // (Default constructor not used) |
| 273 | |
| 274 | |
| 275 | /********************************************************************************** |
| 276 | End of methods of class security_template_line. |
| 277 | **********************************************************************************/ |
| 278 | |