From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1D67F4282E; Fri, 24 Mar 2023 10:02:11 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AEA43406B8; Fri, 24 Mar 2023 10:02:10 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id E57DA4021F for ; Fri, 24 Mar 2023 10:02:08 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32O6YP6x018305; Fri, 24 Mar 2023 02:02:07 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=lyhOOzHcKezqU8ZEKv6J4kujx0GXtlhPpFbwbAHXw/U=; b=lUhpILCImLjHbxxsaLcpv507hambGZ/9dFAk5iyl3NvjoY+LKrmGjKGJwI8KiGKV9MwT 4CBJvSrioYcA7HWf50pWBXqqq0jki+XqqSTwyB2KeYjPySVl8nnTTThFvkCOqh4Op7Pq 0XaCCvh5/dmuA6cRDV3a4+fc1lOHXE9OuHKizgT2sAQbiXgJ+w36bEIghf/dDzeZ17wg Wk+e/kVm5iZ56jp5ISltt0s+owvviNs8pF/DHK+tdoLgy9W2jnHpReoEjogUW7i5OTBy hPuXxaxkBjj1FuID9JB5GmY1pgDSmCJIDA+abjdcWP/BkyLNms8rvATWMXWdm+BJnicd gw== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3ph6q3rebu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 24 Mar 2023 02:02:07 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Fri, 24 Mar 2023 02:02:06 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Fri, 24 Mar 2023 02:02:06 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 0F5703F704A; Fri, 24 Mar 2023 02:02:03 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: , , Akhil Goyal , Brian Dooley , "Gowrishankar Muthukrishnan" Subject: [PATCH] examples/fips_validation: fix digest in non JSON SHA MCT Date: Fri, 24 Mar 2023 14:32:00 +0530 Message-ID: <20230324090200.426613-1-gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: vADz6TQA53KV00lPUrzrM_YlZratxfn2 X-Proofpoint-ORIG-GUID: vADz6TQA53KV00lPUrzrM_YlZratxfn2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-24_04,2023-03-23_02,2023-02-09_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Non JSON SHA MCT tests produce incorrect digest due to a regression while handling MD blocks in common for all kind of SHA, SHA2, SHA3 and SHAKE algorithms. Fixing this along with some cleanup to use only rte_malloc API for storing test vectors as in other tests. Fixes: d8417b5ef4e ("examples/fips_validation: add SHA3 validation") Signed-off-by: Gowrishankar Muthukrishnan --- .../fips_validation/fips_validation_sha.c | 31 ++++++----- examples/fips_validation/main.c | 53 +++++++++---------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/examples/fips_validation/fips_validation_sha.c b/examples/fips_validation/fips_validation_sha.c index 7ce7d3744f..e81bfeceda 100644 --- a/examples/fips_validation/fips_validation_sha.c +++ b/examples/fips_validation/fips_validation_sha.c @@ -7,6 +7,7 @@ #include #include +#include #include #include "fips_validation.h" @@ -28,19 +29,20 @@ struct plain_hash_size_conversion { const char *str; + uint8_t md_blocks; enum rte_crypto_auth_algorithm algo; } phsc[] = { - {"20", RTE_CRYPTO_AUTH_SHA1}, - {"28", RTE_CRYPTO_AUTH_SHA224}, - {"32", RTE_CRYPTO_AUTH_SHA256}, - {"48", RTE_CRYPTO_AUTH_SHA384}, - {"64", RTE_CRYPTO_AUTH_SHA512}, - {"28", RTE_CRYPTO_AUTH_SHA3_224}, - {"32", RTE_CRYPTO_AUTH_SHA3_256}, - {"48", RTE_CRYPTO_AUTH_SHA3_384}, - {"64", RTE_CRYPTO_AUTH_SHA3_512}, - {"16", RTE_CRYPTO_AUTH_SHAKE_128}, - {"32", RTE_CRYPTO_AUTH_SHAKE_256}, + {"20", 3, RTE_CRYPTO_AUTH_SHA1}, + {"28", 3, RTE_CRYPTO_AUTH_SHA224}, + {"32", 3, RTE_CRYPTO_AUTH_SHA256}, + {"48", 3, RTE_CRYPTO_AUTH_SHA384}, + {"64", 3, RTE_CRYPTO_AUTH_SHA512}, + {"28", 1, RTE_CRYPTO_AUTH_SHA3_224}, + {"32", 1, RTE_CRYPTO_AUTH_SHA3_256}, + {"48", 1, RTE_CRYPTO_AUTH_SHA3_384}, + {"64", 1, RTE_CRYPTO_AUTH_SHA3_512}, + {"16", 1, RTE_CRYPTO_AUTH_SHAKE_128}, + {"32", 1, RTE_CRYPTO_AUTH_SHAKE_256}, }; int @@ -69,6 +71,7 @@ parse_interim_algo(__rte_unused const char *key, for (i = 0; i < RTE_DIM(phsc); i++) { if (strstr(text, phsc[i].str)) { info.interim_info.sha_data.algo = phsc[i].algo; + info.interim_info.sha_data.md_blocks = phsc[i].md_blocks; parser_read_uint32_val(ALGO_PREFIX, text, &vec.cipher_auth.digest); break; @@ -84,7 +87,7 @@ parse_interim_algo(__rte_unused const char *key, struct fips_test_callback sha_tests_vectors[] = { {MSGLEN_STR, parser_read_uint32_bit_val, &vec.pt}, {MSG_STR, parse_uint8_known_len_hex_str, &vec.pt}, - {SEED_STR, parse_uint8_hex_str, &vec.cipher_auth.digest}, + {SEED_STR, parse_uint8_hex_str, &vec.pt}, {NULL, NULL, NULL} /**< end pointer */ }; @@ -307,8 +310,8 @@ parse_test_sha_json_algorithm(void) if (sz < 0) return -1; - free(vec.cipher_auth.digest.val); - vec.cipher_auth.digest.val = calloc(1, sz); + rte_free(vec.cipher_auth.digest.val); + vec.cipher_auth.digest.val = rte_malloc(NULL, sz, 0); if (vec.cipher_auth.digest.val == NULL) return -1; diff --git a/examples/fips_validation/main.c b/examples/fips_validation/main.c index 4c231fdb29..4237224d9d 100644 --- a/examples/fips_validation/main.c +++ b/examples/fips_validation/main.c @@ -1618,11 +1618,11 @@ get_writeback_data(struct fips_val *val) /* in case val is reused for MCT test, try to free the buffer first */ if (val->val) { - free(val->val); + rte_free(val->val); val->val = NULL; } - wb_data = dst = calloc(1, total_len); + wb_data = dst = rte_malloc(NULL, total_len, 0); if (!dst) { RTE_LOG(ERR, USER1, "Error %i: Not enough memory\n", -ENOMEM); return -ENOMEM; @@ -1640,7 +1640,7 @@ get_writeback_data(struct fips_val *val) if (data_len) { RTE_LOG(ERR, USER1, "Error -1: write back data\n"); - free(wb_data); + rte_free(wb_data); return -1; } @@ -1863,7 +1863,7 @@ fips_generic_test(void) if (info.file_type != FIPS_TYPE_JSON) fprintf(info.fp_wr, "\n"); - free(val.val); + rte_free(val.val); return 0; } @@ -1883,11 +1883,11 @@ fips_mct_tdes_test(void) int test_mode = info.interim_info.tdes_data.test_mode; pt.len = vec.pt.len; - pt.val = calloc(1, pt.len); + pt.val = rte_malloc(NULL, pt.len, 0); ct.len = vec.ct.len; - ct.val = calloc(1, ct.len); + ct.val = rte_malloc(NULL, ct.len, 0); iv.len = vec.iv.len; - iv.val = calloc(1, iv.len); + iv.val = rte_malloc(NULL, iv.len, 0); for (i = 0; i < TDES_EXTERN_ITER; i++) { if (info.file_type != FIPS_TYPE_JSON) { @@ -2055,10 +2055,10 @@ fips_mct_tdes_test(void) } } - free(val[0].val); - free(pt.val); - free(ct.val); - free(iv.val); + rte_free(val[0].val); + rte_free(pt.val); + rte_free(ct.val); + rte_free(iv.val); return 0; } @@ -2140,7 +2140,7 @@ fips_mct_aes_ecb_test(void) } } - free(val.val); + rte_free(val.val); return 0; } @@ -2160,11 +2160,11 @@ fips_mct_aes_test(void) return fips_mct_aes_ecb_test(); pt.len = vec.pt.len; - pt.val = calloc(1, pt.len); + pt.val = rte_malloc(NULL, pt.len, 0); ct.len = vec.ct.len; - ct.val = calloc(1, ct.len); + ct.val = rte_malloc(NULL, ct.len, 0); iv.len = vec.iv.len; - iv.val = calloc(1, iv.len); + iv.val = rte_malloc(NULL, iv.len, 0); for (i = 0; i < AES_EXTERN_ITER; i++) { if (info.file_type != FIPS_TYPE_JSON) { if (i != 0) @@ -2267,10 +2267,10 @@ fips_mct_aes_test(void) memcpy(vec.iv.val, val[0].val, AES_BLOCK_SIZE); } - free(val[0].val); - free(pt.val); - free(ct.val); - free(iv.val); + rte_free(val[0].val); + rte_free(pt.val); + rte_free(ct.val); + rte_free(iv.val); return 0; } @@ -2288,9 +2288,8 @@ fips_mct_sha_test(void) max_outlen = md_blocks * vec.cipher_auth.digest.len; - free(vec.cipher_auth.digest.val); - - vec.cipher_auth.digest.val = calloc(1, max_outlen); + rte_free(vec.cipher_auth.digest.val); + vec.cipher_auth.digest.val = rte_malloc(NULL, max_outlen, 0); if (vec.pt.val) memcpy(vec.cipher_auth.digest.val, vec.pt.val, vec.cipher_auth.digest.len); @@ -2364,7 +2363,7 @@ fips_mct_sha_test(void) rte_free(vec.pt.val); - free(val.val); + rte_free(val.val); return 0; } @@ -2381,9 +2380,8 @@ fips_mct_shake_test(void) max_outlen = vec.cipher_auth.digest.len; - free(vec.cipher_auth.digest.val); - - vec.cipher_auth.digest.val = calloc(1, max_outlen); + rte_free(vec.cipher_auth.digest.val); + vec.cipher_auth.digest.val = rte_malloc(NULL, max_outlen, 0); if (vec.pt.val) memcpy(vec.cipher_auth.digest.val, vec.pt.val, vec.pt.len); @@ -2452,8 +2450,7 @@ fips_mct_shake_test(void) rte_free(md.val); rte_free(vec.pt.val); - - free(val.val); + rte_free(val.val); return 0; } -- 2.25.1