]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*- |
2 | * BSD LICENSE | |
3 | * | |
11fdf7f2 | 4 | * Copyright(c) 2015-2017 Intel Corporation. All rights reserved. |
7c673cae FG |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | |
9 | * | |
10 | * * Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | |
12 | * * Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in | |
14 | * the documentation and/or other materials provided with the | |
15 | * distribution. | |
16 | * * Neither the name of Intel Corporation nor the names of its | |
17 | * contributors may be used to endorse or promote products derived | |
18 | * from this software without specific prior written permission. | |
19 | * | |
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
31 | */ | |
32 | ||
33 | #include <rte_common.h> | |
34 | #include <rte_hexdump.h> | |
35 | #include <rte_mbuf.h> | |
36 | #include <rte_malloc.h> | |
37 | #include <rte_memcpy.h> | |
38 | ||
39 | #include <rte_crypto.h> | |
40 | #include <rte_cryptodev.h> | |
41 | #include <rte_cryptodev_pmd.h> | |
42 | ||
43 | #include "test.h" | |
11fdf7f2 | 44 | #include "test_cryptodev.h" |
7c673cae FG |
45 | #include "test_cryptodev_blockcipher.h" |
46 | #include "test_cryptodev_aes_test_vectors.h" | |
47 | #include "test_cryptodev_des_test_vectors.h" | |
48 | #include "test_cryptodev_hash_test_vectors.h" | |
11fdf7f2 | 49 | #include "test_cryptodev.h" |
7c673cae FG |
50 | |
51 | static int | |
52 | test_blockcipher_one_case(const struct blockcipher_test_case *t, | |
53 | struct rte_mempool *mbuf_pool, | |
54 | struct rte_mempool *op_mpool, | |
55 | uint8_t dev_id, | |
56 | enum rte_cryptodev_type cryptodev_type, | |
57 | char *test_msg) | |
58 | { | |
59 | struct rte_mbuf *ibuf = NULL; | |
60 | struct rte_mbuf *obuf = NULL; | |
61 | struct rte_mbuf *iobuf; | |
62 | struct rte_crypto_sym_xform *cipher_xform = NULL; | |
63 | struct rte_crypto_sym_xform *auth_xform = NULL; | |
64 | struct rte_crypto_sym_xform *init_xform = NULL; | |
65 | struct rte_crypto_sym_op *sym_op = NULL; | |
66 | struct rte_crypto_op *op = NULL; | |
67 | struct rte_cryptodev_sym_session *sess = NULL; | |
11fdf7f2 | 68 | struct rte_cryptodev_info dev_info; |
7c673cae FG |
69 | |
70 | int status = TEST_SUCCESS; | |
71 | const struct blockcipher_test_data *tdata = t->test_data; | |
72 | uint8_t cipher_key[tdata->cipher_key.len]; | |
73 | uint8_t auth_key[tdata->auth_key.len]; | |
74 | uint32_t buf_len = tdata->ciphertext.len; | |
75 | uint32_t digest_len = 0; | |
76 | char *buf_p = NULL; | |
11fdf7f2 TL |
77 | uint8_t src_pattern = 0xa5; |
78 | uint8_t dst_pattern = 0xb6; | |
79 | uint8_t tmp_src_buf[MBUF_SIZE]; | |
80 | uint8_t tmp_dst_buf[MBUF_SIZE]; | |
81 | ||
82 | int nb_segs = 1; | |
83 | ||
84 | if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SG) { | |
85 | rte_cryptodev_info_get(dev_id, &dev_info); | |
86 | if (!(dev_info.feature_flags & | |
87 | RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) { | |
88 | printf("Device doesn't support scatter-gather. " | |
89 | "Test Skipped.\n"); | |
90 | return 0; | |
91 | } | |
92 | nb_segs = 3; | |
93 | } | |
7c673cae FG |
94 | |
95 | if (tdata->cipher_key.len) | |
96 | memcpy(cipher_key, tdata->cipher_key.data, | |
97 | tdata->cipher_key.len); | |
98 | if (tdata->auth_key.len) | |
99 | memcpy(auth_key, tdata->auth_key.data, | |
100 | tdata->auth_key.len); | |
101 | ||
102 | switch (cryptodev_type) { | |
103 | case RTE_CRYPTODEV_QAT_SYM_PMD: | |
104 | case RTE_CRYPTODEV_OPENSSL_PMD: | |
11fdf7f2 | 105 | case RTE_CRYPTODEV_ARMV8_PMD: /* Fall through */ |
7c673cae FG |
106 | digest_len = tdata->digest.len; |
107 | break; | |
108 | case RTE_CRYPTODEV_AESNI_MB_PMD: | |
11fdf7f2 | 109 | case RTE_CRYPTODEV_SCHEDULER_PMD: |
7c673cae FG |
110 | digest_len = tdata->digest.truncated_len; |
111 | break; | |
112 | default: | |
113 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, | |
114 | "line %u FAILED: %s", | |
115 | __LINE__, "Unsupported PMD type"); | |
116 | status = TEST_FAILED; | |
117 | goto error_exit; | |
118 | } | |
119 | ||
120 | /* preparing data */ | |
7c673cae FG |
121 | if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) |
122 | buf_len += tdata->iv.len; | |
123 | if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) | |
124 | buf_len += digest_len; | |
125 | ||
11fdf7f2 TL |
126 | /* for contiguous mbuf, nb_segs is 1 */ |
127 | ibuf = create_segmented_mbuf(mbuf_pool, | |
128 | tdata->ciphertext.len, nb_segs, src_pattern); | |
129 | if (ibuf == NULL) { | |
7c673cae FG |
130 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, |
131 | "line %u FAILED: %s", | |
11fdf7f2 | 132 | __LINE__, "Cannot create source mbuf"); |
7c673cae FG |
133 | status = TEST_FAILED; |
134 | goto error_exit; | |
135 | } | |
136 | ||
7c673cae FG |
137 | /* only encryption requires plaintext.data input, |
138 | * decryption/(digest gen)/(digest verify) use ciphertext.data | |
139 | * to be computed | |
140 | */ | |
11fdf7f2 TL |
141 | if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) |
142 | pktmbuf_write(ibuf, 0, tdata->plaintext.len, | |
143 | tdata->plaintext.data); | |
144 | else | |
145 | pktmbuf_write(ibuf, 0, tdata->ciphertext.len, | |
146 | tdata->ciphertext.data); | |
7c673cae | 147 | |
11fdf7f2 TL |
148 | if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) { |
149 | rte_memcpy(rte_pktmbuf_prepend(ibuf, tdata->iv.len), | |
150 | tdata->iv.data, tdata->iv.len); | |
151 | } | |
152 | buf_p = rte_pktmbuf_append(ibuf, digest_len); | |
7c673cae FG |
153 | if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) |
154 | rte_memcpy(buf_p, tdata->digest.data, digest_len); | |
155 | else | |
156 | memset(buf_p, 0, digest_len); | |
157 | ||
158 | if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) { | |
159 | obuf = rte_pktmbuf_alloc(mbuf_pool); | |
160 | if (!obuf) { | |
161 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " | |
162 | "FAILED: %s", __LINE__, | |
163 | "Allocation of rte_mbuf failed"); | |
164 | status = TEST_FAILED; | |
165 | goto error_exit; | |
166 | } | |
11fdf7f2 | 167 | memset(obuf->buf_addr, dst_pattern, obuf->buf_len); |
7c673cae FG |
168 | |
169 | buf_p = rte_pktmbuf_append(obuf, buf_len); | |
170 | if (!buf_p) { | |
171 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " | |
172 | "FAILED: %s", __LINE__, | |
173 | "No room to append mbuf"); | |
174 | status = TEST_FAILED; | |
175 | goto error_exit; | |
176 | } | |
177 | memset(buf_p, 0, buf_len); | |
178 | } | |
179 | ||
180 | /* Generate Crypto op data structure */ | |
181 | op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_SYMMETRIC); | |
182 | if (!op) { | |
183 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, | |
184 | "line %u FAILED: %s", | |
185 | __LINE__, "Failed to allocate symmetric crypto " | |
186 | "operation struct"); | |
187 | status = TEST_FAILED; | |
188 | goto error_exit; | |
189 | } | |
190 | ||
191 | sym_op = op->sym; | |
192 | ||
193 | sym_op->m_src = ibuf; | |
194 | ||
195 | if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) { | |
196 | sym_op->m_dst = obuf; | |
197 | iobuf = obuf; | |
198 | } else { | |
199 | sym_op->m_dst = NULL; | |
200 | iobuf = ibuf; | |
201 | } | |
202 | ||
203 | /* sessionless op requires allocate xform using | |
204 | * rte_crypto_op_sym_xforms_alloc(), otherwise rte_zmalloc() | |
205 | * is used | |
206 | */ | |
207 | if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) { | |
208 | uint32_t n_xforms = 0; | |
209 | ||
210 | if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) | |
211 | n_xforms++; | |
212 | if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) | |
213 | n_xforms++; | |
214 | ||
215 | if (rte_crypto_op_sym_xforms_alloc(op, n_xforms) | |
216 | == NULL) { | |
217 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " | |
218 | "FAILED: %s", __LINE__, "Failed to " | |
219 | "allocate space for crypto transforms"); | |
220 | status = TEST_FAILED; | |
221 | goto error_exit; | |
222 | } | |
223 | } else { | |
224 | cipher_xform = rte_zmalloc(NULL, | |
225 | sizeof(struct rte_crypto_sym_xform), 0); | |
226 | ||
227 | auth_xform = rte_zmalloc(NULL, | |
228 | sizeof(struct rte_crypto_sym_xform), 0); | |
229 | ||
230 | if (!cipher_xform || !auth_xform) { | |
231 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " | |
232 | "FAILED: %s", __LINE__, "Failed to " | |
233 | "allocate memory for crypto transforms"); | |
234 | status = TEST_FAILED; | |
235 | goto error_exit; | |
236 | } | |
237 | } | |
238 | ||
239 | /* preparing xform, for sessioned op, init_xform is initialized | |
240 | * here and later as param in rte_cryptodev_sym_session_create() call | |
241 | */ | |
242 | if (t->op_mask == BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN) { | |
243 | if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) { | |
244 | cipher_xform = op->sym->xform; | |
245 | auth_xform = cipher_xform->next; | |
246 | auth_xform->next = NULL; | |
247 | } else { | |
248 | cipher_xform->next = auth_xform; | |
249 | auth_xform->next = NULL; | |
250 | init_xform = cipher_xform; | |
251 | } | |
252 | } else if (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC) { | |
253 | if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) { | |
254 | auth_xform = op->sym->xform; | |
255 | cipher_xform = auth_xform->next; | |
256 | cipher_xform->next = NULL; | |
257 | } else { | |
258 | auth_xform->next = cipher_xform; | |
259 | cipher_xform->next = NULL; | |
260 | init_xform = auth_xform; | |
261 | } | |
262 | } else if ((t->op_mask == BLOCKCIPHER_TEST_OP_ENCRYPT) || | |
263 | (t->op_mask == BLOCKCIPHER_TEST_OP_DECRYPT)) { | |
264 | if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) | |
265 | cipher_xform = op->sym->xform; | |
266 | else | |
267 | init_xform = cipher_xform; | |
268 | cipher_xform->next = NULL; | |
269 | } else if ((t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_GEN) || | |
270 | (t->op_mask == BLOCKCIPHER_TEST_OP_AUTH_VERIFY)) { | |
271 | if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS) | |
272 | auth_xform = op->sym->xform; | |
273 | else | |
274 | init_xform = auth_xform; | |
275 | auth_xform->next = NULL; | |
276 | } else { | |
277 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, | |
278 | "line %u FAILED: %s", | |
279 | __LINE__, "Unrecognized operation"); | |
280 | status = TEST_FAILED; | |
281 | goto error_exit; | |
282 | } | |
283 | ||
284 | /*configure xforms & sym_op cipher and auth data*/ | |
285 | if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) { | |
286 | cipher_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER; | |
287 | cipher_xform->cipher.algo = tdata->crypto_algo; | |
288 | if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) | |
289 | cipher_xform->cipher.op = | |
290 | RTE_CRYPTO_CIPHER_OP_ENCRYPT; | |
291 | else | |
292 | cipher_xform->cipher.op = | |
293 | RTE_CRYPTO_CIPHER_OP_DECRYPT; | |
294 | cipher_xform->cipher.key.data = cipher_key; | |
295 | cipher_xform->cipher.key.length = tdata->cipher_key.len; | |
296 | ||
297 | sym_op->cipher.data.offset = tdata->iv.len; | |
298 | sym_op->cipher.data.length = tdata->ciphertext.len; | |
299 | sym_op->cipher.iv.data = rte_pktmbuf_mtod(sym_op->m_src, | |
300 | uint8_t *); | |
301 | sym_op->cipher.iv.length = tdata->iv.len; | |
302 | sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys( | |
303 | sym_op->m_src); | |
304 | } | |
305 | ||
306 | if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) { | |
307 | uint32_t auth_data_offset = 0; | |
308 | uint32_t digest_offset = tdata->ciphertext.len; | |
309 | ||
310 | if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) { | |
311 | digest_offset += tdata->iv.len; | |
312 | auth_data_offset += tdata->iv.len; | |
313 | } | |
314 | ||
315 | auth_xform->type = RTE_CRYPTO_SYM_XFORM_AUTH; | |
316 | auth_xform->auth.algo = tdata->auth_algo; | |
317 | auth_xform->auth.key.length = tdata->auth_key.len; | |
318 | auth_xform->auth.key.data = auth_key; | |
319 | auth_xform->auth.digest_length = digest_len; | |
320 | ||
321 | if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) { | |
322 | auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; | |
11fdf7f2 TL |
323 | sym_op->auth.digest.data = pktmbuf_mtod_offset |
324 | (iobuf, digest_offset); | |
7c673cae | 325 | sym_op->auth.digest.phys_addr = |
11fdf7f2 | 326 | pktmbuf_mtophys_offset(iobuf, |
7c673cae FG |
327 | digest_offset); |
328 | } else { | |
329 | auth_xform->auth.op = RTE_CRYPTO_AUTH_OP_VERIFY; | |
11fdf7f2 TL |
330 | sym_op->auth.digest.data = pktmbuf_mtod_offset |
331 | (sym_op->m_src, digest_offset); | |
7c673cae | 332 | sym_op->auth.digest.phys_addr = |
11fdf7f2 | 333 | pktmbuf_mtophys_offset(sym_op->m_src, |
7c673cae FG |
334 | digest_offset); |
335 | } | |
336 | ||
337 | sym_op->auth.data.offset = auth_data_offset; | |
338 | sym_op->auth.data.length = tdata->ciphertext.len; | |
339 | sym_op->auth.digest.length = digest_len; | |
340 | } | |
341 | ||
342 | /* create session for sessioned op */ | |
343 | if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)) { | |
344 | sess = rte_cryptodev_sym_session_create(dev_id, | |
345 | init_xform); | |
346 | if (!sess) { | |
347 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " | |
348 | "FAILED: %s", __LINE__, | |
349 | "Session creation failed"); | |
350 | status = TEST_FAILED; | |
351 | goto error_exit; | |
352 | } | |
353 | ||
354 | /* attach symmetric crypto session to crypto operations */ | |
355 | rte_crypto_op_attach_sym_session(op, sess); | |
356 | } | |
357 | ||
11fdf7f2 TL |
358 | TEST_HEXDUMP(stdout, "m_src(before):", |
359 | sym_op->m_src->buf_addr, sym_op->m_src->buf_len); | |
360 | rte_memcpy(tmp_src_buf, sym_op->m_src->buf_addr, | |
361 | sym_op->m_src->buf_len); | |
362 | if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) { | |
363 | TEST_HEXDUMP(stdout, "m_dst(before):", | |
364 | sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len); | |
365 | rte_memcpy(tmp_dst_buf, sym_op->m_dst->buf_addr, | |
366 | sym_op->m_dst->buf_len); | |
367 | } | |
368 | ||
7c673cae FG |
369 | /* Process crypto operation */ |
370 | if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { | |
371 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, | |
372 | "line %u FAILED: %s", | |
373 | __LINE__, "Error sending packet for encryption"); | |
374 | status = TEST_FAILED; | |
375 | goto error_exit; | |
376 | } | |
377 | ||
378 | op = NULL; | |
379 | ||
380 | while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0) | |
381 | rte_pause(); | |
382 | ||
383 | if (!op) { | |
384 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, | |
385 | "line %u FAILED: %s", | |
386 | __LINE__, "Failed to process sym crypto op"); | |
387 | status = TEST_FAILED; | |
388 | goto error_exit; | |
389 | } | |
390 | ||
11fdf7f2 TL |
391 | TEST_HEXDUMP(stdout, "m_src(after):", |
392 | sym_op->m_src->buf_addr, sym_op->m_src->buf_len); | |
7c673cae | 393 | if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) |
11fdf7f2 TL |
394 | TEST_HEXDUMP(stdout, "m_dst(after):", |
395 | sym_op->m_dst->buf_addr, sym_op->m_dst->buf_len); | |
7c673cae FG |
396 | |
397 | /* Verify results */ | |
398 | if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { | |
399 | if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) | |
400 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " | |
401 | "FAILED: Digest verification failed " | |
402 | "(0x%X)", __LINE__, op->status); | |
403 | else | |
404 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " | |
405 | "FAILED: Digest verification failed " | |
406 | "(0x%X)", __LINE__, op->status); | |
407 | status = TEST_FAILED; | |
408 | goto error_exit; | |
409 | } | |
410 | ||
411 | if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) { | |
11fdf7f2 | 412 | uint8_t buffer[2048]; |
7c673cae FG |
413 | const uint8_t *compare_ref; |
414 | uint32_t compare_len; | |
415 | ||
7c673cae FG |
416 | if (t->op_mask & BLOCKCIPHER_TEST_OP_ENCRYPT) { |
417 | compare_ref = tdata->ciphertext.data; | |
418 | compare_len = tdata->ciphertext.len; | |
419 | } else { | |
420 | compare_ref = tdata->plaintext.data; | |
421 | compare_len = tdata->plaintext.len; | |
422 | } | |
423 | ||
11fdf7f2 TL |
424 | if (memcmp(rte_pktmbuf_read(iobuf, tdata->iv.len, compare_len, |
425 | buffer), compare_ref, compare_len)) { | |
7c673cae FG |
426 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " |
427 | "FAILED: %s", __LINE__, | |
428 | "Crypto data not as expected"); | |
429 | status = TEST_FAILED; | |
430 | goto error_exit; | |
431 | } | |
432 | } | |
433 | ||
434 | if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) { | |
435 | uint8_t *auth_res; | |
436 | ||
437 | if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) | |
11fdf7f2 TL |
438 | auth_res = pktmbuf_mtod_offset(iobuf, |
439 | tdata->iv.len + tdata->ciphertext.len); | |
7c673cae | 440 | else |
11fdf7f2 TL |
441 | auth_res = pktmbuf_mtod_offset(iobuf, |
442 | tdata->ciphertext.len); | |
7c673cae FG |
443 | |
444 | if (memcmp(auth_res, tdata->digest.data, digest_len)) { | |
445 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "line %u " | |
446 | "FAILED: %s", __LINE__, "Generated " | |
447 | "digest data not as expected"); | |
448 | status = TEST_FAILED; | |
449 | goto error_exit; | |
450 | } | |
451 | } | |
452 | ||
11fdf7f2 TL |
453 | /* The only parts that should have changed in the buffer are |
454 | * plaintext/ciphertext and digest. | |
455 | * In OOP only the dest buffer should change. | |
456 | */ | |
457 | if (t->feature_mask & BLOCKCIPHER_TEST_FEATURE_OOP) { | |
458 | struct rte_mbuf *mbuf; | |
459 | uint8_t value; | |
460 | uint32_t head_unchanged_len = 0, changed_len = 0; | |
461 | uint32_t i; | |
462 | ||
463 | mbuf = sym_op->m_src; | |
464 | if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) { | |
465 | /* white-box test: PMDs use some of the | |
466 | * tailroom as temp storage in verify case | |
467 | */ | |
468 | head_unchanged_len = rte_pktmbuf_headroom(mbuf) | |
469 | + rte_pktmbuf_data_len(mbuf); | |
470 | changed_len = digest_len; | |
471 | } else { | |
472 | head_unchanged_len = mbuf->buf_len; | |
473 | changed_len = 0; | |
474 | } | |
475 | ||
476 | for (i = 0; i < mbuf->buf_len; i++) { | |
477 | if (i == head_unchanged_len) | |
478 | i += changed_len; | |
479 | value = *((uint8_t *)(mbuf->buf_addr)+i); | |
480 | if (value != tmp_src_buf[i]) { | |
481 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, | |
482 | "line %u FAILED: OOP src outer mbuf data (0x%x) not as expected (0x%x)", | |
483 | __LINE__, value, tmp_src_buf[i]); | |
484 | status = TEST_FAILED; | |
485 | goto error_exit; | |
486 | } | |
487 | } | |
488 | ||
489 | mbuf = sym_op->m_dst; | |
490 | if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH) { | |
491 | head_unchanged_len = rte_pktmbuf_headroom(mbuf) + | |
492 | sym_op->auth.data.offset; | |
493 | changed_len = sym_op->auth.data.length; | |
494 | if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) | |
495 | changed_len += sym_op->auth.digest.length; | |
496 | } else { | |
497 | /* cipher-only */ | |
498 | head_unchanged_len = rte_pktmbuf_headroom(mbuf) + | |
499 | sym_op->cipher.data.offset; | |
500 | changed_len = sym_op->cipher.data.length; | |
501 | } | |
502 | ||
503 | for (i = 0; i < mbuf->buf_len; i++) { | |
504 | if (i == head_unchanged_len) | |
505 | i += changed_len; | |
506 | value = *((uint8_t *)(mbuf->buf_addr)+i); | |
507 | if (value != tmp_dst_buf[i]) { | |
508 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, | |
509 | "line %u FAILED: OOP dst outer mbuf data " | |
510 | "(0x%x) not as expected (0x%x)", | |
511 | __LINE__, value, tmp_dst_buf[i]); | |
512 | status = TEST_FAILED; | |
513 | goto error_exit; | |
514 | } | |
515 | } | |
516 | } else { | |
517 | /* In-place operation */ | |
518 | struct rte_mbuf *mbuf; | |
519 | uint8_t value; | |
520 | uint32_t head_unchanged_len = 0, changed_len = 0; | |
521 | uint32_t i; | |
522 | ||
523 | mbuf = sym_op->m_src; | |
524 | if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) { | |
525 | head_unchanged_len = rte_pktmbuf_headroom(mbuf) + | |
526 | sym_op->cipher.data.offset; | |
527 | changed_len = sym_op->cipher.data.length; | |
528 | } else { | |
529 | /* auth-only */ | |
530 | head_unchanged_len = rte_pktmbuf_headroom(mbuf) + | |
531 | sym_op->auth.data.offset + | |
532 | sym_op->auth.data.length; | |
533 | changed_len = 0; | |
534 | } | |
535 | ||
536 | if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_GEN) | |
537 | changed_len += sym_op->auth.digest.length; | |
538 | ||
539 | if (t->op_mask & BLOCKCIPHER_TEST_OP_AUTH_VERIFY) { | |
540 | /* white-box test: PMDs use some of the | |
541 | * tailroom as temp storage in verify case | |
542 | */ | |
543 | if (t->op_mask & BLOCKCIPHER_TEST_OP_CIPHER) { | |
544 | /* This is simplified, not checking digest*/ | |
545 | changed_len += digest_len*2; | |
546 | } else { | |
547 | head_unchanged_len += digest_len; | |
548 | changed_len += digest_len; | |
549 | } | |
550 | } | |
551 | ||
552 | for (i = 0; i < mbuf->buf_len; i++) { | |
553 | if (i == head_unchanged_len) | |
554 | i += changed_len; | |
555 | value = *((uint8_t *)(mbuf->buf_addr)+i); | |
556 | if (value != tmp_src_buf[i]) { | |
557 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, | |
558 | "line %u FAILED: outer mbuf data (0x%x) " | |
559 | "not as expected (0x%x)", | |
560 | __LINE__, value, tmp_src_buf[i]); | |
561 | status = TEST_FAILED; | |
562 | goto error_exit; | |
563 | } | |
564 | } | |
565 | } | |
566 | ||
7c673cae FG |
567 | snprintf(test_msg, BLOCKCIPHER_TEST_MSG_LEN, "PASS"); |
568 | ||
569 | error_exit: | |
570 | if (!(t->feature_mask & BLOCKCIPHER_TEST_FEATURE_SESSIONLESS)) { | |
571 | if (sess) | |
572 | rte_cryptodev_sym_session_free(dev_id, sess); | |
573 | if (cipher_xform) | |
574 | rte_free(cipher_xform); | |
575 | if (auth_xform) | |
576 | rte_free(auth_xform); | |
577 | } | |
578 | ||
579 | if (op) | |
580 | rte_crypto_op_free(op); | |
581 | ||
582 | if (obuf) | |
583 | rte_pktmbuf_free(obuf); | |
584 | ||
585 | if (ibuf) | |
586 | rte_pktmbuf_free(ibuf); | |
587 | ||
588 | return status; | |
589 | } | |
590 | ||
591 | int | |
592 | test_blockcipher_all_tests(struct rte_mempool *mbuf_pool, | |
593 | struct rte_mempool *op_mpool, | |
594 | uint8_t dev_id, | |
595 | enum rte_cryptodev_type cryptodev_type, | |
596 | enum blockcipher_test_type test_type) | |
597 | { | |
598 | int status, overall_status = TEST_SUCCESS; | |
599 | uint32_t i, test_index = 0; | |
600 | char test_msg[BLOCKCIPHER_TEST_MSG_LEN + 1]; | |
601 | uint32_t n_test_cases = 0; | |
602 | uint32_t target_pmd_mask = 0; | |
603 | const struct blockcipher_test_case *tcs = NULL; | |
604 | ||
605 | switch (test_type) { | |
606 | case BLKCIPHER_AES_CHAIN_TYPE: | |
607 | n_test_cases = sizeof(aes_chain_test_cases) / | |
608 | sizeof(aes_chain_test_cases[0]); | |
609 | tcs = aes_chain_test_cases; | |
610 | break; | |
611 | case BLKCIPHER_AES_CIPHERONLY_TYPE: | |
612 | n_test_cases = sizeof(aes_cipheronly_test_cases) / | |
613 | sizeof(aes_cipheronly_test_cases[0]); | |
614 | tcs = aes_cipheronly_test_cases; | |
615 | break; | |
11fdf7f2 TL |
616 | case BLKCIPHER_AES_DOCSIS_TYPE: |
617 | n_test_cases = sizeof(aes_docsis_test_cases) / | |
618 | sizeof(aes_docsis_test_cases[0]); | |
619 | tcs = aes_docsis_test_cases; | |
620 | break; | |
7c673cae FG |
621 | case BLKCIPHER_3DES_CHAIN_TYPE: |
622 | n_test_cases = sizeof(triple_des_chain_test_cases) / | |
623 | sizeof(triple_des_chain_test_cases[0]); | |
624 | tcs = triple_des_chain_test_cases; | |
625 | break; | |
626 | case BLKCIPHER_3DES_CIPHERONLY_TYPE: | |
627 | n_test_cases = sizeof(triple_des_cipheronly_test_cases) / | |
628 | sizeof(triple_des_cipheronly_test_cases[0]); | |
629 | tcs = triple_des_cipheronly_test_cases; | |
630 | break; | |
11fdf7f2 TL |
631 | case BLKCIPHER_DES_CIPHERONLY_TYPE: |
632 | n_test_cases = sizeof(des_cipheronly_test_cases) / | |
633 | sizeof(des_cipheronly_test_cases[0]); | |
634 | tcs = des_cipheronly_test_cases; | |
635 | break; | |
636 | case BLKCIPHER_DES_DOCSIS_TYPE: | |
637 | n_test_cases = sizeof(des_docsis_test_cases) / | |
638 | sizeof(des_docsis_test_cases[0]); | |
639 | tcs = des_docsis_test_cases; | |
640 | break; | |
7c673cae FG |
641 | case BLKCIPHER_AUTHONLY_TYPE: |
642 | n_test_cases = sizeof(hash_test_cases) / | |
643 | sizeof(hash_test_cases[0]); | |
644 | tcs = hash_test_cases; | |
645 | break; | |
646 | default: | |
647 | break; | |
648 | } | |
649 | ||
650 | switch (cryptodev_type) { | |
651 | case RTE_CRYPTODEV_AESNI_MB_PMD: | |
652 | target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_MB; | |
653 | break; | |
654 | case RTE_CRYPTODEV_QAT_SYM_PMD: | |
655 | target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_QAT; | |
656 | break; | |
657 | case RTE_CRYPTODEV_OPENSSL_PMD: | |
658 | target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_OPENSSL; | |
659 | break; | |
11fdf7f2 TL |
660 | case RTE_CRYPTODEV_ARMV8_PMD: |
661 | target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_ARMV8; | |
662 | break; | |
663 | case RTE_CRYPTODEV_SCHEDULER_PMD: | |
664 | target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_SCHEDULER; | |
665 | break; | |
666 | case RTE_CRYPTODEV_DPAA2_SEC_PMD: | |
667 | target_pmd_mask = BLOCKCIPHER_TEST_TARGET_PMD_DPAA2_SEC; | |
668 | break; | |
7c673cae FG |
669 | default: |
670 | TEST_ASSERT(0, "Unrecognized cryptodev type"); | |
671 | break; | |
672 | } | |
673 | ||
674 | for (i = 0; i < n_test_cases; i++) { | |
675 | const struct blockcipher_test_case *tc = &tcs[i]; | |
676 | ||
677 | if (!(tc->pmd_mask & target_pmd_mask)) | |
678 | continue; | |
679 | ||
680 | status = test_blockcipher_one_case(tc, mbuf_pool, op_mpool, | |
681 | dev_id, cryptodev_type, test_msg); | |
682 | ||
683 | printf(" %u) TestCase %s %s\n", test_index ++, | |
684 | tc->test_descr, test_msg); | |
685 | ||
686 | if (status != TEST_SUCCESS) { | |
687 | if (overall_status == TEST_SUCCESS) | |
688 | overall_status = status; | |
689 | ||
690 | if (tc->feature_mask & BLOCKCIPHER_TEST_FEATURE_STOPPER) | |
691 | break; | |
692 | } | |
693 | } | |
694 | ||
695 | return overall_status; | |
696 | } |