aboutsummaryrefslogtreecommitdiff
path: root/tools/tf_fuzz/calls/security_call.cpp
blob: 3aeb959b74941085c9678d10353108d8c4ba399e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *
 */

#include <cstdlib>

#include "class_forwards.hpp"

#include "boilerplate.hpp"
#include "gibberish.hpp"
#include "compute.hpp"
#include "randomization.hpp"
#include "string_ops.hpp"
#include "data_blocks.hpp"
#include "psa_asset.hpp"
#include "find_or_create_asset.hpp"
#include "template_line.hpp"
#include "tf_fuzz.hpp"
#include "crypto_asset.hpp"
#include "psa_call.hpp"
#include "security_call.hpp"
#include "sst_asset.hpp"



/**********************************************************************************
   Methods of class hash_call follow:
**********************************************************************************/

hash_call::hash_call (tf_fuzz_info *test_state,    // (constructor)
                          long &call_ser_no,
                          asset_search how_asset_found)
                             : security_call(test_state, call_ser_no, how_asset_found)
{
    // TODO:  Randomize key-policy usage and algorithm:
}
hash_call::~hash_call (void)
{
    // Nothing further to delete.
    return;  // just to have something to pin a breakpoint onto
}

/* Note:  These functions are overridden in all subclasses, but they still need to be
          defined, or the linker gives the error "undefined reference to `vtable... */
void hash_call::fill_in_prep_code (void)
{
    // No prep code for hash comparisons.
}

void hash_call::fill_in_command (void)
{
    if (asset_id.asset_name_vector.size() > 1) {  // nothing to compare with less than 2
        // Fill in preceding comment:
        // Fill in the hash-comparison code itself:
        for (auto outer = asset_id.asset_name_vector.begin();
             outer < asset_id.asset_name_vector.end();
             ++outer) {
            for (auto inner = outer+1;
                 inner < asset_id.asset_name_vector.end();
                 ++inner) {
                call_code.append ("    if (" + *outer + "_hash == " + *inner + "_hash) {\n");
                call_code.append (  "        TEST_FAIL(\"Probable data leak between assets "
                                  + *outer + " and " + *inner + ".\\n\");\n");
                call_code.append ("        return;\n");
                call_code.append ("    }\n");
            }
        }
    } else {
        call_code.assign ("    /* Cannot compare hashes;  only one asset specified. */\n");

    }
}

/**********************************************************************************
   End of methods of class hash_call.
**********************************************************************************/