DPDK patches and discussions
 help / color / mirror / Atom feed
From: Gagandeep Singh <G.Singh@nxp.com>
To: Akhil Goyal <gakhil@marvell.com>, "dev@dpdk.org" <dev@dpdk.org>,
	"Power, Ciara" <ciara.power@intel.com>,
	"Zhang, Roy Fan" <roy.fan.zhang@intel.com>
Subject: RE: [EXT] [PATCH 7/8] test/crypto: add external buffer test case
Date: Mon, 16 May 2022 07:25:11 +0000
Message-ID: <AS8PR04MB819898955DD1B8B3E3950B5AE1CF9@AS8PR04MB8198.eurprd04.prod.outlook.com> (raw)
In-Reply-To: <CO6PR18MB448431E94D6AC8161FA030F6D8CA9@CO6PR18MB4484.namprd18.prod.outlook.com>

Hi,

> -----Original Message-----
> From: Akhil Goyal <gakhil@marvell.com>
> Sent: Friday, May 13, 2022 3:57 PM
> To: Gagandeep Singh <G.Singh@nxp.com>; dev@dpdk.org; Power, Ciara
> <ciara.power@intel.com>; Zhang, Roy Fan <roy.fan.zhang@intel.com>
> Subject: RE: [EXT] [PATCH 7/8] test/crypto: add external buffer test case
> 
> > Add a test case to verify crypto functionality with external buffer.
> >
> > Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
> > ---
> >  app/test/test_cryptodev.c | 163
> > ++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 163 insertions(+)
> >
> > diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
> > index 0b53ec0078..b4ffb4fd94 100644
> > --- a/app/test/test_cryptodev.c
> > +++ b/app/test/test_cryptodev.c
> > @@ -2270,6 +2270,167 @@ test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
> >  	return TEST_SUCCESS;
> >  }
> >
> > +static inline void
> > +ext_buf_free_callback_fn(void *addr,
> > +			 void *ext_buf_ptr __rte_unused)
> > +{
> > +	rte_free(addr);
> > +}
> > +
> > +static int
> > +test_AES_CBC_HMAC_SHA1_encrypt_digest_ext_buffer(void)
> > +{
> > +	struct crypto_testsuite_params *ts_params = &testsuite_params;
> > +	struct crypto_unittest_params *ut_params = &unittest_params;
> > +	int status;
> > +	void *buf;
> > +	rte_iova_t iova;
> > +	uint16_t buf_len = QUOTE_1024_BYTES;
> > +	struct rte_mbuf_ext_shared_info *shinfo = NULL;
> > +	struct rte_mbuf *m;
> > +
> > +
> Extra line
> 
> > +	/* Verify the capabilities */
> > +	struct rte_cryptodev_sym_capability_idx cap_idx;
> > +	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
> > +	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
> > +	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
> > +			&cap_idx) == NULL)
> > +		return TEST_SKIPPED;
> > +	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
> > +	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
> > +	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
> > +			&cap_idx) == NULL)
> > +		return TEST_SKIPPED;
> Repeated code.
> 
> > +
> > +	buf = rte_malloc(NULL, buf_len, RTE_CACHE_LINE_SIZE);
> > +	if (buf == NULL)
> > +		return TEST_SKIPPED;
> 
> Why skipped? It is an error if malloc is failed.
> 
> > +
> > +	rte_memcpy(buf, catch_22_quote, QUOTE_512_BYTES);
> > +	shinfo = rte_pktmbuf_ext_shinfo_init_helper(buf, &buf_len,
> > +				ext_buf_free_callback_fn, NULL);
> > +	if (unlikely(shinfo == NULL)) {
> > +		rte_free(buf);
> > +		return -1;
> > +	}
> > +	iova = rte_malloc_virt2iova(buf);
> > +	m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
> > +	if (m == NULL)
> > +		return TEST_SKIPPED;
> Again, it should be TEST_FAILED
> 
> > +	rte_pktmbuf_attach_extbuf(m, buf, iova, buf_len, shinfo);
> > +	rte_pktmbuf_reset_headroom(m);
> > +	m->pkt_len = QUOTE_512_BYTES;
> > +	m->data_len  = QUOTE_512_BYTES;
> Please use proper APIs to append data and increase lengths.
> 
> > +	m->data_off  = 0;
> Why is data off rewritten as 0?
> It is modified by rte_pktmbuf_reset_headroom().
> 
> > +
> > +	ut_params->ibuf = m;
> > +
> > +	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
> > +			DIGEST_BYTE_LENGTH_SHA1);
> > +	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append
> > digest");
> > +
> > +	/* Setup Cipher Parameters */
> > +	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
> > +	ut_params->cipher_xform.next = &ut_params->auth_xform;
> > +
> > +	ut_params->cipher_xform.cipher.algo =
> > RTE_CRYPTO_CIPHER_AES_CBC;
> > +	ut_params->cipher_xform.cipher.op =
> > RTE_CRYPTO_CIPHER_OP_ENCRYPT;
> > +	ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
> > +	ut_params->cipher_xform.cipher.key.length =
> > CIPHER_KEY_LENGTH_AES_CBC;
> > +	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
> > +	ut_params->cipher_xform.cipher.iv.length =
> > CIPHER_IV_LENGTH_AES_CBC;
> > +
> > +	/* Setup HMAC Parameters */
> > +	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
> > +
> > +	ut_params->auth_xform.next = NULL;
> > +
> > +	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
> > +	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
> > +	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
> > +	ut_params->auth_xform.auth.key.data = hmac_sha1_key;
> > +	ut_params->auth_xform.auth.digest_length =
> > DIGEST_BYTE_LENGTH_SHA1;
> > +
> > +	ut_params->sess = rte_cryptodev_sym_session_create(
> > +			ts_params->session_mpool);
> > +	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
> > +
> > +	/* Create crypto session*/
> > +	status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
> > +			ut_params->sess, &ut_params->cipher_xform,
> > +			ts_params->session_priv_mpool);
> > +
> > +	if (status == -ENOTSUP)
> > +		return TEST_SKIPPED;
> > +
> > +	TEST_ASSERT_EQUAL(status, 0, "Session init failed");
> > +
> > +	/* Generate crypto op data structure */
> > +	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
> > +			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
> > +	TEST_ASSERT_NOT_NULL(ut_params->op,
> > +			"Failed to allocate symmetric crypto operation struct");
> > +
> > +	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
> > +
> > +	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
> > +
> > +	/* set crypto operation source mbuf */
> > +	sym_op->m_src = ut_params->ibuf;
> > +
> > +	/* Set crypto operation authentication parameters */
> > +	sym_op->auth.digest.data = ut_params->digest;
> > +	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
> > +			ut_params->ibuf, QUOTE_512_BYTES);
> > +
> > +	sym_op->auth.data.offset = 0;
> > +	sym_op->auth.data.length = QUOTE_512_BYTES;
> > +
> > +	/* Copy IV at the end of the crypto operation */
> > +	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
> > IV_OFFSET),
> > +			aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
> > +
> > +	/* Set crypto operation cipher parameters */
> > +	sym_op->cipher.data.offset = 0;
> > +	sym_op->cipher.data.length = QUOTE_512_BYTES;
> > +
> > +	/* Process crypto operation */
> > +	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
> > +		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
> > +			ut_params->op);
> > +	else
> > +		TEST_ASSERT_NOT_NULL(
> > +			process_crypto_request(ts_params->valid_devs[0],
> > +				ut_params->op),
> > +				"failed to process sym crypto op");
> > +
> > +	TEST_ASSERT_EQUAL(ut_params->op->status,
> > RTE_CRYPTO_OP_STATUS_SUCCESS,
> > +			"crypto op processing failed");
> > +
> > +	/* Validate obuf */
> > +	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
> > +			uint8_t *);
> > +
> > +	TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
> > +			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
> > +			QUOTE_512_BYTES,
> > +			"ciphertext data not as expected");
> > +
> > +	uint8_t *digest = ciphertext + QUOTE_512_BYTES;
> > +
> > +	TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
> > +
> > 	catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
> > +			gbl_driver_id == rte_cryptodev_driver_id_get(
> > +
> > 	RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
> > +
> > 	TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
> > +					DIGEST_BYTE_LENGTH_SHA1,
> > +			"Generated digest data not as expected");
> > +
> Above check for AESNI_MB not required.
> 
> > +	return TEST_SUCCESS;
> > +}
> > +
> > +
> >  /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
> >
> >  #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512) @@
> > -15458,6 +15619,8 @@ static struct unit_test_suite
> > cryptodev_gen_testsuite  = {
> >  		TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
> >  		TEST_CASE_ST(ut_setup, ut_teardown,
> test_enq_callback_setup),
> >  		TEST_CASE_ST(ut_setup, ut_teardown,
> test_deq_callback_setup),
> > +		TEST_CASE_ST(ut_setup, ut_teardown,
> > +
> > 	test_AES_CBC_HMAC_SHA1_encrypt_digest_ext_buffer),
> >  		TEST_CASES_END() /**< NULL terminate unit test array */
> >  	}
> >  };

If you agree, I would like to integrate external buffer testing in blockcipher
test cases so that we can test all other cases as well and there will be no need to add
additional test case. We can simply integrate it by adding additional  
"feature_mask" something like BLOCKCIPHER_TEST_FEATURE_EXTERNAL_BUFFER
to the test cases.
I will try to send it as separate patch.


> > --
> > 2.25.1


  reply	other threads:[~2022-05-16  7:25 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-25  4:14 [PATCH 1/8] app/test-crypto-perf: improve dequeue logic Gagandeep Singh
2022-04-25  4:14 ` [PATCH 2/8] app/test-crypto-perf: support SDAP for PDCP operations Gagandeep Singh
2022-05-13  9:49   ` [EXT] " Akhil Goyal
2022-04-25  4:14 ` [PATCH 3/8] examples/ipsec-secgw: support XCBC-MAC/DES-CBC Gagandeep Singh
2022-05-13  9:54   ` [EXT] " Akhil Goyal
2022-05-16  9:45     ` Gagandeep Singh
2022-04-25  4:14 ` [PATCH 4/8] examples/l2fwd-crypto: add signal handler for exit Gagandeep Singh
2022-04-25  4:14 ` [PATCH 5/8] test/crypto: fix pmd name for dpaa raw buffer crypto driver Gagandeep Singh
2022-04-25  4:14 ` [PATCH 6/8] test/crypto: support raw buffer APIs for PDCP Gagandeep Singh
2022-04-25  4:14 ` [PATCH 7/8] test/crypto: add external buffer test case Gagandeep Singh
2022-05-13 10:26   ` [EXT] " Akhil Goyal
2022-05-16  7:25     ` Gagandeep Singh [this message]
2022-04-25  4:14 ` [PATCH 8/8] test/crypto: add short MAC-I test vector for zuc Gagandeep Singh
2022-05-13 10:46   ` [EXT] " Akhil Goyal
2022-05-16  7:27     ` Gagandeep Singh
2022-05-13  9:46 ` [EXT] [PATCH 1/8] app/test-crypto-perf: improve dequeue logic Akhil Goyal
2022-05-16  7:14   ` Gagandeep Singh
2022-05-16  7:26     ` Anoob Joseph
2022-05-16  7:54       ` Gagandeep Singh
2022-05-17  3:38 ` [PATCH v2 0/7] Crypto related changes in sample/test apps Gagandeep Singh
2022-05-17  3:38   ` [PATCH v2 1/7] app/test-crypto-perf: support SDAP for PDCP operations Gagandeep Singh
2022-05-20  4:20     ` [PATCH v3 0/7] Crypto related changes in sample/test apps Gagandeep Singh
2022-05-20  4:20       ` [PATCH v3 1/7] app/test-crypto-perf: support SDAP for PDCP operations Gagandeep Singh
2022-05-26 13:52         ` [EXT] " Akhil Goyal
2022-05-30  4:31           ` Gagandeep Singh
2022-05-30  6:04             ` Akhil Goyal
2022-05-31 18:14               ` Akhil Goyal
2022-06-06  4:00         ` [PATCH v4] " Gagandeep Singh
2022-06-15 16:06           ` [EXT] " Akhil Goyal
2022-05-20  4:20       ` [PATCH v3 2/7] examples/ipsec-secgw: support XCBC-MAC/DES-CBC Gagandeep Singh
2022-05-26 13:54         ` [EXT] " Akhil Goyal
2022-05-20  4:21       ` [PATCH v3 3/7] examples/l2fwd-crypto: add signal handler for exit Gagandeep Singh
2022-05-26 13:55         ` [EXT] " Akhil Goyal
2022-05-20  4:21       ` [PATCH v3 4/7] test/crypto: fix PMD name for dpaa raw buffer crypto driver Gagandeep Singh
2022-05-26 13:56         ` [EXT] " Akhil Goyal
2022-05-20  4:21       ` [PATCH v3 5/7] test/crypto: support raw buffer APIs for PDCP Gagandeep Singh
2022-05-26 13:58         ` [EXT] " Akhil Goyal
2022-05-20  4:21       ` [PATCH v3 6/7] test/crypto: add short MAC-I test vector for zuc Gagandeep Singh
2022-05-26 13:59         ` [EXT] " Akhil Goyal
2022-05-20  4:21       ` [PATCH v3 7/7] doc: add missing authentication algorithm Gagandeep Singh
2022-05-26 14:00         ` [EXT] " Akhil Goyal
2022-05-17  3:38   ` [PATCH v2 2/7] examples/ipsec-secgw: support XCBC-MAC/DES-CBC Gagandeep Singh
2022-05-17  3:38   ` [PATCH v2 3/7] examples/l2fwd-crypto: add signal handler for exit Gagandeep Singh
2022-05-17 16:32     ` Stephen Hemminger
2022-05-18  4:23       ` Gagandeep Singh
2022-05-17  3:38   ` [PATCH v2 4/7] test/crypto: fix PMD name for dpaa raw buffer crypto driver Gagandeep Singh
2022-05-17  3:38   ` [PATCH v2 5/7] test/crypto: support raw buffer APIs for PDCP Gagandeep Singh
2022-05-17  3:38   ` [PATCH v2 6/7] test/crypto: add short MAC-I test vector for zuc Gagandeep Singh
2022-05-17  3:38   ` [PATCH v2 7/7] doc: add missing authentication algorithm Gagandeep Singh

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=AS8PR04MB819898955DD1B8B3E3950B5AE1CF9@AS8PR04MB8198.eurprd04.prod.outlook.com \
    --to=g.singh@nxp.com \
    --cc=ciara.power@intel.com \
    --cc=dev@dpdk.org \
    --cc=gakhil@marvell.com \
    --cc=roy.fan.zhang@intel.com \
    /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

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ http://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git