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