examples/fips_validation: support GCM parsing
[dpdk.git] / examples / fips_validation / fips_validation.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #ifndef _FIPS_VALIDATION_H_
6 #define _FIPS_VALIDATION_H_
7
8 #define FIPS_PARSE_ERR(fmt, args)                                       \
9         RTE_LOG(ERR, USER1, "FIPS parse error" ## fmt ## "\n", ## args)
10
11 #define ERR_MSG_SIZE            128
12 #define MAX_CASE_LINE           15
13 #define MAX_LINE_CHAR           204800 /*< max number of characters per line */
14 #define MAX_NB_TESTS            10240
15 #define MAX_BUF_SIZE            2048
16 #define MAX_STRING_SIZE         64
17
18 #define POSITIVE_TEST           0
19 #define NEGATIVE_TEST           -1
20
21 #define REQ_FILE_PERFIX         "req"
22 #define RSP_FILE_PERFIX         "rsp"
23 #define FAX_FILE_PERFIX         "fax"
24
25 enum fips_test_algorithms {
26                 FIPS_TEST_ALGO_AES = 0,
27                 FIPS_TEST_ALGO_AES_GCM,
28                 FIPS_TEST_ALGO_HMAC,
29                 FIPS_TEST_ALGO_TDES,
30                 FIPS_TEST_ALGO_MAX
31 };
32
33 enum file_types {
34         FIPS_TYPE_REQ = 1,
35         FIPS_TYPE_FAX,
36         FIPS_TYPE_RSP
37 };
38
39 enum fips_test_op {
40         FIPS_TEST_ENC_AUTH_GEN = 1,
41         FIPS_TEST_DEC_AUTH_VERIF,
42 };
43
44 #define MAX_LINE_PER_VECTOR            16
45
46 struct fips_val {
47         uint8_t *val;
48         uint32_t len;
49 };
50
51 struct fips_test_vector {
52         union {
53                 struct {
54                         struct fips_val key;
55                         struct fips_val digest;
56                         struct fips_val auth_aad;
57                         struct fips_val aad;
58                 } cipher_auth;
59                 struct {
60                         struct fips_val key;
61                         struct fips_val digest;
62                         struct fips_val aad;
63                 } aead;
64         };
65
66         struct fips_val pt;
67         struct fips_val ct;
68         struct fips_val iv;
69
70         enum rte_crypto_op_status status;
71 };
72
73 typedef int (*post_prcess_t)(struct fips_val *val);
74
75 typedef int (*parse_callback_t)(const char *key, char *text,
76                 struct fips_val *val);
77
78 struct fips_test_callback {
79         const char *key;
80         parse_callback_t cb;
81         struct fips_val *val;
82 };
83
84 enum fips_aesavs_test_types {
85         AESAVS_TYPE_GFXBOX = 1,
86         AESAVS_TYPE_KEYSBOX,
87         AESAVS_TYPE_VARKEY,
88         AESAVS_TYPE_VARTXT,
89         AESAVS_TYPE_MMT,
90         AESAVS_TYPE_MCT,
91 };
92
93 enum fips_tdes_test_types {
94         TDES_INVERSE_PERMUTATION = 0,
95         TDES_PERMUTATION,
96         TDES_SUBSTITUTION_TABLE,
97         TDES_VARIABLE_KEY,
98         TDES_VARIABLE_TEXT,
99         TDES_KAT,
100         TDES_MCT, /* Monte Carlo (Modes) Test */
101         TDES_MMT /* Multi block Message Test */
102 };
103
104 struct aesavs_interim_data {
105         enum fips_aesavs_test_types test_type;
106         uint32_t cipher_algo;
107         uint32_t key_len;
108 };
109
110 struct hmac_interim_data {
111         enum rte_crypto_auth_algorithm algo;
112 };
113
114 struct tdes_interim_data {
115         enum fips_tdes_test_types test_type;
116         uint32_t nb_keys;
117 };
118
119 struct fips_test_interim_info {
120         FILE *fp_rd;
121         FILE *fp_wr;
122         enum file_types file_type;
123         enum fips_test_algorithms algo;
124         char *one_line_text;
125         char *vec[MAX_LINE_PER_VECTOR];
126         uint32_t nb_vec_lines;
127         char device_name[MAX_STRING_SIZE];
128
129         union {
130                 struct aesavs_interim_data aes_data;
131                 struct hmac_interim_data hmac_data;
132                 struct tdes_interim_data tdes_data;
133
134         } interim_info;
135
136         enum fips_test_op op;
137
138         const struct fips_test_callback *callbacks;
139         const struct fips_test_callback *interim_callbacks;
140         const struct fips_test_callback *writeback_callbacks;
141
142         post_prcess_t parse_writeback;
143         post_prcess_t kat_check;
144 };
145
146 extern struct fips_test_vector vec;
147 extern struct fips_test_interim_info info;
148
149 int
150 fips_test_init(const char *req_file_path, const char *rsp_file_path,
151                 const char *device_name);
152
153 void
154 fips_test_clear(void);
155
156 int
157 fips_test_fetch_one_block(void);
158
159 int
160 fips_test_parse_one_case(void);
161
162 void
163 fips_test_write_one_case(void);
164
165 int
166 parse_test_aes_init(void);
167
168 int
169 parse_test_tdes_init(void);
170
171 int
172 parse_test_hmac_init(void);
173
174 int
175 parse_test_gcm_init(void);
176
177 int
178 parser_read_uint8_hex(uint8_t *value, const char *p);
179
180 int
181 parse_uint8_hex_str(const char *key, char *src, struct fips_val *val);
182
183 int
184 parse_uint8_known_len_hex_str(const char *key, char *src, struct fips_val *val);
185
186 int
187 parser_read_uint32_val(const char *key, char *src, struct fips_val *val);
188
189 int
190 parser_read_uint32_bit_val(const char *key, char *src, struct fips_val *val);
191
192 int
193 parser_read_uint32(uint32_t *value, char *p);
194
195 int
196 parser_read_uint32_val(const char *key, char *src, struct fips_val *val);
197
198 int
199 writeback_hex_str(const char *key, char *dst, struct fips_val *val);
200
201 void
202 parse_write_hex_str(struct fips_val *src);
203
204 int
205 update_info_vec(uint32_t count);
206
207 #endif