From patchwork Tue Sep 27 06:00:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 116927 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id F3AEFA00C2; Tue, 27 Sep 2022 08:01:03 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3141E427F1; Tue, 27 Sep 2022 08:00:55 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 32394427F0 for ; Tue, 27 Sep 2022 08:00:54 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28R44xIp016169; Mon, 26 Sep 2022 23:00:53 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=lEdefXPG7yiXc3U1cIyWm4bKStpSxg73Xg9lebu2OqQ=; b=KvVuW3XA8xKYLmnPYA/kYw4ieO8PNEC48uThYVw26F5Xv3nzfrjRgOO4WtQgoSk/Vasu qZIzVKiDFgURBIIaJRCG7+RRZmZI6x6ofAyRXN5XOoqOFDasLTi15gpHTAnS5zEA0Enx Nvfrp7HrQGwVkt10mZfElQWNW10JfH2NlBHVAfN62UDr3arKrXMiRR55aL8cFSf9HAo+ 4aD0X/B2lZXFNtMlkwO0vu2mqdmJhdNzr3Mprs6WbvmxKrza9rMfmh8zf349PJH/gfJG wHW/yyv4Hnl8mxAxzdkDI3z+TRw6ih5hj0FAEH6Jw5FSt3y3SUuZWStNJW1w9KUKY11h 4g== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3jt1dp8p8a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 26 Sep 2022 23:00:53 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 26 Sep 2022 23:00:51 -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.2 via Frontend Transport; Mon, 26 Sep 2022 23:00:51 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 21CBA5B6960; Mon, 26 Sep 2022 23:00:48 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: Anoob Joseph , Fan Zhang , Brian Dooley , Akhil Goyal , , Gowrishankar Muthukrishnan Subject: [v2 3/7] examples/fips_validation: add function to calculate SHA hash size Date: Tue, 27 Sep 2022 11:30:36 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 8onpR2bBUygQRzM48UUnCtlVm1aXXEvZ X-Proofpoint-GUID: 8onpR2bBUygQRzM48UUnCtlVm1aXXEvZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-26_11,2022-09-22_02,2022-06-22_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 Add function to calculate hash size for a given SHA hash algorithm. Fixes: d5c247145c2 ("examples/fips_validation: add parsing for SHA") Signed-off-by: Gowrishankar Muthukrishnan Acked-by: Brian Dooley --- v2: - fixed include file --- examples/fips_validation/fips_validation.h | 1 + .../fips_validation/fips_validation_sha.c | 39 ++++++++++++------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/examples/fips_validation/fips_validation.h b/examples/fips_validation/fips_validation.h index a6288e17e5..6e5f2fce75 100644 --- a/examples/fips_validation/fips_validation.h +++ b/examples/fips_validation/fips_validation.h @@ -374,4 +374,5 @@ int prepare_gcm_xform(struct rte_crypto_sym_xform *xform); int prepare_gmac_xform(struct rte_crypto_sym_xform *xform); +int parse_test_sha_hash_size(enum rte_crypto_auth_algorithm algo); #endif diff --git a/examples/fips_validation/fips_validation_sha.c b/examples/fips_validation/fips_validation_sha.c index 75b073c15d..cac2a25e6c 100644 --- a/examples/fips_validation/fips_validation_sha.c +++ b/examples/fips_validation/fips_validation_sha.c @@ -33,6 +33,22 @@ struct plain_hash_size_conversion { {"64", RTE_CRYPTO_AUTH_SHA512}, }; +int +parse_test_sha_hash_size(enum rte_crypto_auth_algorithm algo) +{ + int ret = -EINVAL; + uint8_t i; + + for (i = 0; i < RTE_DIM(phsc); i++) { + if (phsc[i].algo == algo) { + ret = atoi(phsc[i].str); + break; + } + } + + return ret; +} + static int parse_interim_algo(__rte_unused const char *key, char *text, @@ -212,6 +228,7 @@ parse_test_sha_json_algorithm(void) json_t *algorithm_object; const char *algorithm_str; uint32_t i; + int sz; algorithm_object = json_object_get(json_info.json_vector_set, "algorithm"); algorithm_str = json_string_value(algorithm_object); @@ -226,23 +243,15 @@ parse_test_sha_json_algorithm(void) if (i == RTE_DIM(json_algorithms)) return -1; - for (i = 0; i < RTE_DIM(phsc); i++) { - if (info.interim_info.sha_data.algo == phsc[i].algo) { - vec.cipher_auth.digest.len = atoi(phsc[i].str); - free(vec.cipher_auth.digest.val); - vec.cipher_auth.digest.val = calloc(1, vec.cipher_auth.digest.len); - if (vec.cipher_auth.digest.val == NULL) - return -1; - - break; - } - } + sz = parse_test_sha_hash_size(info.interim_info.sha_data.algo); + if (sz < 0) + return -1; - if (i == RTE_DIM(phsc)) { - free(vec.cipher_auth.digest.val); - vec.cipher_auth.digest.val = NULL; + free(vec.cipher_auth.digest.val); + vec.cipher_auth.digest.len = sz; + vec.cipher_auth.digest.val = calloc(1, sz); + if (vec.cipher_auth.digest.val == NULL) return -1; - } return 0; }