[1/6] test/crypto: add asserts to validate test lengths

Message ID 20240822071651.2403105-2-anoobj@marvell.com (mailing list archive)
State Accepted
Delegated to: akhil goyal
Headers
Series Fixes and improvements in crypto unit tests |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Anoob Joseph Aug. 22, 2024, 7:16 a.m. UTC
Add asserts to validate the max lengths set.

Signed-off-by: Anoob Joseph <anoobj@marvell.com>
---
 app/test/test_cryptodev.c                   |  2 +-
 app/test/test_cryptodev.h                   |  2 ++
 app/test/test_cryptodev_aead_test_vectors.h | 14 +++++++++++++-
 3 files changed, 16 insertions(+), 2 deletions(-)
  

Patch

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 0c445f9eae..9d8ca8f616 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -665,7 +665,7 @@  testsuite_setup(void)
 		/* Not already created so create */
 		ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
 				"CRYPTO_LARGE_MBUFPOOL",
-				1, 0, 0, UINT16_MAX,
+				1, 0, 0, LARGE_MBUF_SIZE,
 				rte_socket_id());
 		if (ts_params->large_mbuf_pool == NULL) {
 			RTE_LOG(ERR, USER1,
diff --git a/app/test/test_cryptodev.h b/app/test/test_cryptodev.h
index fd9ea0dd81..af56145cdd 100644
--- a/app/test/test_cryptodev.h
+++ b/app/test/test_cryptodev.h
@@ -24,6 +24,8 @@ 
 #define MBUF_DATAPAYLOAD_SIZE		(4096 + DIGEST_BYTE_LENGTH_SHA512)
 #define MBUF_SIZE			(sizeof(struct rte_mbuf) + \
 		RTE_PKTMBUF_HEADROOM + MBUF_DATAPAYLOAD_SIZE)
+#define LARGE_MBUF_DATAPAYLOAD_SIZE	(UINT16_MAX - RTE_PKTMBUF_HEADROOM)
+#define LARGE_MBUF_SIZE			(RTE_PKTMBUF_HEADROOM + LARGE_MBUF_DATAPAYLOAD_SIZE)
 
 #define BYTE_LENGTH(x)				(x/8)
 /* HASH DIGEST LENGTHS */
diff --git a/app/test/test_cryptodev_aead_test_vectors.h b/app/test/test_cryptodev_aead_test_vectors.h
index e9b0590048..73bfb8dad4 100644
--- a/app/test/test_cryptodev_aead_test_vectors.h
+++ b/app/test/test_cryptodev_aead_test_vectors.h
@@ -5,11 +5,23 @@ 
 #ifndef TEST_CRYPTODEV_AEAD_TEST_VECTORS_H_
 #define TEST_CRYPTODEV_AEAD_TEST_VECTORS_H_
 
+#include "test_cryptodev.h"
+
 #define GMAC_LARGE_PLAINTEXT_LENGTH		65344
-#define MAX_AAD_LENGTH				65536
+#define MAX_AAD_LENGTH				(65535 - RTE_PKTMBUF_HEADROOM)
 #define GCM_LARGE_AAD_LENGTH			65296
 #define AEAD_TEXT_MAX_LENGTH			8096
 
+static_assert(GMAC_LARGE_PLAINTEXT_LENGTH <= LARGE_MBUF_DATAPAYLOAD_SIZE,
+	      "GMAC_LARGE_PLAINTEXT_LENGTH should not be greater than LARGE_MBUF_DATAPAYLOAD_SIZE");
+static_assert(MAX_AAD_LENGTH <= LARGE_MBUF_DATAPAYLOAD_SIZE,
+	      "MAX_AAD_LENGTH should not be greater than LARGE_MBUF_DATAPAYLOAD_SIZE");
+static_assert(GCM_LARGE_AAD_LENGTH <= LARGE_MBUF_DATAPAYLOAD_SIZE,
+	      "GCM_LARGE_AAD_LENGTH should not be greater than LARGE_MBUF_DATAPAYLOAD_SIZE");
+static_assert(AEAD_TEXT_MAX_LENGTH <= LARGE_MBUF_DATAPAYLOAD_SIZE,
+	      "AEAD_TEXT_MAX_LENGTH should not be greater than LARGE_MBUF_DATAPAYLOAD_SIZE");
+
+
 static uint8_t gcm_aad_zero_text[MAX_AAD_LENGTH] = { 0 };
 
 static uint8_t gcm_aad_text[MAX_AAD_LENGTH] = {