DPDK patches and discussions
 help / color / mirror / Atom feed
From: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
To: Kai Ji <kai.ji@intel.com>, "dev@dpdk.org" <dev@dpdk.org>
Cc: Akhil Goyal <gakhil@marvell.com>,
	"stable@dpdk.org" <stable@dpdk.org>,
	Arkadiusz Kusztal <arkadiuszx.kusztal@intel.com>
Subject: RE: [EXT] [dpdk-dev v2 1/3] app/test: add diffie-hellman test cases
Date: Fri, 23 Jun 2023 10:29:41 +0000	[thread overview]
Message-ID: <BY3PR18MB4705E0E2AA1EB6A765AEADA4CB23A@BY3PR18MB4705.namprd18.prod.outlook.com> (raw)
In-Reply-To: <20230314183457.13918-2-kai.ji@intel.com>

> diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
> index 5b16dcab56..b9034b637a 100644
> --- a/app/test/test_cryptodev_asym.c
> +++ b/app/test/test_cryptodev_asym.c
> @@ -64,6 +64,39 @@ static uint32_t test_index;
> 
>  static struct crypto_testsuite_params_asym testsuite_params = { NULL };
> 
> +static void
> +test_crypto_rand(int len, uint8_t *buffer) {
Just a minor suggestion on params order here (below), for ease in readability.
test_crypto_rand(uint8_t *buffer, int len)

> +	int i;
> +
> +	for (i = 0; i < len; ++i)
> +		buffer[i] = (uint8_t)(rand() % ((uint8_t)-1)) | 1; }
rand() % UINT8_MAX easier ?
Also } in next line.

> +
> +static int
> +process_crypto_request(uint8_t dev_id, struct rte_crypto_op **op,
> +				struct rte_crypto_op **result_op)
> +{
> +	/* Process crypto operation */
> +	if (rte_cryptodev_enqueue_burst(dev_id, 0, op, 1) != 1) {
> +		RTE_LOG(ERR, USER1,
> +			"line %u FAILED: %s",
> +			__LINE__, "Error sending packet for operation");
> +		return -1;
> +	}
> +
> +	while (rte_cryptodev_dequeue_burst(dev_id, 0, result_op, 1) == 0)
> +		rte_pause();
> +
> +	if (*result_op == NULL) {
> +		RTE_LOG(ERR, USER1,
> +			"line %u FAILED: %s",
> +			__LINE__, "Failed to process asym crypto op");
> +		return -1;
> +	}
> +	return 0;
> +}
> +
>  static int
>  queue_ops_rsa_sign_verify(void *sess)
>  {
> @@ -809,6 +842,8 @@ testsuite_setup(void)
>  	test_vector.size = 0;
>  	load_test_vectors();
> 
> +	srand(time(NULL));
> +
>  	/* Device, op pool and session configuration for asymmetric crypto. 8<
> */
>  	ts_params->op_mpool = rte_crypto_op_pool_create(
>  			"CRYPTO_ASYM_OP_POOL",
> @@ -2196,6 +2231,219 @@ test_ecpm_all_curve(void)
>  	return overall_status;
>  }
> 
> +static void *
> +dh_alice_bob_set_session(uint8_t dev_id,
> +	struct rte_crypto_op *op,
> +	const struct test_dh_group *group)
> +{
> +	struct rte_crypto_asym_xform xform = { };
> +	void *sess = NULL;
> +	int ret = 0;
> +
> +	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
> +	xform.dh.g.data = group->g.data;
> +	xform.dh.g.length = group->g.bytesize;
> +	xform.dh.p.data = group->p.data;
> +	xform.dh.p.length = group->p.bytesize;
> +	ret = rte_cryptodev_asym_session_create(dev_id, &xform,
> +			testsuite_params.session_mpool, &sess);
> +	if (ret)
> +		return NULL;
> +
> +	rte_crypto_op_attach_asym_session(op, sess);
> +	return sess;
> +}
> +
> +static void
> +dh_alice_bob_gen_x(const struct test_dh_group *group,
> +	uint8_t *private_data)
> +{
> +	test_crypto_rand(group->priv_ff_size, private_data);
> +	if (private_data[0] > group->p.data[0])
> +		private_data[0] = group->p.data[0] - 1; }
} in next line.

> +
> +static int
> +dh_alice_bob_gen_y(struct rte_crypto_op *op,
> +	const char *name,
> +	const uint8_t dev_id,
Could this order be dev_id, name, op etc ??

> +	uint8_t *y,
> +	uint8_t *x,
> +	const int ff_size)
> +{
> +	struct rte_crypto_op *result_op;
> +	int ret = 0;
> +
> +	op->asym->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
> +	op->asym->dh.pub_key.data = y;
> +	op->asym->dh.priv_key.data = x;
> +	op->asym->dh.priv_key.length = ff_size;
> +
> +	ret = process_crypto_request(dev_id, &op, &result_op);
> +	TEST_ASSERT_SUCCESS(ret, "Failed to compute public key for %s",
> name);
> +
> +	return 0;
> +}
> +
> +static int
> +dh_alice_bob_shared_compute(uint8_t dev_id,
> +	const char *name,
> +	struct rte_crypto_op *op,
> +	uint8_t *secret,
> +	uint8_t *peer,
> +	uint32_t peer_size)
> +{
> +	struct rte_crypto_op *result_op;
> +	int ret = 0;
> +
> +	op->asym->dh.ke_type =
> RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE;
> +	op->asym->dh.pub_key.data = peer;
> +	op->asym->dh.pub_key.length = peer_size;
> +	op->asym->dh.shared_secret.data = secret;
> +
> +	ret = process_crypto_request(dev_id, &op, &result_op);
> +	TEST_ASSERT_SUCCESS(ret,
> +		"Failed to compute shared secret for %s",
> +		name);
> +
> +	return 0;
> +}
> +
> +/* Diffie-Hellman test to verify the processed data */ static int
Patch format incorrect ?

> +dh_alice_bob_verify(struct rte_crypto_op *alice_op,
> +	struct rte_crypto_op *bob_op)
> +{
> +	int ret = 0;
> +
> +	/* Verify processed data */
> +	ret = (alice_op->asym->dh.shared_secret.length ==
> +			bob_op->asym->dh.shared_secret.length);
Is 0 length allowed ?

> +	if (!ret) {
> +		RTE_LOG(ERR, USER1, "line %u FAILED: %s", __LINE__,
> +			"Alice's and Bob's shared secret length do not match.");
> +		return TEST_FAILED;
> +	}
> +	ret = memcmp(alice_op->asym->dh.shared_secret.data,
> +		alice_op->asym->dh.shared_secret.data,
> +		bob_op->asym->dh.shared_secret.length);
> +	if (ret) {
> +		RTE_LOG(ERR, USER1, "line %u FAILED: %s", __LINE__,
> +			"Alice's and Bob's shared secret do not match.");
> +		return TEST_FAILED;
> +	}
> +	return TEST_SUCCESS;
> +}
> +
<cut..>

> +static const struct test_dh_group test_dh_ikev2group_24 = {
> +	.id = 0,
> +	/*
> +	 * Officially 24, ikev2
> +	 */
> +	.g = {
> +		.data = test_dh_ikev2group24_g,
> +		.bytesize = sizeof(test_dh_ikev2group24_g),
> +	},
> +	.p = {
> +		.data = test_dh_ikev2group24_p,
> +		.bytesize = sizeof(test_dh_ikev2group24_p),
> +	},
> +	.priv_ff_size = 32,
> +};
> +
Below are suppose to be 2/3 patch right ?

> +static const struct test_dh_group test_ecdh_secp256r1 = {
> +	.id = RTE_CRYPTO_EC_GROUP_SECP256R1,
> +	.priv_ff_size = 32,
> +};
> +static const struct test_dh_group test_ecdh_secp384r1 = {
> +	.id = RTE_CRYPTO_EC_GROUP_SECP384R1,
> +	.priv_ff_size = 48,
> +};
> +static const struct test_dh_group test_ecdh_secp521r1 = {
> +	.id = RTE_CRYPTO_EC_GROUP_SECP521R1,
> +	.priv_ff_size = 64,
> +};
> +
> +
>  #endif /* TEST_CRYPTODEV_DH_TEST_VECTORS_H__ */
> --
> 2.17.1


  reply	other threads:[~2023-06-23 10:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-14  0:12 [dpdk-dev v1 1/2] " Kai Ji
2023-03-14  0:12 ` [dpdk-dev v1 2/2] app/test: add ecdh " Kai Ji
2023-03-14 10:54 ` [EXT] [dpdk-dev v1 1/2] app/test: add diffie-hellman " Akhil Goyal
2023-03-14 18:34 ` [dpdk-dev v2 0/3] app/test: add asymmetric " Kai Ji
2023-03-14 18:34   ` [dpdk-dev v2 1/3] app/test: add diffie-hellman " Kai Ji
2023-06-23 10:29     ` Gowrishankar Muthukrishnan [this message]
2023-03-14 18:34   ` [dpdk-dev v2 2/3] app/test: add ecdh " Kai Ji
2023-03-14 18:34   ` [dpdk-dev v2 3/3] app/test: add ecdsa kat sessionless tests Kai Ji

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BY3PR18MB4705E0E2AA1EB6A765AEADA4CB23A@BY3PR18MB4705.namprd18.prod.outlook.com \
    --to=gmuthukrishn@marvell.com \
    --cc=arkadiuszx.kusztal@intel.com \
    --cc=dev@dpdk.org \
    --cc=gakhil@marvell.com \
    --cc=kai.ji@intel.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).