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