diff mbox series

[v1] examples/fips_validation: fix SHA MCT test from segfault

Message ID cc33a1f1fa1da154bddd019ee5578af7f99df23d.1663336827.git.gmuthukrishn@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers show
Series [v1] examples/fips_validation: fix SHA MCT test from segfault | expand

Checks

Context Check Description
ci/intel-Testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance 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-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Gowrishankar Muthukrishnan Sept. 16, 2022, 2:01 p.m. UTC
In case of FIPS 140-2 format of test vectors in MCT test, msg is
not given in the test vector, hence pt will be NULL which test
function has to handle correctly.

Fixes: d5c247145c2c ("examples/fips_validation: add parsing for SHA")

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

Comments

Brian Dooley Sept. 23, 2022, 4:25 p.m. UTC | #1
> -----Original Message-----
> From: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
> Sent: Friday, September 16, 2022 3:02 PM
> To: dev@dpdk.org
> Cc: Anoob Joseph <anoobj@marvell.com>; Zhang, Roy Fan
> <roy.fan.zhang@intel.com>; Dooley, Brian <brian.dooley@intel.com>; Akhil
> Goyal <gakhil@marvell.com>; jerinj@marvell.com; Gowrishankar
> Muthukrishnan <gmuthukrishn@marvell.com>
> Subject: [v1] examples/fips_validation: fix SHA MCT test from segfault
> 
> In case of FIPS 140-2 format of test vectors in MCT test, msg is not given in
> the test vector, hence pt will be NULL which test function has to handle
> correctly.
> 
> Fixes: d5c247145c2c ("examples/fips_validation: add parsing for SHA")
> 
> Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
> ---
>  examples/fips_validation/main.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/examples/fips_validation/main.c
> b/examples/fips_validation/main.c index 8bd5a66889..cab3dd22b9 100644
> --- a/examples/fips_validation/main.c
> +++ b/examples/fips_validation/main.c
> @@ -1696,13 +1696,14 @@ fips_mct_sha_test(void)
>  	/* val[0] is op result and other value is for parse_writeback callback
> */
>  	struct fips_val val[2] = {{NULL, 0},};
>  	struct fips_val  md[SHA_MD_BLOCK], msg;
> -	char temp[MAX_DIGEST_SIZE*2];
>  	int ret;
>  	uint32_t i, j;
> 
>  	msg.len = SHA_MD_BLOCK * vec.cipher_auth.digest.len;
>  	msg.val = calloc(1, msg.len);
> -	memcpy(vec.cipher_auth.digest.val, vec.pt.val,
> vec.cipher_auth.digest.len);
> +	if (vec.pt.val)
> +		memcpy(vec.cipher_auth.digest.val, vec.pt.val,
> +vec.cipher_auth.digest.len);
> +
>  	for (i = 0; i < SHA_MD_BLOCK; i++)
>  		md[i].val = rte_malloc(NULL, (MAX_DIGEST_SIZE*2), 0);
> 
> @@ -1769,14 +1770,15 @@ fips_mct_sha_test(void)
>  		memcpy(vec.cipher_auth.digest.val, md[2].val, md[2].len);
>  		vec.cipher_auth.digest.len = md[2].len;
> 
> -		if (info.file_type != FIPS_TYPE_JSON) {
> +		if (info.file_type != FIPS_TYPE_JSON)
>  			fprintf(info.fp_wr, "COUNT = %u\n", j);
> -			writeback_hex_str("", temp,
> &vec.cipher_auth.digest);
> -			fprintf(info.fp_wr, "MD = %s\n\n", temp);
> -		}
> +
>  		val[1].val = msg.val;
>  		val[1].len = msg.len;
>  		info.parse_writeback(val);
> +
> +		if (info.file_type != FIPS_TYPE_JSON)
> +			fprintf(info.fp_wr, "\n");
>  	}
> 
>  	for (i = 0; i < (SHA_MD_BLOCK); i++)
> --
> 2.25.1

LGTM

Tested-by: Brian Dooley <brian.dooley@intel.com>
Akhil Goyal Oct. 7, 2022, 9:53 a.m. UTC | #2
> > Subject: [v1] examples/fips_validation: fix SHA MCT test from segfault
> >
> > In case of FIPS 140-2 format of test vectors in MCT test, msg is not given in
> > the test vector, hence pt will be NULL which test function has to handle
> > correctly.
> >
> > Fixes: d5c247145c2c ("examples/fips_validation: add parsing for SHA")
> >
> > Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
> > ---
> Tested-by: Brian Dooley <brian.dooley@intel.com>
Applied to dpdk-next-crypto

Thanks.
diff mbox series

Patch

diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c
index 8bd5a66889..cab3dd22b9 100644
--- a/examples/fips_validation/main.c
+++ b/examples/fips_validation/main.c
@@ -1696,13 +1696,14 @@  fips_mct_sha_test(void)
 	/* val[0] is op result and other value is for parse_writeback callback */
 	struct fips_val val[2] = {{NULL, 0},};
 	struct fips_val  md[SHA_MD_BLOCK], msg;
-	char temp[MAX_DIGEST_SIZE*2];
 	int ret;
 	uint32_t i, j;
 
 	msg.len = SHA_MD_BLOCK * vec.cipher_auth.digest.len;
 	msg.val = calloc(1, msg.len);
-	memcpy(vec.cipher_auth.digest.val, vec.pt.val, vec.cipher_auth.digest.len);
+	if (vec.pt.val)
+		memcpy(vec.cipher_auth.digest.val, vec.pt.val, vec.cipher_auth.digest.len);
+
 	for (i = 0; i < SHA_MD_BLOCK; i++)
 		md[i].val = rte_malloc(NULL, (MAX_DIGEST_SIZE*2), 0);
 
@@ -1769,14 +1770,15 @@  fips_mct_sha_test(void)
 		memcpy(vec.cipher_auth.digest.val, md[2].val, md[2].len);
 		vec.cipher_auth.digest.len = md[2].len;
 
-		if (info.file_type != FIPS_TYPE_JSON) {
+		if (info.file_type != FIPS_TYPE_JSON)
 			fprintf(info.fp_wr, "COUNT = %u\n", j);
-			writeback_hex_str("", temp, &vec.cipher_auth.digest);
-			fprintf(info.fp_wr, "MD = %s\n\n", temp);
-		}
+
 		val[1].val = msg.val;
 		val[1].len = msg.len;
 		info.parse_writeback(val);
+
+		if (info.file_type != FIPS_TYPE_JSON)
+			fprintf(info.fp_wr, "\n");
 	}
 
 	for (i = 0; i < (SHA_MD_BLOCK); i++)