1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
5 #ifndef _FIPS_VALIDATION_H_
6 #define _FIPS_VALIDATION_H_
10 #endif /* RTE_HAS_JANSSON */
12 #define FIPS_PARSE_ERR(fmt, args) \
13 RTE_LOG(ERR, USER1, "FIPS parse error" ## fmt ## "\n", ## args)
15 #define ERR_MSG_SIZE 128
16 #define MAX_CASE_LINE 15
17 #define MAX_LINE_CHAR 204800 /*< max number of characters per line */
18 #define MAX_NB_TESTS 10240
19 #define DEF_MBUF_SEG_SIZE (UINT16_MAX - sizeof(struct rte_mbuf) - \
21 #define MAX_STRING_SIZE 64
22 #define MAX_FILE_NAME_SIZE 256
23 #define MAX_DIGEST_SIZE 64
25 #define POSITIVE_TEST 0
26 #define NEGATIVE_TEST -1
28 #define REQ_FILE_PREFIX "req"
29 #define RSP_FILE_PREFIX "rsp"
30 #define FAX_FILE_PREFIX "fax"
31 #define JSON_FILE_PREFIX "json"
33 #define ACVVERSION "1.0"
35 enum fips_test_algorithms {
36 FIPS_TEST_ALGO_AES = 0,
37 FIPS_TEST_ALGO_AES_GCM,
38 FIPS_TEST_ALGO_AES_CMAC,
39 FIPS_TEST_ALGO_AES_CCM,
43 FIPS_TEST_ALGO_AES_XTS,
55 FIPS_TEST_ENC_AUTH_GEN = 1,
56 FIPS_TEST_DEC_AUTH_VERIF,
59 #define MAX_LINE_PER_VECTOR 16
66 struct fips_test_vector {
70 struct fips_val digest;
71 struct fips_val auth_aad;
76 struct fips_val digest;
85 enum rte_crypto_op_status status;
88 typedef int (*post_prcess_t)(struct fips_val *val);
90 typedef int (*parse_callback_t)(const char *key, char *text,
91 struct fips_val *val);
93 struct fips_test_callback {
99 enum fips_aesavs_test_types {
100 AESAVS_TYPE_GFXBOX = 1,
109 enum fips_tdes_test_types {
110 TDES_INVERSE_PERMUTATION = 0,
112 TDES_SUBSTITUTION_TABLE,
116 TDES_MCT, /* Monte Carlo (Modes) Test */
117 TDES_MMT /* Multi block Message Test */
120 enum fips_tdes_test_mode {
125 enum fips_ccm_test_types {
126 CCM_VADT = 1, /* Variable Associated Data Test */
127 CCM_VPT, /* Variable Payload Test */
128 CCM_VNT, /* Variable Nonce Test */
129 CCM_VTT, /* Variable Tag Test */
130 CCM_DVPT, /* Decryption-Verification Process Test */
133 enum fips_sha_test_types {
138 struct aesavs_interim_data {
139 enum fips_aesavs_test_types test_type;
140 uint32_t cipher_algo;
144 struct hmac_interim_data {
145 enum rte_crypto_auth_algorithm algo;
148 struct tdes_interim_data {
149 enum fips_tdes_test_types test_type;
150 enum fips_tdes_test_mode test_mode;
154 struct ccm_interim_data {
155 enum fips_ccm_test_types test_type;
163 struct sha_interim_data {
164 enum fips_sha_test_types test_type;
165 enum rte_crypto_auth_algorithm algo;
168 struct gcm_interim_data {
173 #ifdef RTE_HAS_JANSSON
174 struct fips_test_json_info {
175 /* Information used for reading from json */
177 json_t *json_vector_set;
178 json_t *json_test_group;
179 json_t *json_test_case;
180 /* Location of json write output */
181 json_t *json_write_root;
182 json_t *json_write_group;
183 json_t *json_write_set;
184 json_t *json_write_case;
188 #endif /* RTE_HAS_JANSSON */
190 struct fips_test_interim_info {
193 enum file_types file_type;
194 enum fips_test_algorithms algo;
196 char *vec[MAX_LINE_PER_VECTOR];
197 uint32_t vec_start_off;
198 uint32_t nb_vec_lines;
199 char device_name[MAX_STRING_SIZE];
200 char file_name[MAX_FILE_NAME_SIZE];
204 struct aesavs_interim_data aes_data;
205 struct hmac_interim_data hmac_data;
206 struct tdes_interim_data tdes_data;
207 struct ccm_interim_data ccm_data;
208 struct sha_interim_data sha_data;
209 struct gcm_interim_data gcm_data;
212 enum fips_test_op op;
214 const struct fips_test_callback *callbacks;
215 const struct fips_test_callback *interim_callbacks;
216 const struct fips_test_callback *writeback_callbacks;
218 post_prcess_t parse_writeback;
219 post_prcess_t kat_check;
222 extern struct fips_test_vector vec;
223 extern struct fips_test_interim_info info;
225 #ifdef RTE_HAS_JANSSON
226 extern struct fips_test_json_info json_info;
227 #endif /* RTE_HAS_JANSSON */
230 fips_test_init(const char *req_file_path, const char *rsp_file_path,
231 const char *device_name);
234 fips_test_clear(void);
237 fips_test_fetch_one_block(void);
240 fips_test_parse_one_case(void);
243 fips_test_write_one_case(void);
245 #ifdef RTE_HAS_JANSSON
247 fips_test_parse_one_json_vector_set(void);
250 fips_test_parse_one_json_group(void);
253 fips_test_parse_one_json_case(void);
256 parse_test_gcm_json_init(void);
259 parse_test_hmac_json_init(void);
262 parse_test_hmac_json_algorithm(void);
265 parse_test_cmac_json_init(void);
268 parse_test_aes_json_init(void);
269 #endif /* RTE_HAS_JANSSON */
272 parse_test_aes_init(void);
275 parse_test_tdes_init(void);
278 parse_test_hmac_init(void);
281 parse_test_gcm_init(void);
284 parse_test_cmac_init(void);
287 parse_test_ccm_init(void);
290 parse_test_sha_init(void);
293 parse_test_xts_init(void);
296 parser_read_uint8_hex(uint8_t *value, const char *p);
299 parse_uint8_hex_str(const char *key, char *src, struct fips_val *val);
302 parse_uint8_known_len_hex_str(const char *key, char *src, struct fips_val *val);
305 parser_read_uint16(uint16_t *value, const char *p);
308 parser_read_uint32_val(const char *key, char *src, struct fips_val *val);
311 parser_read_uint32_bit_val(const char *key, char *src, struct fips_val *val);
314 parser_read_uint32(uint32_t *value, char *p);
317 parser_read_uint32_val(const char *key, char *src, struct fips_val *val);
320 writeback_hex_str(const char *key, char *dst, struct fips_val *val);
323 parse_write_hex_str(struct fips_val *src);
326 update_info_vec(uint32_t count);
328 typedef int (*fips_test_one_case_t)(void);
329 typedef int (*fips_prepare_op_t)(void);
330 typedef int (*fips_prepare_xform_t)(struct rte_crypto_sym_xform *);
332 struct fips_test_ops {
333 fips_prepare_xform_t prepare_xform;
334 fips_prepare_op_t prepare_op;
335 fips_test_one_case_t test;
338 extern struct fips_test_ops test_ops;
340 int prepare_aead_op(void);
342 int prepare_auth_op(void);
344 int prepare_gcm_xform(struct rte_crypto_sym_xform *xform);
346 int prepare_gmac_xform(struct rte_crypto_sym_xform *xform);