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_ZUC_PMD crypto_zuc
63 : : #define CRYPTODEV_NAME_ARMV8_PMD crypto_armv8
64 : : #define CRYPTODEV_NAME_DPAA_SEC_PMD crypto_dpaa_sec
65 : : #define CRYPTODEV_NAME_DPAA2_SEC_PMD crypto_dpaa2_sec
66 : : #define CRYPTODEV_NAME_SCHEDULER_PMD crypto_scheduler
67 : : #define CRYPTODEV_NAME_MVSAM_PMD crypto_mvsam
68 : : #define CRYPTODEV_NAME_CCP_PMD crypto_ccp
69 : : #define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio
70 : : #define CRYPTODEV_NAME_VIRTIO_USER_PMD crypto_virtio_user
71 : : #define CRYPTODEV_NAME_OCTEONTX_SYM_PMD crypto_octeontx
72 : : #define CRYPTODEV_NAME_CAAM_JR_PMD crypto_caam_jr
73 : : #define CRYPTODEV_NAME_NITROX_PMD crypto_nitrox_sym
74 : : #define CRYPTODEV_NAME_BCMFS_PMD crypto_bcmfs
75 : : #define CRYPTODEV_NAME_CN9K_PMD crypto_cn9k
76 : : #define CRYPTODEV_NAME_CN10K_PMD crypto_cn10k
77 : : #define CRYPTODEV_NAME_CN20K_PMD crypto_cn20k
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 rte_security_session_action_type gbl_action_type;
89 : : extern enum cryptodev_api_test_type global_api_test_type;
90 : :
91 : : extern struct crypto_testsuite_params *p_testsuite_params;
92 : : struct crypto_testsuite_params {
93 : : struct rte_mempool *mbuf_pool;
94 : : struct rte_mempool *large_mbuf_pool;
95 : : struct rte_mempool *op_mpool;
96 : : struct rte_mempool *session_mpool;
97 : : struct rte_cryptodev_config conf;
98 : : struct rte_cryptodev_qp_conf qp_conf;
99 : :
100 : : uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
101 : : uint8_t valid_dev_count;
102 : : };
103 : :
104 : : /**
105 : : * Write (spread) data from buffer to mbuf data
106 : : *
107 : : * @param mbuf
108 : : * Destination mbuf
109 : : * @param offset
110 : : * Start offset in mbuf
111 : : * @param len
112 : : * Number of bytes to copy
113 : : * @param buffer
114 : : * Continuous source buffer
115 : : */
116 : : static inline void
117 : 178 : pktmbuf_write(struct rte_mbuf *mbuf, int offset, int len, const uint8_t *buffer)
118 : : {
119 : : int n = len;
120 : : int l;
121 : : struct rte_mbuf *m;
122 : : char *dst;
123 : :
124 [ + - - + ]: 178 : for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
125 : 0 : offset -= m->data_len;
126 : :
127 : 178 : l = m->data_len - offset;
128 : :
129 : : /* copy data from first segment */
130 : 178 : dst = rte_pktmbuf_mtod_offset(m, char *, offset);
131 [ + + ]: 178 : if (len <= l) {
132 [ + + ]: 160 : rte_memcpy(dst, buffer, len);
133 : 160 : return;
134 : : }
135 : :
136 [ + + ]: 18 : rte_memcpy(dst, buffer, l);
137 : 18 : buffer += l;
138 : 18 : n -= l;
139 : :
140 [ + + ]: 93 : for (m = m->next; (m != NULL) && (n > 0); m = m->next) {
141 : 76 : dst = rte_pktmbuf_mtod(m, char *);
142 : 76 : l = m->data_len;
143 [ + + ]: 76 : if (n < l) {
144 [ + - ]: 1 : rte_memcpy(dst, buffer, n);
145 : 1 : return;
146 : : }
147 [ + + ]: 75 : rte_memcpy(dst, buffer, l);
148 : 75 : buffer += l;
149 : 75 : n -= l;
150 : : }
151 : : }
152 : :
153 : : static inline uint8_t *
154 : 170 : pktmbuf_mtod_offset(struct rte_mbuf *mbuf, int offset)
155 : : {
156 : : struct rte_mbuf *m;
157 : :
158 [ + - + + ]: 201 : for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
159 : 31 : offset -= m->data_len;
160 : :
161 [ - + ]: 170 : if (m == NULL) {
162 : : printf("pktmbuf_mtod_offset: offset out of buffer\n");
163 : 0 : return NULL;
164 : : }
165 : 170 : return rte_pktmbuf_mtod_offset(m, uint8_t *, offset);
166 : : }
167 : :
168 : : static inline rte_iova_t
169 : 113 : pktmbuf_iova_offset(struct rte_mbuf *mbuf, int offset)
170 : : {
171 : : struct rte_mbuf *m;
172 : :
173 [ + - + + ]: 135 : for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
174 : 22 : offset -= m->data_len;
175 : :
176 [ - + ]: 113 : if (m == NULL) {
177 : : printf("pktmbuf_iova_offset: offset out of buffer\n");
178 : 0 : return 0;
179 : : }
180 : 113 : return rte_pktmbuf_iova_offset(m, offset);
181 : : }
182 : :
183 : : static inline struct rte_mbuf *
184 : 178 : create_segmented_mbuf(struct rte_mempool *mbuf_pool, int pkt_len,
185 : : int nb_segs, uint8_t pattern)
186 : : {
187 : : struct rte_mbuf *m = NULL, *mbuf = NULL;
188 : : int size, t_len, data_len = 0;
189 : : uint8_t *dst;
190 : :
191 [ - + ]: 178 : if (nb_segs < 1) {
192 : : printf("Number of segments must be 1 or more (is %d)\n",
193 : : nb_segs);
194 : 0 : return NULL;
195 : : }
196 : :
197 [ + - ]: 178 : t_len = pkt_len >= nb_segs ? pkt_len / nb_segs : 1;
198 : : size = pkt_len;
199 : :
200 : : /* Create chained mbuf_src and fill it generated data */
201 : : do {
202 : :
203 : 254 : m = rte_pktmbuf_alloc(mbuf_pool);
204 [ - + ]: 254 : if (m == NULL) {
205 : : printf("Cannot create segment for source mbuf");
206 : 0 : goto fail;
207 : : }
208 : :
209 [ + + ]: 254 : if (mbuf == NULL)
210 : : mbuf = m;
211 : :
212 : : /* Make sure if tailroom is zeroed */
213 : 254 : memset(m->buf_addr, pattern, m->buf_len);
214 : :
215 : 254 : data_len = size > t_len ? t_len : size;
216 : 254 : dst = (uint8_t *)rte_pktmbuf_append(m, data_len);
217 [ - + ]: 254 : if (dst == NULL) {
218 : : printf("Cannot append %d bytes to the mbuf\n",
219 : : data_len);
220 : 0 : goto fail;
221 : : }
222 : :
223 [ + + ]: 254 : if (mbuf != m)
224 : : rte_pktmbuf_chain(mbuf, m);
225 : :
226 : 254 : size -= data_len;
227 : :
228 [ + + ]: 254 : } while (size > 0);
229 : :
230 : : return mbuf;
231 : :
232 : 0 : fail:
233 : 0 : rte_pktmbuf_free(mbuf);
234 : 0 : return NULL;
235 : : }
236 : :
237 : : static inline struct rte_mbuf *
238 : 0 : create_segmented_mbuf_multi_pool(struct rte_mempool *mbuf_pool_small,
239 : : struct rte_mempool *mbuf_pool_large, int pkt_len, int nb_segs, uint8_t pattern)
240 : : {
241 : : struct rte_mempool *mbuf_pool;
242 : : int max_seg_len, seg_len;
243 : :
244 [ # # ]: 0 : if (nb_segs < 1) {
245 : : printf("Number of segments must be 1 or more (is %d)\n", nb_segs);
246 : 0 : return NULL;
247 : : }
248 : :
249 [ # # ]: 0 : if (pkt_len >= nb_segs)
250 : 0 : seg_len = pkt_len / nb_segs;
251 : : else
252 : : seg_len = 1;
253 : :
254 : : /* Determine max segment length */
255 : 0 : max_seg_len = seg_len + pkt_len % nb_segs;
256 : :
257 [ # # ]: 0 : if (max_seg_len > LARGE_MBUF_DATAPAYLOAD_SIZE) {
258 : : printf("Segment size %d is too big\n", max_seg_len);
259 : 0 : return NULL;
260 : : }
261 : :
262 [ # # ]: 0 : if (max_seg_len > MBUF_DATAPAYLOAD_SIZE)
263 : : mbuf_pool = mbuf_pool_large;
264 : : else
265 : : mbuf_pool = mbuf_pool_small;
266 : :
267 [ # # ]: 0 : if (mbuf_pool == NULL) {
268 : : printf("Invalid mbuf pool\n");
269 : 0 : return NULL;
270 : : }
271 : :
272 : 0 : return create_segmented_mbuf(mbuf_pool, pkt_len, nb_segs, pattern);
273 : : }
274 : :
275 : : int
276 : : process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
277 : : struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
278 : : uint8_t len_in_bits, uint8_t cipher_iv_len);
279 : :
280 : : int
281 : : check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
282 : : uint16_t num_ciphers);
283 : :
284 : : int
285 : : check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
286 : : uint16_t num_auths);
287 : :
288 : : int
289 : : check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
290 : : uint16_t num_aeads);
291 : :
292 : : int
293 : : ut_setup(void);
294 : :
295 : : void
296 : : ut_teardown(void);
297 : :
298 : : #endif /* TEST_CRYPTODEV_H_ */
|