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/calls/psa_call.hpp b/tf_fuzz/tfz-cpp/calls/psa_call.hpp
index 08d7316..9a497c0 100644
--- a/tf_fuzz/tfz-cpp/calls/psa_call.hpp
+++ b/tf_fuzz/tfz-cpp/calls/psa_call.hpp
@@ -83,6 +83,15 @@
     /// never be overwritten.
     virtual bool simulate (void);
 
+    // Update policy information in the call based on the policy
+    // asset specified in policy.get_policy_from_policy. If this is unset,
+    // the existing values are used as-is.
+    //
+    // This enables the simulation time setting of the policy.
+    //
+    // See `key_policy_info.get_policy_from_policy`.
+    void copy_policy_to_call(void);
+
     // TODO: move simulation and error modelling code code into simulate().
     // once this is done, remove default impl so that simulate is mandatory for
     // calls.
@@ -159,7 +168,8 @@
 public:
     // Data members:  // (low value in hiding these behind setters and getters)
     // Methods:
-        bool copy_asset_to_call (void);
+        bool copy_asset_to_call (void) override;
+        virtual bool simulate() override;
         crypto_call (tf_fuzz_info *test_state, long &asset_ser_no,
                     asset_search how_asset_found);  // (constructor)
         ~crypto_call (void);
@@ -167,12 +177,12 @@
 protected:
     // Data members:
     // Methods:
-        void fill_in_result_code (void);
+        void fill_in_result_code (void) override;
            // for now, the method-overide buck stops here, but that'll probably change
+        bool simulate_ret_code(void);
+
 
 private:
-    // Data members:
-    // Methods:
 };
 
 class security_call : public psa_call