blob: 806df173bc7a8fb50d6c9a4de5115a9bcff76535 [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
Nik Dewallybacae6c2024-07-30 16:58:14 +01008#include <string>
9#include <vector>
Karl Zhang3de5ab12021-05-31 11:45:48 +080010
Karl Zhang3de5ab12021-05-31 11:45:48 +080011#include "data_blocks.hpp"
Karl Zhang3de5ab12021-05-31 11:45:48 +080012#include "find_or_create_asset.hpp"
Karl Zhang3de5ab12021-05-31 11:45:48 +080013#include "psa_call.hpp"
14#include "security_call.hpp"
Nik Dewallybacae6c2024-07-30 16:58:14 +010015
16class tf_fuzz_info;
Karl Zhang3de5ab12021-05-31 11:45:48 +080017
18
19
20/**********************************************************************************
21 Methods of class hash_call follow:
22**********************************************************************************/
23
24hash_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}
31hash_call::~hash_call (void)
32{
33 // Nothing further to delete.
34 return; // just to have something to pin a breakpoint onto
35}
36
37bool hash_call::copy_call_to_asset (void)
38{
39 // The assets are not directly involved in this call.
40 return true;
41}
42
43bool 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... */
51void hash_call::fill_in_prep_code (void)
52{
53 // No prep code for hash comparisons.
54}
55
56void 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-Palffba10e2021-09-22 21:38:03 +020067 call_code.append (" if (" + *outer + "_hash == " + *inner + "_hash) {\n");
Karl Zhang3de5ab12021-05-31 11:45:48 +080068 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**********************************************************************************/