xref: /dpdk/app/test/test_cryptodev.h (revision 06c047b6)
1a9de470cSBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2a9de470cSBruce Richardson  * Copyright(c) 2015-2017 Intel Corporation
3a9de470cSBruce Richardson  */
4a9de470cSBruce Richardson #ifndef TEST_CRYPTODEV_H_
5a9de470cSBruce Richardson #define TEST_CRYPTODEV_H_
6a9de470cSBruce Richardson 
7a9de470cSBruce Richardson #define HEX_DUMP 0
8a9de470cSBruce Richardson 
9a9de470cSBruce Richardson #define FALSE                           0
10a9de470cSBruce Richardson #define TRUE                            1
11a9de470cSBruce Richardson 
12a9de470cSBruce Richardson #define MAX_NUM_OPS_INFLIGHT            (4096)
13a9de470cSBruce Richardson #define MIN_NUM_OPS_INFLIGHT            (128)
14a9de470cSBruce Richardson #define DEFAULT_NUM_OPS_INFLIGHT        (128)
15a9de470cSBruce Richardson 
16a9de470cSBruce Richardson #define MAX_NUM_QPS_PER_QAT_DEVICE      (2)
17a9de470cSBruce Richardson #define DEFAULT_NUM_QPS_PER_QAT_DEVICE  (2)
18a9de470cSBruce Richardson #define DEFAULT_BURST_SIZE              (64)
19a9de470cSBruce Richardson #define DEFAULT_NUM_XFORMS              (2)
20a9de470cSBruce Richardson #define NUM_MBUFS                       (8191)
21a9de470cSBruce Richardson #define MBUF_CACHE_SIZE                 (256)
220f678fddSSuanming Mou #define MBUF_DATAPAYLOAD_SIZE		(4096 + DIGEST_BYTE_LENGTH_SHA512)
23a9de470cSBruce Richardson #define MBUF_SIZE			(sizeof(struct rte_mbuf) + \
24a9de470cSBruce Richardson 		RTE_PKTMBUF_HEADROOM + MBUF_DATAPAYLOAD_SIZE)
25a9de470cSBruce Richardson 
26a9de470cSBruce Richardson #define BYTE_LENGTH(x)				(x/8)
27a9de470cSBruce Richardson /* HASH DIGEST LENGTHS */
28a9de470cSBruce Richardson #define DIGEST_BYTE_LENGTH_MD5			(BYTE_LENGTH(128))
29a9de470cSBruce Richardson #define DIGEST_BYTE_LENGTH_SHA1			(BYTE_LENGTH(160))
30a9de470cSBruce Richardson #define DIGEST_BYTE_LENGTH_SHA224		(BYTE_LENGTH(224))
31a9de470cSBruce Richardson #define DIGEST_BYTE_LENGTH_SHA256		(BYTE_LENGTH(256))
32a9de470cSBruce Richardson #define DIGEST_BYTE_LENGTH_SHA384		(BYTE_LENGTH(384))
33a9de470cSBruce Richardson #define DIGEST_BYTE_LENGTH_SHA512		(BYTE_LENGTH(512))
34a9de470cSBruce Richardson #define DIGEST_BYTE_LENGTH_AES_XCBC		(BYTE_LENGTH(96))
35a9de470cSBruce Richardson #define DIGEST_BYTE_LENGTH_SNOW3G_UIA2		(BYTE_LENGTH(32))
36a9de470cSBruce Richardson #define DIGEST_BYTE_LENGTH_KASUMI_F9		(BYTE_LENGTH(32))
37a9de470cSBruce Richardson #define AES_XCBC_MAC_KEY_SZ			(16)
38a9de470cSBruce Richardson #define DIGEST_BYTE_LENGTH_AES_GCM		(BYTE_LENGTH(128))
39a9de470cSBruce Richardson 
40a9de470cSBruce Richardson #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA1		(12)
41a9de470cSBruce Richardson #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA224		(16)
42a9de470cSBruce Richardson #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA256		(16)
43a9de470cSBruce Richardson #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA384		(24)
44a9de470cSBruce Richardson #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA512		(32)
45a9de470cSBruce Richardson 
46a9de470cSBruce Richardson #define MAXIMUM_IV_LENGTH				(16)
47305de560SArek Kusztal #define AES_GCM_J0_LENGTH				(16)
48a9de470cSBruce Richardson 
49a9de470cSBruce Richardson #define IV_OFFSET			(sizeof(struct rte_crypto_op) + \
50a9de470cSBruce Richardson 		sizeof(struct rte_crypto_sym_op) + DEFAULT_NUM_XFORMS * \
51a9de470cSBruce Richardson 		sizeof(struct rte_crypto_sym_xform))
52a9de470cSBruce Richardson 
53a9de470cSBruce Richardson #define CRYPTODEV_NAME_NULL_PMD		crypto_null
54a9de470cSBruce Richardson #define CRYPTODEV_NAME_AESNI_MB_PMD	crypto_aesni_mb
55a9de470cSBruce Richardson #define CRYPTODEV_NAME_AESNI_GCM_PMD	crypto_aesni_gcm
56a9de470cSBruce Richardson #define CRYPTODEV_NAME_OPENSSL_PMD	crypto_openssl
57a9de470cSBruce Richardson #define CRYPTODEV_NAME_QAT_SYM_PMD	crypto_qat
58488f5a23SDamian Nowak #define CRYPTODEV_NAME_QAT_ASYM_PMD	crypto_qat_asym
59a9de470cSBruce Richardson #define CRYPTODEV_NAME_SNOW3G_PMD	crypto_snow3g
60a9de470cSBruce Richardson #define CRYPTODEV_NAME_KASUMI_PMD	crypto_kasumi
61a9de470cSBruce Richardson #define CRYPTODEV_NAME_ZUC_PMD		crypto_zuc
62*418c1a54SKai Ji #define CRYPTODEV_NAME_CHACHA20_POLY1305_PMD	crypto_chacha20_poly1305
63a9de470cSBruce Richardson #define CRYPTODEV_NAME_ARMV8_PMD	crypto_armv8
64a9de470cSBruce Richardson #define CRYPTODEV_NAME_DPAA_SEC_PMD	crypto_dpaa_sec
65a9de470cSBruce Richardson #define CRYPTODEV_NAME_DPAA2_SEC_PMD	crypto_dpaa2_sec
66a9de470cSBruce Richardson #define CRYPTODEV_NAME_SCHEDULER_PMD	crypto_scheduler
67a9de470cSBruce Richardson #define CRYPTODEV_NAME_MVSAM_PMD		crypto_mvsam
68a9de470cSBruce Richardson #define CRYPTODEV_NAME_CCP_PMD		crypto_ccp
69a9de470cSBruce Richardson #define CRYPTODEV_NAME_VIRTIO_PMD	crypto_virtio
70a9de470cSBruce Richardson #define CRYPTODEV_NAME_OCTEONTX_SYM_PMD	crypto_octeontx
71a9de470cSBruce Richardson #define CRYPTODEV_NAME_CAAM_JR_PMD	crypto_caam_jr
725adf37e6SNagadheeraj Rottela #define CRYPTODEV_NAME_NITROX_PMD	crypto_nitrox_sym
73cee518e3SVikas Gupta #define CRYPTODEV_NAME_BCMFS_PMD	crypto_bcmfs
745db3d7d0STejasree Kondoj #define CRYPTODEV_NAME_CN9K_PMD		crypto_cn9k
755db3d7d0STejasree Kondoj #define CRYPTODEV_NAME_CN10K_PMD	crypto_cn10k
7640e91195SShiri Kuzin #define CRYPTODEV_NAME_MLX5_PMD		crypto_mlx5
7740e91195SShiri Kuzin 
78a9de470cSBruce Richardson 
794868f659SFan Zhang enum cryptodev_api_test_type {
804868f659SFan Zhang 	CRYPTODEV_API_TEST = 0,
814868f659SFan Zhang 	CRYPTODEV_RAW_API_TEST
824868f659SFan Zhang };
834868f659SFan Zhang 
844868f659SFan Zhang extern enum cryptodev_api_test_type global_api_test_type;
854868f659SFan Zhang 
86da74df7dSCiara Power extern struct crypto_testsuite_params *p_testsuite_params;
87da74df7dSCiara Power struct crypto_testsuite_params {
88da74df7dSCiara Power 	struct rte_mempool *mbuf_pool;
89da74df7dSCiara Power 	struct rte_mempool *large_mbuf_pool;
90da74df7dSCiara Power 	struct rte_mempool *op_mpool;
91da74df7dSCiara Power 	struct rte_mempool *session_mpool;
92da74df7dSCiara Power 	struct rte_mempool *session_priv_mpool;
93da74df7dSCiara Power 	struct rte_cryptodev_config conf;
94da74df7dSCiara Power 	struct rte_cryptodev_qp_conf qp_conf;
95da74df7dSCiara Power 
96da74df7dSCiara Power 	uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
97da74df7dSCiara Power 	uint8_t valid_dev_count;
98da74df7dSCiara Power };
99da74df7dSCiara Power 
100a9de470cSBruce Richardson /**
101a9de470cSBruce Richardson  * Write (spread) data from buffer to mbuf data
102a9de470cSBruce Richardson  *
103a9de470cSBruce Richardson  * @param mbuf
104a9de470cSBruce Richardson  *   Destination mbuf
105a9de470cSBruce Richardson  * @param offset
106a9de470cSBruce Richardson  *   Start offset in mbuf
107a9de470cSBruce Richardson  * @param len
108a9de470cSBruce Richardson  *   Number of bytes to copy
109a9de470cSBruce Richardson  * @param buffer
110a9de470cSBruce Richardson  *   Continuous source buffer
111a9de470cSBruce Richardson  */
112a9de470cSBruce Richardson static inline void
pktmbuf_write(struct rte_mbuf * mbuf,int offset,int len,const uint8_t * buffer)113a9de470cSBruce Richardson pktmbuf_write(struct rte_mbuf *mbuf, int offset, int len, const uint8_t *buffer)
114a9de470cSBruce Richardson {
115a9de470cSBruce Richardson 	int n = len;
116a9de470cSBruce Richardson 	int l;
117a9de470cSBruce Richardson 	struct rte_mbuf *m;
118a9de470cSBruce Richardson 	char *dst;
119a9de470cSBruce Richardson 
120a9de470cSBruce Richardson 	for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
121a9de470cSBruce Richardson 		offset -= m->data_len;
122a9de470cSBruce Richardson 
123a9de470cSBruce Richardson 	l = m->data_len - offset;
124a9de470cSBruce Richardson 
125a9de470cSBruce Richardson 	/* copy data from first segment */
126a9de470cSBruce Richardson 	dst = rte_pktmbuf_mtod_offset(m, char *, offset);
127a9de470cSBruce Richardson 	if (len <= l) {
128a9de470cSBruce Richardson 		rte_memcpy(dst, buffer, len);
129a9de470cSBruce Richardson 		return;
130a9de470cSBruce Richardson 	}
131a9de470cSBruce Richardson 
132a9de470cSBruce Richardson 	rte_memcpy(dst, buffer, l);
133a9de470cSBruce Richardson 	buffer += l;
134a9de470cSBruce Richardson 	n -= l;
135a9de470cSBruce Richardson 
136a9de470cSBruce Richardson 	for (m = m->next; (m != NULL) && (n > 0); m = m->next) {
137a9de470cSBruce Richardson 		dst = rte_pktmbuf_mtod(m, char *);
138a9de470cSBruce Richardson 		l = m->data_len;
139a9de470cSBruce Richardson 		if (n < l) {
140a9de470cSBruce Richardson 			rte_memcpy(dst, buffer, n);
141a9de470cSBruce Richardson 			return;
142a9de470cSBruce Richardson 		}
143a9de470cSBruce Richardson 		rte_memcpy(dst, buffer, l);
144a9de470cSBruce Richardson 		buffer += l;
145a9de470cSBruce Richardson 		n -= l;
146a9de470cSBruce Richardson 	}
147a9de470cSBruce Richardson }
148a9de470cSBruce Richardson 
149a9de470cSBruce Richardson static inline uint8_t *
pktmbuf_mtod_offset(struct rte_mbuf * mbuf,int offset)150a9de470cSBruce Richardson pktmbuf_mtod_offset(struct rte_mbuf *mbuf, int offset) {
151a9de470cSBruce Richardson 	struct rte_mbuf *m;
152a9de470cSBruce Richardson 
153a9de470cSBruce Richardson 	for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
154a9de470cSBruce Richardson 		offset -= m->data_len;
155a9de470cSBruce Richardson 
156a9de470cSBruce Richardson 	if (m == NULL) {
157a9de470cSBruce Richardson 		printf("pktmbuf_mtod_offset: offset out of buffer\n");
158a9de470cSBruce Richardson 		return NULL;
159a9de470cSBruce Richardson 	}
160a9de470cSBruce Richardson 	return rte_pktmbuf_mtod_offset(m, uint8_t *, offset);
161a9de470cSBruce Richardson }
162a9de470cSBruce Richardson 
163a9de470cSBruce Richardson static inline rte_iova_t
pktmbuf_iova_offset(struct rte_mbuf * mbuf,int offset)164a9de470cSBruce Richardson pktmbuf_iova_offset(struct rte_mbuf *mbuf, int offset) {
165a9de470cSBruce Richardson 	struct rte_mbuf *m;
166a9de470cSBruce Richardson 
167a9de470cSBruce Richardson 	for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
168a9de470cSBruce Richardson 		offset -= m->data_len;
169a9de470cSBruce Richardson 
170a9de470cSBruce Richardson 	if (m == NULL) {
171a9de470cSBruce Richardson 		printf("pktmbuf_iova_offset: offset out of buffer\n");
172a9de470cSBruce Richardson 		return 0;
173a9de470cSBruce Richardson 	}
174a9de470cSBruce Richardson 	return rte_pktmbuf_iova_offset(m, offset);
175a9de470cSBruce Richardson }
176a9de470cSBruce Richardson 
177a9de470cSBruce Richardson static inline struct rte_mbuf *
create_segmented_mbuf(struct rte_mempool * mbuf_pool,int pkt_len,int nb_segs,uint8_t pattern)178a9de470cSBruce Richardson create_segmented_mbuf(struct rte_mempool *mbuf_pool, int pkt_len,
179a9de470cSBruce Richardson 		int nb_segs, uint8_t pattern) {
180a9de470cSBruce Richardson 
181a9de470cSBruce Richardson 	struct rte_mbuf *m = NULL, *mbuf = NULL;
182a9de470cSBruce Richardson 	uint8_t *dst;
183a9de470cSBruce Richardson 	int data_len = 0;
184a9de470cSBruce Richardson 	int i, size;
185a9de470cSBruce Richardson 	int t_len;
186a9de470cSBruce Richardson 
187a9de470cSBruce Richardson 	if (pkt_len < 1) {
188a9de470cSBruce Richardson 		printf("Packet size must be 1 or more (is %d)\n", pkt_len);
189a9de470cSBruce Richardson 		return NULL;
190a9de470cSBruce Richardson 	}
191a9de470cSBruce Richardson 
192a9de470cSBruce Richardson 	if (nb_segs < 1) {
193a9de470cSBruce Richardson 		printf("Number of segments must be 1 or more (is %d)\n",
194a9de470cSBruce Richardson 				nb_segs);
195a9de470cSBruce Richardson 		return NULL;
196a9de470cSBruce Richardson 	}
197a9de470cSBruce Richardson 
198a9de470cSBruce Richardson 	t_len = pkt_len >= nb_segs ? pkt_len / nb_segs : 1;
199a9de470cSBruce Richardson 	size = pkt_len;
200a9de470cSBruce Richardson 
201a9de470cSBruce Richardson 	/* Create chained mbuf_src and fill it generated data */
202a9de470cSBruce Richardson 	for (i = 0; size > 0; i++) {
203a9de470cSBruce Richardson 
204a9de470cSBruce Richardson 		m = rte_pktmbuf_alloc(mbuf_pool);
205a9de470cSBruce Richardson 		if (i == 0)
206a9de470cSBruce Richardson 			mbuf = m;
207a9de470cSBruce Richardson 
208a9de470cSBruce Richardson 		if (m == NULL) {
209a9de470cSBruce Richardson 			printf("Cannot create segment for source mbuf");
210a9de470cSBruce Richardson 			goto fail;
211a9de470cSBruce Richardson 		}
212a9de470cSBruce Richardson 
213a9de470cSBruce Richardson 		/* Make sure if tailroom is zeroed */
214a9de470cSBruce Richardson 		memset(m->buf_addr, pattern, m->buf_len);
215a9de470cSBruce Richardson 
216a9de470cSBruce Richardson 		data_len = size > t_len ? t_len : size;
217a9de470cSBruce Richardson 		dst = (uint8_t *)rte_pktmbuf_append(m, data_len);
218a9de470cSBruce Richardson 		if (dst == NULL) {
219a9de470cSBruce Richardson 			printf("Cannot append %d bytes to the mbuf\n",
220a9de470cSBruce Richardson 					data_len);
221a9de470cSBruce Richardson 			goto fail;
222a9de470cSBruce Richardson 		}
223a9de470cSBruce Richardson 
224a9de470cSBruce Richardson 		if (mbuf != m)
225a9de470cSBruce Richardson 			rte_pktmbuf_chain(mbuf, m);
226a9de470cSBruce Richardson 
227a9de470cSBruce Richardson 		size -= data_len;
228a9de470cSBruce Richardson 
229a9de470cSBruce Richardson 	}
230a9de470cSBruce Richardson 	return mbuf;
231a9de470cSBruce Richardson 
232a9de470cSBruce Richardson fail:
233a9de470cSBruce Richardson 	rte_pktmbuf_free(mbuf);
234a9de470cSBruce Richardson 	return NULL;
235a9de470cSBruce Richardson }
236a9de470cSBruce Richardson 
2374868f659SFan Zhang void
2384868f659SFan Zhang process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
2394868f659SFan Zhang 		struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
2404868f659SFan Zhang 		uint8_t len_in_bits, uint8_t cipher_iv_len);
2414868f659SFan Zhang 
2428bfdd8a7SCiara Power int
2438bfdd8a7SCiara Power check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
2448bfdd8a7SCiara Power 		uint16_t num_ciphers);
2458bfdd8a7SCiara Power 
2468bfdd8a7SCiara Power int
2478bfdd8a7SCiara Power check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
2488bfdd8a7SCiara Power 		uint16_t num_auths);
2498bfdd8a7SCiara Power 
2508bfdd8a7SCiara Power int
2518bfdd8a7SCiara Power check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
2528bfdd8a7SCiara Power 		uint16_t num_aeads);
2538bfdd8a7SCiara Power 
254da74df7dSCiara Power int
255da74df7dSCiara Power ut_setup(void);
256da74df7dSCiara Power 
257da74df7dSCiara Power void
258da74df7dSCiara Power ut_teardown(void);
259da74df7dSCiara Power 
260a9de470cSBruce Richardson #endif /* TEST_CRYPTODEV_H_ */
261