Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1 | /* |
Nik Dewally | bacae6c | 2024-07-30 16:58:14 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2024, Arm Limited. All rights reserved. |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef CRYPTO_CALL_HPP |
| 9 | #define CRYPTO_CALL_HPP |
| 10 | |
| 11 | #include <string> |
| 12 | #include <vector> |
Nik Dewally | bacae6c | 2024-07-30 16:58:14 +0100 | [diff] [blame] | 13 | #include <iosfwd> |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 14 | |
Nik Dewally | bacae6c | 2024-07-30 16:58:14 +0100 | [diff] [blame] | 15 | #include "data_blocks.hpp" |
| 16 | #include "find_or_create_asset.hpp" |
| 17 | #include "psa_asset.hpp" |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 18 | #include "psa_call.hpp" |
Nik Dewally | bacae6c | 2024-07-30 16:58:14 +0100 | [diff] [blame] | 19 | |
| 20 | class tf_fuzz_info; |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 21 | |
| 22 | template<class T> bool copy_call_to_asset_t (psa_call *call, bool create_asset_bool) |
| 23 | { |
| 24 | vector<psa_asset*>::iterator found_asset; |
| 25 | |
| 26 | found_asset = call->resolve_asset (create_asset_bool, psa_asset_usage::all); |
| 27 | // Copy over everything relevant: |
| 28 | if (call->asset_info.how_asset_found != asset_search::not_found) { |
| 29 | call->asset_info.the_asset = reinterpret_cast<T>(*found_asset); |
| 30 | /* Note: The vector is base-class, but the assets in this list |
| 31 | themselves *really are* policy_asset-type objects. */ |
| 32 | int i = call->asset_info.the_asset->set_data.n_set_vars; // save this |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 33 | call->asset_info.the_asset->set_data = call->set_data; |
| 34 | call->asset_info.the_asset->set_data.n_set_vars = call->set_data.n_set_vars = ++i; |
| 35 | call->asset_info.the_asset->policy = call->policy; |
| 36 | call->asset_info.the_asset->handle_str = call->asset_info.get_name(); |
| 37 | if (call->asset_info.how_asset_found == asset_search::created_new) { |
| 38 | call->asset_info.the_asset->asset_info.name_specified |
| 39 | = call->asset_info.name_specified; |
| 40 | call->asset_info.the_asset->asset_info.set_name (call->asset_info.get_name()); |
| 41 | call->asset_info.the_asset->asset_info.asset_ser_no |
| 42 | = call->asset_info.asset_ser_no; |
| 43 | call->asset_info.the_asset->asset_info.id_n = call->asset_info.id_n; |
| 44 | } |
| 45 | } |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | |
| 50 | using namespace std; |
| 51 | |
| 52 | class policy_call : public crypto_call |
| 53 | { |
| 54 | public: |
| 55 | // Data members: // (low value in hiding these behind setters and getters) |
| 56 | // Methods: |
| 57 | vector<psa_asset*>::iterator resolve_asset (bool create_asset_bool, |
| 58 | psa_asset_usage where); |
| 59 | void policy_fill_in_prep_code (void); |
| 60 | policy_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 61 | asset_search how_asset_found); // (constructor) |
| 62 | ~policy_call (void); |
| 63 | |
| 64 | protected: |
| 65 | // Data members: |
| 66 | // Methods: |
| 67 | // void calc_result_code (void); for *now* keep this in crypto_call:: |
| 68 | |
| 69 | private: |
| 70 | // Data members: |
| 71 | // Methods: |
| 72 | }; |
| 73 | |
| 74 | |
| 75 | class key_call : public crypto_call |
| 76 | { |
| 77 | public: |
| 78 | // Data members: // (low value in hiding these behind setters and getters) |
| 79 | // Methods: |
| 80 | vector<psa_asset*>::iterator resolve_asset (bool create_asset_bool, |
| 81 | psa_asset_usage where); |
| 82 | key_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 83 | asset_search how_asset_found); // (constructor) |
| 84 | ~key_call (void); |
| 85 | |
| 86 | protected: |
| 87 | // Data members: |
| 88 | // Methods: |
| 89 | // void calc_result_code (void); for *now* keep this in crypto_call:: |
| 90 | |
| 91 | private: |
| 92 | // Data members: |
| 93 | // Methods: |
| 94 | }; |
| 95 | |
| 96 | |
| 97 | /********************************************************************************** |
| 98 | Derived classes of class policy_call follow: |
| 99 | **********************************************************************************/ |
| 100 | |
| 101 | |
| 102 | class init_policy_call : public policy_call |
| 103 | { |
| 104 | public: |
| 105 | // Data members: |
| 106 | // Methods: |
| 107 | bool copy_call_to_asset (void); |
| 108 | void fill_in_prep_code (void); |
| 109 | void fill_in_command (void); |
| 110 | init_policy_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 111 | asset_search how_asset_found); // (constructor) |
| 112 | ~init_policy_call (void); |
| 113 | |
| 114 | |
| 115 | protected: |
| 116 | // Data members: |
| 117 | // Methods: |
| 118 | |
| 119 | private: |
| 120 | // Data members: |
| 121 | // Methods: |
| 122 | }; |
| 123 | |
| 124 | |
| 125 | class reset_policy_call : public policy_call |
| 126 | { |
| 127 | public: |
| 128 | // Data members: |
| 129 | // Methods: |
| 130 | bool copy_call_to_asset (void); |
| 131 | void fill_in_prep_code (void); |
| 132 | void fill_in_command (void); |
| 133 | reset_policy_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 134 | asset_search how_asset_found); // (constructor) |
| 135 | ~reset_policy_call (void); |
| 136 | |
| 137 | |
| 138 | protected: |
| 139 | // Data members: |
| 140 | // Methods: |
| 141 | |
| 142 | private: |
| 143 | // Data members: |
| 144 | // Methods: |
| 145 | }; |
| 146 | |
| 147 | |
| 148 | class set_policy_usage_call : public policy_call |
| 149 | { |
| 150 | public: |
| 151 | // Data members: |
| 152 | // Methods: |
| 153 | bool copy_call_to_asset (void); |
| 154 | void fill_in_prep_code (void); |
| 155 | void fill_in_command (void); |
| 156 | set_policy_usage_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 157 | asset_search how_asset_found); // (constructor) |
| 158 | ~set_policy_usage_call (void); |
| 159 | |
| 160 | |
| 161 | protected: |
| 162 | // Data members: |
| 163 | // Methods: |
| 164 | |
| 165 | private: |
| 166 | // Data members: |
| 167 | // Methods: |
| 168 | }; |
| 169 | |
| 170 | |
| 171 | /* set_policy_usage_call(), above, gives a policy particular attribute, and resets |
| 172 | all others. add_policy_usage_call(), below, ORs in an additional usage |
| 173 | attribute, to whatever is already in there. */ |
| 174 | |
| 175 | class add_policy_usage_call : public policy_call |
| 176 | { |
| 177 | public: |
| 178 | // Data members: |
| 179 | // Methods: |
| 180 | bool copy_call_to_asset (void); |
| 181 | void fill_in_prep_code (void); |
| 182 | void fill_in_command (void); |
| 183 | add_policy_usage_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 184 | asset_search how_asset_found); // (constructor) |
| 185 | ~add_policy_usage_call (void); |
| 186 | |
| 187 | |
| 188 | protected: |
| 189 | // Data members: |
| 190 | // Methods: |
| 191 | |
| 192 | private: |
| 193 | // Data members: |
| 194 | // Methods: |
| 195 | }; |
| 196 | |
| 197 | |
| 198 | class set_policy_lifetime_call : public policy_call |
| 199 | { |
| 200 | public: |
| 201 | // Data members: |
| 202 | // Methods: |
| 203 | bool copy_call_to_asset (void); |
| 204 | void fill_in_prep_code (void); |
| 205 | void fill_in_command (void); |
| 206 | set_policy_lifetime_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 207 | asset_search how_asset_found); // (constructor) |
| 208 | ~set_policy_lifetime_call (void); |
| 209 | |
| 210 | |
| 211 | protected: |
| 212 | // Data members: |
| 213 | // Methods: |
| 214 | |
| 215 | private: |
| 216 | // Data members: |
| 217 | // Methods: |
| 218 | }; |
| 219 | |
| 220 | |
| 221 | class set_policy_algorithm_call : public policy_call |
| 222 | { |
| 223 | public: |
| 224 | // Data members: |
| 225 | // Methods: |
| 226 | bool copy_call_to_asset (void); |
| 227 | void fill_in_prep_code (void); |
| 228 | void fill_in_command (void); |
| 229 | set_policy_algorithm_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 230 | asset_search how_asset_found); // (constructor) |
| 231 | ~set_policy_algorithm_call (void); |
| 232 | |
| 233 | |
| 234 | protected: |
| 235 | // Data members: |
| 236 | // Methods: |
| 237 | |
| 238 | private: |
| 239 | // Data members: |
| 240 | // Methods: |
| 241 | }; |
| 242 | |
| 243 | |
| 244 | class set_policy_size_call : public policy_call |
| 245 | { |
| 246 | public: |
| 247 | // Data members: |
| 248 | // Methods: |
| 249 | bool copy_call_to_asset (void); |
| 250 | void fill_in_prep_code (void); |
| 251 | void fill_in_command (void); |
| 252 | set_policy_size_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 253 | asset_search how_asset_found); // (constructor) |
| 254 | ~set_policy_size_call (void); |
| 255 | |
| 256 | |
| 257 | protected: |
| 258 | // Data members: |
| 259 | // Methods: |
| 260 | |
| 261 | private: |
| 262 | // Data members: |
| 263 | // Methods: |
| 264 | }; |
| 265 | |
| 266 | |
| 267 | class set_policy_type_call : public policy_call |
| 268 | { |
| 269 | public: |
| 270 | // Data members: |
| 271 | // Methods: |
| 272 | bool copy_call_to_asset (void); |
| 273 | void fill_in_prep_code (void); |
| 274 | void fill_in_command (void); |
| 275 | set_policy_type_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 276 | asset_search how_asset_found); // (constructor) |
| 277 | ~set_policy_type_call (void); |
| 278 | |
| 279 | |
| 280 | protected: |
| 281 | // Data members: |
| 282 | // Methods: |
| 283 | |
| 284 | private: |
| 285 | // Data members: |
| 286 | // Methods: |
| 287 | }; |
| 288 | |
| 289 | |
| 290 | class get_policy_lifetime_call : public policy_call |
| 291 | { |
| 292 | public: |
| 293 | // Data members: |
| 294 | // Methods: |
| 295 | bool copy_call_to_asset (void); |
| 296 | void fill_in_prep_code (void); |
| 297 | void fill_in_command (void); |
| 298 | get_policy_lifetime_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 299 | asset_search how_asset_found); // (constructor) |
| 300 | ~get_policy_lifetime_call (void); |
| 301 | |
| 302 | |
| 303 | protected: |
| 304 | // Data members: |
| 305 | // Methods: |
| 306 | |
| 307 | private: |
| 308 | // Data members: |
| 309 | // Methods: |
| 310 | }; |
| 311 | |
| 312 | |
| 313 | class get_policy_size_call : public policy_call |
| 314 | { |
| 315 | public: |
| 316 | // Data members: |
| 317 | // Methods: |
| 318 | bool copy_call_to_asset (void); |
| 319 | void fill_in_prep_code (void); |
| 320 | void fill_in_command (void); |
| 321 | get_policy_size_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 322 | asset_search how_asset_found); // (constructor) |
| 323 | ~get_policy_size_call (void); |
| 324 | |
| 325 | |
| 326 | protected: |
| 327 | // Data members: |
| 328 | // Methods: |
| 329 | |
| 330 | private: |
| 331 | // Data members: |
| 332 | // Methods: |
| 333 | }; |
| 334 | |
| 335 | |
| 336 | class get_policy_type_call : public policy_call |
| 337 | { |
| 338 | public: |
| 339 | // Data members: |
| 340 | // Methods: |
| 341 | bool copy_call_to_asset (void); |
| 342 | void fill_in_prep_code (void); |
| 343 | void fill_in_command (void); |
| 344 | get_policy_type_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 345 | asset_search how_asset_found); // (constructor) |
| 346 | ~get_policy_type_call (void); |
| 347 | |
| 348 | |
| 349 | protected: |
| 350 | // Data members: |
| 351 | // Methods: |
| 352 | |
| 353 | private: |
| 354 | // Data members: |
| 355 | // Methods: |
| 356 | }; |
| 357 | |
| 358 | |
| 359 | class get_policy_algorithm_call : public policy_call |
| 360 | { |
| 361 | public: |
| 362 | // Data members: |
| 363 | // Methods: |
| 364 | bool copy_call_to_asset (void); |
| 365 | void fill_in_prep_code (void); |
| 366 | void fill_in_command (void); |
| 367 | get_policy_algorithm_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 368 | asset_search how_asset_found); // (constructor) |
| 369 | ~get_policy_algorithm_call (void); |
| 370 | |
| 371 | |
| 372 | protected: |
| 373 | // Data members: |
| 374 | // Methods: |
| 375 | |
| 376 | private: |
| 377 | // Data members: |
| 378 | // Methods: |
| 379 | }; |
| 380 | |
| 381 | |
| 382 | class get_policy_usage_call : public policy_call |
| 383 | { |
| 384 | public: |
| 385 | // Data members: |
| 386 | // Methods: |
| 387 | bool copy_call_to_asset (void); |
| 388 | void fill_in_prep_code (void); |
| 389 | void fill_in_command (void); |
| 390 | get_policy_usage_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 391 | asset_search how_asset_found); // (constructor) |
| 392 | ~get_policy_usage_call (void); |
| 393 | |
| 394 | |
| 395 | protected: |
| 396 | // Data members: |
| 397 | // Methods: |
| 398 | |
| 399 | private: |
| 400 | // Data members: |
| 401 | // Methods: |
| 402 | }; |
| 403 | |
| 404 | |
| 405 | /* This is not actually a PSA call; it just emits code to print out, to the log, |
| 406 | information about the usage info retrieved in a get_policy_usage_call above. */ |
| 407 | class print_policy_usage_call : public policy_call |
| 408 | { |
| 409 | public: |
| 410 | // Data members: |
| 411 | // Methods: |
| 412 | bool copy_call_to_asset (void); |
| 413 | void fill_in_prep_code (void); |
| 414 | void fill_in_command (void); |
| 415 | print_policy_usage_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 416 | asset_search how_asset_found); // (constructor) |
| 417 | ~print_policy_usage_call (void); |
| 418 | |
| 419 | |
| 420 | protected: |
| 421 | // Data members: |
| 422 | // Methods: |
| 423 | |
| 424 | private: |
| 425 | // Data members: |
| 426 | // Methods: |
| 427 | }; |
| 428 | |
| 429 | |
| 430 | class get_key_policy_call : public policy_call |
| 431 | { |
| 432 | public: |
| 433 | // Data members: |
| 434 | // Methods: |
| 435 | bool copy_call_to_asset (void); |
| 436 | void fill_in_prep_code (void); |
| 437 | void fill_in_command (void); |
| 438 | get_key_policy_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 439 | asset_search how_asset_found); // (constructor) |
| 440 | ~get_key_policy_call (void); |
| 441 | |
| 442 | |
| 443 | protected: |
| 444 | // Data members: |
| 445 | // Methods: |
| 446 | |
| 447 | private: |
| 448 | // Data members: |
| 449 | // Methods: |
| 450 | }; |
| 451 | |
| 452 | |
| 453 | /********************************************************************************** |
| 454 | End of derived classes of class policy_call. |
| 455 | **********************************************************************************/ |
| 456 | |
| 457 | |
| 458 | /********************************************************************************** |
| 459 | Derived classes of class key_call follow: |
| 460 | **********************************************************************************/ |
| 461 | |
| 462 | |
| 463 | class generate_key_call : public key_call |
| 464 | { |
| 465 | public: |
| 466 | // Data members: |
| 467 | // Methods: |
Nik Dewally | abac0e5 | 2024-08-02 13:42:27 +0100 | [diff] [blame^] | 468 | bool copy_call_to_asset (void) override; |
| 469 | void fill_in_prep_code (void) override; |
| 470 | void fill_in_command (void) override; |
| 471 | bool simulate (void) override; |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 472 | generate_key_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 473 | asset_search how_asset_found); // (constructor) |
| 474 | ~generate_key_call (void); |
| 475 | |
| 476 | |
| 477 | protected: |
| 478 | // Data members: |
| 479 | // Methods: |
| 480 | |
| 481 | private: |
| 482 | // Data members: |
| 483 | // Methods: |
| 484 | }; |
| 485 | |
| 486 | |
| 487 | class create_key_call : public key_call |
| 488 | { |
| 489 | public: |
| 490 | // Data members: |
| 491 | // Methods: |
Nik Dewally | abac0e5 | 2024-08-02 13:42:27 +0100 | [diff] [blame^] | 492 | bool copy_call_to_asset (void) override; |
| 493 | void fill_in_prep_code (void) override; |
| 494 | void fill_in_command (void) override; |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 495 | create_key_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 496 | asset_search how_asset_found); // (constructor) |
| 497 | ~create_key_call (void); |
| 498 | |
| 499 | |
| 500 | protected: |
| 501 | // Data members: |
| 502 | // Methods: |
| 503 | |
| 504 | private: |
| 505 | // Data members: |
| 506 | // Methods: |
| 507 | }; |
| 508 | |
| 509 | |
| 510 | class copy_key_call : public key_call |
| 511 | { |
| 512 | public: |
| 513 | // Data members: |
| 514 | // Methods: |
| 515 | bool copy_call_to_asset (void); |
| 516 | void fill_in_prep_code (void); |
| 517 | void fill_in_command (void); |
| 518 | copy_key_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 519 | asset_search how_asset_found); // (constructor) |
| 520 | ~copy_key_call (void); |
| 521 | |
| 522 | |
| 523 | protected: |
| 524 | // Data members: |
| 525 | // Methods: |
| 526 | |
| 527 | private: |
| 528 | // Data members: |
| 529 | // Methods: |
| 530 | }; |
| 531 | |
| 532 | |
| 533 | class read_key_data_call : public key_call |
| 534 | { |
| 535 | public: |
| 536 | // Data members: |
| 537 | // Methods: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 538 | bool copy_call_to_asset (void) override; |
| 539 | void fill_in_prep_code (void) override; |
| 540 | void fill_in_command (void) override; |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 541 | read_key_data_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 542 | asset_search how_asset_found); // (constructor) |
| 543 | ~read_key_data_call (void); |
| 544 | |
| 545 | |
| 546 | protected: |
| 547 | // Data members: |
| 548 | // Methods: |
| 549 | |
| 550 | private: |
| 551 | // Data members: |
| 552 | // Methods: |
| 553 | }; |
| 554 | |
| 555 | |
| 556 | class remove_key_call : public key_call |
| 557 | { |
| 558 | public: |
| 559 | // Data members: |
| 560 | // Methods: |
Nik Dewally | 6663dde | 2024-08-09 16:12:27 +0100 | [diff] [blame] | 561 | bool copy_call_to_asset (void) override; |
| 562 | void fill_in_prep_code (void) override; |
| 563 | void fill_in_command (void) override; |
Nik Dewally | abac0e5 | 2024-08-02 13:42:27 +0100 | [diff] [blame^] | 564 | bool simulate (void) override; |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 565 | remove_key_call (tf_fuzz_info *test_state, long &asset_ser_no, |
| 566 | asset_search how_asset_found); // (constructor) |
| 567 | ~remove_key_call (void); |
| 568 | |
| 569 | |
| 570 | protected: |
| 571 | // Data members: |
| 572 | // Methods: |
| 573 | |
| 574 | private: |
| 575 | // Data members: |
| 576 | // Methods: |
| 577 | }; |
| 578 | |
| 579 | |
| 580 | /********************************************************************************** |
| 581 | End of derived classes of class key_call. |
| 582 | **********************************************************************************/ |
| 583 | |
| 584 | #endif // CRYPTO_CALL_HPP |