[v1,2/2] examples/fips_validation: add parsing for tdes

Message ID 73d188a54d126678538a1a2b7d8b9aae95e4e6d8.1657694117.git.gmuthukrishn@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: akhil goyal
Headers
Series [v1,1/2] examples/fips_validation: skip offsetting source for json vectors |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/intel-Testing success Testing PASS

Commit Message

Gowrishankar Muthukrishnan July 13, 2022, 6:39 a.m. UTC
  Added function to parse algorithm for TDES CBC and ECB tests in json.

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
---
 doc/guides/sample_app_ug/fips_validation.rst  |   2 +
 examples/fips_validation/fips_validation.c    |   5 +-
 examples/fips_validation/fips_validation.h    |   4 +
 .../fips_validation/fips_validation_tdes.c    | 333 ++++++++++++++++++
 examples/fips_validation/main.c               |  94 +++--
 5 files changed, 403 insertions(+), 35 deletions(-)
  

Patch

diff --git a/doc/guides/sample_app_ug/fips_validation.rst b/doc/guides/sample_app_ug/fips_validation.rst
index 6f4bd34726..33a8c97575 100644
--- a/doc/guides/sample_app_ug/fips_validation.rst
+++ b/doc/guides/sample_app_ug/fips_validation.rst
@@ -64,6 +64,8 @@  ACVP
     * AES-XTS (128,256) - AFT
     * HMAC (SHA1, SHA224, SHA256, SHA384, SHA512)
     * SHA (1, 256, 384, 512) - AFT, MCT
+    * TDES-CBC - AFT, MCT
+    * TDES-ECB - AFT, MCT
 
 
 Application Information
diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c
index c15f0f0202..af0cc7a163 100644
--- a/examples/fips_validation/fips_validation.c
+++ b/examples/fips_validation/fips_validation.c
@@ -468,6 +468,9 @@  fips_test_parse_one_json_vector_set(void)
 		info.algo = FIPS_TEST_ALGO_AES_XTS;
 	else if (strstr(algo_str, "SHA"))
 		info.algo = FIPS_TEST_ALGO_SHA;
+	else if (strstr(algo_str, "TDES-CBC") ||
+		strstr(algo_str, "TDES-ECB"))
+		info.algo = FIPS_TEST_ALGO_TDES;
 	else
 		return -EINVAL;
 
@@ -529,7 +532,7 @@  fips_test_parse_one_json_case(void)
 			 * is not included in the string being parsed.
 			 */
 			ret = info.callbacks[i].cb(
-				"", info.one_line_text,
+				info.callbacks[i].key, info.one_line_text,
 				info.callbacks[i].val
 			);
 			if (ret < 0)
diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h
index 5c1abcbd91..f42040f460 100644
--- a/examples/fips_validation/fips_validation.h
+++ b/examples/fips_validation/fips_validation.h
@@ -114,6 +114,7 @@  enum fips_tdes_test_types {
 	TDES_VARIABLE_KEY,
 	TDES_VARIABLE_TEXT,
 	TDES_KAT,
+	TDES_AFT, /* Functional Test */
 	TDES_MCT, /* Monte Carlo (Modes) Test */
 	TDES_MMT /* Multi block Message Test */
 };
@@ -290,6 +291,9 @@  parse_test_sha_json_algorithm(void);
 
 int
 parse_test_sha_json_test_type(void);
+
+int
+parse_test_tdes_json_init(void);
 #endif /* USE_JANSSON */
 
 int
diff --git a/examples/fips_validation/fips_validation_tdes.c b/examples/fips_validation/fips_validation_tdes.c
index a1ddd57cfd..a418fd9d35 100644
--- a/examples/fips_validation/fips_validation_tdes.c
+++ b/examples/fips_validation/fips_validation_tdes.c
@@ -38,6 +38,21 @@ 
 
 #define DEVICE_STR	"# Config Info for : "
 
+#define ALGO_JSON_STR	"algorithm"
+#define TESTTYPE_JSON_STR "testType"
+#define DIR_JSON_STR	"direction"
+#define KEYOPT_JSON_STR	"keyingOption"
+
+#define PT_JSON_STR	"pt"
+#define CT_JSON_STR	"ct"
+#define IV_JSON_STR	"iv"
+#define KEY1_JSON_STR	"key1"
+#define KEY2_JSON_STR	"key2"
+#define KEY3_JSON_STR	"key3"
+
+#define OP_ENC_JSON_STR	"encrypt"
+#define OP_DEC_JSON_STR	"decrypt"
+
 struct {
 	uint32_t type;
 	const char *desc;
@@ -48,6 +63,7 @@  struct {
 		{TDES_VARIABLE_KEY, "VARIABLE KEY"},
 		{TDES_VARIABLE_TEXT, "VARIABLE PLAINTEXT/CIPHERTEXT"},
 		{TDES_VARIABLE_TEXT, "KAT"},
+		{TDES_AFT, "Functional Test"},
 		{TDES_MCT, "Monte Carlo (Modes) Test"},
 		{TDES_MMT, "Multi block Message Test"},
 };
@@ -92,6 +108,323 @@  struct fips_test_callback tdes_writeback_callbacks[] = {
 		{NULL, NULL, NULL} /**< end pointer */
 };
 
+#ifdef USE_JANSSON
+static struct {
+	enum fips_tdes_test_types type;
+	const char *desc;
+} const tdes_test_types[] = {
+	{TDES_AFT, "AFT"},
+	{TDES_MCT, "MCT"},
+};
+
+static struct {
+	enum fips_tdes_test_mode mode;
+	const char *desc;
+} const tdes_test_modes[] = {
+	{TDES_MODE_CBC, "CBC"},
+	{TDES_MODE_ECB, "ECB"},
+};
+
+static int
+parser_tdes_read_key(const char *key, char *src, struct fips_val *val)
+{
+	uint8_t tmp_key[24] = {0};
+	uint32_t len, i;
+
+	len = strlen(src) / 2;
+
+	if (val->val) {
+		memcpy(tmp_key, val->val, val->len);
+		rte_free(val->val);
+	}
+
+	val->val = rte_zmalloc(NULL, 24, 0);
+	if (!val->val)
+		return -1;
+
+	memcpy(val->val, tmp_key, 24);
+
+	if (strstr(key, KEY1_JSON_STR)) {
+		for (i = 0; i < len; i++) {
+			char byte[3] = {src[i * 2], src[i * 2 + 1], '\0'};
+
+			if (parser_read_uint8_hex(&val->val[i], byte) < 0)
+				goto error_exit;
+		}
+
+		if (info.interim_info.tdes_data.nb_keys == 2)
+			memcpy(val->val + 16, val->val, 8);
+
+	} else if (strstr(key, KEY2_JSON_STR)) {
+		for (i = 0; i < len; i++) {
+			char byte[3] = {src[i * 2], src[i * 2 + 1], '\0'};
+
+			if (parser_read_uint8_hex(&val->val[i + 8], byte) < 0)
+				goto error_exit;
+		}
+
+	} else if (strstr(key, KEY3_JSON_STR)) {
+		for (i = 0; i < len; i++) {
+			char byte[3] = {src[i * 2], src[i * 2 + 1], '\0'};
+
+			if (parser_read_uint8_hex(&val->val[i + 16], byte) < 0)
+				goto error_exit;
+		}
+	} else
+		return -EINVAL;
+
+	val->len = 24;
+
+	return 0;
+
+error_exit:
+	rte_free(val->val);
+	memset(val, 0, sizeof(*val));
+	return -EINVAL;
+}
+
+struct fips_test_callback tdes_dec_json_vectors[] =	{
+	{KEY1_JSON_STR, parser_tdes_read_key, &vec.cipher_auth.key},
+	{KEY2_JSON_STR, parser_tdes_read_key, &vec.cipher_auth.key},
+	{KEY3_JSON_STR, parser_tdes_read_key, &vec.cipher_auth.key},
+	{IV_JSON_STR, parse_uint8_hex_str, &vec.iv},
+	{CT_JSON_STR, parse_uint8_hex_str, &vec.ct},
+	{NULL, NULL, NULL} /**< end pointer */
+};
+
+struct fips_test_callback tdes_enc_json_vectors[] =	{
+	{KEY1_JSON_STR, parser_tdes_read_key, &vec.cipher_auth.key},
+	{KEY2_JSON_STR, parser_tdes_read_key, &vec.cipher_auth.key},
+	{KEY3_JSON_STR, parser_tdes_read_key, &vec.cipher_auth.key},
+	{IV_JSON_STR, parse_uint8_hex_str, &vec.iv},
+	{PT_JSON_STR, parse_uint8_hex_str, &vec.pt},
+	{NULL, NULL, NULL} /**< end pointer */
+};
+
+static int
+parse_test_tdes_json_writeback(struct fips_val *val)
+{
+	struct fips_val tmp_val;
+	json_t *tcId;
+
+	tcId = json_object_get(json_info.json_test_case, "tcId");
+
+	json_info.json_write_case = json_object();
+	json_object_set(json_info.json_write_case, "tcId", tcId);
+
+	if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
+		json_t *ct;
+
+		tmp_val.val = val->val;
+		tmp_val.len = vec.pt.len;
+
+		writeback_hex_str("", info.one_line_text, &tmp_val);
+		ct = json_string(info.one_line_text);
+		json_object_set_new(json_info.json_write_case, CT_JSON_STR, ct);
+
+		tmp_val.val = val->val + vec.pt.len;
+		tmp_val.len = val->len - vec.pt.len;
+
+		writeback_hex_str("", info.one_line_text, &tmp_val);
+	} else {
+		if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) {
+			tmp_val.val = val->val;
+			tmp_val.len = vec.ct.len;
+
+			writeback_hex_str("", info.one_line_text, &tmp_val);
+			json_object_set_new(json_info.json_write_case, PT_JSON_STR,
+								json_string(info.one_line_text));
+		} else {
+			json_object_set_new(json_info.json_write_case, "testPassed", json_false());
+		}
+	}
+
+	return 0;
+}
+
+static int
+parse_test_tdes_mct_json_writeback(struct fips_val *val)
+{
+	json_t *tcId, *resArr, *res, *ct, *pt, *key, *iv;
+	struct fips_val tmp_val;
+
+	tcId = json_object_get(json_info.json_test_case, "tcId");
+	if (json_info.json_write_case) {
+		json_t *wcId;
+
+		wcId = json_object_get(json_info.json_write_case, "tcId");
+		if (!json_equal(tcId, wcId)) {
+			json_info.json_write_case = json_object();
+			json_object_set(json_info.json_write_case, "tcId", tcId);
+			json_object_set(json_info.json_write_case, "resultsArray", json_array());
+		}
+	} else {
+		json_info.json_write_case = json_object();
+		json_object_set(json_info.json_write_case, "tcId", tcId);
+		json_object_set(json_info.json_write_case, "resultsArray", json_array());
+	}
+
+	resArr = json_object_get(json_info.json_write_case, "resultsArray");
+	if (!json_is_array(resArr))
+		return -EINVAL;
+
+	res = json_object();
+	if (info .op == FIPS_TEST_ENC_AUTH_GEN) {
+		tmp_val.len = 8;
+		tmp_val.val = vec.cipher_auth.key.val;
+		writeback_hex_str("", info.one_line_text, &tmp_val);
+		key = json_string(info.one_line_text);
+		json_object_set_new(res, KEY1_JSON_STR, key);
+
+		tmp_val.val = vec.cipher_auth.key.val + 8;
+		writeback_hex_str("", info.one_line_text, &tmp_val);
+		key = json_string(info.one_line_text);
+		json_object_set_new(res, KEY2_JSON_STR, key);
+
+		tmp_val.val =  vec.cipher_auth.key.val + 16;
+		writeback_hex_str("", info.one_line_text, &tmp_val);
+		key = json_string(info.one_line_text);
+		json_object_set_new(res, KEY3_JSON_STR, key);
+
+		if (info.interim_info.tdes_data.test_mode == TDES_MODE_CBC) {
+			writeback_hex_str("", info.one_line_text, &val[2]);
+			iv = json_string(info.one_line_text);
+			json_object_set_new(res, IV_JSON_STR, iv);
+		}
+
+		writeback_hex_str("", info.one_line_text, &val[1]);
+		pt = json_string(info.one_line_text);
+		json_object_set_new(res, PT_JSON_STR, pt);
+
+		tmp_val.val = val->val;
+		tmp_val.len = vec.pt.len;
+
+		writeback_hex_str("", info.one_line_text, &tmp_val);
+		ct = json_string(info.one_line_text);
+		json_object_set_new(res, CT_JSON_STR, ct);
+
+		tmp_val.val = val->val + vec.pt.len;
+		tmp_val.len = val->len - vec.pt.len;
+
+		writeback_hex_str("", info.one_line_text, &tmp_val);
+	} else {
+		if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) {
+			tmp_val.len = 8;
+			tmp_val.val = vec.cipher_auth.key.val;
+			writeback_hex_str("", info.one_line_text, &tmp_val);
+			key = json_string(info.one_line_text);
+			json_object_set_new(res, KEY1_JSON_STR, key);
+
+			tmp_val.val = vec.cipher_auth.key.val + 8;
+			writeback_hex_str("", info.one_line_text, &tmp_val);
+			key = json_string(info.one_line_text);
+			json_object_set_new(res, KEY2_JSON_STR, key);
+
+			tmp_val.val = vec.cipher_auth.key.val + 16;
+			writeback_hex_str("", info.one_line_text, &tmp_val);
+			key = json_string(info.one_line_text);
+			json_object_set_new(res, KEY3_JSON_STR, key);
+
+			if (info.interim_info.tdes_data.test_mode == TDES_MODE_CBC) {
+				writeback_hex_str("", info.one_line_text, &val[2]);
+				iv = json_string(info.one_line_text);
+				json_object_set_new(res, IV_JSON_STR, iv);
+			}
+
+			tmp_val.val = val->val;
+			tmp_val.len = vec.ct.len;
+
+			writeback_hex_str("", info.one_line_text, &tmp_val);
+			pt = json_string(info.one_line_text);
+			json_object_set_new(res, PT_JSON_STR, pt);
+
+			writeback_hex_str("", info.one_line_text, &val[1]);
+			ct = json_string(info.one_line_text);
+			json_object_set_new(res, CT_JSON_STR, ct);
+		} else {
+			json_object_set_new(json_info.json_write_case, "testPassed", json_false());
+		}
+	}
+
+	json_array_append_new(resArr, res);
+
+	return 0;
+}
+
+int parse_test_tdes_json_init(void)
+{
+	json_t *type_obj = json_object_get(json_info.json_test_group, TESTTYPE_JSON_STR);
+	json_t *algo_obj = json_object_get(json_info.json_vector_set, ALGO_JSON_STR);
+	const char *type_str = json_string_value(type_obj);
+	const char *algo_str = json_string_value(algo_obj);
+	uint32_t i;
+
+	if (json_info.json_test_group) {
+		json_t *direction_obj, *opt_obj;
+		const char *direction_str;
+		int opt_val;
+
+		direction_obj = json_object_get(json_info.json_test_group, DIR_JSON_STR);
+		direction_str = json_string_value(direction_obj);
+
+		if (strcmp(direction_str, OP_ENC_JSON_STR) == 0) {
+			info.op = FIPS_TEST_ENC_AUTH_GEN;
+			info.callbacks = tdes_enc_json_vectors;
+		} else if (strcmp(direction_str, OP_DEC_JSON_STR) == 0) {
+			info.op = FIPS_TEST_DEC_AUTH_VERIF;
+			info.callbacks = tdes_dec_json_vectors;
+		} else {
+			return -EINVAL;
+		}
+
+		opt_obj = json_object_get(json_info.json_test_group, KEYOPT_JSON_STR);
+		opt_val = json_integer_value(opt_obj);
+		if (opt_val == 2)
+			info.interim_info.tdes_data.nb_keys = 2;
+		else
+			info.interim_info.tdes_data.nb_keys = 3;
+
+		info.interim_callbacks = NULL;
+	}
+
+	for (i = 0; i < RTE_DIM(tdes_test_types); i++)
+		if (strstr(type_str, tdes_test_types[i].desc)) {
+			info.interim_info.tdes_data.test_type =
+				tdes_test_types[i].type;
+			break;
+		}
+
+	if (i >= RTE_DIM(tdes_test_types))
+		return -EINVAL;
+
+	for (i = 0; RTE_DIM(tdes_test_modes); i++)
+		if (strstr(algo_str, tdes_test_modes[i].desc)) {
+			info.interim_info.tdes_data.test_mode =
+				tdes_test_modes[i].mode;
+			break;
+		}
+
+	if (i >= RTE_DIM(tdes_test_modes))
+		return -EINVAL;
+
+	switch (info.interim_info.tdes_data.test_type) {
+	case TDES_AFT:
+		info.parse_writeback = parse_test_tdes_json_writeback;
+		break;
+	case TDES_MCT:
+		info.parse_writeback = parse_test_tdes_mct_json_writeback;
+		break;
+	default:
+		info.parse_writeback = NULL;
+	};
+
+	if (info.parse_writeback == NULL)
+		return -EINVAL;
+
+	return 0;
+}
+#endif /* USE_JANSSON */
+
 static int
 parse_tdes_interim(const char *key, char *text,
 		__rte_unused struct fips_val *val)
diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c
index 8bd5a66889..5e65c5e193 100644
--- a/examples/fips_validation/main.c
+++ b/examples/fips_validation/main.c
@@ -1303,7 +1303,7 @@  fips_mct_tdes_test(void)
 #define TDES_BLOCK_SIZE		8
 #define TDES_EXTERN_ITER	400
 #define TDES_INTERN_ITER	10000
-	struct fips_val val = {NULL, 0}, val_key;
+	struct fips_val val[3] = {{NULL, 0},}, val_key, pt, ct, iv;
 	uint8_t prev_out[TDES_BLOCK_SIZE] = {0};
 	uint8_t prev_prev_out[TDES_BLOCK_SIZE] = {0};
 	uint8_t prev_in[TDES_BLOCK_SIZE] = {0};
@@ -1311,16 +1311,25 @@  fips_mct_tdes_test(void)
 	int ret;
 	int test_mode = info.interim_info.tdes_data.test_mode;
 
+	pt.len = vec.pt.len;
+	pt.val = calloc(1, pt.len);
+	ct.len = vec.ct.len;
+	ct.val = calloc(1, ct.len);
+	iv.len = vec.iv.len;
+	iv.val = calloc(1, iv.len);
+
 	for (i = 0; i < TDES_EXTERN_ITER; i++) {
-		if ((i == 0) && (info.version == 21.4f)) {
-			if (!(strstr(info.vec[0], "COUNT")))
-				fprintf(info.fp_wr, "%s%u\n", "COUNT = ", 0);
-		}
+		if (info.file_type != FIPS_TYPE_JSON) {
+			if ((i == 0) && (info.version == 21.4f)) {
+				if (!(strstr(info.vec[0], "COUNT")))
+					fprintf(info.fp_wr, "%s%u\n", "COUNT = ", 0);
+			}
 
-		if (i != 0)
-			update_info_vec(i);
+			if (i != 0)
+				update_info_vec(i);
 
-		fips_test_write_one_case();
+			fips_test_write_one_case();
+		}
 
 		for (j = 0; j < TDES_INTERN_ITER; j++) {
 			ret = fips_run_test();
@@ -1335,7 +1344,7 @@  fips_mct_tdes_test(void)
 				return ret;
 			}
 
-			ret = get_writeback_data(&val);
+			ret = get_writeback_data(&val[0]);
 			if (ret < 0)
 				return ret;
 
@@ -1343,51 +1352,61 @@  fips_mct_tdes_test(void)
 				memcpy(prev_in, vec.ct.val, TDES_BLOCK_SIZE);
 
 			if (j == 0) {
-				memcpy(prev_out, val.val, TDES_BLOCK_SIZE);
+				memcpy(prev_out, val[0].val, TDES_BLOCK_SIZE);
+				memcpy(pt.val, vec.pt.val, pt.len);
+				memcpy(ct.val, vec.ct.val, ct.len);
+				memcpy(iv.val, vec.iv.val, iv.len);
 
 				if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
 					if (test_mode == TDES_MODE_ECB) {
-						memcpy(vec.pt.val, val.val,
+						memcpy(vec.pt.val, val[0].val,
 							   TDES_BLOCK_SIZE);
 					} else {
 						memcpy(vec.pt.val, vec.iv.val,
 							   TDES_BLOCK_SIZE);
-						memcpy(vec.iv.val, val.val,
+						memcpy(vec.iv.val, val[0].val,
 							   TDES_BLOCK_SIZE);
 					}
-
+					val[1].val = pt.val;
+					val[1].len = pt.len;
+					val[2].val = iv.val;
+					val[2].len = iv.len;
 				} else {
 					if (test_mode == TDES_MODE_ECB) {
-						memcpy(vec.ct.val, val.val,
+						memcpy(vec.ct.val, val[0].val,
 							   TDES_BLOCK_SIZE);
 					} else {
 						memcpy(vec.iv.val, vec.ct.val,
 							   TDES_BLOCK_SIZE);
-						memcpy(vec.ct.val, val.val,
+						memcpy(vec.ct.val, val[0].val,
 							   TDES_BLOCK_SIZE);
 					}
+					val[1].val = ct.val;
+					val[1].len = ct.len;
+					val[2].val = iv.val;
+					val[2].len = iv.len;
 				}
 				continue;
 			}
 
 			if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
 				if (test_mode == TDES_MODE_ECB) {
-					memcpy(vec.pt.val, val.val,
+					memcpy(vec.pt.val, val[0].val,
 						   TDES_BLOCK_SIZE);
 				} else {
-					memcpy(vec.iv.val, val.val,
+					memcpy(vec.iv.val, val[0].val,
 						   TDES_BLOCK_SIZE);
 					memcpy(vec.pt.val, prev_out,
 						   TDES_BLOCK_SIZE);
 				}
 			} else {
 				if (test_mode == TDES_MODE_ECB) {
-					memcpy(vec.ct.val, val.val,
+					memcpy(vec.ct.val, val[0].val,
 						   TDES_BLOCK_SIZE);
 				} else {
 					memcpy(vec.iv.val, vec.ct.val,
 						   TDES_BLOCK_SIZE);
-					memcpy(vec.ct.val, val.val,
+					memcpy(vec.ct.val, val[0].val,
 						   TDES_BLOCK_SIZE);
 				}
 			}
@@ -1395,14 +1414,15 @@  fips_mct_tdes_test(void)
 			if (j == TDES_INTERN_ITER - 1)
 				continue;
 
-			memcpy(prev_out, val.val, TDES_BLOCK_SIZE);
+			memcpy(prev_out, val[0].val, TDES_BLOCK_SIZE);
 
 			if (j == TDES_INTERN_ITER - 3)
-				memcpy(prev_prev_out, val.val, TDES_BLOCK_SIZE);
+				memcpy(prev_prev_out, val[0].val, TDES_BLOCK_SIZE);
 		}
 
-		info.parse_writeback(&val);
-		fprintf(info.fp_wr, "\n");
+		info.parse_writeback(val);
+		if (info.file_type != FIPS_TYPE_JSON)
+			fprintf(info.fp_wr, "\n");
 
 		if (i == TDES_EXTERN_ITER - 1)
 			continue;
@@ -1424,19 +1444,19 @@  fips_mct_tdes_test(void)
 
 			switch (info.interim_info.tdes_data.nb_keys) {
 			case 3:
-				val_key.val[k] ^= val.val[k];
+				val_key.val[k] ^= val[0].val[k];
 				val_key.val[k + 8] ^= prev_out[k];
 				val_key.val[k + 16] ^= prev_prev_out[k];
 				break;
 			case 2:
-				val_key.val[k] ^= val.val[k];
+				val_key.val[k] ^= val[0].val[k];
 				val_key.val[k + 8] ^= prev_out[k];
-				val_key.val[k + 16] ^= val.val[k];
+				val_key.val[k + 16] ^= val[0].val[k];
 				break;
 			default: /* case 1 */
-				val_key.val[k] ^= val.val[k];
-				val_key.val[k + 8] ^= val.val[k];
-				val_key.val[k + 16] ^= val.val[k];
+				val_key.val[k] ^= val[0].val[k];
+				val_key.val[k + 8] ^= val[0].val[k];
+				val_key.val[k + 16] ^= val[0].val[k];
 				break;
 			}
 
@@ -1449,22 +1469,25 @@  fips_mct_tdes_test(void)
 
 		if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
 			if (test_mode == TDES_MODE_ECB) {
-				memcpy(vec.pt.val, val.val, TDES_BLOCK_SIZE);
+				memcpy(vec.pt.val, val[0].val, TDES_BLOCK_SIZE);
 			} else {
-				memcpy(vec.iv.val, val.val, TDES_BLOCK_SIZE);
+				memcpy(vec.iv.val, val[0].val, TDES_BLOCK_SIZE);
 				memcpy(vec.pt.val, prev_out, TDES_BLOCK_SIZE);
 			}
 		} else {
 			if (test_mode == TDES_MODE_ECB) {
-				memcpy(vec.ct.val, val.val, TDES_BLOCK_SIZE);
+				memcpy(vec.ct.val, val[0].val, TDES_BLOCK_SIZE);
 			} else {
 				memcpy(vec.iv.val, prev_out, TDES_BLOCK_SIZE);
-				memcpy(vec.ct.val, val.val, TDES_BLOCK_SIZE);
+				memcpy(vec.ct.val, val[0].val, TDES_BLOCK_SIZE);
 			}
 		}
 	}
 
-	free(val.val);
+	free(val[0].val);
+	free(pt.val);
+	free(ct.val);
+	free(iv.val);
 
 	return 0;
 }
@@ -2013,6 +2036,9 @@  fips_test_one_test_group(void)
 	case FIPS_TEST_ALGO_SHA:
 		ret = parse_test_sha_json_init();
 		break;
+	case FIPS_TEST_ALGO_TDES:
+		ret = parse_test_tdes_json_init();
+		break;
 	default:
 		return -EINVAL;
 	}