blob: a99496a94498652b7848bbd455d707d9c63487a6 [file] [log] [blame]
Karl Zhang3de5ab12021-05-31 11:45:48 +08001/*
2 * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#include <cstdlib>
9
10#include "class_forwards.hpp"
11
12#include "boilerplate.hpp"
13#include "gibberish.hpp"
14#include "compute.hpp"
15#include "randomization.hpp"
16#include "string_ops.hpp"
17#include "data_blocks.hpp"
18#include "psa_asset.hpp"
19#include "find_or_create_asset.hpp"
20#include "template_line.hpp"
21#include "tf_fuzz.hpp"
22#include "crypto_asset.hpp"
23#include "psa_call.hpp"
24#include "security_call.hpp"
25#include "sst_asset.hpp"
26
27
28
29/**********************************************************************************
30 Methods of class hash_call follow:
31**********************************************************************************/
32
33hash_call::hash_call (tf_fuzz_info *test_state, // (constructor)
34 long &call_ser_no,
35 asset_search how_asset_found)
36 : security_call(test_state, call_ser_no, how_asset_found)
37{
38 call_description = "hash call";
39}
40hash_call::~hash_call (void)
41{
42 // Nothing further to delete.
43 return; // just to have something to pin a breakpoint onto
44}
45
46bool hash_call::copy_call_to_asset (void)
47{
48 // The assets are not directly involved in this call.
49 return true;
50}
51
52bool hash_call::copy_asset_to_call (void)
53{
54 // The assets are not directly involved in this call.
55 return true;
56}
57
58/* Note: These functions are overridden in all subclasses, but they still need to be
59 defined, or the linker gives the error "undefined reference to `vtable... */
60void hash_call::fill_in_prep_code (void)
61{
62 // No prep code for hash comparisons.
63}
64
65void hash_call::fill_in_command (void)
66{
67 if (asset_info.asset_name_vector.size() > 1) { // nothing to compare with less than 2
68 // Fill in preceding comment:
69 // Fill in the hash-comparison code itself:
70 for (auto outer = asset_info.asset_name_vector.begin();
71 outer < asset_info.asset_name_vector.end();
72 ++outer) {
73 for (auto inner = outer+1;
74 inner < asset_info.asset_name_vector.end();
75 ++inner) {
76 call_code.append (" if ( " + *outer + "_act_hash == " + *inner
77 + "_act_hash) {\n");
78 call_code.append ( " TEST_FAIL(\"Probable data leak between assets "
79 + *outer + " and " + *inner + ".\\n\");\n");
80 call_code.append (" return;\n");
81 call_code.append (" }\n");
82 // TODO: Pull this from boilerplate!!
83 }
84 }
85 } else {
86 call_code.assign (" /* Cannot compare hashes; only one asset specified. */\n");
87
88 }
89}
90
91/**********************************************************************************
92 End of methods of class hash_call.
93**********************************************************************************/