1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
8 #include <rte_string_fns.h>
9 #include <rte_cryptodev.h>
10 #include <rte_malloc.h>
12 #include "fips_validation.h"
14 #define DVPT_STR "CCM-DVPT"
15 #define VADT_STR "CCM-VADT"
16 #define VPT_STR "CCM-VPT"
17 #define VNT_STR "CCM-VNT"
18 #define VTT_STR "CCM-VTT"
20 #define PARAM_PREFIX "["
21 #define ALEN_PREFIX "Alen = "
22 #define PLEN_PREFIX "Plen = "
23 #define IVLEN_PREFIX "Nlen = "
24 #define DIGESTL_PREFIX "Tlen = "
26 #define COUNT_STR "Count = "
27 #define KEY_STR "Key = "
28 #define IV_STR "Nonce = "
29 #define PT_STR "Payload = "
30 #define CT_STR "CT = "
31 #define AAD_STR "Adata = "
32 #define POS_NEG_STR "Result = "
34 #define POS_KEYWORD "Pass"
35 #define NEG_KEYWORD "Fail"
38 parser_dvpt_interim(const char *key, char *src, struct fips_val *val)
40 char *tmp, c, value[10];
41 char num_pattern[] = "0123456789";
46 tmp = strstr(src, key);
54 while (strchr(num_pattern, c) && i < 10) {
59 return parser_read_uint32_val("", value, val);
63 parse_dvpt_ct_hex_str(const char *key, char *src, struct fips_val *val)
67 val->len = vec.pt.len;
69 ret = parse_uint8_known_len_hex_str(key, src, val);
73 src += strlen(key) + val->len * 2;
75 ret = parse_uint8_known_len_hex_str("", src, &vec.aead.digest);
78 memset(val, 0, sizeof(*val));
86 parse_uint8_ccm_aad_str(const char *key, char *src, struct fips_val *val)
88 uint32_t len = val->len, j;
92 /* CCM aad requires 18 bytes padding before the real content */
93 val->val = rte_zmalloc(NULL, len + 18, 0);
97 for (j = 0; j < len; j++) {
98 char byte[3] = {src[j * 2], src[j * 2 + 1], '\0'};
100 if (parser_read_uint8_hex(&val->val[j + 18], byte) < 0) {
102 memset(val, 0, sizeof(*val));
110 struct fips_test_callback ccm_vnt_vec[] = {
111 {IV_STR, parse_uint8_known_len_hex_str, &vec.iv},
112 {AAD_STR, parse_uint8_ccm_aad_str, &vec.aead.aad},
113 {PT_STR, parse_uint8_known_len_hex_str, &vec.pt},
114 {NULL, NULL, NULL} /**< end pointer */
117 struct fips_test_callback ccm_vnt_interim_vec[] = {
118 {ALEN_PREFIX, parser_read_uint32_val, &vec.aead.aad},
119 {PLEN_PREFIX, parser_read_uint32_val, &vec.pt},
120 {DIGESTL_PREFIX, parser_read_uint32_val, &vec.aead.digest},
121 {IVLEN_PREFIX, parser_read_uint32_val, &vec.iv},
122 {KEY_STR, parse_uint8_hex_str, &vec.aead.key},
123 {NULL, NULL, NULL} /**< end pointer */
126 struct fips_test_callback ccm_vtt_vec[] = {
127 {AAD_STR, parse_uint8_ccm_aad_str, &vec.aead.aad},
128 {PT_STR, parse_uint8_known_len_hex_str, &vec.pt},
129 {NULL, NULL, NULL} /**< end pointer */
132 struct fips_test_callback ccm_vtt_interim_vec[] = {
133 {ALEN_PREFIX, parser_read_uint32_val, &vec.aead.aad},
134 {PLEN_PREFIX, parser_read_uint32_val, &vec.pt},
135 {IVLEN_PREFIX, parser_read_uint32_val, &vec.iv},
136 {DIGESTL_PREFIX, parser_read_uint32_val, &vec.aead.digest},
137 {KEY_STR, parse_uint8_hex_str, &vec.aead.key},
138 {IV_STR, parse_uint8_known_len_hex_str, &vec.iv},
139 {NULL, NULL, NULL} /**< end pointer */
142 struct fips_test_callback ccm_vadt_vec[] = {
143 {AAD_STR, parse_uint8_ccm_aad_str, &vec.aead.aad},
144 {PT_STR, parse_uint8_known_len_hex_str, &vec.pt},
145 {NULL, NULL, NULL} /**< end pointer */
148 struct fips_test_callback ccm_vadt_interim_vec[] = {
149 {PLEN_PREFIX, parser_read_uint32_val, &vec.pt},
150 {IVLEN_PREFIX, parser_read_uint32_val, &vec.iv},
151 {ALEN_PREFIX, parser_read_uint32_val, &vec.aead.aad},
152 {DIGESTL_PREFIX, parser_read_uint32_val, &vec.aead.digest},
153 {KEY_STR, parse_uint8_hex_str, &vec.aead.key},
154 {IV_STR, parse_uint8_known_len_hex_str, &vec.iv},
155 {NULL, NULL, NULL} /**< end pointer */
158 struct fips_test_callback ccm_vpt_vec[] = {
159 {AAD_STR, parse_uint8_ccm_aad_str, &vec.aead.aad},
160 {PT_STR, parse_uint8_known_len_hex_str, &vec.pt},
161 {NULL, NULL, NULL} /**< end pointer */
164 struct fips_test_callback ccm_vpt_interim_vec[] = {
165 {ALEN_PREFIX, parser_read_uint32_val, &vec.aead.aad},
166 {IVLEN_PREFIX, parser_read_uint32_val, &vec.iv},
167 {DIGESTL_PREFIX, parser_read_uint32_val, &vec.aead.digest},
168 {PLEN_PREFIX, parser_read_uint32_val, &vec.pt},
169 {KEY_STR, parse_uint8_hex_str, &vec.aead.key},
170 {IV_STR, parse_uint8_known_len_hex_str, &vec.iv},
171 {NULL, NULL, NULL} /**< end pointer */
174 struct fips_test_callback ccm_dvpt_vec[] = {
175 {IV_STR, parse_uint8_known_len_hex_str, &vec.iv},
176 {AAD_STR, parse_uint8_ccm_aad_str, &vec.aead.aad},
177 {CT_STR, parse_dvpt_ct_hex_str, &vec.ct},
178 {NULL, NULL, NULL} /**< end pointer */
181 struct fips_test_callback ccm_dvpt_interim_vec[] = {
182 {ALEN_PREFIX, parser_dvpt_interim, &vec.aead.aad},
183 {PLEN_PREFIX, parser_dvpt_interim, &vec.pt},
184 {IVLEN_PREFIX, parser_dvpt_interim, &vec.iv},
185 {DIGESTL_PREFIX, parser_dvpt_interim, &vec.aead.digest},
186 {KEY_STR, parse_uint8_hex_str, &vec.aead.key},
187 {NULL, NULL, NULL} /**< end pointer */
190 struct ccm_test_types {
193 const struct fips_test_callback *cb;
194 const struct fips_test_callback *cb_interim;
195 enum fips_test_op op;
197 {DVPT_STR, CCM_DVPT, ccm_dvpt_vec, ccm_dvpt_interim_vec,
198 FIPS_TEST_DEC_AUTH_VERIF},
199 {VPT_STR, CCM_VPT, ccm_vpt_vec, ccm_vpt_interim_vec,
200 FIPS_TEST_ENC_AUTH_GEN},
201 {VADT_STR, CCM_VADT, ccm_vadt_vec, ccm_vadt_interim_vec,
202 FIPS_TEST_ENC_AUTH_GEN},
203 {VNT_STR, CCM_VNT, ccm_vnt_vec, ccm_vnt_interim_vec,
204 FIPS_TEST_ENC_AUTH_GEN},
205 {VTT_STR, CCM_VTT, ccm_vtt_vec, ccm_vtt_interim_vec,
206 FIPS_TEST_ENC_AUTH_GEN},
210 parse_test_ccm_writeback(struct fips_val *val)
212 struct fips_val tmp_val;
214 switch (info.interim_info.ccm_data.test_type) {
216 fprintf(info.fp_wr, "%s", POS_NEG_STR);
217 if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) {
218 fprintf(info.fp_wr, "%s\n", POS_KEYWORD);
219 fprintf(info.fp_wr, "%s", PT_STR);
221 tmp_val.val = val->val;
222 tmp_val.len = vec.pt.len;
224 if (tmp_val.len == 0)
225 fprintf(info.fp_wr, "00\n");
227 parse_write_hex_str(&tmp_val);
229 fprintf(info.fp_wr, "%s\n", NEG_KEYWORD);
237 fprintf(info.fp_wr, "%s", CT_STR);
239 parse_write_hex_str(val);
249 parse_test_ccm_init(void)
254 for (i = 0; i < info.nb_vec_lines; i++) {
255 char *line = info.vec[i];
258 for (j = 0; j < RTE_DIM(ctt); j++)
259 if (strstr(line, ctt[j].str)) {
260 info.interim_info.ccm_data.test_type =
262 info.callbacks = ctt[j].cb;
263 info.interim_callbacks = ctt[j].cb_interim;
269 info.parse_writeback = parse_test_ccm_writeback;