tf_fuzz: add new crypto key generation model

* Add a new model of what it means for a crypto policy to be valid. This
  fixes the simulation of psa_generate_key() calls, which TF-Fuzz
  currently cannot accurately predict.

  The PSA Crypto properties modelled are whether an algorithm and key
  type are compatible, whether a key type/ algorithm are disabled, and
  what key sizes are allowed.

  Although the PSA Crypto specification has additional, more complicated
  requirements for policies and keys, this commit only implements what
  is necessary for predicting the outcome of psa_generate_key(), and not
  requirements that make a key useless but still valid or involve
  features not yet in TF-M or MbedTLS.

* Improve the way in which policies are filled in, and allow policies to
  be updated at simulation time using the value of a named policy asset.
  Information about other assets and calls is not accessible during
  parse time when the key policy is usually filled in. However, this is
  required for the improved simulation of psa_generate_key calls. This
  is because policy information for generate key calls come from a named
  policy created earlier in the test file.

* Add valid flag to set-policy calls, allowing the creation of a random
  valid policy. For example, see demo/36.test.

* Add demo/36.test. This test generates a policy with a (roughly) even
  chance of being valid or invalid and then tries to generate a key
  using it.

  Running this test a large number of times (~300) succeeds with the
  changes in this commit, showing that TF-Fuzz can now accurately
  predict the outcome of psa_generate_key calls.

Change-Id: Ia40ff893db50b8d2c579d975aa23341b7aab004d
Signed-off-by: Nik Dewally <Nik.Dewally@arm.com>
diff --git a/tf_fuzz/tfz-cpp/utility/data_blocks.cpp b/tf_fuzz/tfz-cpp/utility/data_blocks.cpp
index 5683b06..d80d46f 100644
--- a/tf_fuzz/tfz-cpp/utility/data_blocks.cpp
+++ b/tf_fuzz/tfz-cpp/utility/data_blocks.cpp
@@ -15,7 +15,7 @@
 #include <vector>
 #include <iostream>
 
-#include "randomization.hpp"
+#include "fill_in_policy.hpp"
 #include "gibberish.hpp"
 #include "data_blocks.hpp"
 #include "find_or_create_asset.hpp"
@@ -359,25 +359,24 @@
 {
     get_policy_from_key = false;  // specify policy asset by a key that uses it.
     copy_key = false;  // not copying one key to another
-    /* The following settings are not necessarily being randomized in mutually-
-       consistent ways, for two reasons:  First, the template should set all that
-       matter, and second, testing TF response to nonsensical settings is also
-       valuable. */
-    exportable  = (rand()%2==1? true : false);
-    copyable    = (rand()%2==1? true : false);
-    can_encrypt = (rand()%2==1? true : false);
-    can_decrypt = (rand()%2==1? true : false);
-    can_sign    = (rand()%2==1? true : false);
-    can_verify  = (rand()%2==1? true : false);
-    derivable   = (rand()%2==1? true : false);
-    persistent  = (rand()%2==1? true : false);
-    // There's a really huge number of possible key types; won't randomize all:
-    key_type = rand_key_type();
+    exportable = false;
+    copyable = false;
+    can_encrypt = false;
+    can_decrypt = false;
+    can_sign = false;
+    can_verify = false;
+    derivable= false;
+    persistent= false;
+
+    get_policy_from_policy = "";
+    key_type = "";
+    key_algorithm = "";
+    n_bits = 0;
+
     usage_string.assign ("");
     print_usage_true_string.assign ("");
     print_usage_false_string.assign ("");
-    key_algorithm = rand_key_algorithm();
-    n_bits = 55 + (rand() % 1000);
+
     gibberish *gib = new gibberish;
     char buffer[256];
     char *end;
@@ -389,7 +388,15 @@
     gib->sentence (buffer, buffer + (40ULL + (uint64_t) (rand() % 200)));
     key_data = buffer;
     delete gib;
+
 }
+
+key_policy_info key_policy_info::create_random() {
+    key_policy_info policy;
+    fill_in_policy(policy,false);
+    return policy;
+}
+
 key_policy_info::~key_policy_info (void)  // (destructor)
 {
     return;  // (even if only to have something to pin a breakpoint on)