[PATCH v1] examples/fips_validation: add parsing for sha

Gowrishankar Muthukrishnan gmuthukrishn at marvell.com
Wed Jun 29 11:38:08 CEST 2022


Hi Fan,
<snip>
> > --- a/examples/fips_validation/main.c
> > +++ b/examples/fips_validation/main.c
> > @@ -1693,19 +1693,24 @@ fips_mct_sha_test(void)
> >  #define SHA_EXTERN_ITER	100
> >  #define SHA_INTERN_ITER	1000
> >  #define SHA_MD_BLOCK	3
> > -	struct fips_val val = {NULL, 0}, md[SHA_MD_BLOCK];
> > +	struct fips_val val[2] = {{NULL, 0},}, md[SHA_MD_BLOCK], msg;
> 
> I see to get around with the callback function limitation you extend the fips val
> to an array. Nice move! But if it is not too much trouble for you - please
> comment the purpose of the change - it will make the future maintenance much
> easier!

Yes, I have added a comment on why val is an array in V3 patch.

> 
> >  	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);
> >  	for (i = 0; i < SHA_MD_BLOCK; i++)
> >  		md[i].val = rte_malloc(NULL, (MAX_DIGEST_SIZE*2), 0);
> >
> >  	rte_free(vec.pt.val);
> >  	vec.pt.val = rte_malloc(NULL, (MAX_DIGEST_SIZE*SHA_MD_BLOCK), 0);
> >
> > -	fips_test_write_one_case();
> > -	fprintf(info.fp_wr, "\n");
> > +	if (info.file_type != FIPS_TYPE_JSON) {
> > +		fips_test_write_one_case();
> > +		fprintf(info.fp_wr, "\n");
> > +	}
> >
> >  	for (j = 0; j < SHA_EXTERN_ITER; j++) {
> >
> > @@ -1719,6 +1724,9 @@ fips_mct_sha_test(void)
> >  			vec.cipher_auth.digest.len);
> >  		md[2].len = vec.cipher_auth.digest.len;
> >
> > +		for (i = 0; i < SHA_MD_BLOCK; i++)
> > +			memcpy(&msg.val[i * md[i].len], md[i].val, md[i].len);
> > +
> >  		for (i = 0; i < (SHA_INTERN_ITER); i++) {
> >
> >  			memcpy(vec.pt.val, md[0].val,
> > @@ -1742,7 +1750,7 @@ fips_mct_sha_test(void)
> >  				return ret;
> >  			}
> >
> > -			ret = get_writeback_data(&val);
> > +			ret = get_writeback_data(&val[0]);
> >  			if (ret < 0)
> >  				return ret;
> >
> > @@ -1751,7 +1759,7 @@ fips_mct_sha_test(void)
> >  			memcpy(md[1].val, md[2].val, md[2].len);
> >  			md[1].len = md[2].len;
> >
> > -			memcpy(md[2].val, (val.val + vec.pt.len),
> > +			memcpy(md[2].val, (val[0].val + vec.pt.len),
> >  				vec.cipher_auth.digest.len);
> >  			md[2].len = vec.cipher_auth.digest.len;
> >  		}
> > @@ -1759,11 +1767,14 @@ 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;
> >
> > -		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);
> > +		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);
> >  	}
> >
> >  	for (i = 0; i < (SHA_MD_BLOCK); i++) @@ -1771,7 +1782,8 @@
> > fips_mct_sha_test(void)
> >
> >  	rte_free(vec.pt.val);
> >
> > -	free(val.val);
> > +	free(val[0].val);
> 
> It took me a while to understand why you don't free val[1] ??.
> Nicely done anyway.
> 
> > +	free(msg.val);
> >
> >  	return 0;
> >  }
> > @@ -1996,6 +2008,9 @@ fips_test_one_test_group(void)
> >  	case FIPS_TEST_ALGO_AES:
> >  		ret = parse_test_aes_json_init();
> >  		break;
> > +	case FIPS_TEST_ALGO_SHA:
> > +		ret = parse_test_sha_json_init();
> > +		break;
> >  	default:
> >  		return -EINVAL;
> >  	}
> > --
> > 2.25.1
> 
> Other than that
> Acked-by: Fan Zhang <roy.fan.zhang at intel.com>

Thanks.


More information about the dev mailing list