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 | |
Nik Dewally | bacae6c | 2024-07-30 16:58:14 +0100 | [diff] [blame^] | 8 | #include <string> |
| 9 | #include <vector> |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 10 | |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 11 | #include "data_blocks.hpp" |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 12 | #include "find_or_create_asset.hpp" |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 13 | #include "psa_call.hpp" |
| 14 | #include "security_call.hpp" |
Nik Dewally | bacae6c | 2024-07-30 16:58:14 +0100 | [diff] [blame^] | 15 | |
| 16 | class tf_fuzz_info; |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 17 | |
| 18 | |
| 19 | |
| 20 | /********************************************************************************** |
| 21 | Methods of class hash_call follow: |
| 22 | **********************************************************************************/ |
| 23 | |
| 24 | hash_call::hash_call (tf_fuzz_info *test_state, // (constructor) |
| 25 | long &call_ser_no, |
| 26 | asset_search how_asset_found) |
| 27 | : security_call(test_state, call_ser_no, how_asset_found) |
| 28 | { |
| 29 | call_description = "hash call"; |
| 30 | } |
| 31 | hash_call::~hash_call (void) |
| 32 | { |
| 33 | // Nothing further to delete. |
| 34 | return; // just to have something to pin a breakpoint onto |
| 35 | } |
| 36 | |
| 37 | bool hash_call::copy_call_to_asset (void) |
| 38 | { |
| 39 | // The assets are not directly involved in this call. |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | bool hash_call::copy_asset_to_call (void) |
| 44 | { |
| 45 | // The assets are not directly involved in this call. |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | /* Note: These functions are overridden in all subclasses, but they still need to be |
| 50 | defined, or the linker gives the error "undefined reference to `vtable... */ |
| 51 | void hash_call::fill_in_prep_code (void) |
| 52 | { |
| 53 | // No prep code for hash comparisons. |
| 54 | } |
| 55 | |
| 56 | void hash_call::fill_in_command (void) |
| 57 | { |
| 58 | if (asset_info.asset_name_vector.size() > 1) { // nothing to compare with less than 2 |
| 59 | // Fill in preceding comment: |
| 60 | // Fill in the hash-comparison code itself: |
| 61 | for (auto outer = asset_info.asset_name_vector.begin(); |
| 62 | outer < asset_info.asset_name_vector.end(); |
| 63 | ++outer) { |
| 64 | for (auto inner = outer+1; |
| 65 | inner < asset_info.asset_name_vector.end(); |
| 66 | ++inner) { |
Mate Toth-Pal | ffba10e | 2021-09-22 21:38:03 +0200 | [diff] [blame] | 67 | call_code.append (" if (" + *outer + "_hash == " + *inner + "_hash) {\n"); |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 68 | call_code.append ( " TEST_FAIL(\"Probable data leak between assets " |
| 69 | + *outer + " and " + *inner + ".\\n\");\n"); |
| 70 | call_code.append (" return;\n"); |
| 71 | call_code.append (" }\n"); |
| 72 | // TODO: Pull this from boilerplate!! |
| 73 | } |
| 74 | } |
| 75 | } else { |
| 76 | call_code.assign (" /* Cannot compare hashes; only one asset specified. */\n"); |
| 77 | |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /********************************************************************************** |
| 82 | End of methods of class hash_call. |
| 83 | **********************************************************************************/ |