Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2015-2017 Intel Corporation
3 : : */
4 : : #ifndef TEST_CRYPTODEV_H_
5 : : #define TEST_CRYPTODEV_H_
6 : :
7 : : #include <rte_cryptodev.h>
8 : :
9 : : #define MAX_NUM_OPS_INFLIGHT (4096)
10 : : #define MIN_NUM_OPS_INFLIGHT (128)
11 : : #define DEFAULT_NUM_OPS_INFLIGHT (128)
12 : : #define TEST_STATS_RETRIES (100)
13 : :
14 : : #define DEFAULT_NUM_XFORMS (2)
15 : : #define NUM_MBUFS (8191)
16 : : #define MBUF_CACHE_SIZE (256)
17 : : #define MBUF_DATAPAYLOAD_SIZE (4096 + DIGEST_BYTE_LENGTH_SHA512)
18 : : #define MBUF_SIZE (sizeof(struct rte_mbuf) + \
19 : : RTE_PKTMBUF_HEADROOM + MBUF_DATAPAYLOAD_SIZE)
20 : : #define LARGE_MBUF_DATAPAYLOAD_SIZE (UINT16_MAX - RTE_PKTMBUF_HEADROOM)
21 : : #define LARGE_MBUF_SIZE (RTE_PKTMBUF_HEADROOM + LARGE_MBUF_DATAPAYLOAD_SIZE)
22 : :
23 : : #define BYTE_LENGTH(x) (x/8)
24 : : /* HASH DIGEST LENGTHS */
25 : : #define DIGEST_BYTE_LENGTH_MD5 (BYTE_LENGTH(128))
26 : : #define DIGEST_BYTE_LENGTH_SHA1 (BYTE_LENGTH(160))
27 : : #define DIGEST_BYTE_LENGTH_SHA224 (BYTE_LENGTH(224))
28 : : #define DIGEST_BYTE_LENGTH_SHA256 (BYTE_LENGTH(256))
29 : : #define DIGEST_BYTE_LENGTH_SHA384 (BYTE_LENGTH(384))
30 : : #define DIGEST_BYTE_LENGTH_SHA512 (BYTE_LENGTH(512))
31 : : #define DIGEST_BYTE_LENGTH_AES_XCBC (BYTE_LENGTH(96))
32 : : #define DIGEST_BYTE_LENGTH_SNOW3G_UIA2 (BYTE_LENGTH(32))
33 : : #define DIGEST_BYTE_LENGTH_KASUMI_F9 (BYTE_LENGTH(32))
34 : : #define AES_XCBC_MAC_KEY_SZ (16)
35 : : #define DIGEST_BYTE_LENGTH_AES_GCM (BYTE_LENGTH(128))
36 : :
37 : : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 (12)
38 : : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA224 (16)
39 : : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA256 (16)
40 : : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA384 (24)
41 : : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA512 (32)
42 : :
43 : : /*
44 : : * maximum IV length need to include both the
45 : : * auth IV length (16 bytes) and the cipher IV length (16 bytes)
46 : : */
47 : : #define MAXIMUM_IV_LENGTH (32)
48 : : #define AES_GCM_J0_LENGTH (16)
49 : :
50 : : #define IV_OFFSET (sizeof(struct rte_crypto_op) + \
51 : : sizeof(struct rte_crypto_sym_op) + DEFAULT_NUM_XFORMS * \
52 : : sizeof(struct rte_crypto_sym_xform))
53 : :
54 : : #define CRYPTODEV_NAME_NULL_PMD crypto_null
55 : : #define CRYPTODEV_NAME_AESNI_MB_PMD crypto_aesni_mb
56 : : #define CRYPTODEV_NAME_AESNI_GCM_PMD crypto_aesni_gcm
57 : : #define CRYPTODEV_NAME_OPENSSL_PMD crypto_openssl
58 : : #define CRYPTODEV_NAME_QAT_SYM_PMD crypto_qat
59 : : #define CRYPTODEV_NAME_QAT_ASYM_PMD crypto_qat_asym
60 : : #define CRYPTODEV_NAME_SNOW3G_PMD crypto_snow3g
61 : : #define CRYPTODEV_NAME_KASUMI_PMD crypto_kasumi
62 : : #define CRYPTODEV_NAME_ZUC_PMD crypto_zuc
63 : : #define CRYPTODEV_NAME_CHACHA20_POLY1305_PMD crypto_chacha20_poly1305
64 : : #define CRYPTODEV_NAME_ARMV8_PMD crypto_armv8
65 : : #define CRYPTODEV_NAME_DPAA_SEC_PMD crypto_dpaa_sec
66 : : #define CRYPTODEV_NAME_DPAA2_SEC_PMD crypto_dpaa2_sec
67 : : #define CRYPTODEV_NAME_SCHEDULER_PMD crypto_scheduler
68 : : #define CRYPTODEV_NAME_MVSAM_PMD crypto_mvsam
69 : : #define CRYPTODEV_NAME_CCP_PMD crypto_ccp
70 : : #define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio
71 : : #define CRYPTODEV_NAME_VIRTIO_USER_PMD crypto_virtio_user
72 : : #define CRYPTODEV_NAME_OCTEONTX_SYM_PMD crypto_octeontx
73 : : #define CRYPTODEV_NAME_CAAM_JR_PMD crypto_caam_jr
74 : : #define CRYPTODEV_NAME_NITROX_PMD crypto_nitrox_sym
75 : : #define CRYPTODEV_NAME_BCMFS_PMD crypto_bcmfs
76 : : #define CRYPTODEV_NAME_CN9K_PMD crypto_cn9k
77 : : #define CRYPTODEV_NAME_CN10K_PMD crypto_cn10k
78 : : #define CRYPTODEV_NAME_MLX5_PMD crypto_mlx5
79 : : #define CRYPTODEV_NAME_UADK_PMD crypto_uadk
80 : : #define CRYPTODEV_NAME_ZSDA_SYM_PMD crypto_zsda
81 : :
82 : :
83 : : enum cryptodev_api_test_type {
84 : : CRYPTODEV_API_TEST = 0,
85 : : CRYPTODEV_RAW_API_TEST
86 : : };
87 : :
88 : : extern enum cryptodev_api_test_type global_api_test_type;
89 : :
90 : : extern struct crypto_testsuite_params *p_testsuite_params;
91 : : struct crypto_testsuite_params {
92 : : struct rte_mempool *mbuf_pool;
93 : : struct rte_mempool *large_mbuf_pool;
94 : : struct rte_mempool *op_mpool;
95 : : struct rte_mempool *session_mpool;
96 : : struct rte_cryptodev_config conf;
97 : : struct rte_cryptodev_qp_conf qp_conf;
98 : :
99 : : uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
100 : : uint8_t valid_dev_count;
101 : : };
102 : :
103 : : /**
104 : : * Write (spread) data from buffer to mbuf data
105 : : *
106 : : * @param mbuf
107 : : * Destination mbuf
108 : : * @param offset
109 : : * Start offset in mbuf
110 : : * @param len
111 : : * Number of bytes to copy
112 : : * @param buffer
113 : : * Continuous source buffer
114 : : */
115 : : static inline void
116 : 150 : pktmbuf_write(struct rte_mbuf *mbuf, int offset, int len, const uint8_t *buffer)
117 : : {
118 : : int n = len;
119 : : int l;
120 : : struct rte_mbuf *m;
121 : : char *dst;
122 : :
123 [ + - - + ]: 150 : for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
124 : 0 : offset -= m->data_len;
125 : :
126 : 150 : l = m->data_len - offset;
127 : :
128 : : /* copy data from first segment */
129 : 150 : dst = rte_pktmbuf_mtod_offset(m, char *, offset);
130 [ + + ]: 150 : if (len <= l) {
131 [ + + ]: 132 : rte_memcpy(dst, buffer, len);
132 : 132 : return;
133 : : }
134 : :
135 [ + + ]: 18 : rte_memcpy(dst, buffer, l);
136 : 18 : buffer += l;
137 : 18 : n -= l;
138 : :
139 [ + + ]: 93 : for (m = m->next; (m != NULL) && (n > 0); m = m->next) {
140 : 76 : dst = rte_pktmbuf_mtod(m, char *);
141 : 76 : l = m->data_len;
142 [ + + ]: 76 : if (n < l) {
143 [ - + ]: 1 : rte_memcpy(dst, buffer, n);
144 : 1 : return;
145 : : }
146 [ + + ]: 75 : rte_memcpy(dst, buffer, l);
147 : 75 : buffer += l;
148 : 75 : n -= l;
149 : : }
150 : : }
151 : :
152 : : static inline uint8_t *
153 : 140 : pktmbuf_mtod_offset(struct rte_mbuf *mbuf, int offset)
154 : : {
155 : : struct rte_mbuf *m;
156 : :
157 [ + - + + ]: 171 : for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
158 : 31 : offset -= m->data_len;
159 : :
160 [ - + ]: 140 : if (m == NULL) {
161 : : printf("pktmbuf_mtod_offset: offset out of buffer\n");
162 : 0 : return NULL;
163 : : }
164 : 140 : return rte_pktmbuf_mtod_offset(m, uint8_t *, offset);
165 : : }
166 : :
167 : : static inline rte_iova_t
168 : 93 : pktmbuf_iova_offset(struct rte_mbuf *mbuf, int offset)
169 : : {
170 : : struct rte_mbuf *m;
171 : :
172 [ + - + + ]: 115 : for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
173 : 22 : offset -= m->data_len;
174 : :
175 [ - + ]: 93 : if (m == NULL) {
176 : : printf("pktmbuf_iova_offset: offset out of buffer\n");
177 : 0 : return 0;
178 : : }
179 : 93 : return rte_pktmbuf_iova_offset(m, offset);
180 : : }
181 : :
182 : : static inline struct rte_mbuf *
183 : 150 : create_segmented_mbuf(struct rte_mempool *mbuf_pool, int pkt_len,
184 : : int nb_segs, uint8_t pattern)
185 : : {
186 : : struct rte_mbuf *m = NULL, *mbuf = NULL;
187 : : int size, t_len, data_len = 0;
188 : : uint8_t *dst;
189 : :
190 [ - + ]: 150 : if (nb_segs < 1) {
191 : : printf("Number of segments must be 1 or more (is %d)\n",
192 : : nb_segs);
193 : 0 : return NULL;
194 : : }
195 : :
196 [ + - ]: 150 : t_len = pkt_len >= nb_segs ? pkt_len / nb_segs : 1;
197 : : size = pkt_len;
198 : :
199 : : /* Create chained mbuf_src and fill it generated data */
200 : : do {
201 : :
202 : 226 : m = rte_pktmbuf_alloc(mbuf_pool);
203 [ - + ]: 226 : if (m == NULL) {
204 : : printf("Cannot create segment for source mbuf");
205 : 0 : goto fail;
206 : : }
207 : :
208 [ + + ]: 226 : if (mbuf == NULL)
209 : : mbuf = m;
210 : :
211 : : /* Make sure if tailroom is zeroed */
212 : 226 : memset(m->buf_addr, pattern, m->buf_len);
213 : :
214 : 226 : data_len = size > t_len ? t_len : size;
215 : 226 : dst = (uint8_t *)rte_pktmbuf_append(m, data_len);
216 [ - + ]: 226 : if (dst == NULL) {
217 : : printf("Cannot append %d bytes to the mbuf\n",
218 : : data_len);
219 : 0 : goto fail;
220 : : }
221 : :
222 [ + + ]: 226 : if (mbuf != m)
223 : : rte_pktmbuf_chain(mbuf, m);
224 : :
225 : 226 : size -= data_len;
226 : :
227 [ + + ]: 226 : } while (size > 0);
228 : :
229 : : return mbuf;
230 : :
231 : 0 : fail:
232 : 0 : rte_pktmbuf_free(mbuf);
233 : 0 : return NULL;
234 : : }
235 : :
236 : : static inline struct rte_mbuf *
237 : 0 : create_segmented_mbuf_multi_pool(struct rte_mempool *mbuf_pool_small,
238 : : struct rte_mempool *mbuf_pool_large, int pkt_len, int nb_segs, uint8_t pattern)
239 : : {
240 : : struct rte_mempool *mbuf_pool;
241 : : int max_seg_len, seg_len;
242 : :
243 [ # # ]: 0 : if (nb_segs < 1) {
244 : : printf("Number of segments must be 1 or more (is %d)\n", nb_segs);
245 : 0 : return NULL;
246 : : }
247 : :
248 [ # # ]: 0 : if (pkt_len >= nb_segs)
249 : 0 : seg_len = pkt_len / nb_segs;
250 : : else
251 : : seg_len = 1;
252 : :
253 : : /* Determine max segment length */
254 : 0 : max_seg_len = seg_len + pkt_len % nb_segs;
255 : :
256 [ # # ]: 0 : if (max_seg_len > LARGE_MBUF_DATAPAYLOAD_SIZE) {
257 : : printf("Segment size %d is too big\n", max_seg_len);
258 : 0 : return NULL;
259 : : }
260 : :
261 [ # # ]: 0 : if (max_seg_len > MBUF_DATAPAYLOAD_SIZE)
262 : : mbuf_pool = mbuf_pool_large;
263 : : else
264 : : mbuf_pool = mbuf_pool_small;
265 : :
266 [ # # ]: 0 : if (mbuf_pool == NULL) {
267 : : printf("Invalid mbuf pool\n");
268 : 0 : return NULL;
269 : : }
270 : :
271 : 0 : return create_segmented_mbuf(mbuf_pool, pkt_len, nb_segs, pattern);
272 : : }
273 : :
274 : : int
275 : : process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
276 : : struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
277 : : uint8_t len_in_bits, uint8_t cipher_iv_len);
278 : :
279 : : int
280 : : check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
281 : : uint16_t num_ciphers);
282 : :
283 : : int
284 : : check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
285 : : uint16_t num_auths);
286 : :
287 : : int
288 : : check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
289 : : uint16_t num_aeads);
290 : :
291 : : int
292 : : ut_setup(void);
293 : :
294 : : void
295 : : ut_teardown(void);
296 : :
297 : : #endif /* TEST_CRYPTODEV_H_ */
|