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,
108 enum fips_tdes_test_types {
109 TDES_INVERSE_PERMUTATION = 0,
111 TDES_SUBSTITUTION_TABLE,
115 TDES_MCT, /* Monte Carlo (Modes) Test */
116 TDES_MMT /* Multi block Message Test */
119 enum fips_tdes_test_mode {
124 enum fips_ccm_test_types {
125 CCM_VADT = 1, /* Variable Associated Data Test */
126 CCM_VPT, /* Variable Payload Test */
127 CCM_VNT, /* Variable Nonce Test */
128 CCM_VTT, /* Variable Tag Test */
129 CCM_DVPT, /* Decryption-Verification Process Test */
132 enum fips_sha_test_types {
137 struct aesavs_interim_data {
138 enum fips_aesavs_test_types test_type;
139 uint32_t cipher_algo;
143 struct hmac_interim_data {
144 enum rte_crypto_auth_algorithm algo;
147 struct tdes_interim_data {
148 enum fips_tdes_test_types test_type;
149 enum fips_tdes_test_mode test_mode;
153 struct ccm_interim_data {
154 enum fips_ccm_test_types test_type;
162 struct sha_interim_data {
163 enum fips_sha_test_types test_type;
164 enum rte_crypto_auth_algorithm algo;
167 struct gcm_interim_data {
172 #ifdef RTE_HAS_JANSSON
173 struct fips_test_json_info {
174 /* Information used for reading from json */
176 json_t *json_vector_set;
177 json_t *json_test_group;
178 json_t *json_test_case;
179 /* Location of json write output */
180 json_t *json_write_root;
181 json_t *json_write_group;
182 json_t *json_write_set;
183 json_t *json_write_case;
187 #endif /* RTE_HAS_JANSSON */
189 struct fips_test_interim_info {
192 enum file_types file_type;
193 enum fips_test_algorithms algo;
195 char *vec[MAX_LINE_PER_VECTOR];
196 uint32_t vec_start_off;
197 uint32_t nb_vec_lines;
198 char device_name[MAX_STRING_SIZE];
199 char file_name[MAX_FILE_NAME_SIZE];
203 struct aesavs_interim_data aes_data;
204 struct hmac_interim_data hmac_data;
205 struct tdes_interim_data tdes_data;
206 struct ccm_interim_data ccm_data;
207 struct sha_interim_data sha_data;
208 struct gcm_interim_data gcm_data;
211 enum fips_test_op op;
213 const struct fips_test_callback *callbacks;
214 const struct fips_test_callback *interim_callbacks;
215 const struct fips_test_callback *writeback_callbacks;
217 post_prcess_t parse_writeback;
218 post_prcess_t kat_check;
221 extern struct fips_test_vector vec;
222 extern struct fips_test_interim_info info;
224 #ifdef RTE_HAS_JANSSON
225 extern struct fips_test_json_info json_info;
226 #endif /* RTE_HAS_JANSSON */
229 fips_test_init(const char *req_file_path, const char *rsp_file_path,
230 const char *device_name);
233 fips_test_clear(void);
236 fips_test_fetch_one_block(void);
239 fips_test_parse_one_case(void);
242 fips_test_write_one_case(void);
244 #ifdef RTE_HAS_JANSSON
246 fips_test_parse_one_json_vector_set(void);
249 fips_test_parse_one_json_group(void);
252 fips_test_parse_one_json_case(void);
255 parse_test_gcm_json_init(void);
256 #endif /* RTE_HAS_JANSSON */
259 parse_test_aes_init(void);
262 parse_test_tdes_init(void);
265 parse_test_hmac_init(void);
268 parse_test_gcm_init(void);
271 parse_test_cmac_init(void);
274 parse_test_ccm_init(void);
277 parse_test_sha_init(void);
280 parse_test_xts_init(void);
283 parser_read_uint8_hex(uint8_t *value, const char *p);
286 parse_uint8_hex_str(const char *key, char *src, struct fips_val *val);
289 parse_uint8_known_len_hex_str(const char *key, char *src, struct fips_val *val);
292 parser_read_uint16(uint16_t *value, const char *p);
295 parser_read_uint32_val(const char *key, char *src, struct fips_val *val);
298 parser_read_uint32_bit_val(const char *key, char *src, struct fips_val *val);
301 parser_read_uint32(uint32_t *value, char *p);
304 parser_read_uint32_val(const char *key, char *src, struct fips_val *val);
307 writeback_hex_str(const char *key, char *dst, struct fips_val *val);
310 parse_write_hex_str(struct fips_val *src);
313 update_info_vec(uint32_t count);
315 typedef int (*fips_test_one_case_t)(void);
316 typedef int (*fips_prepare_op_t)(void);
317 typedef int (*fips_prepare_xform_t)(struct rte_crypto_sym_xform *);
319 struct fips_test_ops {
320 fips_prepare_xform_t prepare_xform;
321 fips_prepare_op_t prepare_op;
322 fips_test_one_case_t test;
325 extern struct fips_test_ops test_ops;
327 int prepare_aead_op(void);
329 int prepare_auth_op(void);
331 int prepare_gcm_xform(struct rte_crypto_sym_xform *xform);
333 int prepare_gmac_xform(struct rte_crypto_sym_xform *xform);