[v1] examples/fips_validation: fix memory allocation in aes mct test

Message ID 20220713064439.3990811-1-gmuthukrishn@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: akhil goyal
Headers
Series [v1] examples/fips_validation: fix memory allocation in aes mct test |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
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/github-robot: build success github build: passed
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/intel-Testing success Testing PASS

Commit Message

Gowrishankar Muthukrishnan July 13, 2022, 6:44 a.m. UTC
  Instead of allocating memory in every external iteration, do once
in the beginning of AES MCT tests and free at the end.

Fixes: 8b8546aaedf ("examples/fips_validation: add parsing for AES-CBC")

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
---
 examples/fips_validation/main.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)
  

Patch

diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c
index 5e65c5e193..8babbb3298 100644
--- a/examples/fips_validation/main.c
+++ b/examples/fips_validation/main.c
@@ -1588,9 +1588,12 @@  fips_mct_aes_test(void)
 	if (info.interim_info.aes_data.cipher_algo == RTE_CRYPTO_CIPHER_AES_ECB)
 		return fips_mct_aes_ecb_test();
 
-	memset(&pt, 0, sizeof(struct fips_val));
-	memset(&ct, 0, sizeof(struct fips_val));
-	memset(&iv, 0, sizeof(struct fips_val));
+	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 < AES_EXTERN_ITER; i++) {
 		if (info.file_type != FIPS_TYPE_JSON) {
 			if (i != 0)
@@ -1622,16 +1625,8 @@  fips_mct_aes_test(void)
 
 			if (j == 0) {
 				memcpy(prev_out, val[0].val, AES_BLOCK_SIZE);
-				pt.len = vec.pt.len;
-				pt.val = calloc(1, pt.len);
 				memcpy(pt.val, vec.pt.val, pt.len);
-
-				ct.len = vec.ct.len;
-				ct.val = calloc(1, ct.len);
 				memcpy(ct.val, vec.ct.val, ct.len);
-
-				iv.len = vec.iv.len;
-				iv.val = calloc(1, iv.len);
 				memcpy(iv.val, vec.iv.val, iv.len);
 
 				if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
@@ -1670,12 +1665,8 @@  fips_mct_aes_test(void)
 		if (info.file_type != FIPS_TYPE_JSON)
 			fprintf(info.fp_wr, "\n");
 
-		if (i == AES_EXTERN_ITER - 1) {
-			free(pt.val);
-			free(ct.val);
-			free(iv.val);
+		if (i == AES_EXTERN_ITER - 1)
 			continue;
-		}
 
 		/** update key */
 		memcpy(&val_key, &vec.cipher_auth.key, sizeof(val_key));
@@ -1706,6 +1697,9 @@  fips_mct_aes_test(void)
 	}
 
 	free(val[0].val);
+	free(pt.val);
+	free(ct.val);
+	free(iv.val);
 
 	return 0;
 }