tf_fuzz: allow specifying policy size in template file
Allow the use of `size <NUM>` in set-policy commands to give a policy a
specific key size (in bits).
For example:
`set policy name myAesPolicy type aes size 2048`
Change-Id: I69febd4107ed1190cf3cc780bf74fd1e02b9e206
Signed-off-by: Nik Dewally <Nik.Dewally@arm.com>
diff --git a/tf_fuzz/tfz-cpp/parser/tf_fuzz_grammar.l b/tf_fuzz/tfz-cpp/parser/tf_fuzz_grammar.l
index 7df9896..c516edc 100644
--- a/tf_fuzz/tfz-cpp/parser/tf_fuzz_grammar.l
+++ b/tf_fuzz/tfz-cpp/parser/tf_fuzz_grammar.l
@@ -120,6 +120,7 @@
type return TYPE;
algorithm return ALG;
alg return ALG;
+size return SIZE;
/* Policy-usage and -lifetime keywords: */
export return EXPORT;
exp return EXPORT;
diff --git a/tf_fuzz/tfz-cpp/parser/tf_fuzz_grammar.y b/tf_fuzz/tfz-cpp/parser/tf_fuzz_grammar.y
index dae9c7d..9b93df5 100644
--- a/tf_fuzz/tfz-cpp/parser/tf_fuzz_grammar.y
+++ b/tf_fuzz/tfz-cpp/parser/tf_fuzz_grammar.y
@@ -371,7 +371,7 @@
%token <str> IDENTIFIER_TOK LITERAL_TOK HEX_LIST FILE_PATH_TOK /* variables and content */
%token <valueN> NUMBER_TOK /* variables and content */
%token <tokenN> SEMICOLON SHUFFLE TO OF OPEN_BRACE CLOSE_BRACE /* block structure */
-%token <tokenN> ATTR TYPE ALG /* "set policy" line portions */
+%token <tokenN> ATTR TYPE ALG SIZE /* "set policy" line portions */
%token <tokenN> VALID
%token <tokenN> EXPORT COPY ENCRYPT DECRYPT SIGN VERIFY DERIVE /* key-usage keywords */
%token <tokenN> NOEXPORT NOCOPY NOENCRYPT NODECRYPT NOSIGN NOVERIFY NODERIVE
@@ -1132,6 +1132,13 @@
<< policy_info.key_algorithm << "\"" << endl;)
}
+policy_size:
+ SIZE NUMBER_TOK {
+ IVM(cout << "Policy-Size: \"" << flush;)
+ int num = atol(yytext);
+ policy_info.n_bits = num;
+ IVM(cout << yytext << "\"" << endl;)
+ }
policy_specs:
%empty /* nothing */
| policy_spec policy_specs {
@@ -1140,7 +1147,7 @@
}
;
-policy_spec: policy_usage_list | policy_type | policy_algorithm;
+policy_spec: policy_usage_list | policy_type | policy_algorithm | policy_size;
policy_asset_spec:
%empty /* nothing */
@@ -1361,9 +1368,9 @@
ASSET_NUMBER:
NUMBER_TOK {
- IVM(cout << "ASSET_NUMBER: \"" << flush;)
- nid = atol(yytext);
- parsed_asset.asset_id_n_vector.push_back (nid);
+ IVM(cout << "Policy Size: \"" << flush;)
+ int size = atol(yytext);
+ policy_info.n_bits = size;
IVM(cout << yytext << "\"" << endl;)
}
;