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