xref: /dpdk/examples/fips_validation/fips_validation_aes.c (revision 8d70a19417ad70accc3e138190875ff8f2baae8c)
1cd255ccfSMarko Kovacevic /* SPDX-License-Identifier: BSD-3-Clause
2cd255ccfSMarko Kovacevic  * Copyright(c) 2018 Intel Corporation
3cd255ccfSMarko Kovacevic  */
4cd255ccfSMarko Kovacevic 
5cd255ccfSMarko Kovacevic #include <string.h>
6cd255ccfSMarko Kovacevic #include <time.h>
7cd255ccfSMarko Kovacevic #include <stdio.h>
8cd255ccfSMarko Kovacevic 
9cd255ccfSMarko Kovacevic #include <rte_cryptodev.h>
108b8546aaSGowrishankar Muthukrishnan #include <rte_malloc.h>
11cd255ccfSMarko Kovacevic 
12cd255ccfSMarko Kovacevic #include "fips_validation.h"
13cd255ccfSMarko Kovacevic 
14cd255ccfSMarko Kovacevic #define MODE_STR	"AESVS"
15cd255ccfSMarko Kovacevic #define ALGO_STR	"test data for "
16cd255ccfSMarko Kovacevic #define OP_STR		"State"
17cd255ccfSMarko Kovacevic #define KEY_SIZE_STR	"Key Length : "
18cd255ccfSMarko Kovacevic 
19cd255ccfSMarko Kovacevic 
20cd255ccfSMarko Kovacevic #define COUNT_STR	"COUNT = "
21cd255ccfSMarko Kovacevic #define KEY_STR		"KEY = "
22cd255ccfSMarko Kovacevic #define IV_STR		"IV = "
23cd255ccfSMarko Kovacevic #define PT_STR		"PLAINTEXT = "
24cd255ccfSMarko Kovacevic #define CT_STR		"CIPHERTEXT = "
25cd255ccfSMarko Kovacevic 
26cd255ccfSMarko Kovacevic #define OP_ENC_STR	"ENCRYPT"
27cd255ccfSMarko Kovacevic #define OP_DEC_STR	"DECRYPT"
28cd255ccfSMarko Kovacevic 
298b8546aaSGowrishankar Muthukrishnan #define ALGO_JSON_STR		"algorithm"
308b8546aaSGowrishankar Muthukrishnan #define TESTTYPE_JSON_STR	"testType"
318b8546aaSGowrishankar Muthukrishnan #define DIR_JSON_STR		"direction"
328b8546aaSGowrishankar Muthukrishnan #define KEYLEN_JSON_STR		"keyLen"
338b8546aaSGowrishankar Muthukrishnan 
348b8546aaSGowrishankar Muthukrishnan #define KEY_JSON_STR	"key"
358b8546aaSGowrishankar Muthukrishnan #define IV_JSON_STR	"iv"
368b8546aaSGowrishankar Muthukrishnan #define PT_JSON_STR	"pt"
378b8546aaSGowrishankar Muthukrishnan #define CT_JSON_STR	"ct"
388b8546aaSGowrishankar Muthukrishnan 
398b8546aaSGowrishankar Muthukrishnan #define OP_ENC_JSON_STR	"encrypt"
408b8546aaSGowrishankar Muthukrishnan #define OP_DEC_JSON_STR	"decrypt"
418b8546aaSGowrishankar Muthukrishnan 
42cd255ccfSMarko Kovacevic struct {
43cd255ccfSMarko Kovacevic 	uint32_t type;
44cd255ccfSMarko Kovacevic 	const char *desc;
45cd255ccfSMarko Kovacevic } aes_test_types[] = {
46cd255ccfSMarko Kovacevic 		{AESAVS_TYPE_GFXBOX, "GFSbox"},
47cd255ccfSMarko Kovacevic 		{AESAVS_TYPE_KEYSBOX, "KeySbox"},
48cd255ccfSMarko Kovacevic 		{AESAVS_TYPE_VARKEY, "VarKey"},
49cd255ccfSMarko Kovacevic 		{AESAVS_TYPE_VARTXT, "VarTxt"},
50527cbf3dSMarko Kovacevic 		{TDES_VARIABLE_TEXT, "VARIABLE PLAINTEXT/CIPHERTEXT"},
51527cbf3dSMarko Kovacevic 		{TDES_VARIABLE_TEXT, "KAT"},
52cd255ccfSMarko Kovacevic 		{AESAVS_TYPE_MMT, "MMT"},
53cd255ccfSMarko Kovacevic 		{AESAVS_TYPE_MCT, "MCT"},
548b8546aaSGowrishankar Muthukrishnan 		{AESAVS_TYPE_AFT, "AFT"},
55cd255ccfSMarko Kovacevic };
56cd255ccfSMarko Kovacevic 
57cd255ccfSMarko Kovacevic struct aes_test_algo {
58cd255ccfSMarko Kovacevic 	const char *name;
59cd255ccfSMarko Kovacevic 	enum rte_crypto_cipher_algorithm algo;
60cd255ccfSMarko Kovacevic } const algo_con[] = {
61cd255ccfSMarko Kovacevic 		{"CBC", RTE_CRYPTO_CIPHER_AES_CBC},
62d3190431SMichael Shamis 		{"ECB", RTE_CRYPTO_CIPHER_AES_ECB},
63cd255ccfSMarko Kovacevic };
64cd255ccfSMarko Kovacevic 
65cd255ccfSMarko Kovacevic static int
66cd255ccfSMarko Kovacevic parse_interim_enc_dec(const char *key,
67f2fc83b4SThomas Monjalon 		__rte_unused char *text,
68f2fc83b4SThomas Monjalon 		__rte_unused struct fips_val *val)
69cd255ccfSMarko Kovacevic {
70cd255ccfSMarko Kovacevic 	if (strcmp(key, OP_ENC_STR) == 0)
71cd255ccfSMarko Kovacevic 		info.op = FIPS_TEST_ENC_AUTH_GEN;
72cd255ccfSMarko Kovacevic 	else if (strcmp(key, OP_DEC_STR) == 0)
73cd255ccfSMarko Kovacevic 		info.op = FIPS_TEST_DEC_AUTH_VERIF;
74cd255ccfSMarko Kovacevic 	else
75cd255ccfSMarko Kovacevic 		return -1;
76cd255ccfSMarko Kovacevic 
77cd255ccfSMarko Kovacevic 	return 0;
78cd255ccfSMarko Kovacevic }
79cd255ccfSMarko Kovacevic 
80cd255ccfSMarko Kovacevic struct fips_test_callback aes_tests_interim[] = {
81cd255ccfSMarko Kovacevic 		{OP_ENC_STR, parse_interim_enc_dec, NULL},
82cd255ccfSMarko Kovacevic 		{OP_DEC_STR, parse_interim_enc_dec, NULL},
83cd255ccfSMarko Kovacevic 		{NULL, NULL, NULL} /**< end pointer */
84cd255ccfSMarko Kovacevic };
85cd255ccfSMarko Kovacevic 
86cd255ccfSMarko Kovacevic struct fips_test_callback aes_tests_vectors[] = {
87cd255ccfSMarko Kovacevic 		{KEY_STR, parse_uint8_hex_str, &vec.cipher_auth.key},
88cd255ccfSMarko Kovacevic 		{IV_STR, parse_uint8_hex_str, &vec.iv},
89cd255ccfSMarko Kovacevic 		{PT_STR, parse_uint8_hex_str, &vec.pt},
90cd255ccfSMarko Kovacevic 		{CT_STR, parse_uint8_hex_str, &vec.ct},
91cd255ccfSMarko Kovacevic 		{NULL, NULL, NULL} /**< end pointer */
92cd255ccfSMarko Kovacevic };
93cd255ccfSMarko Kovacevic 
94cd255ccfSMarko Kovacevic struct fips_test_callback aes_tests_interim_vectors[] = {
95cd255ccfSMarko Kovacevic 		{OP_ENC_STR, parse_interim_enc_dec, NULL},
96cd255ccfSMarko Kovacevic 		{OP_DEC_STR, parse_interim_enc_dec, NULL},
97cd255ccfSMarko Kovacevic 		{NULL, NULL, NULL} /**< end pointer */
98cd255ccfSMarko Kovacevic };
99cd255ccfSMarko Kovacevic 
100cd255ccfSMarko Kovacevic struct fips_test_callback aes_writeback_callbacks[] = {
101cd255ccfSMarko Kovacevic 		/** First element is used to pass COUNT string */
102cd255ccfSMarko Kovacevic 		{COUNT_STR, NULL, NULL},
103cd255ccfSMarko Kovacevic 		{IV_STR, writeback_hex_str, &vec.iv},
104cd255ccfSMarko Kovacevic 		{KEY_STR, writeback_hex_str, &vec.cipher_auth.key},
105cd255ccfSMarko Kovacevic 		{PT_STR, writeback_hex_str, &vec.pt},
106cd255ccfSMarko Kovacevic 		{CT_STR, writeback_hex_str, &vec.ct},
107cd255ccfSMarko Kovacevic 		{NULL, NULL, NULL} /**< end pointer */
108cd255ccfSMarko Kovacevic };
109cd255ccfSMarko Kovacevic 
110*8d70a194SDavid Marchand #ifdef USE_JANSSON
1118b8546aaSGowrishankar Muthukrishnan struct fips_test_callback aes_dec_json_vectors[] = {
1128b8546aaSGowrishankar Muthukrishnan 		{KEY_JSON_STR, parse_uint8_known_len_hex_str, &vec.cipher_auth.key},
1138b8546aaSGowrishankar Muthukrishnan 		{IV_JSON_STR, parse_uint8_hex_str, &vec.iv},
1148b8546aaSGowrishankar Muthukrishnan 		{CT_JSON_STR, parse_uint8_hex_str, &vec.ct},
1158b8546aaSGowrishankar Muthukrishnan 		{NULL, NULL, NULL} /**< end pointer */
1168b8546aaSGowrishankar Muthukrishnan };
1178b8546aaSGowrishankar Muthukrishnan 
1188b8546aaSGowrishankar Muthukrishnan struct fips_test_callback aes_interim_json_vectors[] = {
1198b8546aaSGowrishankar Muthukrishnan 		{KEYLEN_JSON_STR, parser_read_uint32_bit_val, &vec.cipher_auth.key},
1208b8546aaSGowrishankar Muthukrishnan 		{NULL, NULL, NULL} /**< end pointer */
1218b8546aaSGowrishankar Muthukrishnan };
1228b8546aaSGowrishankar Muthukrishnan 
1238b8546aaSGowrishankar Muthukrishnan struct fips_test_callback aes_enc_json_vectors[] = {
1248b8546aaSGowrishankar Muthukrishnan 		{KEY_JSON_STR, parse_uint8_known_len_hex_str, &vec.cipher_auth.key},
1258b8546aaSGowrishankar Muthukrishnan 		{IV_JSON_STR, parse_uint8_hex_str, &vec.iv},
1268b8546aaSGowrishankar Muthukrishnan 		{PT_JSON_STR, parse_uint8_hex_str, &vec.pt},
1278b8546aaSGowrishankar Muthukrishnan 		{NULL, NULL, NULL} /**< end pointer */
1288b8546aaSGowrishankar Muthukrishnan };
1298b8546aaSGowrishankar Muthukrishnan 
1308b8546aaSGowrishankar Muthukrishnan static int
1318b8546aaSGowrishankar Muthukrishnan parse_test_aes_json_writeback(struct fips_val *val)
1328b8546aaSGowrishankar Muthukrishnan {
1338b8546aaSGowrishankar Muthukrishnan 	struct fips_val tmp_val;
1348b8546aaSGowrishankar Muthukrishnan 	json_t *tcId;
1358b8546aaSGowrishankar Muthukrishnan 
1368b8546aaSGowrishankar Muthukrishnan 	tcId = json_object_get(json_info.json_test_case, "tcId");
1378b8546aaSGowrishankar Muthukrishnan 
1388b8546aaSGowrishankar Muthukrishnan 	json_info.json_write_case = json_object();
1398b8546aaSGowrishankar Muthukrishnan 	json_object_set(json_info.json_write_case, "tcId", tcId);
1408b8546aaSGowrishankar Muthukrishnan 
1418b8546aaSGowrishankar Muthukrishnan 	if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
1428b8546aaSGowrishankar Muthukrishnan 		json_t *ct;
1438b8546aaSGowrishankar Muthukrishnan 
1448b8546aaSGowrishankar Muthukrishnan 		tmp_val.val = val->val;
1458b8546aaSGowrishankar Muthukrishnan 		tmp_val.len = vec.pt.len;
1468b8546aaSGowrishankar Muthukrishnan 
1478b8546aaSGowrishankar Muthukrishnan 		writeback_hex_str("", info.one_line_text, &tmp_val);
1488b8546aaSGowrishankar Muthukrishnan 		ct = json_string(info.one_line_text);
1498b8546aaSGowrishankar Muthukrishnan 		json_object_set_new(json_info.json_write_case, CT_JSON_STR, ct);
1508b8546aaSGowrishankar Muthukrishnan 
1518b8546aaSGowrishankar Muthukrishnan 		tmp_val.val = val->val + vec.pt.len;
1528b8546aaSGowrishankar Muthukrishnan 		tmp_val.len = val->len - vec.pt.len;
1538b8546aaSGowrishankar Muthukrishnan 
1548b8546aaSGowrishankar Muthukrishnan 		writeback_hex_str("", info.one_line_text, &tmp_val);
1558b8546aaSGowrishankar Muthukrishnan 	} else {
1568b8546aaSGowrishankar Muthukrishnan 		if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) {
1578b8546aaSGowrishankar Muthukrishnan 			tmp_val.val = val->val;
1588b8546aaSGowrishankar Muthukrishnan 			tmp_val.len = vec.ct.len;
1598b8546aaSGowrishankar Muthukrishnan 
1608b8546aaSGowrishankar Muthukrishnan 			writeback_hex_str("", info.one_line_text, &tmp_val);
1618b8546aaSGowrishankar Muthukrishnan 			json_object_set_new(json_info.json_write_case, PT_JSON_STR,
1628b8546aaSGowrishankar Muthukrishnan 								json_string(info.one_line_text));
1638b8546aaSGowrishankar Muthukrishnan 		} else {
1648b8546aaSGowrishankar Muthukrishnan 			json_object_set_new(json_info.json_write_case, "testPassed", json_false());
1658b8546aaSGowrishankar Muthukrishnan 		}
1668b8546aaSGowrishankar Muthukrishnan 	}
1678b8546aaSGowrishankar Muthukrishnan 
1688b8546aaSGowrishankar Muthukrishnan 	return 0;
1698b8546aaSGowrishankar Muthukrishnan }
1708b8546aaSGowrishankar Muthukrishnan 
1718b8546aaSGowrishankar Muthukrishnan static int
1728b8546aaSGowrishankar Muthukrishnan parse_test_aes_mct_json_writeback(struct fips_val *val)
1738b8546aaSGowrishankar Muthukrishnan {
1748b8546aaSGowrishankar Muthukrishnan 	json_t *tcId, *resArr, *res, *ct, *pt, *key, *iv;
1758b8546aaSGowrishankar Muthukrishnan 	struct fips_val tmp_val;
1768b8546aaSGowrishankar Muthukrishnan 
1778b8546aaSGowrishankar Muthukrishnan 	tcId = json_object_get(json_info.json_test_case, "tcId");
1788b8546aaSGowrishankar Muthukrishnan 	if (json_info.json_write_case) {
1798b8546aaSGowrishankar Muthukrishnan 		json_t *wcId;
1808b8546aaSGowrishankar Muthukrishnan 
1818b8546aaSGowrishankar Muthukrishnan 		wcId = json_object_get(json_info.json_write_case, "tcId");
1828b8546aaSGowrishankar Muthukrishnan 		if (!json_equal(tcId, wcId)) {
1838b8546aaSGowrishankar Muthukrishnan 			json_info.json_write_case = json_object();
1848b8546aaSGowrishankar Muthukrishnan 			json_object_set(json_info.json_write_case, "tcId", tcId);
1858b8546aaSGowrishankar Muthukrishnan 			json_object_set(json_info.json_write_case, "resultsArray", json_array());
1868b8546aaSGowrishankar Muthukrishnan 		}
1878b8546aaSGowrishankar Muthukrishnan 	} else {
1888b8546aaSGowrishankar Muthukrishnan 		json_info.json_write_case = json_object();
1898b8546aaSGowrishankar Muthukrishnan 		json_object_set(json_info.json_write_case, "tcId", tcId);
1908b8546aaSGowrishankar Muthukrishnan 		json_object_set(json_info.json_write_case, "resultsArray", json_array());
1918b8546aaSGowrishankar Muthukrishnan 	}
1928b8546aaSGowrishankar Muthukrishnan 
1938b8546aaSGowrishankar Muthukrishnan 	resArr = json_object_get(json_info.json_write_case, "resultsArray");
1948b8546aaSGowrishankar Muthukrishnan 	if (!json_is_array(resArr))
1958b8546aaSGowrishankar Muthukrishnan 		return -EINVAL;
1968b8546aaSGowrishankar Muthukrishnan 
1978b8546aaSGowrishankar Muthukrishnan 	res = json_object();
1988b8546aaSGowrishankar Muthukrishnan 	if (info .op == FIPS_TEST_ENC_AUTH_GEN) {
1998b8546aaSGowrishankar Muthukrishnan 		writeback_hex_str("", info.one_line_text, &vec.cipher_auth.key);
2008b8546aaSGowrishankar Muthukrishnan 		key = json_string(info.one_line_text);
2018b8546aaSGowrishankar Muthukrishnan 		json_object_set_new(res, KEY_JSON_STR, key);
2028b8546aaSGowrishankar Muthukrishnan 
2038b8546aaSGowrishankar Muthukrishnan 		writeback_hex_str("", info.one_line_text, &val[2]);
2048b8546aaSGowrishankar Muthukrishnan 		iv = json_string(info.one_line_text);
2058b8546aaSGowrishankar Muthukrishnan 		json_object_set_new(res, IV_JSON_STR, iv);
2068b8546aaSGowrishankar Muthukrishnan 
2078b8546aaSGowrishankar Muthukrishnan 		writeback_hex_str("", info.one_line_text, &val[1]);
2088b8546aaSGowrishankar Muthukrishnan 		pt = json_string(info.one_line_text);
2098b8546aaSGowrishankar Muthukrishnan 		json_object_set_new(res, PT_JSON_STR, pt);
2108b8546aaSGowrishankar Muthukrishnan 
2118b8546aaSGowrishankar Muthukrishnan 		tmp_val.val = val->val;
2128b8546aaSGowrishankar Muthukrishnan 		tmp_val.len = vec.pt.len;
2138b8546aaSGowrishankar Muthukrishnan 
2148b8546aaSGowrishankar Muthukrishnan 		writeback_hex_str("", info.one_line_text, &tmp_val);
2158b8546aaSGowrishankar Muthukrishnan 		ct = json_string(info.one_line_text);
2168b8546aaSGowrishankar Muthukrishnan 		json_object_set_new(res, CT_JSON_STR, ct);
2178b8546aaSGowrishankar Muthukrishnan 
2188b8546aaSGowrishankar Muthukrishnan 		tmp_val.val = val->val + vec.pt.len;
2198b8546aaSGowrishankar Muthukrishnan 		tmp_val.len = val->len - vec.pt.len;
2208b8546aaSGowrishankar Muthukrishnan 
2218b8546aaSGowrishankar Muthukrishnan 		writeback_hex_str("", info.one_line_text, &tmp_val);
2228b8546aaSGowrishankar Muthukrishnan 	} else {
2238b8546aaSGowrishankar Muthukrishnan 		if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) {
2248b8546aaSGowrishankar Muthukrishnan 			writeback_hex_str("", info.one_line_text, &vec.cipher_auth.key);
2258b8546aaSGowrishankar Muthukrishnan 			key = json_string(info.one_line_text);
2268b8546aaSGowrishankar Muthukrishnan 			json_object_set_new(res, KEY_JSON_STR, key);
2278b8546aaSGowrishankar Muthukrishnan 
2288b8546aaSGowrishankar Muthukrishnan 			writeback_hex_str("", info.one_line_text, &val[2]);
2298b8546aaSGowrishankar Muthukrishnan 			iv = json_string(info.one_line_text);
2308b8546aaSGowrishankar Muthukrishnan 			json_object_set_new(res, IV_JSON_STR, iv);
2318b8546aaSGowrishankar Muthukrishnan 
2328b8546aaSGowrishankar Muthukrishnan 			tmp_val.val = val->val;
2338b8546aaSGowrishankar Muthukrishnan 			tmp_val.len = vec.ct.len;
2348b8546aaSGowrishankar Muthukrishnan 
2358b8546aaSGowrishankar Muthukrishnan 			writeback_hex_str("", info.one_line_text, &tmp_val);
2368b8546aaSGowrishankar Muthukrishnan 			pt = json_string(info.one_line_text);
2378b8546aaSGowrishankar Muthukrishnan 			json_object_set_new(res, PT_JSON_STR, pt);
2388b8546aaSGowrishankar Muthukrishnan 
2398b8546aaSGowrishankar Muthukrishnan 			writeback_hex_str("", info.one_line_text, &val[1]);
2408b8546aaSGowrishankar Muthukrishnan 			ct = json_string(info.one_line_text);
2418b8546aaSGowrishankar Muthukrishnan 			json_object_set_new(res, CT_JSON_STR, ct);
2428b8546aaSGowrishankar Muthukrishnan 		} else {
2438b8546aaSGowrishankar Muthukrishnan 			json_object_set_new(json_info.json_write_case, "testPassed", json_false());
2448b8546aaSGowrishankar Muthukrishnan 		}
2458b8546aaSGowrishankar Muthukrishnan 	}
2468b8546aaSGowrishankar Muthukrishnan 
2478b8546aaSGowrishankar Muthukrishnan 	json_array_append_new(resArr, res);
2488b8546aaSGowrishankar Muthukrishnan 	return 0;
2498b8546aaSGowrishankar Muthukrishnan }
2508b8546aaSGowrishankar Muthukrishnan 
2518b8546aaSGowrishankar Muthukrishnan int
2528b8546aaSGowrishankar Muthukrishnan parse_test_aes_json_init(void)
2538b8546aaSGowrishankar Muthukrishnan {
2548b8546aaSGowrishankar Muthukrishnan 	json_t *type_obj = json_object_get(json_info.json_test_group, TESTTYPE_JSON_STR);
2558b8546aaSGowrishankar Muthukrishnan 	json_t *algo_obj = json_object_get(json_info.json_vector_set, ALGO_JSON_STR);
2568b8546aaSGowrishankar Muthukrishnan 	const char *type_str = json_string_value(type_obj);
2578b8546aaSGowrishankar Muthukrishnan 	const char *algo_str = json_string_value(algo_obj);
2588b8546aaSGowrishankar Muthukrishnan 	uint32_t i;
2598b8546aaSGowrishankar Muthukrishnan 
2608b8546aaSGowrishankar Muthukrishnan 	if (json_info.json_test_group) {
2618b8546aaSGowrishankar Muthukrishnan 		json_t *direction_obj;
2628b8546aaSGowrishankar Muthukrishnan 		const char *direction_str;
2638b8546aaSGowrishankar Muthukrishnan 
2648b8546aaSGowrishankar Muthukrishnan 		direction_obj = json_object_get(json_info.json_test_group, DIR_JSON_STR);
2658b8546aaSGowrishankar Muthukrishnan 		direction_str = json_string_value(direction_obj);
2668b8546aaSGowrishankar Muthukrishnan 
2678b8546aaSGowrishankar Muthukrishnan 		if (strcmp(direction_str, OP_ENC_JSON_STR) == 0) {
2688b8546aaSGowrishankar Muthukrishnan 			info.op = FIPS_TEST_ENC_AUTH_GEN;
2698b8546aaSGowrishankar Muthukrishnan 			info.callbacks = aes_enc_json_vectors;
2708b8546aaSGowrishankar Muthukrishnan 
2718b8546aaSGowrishankar Muthukrishnan 		} else if (strcmp(direction_str, OP_DEC_JSON_STR) == 0) {
2728b8546aaSGowrishankar Muthukrishnan 			info.op = FIPS_TEST_DEC_AUTH_VERIF;
2738b8546aaSGowrishankar Muthukrishnan 			info.callbacks = aes_dec_json_vectors;
2748b8546aaSGowrishankar Muthukrishnan 		} else {
2758b8546aaSGowrishankar Muthukrishnan 			return -EINVAL;
2768b8546aaSGowrishankar Muthukrishnan 		}
2778b8546aaSGowrishankar Muthukrishnan 		info.interim_callbacks = aes_interim_json_vectors;
2788b8546aaSGowrishankar Muthukrishnan 	}
2798b8546aaSGowrishankar Muthukrishnan 
2808b8546aaSGowrishankar Muthukrishnan 	for (i = 0; i < RTE_DIM(aes_test_types); i++)
2818b8546aaSGowrishankar Muthukrishnan 		if (strstr(type_str, aes_test_types[i].desc)) {
2828b8546aaSGowrishankar Muthukrishnan 			info.interim_info.aes_data.test_type =
2838b8546aaSGowrishankar Muthukrishnan 				aes_test_types[i].type;
2848b8546aaSGowrishankar Muthukrishnan 			break;
2858b8546aaSGowrishankar Muthukrishnan 		}
2868b8546aaSGowrishankar Muthukrishnan 
2878b8546aaSGowrishankar Muthukrishnan 	if (i >= RTE_DIM(aes_test_types))
2888b8546aaSGowrishankar Muthukrishnan 		return -EINVAL;
2898b8546aaSGowrishankar Muthukrishnan 
2908b8546aaSGowrishankar Muthukrishnan 	switch (info.interim_info.aes_data.test_type) {
2918b8546aaSGowrishankar Muthukrishnan 	case AESAVS_TYPE_MCT:
2928b8546aaSGowrishankar Muthukrishnan 		info.parse_writeback = parse_test_aes_mct_json_writeback;
2938b8546aaSGowrishankar Muthukrishnan 		break;
2948b8546aaSGowrishankar Muthukrishnan 	case AESAVS_TYPE_AFT:
2958b8546aaSGowrishankar Muthukrishnan 		info.parse_writeback = parse_test_aes_json_writeback;
2968b8546aaSGowrishankar Muthukrishnan 		break;
2978b8546aaSGowrishankar Muthukrishnan 	default:
2988b8546aaSGowrishankar Muthukrishnan 		info.parse_writeback = NULL;
2998b8546aaSGowrishankar Muthukrishnan 	}
3008b8546aaSGowrishankar Muthukrishnan 
3018b8546aaSGowrishankar Muthukrishnan 	if (!info.parse_writeback)
3028b8546aaSGowrishankar Muthukrishnan 		return -EINVAL;
3038b8546aaSGowrishankar Muthukrishnan 
3048b8546aaSGowrishankar Muthukrishnan 	for (i = 0; i < RTE_DIM(algo_con); i++)
3058b8546aaSGowrishankar Muthukrishnan 		if (strstr(algo_str, algo_con[i].name)) {
3068b8546aaSGowrishankar Muthukrishnan 			info.interim_info.aes_data.cipher_algo =
3078b8546aaSGowrishankar Muthukrishnan 				(uint32_t)algo_con[i].algo;
3088b8546aaSGowrishankar Muthukrishnan 			break;
3098b8546aaSGowrishankar Muthukrishnan 		}
3108b8546aaSGowrishankar Muthukrishnan 
3118b8546aaSGowrishankar Muthukrishnan 	if (i >= RTE_DIM(algo_con))
3128b8546aaSGowrishankar Muthukrishnan 		return -EINVAL;
3138b8546aaSGowrishankar Muthukrishnan 
3148b8546aaSGowrishankar Muthukrishnan 	return 0;
3158b8546aaSGowrishankar Muthukrishnan }
316*8d70a194SDavid Marchand #endif /* USE_JANSSON */
3178b8546aaSGowrishankar Muthukrishnan 
318cd255ccfSMarko Kovacevic static int
319cd255ccfSMarko Kovacevic parse_test_aes_writeback(struct fips_val *val)
320cd255ccfSMarko Kovacevic {
321cd255ccfSMarko Kovacevic 	if (info.op == FIPS_TEST_ENC_AUTH_GEN)
322cd255ccfSMarko Kovacevic 		fprintf(info.fp_wr, "%s", CT_STR);
323cd255ccfSMarko Kovacevic 	else
324cd255ccfSMarko Kovacevic 		fprintf(info.fp_wr, "%s", PT_STR);
325cd255ccfSMarko Kovacevic 
326cd255ccfSMarko Kovacevic 	parse_write_hex_str(val);
327cd255ccfSMarko Kovacevic 
328cd255ccfSMarko Kovacevic 	return 0;
329cd255ccfSMarko Kovacevic }
330cd255ccfSMarko Kovacevic 
331cd255ccfSMarko Kovacevic static int
332cd255ccfSMarko Kovacevic rsp_test_aes_check(struct fips_val *val)
333cd255ccfSMarko Kovacevic {
334cd255ccfSMarko Kovacevic 	struct fips_val *data;
335cd255ccfSMarko Kovacevic 
336cd255ccfSMarko Kovacevic 	if (info.op == FIPS_TEST_ENC_AUTH_GEN)
337cd255ccfSMarko Kovacevic 		data = &vec.ct;
338cd255ccfSMarko Kovacevic 	else
339cd255ccfSMarko Kovacevic 		data = &vec.pt;
340cd255ccfSMarko Kovacevic 
341cd255ccfSMarko Kovacevic 	if (memcmp(val->val, data->val, val->len) == 0)
342cd255ccfSMarko Kovacevic 		fprintf(info.fp_wr, "Success\n");
343cd255ccfSMarko Kovacevic 	else
344cd255ccfSMarko Kovacevic 		fprintf(info.fp_wr, "Failed\n");
345cd255ccfSMarko Kovacevic 
346cd255ccfSMarko Kovacevic 	return 0;
347cd255ccfSMarko Kovacevic }
348cd255ccfSMarko Kovacevic 
349cd255ccfSMarko Kovacevic int
350cd255ccfSMarko Kovacevic parse_test_aes_init(void)
351cd255ccfSMarko Kovacevic {
352cd255ccfSMarko Kovacevic 	char *tmp;
353cd255ccfSMarko Kovacevic 	uint32_t i, j;
354cd255ccfSMarko Kovacevic 
355cd255ccfSMarko Kovacevic 	for (i = 0; i < info.nb_vec_lines; i++) {
356cd255ccfSMarko Kovacevic 		char *line = info.vec[i];
357cd255ccfSMarko Kovacevic 
358cd255ccfSMarko Kovacevic 		tmp = strstr(line, MODE_STR);
359cd255ccfSMarko Kovacevic 		if (tmp) {
360cd255ccfSMarko Kovacevic 			for (j = 0; j < RTE_DIM(aes_test_types); j++)
361cd255ccfSMarko Kovacevic 				if (strstr(line, aes_test_types[j].desc)) {
362cd255ccfSMarko Kovacevic 					info.interim_info.aes_data.test_type =
363cd255ccfSMarko Kovacevic 							aes_test_types[j].type;
364cd255ccfSMarko Kovacevic 					break;
365cd255ccfSMarko Kovacevic 				}
366cd255ccfSMarko Kovacevic 
367cd255ccfSMarko Kovacevic 			if (j >= RTE_DIM(aes_test_types))
368cd255ccfSMarko Kovacevic 				return -EINVAL;
369cd255ccfSMarko Kovacevic 
370cd255ccfSMarko Kovacevic 			tmp = strstr(line, ALGO_STR);
371cd255ccfSMarko Kovacevic 			if (!tmp)
372cd255ccfSMarko Kovacevic 				return -EINVAL;
373cd255ccfSMarko Kovacevic 
374cd255ccfSMarko Kovacevic 			tmp += strlen(ALGO_STR);
375cd255ccfSMarko Kovacevic 			for (j = 0; j < RTE_DIM(algo_con); j++)
376cd255ccfSMarko Kovacevic 				if (strcmp(algo_con[j].name, tmp) == 0) {
377cd255ccfSMarko Kovacevic 					info.interim_info.aes_data.cipher_algo =
378cd255ccfSMarko Kovacevic 						(uint32_t)algo_con[j].algo;
379cd255ccfSMarko Kovacevic 					break;
380cd255ccfSMarko Kovacevic 				}
381cd255ccfSMarko Kovacevic 			if (j >= RTE_DIM(algo_con))
382cd255ccfSMarko Kovacevic 				return -EINVAL;
383cd255ccfSMarko Kovacevic 
384cd255ccfSMarko Kovacevic 			continue;
385cd255ccfSMarko Kovacevic 		}
386cd255ccfSMarko Kovacevic 
387cd255ccfSMarko Kovacevic 		tmp = strstr(line, OP_STR);
388cd255ccfSMarko Kovacevic 		if (tmp)
389cd255ccfSMarko Kovacevic 			continue;
390cd255ccfSMarko Kovacevic 
391cd255ccfSMarko Kovacevic 		tmp = strstr(line, KEY_SIZE_STR);
392cd255ccfSMarko Kovacevic 		if (tmp) {
393cd255ccfSMarko Kovacevic 			tmp += strlen(KEY_SIZE_STR);
394cd255ccfSMarko Kovacevic 			if (parser_read_uint32
395cd255ccfSMarko Kovacevic 					(&info.interim_info.aes_data.key_len,
396cd255ccfSMarko Kovacevic 							tmp) < 0)
397cd255ccfSMarko Kovacevic 				return -EINVAL;
398cd255ccfSMarko Kovacevic 
399cd255ccfSMarko Kovacevic 			info.interim_info.aes_data.key_len /= 8;
400cd255ccfSMarko Kovacevic 
401cd255ccfSMarko Kovacevic 			continue;
402cd255ccfSMarko Kovacevic 		}
403cd255ccfSMarko Kovacevic 	}
404cd255ccfSMarko Kovacevic 
405cd255ccfSMarko Kovacevic 	info.parse_writeback = parse_test_aes_writeback;
406cd255ccfSMarko Kovacevic 	info.callbacks = aes_tests_vectors;
407cd255ccfSMarko Kovacevic 	info.interim_callbacks = aes_tests_interim_vectors;
408cd255ccfSMarko Kovacevic 	info.writeback_callbacks = aes_writeback_callbacks;
409cd255ccfSMarko Kovacevic 	info.kat_check = rsp_test_aes_check;
410cd255ccfSMarko Kovacevic 
411cd255ccfSMarko Kovacevic 	return 0;
412cd255ccfSMarko Kovacevic }
413