]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | /* SPDX-License-Identifier: BSD-3-Clause |
2 | * Copyright(c) 2018 Cavium Networks | |
3 | */ | |
4 | ||
5 | #include <rte_bus_vdev.h> | |
6 | #include <rte_common.h> | |
7 | #include <rte_hexdump.h> | |
8 | #include <rte_mbuf.h> | |
9 | #include <rte_malloc.h> | |
10 | #include <rte_memcpy.h> | |
11 | #include <rte_pause.h> | |
12 | ||
13 | #include <rte_cryptodev.h> | |
14 | #include <rte_cryptodev_pmd.h> | |
15 | #include <rte_crypto.h> | |
16 | ||
17 | #include "test_cryptodev.h" | |
18 | #include "test_cryptodev_dh_test_vectors.h" | |
19 | #include "test_cryptodev_dsa_test_vectors.h" | |
20 | #include "test_cryptodev_mod_test_vectors.h" | |
21 | #include "test_cryptodev_rsa_test_vectors.h" | |
22 | #include "test_cryptodev_asym_util.h" | |
23 | #include "test.h" | |
24 | ||
25 | #define TEST_NUM_BUFS 10 | |
26 | #define TEST_NUM_SESSIONS 4 | |
27 | ||
28 | static int gbl_driver_id; | |
29 | struct crypto_testsuite_params { | |
30 | struct rte_mempool *op_mpool; | |
31 | struct rte_mempool *session_mpool; | |
32 | struct rte_cryptodev_config conf; | |
33 | struct rte_cryptodev_qp_conf qp_conf; | |
34 | uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS]; | |
35 | uint8_t valid_dev_count; | |
36 | }; | |
37 | ||
38 | struct crypto_unittest_params { | |
39 | struct rte_cryptodev_asym_session *sess; | |
40 | struct rte_crypto_op *op; | |
41 | }; | |
42 | ||
43 | static struct crypto_testsuite_params testsuite_params = { NULL }; | |
44 | ||
45 | static int | |
46 | test_rsa_sign_verify(void) | |
47 | { | |
48 | struct crypto_testsuite_params *ts_params = &testsuite_params; | |
49 | struct rte_mempool *op_mpool = ts_params->op_mpool; | |
50 | struct rte_mempool *sess_mpool = ts_params->session_mpool; | |
51 | uint8_t dev_id = ts_params->valid_devs[0]; | |
52 | struct rte_crypto_asym_op *asym_op = NULL; | |
53 | struct rte_crypto_op *op = NULL, *result_op = NULL; | |
54 | struct rte_cryptodev_asym_session *sess = NULL; | |
55 | int status = TEST_SUCCESS; | |
56 | uint8_t output_buf[TEST_DATA_SIZE] = {0}; | |
57 | uint8_t input_buf[TEST_DATA_SIZE] = {0}; | |
58 | ||
59 | sess = rte_cryptodev_asym_session_create(sess_mpool); | |
60 | ||
61 | if (!sess) { | |
62 | RTE_LOG(ERR, USER1, "line %u " | |
63 | "FAILED: %s", __LINE__, | |
64 | "Session creation failed"); | |
65 | status = TEST_FAILED; | |
66 | goto error_exit; | |
67 | } | |
68 | ||
69 | if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform, | |
70 | sess_mpool) < 0) { | |
71 | RTE_LOG(ERR, USER1, | |
72 | "line %u FAILED: %s", | |
73 | __LINE__, "unabled to config sym session"); | |
74 | status = TEST_FAILED; | |
75 | goto error_exit; | |
76 | } | |
77 | ||
78 | /* set up crypto op data structure */ | |
79 | op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); | |
80 | if (!op) { | |
81 | RTE_LOG(ERR, USER1, | |
82 | "line %u FAILED: %s", | |
83 | __LINE__, | |
84 | "Failed to allocate asymmetric crypto " | |
85 | "operation struct"); | |
86 | status = TEST_FAILED; | |
87 | goto error_exit; | |
88 | } | |
89 | ||
90 | asym_op = op->asym; | |
91 | /* Compute sign on the test vector */ | |
92 | asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN; | |
93 | ||
94 | memcpy(input_buf, &rsaplaintext.data, | |
95 | rsaplaintext.len); | |
96 | asym_op->rsa.message.data = input_buf; | |
97 | asym_op->rsa.message.length = rsaplaintext.len; | |
98 | asym_op->rsa.sign.data = output_buf; | |
99 | asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT1; | |
100 | ||
101 | debug_hexdump(stdout, "message", asym_op->rsa.message.data, | |
102 | asym_op->rsa.message.length); | |
103 | ||
104 | /* attach asymmetric crypto session to crypto operations */ | |
105 | rte_crypto_op_attach_asym_session(op, sess); | |
106 | ||
107 | RTE_LOG(DEBUG, USER1, "Process ASYM operation"); | |
108 | ||
109 | /* Process crypto operation */ | |
110 | if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { | |
111 | RTE_LOG(ERR, USER1, | |
112 | "line %u FAILED: %s", | |
113 | __LINE__, "Error sending packet for operation"); | |
114 | status = TEST_FAILED; | |
115 | goto error_exit; | |
116 | } | |
117 | ||
118 | while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) | |
119 | rte_pause(); | |
120 | ||
121 | if (result_op == NULL) { | |
122 | RTE_LOG(ERR, USER1, | |
123 | "line %u FAILED: %s", | |
124 | __LINE__, "Failed to process asym crypto op"); | |
125 | status = TEST_FAILED; | |
126 | goto error_exit; | |
127 | } | |
128 | debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data, | |
129 | asym_op->rsa.sign.length); | |
130 | asym_op = result_op->asym; | |
131 | ||
132 | /* Verify sign */ | |
133 | asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY; | |
134 | asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT2; | |
135 | ||
136 | /* Process crypto operation */ | |
137 | if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { | |
138 | RTE_LOG(ERR, USER1, | |
139 | "line %u FAILED: %s", | |
140 | __LINE__, "Error sending packet for operation"); | |
141 | status = TEST_FAILED; | |
142 | goto error_exit; | |
143 | } | |
144 | ||
145 | while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) | |
146 | rte_pause(); | |
147 | ||
148 | if (result_op == NULL) { | |
149 | RTE_LOG(ERR, USER1, | |
150 | "line %u FAILED: %s", | |
151 | __LINE__, "Failed to process asym crypto op"); | |
152 | status = TEST_FAILED; | |
153 | goto error_exit; | |
154 | } | |
155 | status = TEST_SUCCESS; | |
156 | int ret = 0; | |
157 | ret = rsa_verify(&rsaplaintext, result_op); | |
158 | if (ret) | |
159 | status = TEST_FAILED; | |
160 | ||
161 | error_exit: | |
162 | ||
163 | if (sess) { | |
164 | rte_cryptodev_asym_session_clear(dev_id, sess); | |
165 | rte_cryptodev_asym_session_free(sess); | |
166 | } | |
167 | ||
168 | if (op) | |
169 | rte_crypto_op_free(op); | |
170 | ||
171 | TEST_ASSERT_EQUAL(status, 0, "Test failed"); | |
172 | ||
173 | return status; | |
174 | } | |
175 | ||
176 | static int | |
177 | test_rsa_enc_dec(void) | |
178 | { | |
179 | struct crypto_testsuite_params *ts_params = &testsuite_params; | |
180 | struct rte_mempool *op_mpool = ts_params->op_mpool; | |
181 | struct rte_mempool *sess_mpool = ts_params->session_mpool; | |
182 | uint8_t dev_id = ts_params->valid_devs[0]; | |
183 | struct rte_crypto_asym_op *asym_op = NULL; | |
184 | struct rte_crypto_op *op = NULL, *result_op = NULL; | |
185 | struct rte_cryptodev_asym_session *sess = NULL; | |
186 | int status = TEST_SUCCESS; | |
187 | uint8_t input_buf[TEST_DATA_SIZE] = {0}; | |
188 | ||
189 | sess = rte_cryptodev_asym_session_create(sess_mpool); | |
190 | ||
191 | if (!sess) { | |
192 | RTE_LOG(ERR, USER1, "line %u " | |
193 | "FAILED: %s", __LINE__, | |
194 | "Session creation failed"); | |
195 | status = TEST_FAILED; | |
196 | goto error_exit; | |
197 | } | |
198 | ||
199 | if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform, | |
200 | sess_mpool) < 0) { | |
201 | RTE_LOG(ERR, USER1, | |
202 | "line %u FAILED: %s", | |
203 | __LINE__, "unabled to config sym session"); | |
204 | status = TEST_FAILED; | |
205 | goto error_exit; | |
206 | } | |
207 | ||
208 | /* set up crypto op data structure */ | |
209 | op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); | |
210 | if (!op) { | |
211 | RTE_LOG(ERR, USER1, | |
212 | "line %u FAILED: %s", | |
213 | __LINE__, | |
214 | "Failed to allocate asymmetric crypto " | |
215 | "operation struct"); | |
216 | status = TEST_FAILED; | |
217 | goto error_exit; | |
218 | } | |
219 | ||
220 | asym_op = op->asym; | |
221 | /*Compute encryption on the test vector */ | |
222 | asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT; | |
223 | ||
224 | memcpy(input_buf, rsaplaintext.data, | |
225 | rsaplaintext.len); | |
226 | asym_op->rsa.message.data = input_buf; | |
227 | asym_op->rsa.message.length = rsaplaintext.len; | |
228 | asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT2; | |
229 | ||
230 | debug_hexdump(stdout, "message", asym_op->rsa.message.data, | |
231 | asym_op->rsa.message.length); | |
232 | ||
233 | /* attach asymmetric crypto session to crypto operations */ | |
234 | rte_crypto_op_attach_asym_session(op, sess); | |
235 | ||
236 | RTE_LOG(DEBUG, USER1, "Process ASYM operation"); | |
237 | ||
238 | /* Process crypto operation */ | |
239 | if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { | |
240 | RTE_LOG(ERR, USER1, | |
241 | "line %u FAILED: %s", | |
242 | __LINE__, "Error sending packet for operation"); | |
243 | status = TEST_FAILED; | |
244 | goto error_exit; | |
245 | } | |
246 | ||
247 | while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) | |
248 | rte_pause(); | |
249 | ||
250 | if (result_op == NULL) { | |
251 | RTE_LOG(ERR, USER1, | |
252 | "line %u FAILED: %s", | |
253 | __LINE__, "Failed to process asym crypto op"); | |
254 | status = TEST_FAILED; | |
255 | goto error_exit; | |
256 | } | |
257 | debug_hexdump(stdout, "encrypted message", asym_op->rsa.message.data, | |
258 | asym_op->rsa.message.length); | |
259 | /* Use the resulted output as decryption Input vector*/ | |
260 | asym_op = result_op->asym; | |
261 | asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT; | |
262 | asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT1; | |
263 | ||
264 | /* Process crypto operation */ | |
265 | if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { | |
266 | RTE_LOG(ERR, USER1, | |
267 | "line %u FAILED: %s", | |
268 | __LINE__, "Error sending packet for operation"); | |
269 | status = TEST_FAILED; | |
270 | goto error_exit; | |
271 | } | |
272 | ||
273 | while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) | |
274 | rte_pause(); | |
275 | ||
276 | if (result_op == NULL) { | |
277 | RTE_LOG(ERR, USER1, | |
278 | "line %u FAILED: %s", | |
279 | __LINE__, "Failed to process asym crypto op"); | |
280 | status = TEST_FAILED; | |
281 | goto error_exit; | |
282 | } | |
283 | status = TEST_SUCCESS; | |
284 | int ret = 0; | |
285 | ret = rsa_verify(&rsaplaintext, result_op); | |
286 | if (ret) | |
287 | status = TEST_FAILED; | |
288 | ||
289 | error_exit: | |
290 | ||
291 | if (sess) { | |
292 | rte_cryptodev_asym_session_clear(dev_id, sess); | |
293 | rte_cryptodev_asym_session_free(sess); | |
294 | } | |
295 | ||
296 | if (op) | |
297 | rte_crypto_op_free(op); | |
298 | ||
299 | TEST_ASSERT_EQUAL(status, 0, "Test failed"); | |
300 | ||
301 | return status; | |
302 | } | |
303 | ||
304 | static int | |
305 | testsuite_setup(void) | |
306 | { | |
307 | struct crypto_testsuite_params *ts_params = &testsuite_params; | |
308 | struct rte_cryptodev_info info; | |
309 | uint32_t i = 0, nb_devs, dev_id; | |
310 | int ret; | |
311 | uint16_t qp_id; | |
312 | ||
313 | memset(ts_params, 0, sizeof(*ts_params)); | |
314 | ||
315 | ts_params->op_mpool = rte_crypto_op_pool_create( | |
316 | "CRYPTO_ASYM_OP_POOL", | |
317 | RTE_CRYPTO_OP_TYPE_ASYMMETRIC, | |
318 | TEST_NUM_BUFS, 0, | |
319 | 0, | |
320 | rte_socket_id()); | |
321 | if (ts_params->op_mpool == NULL) { | |
322 | RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n"); | |
323 | return TEST_FAILED; | |
324 | } | |
325 | ||
326 | /* Create an OPENSSL device if required */ | |
327 | if (gbl_driver_id == rte_cryptodev_driver_id_get( | |
328 | RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) { | |
329 | nb_devs = rte_cryptodev_device_count_by_driver( | |
330 | rte_cryptodev_driver_id_get( | |
331 | RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))); | |
332 | if (nb_devs < 1) { | |
333 | ret = rte_vdev_init( | |
334 | RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), | |
335 | NULL); | |
336 | ||
337 | TEST_ASSERT(ret == 0, "Failed to create " | |
338 | "instance of pmd : %s", | |
339 | RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); | |
340 | } | |
341 | } | |
342 | ||
343 | nb_devs = rte_cryptodev_count(); | |
344 | if (nb_devs < 1) { | |
345 | RTE_LOG(ERR, USER1, "No crypto devices found?\n"); | |
346 | return TEST_FAILED; | |
347 | } | |
348 | ||
349 | /* Create list of valid crypto devs */ | |
350 | for (i = 0; i < nb_devs; i++) { | |
351 | rte_cryptodev_info_get(i, &info); | |
352 | if (info.driver_id == gbl_driver_id) | |
353 | ts_params->valid_devs[ts_params->valid_dev_count++] = i; | |
354 | } | |
355 | ||
356 | if (ts_params->valid_dev_count < 1) | |
357 | return TEST_FAILED; | |
358 | ||
359 | /* Set up all the qps on the first of the valid devices found */ | |
360 | ||
361 | dev_id = ts_params->valid_devs[0]; | |
362 | ||
363 | rte_cryptodev_info_get(dev_id, &info); | |
364 | ||
365 | /* check if device support asymmetric, skip if not */ | |
366 | if (!(info.feature_flags & | |
367 | RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) { | |
368 | RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. " | |
369 | "Test Skipped.\n"); | |
370 | return TEST_FAILED; | |
371 | } | |
372 | ||
373 | /* configure device with num qp */ | |
374 | ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; | |
375 | ts_params->conf.socket_id = SOCKET_ID_ANY; | |
376 | TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, | |
377 | &ts_params->conf), | |
378 | "Failed to configure cryptodev %u with %u qps", | |
379 | dev_id, ts_params->conf.nb_queue_pairs); | |
380 | ||
381 | /* configure qp */ | |
382 | ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; | |
383 | for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { | |
384 | TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( | |
385 | dev_id, qp_id, &ts_params->qp_conf, | |
386 | rte_cryptodev_socket_id(dev_id), | |
387 | ts_params->session_mpool), | |
388 | "Failed to setup queue pair %u on cryptodev %u ASYM", | |
389 | qp_id, dev_id); | |
390 | } | |
391 | ||
392 | /* setup asym session pool */ | |
393 | unsigned int session_size = | |
394 | rte_cryptodev_asym_get_private_session_size(dev_id); | |
395 | /* | |
396 | * Create mempool with TEST_NUM_SESSIONS * 2, | |
397 | * to include the session headers | |
398 | */ | |
399 | ts_params->session_mpool = rte_mempool_create( | |
400 | "test_asym_sess_mp", | |
401 | TEST_NUM_SESSIONS * 2, | |
402 | session_size, | |
403 | 0, 0, NULL, NULL, NULL, | |
404 | NULL, SOCKET_ID_ANY, | |
405 | 0); | |
406 | ||
407 | TEST_ASSERT_NOT_NULL(ts_params->session_mpool, | |
408 | "session mempool allocation failed"); | |
409 | ||
410 | return TEST_SUCCESS; | |
411 | } | |
412 | ||
413 | static void | |
414 | testsuite_teardown(void) | |
415 | { | |
416 | struct crypto_testsuite_params *ts_params = &testsuite_params; | |
417 | ||
418 | if (ts_params->op_mpool != NULL) { | |
419 | RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", | |
420 | rte_mempool_avail_count(ts_params->op_mpool)); | |
421 | } | |
422 | ||
423 | /* Free session mempools */ | |
424 | if (ts_params->session_mpool != NULL) { | |
425 | rte_mempool_free(ts_params->session_mpool); | |
426 | ts_params->session_mpool = NULL; | |
427 | } | |
428 | } | |
429 | ||
430 | static int | |
431 | ut_setup(void) | |
432 | { | |
433 | struct crypto_testsuite_params *ts_params = &testsuite_params; | |
434 | ||
435 | uint16_t qp_id; | |
436 | ||
437 | /* Reconfigure device to default parameters */ | |
438 | ts_params->conf.socket_id = SOCKET_ID_ANY; | |
439 | ||
440 | TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], | |
441 | &ts_params->conf), | |
442 | "Failed to configure cryptodev %u", | |
443 | ts_params->valid_devs[0]); | |
444 | ||
445 | for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { | |
446 | TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( | |
447 | ts_params->valid_devs[0], qp_id, | |
448 | &ts_params->qp_conf, | |
449 | rte_cryptodev_socket_id(ts_params->valid_devs[0]), | |
450 | ts_params->session_mpool), | |
451 | "Failed to setup queue pair %u on cryptodev %u", | |
452 | qp_id, ts_params->valid_devs[0]); | |
453 | } | |
454 | ||
455 | rte_cryptodev_stats_reset(ts_params->valid_devs[0]); | |
456 | ||
457 | /* Start the device */ | |
458 | TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), | |
459 | "Failed to start cryptodev %u", | |
460 | ts_params->valid_devs[0]); | |
461 | ||
462 | return TEST_SUCCESS; | |
463 | } | |
464 | ||
465 | static void | |
466 | ut_teardown(void) | |
467 | { | |
468 | struct crypto_testsuite_params *ts_params = &testsuite_params; | |
469 | struct rte_cryptodev_stats stats; | |
470 | ||
471 | rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats); | |
472 | ||
473 | /* Stop the device */ | |
474 | rte_cryptodev_stop(ts_params->valid_devs[0]); | |
475 | } | |
476 | ||
477 | static inline void print_asym_capa( | |
478 | const struct rte_cryptodev_asymmetric_xform_capability *capa) | |
479 | { | |
480 | int i = 0; | |
481 | ||
482 | printf("\nxform type: %s\n===================\n", | |
483 | rte_crypto_asym_xform_strings[capa->xform_type]); | |
484 | printf("operation supported -"); | |
485 | ||
486 | for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) { | |
487 | /* check supported operations */ | |
488 | if (rte_cryptodev_asym_xform_capability_check_optype(capa, i)) | |
489 | printf(" %s", | |
490 | rte_crypto_asym_op_strings[i]); | |
491 | } | |
492 | switch (capa->xform_type) { | |
493 | case RTE_CRYPTO_ASYM_XFORM_RSA: | |
494 | case RTE_CRYPTO_ASYM_XFORM_MODINV: | |
495 | case RTE_CRYPTO_ASYM_XFORM_MODEX: | |
496 | case RTE_CRYPTO_ASYM_XFORM_DH: | |
497 | case RTE_CRYPTO_ASYM_XFORM_DSA: | |
498 | printf(" modlen: min %d max %d increment %d\n", | |
499 | capa->modlen.min, | |
500 | capa->modlen.max, | |
501 | capa->modlen.increment); | |
502 | break; | |
503 | default: | |
504 | break; | |
505 | } | |
506 | } | |
507 | ||
508 | static int | |
509 | test_capability(void) | |
510 | { | |
511 | struct crypto_testsuite_params *ts_params = &testsuite_params; | |
512 | uint8_t dev_id = ts_params->valid_devs[0]; | |
513 | struct rte_cryptodev_info dev_info; | |
514 | const struct rte_cryptodev_capabilities *dev_capa; | |
515 | int i = 0; | |
516 | struct rte_cryptodev_asym_capability_idx idx; | |
517 | const struct rte_cryptodev_asymmetric_xform_capability *capa; | |
518 | ||
519 | rte_cryptodev_info_get(dev_id, &dev_info); | |
520 | if (!(dev_info.feature_flags & | |
521 | RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) { | |
522 | RTE_LOG(INFO, USER1, | |
523 | "Device doesn't support asymmetric. Test Skipped\n"); | |
524 | return TEST_SUCCESS; | |
525 | } | |
526 | ||
527 | /* print xform capability */ | |
528 | for (i = 0; | |
529 | dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED; | |
530 | i++) { | |
531 | dev_capa = &(dev_info.capabilities[i]); | |
532 | if (dev_info.capabilities[i].op == | |
533 | RTE_CRYPTO_OP_TYPE_ASYMMETRIC) { | |
534 | idx.type = dev_capa->asym.xform_capa.xform_type; | |
535 | ||
536 | capa = rte_cryptodev_asym_capability_get(dev_id, | |
537 | (const struct | |
538 | rte_cryptodev_asym_capability_idx *) &idx); | |
539 | print_asym_capa(capa); | |
540 | } | |
541 | } | |
542 | return TEST_SUCCESS; | |
543 | } | |
544 | ||
545 | static int | |
546 | test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm) | |
547 | { | |
548 | struct crypto_testsuite_params *ts_params = &testsuite_params; | |
549 | struct rte_mempool *op_mpool = ts_params->op_mpool; | |
550 | struct rte_mempool *sess_mpool = ts_params->session_mpool; | |
551 | uint8_t dev_id = ts_params->valid_devs[0]; | |
552 | struct rte_crypto_asym_op *asym_op = NULL; | |
553 | struct rte_crypto_op *op = NULL, *result_op = NULL; | |
554 | struct rte_cryptodev_asym_session *sess = NULL; | |
555 | int status = TEST_SUCCESS; | |
556 | uint8_t output[TEST_DH_MOD_LEN]; | |
557 | struct rte_crypto_asym_xform xform = *xfrm; | |
558 | uint8_t peer[] = "01234567890123456789012345678901234567890123456789"; | |
559 | ||
560 | sess = rte_cryptodev_asym_session_create(sess_mpool); | |
561 | if (sess == NULL) { | |
562 | RTE_LOG(ERR, USER1, | |
563 | "line %u FAILED: %s", __LINE__, | |
564 | "Session creation failed"); | |
565 | status = TEST_FAILED; | |
566 | goto error_exit; | |
567 | } | |
568 | /* set up crypto op data structure */ | |
569 | op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); | |
570 | if (!op) { | |
571 | RTE_LOG(ERR, USER1, | |
572 | "line %u FAILED: %s", | |
573 | __LINE__, "Failed to allocate asymmetric crypto " | |
574 | "operation struct"); | |
575 | status = TEST_FAILED; | |
576 | goto error_exit; | |
577 | } | |
578 | asym_op = op->asym; | |
579 | ||
580 | /* Setup a xform and op to generate private key only */ | |
581 | xform.dh.type = RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE; | |
582 | xform.next = NULL; | |
583 | asym_op->dh.priv_key.data = dh_test_params.priv_key.data; | |
584 | asym_op->dh.priv_key.length = dh_test_params.priv_key.length; | |
585 | asym_op->dh.pub_key.data = (uint8_t *)peer; | |
586 | asym_op->dh.pub_key.length = sizeof(peer); | |
587 | asym_op->dh.shared_secret.data = output; | |
588 | asym_op->dh.shared_secret.length = sizeof(output); | |
589 | ||
590 | if (rte_cryptodev_asym_session_init(dev_id, sess, &xform, | |
591 | sess_mpool) < 0) { | |
592 | RTE_LOG(ERR, USER1, | |
593 | "line %u FAILED: %s", | |
594 | __LINE__, "unabled to config sym session"); | |
595 | status = TEST_FAILED; | |
596 | goto error_exit; | |
597 | } | |
598 | ||
599 | /* attach asymmetric crypto session to crypto operations */ | |
600 | rte_crypto_op_attach_asym_session(op, sess); | |
601 | ||
602 | RTE_LOG(DEBUG, USER1, "Process ASYM operation"); | |
603 | ||
604 | /* Process crypto operation */ | |
605 | if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { | |
606 | RTE_LOG(ERR, USER1, | |
607 | "line %u FAILED: %s", | |
608 | __LINE__, "Error sending packet for operation"); | |
609 | status = TEST_FAILED; | |
610 | goto error_exit; | |
611 | } | |
612 | ||
613 | while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) | |
614 | rte_pause(); | |
615 | ||
616 | if (result_op == NULL) { | |
617 | RTE_LOG(ERR, USER1, | |
618 | "line %u FAILED: %s", | |
619 | __LINE__, "Failed to process asym crypto op"); | |
620 | status = TEST_FAILED; | |
621 | goto error_exit; | |
622 | } | |
623 | ||
624 | debug_hexdump(stdout, "shared secret:", | |
625 | asym_op->dh.shared_secret.data, | |
626 | asym_op->dh.shared_secret.length); | |
627 | ||
628 | error_exit: | |
629 | if (sess != NULL) { | |
630 | rte_cryptodev_asym_session_clear(dev_id, sess); | |
631 | rte_cryptodev_asym_session_free(sess); | |
632 | } | |
633 | if (op != NULL) | |
634 | rte_crypto_op_free(op); | |
635 | return status; | |
636 | } | |
637 | ||
638 | static int | |
639 | test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm) | |
640 | { | |
641 | struct crypto_testsuite_params *ts_params = &testsuite_params; | |
642 | struct rte_mempool *op_mpool = ts_params->op_mpool; | |
643 | struct rte_mempool *sess_mpool = ts_params->session_mpool; | |
644 | uint8_t dev_id = ts_params->valid_devs[0]; | |
645 | struct rte_crypto_asym_op *asym_op = NULL; | |
646 | struct rte_crypto_op *op = NULL, *result_op = NULL; | |
647 | struct rte_cryptodev_asym_session *sess = NULL; | |
648 | int status = TEST_SUCCESS; | |
649 | uint8_t output[TEST_DH_MOD_LEN]; | |
650 | struct rte_crypto_asym_xform xform = *xfrm; | |
651 | ||
652 | sess = rte_cryptodev_asym_session_create(sess_mpool); | |
653 | if (sess == NULL) { | |
654 | RTE_LOG(ERR, USER1, | |
655 | "line %u FAILED: %s", __LINE__, | |
656 | "Session creation failed"); | |
657 | status = TEST_FAILED; | |
658 | goto error_exit; | |
659 | } | |
660 | /* set up crypto op data structure */ | |
661 | op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); | |
662 | if (!op) { | |
663 | RTE_LOG(ERR, USER1, | |
664 | "line %u FAILED: %s", | |
665 | __LINE__, "Failed to allocate asymmetric crypto " | |
666 | "operation struct"); | |
667 | status = TEST_FAILED; | |
668 | goto error_exit; | |
669 | } | |
670 | asym_op = op->asym; | |
671 | ||
672 | /* Setup a xform and op to generate private key only */ | |
673 | xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE; | |
674 | xform.next = NULL; | |
675 | asym_op->dh.priv_key.data = output; | |
676 | asym_op->dh.priv_key.length = sizeof(output); | |
677 | ||
678 | if (rte_cryptodev_asym_session_init(dev_id, sess, &xform, | |
679 | sess_mpool) < 0) { | |
680 | RTE_LOG(ERR, USER1, | |
681 | "line %u FAILED: %s", | |
682 | __LINE__, "unabled to config sym session"); | |
683 | status = TEST_FAILED; | |
684 | goto error_exit; | |
685 | } | |
686 | ||
687 | /* attach asymmetric crypto session to crypto operations */ | |
688 | rte_crypto_op_attach_asym_session(op, sess); | |
689 | ||
690 | RTE_LOG(DEBUG, USER1, "Process ASYM operation"); | |
691 | ||
692 | /* Process crypto operation */ | |
693 | if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { | |
694 | RTE_LOG(ERR, USER1, | |
695 | "line %u FAILED: %s", | |
696 | __LINE__, "Error sending packet for operation"); | |
697 | status = TEST_FAILED; | |
698 | goto error_exit; | |
699 | } | |
700 | ||
701 | while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) | |
702 | rte_pause(); | |
703 | ||
704 | if (result_op == NULL) { | |
705 | RTE_LOG(ERR, USER1, | |
706 | "line %u FAILED: %s", | |
707 | __LINE__, "Failed to process asym crypto op"); | |
708 | status = TEST_FAILED; | |
709 | goto error_exit; | |
710 | } | |
711 | ||
712 | debug_hexdump(stdout, "private key:", | |
713 | asym_op->dh.priv_key.data, | |
714 | asym_op->dh.priv_key.length); | |
715 | ||
716 | ||
717 | error_exit: | |
718 | if (sess != NULL) { | |
719 | rte_cryptodev_asym_session_clear(dev_id, sess); | |
720 | rte_cryptodev_asym_session_free(sess); | |
721 | } | |
722 | if (op != NULL) | |
723 | rte_crypto_op_free(op); | |
724 | ||
725 | return status; | |
726 | } | |
727 | ||
728 | ||
729 | static int | |
730 | test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm) | |
731 | { | |
732 | struct crypto_testsuite_params *ts_params = &testsuite_params; | |
733 | struct rte_mempool *op_mpool = ts_params->op_mpool; | |
734 | struct rte_mempool *sess_mpool = ts_params->session_mpool; | |
735 | uint8_t dev_id = ts_params->valid_devs[0]; | |
736 | struct rte_crypto_asym_op *asym_op = NULL; | |
737 | struct rte_crypto_op *op = NULL, *result_op = NULL; | |
738 | struct rte_cryptodev_asym_session *sess = NULL; | |
739 | int status = TEST_SUCCESS; | |
740 | uint8_t output[TEST_DH_MOD_LEN]; | |
741 | struct rte_crypto_asym_xform xform = *xfrm; | |
742 | ||
743 | sess = rte_cryptodev_asym_session_create(sess_mpool); | |
744 | if (sess == NULL) { | |
745 | RTE_LOG(ERR, USER1, | |
746 | "line %u FAILED: %s", __LINE__, | |
747 | "Session creation failed"); | |
748 | status = TEST_FAILED; | |
749 | goto error_exit; | |
750 | } | |
751 | /* set up crypto op data structure */ | |
752 | op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); | |
753 | if (!op) { | |
754 | RTE_LOG(ERR, USER1, | |
755 | "line %u FAILED: %s", | |
756 | __LINE__, "Failed to allocate asymmetric crypto " | |
757 | "operation struct"); | |
758 | status = TEST_FAILED; | |
759 | goto error_exit; | |
760 | } | |
761 | asym_op = op->asym; | |
762 | /* Setup a xform chain to generate public key | |
763 | * using test private key | |
764 | * | |
765 | */ | |
766 | xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE; | |
767 | xform.next = NULL; | |
768 | ||
769 | asym_op->dh.pub_key.data = output; | |
770 | asym_op->dh.pub_key.length = sizeof(output); | |
771 | /* load pre-defined private key */ | |
772 | asym_op->dh.priv_key.data = rte_malloc(NULL, | |
773 | dh_test_params.priv_key.length, | |
774 | 0); | |
775 | asym_op->dh.priv_key = dh_test_params.priv_key; | |
776 | ||
777 | if (rte_cryptodev_asym_session_init(dev_id, sess, &xform, | |
778 | sess_mpool) < 0) { | |
779 | RTE_LOG(ERR, USER1, | |
780 | "line %u FAILED: %s", | |
781 | __LINE__, "unabled to config sym session"); | |
782 | status = TEST_FAILED; | |
783 | goto error_exit; | |
784 | } | |
785 | ||
786 | /* attach asymmetric crypto session to crypto operations */ | |
787 | rte_crypto_op_attach_asym_session(op, sess); | |
788 | ||
789 | RTE_LOG(DEBUG, USER1, "Process ASYM operation"); | |
790 | ||
791 | /* Process crypto operation */ | |
792 | if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { | |
793 | RTE_LOG(ERR, USER1, | |
794 | "line %u FAILED: %s", | |
795 | __LINE__, "Error sending packet for operation"); | |
796 | status = TEST_FAILED; | |
797 | goto error_exit; | |
798 | } | |
799 | ||
800 | while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) | |
801 | rte_pause(); | |
802 | ||
803 | if (result_op == NULL) { | |
804 | RTE_LOG(ERR, USER1, | |
805 | "line %u FAILED: %s", | |
806 | __LINE__, "Failed to process asym crypto op"); | |
807 | status = TEST_FAILED; | |
808 | goto error_exit; | |
809 | } | |
810 | ||
811 | debug_hexdump(stdout, "pub key:", | |
812 | asym_op->dh.pub_key.data, asym_op->dh.pub_key.length); | |
813 | ||
814 | debug_hexdump(stdout, "priv key:", | |
815 | asym_op->dh.priv_key.data, asym_op->dh.priv_key.length); | |
816 | ||
817 | error_exit: | |
818 | if (sess != NULL) { | |
819 | rte_cryptodev_asym_session_clear(dev_id, sess); | |
820 | rte_cryptodev_asym_session_free(sess); | |
821 | } | |
822 | if (op != NULL) | |
823 | rte_crypto_op_free(op); | |
824 | ||
825 | return status; | |
826 | } | |
827 | ||
828 | static int | |
829 | test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm) | |
830 | { | |
831 | struct crypto_testsuite_params *ts_params = &testsuite_params; | |
832 | struct rte_mempool *op_mpool = ts_params->op_mpool; | |
833 | struct rte_mempool *sess_mpool = ts_params->session_mpool; | |
834 | uint8_t dev_id = ts_params->valid_devs[0]; | |
835 | struct rte_crypto_asym_op *asym_op = NULL; | |
836 | struct rte_crypto_op *op = NULL, *result_op = NULL; | |
837 | struct rte_cryptodev_asym_session *sess = NULL; | |
838 | int status = TEST_SUCCESS; | |
839 | uint8_t out_pub_key[TEST_DH_MOD_LEN]; | |
840 | uint8_t out_prv_key[TEST_DH_MOD_LEN]; | |
841 | struct rte_crypto_asym_xform pub_key_xform; | |
842 | struct rte_crypto_asym_xform xform = *xfrm; | |
843 | ||
844 | sess = rte_cryptodev_asym_session_create(sess_mpool); | |
845 | if (sess == NULL) { | |
846 | RTE_LOG(ERR, USER1, | |
847 | "line %u FAILED: %s", __LINE__, | |
848 | "Session creation failed"); | |
849 | status = TEST_FAILED; | |
850 | goto error_exit; | |
851 | } | |
852 | ||
853 | /* set up crypto op data structure */ | |
854 | op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); | |
855 | if (!op) { | |
856 | RTE_LOG(ERR, USER1, | |
857 | "line %u FAILED: %s", | |
858 | __LINE__, "Failed to allocate asymmetric crypto " | |
859 | "operation struct"); | |
860 | status = TEST_FAILED; | |
861 | goto error_exit; | |
862 | } | |
863 | asym_op = op->asym; | |
864 | /* Setup a xform chain to generate | |
865 | * private key first followed by | |
866 | * public key | |
867 | */xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE; | |
868 | pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH; | |
869 | pub_key_xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE; | |
870 | xform.next = &pub_key_xform; | |
871 | ||
872 | asym_op->dh.pub_key.data = out_pub_key; | |
873 | asym_op->dh.pub_key.length = sizeof(out_pub_key); | |
874 | asym_op->dh.priv_key.data = out_prv_key; | |
875 | asym_op->dh.priv_key.length = sizeof(out_prv_key); | |
876 | if (rte_cryptodev_asym_session_init(dev_id, sess, &xform, | |
877 | sess_mpool) < 0) { | |
878 | RTE_LOG(ERR, USER1, | |
879 | "line %u FAILED: %s", | |
880 | __LINE__, "unabled to config sym session"); | |
881 | status = TEST_FAILED; | |
882 | goto error_exit; | |
883 | } | |
884 | ||
885 | /* attach asymmetric crypto session to crypto operations */ | |
886 | rte_crypto_op_attach_asym_session(op, sess); | |
887 | ||
888 | RTE_LOG(DEBUG, USER1, "Process ASYM operation"); | |
889 | ||
890 | /* Process crypto operation */ | |
891 | if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { | |
892 | RTE_LOG(ERR, USER1, | |
893 | "line %u FAILED: %s", | |
894 | __LINE__, "Error sending packet for operation"); | |
895 | status = TEST_FAILED; | |
896 | goto error_exit; | |
897 | } | |
898 | ||
899 | while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) | |
900 | rte_pause(); | |
901 | ||
902 | if (result_op == NULL) { | |
903 | RTE_LOG(ERR, USER1, | |
904 | "line %u FAILED: %s", | |
905 | __LINE__, "Failed to process asym crypto op"); | |
906 | status = TEST_FAILED; | |
907 | goto error_exit; | |
908 | } | |
909 | debug_hexdump(stdout, "priv key:", | |
910 | out_prv_key, asym_op->dh.priv_key.length); | |
911 | debug_hexdump(stdout, "pub key:", | |
912 | out_pub_key, asym_op->dh.pub_key.length); | |
913 | ||
914 | error_exit: | |
915 | if (sess != NULL) { | |
916 | rte_cryptodev_asym_session_clear(dev_id, sess); | |
917 | rte_cryptodev_asym_session_free(sess); | |
918 | } | |
919 | if (op != NULL) | |
920 | rte_crypto_op_free(op); | |
921 | ||
922 | return status; | |
923 | } | |
924 | ||
925 | static int | |
926 | test_mod_inv(void) | |
927 | { | |
928 | struct crypto_testsuite_params *ts_params = &testsuite_params; | |
929 | struct rte_mempool *op_mpool = ts_params->op_mpool; | |
930 | struct rte_mempool *sess_mpool = ts_params->session_mpool; | |
931 | uint8_t dev_id = ts_params->valid_devs[0]; | |
932 | struct rte_crypto_asym_op *asym_op = NULL; | |
933 | struct rte_crypto_op *op = NULL, *result_op = NULL; | |
934 | struct rte_cryptodev_asym_session *sess = NULL; | |
935 | int status = TEST_SUCCESS; | |
936 | struct rte_cryptodev_asym_capability_idx cap_idx; | |
937 | const struct rte_cryptodev_asymmetric_xform_capability *capability; | |
938 | uint8_t input[TEST_DATA_SIZE] = {0}; | |
939 | int ret = 0; | |
940 | ||
941 | if (rte_cryptodev_asym_get_xform_enum( | |
942 | &modinv_xform.xform_type, "modinv") < 0) { | |
943 | RTE_LOG(ERR, USER1, | |
944 | "Invalid ASYNC algorithm specified\n"); | |
945 | return -1; | |
946 | } | |
947 | ||
948 | cap_idx.type = modinv_xform.xform_type; | |
949 | capability = rte_cryptodev_asym_capability_get(dev_id, | |
950 | &cap_idx); | |
951 | ||
952 | if (rte_cryptodev_asym_xform_capability_check_modlen( | |
953 | capability, | |
954 | modinv_xform.modinv.modulus.length)) { | |
955 | RTE_LOG(ERR, USER1, | |
956 | "Invalid MODULOUS length specified\n"); | |
957 | return -1; | |
958 | } | |
959 | ||
960 | sess = rte_cryptodev_asym_session_create(sess_mpool); | |
961 | if (!sess) { | |
962 | RTE_LOG(ERR, USER1, "line %u " | |
963 | "FAILED: %s", __LINE__, | |
964 | "Session creation failed"); | |
965 | status = TEST_FAILED; | |
966 | goto error_exit; | |
967 | } | |
968 | ||
969 | if (rte_cryptodev_asym_session_init(dev_id, sess, &modinv_xform, | |
970 | sess_mpool) < 0) { | |
971 | RTE_LOG(ERR, USER1, | |
972 | "line %u FAILED: %s", | |
973 | __LINE__, "unabled to config sym session"); | |
974 | status = TEST_FAILED; | |
975 | goto error_exit; | |
976 | } | |
977 | ||
978 | /* generate crypto op data structure */ | |
979 | op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); | |
980 | if (!op) { | |
981 | RTE_LOG(ERR, USER1, | |
982 | "line %u FAILED: %s", | |
983 | __LINE__, "Failed to allocate asymmetric crypto " | |
984 | "operation struct"); | |
985 | status = TEST_FAILED; | |
986 | goto error_exit; | |
987 | } | |
988 | ||
989 | asym_op = op->asym; | |
990 | memcpy(input, base, sizeof(base)); | |
991 | asym_op->modinv.base.data = input; | |
992 | asym_op->modinv.base.length = sizeof(base); | |
993 | ||
994 | /* attach asymmetric crypto session to crypto operations */ | |
995 | rte_crypto_op_attach_asym_session(op, sess); | |
996 | ||
997 | RTE_LOG(DEBUG, USER1, "Process ASYM operation"); | |
998 | ||
999 | /* Process crypto operation */ | |
1000 | if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { | |
1001 | RTE_LOG(ERR, USER1, | |
1002 | "line %u FAILED: %s", | |
1003 | __LINE__, "Error sending packet for operation"); | |
1004 | status = TEST_FAILED; | |
1005 | goto error_exit; | |
1006 | } | |
1007 | ||
1008 | while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) | |
1009 | rte_pause(); | |
1010 | ||
1011 | if (result_op == NULL) { | |
1012 | RTE_LOG(ERR, USER1, | |
1013 | "line %u FAILED: %s", | |
1014 | __LINE__, "Failed to process asym crypto op"); | |
1015 | status = TEST_FAILED; | |
1016 | goto error_exit; | |
1017 | } | |
1018 | ||
1019 | ret = verify_modinv(mod_inv, result_op); | |
1020 | if (ret) { | |
1021 | RTE_LOG(ERR, USER1, | |
1022 | "operation verification failed\n"); | |
1023 | status = TEST_FAILED; | |
1024 | } | |
1025 | ||
1026 | error_exit: | |
1027 | if (sess) { | |
1028 | rte_cryptodev_asym_session_clear(dev_id, sess); | |
1029 | rte_cryptodev_asym_session_free(sess); | |
1030 | } | |
1031 | ||
1032 | if (op) | |
1033 | rte_crypto_op_free(op); | |
1034 | ||
1035 | TEST_ASSERT_EQUAL(status, 0, "Test failed"); | |
1036 | ||
1037 | return status; | |
1038 | } | |
1039 | ||
1040 | static int | |
1041 | test_mod_exp(void) | |
1042 | { | |
1043 | struct crypto_testsuite_params *ts_params = &testsuite_params; | |
1044 | struct rte_mempool *op_mpool = ts_params->op_mpool; | |
1045 | struct rte_mempool *sess_mpool = ts_params->session_mpool; | |
1046 | uint8_t dev_id = ts_params->valid_devs[0]; | |
1047 | struct rte_crypto_asym_op *asym_op = NULL; | |
1048 | struct rte_crypto_op *op = NULL, *result_op = NULL; | |
1049 | struct rte_cryptodev_asym_session *sess = NULL; | |
1050 | int status = TEST_SUCCESS; | |
1051 | struct rte_cryptodev_asym_capability_idx cap_idx; | |
1052 | const struct rte_cryptodev_asymmetric_xform_capability *capability; | |
1053 | uint8_t input[TEST_DATA_SIZE] = {0}; | |
1054 | int ret = 0; | |
1055 | ||
1056 | if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type, | |
1057 | "modexp") | |
1058 | < 0) { | |
1059 | RTE_LOG(ERR, USER1, | |
1060 | "Invalid ASYNC algorithm specified\n"); | |
1061 | return -1; | |
1062 | } | |
1063 | ||
1064 | /* check for modlen capability */ | |
1065 | cap_idx.type = modex_xform.xform_type; | |
1066 | capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx); | |
1067 | ||
1068 | if (rte_cryptodev_asym_xform_capability_check_modlen( | |
1069 | capability, modex_xform.modex.modulus.length)) { | |
1070 | RTE_LOG(ERR, USER1, | |
1071 | "Invalid MODULOUS length specified\n"); | |
1072 | return -1; | |
1073 | } | |
1074 | ||
1075 | /* generate crypto op data structure */ | |
1076 | op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); | |
1077 | if (!op) { | |
1078 | RTE_LOG(ERR, USER1, | |
1079 | "line %u FAILED: %s", | |
1080 | __LINE__, "Failed to allocate asymmetric crypto " | |
1081 | "operation struct"); | |
1082 | status = TEST_FAILED; | |
1083 | goto error_exit; | |
1084 | } | |
1085 | ||
1086 | sess = rte_cryptodev_asym_session_create(sess_mpool); | |
1087 | if (!sess) { | |
1088 | RTE_LOG(ERR, USER1, | |
1089 | "line %u " | |
1090 | "FAILED: %s", __LINE__, | |
1091 | "Session creation failed"); | |
1092 | status = TEST_FAILED; | |
1093 | goto error_exit; | |
1094 | } | |
1095 | ||
1096 | if (rte_cryptodev_asym_session_init(dev_id, sess, &modex_xform, | |
1097 | sess_mpool) < 0) { | |
1098 | RTE_LOG(ERR, USER1, | |
1099 | "line %u FAILED: %s", | |
1100 | __LINE__, "unabled to config sym session"); | |
1101 | status = TEST_FAILED; | |
1102 | goto error_exit; | |
1103 | } | |
1104 | ||
1105 | asym_op = op->asym; | |
1106 | memcpy(input, base, sizeof(base)); | |
1107 | asym_op->modex.base.data = input; | |
1108 | asym_op->modex.base.length = sizeof(base); | |
1109 | /* attach asymmetric crypto session to crypto operations */ | |
1110 | rte_crypto_op_attach_asym_session(op, sess); | |
1111 | ||
1112 | RTE_LOG(DEBUG, USER1, "Process ASYM operation"); | |
1113 | /* Process crypto operation */ | |
1114 | if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { | |
1115 | RTE_LOG(ERR, USER1, | |
1116 | "line %u FAILED: %s", | |
1117 | __LINE__, "Error sending packet for operation"); | |
1118 | status = TEST_FAILED; | |
1119 | goto error_exit; | |
1120 | } | |
1121 | ||
1122 | while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) | |
1123 | rte_pause(); | |
1124 | ||
1125 | if (result_op == NULL) { | |
1126 | RTE_LOG(ERR, USER1, | |
1127 | "line %u FAILED: %s", | |
1128 | __LINE__, "Failed to process asym crypto op"); | |
1129 | status = TEST_FAILED; | |
1130 | goto error_exit; | |
1131 | } | |
1132 | ||
1133 | ret = verify_modexp(mod_exp, result_op); | |
1134 | if (ret) { | |
1135 | RTE_LOG(ERR, USER1, | |
1136 | "operation verification failed\n"); | |
1137 | status = TEST_FAILED; | |
1138 | } | |
1139 | ||
1140 | error_exit: | |
1141 | if (sess != NULL) { | |
1142 | rte_cryptodev_asym_session_clear(dev_id, sess); | |
1143 | rte_cryptodev_asym_session_free(sess); | |
1144 | } | |
1145 | ||
1146 | if (op != NULL) | |
1147 | rte_crypto_op_free(op); | |
1148 | ||
1149 | TEST_ASSERT_EQUAL(status, 0, "Test failed"); | |
1150 | ||
1151 | return status; | |
1152 | } | |
1153 | ||
1154 | static int | |
1155 | test_dh_keygenration(void) | |
1156 | { | |
1157 | int status; | |
1158 | ||
1159 | debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length); | |
1160 | debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length); | |
1161 | debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data, | |
1162 | dh_test_params.priv_key.length); | |
1163 | ||
1164 | RTE_LOG(INFO, USER1, | |
1165 | "Test Public and Private key pair generation\n"); | |
1166 | ||
1167 | status = test_dh_gen_kp(&dh_xform); | |
1168 | TEST_ASSERT_EQUAL(status, 0, "Test failed"); | |
1169 | ||
1170 | RTE_LOG(INFO, USER1, | |
1171 | "Test Public Key Generation using pre-defined priv key\n"); | |
1172 | ||
1173 | status = test_dh_gen_pub_key(&dh_xform); | |
1174 | TEST_ASSERT_EQUAL(status, 0, "Test failed"); | |
1175 | ||
1176 | RTE_LOG(INFO, USER1, | |
1177 | "Test Private Key Generation only\n"); | |
1178 | ||
1179 | status = test_dh_gen_priv_key(&dh_xform); | |
1180 | TEST_ASSERT_EQUAL(status, 0, "Test failed"); | |
1181 | ||
1182 | RTE_LOG(INFO, USER1, | |
1183 | "Test shared secret compute\n"); | |
1184 | ||
1185 | status = test_dh_gen_shared_sec(&dh_xform); | |
1186 | TEST_ASSERT_EQUAL(status, 0, "Test failed"); | |
1187 | ||
1188 | return status; | |
1189 | } | |
1190 | ||
1191 | static int | |
1192 | test_dsa_sign(void) | |
1193 | { | |
1194 | struct crypto_testsuite_params *ts_params = &testsuite_params; | |
1195 | struct rte_mempool *op_mpool = ts_params->op_mpool; | |
1196 | struct rte_mempool *sess_mpool = ts_params->session_mpool; | |
1197 | uint8_t dev_id = ts_params->valid_devs[0]; | |
1198 | struct rte_crypto_asym_op *asym_op = NULL; | |
1199 | struct rte_crypto_op *op = NULL, *result_op = NULL; | |
1200 | struct rte_cryptodev_asym_session *sess = NULL; | |
1201 | int status = TEST_SUCCESS; | |
1202 | uint8_t r[TEST_DH_MOD_LEN]; | |
1203 | uint8_t s[TEST_DH_MOD_LEN]; | |
1204 | uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344"; | |
1205 | ||
1206 | sess = rte_cryptodev_asym_session_create(sess_mpool); | |
1207 | if (sess == NULL) { | |
1208 | RTE_LOG(ERR, USER1, | |
1209 | "line %u FAILED: %s", __LINE__, | |
1210 | "Session creation failed"); | |
1211 | status = TEST_FAILED; | |
1212 | goto error_exit; | |
1213 | } | |
1214 | /* set up crypto op data structure */ | |
1215 | op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); | |
1216 | if (!op) { | |
1217 | RTE_LOG(ERR, USER1, | |
1218 | "line %u FAILED: %s", | |
1219 | __LINE__, "Failed to allocate asymmetric crypto " | |
1220 | "operation struct"); | |
1221 | status = TEST_FAILED; | |
1222 | goto error_exit; | |
1223 | } | |
1224 | asym_op = op->asym; | |
1225 | ||
1226 | debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data, | |
1227 | dsa_xform.dsa.p.length); | |
1228 | debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data, | |
1229 | dsa_xform.dsa.q.length); | |
1230 | debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data, | |
1231 | dsa_xform.dsa.g.length); | |
1232 | debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data, | |
1233 | dsa_xform.dsa.x.length); | |
1234 | ||
1235 | if (rte_cryptodev_asym_session_init(dev_id, sess, &dsa_xform, | |
1236 | sess_mpool) < 0) { | |
1237 | RTE_LOG(ERR, USER1, | |
1238 | "line %u FAILED: %s", | |
1239 | __LINE__, "unabled to config sym session"); | |
1240 | status = TEST_FAILED; | |
1241 | goto error_exit; | |
1242 | } | |
1243 | ||
1244 | /* attach asymmetric crypto session to crypto operations */ | |
1245 | rte_crypto_op_attach_asym_session(op, sess); | |
1246 | asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN; | |
1247 | asym_op->dsa.message.data = dgst; | |
1248 | asym_op->dsa.message.length = sizeof(dgst); | |
1249 | asym_op->dsa.r.length = sizeof(r); | |
1250 | asym_op->dsa.r.data = r; | |
1251 | asym_op->dsa.s.length = sizeof(s); | |
1252 | asym_op->dsa.s.data = s; | |
1253 | ||
1254 | RTE_LOG(DEBUG, USER1, "Process ASYM operation"); | |
1255 | ||
1256 | /* Process crypto operation */ | |
1257 | if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { | |
1258 | RTE_LOG(ERR, USER1, | |
1259 | "line %u FAILED: %s", | |
1260 | __LINE__, "Error sending packet for operation"); | |
1261 | status = TEST_FAILED; | |
1262 | goto error_exit; | |
1263 | } | |
1264 | ||
1265 | while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) | |
1266 | rte_pause(); | |
1267 | ||
1268 | if (result_op == NULL) { | |
1269 | RTE_LOG(ERR, USER1, | |
1270 | "line %u FAILED: %s", | |
1271 | __LINE__, "Failed to process asym crypto op"); | |
1272 | status = TEST_FAILED; | |
1273 | goto error_exit; | |
1274 | } | |
1275 | ||
1276 | asym_op = result_op->asym; | |
1277 | ||
1278 | debug_hexdump(stdout, "r:", | |
1279 | asym_op->dsa.r.data, asym_op->dsa.r.length); | |
1280 | debug_hexdump(stdout, "s:", | |
1281 | asym_op->dsa.s.data, asym_op->dsa.s.length); | |
1282 | ||
1283 | /* Test PMD DSA sign verification using signer public key */ | |
1284 | asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY; | |
1285 | ||
1286 | /* copy signer public key */ | |
1287 | asym_op->dsa.y.data = dsa_test_params.y.data; | |
1288 | asym_op->dsa.y.length = dsa_test_params.y.length; | |
1289 | ||
1290 | /* Process crypto operation */ | |
1291 | if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { | |
1292 | RTE_LOG(ERR, USER1, | |
1293 | "line %u FAILED: %s", | |
1294 | __LINE__, "Error sending packet for operation"); | |
1295 | status = TEST_FAILED; | |
1296 | goto error_exit; | |
1297 | } | |
1298 | ||
1299 | while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) | |
1300 | rte_pause(); | |
1301 | ||
1302 | if (result_op == NULL) { | |
1303 | RTE_LOG(ERR, USER1, | |
1304 | "line %u FAILED: %s", | |
1305 | __LINE__, "Failed to process asym crypto op"); | |
1306 | status = TEST_FAILED; | |
1307 | goto error_exit; | |
1308 | } | |
1309 | ||
1310 | if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { | |
1311 | RTE_LOG(ERR, USER1, | |
1312 | "line %u FAILED: %s", | |
1313 | __LINE__, "Failed to process asym crypto op"); | |
1314 | status = TEST_FAILED; | |
1315 | } | |
1316 | error_exit: | |
1317 | if (sess != NULL) { | |
1318 | rte_cryptodev_asym_session_clear(dev_id, sess); | |
1319 | rte_cryptodev_asym_session_free(sess); | |
1320 | } | |
1321 | if (op != NULL) | |
1322 | rte_crypto_op_free(op); | |
1323 | return status; | |
1324 | } | |
1325 | ||
1326 | static int | |
1327 | test_dsa(void) | |
1328 | { | |
1329 | int status; | |
1330 | status = test_dsa_sign(); | |
1331 | TEST_ASSERT_EQUAL(status, 0, "Test failed"); | |
1332 | return status; | |
1333 | } | |
1334 | ||
1335 | ||
1336 | static struct unit_test_suite cryptodev_openssl_asym_testsuite = { | |
1337 | .suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite", | |
1338 | .setup = testsuite_setup, | |
1339 | .teardown = testsuite_teardown, | |
1340 | .unit_test_cases = { | |
1341 | TEST_CASE_ST(ut_setup, ut_teardown, test_capability), | |
1342 | TEST_CASE_ST(ut_setup, ut_teardown, test_dsa), | |
1343 | TEST_CASE_ST(ut_setup, ut_teardown, test_dh_keygenration), | |
1344 | TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec), | |
1345 | TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify), | |
1346 | TEST_CASE_ST(ut_setup, ut_teardown, test_mod_inv), | |
1347 | TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp), | |
1348 | TEST_CASES_END() /**< NULL terminate unit test array */ | |
1349 | } | |
1350 | }; | |
1351 | ||
1352 | static int | |
1353 | test_cryptodev_openssl_asym(void) | |
1354 | { | |
1355 | gbl_driver_id = rte_cryptodev_driver_id_get( | |
1356 | RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); | |
1357 | ||
1358 | if (gbl_driver_id == -1) { | |
1359 | RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if " | |
1360 | "CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled " | |
1361 | "in config file to run this testsuite.\n"); | |
1362 | return TEST_FAILED; | |
1363 | } | |
1364 | ||
1365 | return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite); | |
1366 | } | |
1367 | ||
1368 | REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest, | |
1369 | test_cryptodev_openssl_asym); |