1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
5 #ifndef _FIPS_VALIDATION_H_
6 #define _FIPS_VALIDATION_H_
8 #define FIPS_PARSE_ERR(fmt, args) \
9 RTE_LOG(ERR, USER1, "FIPS parse error" ## fmt ## "\n", ## args)
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
18 #define POSITIVE_TEST 0
19 #define NEGATIVE_TEST -1
21 #define REQ_FILE_PERFIX "req"
22 #define RSP_FILE_PERFIX "rsp"
23 #define FAX_FILE_PERFIX "fax"
25 enum fips_test_algorithms {
26 FIPS_TEST_ALGO_AES = 0,
27 FIPS_TEST_ALGO_AES_GCM,
28 FIPS_TEST_ALGO_AES_CMAC,
29 FIPS_TEST_ALGO_AES_CCM,
42 FIPS_TEST_ENC_AUTH_GEN = 1,
43 FIPS_TEST_DEC_AUTH_VERIF,
46 #define MAX_LINE_PER_VECTOR 16
53 struct fips_test_vector {
57 struct fips_val digest;
58 struct fips_val auth_aad;
63 struct fips_val digest;
72 enum rte_crypto_op_status status;
75 typedef int (*post_prcess_t)(struct fips_val *val);
77 typedef int (*parse_callback_t)(const char *key, char *text,
78 struct fips_val *val);
80 struct fips_test_callback {
86 enum fips_aesavs_test_types {
87 AESAVS_TYPE_GFXBOX = 1,
95 enum fips_tdes_test_types {
96 TDES_INVERSE_PERMUTATION = 0,
98 TDES_SUBSTITUTION_TABLE,
102 TDES_MCT, /* Monte Carlo (Modes) Test */
103 TDES_MMT /* Multi block Message Test */
106 enum fips_ccm_test_types {
107 CCM_VADT = 1, /* Variable Associated Data Test */
108 CCM_VPT, /* Variable Payload Test */
109 CCM_VNT, /* Variable Nonce Test */
110 CCM_VTT, /* Variable Tag Test */
111 CCM_DVPT, /* Decryption-Verification Process Test */
114 struct aesavs_interim_data {
115 enum fips_aesavs_test_types test_type;
116 uint32_t cipher_algo;
120 struct hmac_interim_data {
121 enum rte_crypto_auth_algorithm algo;
124 struct tdes_interim_data {
125 enum fips_tdes_test_types test_type;
129 struct ccm_interim_data {
130 enum fips_ccm_test_types test_type;
138 struct fips_test_interim_info {
141 enum file_types file_type;
142 enum fips_test_algorithms algo;
144 char *vec[MAX_LINE_PER_VECTOR];
145 uint32_t nb_vec_lines;
146 char device_name[MAX_STRING_SIZE];
149 struct aesavs_interim_data aes_data;
150 struct hmac_interim_data hmac_data;
151 struct tdes_interim_data tdes_data;
152 struct ccm_interim_data ccm_data;
156 enum fips_test_op op;
158 const struct fips_test_callback *callbacks;
159 const struct fips_test_callback *interim_callbacks;
160 const struct fips_test_callback *writeback_callbacks;
162 post_prcess_t parse_writeback;
163 post_prcess_t kat_check;
166 extern struct fips_test_vector vec;
167 extern struct fips_test_interim_info info;
170 fips_test_init(const char *req_file_path, const char *rsp_file_path,
171 const char *device_name);
174 fips_test_clear(void);
177 fips_test_fetch_one_block(void);
180 fips_test_parse_one_case(void);
183 fips_test_write_one_case(void);
186 parse_test_aes_init(void);
189 parse_test_tdes_init(void);
192 parse_test_hmac_init(void);
195 parse_test_gcm_init(void);
198 parse_test_cmac_init(void);
201 parse_test_ccm_init(void);
204 parser_read_uint8_hex(uint8_t *value, const char *p);
207 parse_uint8_hex_str(const char *key, char *src, struct fips_val *val);
210 parse_uint8_known_len_hex_str(const char *key, char *src, struct fips_val *val);
213 parser_read_uint32_val(const char *key, char *src, struct fips_val *val);
216 parser_read_uint32_bit_val(const char *key, char *src, struct fips_val *val);
219 parser_read_uint32(uint32_t *value, char *p);
222 parser_read_uint32_val(const char *key, char *src, struct fips_val *val);
225 writeback_hex_str(const char *key, char *dst, struct fips_val *val);
228 parse_write_hex_str(struct fips_val *src);
231 update_info_vec(uint32_t count);