Add tf_fuzz tool
This is fully derived from tf-m repo.
Signed-off-by: Karl Zhang <karl.zhang@arm.com>
Change-Id: I8d35e70eda9081af66d8fa3f3cb4beb1d953060e
diff --git a/tf_fuzz/assets/README b/tf_fuzz/assets/README
new file mode 100644
index 0000000..870416e
--- /dev/null
+++ b/tf_fuzz/assets/README
@@ -0,0 +1,10 @@
+This directory contains C++ header and program files for classes of objects that
+track PSA assets, notably during the Simulate phase.
+
+For more information, please browse to:
+
+ https://ci.trustedfirmware.org/job/tf-m-build-test-nightly/lastSuccessfulBuild/artifact/build-docs/tf-m_documents/install/doc/user_guide/html/docs/user_guides/tf_fuzz/asset_dir.html
+
+--------------
+
+*Copyright (c) 2019-2020, Arm Limited. All rights reserved.*
diff --git a/tf_fuzz/assets/crypto_asset.cpp b/tf_fuzz/assets/crypto_asset.cpp
new file mode 100644
index 0000000..7918a79
--- /dev/null
+++ b/tf_fuzz/assets/crypto_asset.cpp
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "class_forwards.hpp"
+
+#include "boilerplate.hpp"
+#include "randomization.hpp"
+#include "gibberish.hpp"
+#include "compute.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"
+
+
+
+/**********************************************************************************
+ Methods of class crypto_asset follow:
+**********************************************************************************/
+
+crypto_asset::crypto_asset (void) // (default constructor)
+{
+ return; // just to have something to pin a breakpoint onto
+}
+
+
+crypto_asset::~crypto_asset (void) // (destructor)
+{
+ return; // just to have something to pin a breakpoint onto
+}
+
+/**********************************************************************************
+ End of methods of class crypto_asset.
+**********************************************************************************/
+
+
+/**********************************************************************************
+ Methods of class policy_asset follow:
+**********************************************************************************/
+
+policy_asset::policy_asset (void) // (default constructor)
+{
+ // Randomize key-policy usage and algorithm:
+ policy_usage = rand_key_usage();
+ policy_algorithm = rand_key_algorithm();
+ // keys: Should automatically come up as empby.
+}
+
+
+policy_asset::~policy_asset (void) // (destructor)
+{
+ return; // just to have something to pin a breakpoint onto
+}
+
+/**********************************************************************************
+ End of methods of class policy_asset.
+**********************************************************************************/
+
+
+/**********************************************************************************
+ Methods of class key_asset follow:
+**********************************************************************************/
+
+bool key_asset::set_key_id (int id_n)
+{
+ key_id = id_n;
+ return true;
+}
+
+
+key_asset::key_asset (void)
+{
+ // Note: Similar random initialization for asset and template
+ // Randomize handle:
+ // TODO: Key handles appear to be a lot more complex a question than the below
+ gibberish *gib = new gibberish;
+ char buffer[256];
+ char *end;
+ int buf_len = 5ULL + (uint64_t) (rand() % 10);
+ end = gib->word (false, buffer, buffer + buf_len);
+ *end = '\0';
+ buffer[buf_len] = '\0';
+ handle_str = buffer;
+ // Randomize key type:
+ key_type = rand_key_type();
+ // Randomize lifetime:
+ lifetime_str = ((rand() % 2) == 1)?
+ "PSA_KEY_LIFETIME_VOLATILE" : "PSA_KEY_LIFETIME_PERSISTENT";
+}
+
+
+key_asset::~key_asset (void)
+{
+ return; // just to have something to pin a breakpoint onto
+}
+
+/**********************************************************************************
+ End of methods of class key_asset.
+**********************************************************************************/
diff --git a/tf_fuzz/assets/crypto_asset.hpp b/tf_fuzz/assets/crypto_asset.hpp
new file mode 100644
index 0000000..bcee450
--- /dev/null
+++ b/tf_fuzz/assets/crypto_asset.hpp
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef CRYPTO_ASSET_HPP
+#define CRYPTO_ASSET_HPP
+
+#include <string>
+#include <vector>
+#include <cstddef>
+#include <cstdint>
+
+
+/* This project's header files #including other project headers quickly becomes
+ unrealistically complicated. The only solution is for each .cpp to include
+ the headers it needs.
+#include "psa_asset.hpp"
+*/
+
+
+using namespace std;
+
+class crypto_asset : public psa_asset
+{
+public:
+ // Data members:
+ key_policy_info policy;
+ // Methods:
+ crypto_asset (void); // (constructor)
+ ~crypto_asset (void);
+
+protected:
+ // Data members:
+ // Methods:
+
+private:
+ // Data members:
+ // Methods:
+};
+
+class policy_asset : public crypto_asset
+{
+public:
+ // Data members:
+ string policy_usage; // for now just strings; maybe future tap TF-M(?) value list
+ string key_type; // DES, AES, RAW, vendor, none, etc.
+ string policy_algorithm;
+ vector<key_asset*> keys; // keys that use this policy
+ // Methods:
+ policy_asset (void); // (constructor)
+ ~policy_asset (void);
+
+protected:
+ // Data members:
+ // Methods:
+
+private:
+ // Data members:
+ // Methods:
+};
+
+class key_asset : public crypto_asset
+{
+public:
+ // Data members:
+ vector<policy_asset*>::iterator the_policy_asset;
+ /* The policy for this key. Note that psa_make_key() lets us create
+ a key without associating a policy with it. In that case, this will
+ be null, and the attributes below apply. Later, psa_set_key_policy
+ lets us associate a policy with a key, at which point this becomes
+ non-null and the following attributes no longer apply. */
+ string key_type; // DES, AES, RAW, vendor, none, etc.
+ string usage; // for now just strings; maybe future tap TF-M(?) value list
+ string alg; // these only apply if the string was created without a policy
+ string lifetime_str; // similarly, the text representation of the key's lifetime
+ // Methods:
+ bool set_key_id (int id_n); // checks key-ID value, returns true==success
+ key_asset (void); // (constructor)
+ ~key_asset (void);
+
+protected:
+ // Data members:
+ uint64_t key_id;
+ // Methods:
+
+private:
+ // Data members:
+ // Methods:
+};
+
+#endif // CRYPTO_ASSET_HPP
diff --git a/tf_fuzz/assets/crypto_asset.o b/tf_fuzz/assets/crypto_asset.o
new file mode 100644
index 0000000..accb11f
--- /dev/null
+++ b/tf_fuzz/assets/crypto_asset.o
Binary files differ
diff --git a/tf_fuzz/assets/psa_asset.cpp b/tf_fuzz/assets/psa_asset.cpp
new file mode 100644
index 0000000..2c230e7
--- /dev/null
+++ b/tf_fuzz/assets/psa_asset.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "class_forwards.hpp"
+
+#include "boilerplate.hpp"
+#include "gibberish.hpp"
+#include "compute.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"
+
+
+/**********************************************************************************
+ Methods of class psa_asset follow:
+**********************************************************************************/
+
+void psa_asset::set_name (string set_val)
+{
+ asset_info.name_specified = true;
+ asset_name.assign (set_val);
+}
+
+string psa_asset::get_name (void)
+{
+ return asset_name;
+}
+
+bool psa_asset::simulate (void) {
+ return false;
+ // by default, assume that nothing changed; derived classes may override.
+}
+
+psa_asset::psa_asset (void) // (default constructor)
+{
+ asset_info.asset_ser_no = unique_id_counter++;
+}
+
+
+psa_asset::~psa_asset (void)
+{
+ return; // just to have something to pin a breakpoint onto
+}
+
+/**********************************************************************************
+ End of methods of class psa_asset.
+**********************************************************************************/
diff --git a/tf_fuzz/assets/psa_asset.hpp b/tf_fuzz/assets/psa_asset.hpp
new file mode 100644
index 0000000..9eb4d3f
--- /dev/null
+++ b/tf_fuzz/assets/psa_asset.hpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef PSA_ASSET_HPP
+#define PSA_ASSET_HPP
+
+#include <string>
+#include <vector>
+#include <cstdint>
+
+/* This project's header files #including other project headers quickly becomes
+ unrealistically complicated. The only solution is for each .cpp to include
+ the headers it needs. */
+
+using namespace std;
+
+class psa_asset
+{
+public:
+ /* Data members -- not all PSA assets have all of these, but they need to be
+ accessible polymorphically via a psa_asset iterator: */
+ set_data_info set_data;
+ /* For a PSA-asset tracker, this is really more about an asset's
+ on-going, real-time asset data value than about *setting* its data
+ value. On a template_line or a psa_call, it's about setting its
+ value at one particular time. */
+ expect_info exp_data;
+ /* For now at least, this is here only for its n_exp_vars member, to
+ keep track of how many expected-data variables in the test. */
+ asset_name_id_info asset_info; // everything about the asset(s) for this line
+ key_policy_info policy; // (specific to crypto, but have to put this here)
+ vector<int> template_ref;
+ // list of template line #s that reference this asset
+ vector<psa_call> call_ref; // list of PSA calls that reference this asset
+ string handle_str; // the text name of the key's "handle"
+ bool asset_name_specified;
+ /* true if the template specified the asset_name, as opposed to us
+ having inferred it. */
+ // Methods:
+ void set_name (string set_val);
+ string get_name (void);
+ virtual bool simulate (void);
+ /* simulate() tells this asset to react to its current state information.
+ Initially, this won't really do much, but will allow assets to react
+ to each other, if that is relevant. It returns true if anything
+ in the state of the asset changed, in which case all assets' simulate()
+ methods will be invoked again to react again. That will repeat until
+ all assets read a quiescent state. */
+ psa_asset(); // (constructor)
+ ~psa_asset();
+
+protected:
+ // Data members:
+ // These are initially copied over from the call (or possibly template line):
+ string data; // String describing current data value.
+ string asset_name; // human-meaningful name
+ static long unique_id_counter; // counts off unique IDs for assets
+ // Methods:
+
+private:
+ // Data members:
+ // Methods:
+};
+
+#endif // PSA_ASSET_HPP
diff --git a/tf_fuzz/assets/psa_asset.o b/tf_fuzz/assets/psa_asset.o
new file mode 100644
index 0000000..994bdd7
--- /dev/null
+++ b/tf_fuzz/assets/psa_asset.o
Binary files differ
diff --git a/tf_fuzz/assets/sst_asset.cpp b/tf_fuzz/assets/sst_asset.cpp
new file mode 100644
index 0000000..ac4de6f
--- /dev/null
+++ b/tf_fuzz/assets/sst_asset.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "class_forwards.hpp"
+
+#include "boilerplate.hpp"
+#include "gibberish.hpp"
+#include "compute.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 "sst_asset.hpp"
+
+
+
+/**********************************************************************************
+ Methods of class sst_asset follow:
+**********************************************************************************/
+
+bool sst_asset::set_uid (uint64_t uid)
+{
+ /* TODO: What are the limits upon UIDs? I don't necessarily not want to be
+ able to set an illegal value, but if it is illegal, I might want to
+ set some flag appropriately to generate expected results. */
+ asset_info.set_id_n (uid);
+ return true;
+}
+
+sst_asset::sst_asset (void) // (default constructor)
+{
+ return; // just to have something to pin a breakpoint onto
+}
+
+
+sst_asset::~sst_asset (void) // (destructor)
+{
+ return; // just to have something to pin a breakpoint onto
+}
+
+/**********************************************************************************
+ End of methods of class sst_asset.
+**********************************************************************************/
diff --git a/tf_fuzz/assets/sst_asset.hpp b/tf_fuzz/assets/sst_asset.hpp
new file mode 100644
index 0000000..0fbd5b8
--- /dev/null
+++ b/tf_fuzz/assets/sst_asset.hpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef SST_ASSET_HPP
+#define SST_ASSET_HPP
+
+#include <string>
+
+/* This project's header files #including other project headers quickly becomes
+ unrealistically complicated. The only solution is for each .cpp to include
+ the headers it needs.
+#include "psa_asset.hpp"
+*/
+
+
+using namespace std;
+
+class sst_asset : public psa_asset
+{
+public: // (low value in hiding these behind setters and getters)
+ // Data members:
+ // Methods:
+ bool set_uid (uint64_t uid); // checks input UID value, returns true==success
+ void set_literal_data (string literal_data);
+ // if literal data, this sets both "data" string and "data_length"
+ sst_asset (void); // (constructor)
+ ~sst_asset (void);
+
+protected:
+ // Data members:
+ // Methods:
+
+private:
+ // Data members:
+ // Methods:
+};
+
+#endif // SST_ASSET_HPP
diff --git a/tf_fuzz/assets/sst_asset.o b/tf_fuzz/assets/sst_asset.o
new file mode 100644
index 0000000..2e5a2ef
--- /dev/null
+++ b/tf_fuzz/assets/sst_asset.o
Binary files differ