examples/fips_validation: add crypto FIPS application
[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_MAX
27 };
28
29 enum file_types {
30         FIPS_TYPE_REQ = 1,
31         FIPS_TYPE_FAX,
32         FIPS_TYPE_RSP
33 };
34
35 enum fips_test_op {
36         FIPS_TEST_ENC_AUTH_GEN = 1,
37         FIPS_TEST_DEC_AUTH_VERIF,
38 };
39
40 #define MAX_LINE_PER_VECTOR            16
41
42 struct fips_val {
43         uint8_t *val;
44         uint32_t len;
45 };
46
47 struct fips_test_vector {
48         union {
49                 struct {
50                         struct fips_val key;
51                         struct fips_val digest;
52                         struct fips_val auth_aad;
53                         struct fips_val aad;
54                 } cipher_auth;
55                 struct {
56                         struct fips_val key;
57                         struct fips_val digest;
58                         struct fips_val aad;
59                 } aead;
60         };
61
62         struct fips_val pt;
63         struct fips_val ct;
64         struct fips_val iv;
65
66         enum rte_crypto_op_status status;
67 };
68
69 typedef int (*post_prcess_t)(struct fips_val *val);
70
71 typedef int (*parse_callback_t)(const char *key, char *text,
72                 struct fips_val *val);
73
74 struct fips_test_callback {
75         const char *key;
76         parse_callback_t cb;
77         struct fips_val *val;
78 };
79
80 struct fips_test_interim_info {
81         FILE *fp_rd;
82         FILE *fp_wr;
83         enum file_types file_type;
84         enum fips_test_algorithms algo;
85         char *one_line_text;
86         char *vec[MAX_LINE_PER_VECTOR];
87         uint32_t nb_vec_lines;
88         char device_name[MAX_STRING_SIZE];
89
90         enum fips_test_op op;
91
92         const struct fips_test_callback *callbacks;
93         const struct fips_test_callback *interim_callbacks;
94         const struct fips_test_callback *writeback_callbacks;
95
96         post_prcess_t parse_writeback;
97         post_prcess_t kat_check;
98 };
99
100 extern struct fips_test_vector vec;
101 extern struct fips_test_interim_info info;
102
103 int
104 fips_test_init(const char *req_file_path, const char *rsp_file_path,
105                 const char *device_name);
106
107 void
108 fips_test_clear(void);
109
110 int
111 fips_test_fetch_one_block(void);
112
113 int
114 fips_test_parse_one_case(void);
115
116 void
117 fips_test_write_one_case(void);
118
119 int
120 parser_read_uint8_hex(uint8_t *value, const char *p);
121
122 int
123 parse_uint8_hex_str(const char *key, char *src, struct fips_val *val);
124
125 int
126 parse_uint8_known_len_hex_str(const char *key, char *src, struct fips_val *val);
127
128 int
129 parser_read_uint32_val(const char *key, char *src, struct fips_val *val);
130
131 int
132 parser_read_uint32_bit_val(const char *key, char *src, struct fips_val *val);
133
134 int
135 parser_read_uint32(uint32_t *value, char *p);
136
137 int
138 parser_read_uint32_val(const char *key, char *src, struct fips_val *val);
139
140 int
141 writeback_hex_str(const char *key, char *dst, struct fips_val *val);
142
143 void
144 parse_write_hex_str(struct fips_val *src);
145
146 int
147 update_info_vec(uint32_t count);
148
149 #endif