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 HEX_DUMP 0
10 : :
11 : : #define FALSE 0
12 : : #define TRUE 1
13 : :
14 : : #define MAX_NUM_OPS_INFLIGHT (4096)
15 : : #define MIN_NUM_OPS_INFLIGHT (128)
16 : : #define DEFAULT_NUM_OPS_INFLIGHT (128)
17 : :
18 : : #define MAX_NUM_QPS_PER_QAT_DEVICE (2)
19 : : #define DEFAULT_NUM_QPS_PER_QAT_DEVICE (2)
20 : : #define DEFAULT_BURST_SIZE (64)
21 : : #define DEFAULT_NUM_XFORMS (2)
22 : : #define NUM_MBUFS (8191)
23 : : #define MBUF_CACHE_SIZE (256)
24 : : #define MBUF_DATAPAYLOAD_SIZE (4096 + DIGEST_BYTE_LENGTH_SHA512)
25 : : #define MBUF_SIZE (sizeof(struct rte_mbuf) + \
26 : : RTE_PKTMBUF_HEADROOM + MBUF_DATAPAYLOAD_SIZE)
27 : :
28 : : #define BYTE_LENGTH(x) (x/8)
29 : : /* HASH DIGEST LENGTHS */
30 : : #define DIGEST_BYTE_LENGTH_MD5 (BYTE_LENGTH(128))
31 : : #define DIGEST_BYTE_LENGTH_SHA1 (BYTE_LENGTH(160))
32 : : #define DIGEST_BYTE_LENGTH_SHA224 (BYTE_LENGTH(224))
33 : : #define DIGEST_BYTE_LENGTH_SHA256 (BYTE_LENGTH(256))
34 : : #define DIGEST_BYTE_LENGTH_SHA384 (BYTE_LENGTH(384))
35 : : #define DIGEST_BYTE_LENGTH_SHA512 (BYTE_LENGTH(512))
36 : : #define DIGEST_BYTE_LENGTH_AES_XCBC (BYTE_LENGTH(96))
37 : : #define DIGEST_BYTE_LENGTH_SNOW3G_UIA2 (BYTE_LENGTH(32))
38 : : #define DIGEST_BYTE_LENGTH_KASUMI_F9 (BYTE_LENGTH(32))
39 : : #define AES_XCBC_MAC_KEY_SZ (16)
40 : : #define DIGEST_BYTE_LENGTH_AES_GCM (BYTE_LENGTH(128))
41 : :
42 : : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 (12)
43 : : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA224 (16)
44 : : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA256 (16)
45 : : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA384 (24)
46 : : #define TRUNCATED_DIGEST_BYTE_LENGTH_SHA512 (32)
47 : :
48 : : #define MAXIMUM_IV_LENGTH (16)
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_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 : :
81 : :
82 : : enum cryptodev_api_test_type {
83 : : CRYPTODEV_API_TEST = 0,
84 : : CRYPTODEV_RAW_API_TEST
85 : : };
86 : :
87 : : extern enum cryptodev_api_test_type global_api_test_type;
88 : :
89 : : extern struct crypto_testsuite_params *p_testsuite_params;
90 : : struct crypto_testsuite_params {
91 : : struct rte_mempool *mbuf_pool;
92 : : struct rte_mempool *large_mbuf_pool;
93 : : struct rte_mempool *op_mpool;
94 : : struct rte_mempool *session_mpool;
95 : : struct rte_mempool *session_priv_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 : : struct rte_mbuf *m;
155 : :
156 [ + - + + ]: 171 : for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
157 : 31 : offset -= m->data_len;
158 : :
159 [ - + ]: 140 : if (m == NULL) {
160 : : printf("pktmbuf_mtod_offset: offset out of buffer\n");
161 : 0 : return NULL;
162 : : }
163 : 140 : return rte_pktmbuf_mtod_offset(m, uint8_t *, offset);
164 : : }
165 : :
166 : : static inline rte_iova_t
167 : 93 : pktmbuf_iova_offset(struct rte_mbuf *mbuf, int offset) {
168 : : struct rte_mbuf *m;
169 : :
170 [ + - + + ]: 115 : for (m = mbuf; (m != NULL) && (offset > m->data_len); m = m->next)
171 : 22 : offset -= m->data_len;
172 : :
173 [ - + ]: 93 : if (m == NULL) {
174 : : printf("pktmbuf_iova_offset: offset out of buffer\n");
175 : 0 : return 0;
176 : : }
177 : 93 : return rte_pktmbuf_iova_offset(m, offset);
178 : : }
179 : :
180 : : static inline struct rte_mbuf *
181 : 150 : create_segmented_mbuf(struct rte_mempool *mbuf_pool, int pkt_len,
182 : : int nb_segs, uint8_t pattern) {
183 : :
184 : : struct rte_mbuf *m = NULL, *mbuf = NULL;
185 : : int size, t_len, data_len = 0;
186 : : uint8_t *dst;
187 : :
188 [ - + ]: 150 : if (nb_segs < 1) {
189 : : printf("Number of segments must be 1 or more (is %d)\n",
190 : : nb_segs);
191 : 0 : return NULL;
192 : : }
193 : :
194 [ + - ]: 150 : t_len = pkt_len >= nb_segs ? pkt_len / nb_segs : 1;
195 : : size = pkt_len;
196 : :
197 : : /* Create chained mbuf_src and fill it generated data */
198 : : do {
199 : :
200 : 226 : m = rte_pktmbuf_alloc(mbuf_pool);
201 [ - + ]: 226 : if (m == NULL) {
202 : : printf("Cannot create segment for source mbuf");
203 : 0 : goto fail;
204 : : }
205 : :
206 [ + + ]: 226 : if (mbuf == NULL)
207 : : mbuf = m;
208 : :
209 : : /* Make sure if tailroom is zeroed */
210 : 226 : memset(m->buf_addr, pattern, m->buf_len);
211 : :
212 : 226 : data_len = size > t_len ? t_len : size;
213 : 226 : dst = (uint8_t *)rte_pktmbuf_append(m, data_len);
214 [ - + ]: 226 : if (dst == NULL) {
215 : : printf("Cannot append %d bytes to the mbuf\n",
216 : : data_len);
217 : 0 : goto fail;
218 : : }
219 : :
220 [ + + ]: 226 : if (mbuf != m)
221 : : rte_pktmbuf_chain(mbuf, m);
222 : :
223 : 226 : size -= data_len;
224 : :
225 [ + + ]: 226 : } while (size > 0);
226 : :
227 : : return mbuf;
228 : :
229 : 0 : fail:
230 : 0 : rte_pktmbuf_free(mbuf);
231 : 0 : return NULL;
232 : : }
233 : :
234 : : int
235 : : process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
236 : : struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
237 : : uint8_t len_in_bits, uint8_t cipher_iv_len);
238 : :
239 : : int
240 : : check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
241 : : uint16_t num_ciphers);
242 : :
243 : : int
244 : : check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
245 : : uint16_t num_auths);
246 : :
247 : : int
248 : : check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
249 : : uint16_t num_aeads);
250 : :
251 : : int
252 : : ut_setup(void);
253 : :
254 : : void
255 : : ut_teardown(void);
256 : :
257 : : #endif /* TEST_CRYPTODEV_H_ */
|