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