xref: /dpdk/examples/fips_validation/fips_validation.h (revision 527cbf3d5ee380f49db828957de4ba75f71e4311)
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_HMAC,
28 		FIPS_TEST_ALGO_TDES,
29 		FIPS_TEST_ALGO_MAX
30 };
31 
32 enum file_types {
33 	FIPS_TYPE_REQ = 1,
34 	FIPS_TYPE_FAX,
35 	FIPS_TYPE_RSP
36 };
37 
38 enum fips_test_op {
39 	FIPS_TEST_ENC_AUTH_GEN = 1,
40 	FIPS_TEST_DEC_AUTH_VERIF,
41 };
42 
43 #define MAX_LINE_PER_VECTOR            16
44 
45 struct fips_val {
46 	uint8_t *val;
47 	uint32_t len;
48 };
49 
50 struct fips_test_vector {
51 	union {
52 		struct {
53 			struct fips_val key;
54 			struct fips_val digest;
55 			struct fips_val auth_aad;
56 			struct fips_val aad;
57 		} cipher_auth;
58 		struct {
59 			struct fips_val key;
60 			struct fips_val digest;
61 			struct fips_val aad;
62 		} aead;
63 	};
64 
65 	struct fips_val pt;
66 	struct fips_val ct;
67 	struct fips_val iv;
68 
69 	enum rte_crypto_op_status status;
70 };
71 
72 typedef int (*post_prcess_t)(struct fips_val *val);
73 
74 typedef int (*parse_callback_t)(const char *key, char *text,
75 		struct fips_val *val);
76 
77 struct fips_test_callback {
78 	const char *key;
79 	parse_callback_t cb;
80 	struct fips_val *val;
81 };
82 
83 enum fips_aesavs_test_types {
84 	AESAVS_TYPE_GFXBOX = 1,
85 	AESAVS_TYPE_KEYSBOX,
86 	AESAVS_TYPE_VARKEY,
87 	AESAVS_TYPE_VARTXT,
88 	AESAVS_TYPE_MMT,
89 	AESAVS_TYPE_MCT,
90 };
91 
92 enum fips_tdes_test_types {
93 	TDES_INVERSE_PERMUTATION = 0,
94 	TDES_PERMUTATION,
95 	TDES_SUBSTITUTION_TABLE,
96 	TDES_VARIABLE_KEY,
97 	TDES_VARIABLE_TEXT,
98 	TDES_KAT,
99 	TDES_MCT, /* Monte Carlo (Modes) Test */
100 	TDES_MMT /* Multi block Message Test */
101 };
102 
103 struct aesavs_interim_data {
104 	enum fips_aesavs_test_types test_type;
105 	uint32_t cipher_algo;
106 	uint32_t key_len;
107 };
108 
109 struct hmac_interim_data {
110 	enum rte_crypto_auth_algorithm algo;
111 };
112 
113 struct tdes_interim_data {
114 	enum fips_tdes_test_types test_type;
115 	uint32_t nb_keys;
116 };
117 
118 struct fips_test_interim_info {
119 	FILE *fp_rd;
120 	FILE *fp_wr;
121 	enum file_types file_type;
122 	enum fips_test_algorithms algo;
123 	char *one_line_text;
124 	char *vec[MAX_LINE_PER_VECTOR];
125 	uint32_t nb_vec_lines;
126 	char device_name[MAX_STRING_SIZE];
127 
128 	union {
129 		struct aesavs_interim_data aes_data;
130 		struct hmac_interim_data hmac_data;
131 		struct tdes_interim_data tdes_data;
132 
133 	} interim_info;
134 
135 	enum fips_test_op op;
136 
137 	const struct fips_test_callback *callbacks;
138 	const struct fips_test_callback *interim_callbacks;
139 	const struct fips_test_callback *writeback_callbacks;
140 
141 	post_prcess_t parse_writeback;
142 	post_prcess_t kat_check;
143 };
144 
145 extern struct fips_test_vector vec;
146 extern struct fips_test_interim_info info;
147 
148 int
149 fips_test_init(const char *req_file_path, const char *rsp_file_path,
150 		const char *device_name);
151 
152 void
153 fips_test_clear(void);
154 
155 int
156 fips_test_fetch_one_block(void);
157 
158 int
159 fips_test_parse_one_case(void);
160 
161 void
162 fips_test_write_one_case(void);
163 
164 int
165 parse_test_aes_init(void);
166 
167 int
168 parse_test_tdes_init(void);
169 
170 int
171 parse_test_hmac_init(void);
172 
173 int
174 parser_read_uint8_hex(uint8_t *value, const char *p);
175 
176 int
177 parse_uint8_hex_str(const char *key, char *src, struct fips_val *val);
178 
179 int
180 parse_uint8_known_len_hex_str(const char *key, char *src, struct fips_val *val);
181 
182 int
183 parser_read_uint32_val(const char *key, char *src, struct fips_val *val);
184 
185 int
186 parser_read_uint32_bit_val(const char *key, char *src, struct fips_val *val);
187 
188 int
189 parser_read_uint32(uint32_t *value, char *p);
190 
191 int
192 parser_read_uint32_val(const char *key, char *src, struct fips_val *val);
193 
194 int
195 writeback_hex_str(const char *key, char *dst, struct fips_val *val);
196 
197 void
198 parse_write_hex_str(struct fips_val *src);
199 
200 int
201 update_info_vec(uint32_t count);
202 
203 #endif
204