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