Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1 | /* |
Nik Dewally | abac0e5 | 2024-08-02 13:42:27 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2019-2024, Arm Limited. All rights reserved. |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | |
| 9 | %{ |
| 10 | #include "class_forwards.hpp" |
| 11 | #include "boilerplate.hpp" |
| 12 | #include "gibberish.hpp" |
| 13 | #include "compute.hpp" |
| 14 | #include "string_ops.hpp" |
| 15 | #include "data_blocks.hpp" |
| 16 | #include "psa_asset.hpp" |
| 17 | #include "sst_asset.hpp" |
| 18 | #include "crypto_asset.hpp" |
| 19 | #include "find_or_create_asset.hpp" |
| 20 | #include "template_line.hpp" |
| 21 | #include "tf_fuzz.hpp" |
| 22 | #include "psa_call.hpp" |
| 23 | #include "tf_fuzz_grammar.tab.hpp" |
| 24 | |
| 25 | int yycolumn = 1; |
| 26 | |
| 27 | //char *yytext; |
| 28 | |
| 29 | #define YY_USER_ACTION yylloc.first_line = yylloc.last_line = yylineno; \ |
| 30 | yylloc.first_column = yycolumn; yylloc.last_column = yycolumn + yyleng - 1; \ |
| 31 | yycolumn += yyleng; \ |
| 32 | yylval.str = strdup(yytext); |
| 33 | |
| 34 | void yyerror (tf_fuzz_info *, const char *str) |
| 35 | /* not sure why it sends the yyparse() argument to yyerror(), but OK... */ |
| 36 | { |
| 37 | fprintf (stderr, "tf_fuzz template on line %d, at text = \"%s\": %s\n", |
| 38 | yylineno, yytext, str); |
| 39 | exit (1); |
| 40 | } |
| 41 | |
| 42 | #ifndef yyterminate |
| 43 | #define yyterminate() return YY_NULL |
| 44 | #endif |
| 45 | |
| 46 | %} |
| 47 | |
| 48 | %x BLOCK_COMMENT |
| 49 | |
| 50 | %option yylineno |
| 51 | %option nodefault |
| 52 | %option noyywrap |
| 53 | %array |
| 54 | |
| 55 | %% |
| 56 | |
| 57 | \r ; /* ignore all \r */ |
| 58 | \/\/.*\n ; /* ignore C++-style line comments */ |
| 59 | purpose[ \t]+[^;]*; return PURPOSE; |
| 60 | "/*" {BEGIN(BLOCK_COMMENT);} |
| 61 | <BLOCK_COMMENT>"*/" {BEGIN(INITIAL);} |
| 62 | <BLOCK_COMMENT>\n ; |
| 63 | <BLOCK_COMMENT>. ; |
| 64 | /* Root commands: */ |
| 65 | set return SET; |
| 66 | read return READ; |
| 67 | remove return REMOVE; |
| 68 | rm return REMOVE; |
| 69 | secure return SECURE; |
| 70 | sec return SECURE; |
| 71 | done return DONE; |
| 72 | /* PSA-asset types: */ |
| 73 | sst return SST; |
| 74 | key return KEY; |
| 75 | policy return POLICY; |
| 76 | /* Other root-command operands: */ |
| 77 | expect return EXPECT; |
| 78 | exp return EXPECT; |
| 79 | pass return PASS; |
| 80 | fail return FAIL; |
| 81 | nothing return NOTHING; |
| 82 | error return ERROR; |
| 83 | \{ return OPEN_BRACE; |
| 84 | \} return CLOSE_BRACE; |
| 85 | ; return SEMICOLON; |
| 86 | name return NAME; |
| 87 | uid return UID; |
| 88 | data return DATA; |
| 89 | \* return STAR; |
| 90 | active return ACTIVE; |
| 91 | act return ACTIVE; |
| 92 | deleted return DELETED; |
| 93 | del return DELETED; |
| 94 | removed return DELETED; |
| 95 | check return CHECK; |
| 96 | chk return CHECK; |
| 97 | var return VAR; |
| 98 | print return PRINT; |
| 99 | hash return HASH; |
| 100 | neq return NEQ; |
| 101 | dfname return DFNAME; |
| 102 | shuffle return SHUFFLE; |
| 103 | shuf return SHUFFLE; |
| 104 | to return TO; |
| 105 | of return OF; |
| 106 | /* SST creation keywords: */ |
| 107 | flag return FLAG; |
| 108 | none return NONE; |
| 109 | write_once return WRITE_ONCE; |
| 110 | wo return WRITE_ONCE; |
| 111 | no_rp return NO_RP; |
| 112 | nrp return NO_RP; |
| 113 | no_conf return NO_CONF; |
| 114 | ncf return NO_CONF; |
| 115 | /* Offset into an SST asset */ |
| 116 | offset return OFFSET; |
| 117 | /* Policy keywords: */ |
| 118 | attributes return ATTR; |
| 119 | attr return ATTR; |
| 120 | type return TYPE; |
| 121 | algorithm return ALG; |
| 122 | alg return ALG; |
| 123 | /* Policy-usage and -lifetime keywords: */ |
| 124 | export return EXPORT; |
| 125 | exp return EXPORT; |
| 126 | noexport return NOEXPORT; |
| 127 | nex return NOEXPORT; |
| 128 | copy return COPY; |
| 129 | nocopy return NOCOPY; |
| 130 | encrypt return ENCRYPT; |
| 131 | encr return ENCRYPT; |
| 132 | noencrypt return NOENCRYPT; |
| 133 | nenc return NOENCRYPT; |
| 134 | decrypt return DECRYPT; |
| 135 | decr return DECRYPT; |
| 136 | nodecrypt return NODECRYPT; |
| 137 | ndecr return NODECRYPT; |
| 138 | sign return SIGN; |
| 139 | nosign return NOSIGN; |
| 140 | verify return VERIFY; |
| 141 | ver return VERIFY; |
| 142 | noverify return NOVERIFY; |
| 143 | nver return NOVERIFY; |
| 144 | derive return DERIVE; |
| 145 | der return DERIVE; |
| 146 | noderive return NODERIVE; |
| 147 | nder return NODERIVE; |
| 148 | persistent return PERSISTENT; |
| 149 | pers return PERSISTENT; |
| 150 | volatile return VOLATILE; |
| 151 | vol return VOLATILE; |
| 152 | from return FROM; |
| 153 | with return WITH; |
Nik Dewally | abac0e5 | 2024-08-02 13:42:27 +0100 | [diff] [blame^] | 154 | valid return VALID; |
Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 155 | /* Structure operands: */ |
| 156 | [a-zA-z][a-zA-Z_0-9]* {yylval.str = yytext; return IDENTIFIER_TOK;} |
| 157 | [+-]?[0-9]* {yylval.valueN = atol(yytext); return NUMBER_TOK;} |
| 158 | \'[a-zA-Z_0-9\/\.]+\' {yylval.str = yytext; return FILE_PATH_TOK;} |
| 159 | \"[^\"]*\" {yylval.str = yytext; return LITERAL_TOK;} |
| 160 | \[[a-fA-F 0-9]*\] {yylval.str = yytext; return HEX_LIST;} |
| 161 | /* inside quotes: anything but a quote, or nothing */ |
| 162 | [ \t\n\r] ; /* ignore white space */ |
| 163 | . yyerror ((tf_fuzz_info *) NULL, "Unexpected character"); |
| 164 | |
| 165 | %% |