1305921f4SMarko Kovacevic /* SPDX-License-Identifier: BSD-3-Clause
2305921f4SMarko Kovacevic * Copyright(c) 2018 Intel Corporation
3305921f4SMarko Kovacevic */
4305921f4SMarko Kovacevic
5305921f4SMarko Kovacevic #include <stdio.h>
6305921f4SMarko Kovacevic #include <string.h>
7305921f4SMarko Kovacevic
8305921f4SMarko Kovacevic #include <rte_string_fns.h>
9305921f4SMarko Kovacevic #include <rte_cryptodev.h>
10305921f4SMarko Kovacevic #include <rte_malloc.h>
11305921f4SMarko Kovacevic
12305921f4SMarko Kovacevic #include "fips_validation.h"
13305921f4SMarko Kovacevic
14305921f4SMarko Kovacevic #define DVPT_STR "CCM-DVPT"
15305921f4SMarko Kovacevic #define VADT_STR "CCM-VADT"
16305921f4SMarko Kovacevic #define VPT_STR "CCM-VPT"
17305921f4SMarko Kovacevic #define VNT_STR "CCM-VNT"
18305921f4SMarko Kovacevic #define VTT_STR "CCM-VTT"
19305921f4SMarko Kovacevic
20305921f4SMarko Kovacevic #define PARAM_PREFIX "["
21305921f4SMarko Kovacevic #define ALEN_PREFIX "Alen = "
22305921f4SMarko Kovacevic #define PLEN_PREFIX "Plen = "
23305921f4SMarko Kovacevic #define IVLEN_PREFIX "Nlen = "
24305921f4SMarko Kovacevic #define DIGESTL_PREFIX "Tlen = "
25305921f4SMarko Kovacevic
26305921f4SMarko Kovacevic #define COUNT_STR "Count = "
27305921f4SMarko Kovacevic #define KEY_STR "Key = "
28305921f4SMarko Kovacevic #define IV_STR "Nonce = "
29305921f4SMarko Kovacevic #define PT_STR "Payload = "
30305921f4SMarko Kovacevic #define CT_STR "CT = "
31305921f4SMarko Kovacevic #define AAD_STR "Adata = "
32305921f4SMarko Kovacevic #define POS_NEG_STR "Result = "
33305921f4SMarko Kovacevic
34305921f4SMarko Kovacevic #define POS_KEYWORD "Pass"
35305921f4SMarko Kovacevic #define NEG_KEYWORD "Fail"
36305921f4SMarko Kovacevic
37*55a7050eSGowrishankar Muthukrishnan #define DIR_JSON_STR "direction"
38*55a7050eSGowrishankar Muthukrishnan #define IVLEN_JSON_STR "ivLen"
39*55a7050eSGowrishankar Muthukrishnan #define PTLEN_JSON_STR "payloadLen"
40*55a7050eSGowrishankar Muthukrishnan #define AADLEN_JSON_STR "aadLen"
41*55a7050eSGowrishankar Muthukrishnan #define TAGLEN_JSON_STR "tagLen"
42*55a7050eSGowrishankar Muthukrishnan #define KEYLEN_JSON_STR "keyLen"
43*55a7050eSGowrishankar Muthukrishnan #define PT_JSON_STR "pt"
44*55a7050eSGowrishankar Muthukrishnan #define CT_JSON_STR "ct"
45*55a7050eSGowrishankar Muthukrishnan #define KEY_JSON_STR "key"
46*55a7050eSGowrishankar Muthukrishnan #define IV_JSON_STR "iv"
47*55a7050eSGowrishankar Muthukrishnan #define AAD_JSON_STR "aad"
48*55a7050eSGowrishankar Muthukrishnan
49305921f4SMarko Kovacevic static int
parser_dvpt_interim(const char * key,char * src,struct fips_val * val)50305921f4SMarko Kovacevic parser_dvpt_interim(const char *key, char *src, struct fips_val *val)
51305921f4SMarko Kovacevic {
52305921f4SMarko Kovacevic char *tmp, c, value[10];
53305921f4SMarko Kovacevic char num_pattern[] = "0123456789";
54305921f4SMarko Kovacevic int i = 0;
55305921f4SMarko Kovacevic
56305921f4SMarko Kovacevic memset(value, 0, 10);
57305921f4SMarko Kovacevic
58305921f4SMarko Kovacevic tmp = strstr(src, key);
59305921f4SMarko Kovacevic if (!tmp)
60305921f4SMarko Kovacevic return -1;
61305921f4SMarko Kovacevic
62305921f4SMarko Kovacevic tmp += strlen(key);
63305921f4SMarko Kovacevic
64305921f4SMarko Kovacevic c = tmp[0];
65305921f4SMarko Kovacevic
66305921f4SMarko Kovacevic while (strchr(num_pattern, c) && i < 10) {
67305921f4SMarko Kovacevic value[i++] = c;
68305921f4SMarko Kovacevic c = tmp[i];
69305921f4SMarko Kovacevic }
70305921f4SMarko Kovacevic
71305921f4SMarko Kovacevic return parser_read_uint32_val("", value, val);
72305921f4SMarko Kovacevic }
73305921f4SMarko Kovacevic
74305921f4SMarko Kovacevic static int
parse_dvpt_ct_hex_str(const char * key,char * src,struct fips_val * val)75305921f4SMarko Kovacevic parse_dvpt_ct_hex_str(const char *key, char *src, struct fips_val *val)
76305921f4SMarko Kovacevic {
77305921f4SMarko Kovacevic int ret;
78305921f4SMarko Kovacevic
79305921f4SMarko Kovacevic val->len = vec.pt.len;
80305921f4SMarko Kovacevic
81305921f4SMarko Kovacevic ret = parse_uint8_known_len_hex_str(key, src, val);
82305921f4SMarko Kovacevic if (ret < 0)
83305921f4SMarko Kovacevic return ret;
84305921f4SMarko Kovacevic
85305921f4SMarko Kovacevic src += strlen(key) + val->len * 2;
86305921f4SMarko Kovacevic
87305921f4SMarko Kovacevic ret = parse_uint8_known_len_hex_str("", src, &vec.aead.digest);
88305921f4SMarko Kovacevic if (ret < 0) {
89305921f4SMarko Kovacevic rte_free(val->val);
90305921f4SMarko Kovacevic memset(val, 0, sizeof(*val));
91305921f4SMarko Kovacevic return ret;
92305921f4SMarko Kovacevic }
93305921f4SMarko Kovacevic
94305921f4SMarko Kovacevic return 0;
95305921f4SMarko Kovacevic }
96305921f4SMarko Kovacevic
97305921f4SMarko Kovacevic static int
parse_uint8_ccm_aad_str(const char * key,char * src,struct fips_val * val)98305921f4SMarko Kovacevic parse_uint8_ccm_aad_str(const char *key, char *src, struct fips_val *val)
99305921f4SMarko Kovacevic {
100305921f4SMarko Kovacevic uint32_t len = val->len, j;
101305921f4SMarko Kovacevic
102305921f4SMarko Kovacevic src += strlen(key);
103305921f4SMarko Kovacevic
104305921f4SMarko Kovacevic /* CCM aad requires 18 bytes padding before the real content */
105305921f4SMarko Kovacevic val->val = rte_zmalloc(NULL, len + 18, 0);
106305921f4SMarko Kovacevic if (!val->val)
107305921f4SMarko Kovacevic return -1;
108305921f4SMarko Kovacevic
109305921f4SMarko Kovacevic for (j = 0; j < len; j++) {
110305921f4SMarko Kovacevic char byte[3] = {src[j * 2], src[j * 2 + 1], '\0'};
111305921f4SMarko Kovacevic
112305921f4SMarko Kovacevic if (parser_read_uint8_hex(&val->val[j + 18], byte) < 0) {
113305921f4SMarko Kovacevic rte_free(val->val);
114305921f4SMarko Kovacevic memset(val, 0, sizeof(*val));
115305921f4SMarko Kovacevic return -EINVAL;
116305921f4SMarko Kovacevic }
117305921f4SMarko Kovacevic }
118305921f4SMarko Kovacevic
119305921f4SMarko Kovacevic return 0;
120305921f4SMarko Kovacevic }
121305921f4SMarko Kovacevic
122305921f4SMarko Kovacevic struct fips_test_callback ccm_vnt_vec[] = {
123305921f4SMarko Kovacevic {IV_STR, parse_uint8_known_len_hex_str, &vec.iv},
124305921f4SMarko Kovacevic {AAD_STR, parse_uint8_ccm_aad_str, &vec.aead.aad},
125305921f4SMarko Kovacevic {PT_STR, parse_uint8_known_len_hex_str, &vec.pt},
126305921f4SMarko Kovacevic {NULL, NULL, NULL} /**< end pointer */
127305921f4SMarko Kovacevic };
128305921f4SMarko Kovacevic
129305921f4SMarko Kovacevic struct fips_test_callback ccm_vnt_interim_vec[] = {
130305921f4SMarko Kovacevic {ALEN_PREFIX, parser_read_uint32_val, &vec.aead.aad},
131305921f4SMarko Kovacevic {PLEN_PREFIX, parser_read_uint32_val, &vec.pt},
132305921f4SMarko Kovacevic {DIGESTL_PREFIX, parser_read_uint32_val, &vec.aead.digest},
133305921f4SMarko Kovacevic {IVLEN_PREFIX, parser_read_uint32_val, &vec.iv},
134305921f4SMarko Kovacevic {KEY_STR, parse_uint8_hex_str, &vec.aead.key},
135305921f4SMarko Kovacevic {NULL, NULL, NULL} /**< end pointer */
136305921f4SMarko Kovacevic };
137305921f4SMarko Kovacevic
138305921f4SMarko Kovacevic struct fips_test_callback ccm_vtt_vec[] = {
139305921f4SMarko Kovacevic {AAD_STR, parse_uint8_ccm_aad_str, &vec.aead.aad},
140305921f4SMarko Kovacevic {PT_STR, parse_uint8_known_len_hex_str, &vec.pt},
141305921f4SMarko Kovacevic {NULL, NULL, NULL} /**< end pointer */
142305921f4SMarko Kovacevic };
143305921f4SMarko Kovacevic
144305921f4SMarko Kovacevic struct fips_test_callback ccm_vtt_interim_vec[] = {
145305921f4SMarko Kovacevic {ALEN_PREFIX, parser_read_uint32_val, &vec.aead.aad},
146305921f4SMarko Kovacevic {PLEN_PREFIX, parser_read_uint32_val, &vec.pt},
147305921f4SMarko Kovacevic {IVLEN_PREFIX, parser_read_uint32_val, &vec.iv},
148305921f4SMarko Kovacevic {DIGESTL_PREFIX, parser_read_uint32_val, &vec.aead.digest},
149305921f4SMarko Kovacevic {KEY_STR, parse_uint8_hex_str, &vec.aead.key},
150305921f4SMarko Kovacevic {IV_STR, parse_uint8_known_len_hex_str, &vec.iv},
151305921f4SMarko Kovacevic {NULL, NULL, NULL} /**< end pointer */
152305921f4SMarko Kovacevic };
153305921f4SMarko Kovacevic
154305921f4SMarko Kovacevic struct fips_test_callback ccm_vadt_vec[] = {
155305921f4SMarko Kovacevic {AAD_STR, parse_uint8_ccm_aad_str, &vec.aead.aad},
156305921f4SMarko Kovacevic {PT_STR, parse_uint8_known_len_hex_str, &vec.pt},
157305921f4SMarko Kovacevic {NULL, NULL, NULL} /**< end pointer */
158305921f4SMarko Kovacevic };
159305921f4SMarko Kovacevic
160305921f4SMarko Kovacevic struct fips_test_callback ccm_vadt_interim_vec[] = {
161305921f4SMarko Kovacevic {PLEN_PREFIX, parser_read_uint32_val, &vec.pt},
162305921f4SMarko Kovacevic {IVLEN_PREFIX, parser_read_uint32_val, &vec.iv},
163305921f4SMarko Kovacevic {ALEN_PREFIX, parser_read_uint32_val, &vec.aead.aad},
164305921f4SMarko Kovacevic {DIGESTL_PREFIX, parser_read_uint32_val, &vec.aead.digest},
165305921f4SMarko Kovacevic {KEY_STR, parse_uint8_hex_str, &vec.aead.key},
166305921f4SMarko Kovacevic {IV_STR, parse_uint8_known_len_hex_str, &vec.iv},
167305921f4SMarko Kovacevic {NULL, NULL, NULL} /**< end pointer */
168305921f4SMarko Kovacevic };
169305921f4SMarko Kovacevic
170305921f4SMarko Kovacevic struct fips_test_callback ccm_vpt_vec[] = {
171305921f4SMarko Kovacevic {AAD_STR, parse_uint8_ccm_aad_str, &vec.aead.aad},
172305921f4SMarko Kovacevic {PT_STR, parse_uint8_known_len_hex_str, &vec.pt},
173305921f4SMarko Kovacevic {NULL, NULL, NULL} /**< end pointer */
174305921f4SMarko Kovacevic };
175305921f4SMarko Kovacevic
176305921f4SMarko Kovacevic struct fips_test_callback ccm_vpt_interim_vec[] = {
177305921f4SMarko Kovacevic {ALEN_PREFIX, parser_read_uint32_val, &vec.aead.aad},
178305921f4SMarko Kovacevic {IVLEN_PREFIX, parser_read_uint32_val, &vec.iv},
179305921f4SMarko Kovacevic {DIGESTL_PREFIX, parser_read_uint32_val, &vec.aead.digest},
180305921f4SMarko Kovacevic {PLEN_PREFIX, parser_read_uint32_val, &vec.pt},
181305921f4SMarko Kovacevic {KEY_STR, parse_uint8_hex_str, &vec.aead.key},
182305921f4SMarko Kovacevic {IV_STR, parse_uint8_known_len_hex_str, &vec.iv},
183305921f4SMarko Kovacevic {NULL, NULL, NULL} /**< end pointer */
184305921f4SMarko Kovacevic };
185305921f4SMarko Kovacevic
186305921f4SMarko Kovacevic struct fips_test_callback ccm_dvpt_vec[] = {
187305921f4SMarko Kovacevic {IV_STR, parse_uint8_known_len_hex_str, &vec.iv},
188305921f4SMarko Kovacevic {AAD_STR, parse_uint8_ccm_aad_str, &vec.aead.aad},
189305921f4SMarko Kovacevic {CT_STR, parse_dvpt_ct_hex_str, &vec.ct},
190305921f4SMarko Kovacevic {NULL, NULL, NULL} /**< end pointer */
191305921f4SMarko Kovacevic };
192305921f4SMarko Kovacevic
193305921f4SMarko Kovacevic struct fips_test_callback ccm_dvpt_interim_vec[] = {
194305921f4SMarko Kovacevic {ALEN_PREFIX, parser_dvpt_interim, &vec.aead.aad},
195305921f4SMarko Kovacevic {PLEN_PREFIX, parser_dvpt_interim, &vec.pt},
196305921f4SMarko Kovacevic {IVLEN_PREFIX, parser_dvpt_interim, &vec.iv},
197305921f4SMarko Kovacevic {DIGESTL_PREFIX, parser_dvpt_interim, &vec.aead.digest},
198305921f4SMarko Kovacevic {KEY_STR, parse_uint8_hex_str, &vec.aead.key},
199305921f4SMarko Kovacevic {NULL, NULL, NULL} /**< end pointer */
200305921f4SMarko Kovacevic };
201305921f4SMarko Kovacevic
202305921f4SMarko Kovacevic struct ccm_test_types {
203305921f4SMarko Kovacevic const char *str;
204305921f4SMarko Kovacevic uint32_t type;
205305921f4SMarko Kovacevic const struct fips_test_callback *cb;
206305921f4SMarko Kovacevic const struct fips_test_callback *cb_interim;
207305921f4SMarko Kovacevic enum fips_test_op op;
208305921f4SMarko Kovacevic } ctt[] = {
209305921f4SMarko Kovacevic {DVPT_STR, CCM_DVPT, ccm_dvpt_vec, ccm_dvpt_interim_vec,
210305921f4SMarko Kovacevic FIPS_TEST_DEC_AUTH_VERIF},
211305921f4SMarko Kovacevic {VPT_STR, CCM_VPT, ccm_vpt_vec, ccm_vpt_interim_vec,
212305921f4SMarko Kovacevic FIPS_TEST_ENC_AUTH_GEN},
213305921f4SMarko Kovacevic {VADT_STR, CCM_VADT, ccm_vadt_vec, ccm_vadt_interim_vec,
214305921f4SMarko Kovacevic FIPS_TEST_ENC_AUTH_GEN},
215305921f4SMarko Kovacevic {VNT_STR, CCM_VNT, ccm_vnt_vec, ccm_vnt_interim_vec,
216305921f4SMarko Kovacevic FIPS_TEST_ENC_AUTH_GEN},
217305921f4SMarko Kovacevic {VTT_STR, CCM_VTT, ccm_vtt_vec, ccm_vtt_interim_vec,
218305921f4SMarko Kovacevic FIPS_TEST_ENC_AUTH_GEN},
219305921f4SMarko Kovacevic };
220305921f4SMarko Kovacevic
221*55a7050eSGowrishankar Muthukrishnan #ifdef USE_JANSSON
222*55a7050eSGowrishankar Muthukrishnan static int
parser_read_ccm_direction_str(__rte_unused const char * key,char * src,__rte_unused struct fips_val * val)223*55a7050eSGowrishankar Muthukrishnan parser_read_ccm_direction_str(__rte_unused const char *key, char *src,
224*55a7050eSGowrishankar Muthukrishnan __rte_unused struct fips_val *val)
225*55a7050eSGowrishankar Muthukrishnan {
226*55a7050eSGowrishankar Muthukrishnan if (strcmp(src, "encrypt") == 0)
227*55a7050eSGowrishankar Muthukrishnan info.op = FIPS_TEST_ENC_AUTH_GEN;
228*55a7050eSGowrishankar Muthukrishnan else if (strcmp(src, "decrypt") == 0)
229*55a7050eSGowrishankar Muthukrishnan info.op = FIPS_TEST_DEC_AUTH_VERIF;
230*55a7050eSGowrishankar Muthukrishnan
231*55a7050eSGowrishankar Muthukrishnan return 0;
232*55a7050eSGowrishankar Muthukrishnan }
233*55a7050eSGowrishankar Muthukrishnan
234*55a7050eSGowrishankar Muthukrishnan static int
parser_read_ccm_aad_str(const char * key,char * src,struct fips_val * val)235*55a7050eSGowrishankar Muthukrishnan parser_read_ccm_aad_str(const char *key, char *src, struct fips_val *val)
236*55a7050eSGowrishankar Muthukrishnan {
237*55a7050eSGowrishankar Muthukrishnan struct fips_val tmp_val = {0};
238*55a7050eSGowrishankar Muthukrishnan uint32_t len = val->len;
239*55a7050eSGowrishankar Muthukrishnan
240*55a7050eSGowrishankar Muthukrishnan /* CCM aad requires 18 bytes padding before the real content */
241*55a7050eSGowrishankar Muthukrishnan val->val = rte_zmalloc(NULL, len + 18, 0);
242*55a7050eSGowrishankar Muthukrishnan if (!val->val)
243*55a7050eSGowrishankar Muthukrishnan return -1;
244*55a7050eSGowrishankar Muthukrishnan
245*55a7050eSGowrishankar Muthukrishnan if (parse_uint8_hex_str(key, src, &tmp_val) < 0)
246*55a7050eSGowrishankar Muthukrishnan return -1;
247*55a7050eSGowrishankar Muthukrishnan
248*55a7050eSGowrishankar Muthukrishnan memcpy(val->val + 18, tmp_val.val, val->len);
249*55a7050eSGowrishankar Muthukrishnan rte_free(tmp_val.val);
250*55a7050eSGowrishankar Muthukrishnan
251*55a7050eSGowrishankar Muthukrishnan return 0;
252*55a7050eSGowrishankar Muthukrishnan }
253*55a7050eSGowrishankar Muthukrishnan
254*55a7050eSGowrishankar Muthukrishnan static int
parse_read_ccm_ct_str(const char * key,char * src,struct fips_val * val)255*55a7050eSGowrishankar Muthukrishnan parse_read_ccm_ct_str(const char *key, char *src, struct fips_val *val)
256*55a7050eSGowrishankar Muthukrishnan {
257*55a7050eSGowrishankar Muthukrishnan int ret;
258*55a7050eSGowrishankar Muthukrishnan
259*55a7050eSGowrishankar Muthukrishnan val->len = vec.pt.len;
260*55a7050eSGowrishankar Muthukrishnan
261*55a7050eSGowrishankar Muthukrishnan ret = parse_uint8_known_len_hex_str(key, src, val);
262*55a7050eSGowrishankar Muthukrishnan if (ret < 0)
263*55a7050eSGowrishankar Muthukrishnan return ret;
264*55a7050eSGowrishankar Muthukrishnan
265*55a7050eSGowrishankar Muthukrishnan src += val->len * 2;
266*55a7050eSGowrishankar Muthukrishnan
267*55a7050eSGowrishankar Muthukrishnan ret = parse_uint8_known_len_hex_str("", src, &vec.aead.digest);
268*55a7050eSGowrishankar Muthukrishnan if (ret < 0) {
269*55a7050eSGowrishankar Muthukrishnan rte_free(val->val);
270*55a7050eSGowrishankar Muthukrishnan memset(val, 0, sizeof(*val));
271*55a7050eSGowrishankar Muthukrishnan return ret;
272*55a7050eSGowrishankar Muthukrishnan }
273*55a7050eSGowrishankar Muthukrishnan
274*55a7050eSGowrishankar Muthukrishnan return 0;
275*55a7050eSGowrishankar Muthukrishnan }
276*55a7050eSGowrishankar Muthukrishnan
277*55a7050eSGowrishankar Muthukrishnan struct fips_test_callback ccm_tests_interim_json_vectors[] = {
278*55a7050eSGowrishankar Muthukrishnan {DIR_JSON_STR, parser_read_ccm_direction_str, NULL},
279*55a7050eSGowrishankar Muthukrishnan {IVLEN_JSON_STR, parser_read_uint32_bit_val, &vec.iv},
280*55a7050eSGowrishankar Muthukrishnan {PTLEN_JSON_STR, parser_read_uint32_bit_val, &vec.pt},
281*55a7050eSGowrishankar Muthukrishnan {AADLEN_JSON_STR, parser_read_uint32_bit_val, &vec.aead.aad},
282*55a7050eSGowrishankar Muthukrishnan {TAGLEN_JSON_STR, parser_read_uint32_bit_val, &vec.aead.digest},
283*55a7050eSGowrishankar Muthukrishnan {KEYLEN_JSON_STR, parser_read_uint32_bit_val, &vec.aead.key},
284*55a7050eSGowrishankar Muthukrishnan {NULL, NULL, NULL} /**< end pointer */
285*55a7050eSGowrishankar Muthukrishnan };
286*55a7050eSGowrishankar Muthukrishnan
287*55a7050eSGowrishankar Muthukrishnan struct fips_test_callback ccm_tests_json_vectors[] = {
288*55a7050eSGowrishankar Muthukrishnan {PT_JSON_STR, parse_uint8_known_len_hex_str, &vec.pt},
289*55a7050eSGowrishankar Muthukrishnan {CT_JSON_STR, parse_read_ccm_ct_str, &vec.ct},
290*55a7050eSGowrishankar Muthukrishnan {KEY_JSON_STR, parse_uint8_known_len_hex_str, &vec.aead.key},
291*55a7050eSGowrishankar Muthukrishnan {IV_JSON_STR, parse_uint8_known_len_hex_str, &vec.iv},
292*55a7050eSGowrishankar Muthukrishnan {AAD_JSON_STR, parser_read_ccm_aad_str, &vec.aead.aad},
293*55a7050eSGowrishankar Muthukrishnan {NULL, NULL, NULL} /**< end pointer */
294*55a7050eSGowrishankar Muthukrishnan };
295*55a7050eSGowrishankar Muthukrishnan
296*55a7050eSGowrishankar Muthukrishnan static int
parse_test_ccm_json_writeback(struct fips_val * val)297*55a7050eSGowrishankar Muthukrishnan parse_test_ccm_json_writeback(struct fips_val *val)
298*55a7050eSGowrishankar Muthukrishnan {
299*55a7050eSGowrishankar Muthukrishnan struct fips_val tmp_val;
300*55a7050eSGowrishankar Muthukrishnan json_t *tcId;
301*55a7050eSGowrishankar Muthukrishnan
302*55a7050eSGowrishankar Muthukrishnan tcId = json_object_get(json_info.json_test_case, "tcId");
303*55a7050eSGowrishankar Muthukrishnan json_info.json_write_case = json_object();
304*55a7050eSGowrishankar Muthukrishnan json_object_set(json_info.json_write_case, "tcId", tcId);
305*55a7050eSGowrishankar Muthukrishnan
306*55a7050eSGowrishankar Muthukrishnan if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
307*55a7050eSGowrishankar Muthukrishnan json_t *ct;
308*55a7050eSGowrishankar Muthukrishnan
309*55a7050eSGowrishankar Muthukrishnan info.one_line_text[0] = '\0';
310*55a7050eSGowrishankar Muthukrishnan writeback_hex_str("", info.one_line_text, val);
311*55a7050eSGowrishankar Muthukrishnan ct = json_string(info.one_line_text);
312*55a7050eSGowrishankar Muthukrishnan json_object_set_new(json_info.json_write_case, CT_JSON_STR, ct);
313*55a7050eSGowrishankar Muthukrishnan } else {
314*55a7050eSGowrishankar Muthukrishnan if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) {
315*55a7050eSGowrishankar Muthukrishnan tmp_val.val = val->val;
316*55a7050eSGowrishankar Muthukrishnan tmp_val.len = vec.pt.len;
317*55a7050eSGowrishankar Muthukrishnan
318*55a7050eSGowrishankar Muthukrishnan info.one_line_text[0] = '\0';
319*55a7050eSGowrishankar Muthukrishnan writeback_hex_str("", info.one_line_text, &tmp_val);
320*55a7050eSGowrishankar Muthukrishnan json_object_set_new(json_info.json_write_case, PT_JSON_STR,
321*55a7050eSGowrishankar Muthukrishnan json_string(info.one_line_text));
322*55a7050eSGowrishankar Muthukrishnan } else {
323*55a7050eSGowrishankar Muthukrishnan json_object_set_new(json_info.json_write_case, "testPassed",
324*55a7050eSGowrishankar Muthukrishnan json_false());
325*55a7050eSGowrishankar Muthukrishnan }
326*55a7050eSGowrishankar Muthukrishnan }
327*55a7050eSGowrishankar Muthukrishnan
328*55a7050eSGowrishankar Muthukrishnan return 0;
329*55a7050eSGowrishankar Muthukrishnan }
330*55a7050eSGowrishankar Muthukrishnan
331*55a7050eSGowrishankar Muthukrishnan int
parse_test_ccm_json_init(void)332*55a7050eSGowrishankar Muthukrishnan parse_test_ccm_json_init(void)
333*55a7050eSGowrishankar Muthukrishnan {
334*55a7050eSGowrishankar Muthukrishnan info.interim_callbacks = ccm_tests_interim_json_vectors;
335*55a7050eSGowrishankar Muthukrishnan info.parse_writeback = parse_test_ccm_json_writeback;
336*55a7050eSGowrishankar Muthukrishnan info.callbacks = ccm_tests_json_vectors;
337*55a7050eSGowrishankar Muthukrishnan return 0;
338*55a7050eSGowrishankar Muthukrishnan }
339*55a7050eSGowrishankar Muthukrishnan #endif /* USE_JANSSON */
340*55a7050eSGowrishankar Muthukrishnan
341305921f4SMarko Kovacevic static int
parse_test_ccm_writeback(struct fips_val * val)342305921f4SMarko Kovacevic parse_test_ccm_writeback(struct fips_val *val)
343305921f4SMarko Kovacevic {
344305921f4SMarko Kovacevic struct fips_val tmp_val;
345305921f4SMarko Kovacevic
346305921f4SMarko Kovacevic switch (info.interim_info.ccm_data.test_type) {
347305921f4SMarko Kovacevic case CCM_DVPT:
348305921f4SMarko Kovacevic fprintf(info.fp_wr, "%s", POS_NEG_STR);
349305921f4SMarko Kovacevic if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) {
350305921f4SMarko Kovacevic fprintf(info.fp_wr, "%s\n", POS_KEYWORD);
351305921f4SMarko Kovacevic fprintf(info.fp_wr, "%s", PT_STR);
352305921f4SMarko Kovacevic
353305921f4SMarko Kovacevic tmp_val.val = val->val;
354305921f4SMarko Kovacevic tmp_val.len = vec.pt.len;
355305921f4SMarko Kovacevic
356305921f4SMarko Kovacevic if (tmp_val.len == 0)
357305921f4SMarko Kovacevic fprintf(info.fp_wr, "00\n");
358305921f4SMarko Kovacevic else
359305921f4SMarko Kovacevic parse_write_hex_str(&tmp_val);
360305921f4SMarko Kovacevic } else
361305921f4SMarko Kovacevic fprintf(info.fp_wr, "%s\n", NEG_KEYWORD);
362305921f4SMarko Kovacevic
363305921f4SMarko Kovacevic break;
364305921f4SMarko Kovacevic
365305921f4SMarko Kovacevic case CCM_VADT:
366305921f4SMarko Kovacevic case CCM_VNT:
367305921f4SMarko Kovacevic case CCM_VPT:
368305921f4SMarko Kovacevic case CCM_VTT:
369305921f4SMarko Kovacevic fprintf(info.fp_wr, "%s", CT_STR);
370305921f4SMarko Kovacevic
371305921f4SMarko Kovacevic parse_write_hex_str(val);
372305921f4SMarko Kovacevic
373305921f4SMarko Kovacevic break;
374305921f4SMarko Kovacevic
375305921f4SMarko Kovacevic }
376305921f4SMarko Kovacevic
377305921f4SMarko Kovacevic return 0;
378305921f4SMarko Kovacevic }
379305921f4SMarko Kovacevic
380305921f4SMarko Kovacevic int
parse_test_ccm_init(void)381305921f4SMarko Kovacevic parse_test_ccm_init(void)
382305921f4SMarko Kovacevic {
383305921f4SMarko Kovacevic
384305921f4SMarko Kovacevic uint32_t i;
385305921f4SMarko Kovacevic
386305921f4SMarko Kovacevic for (i = 0; i < info.nb_vec_lines; i++) {
387305921f4SMarko Kovacevic char *line = info.vec[i];
388305921f4SMarko Kovacevic uint32_t j;
389305921f4SMarko Kovacevic
390305921f4SMarko Kovacevic for (j = 0; j < RTE_DIM(ctt); j++)
391305921f4SMarko Kovacevic if (strstr(line, ctt[j].str)) {
392305921f4SMarko Kovacevic info.interim_info.ccm_data.test_type =
393305921f4SMarko Kovacevic ctt[j].type;
394305921f4SMarko Kovacevic info.callbacks = ctt[j].cb;
395305921f4SMarko Kovacevic info.interim_callbacks = ctt[j].cb_interim;
396305921f4SMarko Kovacevic info.op = ctt[j].op;
397305921f4SMarko Kovacevic break;
398305921f4SMarko Kovacevic }
399305921f4SMarko Kovacevic }
400305921f4SMarko Kovacevic
401305921f4SMarko Kovacevic info.parse_writeback = parse_test_ccm_writeback;
402305921f4SMarko Kovacevic
403305921f4SMarko Kovacevic return 0;
404305921f4SMarko Kovacevic }
405