[dpdk-dev] [PATCH v4 1/2] test/crypto: add rsa and mod test application

De Lara Guarch, Pablo pablo.de.lara.guarch at intel.com
Tue Jul 10 00:14:07 CEST 2018



> -----Original Message-----
> From: Shally Verma [mailto:shally.verma at caviumnetworks.com]
> Sent: Thursday, July 5, 2018 4:54 PM
> To: De Lara Guarch, Pablo <pablo.de.lara.guarch at intel.com>
> Cc: dev at dpdk.org; pathreya at caviumnetworks.com; Sunila Sahu
> <sunila.sahu at caviumnetworks.com>; Ashish Gupta
> <ashish.gupta at caviumnetworks.com>
> Subject: [PATCH v4 1/2] test/crypto: add rsa and mod test application
> 
> From: Sunila Sahu <sunila.sahu at caviumnetworks.com>
> 
> Test application include test case for :
> - RSA encrypt, decrypt, sign and verify
> - Modular Inversion and Exponentiation
> 
> Test cases uses predefined test vectors.
> 
> Signed-off-by: Sunila Sahu <sunila.sahu at caviumnetworks.com>
> Signed-off-by: Shally Verma <shally.verma at caviumnetworks.com>
> Signed-off-by: Ashish Gupta <ashish.gupta at caviumnetworks.com>
> ---
>  test/test/Makefile                          |   1 +
>  test/test/meson.build                       |   1 +
>  test/test/test_cryptodev_asym.c             | 836
> ++++++++++++++++++++++++++++
>  test/test/test_cryptodev_asym_util.h        |  45 ++
>  test/test/test_cryptodev_mod_test_vectors.h | 103 ++++
> test/test/test_cryptodev_rsa_test_vectors.h |  90 +++
>  6 files changed, 1076 insertions(+)
> 
> diff --git a/test/test/Makefile b/test/test/Makefile index eccc8ef..d6fb88f
> 100644
> --- a/test/test/Makefile
> +++ b/test/test/Makefile
> @@ -179,6 +179,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_PMD_RING) +=
> test_pmd_ring_perf.c
> 
>  SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_blockcipher.c
>  SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev.c
> +SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_asym.c
> 
>  ifeq ($(CONFIG_RTE_COMPRESSDEV_TEST),y)
>  SRCS-$(CONFIG_RTE_LIBRTE_COMPRESSDEV) += test_compressdev.c diff --git
> a/test/test/meson.build b/test/test/meson.build index a907fd2..06cd6f7 100644
> --- a/test/test/meson.build
> +++ b/test/test/meson.build
> @@ -22,6 +22,7 @@ test_sources = files('commands.c',
>  	'test_cpuflags.c',
>  	'test_crc.c',
>  	'test_cryptodev.c',
> +	'test_cryptodev_asym.c',
>  	'test_cryptodev_blockcipher.c',
>  	'test_cycles.c',
>  	'test_debug.c',
> diff --git a/test/test/test_cryptodev_asym.c b/test/test/test_cryptodev_asym.c
> new file mode 100644 index 0000000..9b6ffac
> --- /dev/null
> +++ b/test/test/test_cryptodev_asym.c
> @@ -0,0 +1,836 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2018 Cavium Networks
> + */
> +
> +#include <rte_bus_vdev.h>
> +#include <rte_common.h>
> +#include <rte_hexdump.h>
> +#include <rte_mbuf.h>
> +#include <rte_malloc.h>
> +#include <rte_memcpy.h>
> +#include <rte_pause.h>
> +
> +#include <rte_cryptodev.h>
> +#include <rte_cryptodev_pmd.h>
> +#include <rte_crypto.h>
> +
> +#include "test_cryptodev.h"
> +#include "test_cryptodev_mod_test_vectors.h"
> +#include "test_cryptodev_rsa_test_vectors.h"
> +#include "test_cryptodev_asym_util.h"
> +#include "test.h"
> +
> +#define TEST_NUM_BUFS 10
> +#define TEST_NUM_SESSIONS 4
> +#define ASYM_TEST_MSG_LEN	256
> +
> +static int gbl_driver_id;
> +struct crypto_testsuite_params {
> +	struct rte_mempool *op_mpool;
> +	struct rte_mempool *session_mpool;
> +	struct rte_cryptodev_config conf;
> +	struct rte_cryptodev_qp_conf qp_conf;
> +	uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
> +	uint8_t valid_dev_count;
> +};
> +
> +struct crypto_unittest_params {
> +	struct rte_cryptodev_asym_session *sess;
> +	struct rte_crypto_op *op;
> +};
> +
> +static struct crypto_testsuite_params testsuite_params = { NULL };
> +
> +static int
> +test_rsa_sign_verify(void)
> +{
> +	struct crypto_testsuite_params *ts_params = &testsuite_params;
> +	struct rte_mempool *op_mpool = ts_params->op_mpool;
> +	struct rte_mempool *sess_mpool = ts_params->session_mpool;
> +	uint8_t dev_id = ts_params->valid_devs[0];
> +	struct rte_crypto_asym_op *asym_op = NULL;
> +	struct rte_crypto_op *op = NULL, *result_op = NULL;
> +	struct rte_cryptodev_asym_session *sess = NULL;
> +	int status = TEST_SUCCESS;
> +	uint8_t output_buf[TEST_DATA_SIZE] = {0};
> +	uint8_t input_buf[TEST_DATA_SIZE] = {0};
> +	char test_msg[ASYM_TEST_MSG_LEN + 1];
> +
> +	sess = rte_cryptodev_asym_session_create(sess_mpool);
> +
> +	if (!sess) {
> +		snprintf(test_msg, ASYM_TEST_MSG_LEN, "line %u "
> +				"FAILED: %s", __LINE__,
> +				"Session creation failed");

Shouldn't this be printf/RTE_LOG? Afaik, you are just printing into test_msg,
but not showing that in the screen.

> +		status = TEST_FAILED;
> +		goto error_exit;
> +	}

...

> +	}
> +
> +	/* print xfrm capability */

Use "xform".

...

> +++ b/test/test/test_cryptodev_asym_util.h

...

> +
> +static inline int verify_modexp(uint8_t *mod_exp,
> +		struct rte_crypto_op *result_op)
> +{
> +	int ret = 0;
> +	if (memcmp(mod_exp, result_op->asym->modex.base.data,
> +				result_op->asym->modex.base.length))
> +		ret = -1;
> +	return ret;

Ret variable is not required. Just return -1 inside if, and 0 outside.

...

> diff --git a/test/test/test_cryptodev_rsa_test_vectors.h
> b/test/test/test_cryptodev_rsa_test_vectors.h

...

> +		{
> +			.d = {
> +				.data = rsa_d,
> +				.length = sizeof(rsa_d)
> +			},
> +		}

These outer braces are not needed.


More information about the dev mailing list