Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018 Cavium Networks
3 : : * Copyright (c) 2019 Intel Corporation
4 : : */
5 : :
6 : : #include <rte_bus_vdev.h>
7 : : #include <rte_common.h>
8 : : #include <rte_hexdump.h>
9 : : #include <rte_mbuf.h>
10 : : #include <rte_malloc.h>
11 : : #include <rte_memcpy.h>
12 : : #include <rte_pause.h>
13 : :
14 : : #include <rte_cryptodev.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_ecdh_test_vectors.h"
21 : : #include "test_cryptodev_ecdsa_test_vectors.h"
22 : : #include "test_cryptodev_ecpm_test_vectors.h"
23 : : #include "test_cryptodev_eddsa_test_vectors.h"
24 : : #include "test_cryptodev_mod_test_vectors.h"
25 : : #include "test_cryptodev_rsa_test_vectors.h"
26 : : #include "test_cryptodev_sm2_test_vectors.h"
27 : : #include "test_cryptodev_asym_util.h"
28 : : #include "test.h"
29 : :
30 : : #define TEST_NUM_BUFS 10
31 : : #define TEST_NUM_SESSIONS 4
32 : :
33 : : #ifndef TEST_DATA_SIZE
34 : : #define TEST_DATA_SIZE 4096
35 : : #endif
36 : : #define ASYM_TEST_MSG_LEN 256
37 : : #define TEST_VECTOR_SIZE 256
38 : : #define DEQ_TIMEOUT 10000
39 : :
40 : : static int gbl_driver_id;
41 : : static struct crypto_testsuite_params_asym {
42 : : struct rte_mempool *op_mpool;
43 : : struct rte_mempool *session_mpool;
44 : : struct rte_cryptodev_config conf;
45 : : struct rte_cryptodev_qp_conf qp_conf;
46 : : uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
47 : : uint8_t valid_dev_count;
48 : : } testsuite_params, *params = &testsuite_params;
49 : :
50 : : static struct ut_args {
51 : : void *sess;
52 : : struct rte_crypto_op *op;
53 : : struct rte_crypto_op *result_op;
54 : : } _args, *self = &_args;
55 : :
56 : : static int
57 : 2 : queue_ops_rsa_sign_verify(void *sess)
58 : : {
59 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
60 : 2 : struct rte_mempool *op_mpool = ts_params->op_mpool;
61 : 2 : uint8_t dev_id = ts_params->valid_devs[0];
62 : : struct rte_crypto_op *op, *result_op;
63 : : struct rte_crypto_asym_op *asym_op;
64 : : uint8_t output_buf[TEST_DATA_SIZE];
65 : : int status;
66 : :
67 : : /* Set up crypto op data structure */
68 : 2 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
69 [ - + ]: 2 : if (!op) {
70 : 0 : RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
71 : : "operation struct\n");
72 : 0 : return TEST_FAILED;
73 : : }
74 : :
75 : : asym_op = op->asym;
76 : :
77 : : /* Compute sign on the test vector */
78 : 2 : asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
79 : :
80 : 2 : asym_op->rsa.message.data = rsaplaintext.data;
81 : 2 : asym_op->rsa.message.length = rsaplaintext.len;
82 : 2 : asym_op->rsa.sign.length = RTE_DIM(rsa_n);
83 : 2 : asym_op->rsa.sign.data = output_buf;
84 : :
85 : 2 : debug_hexdump(stdout, "message", asym_op->rsa.message.data,
86 : : asym_op->rsa.message.length);
87 : :
88 : : /* Attach asymmetric crypto session to crypto operations */
89 [ + - ]: 2 : rte_crypto_op_attach_asym_session(op, sess);
90 : :
91 : 2 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
92 : :
93 : : /* Process crypto operation */
94 [ - + ]: 2 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
95 : 0 : RTE_LOG(ERR, USER1, "Error sending packet for sign\n");
96 : : status = TEST_FAILED;
97 : 0 : goto error_exit;
98 : : }
99 : :
100 [ - + ]: 2 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
101 : : rte_pause();
102 : :
103 [ - + ]: 2 : if (result_op == NULL) {
104 : 0 : RTE_LOG(ERR, USER1, "Failed to process sign op\n");
105 : : status = TEST_FAILED;
106 : 0 : goto error_exit;
107 : : }
108 : :
109 : 2 : debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data,
110 : : asym_op->rsa.sign.length);
111 : 2 : asym_op = result_op->asym;
112 : :
113 : : /* Verify sign */
114 : 2 : asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
115 : :
116 : : /* Process crypto operation */
117 [ - + ]: 2 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
118 : 0 : RTE_LOG(ERR, USER1, "Error sending packet for verify\n");
119 : : status = TEST_FAILED;
120 : 0 : goto error_exit;
121 : : }
122 : :
123 [ - + ]: 2 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
124 : : rte_pause();
125 : :
126 [ - + ]: 2 : if (result_op == NULL) {
127 : 0 : RTE_LOG(ERR, USER1, "Failed to process verify op\n");
128 : : status = TEST_FAILED;
129 : 0 : goto error_exit;
130 : : }
131 : :
132 [ - + ]: 2 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
133 : 0 : RTE_LOG(ERR, USER1, "Failed to process sign-verify op\n");
134 : : status = TEST_FAILED;
135 : 0 : goto error_exit;
136 : : }
137 : :
138 : : /* Negative test */
139 : 2 : result_op->asym->rsa.sign.data[0] ^= 0xff;
140 [ - + ]: 2 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &result_op, 1) != 1) {
141 : 0 : RTE_LOG(ERR, USER1, "Error sending packet for verify\n");
142 : : status = TEST_FAILED;
143 : 0 : goto error_exit;
144 : : }
145 : :
146 [ - + ]: 2 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
147 : : rte_pause();
148 : :
149 [ - + ]: 2 : if (result_op == NULL) {
150 : 0 : RTE_LOG(ERR, USER1, "Failed to process verify op\n");
151 : : status = TEST_FAILED;
152 : 0 : goto error_exit;
153 : : }
154 : :
155 [ - + ]: 2 : if (result_op->status != RTE_CRYPTO_OP_STATUS_ERROR) {
156 : 0 : RTE_LOG(ERR, USER1, "Failed to process sign-verify op\n");
157 : : status = TEST_FAILED;
158 : 0 : goto error_exit;
159 : : }
160 : :
161 : : status = TEST_SUCCESS;
162 : 2 : error_exit:
163 : :
164 : 2 : rte_crypto_op_free(op);
165 : :
166 : 2 : return status;
167 : : }
168 : :
169 : : static int
170 : 2 : queue_ops_rsa_enc_dec(void *sess)
171 : : {
172 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
173 : 2 : struct rte_mempool *op_mpool = ts_params->op_mpool;
174 : 2 : uint8_t dev_id = ts_params->valid_devs[0];
175 : : struct rte_crypto_op *op, *result_op;
176 : : struct rte_crypto_asym_op *asym_op;
177 : 2 : uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
178 : 2 : uint8_t msg_buf[TEST_DATA_SIZE] = {0};
179 : : int ret, status;
180 : :
181 : 2 : memcpy(msg_buf, rsaplaintext.data, rsaplaintext.len);
182 : :
183 : : /* Set up crypto op data structure */
184 : 2 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
185 [ - + ]: 2 : if (!op) {
186 : 0 : RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
187 : : "operation struct\n");
188 : 0 : return TEST_FAILED;
189 : : }
190 : :
191 : : asym_op = op->asym;
192 : :
193 : : /* Compute encryption on the test vector */
194 : 2 : asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
195 : :
196 : 2 : asym_op->rsa.message.data = msg_buf;
197 : 2 : asym_op->rsa.cipher.data = cipher_buf;
198 : 2 : asym_op->rsa.cipher.length = RTE_DIM(rsa_n);
199 : 2 : asym_op->rsa.message.length = rsaplaintext.len;
200 : :
201 : 2 : debug_hexdump(stdout, "message", asym_op->rsa.message.data,
202 : : asym_op->rsa.message.length);
203 : :
204 : : /* Attach asymmetric crypto session to crypto operations */
205 [ + - ]: 2 : rte_crypto_op_attach_asym_session(op, sess);
206 : :
207 : 2 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
208 : :
209 : : /* Process crypto operation */
210 [ - + ]: 2 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
211 : 0 : RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
212 : : status = TEST_FAILED;
213 : 0 : goto error_exit;
214 : : }
215 : :
216 [ - + ]: 2 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
217 : : rte_pause();
218 : :
219 [ - + ]: 2 : if (result_op == NULL) {
220 : 0 : RTE_LOG(ERR, USER1, "Failed to process encryption op\n");
221 : : status = TEST_FAILED;
222 : 0 : goto error_exit;
223 : : }
224 : 2 : debug_hexdump(stdout, "encrypted message", asym_op->rsa.cipher.data,
225 : : asym_op->rsa.cipher.length);
226 : :
227 : : /* Use the resulted output as decryption Input vector*/
228 : 2 : asym_op = result_op->asym;
229 : 2 : asym_op->rsa.message.length = RTE_DIM(rsa_n);
230 : 2 : asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
231 : 2 : memset(asym_op->rsa.message.data, 0, asym_op->rsa.message.length);
232 : :
233 : : /* Process crypto operation */
234 [ - + ]: 2 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
235 : 0 : RTE_LOG(ERR, USER1, "Error sending packet for decryption\n");
236 : : status = TEST_FAILED;
237 : 0 : goto error_exit;
238 : : }
239 : :
240 [ - + ]: 2 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
241 : : rte_pause();
242 : :
243 [ - + ]: 2 : if (result_op == NULL) {
244 : 0 : RTE_LOG(ERR, USER1, "Failed to process decryption op\n");
245 : : status = TEST_FAILED;
246 : 0 : goto error_exit;
247 : : }
248 : :
249 [ - + ]: 2 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
250 : 0 : RTE_LOG(ERR, USER1, "Expected crypto op to succeed\n");
251 : : status = TEST_FAILED;
252 : 0 : goto error_exit;
253 : : }
254 : :
255 : : ret = rsa_verify(&rsaplaintext, result_op);
256 : : if (ret) {
257 : : status = TEST_FAILED;
258 : 0 : goto error_exit;
259 : : }
260 : :
261 : : status = TEST_SUCCESS;
262 : 2 : error_exit:
263 : :
264 : 2 : rte_crypto_op_free(op);
265 : :
266 : 2 : return status;
267 : : }
268 : :
269 : : static int
270 : 1 : test_rsa_sign_verify(void)
271 : : {
272 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
273 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
274 : : struct rte_cryptodev_asym_capability_idx idx;
275 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
276 : : struct rte_crypto_asym_xform xform;
277 : 1 : void *sess = NULL;
278 : : struct rte_cryptodev_info dev_info;
279 : : int ret, status = TEST_SUCCESS;
280 : :
281 : : /* Check RSA capability */
282 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_RSA;
283 [ + - ]: 1 : if (rte_cryptodev_asym_capability_get(dev_id, &idx) == NULL)
284 : : return -ENOTSUP;
285 : :
286 : : /* Test case supports op with exponent key only,
287 : : * Check in PMD feature flag for RSA exponent key type support.
288 : : */
289 : 1 : rte_cryptodev_info_get(dev_id, &dev_info);
290 [ - + ]: 1 : if (!(dev_info.feature_flags &
291 : : RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
292 : 0 : RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
293 : : "exponent key type. Test Skipped\n");
294 : 0 : return TEST_SKIPPED;
295 : : }
296 : :
297 : : memcpy(&xform, &rsa_xform, sizeof(rsa_xform));
298 : 1 : xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
299 : :
300 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
301 : :
302 [ - + ]: 1 : if (ret < 0) {
303 : 0 : RTE_LOG(ERR, USER1, "Session creation failed for "
304 : : "sign_verify\n");
305 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
306 : 0 : goto error_exit;
307 : : }
308 : :
309 : 1 : status = queue_ops_rsa_sign_verify(sess);
310 : :
311 : 1 : error_exit:
312 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
313 : :
314 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
315 : :
316 : : return status;
317 : : }
318 : :
319 : : static int
320 : 1 : test_rsa_enc_dec(void)
321 : : {
322 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
323 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
324 : : struct rte_cryptodev_asym_capability_idx idx;
325 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
326 : : struct rte_crypto_asym_xform xform;
327 : 1 : void *sess = NULL;
328 : : struct rte_cryptodev_info dev_info;
329 : : int ret, status = TEST_SUCCESS;
330 : :
331 : : /* Check RSA capability */
332 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_RSA;
333 [ + - ]: 1 : if (rte_cryptodev_asym_capability_get(dev_id, &idx) == NULL)
334 : : return -ENOTSUP;
335 : :
336 : : /* Test case supports op with exponent key only,
337 : : * Check in PMD feature flag for RSA exponent key type support.
338 : : */
339 : 1 : rte_cryptodev_info_get(dev_id, &dev_info);
340 [ - + ]: 1 : if (!(dev_info.feature_flags &
341 : : RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
342 : 0 : RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
343 : : "exponent key type. Test skipped\n");
344 : 0 : return TEST_SKIPPED;
345 : : }
346 : :
347 : : memcpy(&xform, &rsa_xform, sizeof(rsa_xform));
348 : 1 : xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
349 : :
350 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
351 : :
352 [ - + ]: 1 : if (ret < 0) {
353 : 0 : RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
354 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
355 : 0 : goto error_exit;
356 : : }
357 : :
358 : 1 : status = queue_ops_rsa_enc_dec(sess);
359 : :
360 : 1 : error_exit:
361 : :
362 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
363 : :
364 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
365 : :
366 : : return status;
367 : : }
368 : :
369 : : static int
370 : 1 : test_rsa_sign_verify_crt(void)
371 : : {
372 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
373 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
374 : : struct rte_cryptodev_asym_capability_idx idx;
375 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
376 : 1 : void *sess = NULL;
377 : : struct rte_cryptodev_info dev_info;
378 : : int ret, status = TEST_SUCCESS;
379 : :
380 : : /* Check RSA capability */
381 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_RSA;
382 [ + - ]: 1 : if (rte_cryptodev_asym_capability_get(dev_id, &idx) == NULL)
383 : : return -ENOTSUP;
384 : :
385 : : /* Test case supports op with quintuple format key only,
386 : : * Check im PMD feature flag for RSA quintuple key type support.
387 : : */
388 : 1 : rte_cryptodev_info_get(dev_id, &dev_info);
389 [ - + ]: 1 : if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
390 : 0 : RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
391 : : "quintuple key type. Test skipped\n");
392 : 0 : return TEST_SKIPPED;
393 : : }
394 : :
395 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
396 : :
397 [ - + ]: 1 : if (ret < 0) {
398 : 0 : RTE_LOG(ERR, USER1, "Session creation failed for "
399 : : "sign_verify_crt\n");
400 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
401 : 0 : goto error_exit;
402 : : }
403 : :
404 : 1 : status = queue_ops_rsa_sign_verify(sess);
405 : :
406 : 1 : error_exit:
407 : :
408 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
409 : :
410 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
411 : :
412 : : return status;
413 : : }
414 : :
415 : : static int
416 : 1 : test_rsa_enc_dec_crt(void)
417 : : {
418 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
419 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
420 : : struct rte_cryptodev_asym_capability_idx idx;
421 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
422 : 1 : void *sess = NULL;
423 : : struct rte_cryptodev_info dev_info;
424 : : int ret, status = TEST_SUCCESS;
425 : :
426 : : /* Check RSA capability */
427 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_RSA;
428 [ + - ]: 1 : if (rte_cryptodev_asym_capability_get(dev_id, &idx) == NULL)
429 : : return -ENOTSUP;
430 : :
431 : : /* Test case supports op with quintuple format key only,
432 : : * Check in PMD feature flag for RSA quintuple key type support.
433 : : */
434 : 1 : rte_cryptodev_info_get(dev_id, &dev_info);
435 [ - + ]: 1 : if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
436 : 0 : RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
437 : : "quintuple key type. Test skipped\n");
438 : 0 : return TEST_SKIPPED;
439 : : }
440 : :
441 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
442 : :
443 [ - + ]: 1 : if (ret < 0) {
444 : 0 : RTE_LOG(ERR, USER1, "Session creation failed for "
445 : : "enc_dec_crt\n");
446 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
447 : 0 : goto error_exit;
448 : : }
449 : :
450 : 1 : status = queue_ops_rsa_enc_dec(sess);
451 : :
452 : 1 : error_exit:
453 : :
454 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
455 : :
456 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
457 : :
458 : : return status;
459 : : }
460 : :
461 : : static int
462 : 1 : testsuite_setup(void)
463 : : {
464 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
465 : : uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
466 : : struct rte_cryptodev_info info;
467 : : int ret, dev_id = -1;
468 : : uint32_t i, nb_devs;
469 : : uint16_t qp_id;
470 : :
471 : : memset(ts_params, 0, sizeof(*ts_params));
472 : :
473 : : /* Device, op pool and session configuration for asymmetric crypto. 8< */
474 : 1 : ts_params->op_mpool = rte_crypto_op_pool_create(
475 : : "CRYPTO_ASYM_OP_POOL",
476 : : RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
477 : : TEST_NUM_BUFS, 0,
478 : : 0,
479 : 1 : rte_socket_id());
480 [ - + ]: 1 : if (ts_params->op_mpool == NULL) {
481 : 0 : RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
482 : 0 : return TEST_FAILED;
483 : : }
484 : :
485 : : /* Create an OPENSSL device if required */
486 [ + - ]: 1 : if (gbl_driver_id == rte_cryptodev_driver_id_get(
487 : : RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
488 : 1 : nb_devs = rte_cryptodev_device_count_by_driver(
489 : 1 : rte_cryptodev_driver_id_get(
490 : : RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
491 [ - + ]: 1 : if (nb_devs < 1) {
492 : 0 : ret = rte_vdev_init(
493 : : RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
494 : : NULL);
495 : :
496 [ # # ]: 0 : TEST_ASSERT(ret == 0, "Failed to create "
497 : : "instance of pmd : %s",
498 : : RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
499 : : }
500 : : }
501 : :
502 : : /* Get list of valid crypto devs */
503 : 1 : nb_devs = rte_cryptodev_devices_get(
504 : : rte_cryptodev_driver_name_get(gbl_driver_id),
505 : : valid_devs, RTE_CRYPTO_MAX_DEVS);
506 [ - + ]: 1 : if (nb_devs < 1) {
507 : 0 : RTE_LOG(ERR, USER1, "No crypto devices found?\n");
508 : 0 : return TEST_SKIPPED;
509 : : }
510 : :
511 : : /*
512 : : * Get first valid asymmetric device found in test suite param and
513 : : * break
514 : : */
515 [ + - ]: 1 : for (i = 0; i < nb_devs ; i++) {
516 : 1 : rte_cryptodev_info_get(valid_devs[i], &info);
517 [ + - ]: 1 : if (info.feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
518 : 1 : dev_id = ts_params->valid_devs[0] = valid_devs[i];
519 : 1 : break;
520 : : }
521 : : }
522 : :
523 [ - + ]: 1 : if (dev_id == -1) {
524 : 0 : RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
525 : : "Test skipped.\n");
526 : 0 : return TEST_FAILED;
527 : : }
528 : :
529 : : /* Set valid device count */
530 : 1 : ts_params->valid_dev_count = nb_devs;
531 : :
532 : : /* configure device with num qp */
533 : 1 : ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
534 : 1 : ts_params->conf.socket_id = SOCKET_ID_ANY;
535 : 1 : ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY |
536 : : RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO;
537 [ - + ]: 1 : TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
538 : : &ts_params->conf),
539 : : "Failed to configure cryptodev %u with %u qps",
540 : : dev_id, ts_params->conf.nb_queue_pairs);
541 : :
542 : : /* configure qp */
543 : 1 : ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
544 : 1 : ts_params->qp_conf.mp_session = ts_params->session_mpool;
545 [ + + ]: 9 : for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
546 [ - + ]: 8 : TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
547 : : dev_id, qp_id, &ts_params->qp_conf,
548 : : rte_cryptodev_socket_id(dev_id)),
549 : : "Failed to setup queue pair %u on cryptodev %u ASYM",
550 : : qp_id, dev_id);
551 : : }
552 : :
553 : 1 : ts_params->session_mpool = rte_cryptodev_asym_session_pool_create(
554 : : "test_asym_sess_mp", TEST_NUM_SESSIONS, 0, 0,
555 : : SOCKET_ID_ANY);
556 : :
557 [ - + ]: 1 : TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
558 : : "session mempool allocation failed");
559 : : /* >8 End of device, op pool and session configuration for asymmetric crypto section. */
560 : : return TEST_SUCCESS;
561 : : }
562 : :
563 : : static void
564 : 1 : testsuite_teardown(void)
565 : : {
566 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
567 : :
568 : : /* Reset device */
569 : 1 : ts_params->qp_conf.mp_session = NULL;
570 : 1 : ts_params->conf.ff_disable = 0;
571 [ - + ]: 1 : if (rte_cryptodev_configure(ts_params->valid_devs[0], &ts_params->conf))
572 : 0 : RTE_LOG(DEBUG, USER1, "Could not reset cryptodev\n");
573 : :
574 [ + - ]: 1 : if (ts_params->op_mpool != NULL) {
575 : 1 : RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
576 : : rte_mempool_avail_count(ts_params->op_mpool));
577 : : }
578 : :
579 : : /* Free session mempools */
580 [ + - ]: 1 : if (ts_params->session_mpool != NULL) {
581 : 1 : rte_mempool_free(ts_params->session_mpool);
582 : 1 : ts_params->session_mpool = NULL;
583 : : }
584 : 1 : }
585 : :
586 : : static int
587 : 24 : ut_setup_asym(void)
588 : : {
589 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
590 : : uint16_t qp_id;
591 : :
592 : 24 : memset(self, 0, sizeof(*self));
593 : 24 : self->op = rte_crypto_op_alloc(params->op_mpool,
594 : : RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
595 [ - + ]: 24 : TEST_ASSERT_NOT_NULL(self->op,
596 : : "Failed to allocate asymmetric crypto operation struct"
597 : : );
598 : :
599 : : /* Reconfigure device to default parameters */
600 : 24 : ts_params->conf.socket_id = SOCKET_ID_ANY;
601 : :
602 [ - + ]: 24 : TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
603 : : &ts_params->conf),
604 : : "Failed to configure cryptodev %u",
605 : : ts_params->valid_devs[0]);
606 : :
607 [ + + ]: 216 : for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
608 [ - + ]: 192 : TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
609 : : ts_params->valid_devs[0], qp_id,
610 : : &ts_params->qp_conf,
611 : : rte_cryptodev_socket_id(ts_params->valid_devs[0])),
612 : : "Failed to setup queue pair %u on cryptodev %u",
613 : : qp_id, ts_params->valid_devs[0]);
614 : : }
615 : :
616 : : /* Start the device */
617 [ - + ]: 24 : TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
618 : : "Failed to start cryptodev %u",
619 : : ts_params->valid_devs[0]);
620 : :
621 : : return TEST_SUCCESS;
622 : : }
623 : :
624 : : static void
625 : 24 : ut_teardown_asym(void)
626 : : {
627 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
628 : 24 : uint8_t dev_id = ts_params->valid_devs[0];
629 : :
630 [ + + ]: 24 : if (self->sess != NULL)
631 : 10 : rte_cryptodev_asym_session_free(dev_id, self->sess);
632 : 24 : rte_crypto_op_free(self->op);
633 : 24 : self->sess = NULL;
634 : 24 : self->op = NULL;
635 : 24 : self->result_op = NULL;
636 : :
637 : : /* Stop the device */
638 : 24 : rte_cryptodev_stop(ts_params->valid_devs[0]);
639 : 24 : }
640 : :
641 : 8 : static inline void print_asym_capa(
642 : : const struct rte_cryptodev_asymmetric_xform_capability *capa)
643 : : {
644 : : int i = 0;
645 : :
646 : 8 : printf("\nxform type: %s\n===================\n",
647 : 8 : rte_cryptodev_asym_get_xform_string(capa->xform_type));
648 : : printf("operation supported -");
649 : :
650 [ + + ]: 40 : for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
651 : : /* check supported operations */
652 [ + + ]: 32 : if (rte_cryptodev_asym_xform_capability_check_optype(capa, i)) {
653 [ + + ]: 15 : if (capa->xform_type == RTE_CRYPTO_ASYM_XFORM_DH)
654 : 3 : printf(" %s", rte_crypto_asym_ke_strings[i]);
655 : : else
656 : 12 : printf(" %s", rte_crypto_asym_op_strings[i]);
657 : : }
658 : : }
659 [ + + ]: 8 : switch (capa->xform_type) {
660 : 5 : case RTE_CRYPTO_ASYM_XFORM_RSA:
661 : : case RTE_CRYPTO_ASYM_XFORM_MODINV:
662 : : case RTE_CRYPTO_ASYM_XFORM_MODEX:
663 : : case RTE_CRYPTO_ASYM_XFORM_DH:
664 : : case RTE_CRYPTO_ASYM_XFORM_DSA:
665 : 5 : printf(" modlen: min %d max %d increment %d",
666 : 5 : capa->modlen.min,
667 : 5 : capa->modlen.max,
668 : 5 : capa->modlen.increment);
669 : : break;
670 : : case RTE_CRYPTO_ASYM_XFORM_ECDSA:
671 : : case RTE_CRYPTO_ASYM_XFORM_ECPM:
672 : : case RTE_CRYPTO_ASYM_XFORM_SM2:
673 : : default:
674 : : break;
675 : : }
676 : : printf("\n");
677 : 8 : }
678 : :
679 : : static int
680 : 1 : test_capability(void)
681 : : {
682 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
683 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
684 : : struct rte_cryptodev_info dev_info;
685 : : const struct rte_cryptodev_capabilities *dev_capa;
686 : : int i = 0;
687 : : struct rte_cryptodev_asym_capability_idx idx;
688 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
689 : :
690 : 1 : rte_cryptodev_info_get(dev_id, &dev_info);
691 [ - + ]: 1 : if (!(dev_info.feature_flags &
692 : : RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
693 : 0 : RTE_LOG(INFO, USER1,
694 : : "Device doesn't support asymmetric. Test Skipped\n");
695 : 0 : return TEST_SKIPPED;
696 : : }
697 : :
698 : : /* print xform capability */
699 : : for (i = 0;
700 [ + + ]: 31 : dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
701 : 30 : i++) {
702 : : dev_capa = &(dev_info.capabilities[i]);
703 [ + + ]: 30 : if (dev_info.capabilities[i].op ==
704 : : RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
705 : 8 : idx.type = dev_capa->asym.xform_capa.xform_type;
706 : :
707 : 8 : capa = rte_cryptodev_asym_capability_get(dev_id,
708 : : (const struct
709 : : rte_cryptodev_asym_capability_idx *) &idx);
710 [ - + ]: 8 : TEST_ASSERT_NOT_NULL(capa, "Failed to get asymmetric capability");
711 : 8 : print_asym_capa(capa);
712 : : }
713 : : }
714 : : return TEST_SUCCESS;
715 : : }
716 : :
717 : : static int
718 : 1 : test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
719 : : {
720 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
721 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
722 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
723 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
724 : : struct rte_crypto_asym_op *asym_op = NULL;
725 : 1 : struct rte_crypto_op *op = NULL, *result_op = NULL;
726 : 1 : void *sess = NULL;
727 : : int ret, status = TEST_SUCCESS;
728 : : uint8_t output[TEST_DH_MOD_LEN];
729 : 1 : struct rte_crypto_asym_xform xform = *xfrm;
730 : 1 : uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
731 : :
732 : : /* set up crypto op data structure */
733 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
734 [ - + ]: 1 : if (!op) {
735 : 0 : RTE_LOG(ERR, USER1,
736 : : "line %u FAILED: %s",
737 : : __LINE__, "Failed to allocate asymmetric crypto "
738 : : "operation struct");
739 : : status = TEST_FAILED;
740 : 0 : goto error_exit;
741 : : }
742 : : asym_op = op->asym;
743 : :
744 : : /* Setup a xform and op to generate private key only */
745 : 1 : xform.next = NULL;
746 : 1 : asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE;
747 : 1 : asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
748 : 1 : asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
749 : 1 : asym_op->dh.pub_key.data = (uint8_t *)peer;
750 : 1 : asym_op->dh.pub_key.length = sizeof(peer);
751 : 1 : asym_op->dh.shared_secret.data = output;
752 : 1 : asym_op->dh.shared_secret.length = sizeof(output);
753 : :
754 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
755 [ - + ]: 1 : if (ret < 0) {
756 : 0 : RTE_LOG(ERR, USER1,
757 : : "line %u FAILED: %s", __LINE__,
758 : : "Session creation failed");
759 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
760 : 0 : goto error_exit;
761 : : }
762 : :
763 : : /* attach asymmetric crypto session to crypto operations */
764 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
765 : :
766 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation");
767 : :
768 : : /* Process crypto operation */
769 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
770 : 0 : RTE_LOG(ERR, USER1,
771 : : "line %u FAILED: %s",
772 : : __LINE__, "Error sending packet for operation");
773 : : status = TEST_FAILED;
774 : 0 : goto error_exit;
775 : : }
776 : :
777 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
778 : : rte_pause();
779 : :
780 [ - + ]: 1 : if (result_op == NULL) {
781 : 0 : RTE_LOG(ERR, USER1,
782 : : "line %u FAILED: %s",
783 : : __LINE__, "Failed to process asym crypto op");
784 : : status = TEST_FAILED;
785 : 0 : goto error_exit;
786 : : }
787 : :
788 : 1 : debug_hexdump(stdout, "shared secret:",
789 : 1 : asym_op->dh.shared_secret.data,
790 : : asym_op->dh.shared_secret.length);
791 : :
792 : 1 : error_exit:
793 [ + - ]: 1 : if (sess != NULL)
794 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
795 : 1 : rte_crypto_op_free(op);
796 : 1 : return status;
797 : : }
798 : :
799 : : static int
800 : 1 : test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
801 : : {
802 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
803 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
804 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
805 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
806 : : struct rte_crypto_asym_op *asym_op = NULL;
807 : 1 : struct rte_crypto_op *op = NULL, *result_op = NULL;
808 : 1 : void *sess = NULL;
809 : : int ret, status = TEST_SUCCESS;
810 : : uint8_t output[TEST_DH_MOD_LEN];
811 : 1 : struct rte_crypto_asym_xform xform = *xfrm;
812 : :
813 : : /* set up crypto op data structure */
814 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
815 [ - + ]: 1 : if (!op) {
816 : 0 : RTE_LOG(ERR, USER1,
817 : : "line %u FAILED: %s",
818 : : __LINE__, "Failed to allocate asymmetric crypto "
819 : : "operation struct");
820 : : status = TEST_FAILED;
821 : 0 : goto error_exit;
822 : : }
823 : : asym_op = op->asym;
824 : :
825 : : /* Setup a xform and op to generate private key only */
826 : 1 : xform.next = NULL;
827 : 1 : asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE;
828 : 1 : asym_op->dh.priv_key.data = output;
829 : 1 : asym_op->dh.priv_key.length = sizeof(output);
830 : :
831 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
832 [ - + ]: 1 : if (ret < 0) {
833 : 0 : RTE_LOG(ERR, USER1,
834 : : "line %u FAILED: %s", __LINE__,
835 : : "Session creation failed");
836 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
837 : 0 : goto error_exit;
838 : : }
839 : :
840 : : /* attach asymmetric crypto session to crypto operations */
841 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
842 : :
843 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation");
844 : :
845 : : /* Process crypto operation */
846 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
847 : 0 : RTE_LOG(ERR, USER1,
848 : : "line %u FAILED: %s",
849 : : __LINE__, "Error sending packet for operation");
850 : : status = TEST_FAILED;
851 : 0 : goto error_exit;
852 : : }
853 : :
854 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
855 : : rte_pause();
856 : :
857 [ - + ]: 1 : if (result_op == NULL) {
858 : 0 : RTE_LOG(ERR, USER1,
859 : : "line %u FAILED: %s",
860 : : __LINE__, "Failed to process asym crypto op");
861 : : status = TEST_FAILED;
862 : 0 : goto error_exit;
863 : : }
864 : :
865 : 1 : debug_hexdump(stdout, "private key:",
866 : 1 : asym_op->dh.priv_key.data,
867 : : asym_op->dh.priv_key.length);
868 : :
869 : :
870 : 1 : error_exit:
871 [ + - ]: 1 : if (sess != NULL)
872 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
873 : 1 : rte_crypto_op_free(op);
874 : :
875 : 1 : return status;
876 : : }
877 : :
878 : :
879 : : static int
880 : 1 : test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
881 : : {
882 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
883 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
884 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
885 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
886 : : struct rte_crypto_asym_op *asym_op = NULL;
887 : 1 : struct rte_crypto_op *op = NULL, *result_op = NULL;
888 : 1 : void *sess = NULL;
889 : : int ret, status = TEST_SUCCESS;
890 : : uint8_t output[TEST_DH_MOD_LEN];
891 : 1 : struct rte_crypto_asym_xform xform = *xfrm;
892 : :
893 : : /* set up crypto op data structure */
894 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
895 [ - + ]: 1 : if (!op) {
896 : 0 : RTE_LOG(ERR, USER1,
897 : : "line %u FAILED: %s",
898 : : __LINE__, "Failed to allocate asymmetric crypto "
899 : : "operation struct");
900 : : status = TEST_FAILED;
901 : 0 : goto error_exit;
902 : : }
903 : : asym_op = op->asym;
904 : : /* Setup a xform chain to generate public key
905 : : * using test private key
906 : : *
907 : : */
908 : 1 : xform.next = NULL;
909 : :
910 : 1 : asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
911 : 1 : asym_op->dh.pub_key.data = output;
912 : 1 : asym_op->dh.pub_key.length = sizeof(output);
913 : : /* load pre-defined private key */
914 : 1 : asym_op->dh.priv_key.data = rte_malloc(NULL,
915 : : dh_test_params.priv_key.length,
916 : : 0);
917 : 1 : asym_op->dh.priv_key = dh_test_params.priv_key;
918 : :
919 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
920 [ - + ]: 1 : if (ret < 0) {
921 : 0 : RTE_LOG(ERR, USER1,
922 : : "line %u FAILED: %s", __LINE__,
923 : : "Session creation failed");
924 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
925 : 0 : goto error_exit;
926 : : }
927 : :
928 : : /* attach asymmetric crypto session to crypto operations */
929 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
930 : :
931 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation");
932 : :
933 : : /* Process crypto operation */
934 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
935 : 0 : RTE_LOG(ERR, USER1,
936 : : "line %u FAILED: %s",
937 : : __LINE__, "Error sending packet for operation");
938 : : status = TEST_FAILED;
939 : 0 : goto error_exit;
940 : : }
941 : :
942 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
943 : : rte_pause();
944 : :
945 [ - + ]: 1 : if (result_op == NULL) {
946 : 0 : RTE_LOG(ERR, USER1,
947 : : "line %u FAILED: %s",
948 : : __LINE__, "Failed to process asym crypto op");
949 : : status = TEST_FAILED;
950 : 0 : goto error_exit;
951 : : }
952 : :
953 : 1 : debug_hexdump(stdout, "pub key:",
954 : 1 : asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
955 : :
956 : 1 : debug_hexdump(stdout, "priv key:",
957 : 1 : asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
958 : :
959 : 1 : error_exit:
960 [ + - ]: 1 : if (sess != NULL)
961 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
962 : 1 : rte_crypto_op_free(op);
963 : :
964 : 1 : return status;
965 : : }
966 : :
967 : : static int
968 : 1 : test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
969 : : {
970 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
971 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
972 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
973 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
974 : : struct rte_crypto_asym_op *asym_op = NULL;
975 : 1 : struct rte_crypto_op *op = NULL, *result_op = NULL;
976 : 1 : void *sess = NULL;
977 : : int ret, status = TEST_SUCCESS;
978 : : uint8_t out_pub_key[TEST_DH_MOD_LEN];
979 : : uint8_t out_prv_key[TEST_DH_MOD_LEN];
980 : : struct rte_crypto_asym_xform pub_key_xform;
981 : 1 : struct rte_crypto_asym_xform xform = *xfrm;
982 : :
983 : : /* set up crypto op data structure */
984 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
985 [ - + ]: 1 : if (!op) {
986 : 0 : RTE_LOG(ERR, USER1,
987 : : "line %u FAILED: %s",
988 : : __LINE__, "Failed to allocate asymmetric crypto "
989 : : "operation struct");
990 : : status = TEST_FAILED;
991 : 0 : goto error_exit;
992 : : }
993 : : asym_op = op->asym;
994 : : /* Setup a xform chain to generate
995 : : * private key first followed by
996 : : * public key
997 : : */
998 : 1 : pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
999 : 1 : xform.next = &pub_key_xform;
1000 : :
1001 : 1 : asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
1002 : 1 : asym_op->dh.pub_key.data = out_pub_key;
1003 : 1 : asym_op->dh.pub_key.length = sizeof(out_pub_key);
1004 : 1 : asym_op->dh.priv_key.data = out_prv_key;
1005 : 1 : asym_op->dh.priv_key.length = 0;
1006 : :
1007 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1008 [ - + ]: 1 : if (ret < 0) {
1009 : 0 : RTE_LOG(ERR, USER1,
1010 : : "line %u FAILED: %s", __LINE__,
1011 : : "Session creation failed");
1012 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1013 : 0 : goto error_exit;
1014 : : }
1015 : :
1016 : : /* attach asymmetric crypto session to crypto operations */
1017 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
1018 : :
1019 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1020 : :
1021 : : /* Process crypto operation */
1022 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1023 : 0 : RTE_LOG(ERR, USER1,
1024 : : "line %u FAILED: %s",
1025 : : __LINE__, "Error sending packet for operation");
1026 : : status = TEST_FAILED;
1027 : 0 : goto error_exit;
1028 : : }
1029 : :
1030 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1031 : : rte_pause();
1032 : :
1033 [ - + ]: 1 : if (result_op == NULL) {
1034 : 0 : RTE_LOG(ERR, USER1,
1035 : : "line %u FAILED: %s",
1036 : : __LINE__, "Failed to process asym crypto op");
1037 : : status = TEST_FAILED;
1038 : 0 : goto error_exit;
1039 : : }
1040 : 1 : debug_hexdump(stdout, "priv key:",
1041 : : out_prv_key, asym_op->dh.priv_key.length);
1042 : 1 : debug_hexdump(stdout, "pub key:",
1043 : : out_pub_key, asym_op->dh.pub_key.length);
1044 : :
1045 : 1 : error_exit:
1046 [ + - ]: 1 : if (sess != NULL)
1047 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
1048 : 1 : rte_crypto_op_free(op);
1049 : :
1050 : 1 : return status;
1051 : : }
1052 : :
1053 : : static int
1054 : 1 : test_mod_inv(void)
1055 : : {
1056 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1057 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
1058 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
1059 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
1060 : : struct rte_crypto_asym_op *asym_op = NULL;
1061 : 1 : struct rte_crypto_op *op = NULL, *result_op = NULL;
1062 : 1 : void *sess = NULL;
1063 : : int status = TEST_SUCCESS;
1064 : : struct rte_cryptodev_asym_capability_idx cap_idx;
1065 : : const struct rte_cryptodev_asymmetric_xform_capability *capability;
1066 : 1 : uint8_t input[TEST_DATA_SIZE] = {0};
1067 : : int ret = 0;
1068 : 1 : uint8_t result[sizeof(mod_p)] = { 0 };
1069 : :
1070 [ - + ]: 1 : if (rte_cryptodev_asym_get_xform_enum(
1071 : : &modinv_xform.xform_type, "modinv") < 0) {
1072 : 0 : RTE_LOG(ERR, USER1,
1073 : : "Invalid ASYM algorithm specified\n");
1074 : 0 : return -1;
1075 : : }
1076 : :
1077 : 1 : cap_idx.type = modinv_xform.xform_type;
1078 : 1 : capability = rte_cryptodev_asym_capability_get(dev_id,
1079 : : &cap_idx);
1080 : :
1081 [ - + ]: 1 : if (capability == NULL) {
1082 : 0 : RTE_LOG(INFO, USER1,
1083 : : "Device doesn't support MOD INV. Test Skipped\n");
1084 : 0 : return TEST_SKIPPED;
1085 : : }
1086 : :
1087 [ - + ]: 1 : if (rte_cryptodev_asym_xform_capability_check_modlen(
1088 : : capability,
1089 : 1 : modinv_xform.modinv.modulus.length)) {
1090 : 0 : RTE_LOG(ERR, USER1,
1091 : : "Invalid MODULUS length specified\n");
1092 : 0 : return TEST_SKIPPED;
1093 : : }
1094 : :
1095 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool, &sess);
1096 [ - + ]: 1 : if (ret < 0) {
1097 : 0 : RTE_LOG(ERR, USER1, "line %u "
1098 : : "FAILED: %s", __LINE__,
1099 : : "Session creation failed");
1100 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1101 : 0 : goto error_exit;
1102 : : }
1103 : :
1104 : : /* generate crypto op data structure */
1105 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1106 [ - + ]: 1 : if (!op) {
1107 : 0 : RTE_LOG(ERR, USER1,
1108 : : "line %u FAILED: %s",
1109 : : __LINE__, "Failed to allocate asymmetric crypto "
1110 : : "operation struct");
1111 : : status = TEST_FAILED;
1112 : 0 : goto error_exit;
1113 : : }
1114 : :
1115 : : asym_op = op->asym;
1116 : : memcpy(input, base, sizeof(base));
1117 : 1 : asym_op->modinv.base.data = input;
1118 : 1 : asym_op->modinv.base.length = sizeof(base);
1119 : 1 : asym_op->modinv.result.data = result;
1120 : 1 : asym_op->modinv.result.length = sizeof(result);
1121 : :
1122 : : /* attach asymmetric crypto session to crypto operations */
1123 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
1124 : :
1125 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1126 : :
1127 : : /* Process crypto operation */
1128 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1129 : 0 : RTE_LOG(ERR, USER1,
1130 : : "line %u FAILED: %s",
1131 : : __LINE__, "Error sending packet for operation");
1132 : : status = TEST_FAILED;
1133 : 0 : goto error_exit;
1134 : : }
1135 : :
1136 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1137 : : rte_pause();
1138 : :
1139 [ - + ]: 1 : if (result_op == NULL) {
1140 : 0 : RTE_LOG(ERR, USER1,
1141 : : "line %u FAILED: %s",
1142 : : __LINE__, "Failed to process asym crypto op");
1143 : : status = TEST_FAILED;
1144 : 0 : goto error_exit;
1145 : : }
1146 : :
1147 : : ret = verify_modinv(mod_inv, result_op);
1148 : : if (ret) {
1149 : 0 : RTE_LOG(ERR, USER1,
1150 : : "operation verification failed\n");
1151 : : status = TEST_FAILED;
1152 : : }
1153 : :
1154 : 1 : error_exit:
1155 [ + - ]: 1 : if (sess)
1156 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
1157 : :
1158 : 1 : rte_crypto_op_free(op);
1159 : :
1160 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
1161 : :
1162 : : return status;
1163 : : }
1164 : :
1165 : : static int
1166 : 1 : test_mod_exp(void)
1167 : : {
1168 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1169 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
1170 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
1171 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
1172 : : struct rte_crypto_asym_op *asym_op = NULL;
1173 : 1 : struct rte_crypto_op *op = NULL, *result_op = NULL;
1174 : 1 : void *sess = NULL;
1175 : : int status = TEST_SUCCESS;
1176 : : struct rte_cryptodev_asym_capability_idx cap_idx;
1177 : : const struct rte_cryptodev_asymmetric_xform_capability *capability;
1178 : 1 : uint8_t input[TEST_DATA_SIZE] = {0};
1179 : : int ret = 0;
1180 : 1 : uint8_t result[sizeof(mod_p)] = { 0 };
1181 : :
1182 [ - + ]: 1 : if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1183 : : "modexp")
1184 : : < 0) {
1185 : 0 : RTE_LOG(ERR, USER1,
1186 : : "Invalid ASYM algorithm specified\n");
1187 : 0 : return -1;
1188 : : }
1189 : :
1190 : : /* check for modlen capability */
1191 : 1 : cap_idx.type = modex_xform.xform_type;
1192 : 1 : capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1193 : :
1194 [ - + ]: 1 : if (capability == NULL) {
1195 : 0 : RTE_LOG(INFO, USER1,
1196 : : "Device doesn't support MOD EXP. Test Skipped\n");
1197 : 0 : return TEST_SKIPPED;
1198 : : }
1199 : :
1200 [ - + ]: 1 : if (rte_cryptodev_asym_xform_capability_check_modlen(
1201 : 1 : capability, modex_xform.modex.modulus.length)) {
1202 : 0 : RTE_LOG(ERR, USER1,
1203 : : "Invalid MODULUS length specified\n");
1204 : 0 : return TEST_SKIPPED;
1205 : : }
1206 : :
1207 : : /* Create op, create session, and process packets. 8< */
1208 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1209 [ - + ]: 1 : if (!op) {
1210 : 0 : RTE_LOG(ERR, USER1,
1211 : : "line %u FAILED: %s",
1212 : : __LINE__, "Failed to allocate asymmetric crypto "
1213 : : "operation struct");
1214 : : status = TEST_FAILED;
1215 : 0 : goto error_exit;
1216 : : }
1217 : :
1218 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool, &sess);
1219 [ - + ]: 1 : if (ret < 0) {
1220 : 0 : RTE_LOG(ERR, USER1,
1221 : : "line %u "
1222 : : "FAILED: %s", __LINE__,
1223 : : "Session creation failed");
1224 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1225 : 0 : goto error_exit;
1226 : : }
1227 : :
1228 : 1 : asym_op = op->asym;
1229 : : memcpy(input, base, sizeof(base));
1230 : 1 : asym_op->modex.base.data = input;
1231 : 1 : asym_op->modex.base.length = sizeof(base);
1232 : 1 : asym_op->modex.result.data = result;
1233 : 1 : asym_op->modex.result.length = sizeof(result);
1234 : : /* attach asymmetric crypto session to crypto operations */
1235 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
1236 : :
1237 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1238 : : /* Process crypto operation */
1239 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1240 : 0 : RTE_LOG(ERR, USER1,
1241 : : "line %u FAILED: %s",
1242 : : __LINE__, "Error sending packet for operation");
1243 : : status = TEST_FAILED;
1244 : 0 : goto error_exit;
1245 : : }
1246 : :
1247 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1248 : : rte_pause();
1249 : :
1250 [ - + ]: 1 : if (result_op == NULL) {
1251 : 0 : RTE_LOG(ERR, USER1,
1252 : : "line %u FAILED: %s",
1253 : : __LINE__, "Failed to process asym crypto op");
1254 : : status = TEST_FAILED;
1255 : 0 : goto error_exit;
1256 : : }
1257 : : /* >8 End of create op, create session, and process packets section. */
1258 : : ret = verify_modexp(mod_exp, result_op);
1259 : : if (ret) {
1260 : 0 : RTE_LOG(ERR, USER1,
1261 : : "operation verification failed\n");
1262 : : status = TEST_FAILED;
1263 : : }
1264 : :
1265 : 1 : error_exit:
1266 [ + - ]: 1 : if (sess != NULL)
1267 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
1268 : :
1269 : 1 : rte_crypto_op_free(op);
1270 : :
1271 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
1272 : :
1273 : : return status;
1274 : : }
1275 : :
1276 : : static int
1277 : 1 : test_dh_key_generation(void)
1278 : : {
1279 : : int status;
1280 : :
1281 : 1 : debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1282 : 1 : debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1283 : 1 : debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1284 : : dh_test_params.priv_key.length);
1285 : :
1286 : 1 : RTE_LOG(INFO, USER1,
1287 : : "Test Public and Private key pair generation\n");
1288 : :
1289 : 1 : status = test_dh_gen_kp(&dh_xform);
1290 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
1291 : :
1292 : 1 : RTE_LOG(INFO, USER1,
1293 : : "Test Public Key Generation using pre-defined priv key\n");
1294 : :
1295 : 1 : status = test_dh_gen_pub_key(&dh_xform);
1296 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
1297 : :
1298 : 1 : RTE_LOG(INFO, USER1,
1299 : : "Test Private Key Generation only\n");
1300 : :
1301 : 1 : status = test_dh_gen_priv_key(&dh_xform);
1302 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
1303 : :
1304 : 1 : RTE_LOG(INFO, USER1,
1305 : : "Test shared secret compute\n");
1306 : :
1307 : 1 : status = test_dh_gen_shared_sec(&dh_xform);
1308 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
1309 : :
1310 : : return status;
1311 : : }
1312 : :
1313 : : static int
1314 : 1 : test_dsa_sign(struct rte_crypto_dsa_op_param *dsa_op)
1315 : : {
1316 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1317 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
1318 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
1319 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
1320 : : struct rte_crypto_asym_op *asym_op = NULL;
1321 : 1 : struct rte_crypto_op *op = NULL, *result_op = NULL;
1322 : 1 : void *sess = NULL;
1323 : : int status = TEST_SUCCESS;
1324 : : int ret;
1325 : :
1326 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
1327 [ - + ]: 1 : if (ret < 0) {
1328 : 0 : RTE_LOG(ERR, USER1,
1329 : : "line %u FAILED: %s", __LINE__,
1330 : : "Session creation failed");
1331 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1332 : 0 : goto error_exit;
1333 : : }
1334 : : /* set up crypto op data structure */
1335 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1336 [ - + ]: 1 : if (!op) {
1337 : 0 : RTE_LOG(ERR, USER1,
1338 : : "line %u FAILED: %s",
1339 : : __LINE__, "Failed to allocate asymmetric crypto "
1340 : : "operation struct");
1341 : : status = TEST_FAILED;
1342 : 0 : goto error_exit;
1343 : : }
1344 : : asym_op = op->asym;
1345 : 1 : asym_op->dsa = *dsa_op;
1346 : :
1347 : 1 : debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1348 : : dsa_xform.dsa.p.length);
1349 : 1 : debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1350 : : dsa_xform.dsa.q.length);
1351 : 1 : debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1352 : : dsa_xform.dsa.g.length);
1353 : 1 : debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1354 : : dsa_xform.dsa.x.length);
1355 : :
1356 : : /* attach asymmetric crypto session to crypto operations */
1357 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
1358 : 1 : asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1359 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1360 : :
1361 : : /* Process crypto operation */
1362 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1363 : 0 : RTE_LOG(ERR, USER1,
1364 : : "line %u FAILED: %s",
1365 : : __LINE__, "Error sending packet for operation");
1366 : : status = TEST_FAILED;
1367 : 0 : goto error_exit;
1368 : : }
1369 : :
1370 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1371 : : rte_pause();
1372 : :
1373 [ - + ]: 1 : if (result_op == NULL) {
1374 : 0 : RTE_LOG(ERR, USER1,
1375 : : "line %u FAILED: %s",
1376 : : __LINE__, "Failed to process asym crypto op");
1377 : : status = TEST_FAILED;
1378 : 0 : goto error_exit;
1379 : : }
1380 : :
1381 : : asym_op = result_op->asym;
1382 : 1 : dsa_op->r.length = asym_op->dsa.r.length;
1383 : 1 : dsa_op->s.length = asym_op->dsa.s.length;
1384 : :
1385 : 1 : debug_hexdump(stdout, "r:",
1386 : 1 : asym_op->dsa.r.data, asym_op->dsa.r.length);
1387 : 1 : debug_hexdump(stdout, "s:",
1388 : 1 : asym_op->dsa.s.data, asym_op->dsa.s.length);
1389 : 1 : error_exit:
1390 [ + - ]: 1 : if (sess != NULL)
1391 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
1392 : 1 : rte_crypto_op_free(op);
1393 : 1 : return status;
1394 : : }
1395 : :
1396 : : static int
1397 : 1 : test_dsa_verify(struct rte_crypto_dsa_op_param *dsa_op)
1398 : : {
1399 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1400 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
1401 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
1402 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
1403 : : struct rte_crypto_asym_op *asym_op = NULL;
1404 : 1 : struct rte_crypto_op *op = NULL, *result_op = NULL;
1405 : 1 : void *sess = NULL;
1406 : : int status = TEST_SUCCESS;
1407 : : int ret;
1408 : :
1409 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
1410 [ - + ]: 1 : if (ret < 0) {
1411 : 0 : RTE_LOG(ERR, USER1,
1412 : : "line %u FAILED: %s", __LINE__,
1413 : : "Session creation failed");
1414 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1415 : 0 : goto error_exit;
1416 : : }
1417 : : /* set up crypto op data structure */
1418 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1419 [ - + ]: 1 : if (!op) {
1420 : 0 : RTE_LOG(ERR, USER1,
1421 : : "line %u FAILED: %s",
1422 : : __LINE__, "Failed to allocate asymmetric crypto "
1423 : : "operation struct");
1424 : : status = TEST_FAILED;
1425 : 0 : goto error_exit;
1426 : : }
1427 : : asym_op = op->asym;
1428 : 1 : asym_op->dsa = *dsa_op;
1429 : :
1430 : 1 : debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1431 : : dsa_xform.dsa.p.length);
1432 : 1 : debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1433 : : dsa_xform.dsa.q.length);
1434 : 1 : debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1435 : : dsa_xform.dsa.g.length);
1436 : :
1437 : : /* attach asymmetric crypto session to crypto operations */
1438 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
1439 : :
1440 : 1 : debug_hexdump(stdout, "r:",
1441 : 1 : asym_op->dsa.r.data, asym_op->dsa.r.length);
1442 : 1 : debug_hexdump(stdout, "s:",
1443 : 1 : asym_op->dsa.s.data, asym_op->dsa.s.length);
1444 : :
1445 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM verify operation");
1446 : : /* Test PMD DSA sign verification using signer public key */
1447 : 1 : asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1448 : :
1449 : : /* copy signer public key */
1450 : 1 : asym_op->dsa.y.data = dsa_test_params.y.data;
1451 : 1 : asym_op->dsa.y.length = dsa_test_params.y.length;
1452 : :
1453 : : /* Process crypto operation */
1454 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1455 : 0 : RTE_LOG(ERR, USER1,
1456 : : "line %u FAILED: %s",
1457 : : __LINE__, "Error sending packet for operation");
1458 : : status = TEST_FAILED;
1459 : 0 : goto error_exit;
1460 : : }
1461 : :
1462 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1463 : : rte_pause();
1464 : :
1465 [ - + ]: 1 : if (result_op == NULL) {
1466 : 0 : RTE_LOG(ERR, USER1,
1467 : : "line %u FAILED: %s",
1468 : : __LINE__, "Failed to process asym crypto op");
1469 : : status = TEST_FAILED;
1470 : 0 : goto error_exit;
1471 : : }
1472 : :
1473 [ + - ]: 1 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1474 : 0 : RTE_LOG(ERR, USER1,
1475 : : "line %u FAILED: %s",
1476 : : __LINE__, "Failed to process asym crypto op");
1477 : : status = TEST_FAILED;
1478 : : }
1479 : 1 : error_exit:
1480 [ + - ]: 1 : if (sess != NULL)
1481 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
1482 : 1 : rte_crypto_op_free(op);
1483 : 1 : return status;
1484 : : }
1485 : :
1486 : : static int
1487 : 1 : test_dsa(void)
1488 : : {
1489 : : int status;
1490 : : uint8_t r[TEST_DH_MOD_LEN];
1491 : : uint8_t s[TEST_DH_MOD_LEN];
1492 : : struct rte_crypto_dsa_op_param dsa_op;
1493 : 1 : uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1494 : :
1495 : 1 : dsa_op.message.data = dgst;
1496 : 1 : dsa_op.message.length = sizeof(dgst);
1497 : 1 : dsa_op.r.data = r;
1498 : 1 : dsa_op.s.data = s;
1499 : 1 : dsa_op.r.length = sizeof(r);
1500 : 1 : dsa_op.s.length = sizeof(s);
1501 : :
1502 : 1 : status = test_dsa_sign(&dsa_op);
1503 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "DSA sign test failed");
1504 : 1 : status = test_dsa_verify(&dsa_op);
1505 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "DSA verify test failed");
1506 : : return status;
1507 : : }
1508 : :
1509 : : static int
1510 : 0 : test_ecdsa_sign_verify(enum curve curve_id)
1511 : : {
1512 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1513 : 0 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
1514 : 0 : struct rte_mempool *op_mpool = ts_params->op_mpool;
1515 : : struct crypto_testsuite_ecdsa_params input_params;
1516 : 0 : void *sess = NULL;
1517 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
1518 : 0 : struct rte_crypto_op *result_op = NULL;
1519 : : uint8_t output_buf_r[TEST_DATA_SIZE];
1520 : : uint8_t output_buf_s[TEST_DATA_SIZE];
1521 : : struct rte_crypto_asym_xform xform;
1522 : : struct rte_crypto_asym_op *asym_op;
1523 : : struct rte_cryptodev_info dev_info;
1524 : 0 : struct rte_crypto_op *op = NULL;
1525 : : int ret, status = TEST_SUCCESS;
1526 : :
1527 [ # # # # : 0 : switch (curve_id) {
# # # ]
1528 : 0 : case SECP192R1:
1529 : 0 : input_params = ecdsa_param_secp192r1;
1530 : 0 : break;
1531 : 0 : case SECP224R1:
1532 : 0 : input_params = ecdsa_param_secp224r1;
1533 : 0 : break;
1534 : 0 : case SECP256R1:
1535 : 0 : input_params = ecdsa_param_secp256r1;
1536 : 0 : break;
1537 : 0 : case SECP384R1:
1538 : 0 : input_params = ecdsa_param_secp384r1;
1539 : 0 : break;
1540 : 0 : case SECP521R1:
1541 : 0 : input_params = ecdsa_param_secp521r1;
1542 : 0 : break;
1543 : 0 : case SECP521R1_UA:
1544 : 0 : input_params = ecdsa_param_secp521r1_ua;
1545 : 0 : break;
1546 : 0 : default:
1547 : 0 : RTE_LOG(ERR, USER1,
1548 : : "line %u FAILED: %s", __LINE__,
1549 : : "Unsupported curve id\n");
1550 : : status = TEST_FAILED;
1551 : 0 : goto exit;
1552 : : }
1553 : :
1554 : 0 : rte_cryptodev_info_get(dev_id, &dev_info);
1555 : :
1556 : : /* Setup crypto op data structure */
1557 : 0 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1558 [ # # ]: 0 : if (op == NULL) {
1559 : 0 : RTE_LOG(ERR, USER1,
1560 : : "line %u FAILED: %s", __LINE__,
1561 : : "Failed to allocate asymmetric crypto "
1562 : : "operation struct\n");
1563 : : status = TEST_FAILED;
1564 : 0 : goto exit;
1565 : : }
1566 : : asym_op = op->asym;
1567 : :
1568 : : /* Setup asym xform */
1569 : 0 : xform.next = NULL;
1570 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
1571 : 0 : xform.ec.curve_id = input_params.curve;
1572 : 0 : xform.ec.pkey.data = input_params.pkey.data;
1573 : 0 : xform.ec.pkey.length = input_params.pkey.length;
1574 : 0 : xform.ec.q.x.data = input_params.pubkey_qx.data;
1575 : 0 : xform.ec.q.x.length = input_params.pubkey_qx.length;
1576 : 0 : xform.ec.q.y.data = input_params.pubkey_qy.data;
1577 : 0 : xform.ec.q.y.length = input_params.pubkey_qy.length;
1578 : :
1579 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1580 [ # # ]: 0 : if (ret < 0) {
1581 : 0 : RTE_LOG(ERR, USER1,
1582 : : "line %u FAILED: %s", __LINE__,
1583 : : "Session creation failed\n");
1584 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1585 : 0 : goto exit;
1586 : : }
1587 : :
1588 : : /* Attach asymmetric crypto session to crypto operations */
1589 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
1590 : :
1591 : : /* Compute sign */
1592 : :
1593 : : /* Populate op with operational details */
1594 : 0 : op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1595 : 0 : op->asym->ecdsa.message.data = input_params.digest.data;
1596 : 0 : op->asym->ecdsa.message.length = input_params.digest.length;
1597 : 0 : op->asym->ecdsa.k.data = input_params.scalar.data;
1598 : 0 : op->asym->ecdsa.k.length = input_params.scalar.length;
1599 : :
1600 : : /* Init out buf */
1601 : 0 : op->asym->ecdsa.r.data = output_buf_r;
1602 : 0 : op->asym->ecdsa.s.data = output_buf_s;
1603 : :
1604 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
1605 : :
1606 : : /* Process crypto operation */
1607 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1608 : 0 : RTE_LOG(ERR, USER1,
1609 : : "line %u FAILED: %s", __LINE__,
1610 : : "Error sending packet for operation\n");
1611 : : status = TEST_FAILED;
1612 : 0 : goto exit;
1613 : : }
1614 : :
1615 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1616 : : rte_pause();
1617 : :
1618 [ # # ]: 0 : if (result_op == NULL) {
1619 : 0 : RTE_LOG(ERR, USER1,
1620 : : "line %u FAILED: %s", __LINE__,
1621 : : "Failed to process asym crypto op\n");
1622 : : status = TEST_FAILED;
1623 : 0 : goto exit;
1624 : : }
1625 : :
1626 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1627 : 0 : RTE_LOG(ERR, USER1,
1628 : : "line %u FAILED: %s", __LINE__,
1629 : : "Failed to process asym crypto op\n");
1630 : : status = TEST_FAILED;
1631 : 0 : goto exit;
1632 : : }
1633 : :
1634 : : asym_op = result_op->asym;
1635 : :
1636 : 0 : debug_hexdump(stdout, "r:",
1637 : 0 : asym_op->ecdsa.r.data, asym_op->ecdsa.r.length);
1638 : 0 : debug_hexdump(stdout, "s:",
1639 : 0 : asym_op->ecdsa.s.data, asym_op->ecdsa.s.length);
1640 : :
1641 : 0 : ret = verify_ecdsa_sign(input_params.sign_r.data,
1642 : : input_params.sign_s.data, result_op);
1643 [ # # ]: 0 : if (ret) {
1644 : : status = TEST_FAILED;
1645 : 0 : RTE_LOG(ERR, USER1,
1646 : : "line %u FAILED: %s", __LINE__,
1647 : : "ECDSA sign failed.\n");
1648 : 0 : goto exit;
1649 : : }
1650 : :
1651 : : /* Verify sign */
1652 : :
1653 : : /* Populate op with operational details */
1654 : 0 : op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1655 : 0 : op->asym->ecdsa.r.data = asym_op->ecdsa.r.data;
1656 : 0 : op->asym->ecdsa.r.length = asym_op->ecdsa.r.length;
1657 : 0 : op->asym->ecdsa.s.data = asym_op->ecdsa.s.data;
1658 : 0 : op->asym->ecdsa.s.length = asym_op->ecdsa.s.length;
1659 : :
1660 : : /* Enqueue sign result for verify */
1661 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1662 : : status = TEST_FAILED;
1663 : 0 : RTE_LOG(ERR, USER1,
1664 : : "line %u FAILED: %s", __LINE__,
1665 : : "Error sending packet for operation\n");
1666 : 0 : goto exit;
1667 : : }
1668 : :
1669 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1670 : : rte_pause();
1671 : :
1672 [ # # ]: 0 : if (result_op == NULL) {
1673 : : status = TEST_FAILED;
1674 : 0 : goto exit;
1675 : : }
1676 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1677 : : status = TEST_FAILED;
1678 : 0 : RTE_LOG(ERR, USER1,
1679 : : "line %u FAILED: %s", __LINE__,
1680 : : "ECDSA verify failed.\n");
1681 : 0 : goto exit;
1682 : : }
1683 : :
1684 : 0 : exit:
1685 [ # # ]: 0 : if (sess != NULL)
1686 : 0 : rte_cryptodev_asym_session_free(dev_id, sess);
1687 : 0 : rte_crypto_op_free(op);
1688 : 0 : return status;
1689 : : };
1690 : :
1691 : : static int
1692 : 0 : test_ecdsa_sign_verify_all_curve(void)
1693 : : {
1694 : : int status, overall_status = TEST_SUCCESS;
1695 : : enum curve curve_id;
1696 : : int test_index = 0;
1697 : : const char *msg;
1698 : :
1699 [ # # ]: 0 : for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
1700 : 0 : if (curve_id == ED25519 || curve_id == ED448 ||
1701 [ # # # # ]: 0 : curve_id == ECGROUP19 || curve_id == ECGROUP20 ||
1702 : : curve_id == ECGROUP21)
1703 : 0 : continue;
1704 : :
1705 : 0 : status = test_ecdsa_sign_verify(curve_id);
1706 [ # # ]: 0 : if (status == TEST_SUCCESS) {
1707 : : msg = "succeeded";
1708 : : } else {
1709 : : msg = "failed";
1710 : : overall_status = status;
1711 : : }
1712 : 0 : printf(" %u) TestCase Sign/Veriy Curve %s %s\n",
1713 : : test_index ++, curve[curve_id], msg);
1714 : : }
1715 : 0 : return overall_status;
1716 : : }
1717 : :
1718 : : static int
1719 : 0 : test_ecpm(enum curve curve_id)
1720 : : {
1721 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1722 : 0 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
1723 : 0 : struct rte_mempool *op_mpool = ts_params->op_mpool;
1724 : : struct crypto_testsuite_ecpm_params input_params;
1725 : 0 : void *sess = NULL;
1726 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
1727 : 0 : struct rte_crypto_op *result_op = NULL;
1728 : : uint8_t output_buf_x[TEST_DATA_SIZE];
1729 : : uint8_t output_buf_y[TEST_DATA_SIZE];
1730 : : struct rte_crypto_asym_xform xform;
1731 : : struct rte_crypto_asym_op *asym_op;
1732 : : struct rte_cryptodev_info dev_info;
1733 : 0 : struct rte_crypto_op *op = NULL;
1734 : : int ret, status = TEST_SUCCESS;
1735 : :
1736 [ # # # # : 0 : switch (curve_id) {
# # ]
1737 : 0 : case SECP192R1:
1738 : 0 : input_params = ecpm_param_secp192r1;
1739 : 0 : break;
1740 : 0 : case SECP224R1:
1741 : 0 : input_params = ecpm_param_secp224r1;
1742 : 0 : break;
1743 : 0 : case SECP256R1:
1744 : 0 : input_params = ecpm_param_secp256r1;
1745 : 0 : break;
1746 : 0 : case SECP384R1:
1747 : 0 : input_params = ecpm_param_secp384r1;
1748 : 0 : break;
1749 : 0 : case SECP521R1:
1750 : 0 : input_params = ecpm_param_secp521r1;
1751 : 0 : break;
1752 : 0 : default:
1753 : 0 : RTE_LOG(ERR, USER1,
1754 : : "line %u FAILED: %s", __LINE__,
1755 : : "Unsupported curve id\n");
1756 : : status = TEST_FAILED;
1757 : 0 : goto exit;
1758 : : }
1759 : :
1760 : 0 : rte_cryptodev_info_get(dev_id, &dev_info);
1761 : :
1762 : : /* Setup crypto op data structure */
1763 : 0 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1764 [ # # ]: 0 : if (op == NULL) {
1765 : 0 : RTE_LOG(ERR, USER1,
1766 : : "line %u FAILED: %s", __LINE__,
1767 : : "Failed to allocate asymmetric crypto "
1768 : : "operation struct\n");
1769 : : status = TEST_FAILED;
1770 : 0 : goto exit;
1771 : : }
1772 : : asym_op = op->asym;
1773 : :
1774 : : /* Setup asym xform */
1775 : 0 : xform.next = NULL;
1776 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
1777 : 0 : xform.ec.curve_id = input_params.curve;
1778 : :
1779 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1780 [ # # ]: 0 : if (ret < 0) {
1781 : 0 : RTE_LOG(ERR, USER1,
1782 : : "line %u FAILED: %s", __LINE__,
1783 : : "Session creation failed\n");
1784 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1785 : 0 : goto exit;
1786 : : }
1787 : :
1788 : : /* Attach asymmetric crypto session to crypto operations */
1789 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
1790 : :
1791 : : /* Populate op with operational details */
1792 : 0 : op->asym->ecpm.p.x.data = input_params.gen_x.data;
1793 : 0 : op->asym->ecpm.p.x.length = input_params.gen_x.length;
1794 : 0 : op->asym->ecpm.p.y.data = input_params.gen_y.data;
1795 : 0 : op->asym->ecpm.p.y.length = input_params.gen_y.length;
1796 : 0 : op->asym->ecpm.scalar.data = input_params.privkey.data;
1797 : 0 : op->asym->ecpm.scalar.length = input_params.privkey.length;
1798 : :
1799 : : /* Init out buf */
1800 : 0 : op->asym->ecpm.r.x.data = output_buf_x;
1801 : 0 : op->asym->ecpm.r.y.data = output_buf_y;
1802 : :
1803 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
1804 : :
1805 : : /* Process crypto operation */
1806 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1807 : 0 : RTE_LOG(ERR, USER1,
1808 : : "line %u FAILED: %s", __LINE__,
1809 : : "Error sending packet for operation\n");
1810 : : status = TEST_FAILED;
1811 : 0 : goto exit;
1812 : : }
1813 : :
1814 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1815 : : rte_pause();
1816 : :
1817 [ # # ]: 0 : if (result_op == NULL) {
1818 : 0 : RTE_LOG(ERR, USER1,
1819 : : "line %u FAILED: %s", __LINE__,
1820 : : "Failed to process asym crypto op\n");
1821 : : status = TEST_FAILED;
1822 : 0 : goto exit;
1823 : : }
1824 : :
1825 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1826 : 0 : RTE_LOG(ERR, USER1,
1827 : : "line %u FAILED: %s", __LINE__,
1828 : : "Failed to process asym crypto op\n");
1829 : : status = TEST_FAILED;
1830 : 0 : goto exit;
1831 : : }
1832 : :
1833 : : asym_op = result_op->asym;
1834 : :
1835 : 0 : debug_hexdump(stdout, "r x:",
1836 : 0 : asym_op->ecpm.r.x.data, asym_op->ecpm.r.x.length);
1837 : 0 : debug_hexdump(stdout, "r y:",
1838 : 0 : asym_op->ecpm.r.y.data, asym_op->ecpm.r.y.length);
1839 : :
1840 : 0 : ret = verify_ecpm(input_params.pubkey_x.data,
1841 : : input_params.pubkey_y.data, result_op);
1842 [ # # ]: 0 : if (ret) {
1843 : : status = TEST_FAILED;
1844 : 0 : RTE_LOG(ERR, USER1,
1845 : : "line %u FAILED: %s", __LINE__,
1846 : : "EC Point Multiplication failed.\n");
1847 : 0 : goto exit;
1848 : : }
1849 : :
1850 : 0 : exit:
1851 [ # # ]: 0 : if (sess != NULL)
1852 : 0 : rte_cryptodev_asym_session_free(dev_id, sess);
1853 : 0 : rte_crypto_op_free(op);
1854 : 0 : return status;
1855 : : }
1856 : :
1857 : : static int
1858 : 0 : test_ecpm_all_curve(void)
1859 : : {
1860 : : int status, overall_status = TEST_SUCCESS;
1861 : : enum curve curve_id;
1862 : : int test_index = 0;
1863 : : const char *msg;
1864 : :
1865 [ # # ]: 0 : for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
1866 : 0 : if (curve_id == SECP521R1_UA || curve_id == ECGROUP19 ||
1867 : : curve_id == ECGROUP20 || curve_id == ECGROUP21 ||
1868 [ # # ]: 0 : curve_id == ED25519 || curve_id == ED448)
1869 : 0 : continue;
1870 : :
1871 : 0 : status = test_ecpm(curve_id);
1872 [ # # ]: 0 : if (status == TEST_SUCCESS) {
1873 : : msg = "succeeded";
1874 : : } else {
1875 : : msg = "failed";
1876 : : overall_status = status;
1877 : : }
1878 : 0 : printf(" %u) TestCase EC Point Mul Curve %s %s\n",
1879 : : test_index ++, curve[curve_id], msg);
1880 : : }
1881 : 0 : return overall_status;
1882 : : }
1883 : :
1884 : : static int
1885 : 0 : test_ecdh_priv_key_generate(enum curve curve_id)
1886 : : {
1887 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1888 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
1889 : 0 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
1890 : 0 : struct rte_mempool *op_mpool = ts_params->op_mpool;
1891 : : struct rte_cryptodev_asym_capability_idx idx;
1892 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
1893 : 0 : struct rte_crypto_asym_xform xform = {0};
1894 : 0 : struct rte_crypto_op *result_op = NULL;
1895 : : uint8_t output_buf[TEST_DATA_SIZE];
1896 : : struct rte_crypto_asym_op *asym_op;
1897 : 0 : struct rte_crypto_op *op = NULL;
1898 : : int ret, status = TEST_SUCCESS;
1899 : : uint16_t output_buflen = 0;
1900 : 0 : void *sess = NULL;
1901 : : int curve;
1902 : :
1903 : : /* Check ECDH capability */
1904 : 0 : idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH;
1905 : 0 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
1906 [ # # ]: 0 : if (capa == NULL)
1907 : : return -ENOTSUP;
1908 : :
1909 [ # # ]: 0 : if (!(capa->op_types & (1 << RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE)))
1910 : : return -ENOTSUP;
1911 : :
1912 : : switch (curve_id) {
1913 : : case SECP192R1:
1914 : : curve = RTE_CRYPTO_EC_GROUP_SECP192R1;
1915 : : output_buflen = 24;
1916 : : break;
1917 : : case SECP224R1:
1918 : : curve = RTE_CRYPTO_EC_GROUP_SECP224R1;
1919 : : output_buflen = 28;
1920 : : break;
1921 : : case SECP256R1:
1922 : : curve = RTE_CRYPTO_EC_GROUP_SECP256R1;
1923 : : output_buflen = 32;
1924 : : break;
1925 : : case SECP384R1:
1926 : : curve = RTE_CRYPTO_EC_GROUP_SECP384R1;
1927 : : output_buflen = 48;
1928 : : break;
1929 : : case SECP521R1:
1930 : : curve = RTE_CRYPTO_EC_GROUP_SECP521R1;
1931 : : output_buflen = 66;
1932 : : break;
1933 : 0 : default:
1934 : 0 : RTE_LOG(ERR, USER1,
1935 : : "line %u FAILED: %s", __LINE__,
1936 : : "Unsupported curve id\n");
1937 : : status = TEST_FAILED;
1938 : 0 : goto exit;
1939 : : }
1940 : :
1941 : : /* Setup crypto op data structure */
1942 : 0 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1943 [ # # ]: 0 : if (op == NULL) {
1944 : 0 : RTE_LOG(ERR, USER1,
1945 : : "line %u FAILED: %s", __LINE__,
1946 : : "Failed to allocate asymmetric crypto "
1947 : : "operation struct\n");
1948 : : status = TEST_FAILED;
1949 : 0 : goto exit;
1950 : : }
1951 : : asym_op = op->asym;
1952 : :
1953 : : /* Setup asym xform */
1954 : 0 : xform.next = NULL;
1955 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
1956 : 0 : xform.ec.curve_id = curve;
1957 : :
1958 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1959 [ # # ]: 0 : if (ret < 0) {
1960 : 0 : RTE_LOG(ERR, USER1,
1961 : : "line %u FAILED: %s", __LINE__,
1962 : : "Session creation failed\n");
1963 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1964 : 0 : goto exit;
1965 : : }
1966 : :
1967 : : /* Attach asymmetric crypto session to crypto operations */
1968 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
1969 : :
1970 : : /* Populate op with operational details */
1971 : 0 : asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE;
1972 : :
1973 : : /* Init out buf */
1974 : 0 : asym_op->ecdh.priv_key.data = output_buf;
1975 : 0 : asym_op->ecdh.priv_key.length = output_buflen;
1976 : :
1977 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
1978 : :
1979 : : /* Process crypto operation */
1980 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1981 : 0 : RTE_LOG(ERR, USER1,
1982 : : "line %u FAILED: %s", __LINE__,
1983 : : "Error sending packet for operation\n");
1984 : : status = TEST_FAILED;
1985 : 0 : goto exit;
1986 : : }
1987 : :
1988 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1989 : : rte_pause();
1990 : :
1991 [ # # ]: 0 : if (result_op == NULL) {
1992 : 0 : RTE_LOG(ERR, USER1,
1993 : : "line %u FAILED: %s", __LINE__,
1994 : : "Failed to process asym crypto op\n");
1995 : : status = TEST_FAILED;
1996 : 0 : goto exit;
1997 : : }
1998 : :
1999 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2000 : 0 : RTE_LOG(ERR, USER1,
2001 : : "line %u FAILED: %s", __LINE__,
2002 : : "Failed to process asym crypto op\n");
2003 : : status = TEST_FAILED;
2004 : 0 : goto exit;
2005 : : }
2006 : :
2007 : : asym_op = result_op->asym;
2008 : :
2009 : 0 : debug_hexdump(stdout, "priv_key:",
2010 : 0 : asym_op->ecdh.priv_key.data, asym_op->ecdh.priv_key.length);
2011 : :
2012 : 0 : exit:
2013 [ # # ]: 0 : if (sess != NULL)
2014 : 0 : rte_cryptodev_asym_session_free(dev_id, sess);
2015 : 0 : rte_crypto_op_free(op);
2016 : 0 : return status;
2017 : : }
2018 : :
2019 : : static int
2020 : 0 : test_ecdh_pub_key_generate(enum curve curve_id)
2021 : : {
2022 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
2023 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
2024 : 0 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
2025 : 0 : struct rte_mempool *op_mpool = ts_params->op_mpool;
2026 : : struct crypto_testsuite_ecdh_params input_params;
2027 : : struct rte_cryptodev_asym_capability_idx idx;
2028 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
2029 : 0 : struct rte_crypto_asym_xform xform = {0};
2030 : 0 : struct rte_crypto_op *result_op = NULL;
2031 : : uint8_t output_buf_x[TEST_DATA_SIZE];
2032 : : uint8_t output_buf_y[TEST_DATA_SIZE];
2033 : : struct rte_crypto_asym_op *asym_op;
2034 : 0 : struct rte_crypto_op *op = NULL;
2035 : : int ret, status = TEST_SUCCESS;
2036 : 0 : void *sess = NULL;
2037 : :
2038 : : /* Check ECDH capability */
2039 : 0 : idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2040 : 0 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
2041 [ # # ]: 0 : if (capa == NULL)
2042 : : return TEST_SKIPPED;
2043 : :
2044 [ # # ]: 0 : if (!(capa->op_types & (1 << RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE)))
2045 : : return TEST_SKIPPED;
2046 : :
2047 [ # # ]: 0 : if (curve_id == ED25519 || curve_id == ED448) {
2048 : : /* Check EdDSA capability */
2049 : 0 : idx.type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
2050 : 0 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
2051 [ # # ]: 0 : if (capa == NULL)
2052 : : return TEST_SKIPPED;
2053 : : }
2054 : :
2055 [ # # # # : 0 : switch (curve_id) {
# # # # #
# # ]
2056 : 0 : case SECP192R1:
2057 : 0 : input_params = ecdh_param_secp192r1;
2058 : 0 : break;
2059 : 0 : case SECP224R1:
2060 : 0 : input_params = ecdh_param_secp224r1;
2061 : 0 : break;
2062 : 0 : case SECP256R1:
2063 : 0 : input_params = ecdh_param_secp256r1;
2064 : 0 : break;
2065 : 0 : case SECP384R1:
2066 : 0 : input_params = ecdh_param_secp384r1;
2067 : 0 : break;
2068 : 0 : case SECP521R1:
2069 : 0 : input_params = ecdh_param_secp521r1;
2070 : 0 : break;
2071 : 0 : case ECGROUP19:
2072 : 0 : input_params = ecdh_param_group19;
2073 : 0 : break;
2074 : 0 : case ECGROUP20:
2075 : 0 : input_params = ecdh_param_group20;
2076 : 0 : break;
2077 : 0 : case ECGROUP21:
2078 : 0 : input_params = ecdh_param_group21;
2079 : 0 : break;
2080 : 0 : case ED25519:
2081 : 0 : input_params = ecdh_param_ed25519;
2082 : 0 : break;
2083 : 0 : case ED448:
2084 : 0 : input_params = ecdh_param_ed448;
2085 : 0 : break;
2086 : 0 : default:
2087 : 0 : RTE_LOG(ERR, USER1,
2088 : : "line %u FAILED: %s", __LINE__,
2089 : : "Unsupported curve id\n");
2090 : : status = TEST_FAILED;
2091 : 0 : goto exit;
2092 : : }
2093 : :
2094 : 0 : debug_hexdump(stdout, "pkey:",
2095 : : input_params.pkey_A.data, input_params.pkey_A.length);
2096 : :
2097 : : /* Setup crypto op data structure */
2098 : 0 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2099 [ # # ]: 0 : if (op == NULL) {
2100 : 0 : RTE_LOG(ERR, USER1,
2101 : : "line %u FAILED: %s", __LINE__,
2102 : : "Failed to allocate asymmetric crypto "
2103 : : "operation struct\n");
2104 : : status = TEST_FAILED;
2105 : 0 : goto exit;
2106 : : }
2107 : : asym_op = op->asym;
2108 : :
2109 : : /* Setup asym xform */
2110 : 0 : xform.next = NULL;
2111 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2112 : 0 : xform.ec.curve_id = input_params.curve;
2113 : 0 : xform.ec.pkey.data = input_params.pkey_A.data;
2114 : 0 : xform.ec.pkey.length = input_params.pkey_A.length;
2115 : :
2116 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2117 [ # # ]: 0 : if (ret < 0) {
2118 : 0 : RTE_LOG(ERR, USER1,
2119 : : "line %u FAILED: %s", __LINE__,
2120 : : "Session creation failed\n");
2121 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2122 : 0 : goto exit;
2123 : : }
2124 : :
2125 : : /* Attach asymmetric crypto session to crypto operations */
2126 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
2127 : :
2128 : : /* Populate op with operational details */
2129 : 0 : asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
2130 [ # # ]: 0 : if (curve_id == ED25519 || curve_id == ED448)
2131 : 0 : asym_op->flags |= RTE_CRYPTO_ASYM_FLAG_PUB_KEY_COMPRESSED;
2132 : :
2133 : : /* Init out buf */
2134 : 0 : asym_op->ecdh.pub_key.x.data = output_buf_x;
2135 [ # # ]: 0 : if (curve_id == ED25519 || curve_id == ED448)
2136 : 0 : asym_op->ecdh.pub_key.y.data = NULL;
2137 : : else
2138 : 0 : asym_op->ecdh.pub_key.y.data = output_buf_y;
2139 : :
2140 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2141 : :
2142 : : /* Process crypto operation */
2143 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2144 : 0 : RTE_LOG(ERR, USER1,
2145 : : "line %u FAILED: %s", __LINE__,
2146 : : "Error sending packet for operation\n");
2147 : : status = TEST_FAILED;
2148 : 0 : goto exit;
2149 : : }
2150 : :
2151 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2152 : : rte_pause();
2153 : :
2154 [ # # ]: 0 : if (result_op == NULL) {
2155 : 0 : RTE_LOG(ERR, USER1,
2156 : : "line %u FAILED: %s", __LINE__,
2157 : : "Failed to process asym crypto op\n");
2158 : : status = TEST_FAILED;
2159 : 0 : goto exit;
2160 : : }
2161 : :
2162 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2163 : 0 : RTE_LOG(ERR, USER1,
2164 : : "line %u FAILED: %s", __LINE__,
2165 : : "Failed to process asym crypto op\n");
2166 : : status = TEST_FAILED;
2167 : 0 : goto exit;
2168 : : }
2169 : :
2170 : : asym_op = result_op->asym;
2171 : :
2172 : 0 : debug_hexdump(stdout, "qx:",
2173 : 0 : asym_op->ecdh.pub_key.x.data, asym_op->ecdh.pub_key.x.length);
2174 : 0 : debug_hexdump(stdout, "qy:",
2175 : 0 : asym_op->ecdh.pub_key.y.data, asym_op->ecdh.pub_key.y.length);
2176 : :
2177 [ # # ]: 0 : if (curve_id == ED25519 || curve_id == ED448)
2178 : 0 : ret = memcmp(input_params.pubkey_qA_x.data, result_op->asym->ecdh.pub_key.x.data,
2179 : 0 : result_op->asym->ecdh.pub_key.x.length);
2180 : : else
2181 : 0 : ret = verify_ecdh_secret(input_params.pubkey_qA_x.data,
2182 : : input_params.pubkey_qA_y.data, result_op);
2183 : :
2184 [ # # ]: 0 : if (ret) {
2185 : : status = TEST_FAILED;
2186 : 0 : RTE_LOG(ERR, USER1,
2187 : : "line %u FAILED: %s", __LINE__,
2188 : : "ECDH public key generation failed.\n");
2189 : 0 : goto exit;
2190 : : }
2191 : :
2192 : 0 : exit:
2193 [ # # ]: 0 : if (sess != NULL)
2194 : 0 : rte_cryptodev_asym_session_free(dev_id, sess);
2195 : 0 : rte_crypto_op_free(op);
2196 : 0 : return status;
2197 : : }
2198 : :
2199 : : static int
2200 : 0 : test_ecdh_pub_key_verify(enum curve curve_id)
2201 : : {
2202 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
2203 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
2204 : 0 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
2205 : 0 : struct rte_mempool *op_mpool = ts_params->op_mpool;
2206 : : struct crypto_testsuite_ecdh_params input_params;
2207 : : struct rte_cryptodev_asym_capability_idx idx;
2208 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
2209 : 0 : struct rte_crypto_asym_xform xform = {0};
2210 : 0 : struct rte_crypto_op *result_op = NULL;
2211 : : struct rte_crypto_asym_op *asym_op;
2212 : 0 : struct rte_crypto_op *op = NULL;
2213 : : int ret, status = TEST_SUCCESS;
2214 : 0 : void *sess = NULL;
2215 : :
2216 : : /* Check ECDH capability */
2217 : 0 : idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2218 : 0 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
2219 [ # # ]: 0 : if (capa == NULL)
2220 : : return -ENOTSUP;
2221 : :
2222 [ # # ]: 0 : if (!(capa->op_types & (1 << RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY)))
2223 : : return -ENOTSUP;
2224 : :
2225 [ # # # # : 0 : switch (curve_id) {
# # # #
# ]
2226 : 0 : case SECP192R1:
2227 : 0 : input_params = ecdh_param_secp192r1;
2228 : 0 : break;
2229 : 0 : case SECP224R1:
2230 : 0 : input_params = ecdh_param_secp224r1;
2231 : 0 : break;
2232 : 0 : case SECP256R1:
2233 : 0 : input_params = ecdh_param_secp256r1;
2234 : 0 : break;
2235 : 0 : case SECP384R1:
2236 : 0 : input_params = ecdh_param_secp384r1;
2237 : 0 : break;
2238 : 0 : case SECP521R1:
2239 : 0 : input_params = ecdh_param_secp521r1;
2240 : 0 : break;
2241 : 0 : case ECGROUP19:
2242 : 0 : input_params = ecdh_param_group19;
2243 : 0 : break;
2244 : 0 : case ECGROUP20:
2245 : 0 : input_params = ecdh_param_group20;
2246 : 0 : break;
2247 : 0 : case ECGROUP21:
2248 : 0 : input_params = ecdh_param_group21;
2249 : 0 : break;
2250 : 0 : default:
2251 : 0 : RTE_LOG(ERR, USER1,
2252 : : "line %u FAILED: %s", __LINE__,
2253 : : "Unsupported curve id\n");
2254 : : status = TEST_FAILED;
2255 : 0 : goto exit;
2256 : : }
2257 : :
2258 : 0 : debug_hexdump(stdout, "qx:",
2259 : : input_params.pubkey_qA_x.data, input_params.pubkey_qA_x.length);
2260 : 0 : debug_hexdump(stdout, "qy:",
2261 : : input_params.pubkey_qA_y.data, input_params.pubkey_qA_y.length);
2262 : :
2263 : : /* Setup crypto op data structure */
2264 : 0 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2265 [ # # ]: 0 : if (op == NULL) {
2266 : 0 : RTE_LOG(ERR, USER1,
2267 : : "line %u FAILED: %s", __LINE__,
2268 : : "Failed to allocate asymmetric crypto "
2269 : : "operation struct\n");
2270 : : status = TEST_FAILED;
2271 : 0 : goto exit;
2272 : : }
2273 : : asym_op = op->asym;
2274 : :
2275 : : /* Setup asym xform */
2276 : 0 : xform.next = NULL;
2277 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2278 : 0 : xform.ec.curve_id = input_params.curve;
2279 : :
2280 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2281 [ # # ]: 0 : if (ret < 0) {
2282 : 0 : RTE_LOG(ERR, USER1,
2283 : : "line %u FAILED: %s", __LINE__,
2284 : : "Session creation failed\n");
2285 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2286 : 0 : goto exit;
2287 : : }
2288 : :
2289 : : /* Attach asymmetric crypto session to crypto operations */
2290 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
2291 : :
2292 : : /* Populate op with operational details */
2293 : 0 : asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY;
2294 : 0 : asym_op->ecdh.pub_key.x.data = input_params.pubkey_qA_x.data;
2295 : 0 : asym_op->ecdh.pub_key.x.length = input_params.pubkey_qA_x.length;
2296 : 0 : asym_op->ecdh.pub_key.y.data = input_params.pubkey_qA_y.data;
2297 : 0 : asym_op->ecdh.pub_key.y.length = input_params.pubkey_qA_y.length;
2298 : :
2299 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2300 : :
2301 : : /* Process crypto operation */
2302 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2303 : 0 : RTE_LOG(ERR, USER1,
2304 : : "line %u FAILED: %s", __LINE__,
2305 : : "Error sending packet for operation\n");
2306 : : status = TEST_FAILED;
2307 : 0 : goto exit;
2308 : : }
2309 : :
2310 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2311 : : rte_pause();
2312 : :
2313 [ # # ]: 0 : if (result_op == NULL) {
2314 : 0 : RTE_LOG(ERR, USER1,
2315 : : "line %u FAILED: %s", __LINE__,
2316 : : "Failed to process asym crypto op\n");
2317 : : status = TEST_FAILED;
2318 : 0 : goto exit;
2319 : : }
2320 : :
2321 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2322 : 0 : RTE_LOG(ERR, USER1,
2323 : : "line %u FAILED: %s", __LINE__,
2324 : : "Failed to process asym crypto op\n");
2325 : : status = TEST_FAILED;
2326 : 0 : goto exit;
2327 : : }
2328 : :
2329 : 0 : exit:
2330 [ # # ]: 0 : if (sess != NULL)
2331 : 0 : rte_cryptodev_asym_session_free(dev_id, sess);
2332 : 0 : rte_crypto_op_free(op);
2333 : 0 : return status;
2334 : : }
2335 : :
2336 : : static int
2337 : 0 : test_ecdh_shared_secret(enum curve curve_id)
2338 : : {
2339 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
2340 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
2341 : 0 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
2342 : 0 : struct rte_mempool *op_mpool = ts_params->op_mpool;
2343 : : struct crypto_testsuite_ecdh_params input_params;
2344 : : struct rte_cryptodev_asym_capability_idx idx;
2345 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
2346 : 0 : struct rte_crypto_asym_xform xform = {0};
2347 : 0 : struct rte_crypto_op *result_op = NULL;
2348 : : uint8_t output_buf_x[TEST_DATA_SIZE];
2349 : : uint8_t output_buf_y[TEST_DATA_SIZE];
2350 : : struct rte_crypto_asym_op *asym_op;
2351 : 0 : struct rte_crypto_op *op = NULL;
2352 : : int ret, status = TEST_SUCCESS;
2353 : 0 : void *sess = NULL;
2354 : :
2355 : : /* Check ECDH capability */
2356 : 0 : idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2357 : 0 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
2358 [ # # ]: 0 : if (capa == NULL)
2359 : : return -ENOTSUP;
2360 : :
2361 [ # # ]: 0 : if (!(capa->op_types & (1 << RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE)))
2362 : : return -ENOTSUP;
2363 : :
2364 [ # # # # : 0 : switch (curve_id) {
# # # #
# ]
2365 : 0 : case SECP192R1:
2366 : 0 : input_params = ecdh_param_secp192r1;
2367 : 0 : break;
2368 : 0 : case SECP224R1:
2369 : 0 : input_params = ecdh_param_secp224r1;
2370 : 0 : break;
2371 : 0 : case SECP256R1:
2372 : 0 : input_params = ecdh_param_secp256r1;
2373 : 0 : break;
2374 : 0 : case SECP384R1:
2375 : 0 : input_params = ecdh_param_secp384r1;
2376 : 0 : break;
2377 : 0 : case SECP521R1:
2378 : 0 : input_params = ecdh_param_secp521r1;
2379 : 0 : break;
2380 : 0 : case ECGROUP19:
2381 : 0 : input_params = ecdh_param_group19;
2382 : 0 : break;
2383 : 0 : case ECGROUP20:
2384 : 0 : input_params = ecdh_param_group20;
2385 : 0 : break;
2386 : 0 : case ECGROUP21:
2387 : 0 : input_params = ecdh_param_group21;
2388 : 0 : break;
2389 : 0 : default:
2390 : 0 : RTE_LOG(ERR, USER1,
2391 : : "line %u FAILED: %s", __LINE__,
2392 : : "Unsupported curve id\n");
2393 : : status = TEST_FAILED;
2394 : 0 : goto exit;
2395 : : }
2396 : :
2397 : : /* zA = dA.QB */
2398 : 0 : debug_hexdump(stdout, "pkey:",
2399 : : input_params.pkey_A.data, input_params.pkey_A.length);
2400 : 0 : debug_hexdump(stdout, "qx:",
2401 : : input_params.pubkey_qB_x.data, input_params.pubkey_qB_x.length);
2402 : 0 : debug_hexdump(stdout, "qy:",
2403 : : input_params.pubkey_qB_y.data, input_params.pubkey_qB_y.length);
2404 : :
2405 : : /* Setup crypto op data structure */
2406 : 0 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2407 [ # # ]: 0 : if (op == NULL) {
2408 : 0 : RTE_LOG(ERR, USER1,
2409 : : "line %u FAILED: %s", __LINE__,
2410 : : "Failed to allocate asymmetric crypto "
2411 : : "operation struct\n");
2412 : : status = TEST_FAILED;
2413 : 0 : goto exit;
2414 : : }
2415 : : asym_op = op->asym;
2416 : :
2417 : : /* Setup asym xform */
2418 : 0 : xform.next = NULL;
2419 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2420 : 0 : xform.ec.curve_id = input_params.curve;
2421 : 0 : xform.ec.pkey.data = input_params.pkey_A.data;
2422 : 0 : xform.ec.pkey.length = input_params.pkey_A.length;
2423 : 0 : xform.ec.q.x.data = input_params.pubkey_qB_x.data;
2424 : 0 : xform.ec.q.x.length = input_params.pubkey_qB_x.length;
2425 : 0 : xform.ec.q.y.data = input_params.pubkey_qB_y.data;
2426 : 0 : xform.ec.q.y.length = input_params.pubkey_qB_y.length;
2427 : :
2428 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2429 [ # # ]: 0 : if (ret < 0) {
2430 : 0 : RTE_LOG(ERR, USER1,
2431 : : "line %u FAILED: %s", __LINE__,
2432 : : "Session creation failed\n");
2433 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2434 : 0 : goto exit;
2435 : : }
2436 : :
2437 : : /* Attach asymmetric crypto session to crypto operations */
2438 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
2439 : :
2440 : : /* Populate op with operational details */
2441 : 0 : asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE;
2442 : :
2443 : : /* Init out buf */
2444 : 0 : asym_op->ecdh.shared_secret.x.data = output_buf_x;
2445 : 0 : asym_op->ecdh.shared_secret.y.data = output_buf_y;
2446 : :
2447 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2448 : :
2449 : : /* Process crypto operation */
2450 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2451 : 0 : RTE_LOG(ERR, USER1,
2452 : : "line %u FAILED: %s", __LINE__,
2453 : : "Error sending packet for operation\n");
2454 : : status = TEST_FAILED;
2455 : 0 : goto exit;
2456 : : }
2457 : :
2458 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2459 : : rte_pause();
2460 : :
2461 [ # # ]: 0 : if (result_op == NULL) {
2462 : 0 : RTE_LOG(ERR, USER1,
2463 : : "line %u FAILED: %s", __LINE__,
2464 : : "Failed to process asym crypto op\n");
2465 : : status = TEST_FAILED;
2466 : 0 : goto exit;
2467 : : }
2468 : :
2469 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2470 : 0 : RTE_LOG(ERR, USER1,
2471 : : "line %u FAILED: %s", __LINE__,
2472 : : "Failed to process asym crypto op\n");
2473 : : status = TEST_FAILED;
2474 : 0 : goto exit;
2475 : : }
2476 : :
2477 : : asym_op = result_op->asym;
2478 : :
2479 : 0 : debug_hexdump(stdout, "secret_x:",
2480 : 0 : asym_op->ecdh.shared_secret.x.data, asym_op->ecdh.shared_secret.x.length);
2481 : 0 : debug_hexdump(stdout, "secret_y:",
2482 : 0 : asym_op->ecdh.shared_secret.y.data, asym_op->ecdh.shared_secret.y.length);
2483 : :
2484 : 0 : ret = verify_ecdh_secret(input_params.secret_x.data,
2485 : : input_params.secret_y.data, result_op);
2486 [ # # ]: 0 : if (ret) {
2487 : : status = TEST_FAILED;
2488 : 0 : RTE_LOG(ERR, USER1,
2489 : : "line %u FAILED: %s", __LINE__,
2490 : : "ECDH shared secret compute failed.\n");
2491 : 0 : goto exit;
2492 : : }
2493 : :
2494 [ # # ]: 0 : if (sess != NULL)
2495 : 0 : rte_cryptodev_asym_session_free(dev_id, sess);
2496 : 0 : rte_crypto_op_free(op);
2497 : :
2498 : : /* zB = dB.QA */
2499 : 0 : debug_hexdump(stdout, "pkey:",
2500 : : input_params.pkey_B.data, input_params.pkey_B.length);
2501 : 0 : debug_hexdump(stdout, "qx:",
2502 : : input_params.pubkey_qA_x.data, input_params.pubkey_qA_x.length);
2503 : 0 : debug_hexdump(stdout, "qy:",
2504 : : input_params.pubkey_qA_y.data, input_params.pubkey_qA_y.length);
2505 : :
2506 : : /* Setup crypto op data structure */
2507 : 0 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2508 [ # # ]: 0 : if (op == NULL) {
2509 : 0 : RTE_LOG(ERR, USER1,
2510 : : "line %u FAILED: %s", __LINE__,
2511 : : "Failed to allocate asymmetric crypto "
2512 : : "operation struct\n");
2513 : : status = TEST_FAILED;
2514 : 0 : goto exit;
2515 : : }
2516 : : asym_op = op->asym;
2517 : :
2518 : : /* Setup asym xform */
2519 : 0 : xform.next = NULL;
2520 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2521 : 0 : xform.ec.curve_id = input_params.curve;
2522 : 0 : xform.ec.pkey.data = input_params.pkey_B.data;
2523 : 0 : xform.ec.pkey.length = input_params.pkey_B.length;
2524 : 0 : xform.ec.q.x.data = input_params.pubkey_qA_x.data;
2525 : 0 : xform.ec.q.x.length = input_params.pubkey_qA_x.length;
2526 : 0 : xform.ec.q.y.data = input_params.pubkey_qA_y.data;
2527 : 0 : xform.ec.q.y.length = input_params.pubkey_qA_y.length;
2528 : :
2529 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2530 [ # # ]: 0 : if (ret < 0) {
2531 : 0 : RTE_LOG(ERR, USER1,
2532 : : "line %u FAILED: %s", __LINE__,
2533 : : "Session creation failed\n");
2534 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2535 : 0 : goto exit;
2536 : : }
2537 : :
2538 : : /* Attach asymmetric crypto session to crypto operations */
2539 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
2540 : :
2541 : : /* Populate op with operational details */
2542 : 0 : asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE;
2543 : :
2544 : : /* Init out buf */
2545 : 0 : asym_op->ecdh.shared_secret.x.data = output_buf_x;
2546 : 0 : asym_op->ecdh.shared_secret.y.data = output_buf_y;
2547 : :
2548 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2549 : :
2550 : : /* Process crypto operation */
2551 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2552 : 0 : RTE_LOG(ERR, USER1,
2553 : : "line %u FAILED: %s", __LINE__,
2554 : : "Error sending packet for operation\n");
2555 : : status = TEST_FAILED;
2556 : 0 : goto exit;
2557 : : }
2558 : :
2559 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2560 : : rte_pause();
2561 : :
2562 [ # # ]: 0 : if (result_op == NULL) {
2563 : 0 : RTE_LOG(ERR, USER1,
2564 : : "line %u FAILED: %s", __LINE__,
2565 : : "Failed to process asym crypto op\n");
2566 : : status = TEST_FAILED;
2567 : 0 : goto exit;
2568 : : }
2569 : :
2570 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2571 : 0 : RTE_LOG(ERR, USER1,
2572 : : "line %u FAILED: %s", __LINE__,
2573 : : "Failed to process asym crypto op\n");
2574 : : status = TEST_FAILED;
2575 : 0 : goto exit;
2576 : : }
2577 : :
2578 : : asym_op = result_op->asym;
2579 : :
2580 : 0 : debug_hexdump(stdout, "secret_x:",
2581 : 0 : asym_op->ecdh.shared_secret.x.data, asym_op->ecdh.shared_secret.x.length);
2582 : 0 : debug_hexdump(stdout, "secret_y:",
2583 : 0 : asym_op->ecdh.shared_secret.y.data, asym_op->ecdh.shared_secret.y.length);
2584 : :
2585 : 0 : ret = verify_ecdh_secret(input_params.secret_x.data,
2586 : : input_params.secret_y.data, result_op);
2587 [ # # ]: 0 : if (ret) {
2588 : : status = TEST_FAILED;
2589 : 0 : RTE_LOG(ERR, USER1,
2590 : : "line %u FAILED: %s", __LINE__,
2591 : : "ECDH shared secret compute failed.\n");
2592 : 0 : goto exit;
2593 : : }
2594 : :
2595 : 0 : exit:
2596 [ # # ]: 0 : if (sess != NULL)
2597 : 0 : rte_cryptodev_asym_session_free(dev_id, sess);
2598 : 0 : rte_crypto_op_free(op);
2599 : 0 : return status;
2600 : : }
2601 : :
2602 : : static int
2603 : 0 : test_ecdh_all_curve(void)
2604 : : {
2605 : : int status, overall_status = TEST_SUCCESS;
2606 : : enum curve curve_id;
2607 : : int test_index = 0;
2608 : : const char *msg;
2609 : :
2610 [ # # ]: 0 : for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2611 : 0 : if (curve_id == SECP521R1_UA || curve_id == ECGROUP19 ||
2612 : : curve_id == ECGROUP20 || curve_id == ECGROUP21 ||
2613 [ # # ]: 0 : curve_id == ED25519 || curve_id == ED448)
2614 : 0 : continue;
2615 : :
2616 : 0 : status = test_ecdh_priv_key_generate(curve_id);
2617 [ # # ]: 0 : if (status == TEST_SUCCESS) {
2618 : : msg = "succeeded";
2619 : : } else {
2620 : : msg = "failed";
2621 : : overall_status = status;
2622 : : }
2623 : 0 : printf(" %u) TestCase ECDH private key generation for Curve %s %s\n",
2624 : : test_index ++, curve[curve_id], msg);
2625 : : }
2626 : :
2627 [ # # ]: 0 : for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2628 [ # # ]: 0 : if (curve_id == SECP521R1_UA)
2629 : 0 : continue;
2630 : :
2631 : 0 : status = test_ecdh_pub_key_generate(curve_id);
2632 [ # # ]: 0 : if (status == TEST_SUCCESS) {
2633 : : msg = "succeeded";
2634 [ # # ]: 0 : } else if (status == TEST_SKIPPED) {
2635 : : msg = "skipped";
2636 : : } else {
2637 : : msg = "failed";
2638 : : overall_status = status;
2639 : : }
2640 : 0 : printf(" %u) TestCase ECDH public key generation for Curve %s %s\n",
2641 : : test_index ++, curve[curve_id], msg);
2642 : : }
2643 : :
2644 [ # # ]: 0 : for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2645 [ # # # # ]: 0 : if (curve_id == SECP521R1_UA || curve_id == ED25519 || curve_id == ED448)
2646 : 0 : continue;
2647 : :
2648 : 0 : status = test_ecdh_pub_key_verify(curve_id);
2649 [ # # ]: 0 : if (status == TEST_SUCCESS) {
2650 : : msg = "succeeded";
2651 : : } else {
2652 : : msg = "failed";
2653 : : overall_status = status;
2654 : : }
2655 : 0 : printf(" %u) TestCase ECDH public key verification for Curve %s %s\n",
2656 : : test_index ++, curve[curve_id], msg);
2657 : : }
2658 : :
2659 [ # # ]: 0 : for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2660 [ # # # # ]: 0 : if (curve_id == SECP521R1_UA || curve_id == ED25519 || curve_id == ED448)
2661 : 0 : continue;
2662 : :
2663 : 0 : status = test_ecdh_shared_secret(curve_id);
2664 [ # # ]: 0 : if (status == TEST_SUCCESS) {
2665 : : msg = "succeeded";
2666 : : } else {
2667 : : msg = "failed";
2668 : : overall_status = status;
2669 : : }
2670 : 0 : printf(" %u) TestCase ECDH shared secret compute for Curve %s %s\n",
2671 : : test_index ++, curve[curve_id], msg);
2672 : : }
2673 : :
2674 : 0 : return overall_status;
2675 : : }
2676 : :
2677 : : static int
2678 : 1 : test_sm2_sign(void)
2679 : : {
2680 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
2681 : 1 : struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
2682 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
2683 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
2684 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
2685 : : struct rte_cryptodev_asym_capability_idx idx;
2686 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
2687 : 1 : struct rte_crypto_op *result_op = NULL;
2688 : : uint8_t output_buf_r[TEST_DATA_SIZE];
2689 : : uint8_t output_buf_s[TEST_DATA_SIZE];
2690 : : struct rte_crypto_asym_xform xform;
2691 : : struct rte_crypto_asym_op *asym_op;
2692 : 1 : struct rte_crypto_op *op = NULL;
2693 : : int ret, status = TEST_SUCCESS;
2694 : 1 : void *sess = NULL;
2695 : :
2696 : : /* Check SM2 capability */
2697 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
2698 : 1 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
2699 [ + - ]: 1 : if (capa == NULL)
2700 : : return -ENOTSUP;
2701 : :
2702 : : /* Setup crypto op data structure */
2703 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2704 [ - + ]: 1 : if (op == NULL) {
2705 : 0 : RTE_LOG(ERR, USER1,
2706 : : "line %u FAILED: %s", __LINE__,
2707 : : "Failed to allocate asymmetric crypto "
2708 : : "operation struct\n");
2709 : : status = TEST_FAILED;
2710 : 0 : goto exit;
2711 : : }
2712 : :
2713 : : asym_op = op->asym;
2714 : :
2715 : : /* Setup asym xform */
2716 : 1 : xform.next = NULL;
2717 : 1 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
2718 : 1 : xform.ec.curve_id = input_params.curve;
2719 : 1 : xform.ec.pkey.data = input_params.pkey.data;
2720 : 1 : xform.ec.pkey.length = input_params.pkey.length;
2721 : 1 : xform.ec.q.x.data = input_params.pubkey_qx.data;
2722 : 1 : xform.ec.q.x.length = input_params.pubkey_qx.length;
2723 : 1 : xform.ec.q.y.data = input_params.pubkey_qy.data;
2724 : 1 : xform.ec.q.y.length = input_params.pubkey_qy.length;
2725 : :
2726 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2727 [ - + ]: 1 : if (ret < 0) {
2728 : 0 : RTE_LOG(ERR, USER1,
2729 : : "line %u FAILED: %s", __LINE__,
2730 : : "Session creation failed\n");
2731 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2732 : 0 : goto exit;
2733 : : }
2734 : :
2735 : : /* Attach asymmetric crypto session to crypto operations */
2736 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
2737 : :
2738 : : /* Compute sign */
2739 : :
2740 : : /* Populate op with operational details */
2741 : 1 : asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
2742 [ + - ]: 1 : if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
2743 : : RTE_CRYPTO_ASYM_OP_SIGN, RTE_CRYPTO_SM2_PH))
2744 : 1 : asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
2745 : : else
2746 : 0 : asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
2747 : :
2748 [ + - ]: 1 : if (asym_op->sm2.hash == RTE_CRYPTO_AUTH_SM3) {
2749 : 1 : asym_op->sm2.message.data = input_params.message.data;
2750 : 1 : asym_op->sm2.message.length = input_params.message.length;
2751 : 1 : asym_op->sm2.id.data = input_params.id.data;
2752 : 1 : asym_op->sm2.id.length = input_params.id.length;
2753 : : } else {
2754 : 0 : asym_op->sm2.message.data = input_params.digest.data;
2755 : 0 : asym_op->sm2.message.length = input_params.digest.length;
2756 : 0 : asym_op->sm2.id.data = NULL;
2757 : 0 : asym_op->sm2.id.length = 0;
2758 : : }
2759 : :
2760 [ + - ]: 1 : if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
2761 : : RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_RNG)) {
2762 : 1 : asym_op->sm2.k.data = NULL;
2763 : 1 : asym_op->sm2.k.length = 0;
2764 : : } else {
2765 : 0 : asym_op->sm2.k.data = input_params.k.data;
2766 : 0 : asym_op->sm2.k.length = input_params.k.length;
2767 : : }
2768 : :
2769 : : /* Init out buf */
2770 : 1 : asym_op->sm2.r.data = output_buf_r;
2771 : 1 : asym_op->sm2.s.data = output_buf_s;
2772 : :
2773 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2774 : :
2775 : : /* Process crypto operation */
2776 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2777 : 0 : RTE_LOG(ERR, USER1,
2778 : : "line %u FAILED: %s", __LINE__,
2779 : : "Error sending packet for operation\n");
2780 : : status = TEST_FAILED;
2781 : 0 : goto exit;
2782 : : }
2783 : :
2784 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2785 : : rte_pause();
2786 : :
2787 [ - + ]: 1 : if (result_op == NULL) {
2788 : 0 : RTE_LOG(ERR, USER1,
2789 : : "line %u FAILED: %s", __LINE__,
2790 : : "Failed to process asym crypto op\n");
2791 : : status = TEST_FAILED;
2792 : 0 : goto exit;
2793 : : }
2794 : :
2795 [ - + ]: 1 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2796 : 0 : RTE_LOG(ERR, USER1,
2797 : : "line %u FAILED: %s", __LINE__,
2798 : : "Failed to process asym crypto op\n");
2799 : : status = TEST_FAILED;
2800 : 0 : goto exit;
2801 : : }
2802 : :
2803 : : asym_op = result_op->asym;
2804 : :
2805 : 1 : debug_hexdump(stdout, "r:",
2806 : 1 : asym_op->sm2.r.data, asym_op->sm2.r.length);
2807 : 1 : debug_hexdump(stdout, "s:",
2808 : 1 : asym_op->sm2.s.data, asym_op->sm2.s.length);
2809 : :
2810 [ - + ]: 1 : if (!rte_cryptodev_asym_xform_capability_check_opcap(capa,
2811 : : RTE_CRYPTO_ASYM_OP_SIGN, RTE_CRYPTO_SM2_RNG)) {
2812 : : /* Verify sign (by comparison). */
2813 [ # # ]: 0 : if (memcmp(input_params.sign_r.data, asym_op->sm2.r.data,
2814 : : asym_op->sm2.r.length) != 0) {
2815 : : status = TEST_FAILED;
2816 : 0 : RTE_LOG(ERR, USER1,
2817 : : "line %u FAILED: %s", __LINE__,
2818 : : "SM2 sign failed.\n");
2819 : 0 : goto exit;
2820 : : }
2821 [ # # ]: 0 : if (memcmp(input_params.sign_s.data, asym_op->sm2.s.data,
2822 : : asym_op->sm2.s.length) != 0) {
2823 : : status = TEST_FAILED;
2824 : 0 : RTE_LOG(ERR, USER1,
2825 : : "line %u FAILED: %s", __LINE__,
2826 : : "SM2 sign failed.\n");
2827 : 0 : goto exit;
2828 : : }
2829 : : } else {
2830 : : /* Verify sign (in roundtrip).
2831 : : * Due to random number used per message, sign op
2832 : : * would produce different output for same message
2833 : : * every time. Hence, we can't have expected output
2834 : : * to match, instead reverse op to verify.
2835 : : */
2836 : :
2837 : : /* Populate op with operational details */
2838 : 1 : asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
2839 : :
2840 : : /* Enqueue sign result for verify */
2841 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2842 : : status = TEST_FAILED;
2843 : 0 : RTE_LOG(ERR, USER1,
2844 : : "line %u FAILED: %s", __LINE__,
2845 : : "Error sending packet for operation\n");
2846 : 0 : goto exit;
2847 : : }
2848 : :
2849 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2850 : : rte_pause();
2851 : :
2852 [ - + ]: 1 : if (result_op == NULL) {
2853 : : status = TEST_FAILED;
2854 : 0 : goto exit;
2855 : : }
2856 [ + - ]: 1 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2857 : : status = TEST_FAILED;
2858 : 0 : RTE_LOG(ERR, USER1,
2859 : : "line %u FAILED: %s", __LINE__,
2860 : : "SM2 verify failed.\n");
2861 : 0 : goto exit;
2862 : : }
2863 : : }
2864 : :
2865 : 1 : exit:
2866 [ + - ]: 1 : if (sess != NULL)
2867 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
2868 : 1 : rte_crypto_op_free(op);
2869 : 1 : return status;
2870 : : };
2871 : :
2872 : : static int
2873 : 1 : test_sm2_verify(void)
2874 : : {
2875 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
2876 : 1 : struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
2877 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
2878 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
2879 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
2880 : : struct rte_cryptodev_asym_capability_idx idx;
2881 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
2882 : 1 : struct rte_crypto_op *result_op = NULL;
2883 : : struct rte_crypto_asym_xform xform;
2884 : : struct rte_crypto_asym_op *asym_op;
2885 : 1 : struct rte_crypto_op *op = NULL;
2886 : : int ret, status = TEST_SUCCESS;
2887 : 1 : void *sess = NULL;
2888 : :
2889 : : /* Check SM2 capability */
2890 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
2891 : 1 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
2892 [ + - ]: 1 : if (capa == NULL)
2893 : : return -ENOTSUP;
2894 : :
2895 : : /* Setup crypto op data structure */
2896 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2897 [ - + ]: 1 : if (op == NULL) {
2898 : 0 : RTE_LOG(ERR, USER1,
2899 : : "line %u FAILED: %s", __LINE__,
2900 : : "Failed to allocate asymmetric crypto "
2901 : : "operation struct\n");
2902 : : status = TEST_FAILED;
2903 : 0 : goto exit;
2904 : : }
2905 : :
2906 : : asym_op = op->asym;
2907 : :
2908 : : /* Setup asym xform */
2909 : 1 : xform.next = NULL;
2910 : 1 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
2911 : 1 : xform.ec.curve_id = input_params.curve;
2912 : 1 : xform.ec.pkey.data = input_params.pkey.data;
2913 : 1 : xform.ec.pkey.length = input_params.pkey.length;
2914 : 1 : xform.ec.q.x.data = input_params.pubkey_qx.data;
2915 : 1 : xform.ec.q.x.length = input_params.pubkey_qx.length;
2916 : 1 : xform.ec.q.y.data = input_params.pubkey_qy.data;
2917 : 1 : xform.ec.q.y.length = input_params.pubkey_qy.length;
2918 : :
2919 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2920 [ - + ]: 1 : if (ret < 0) {
2921 : 0 : RTE_LOG(ERR, USER1,
2922 : : "line %u FAILED: %s", __LINE__,
2923 : : "Session creation failed\n");
2924 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2925 : 0 : goto exit;
2926 : : }
2927 : :
2928 : : /* Attach asymmetric crypto session to crypto operations */
2929 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
2930 : :
2931 : : /* Verify given sign */
2932 : :
2933 : : /* Populate op with operational details */
2934 : 1 : asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
2935 : :
2936 [ + - ]: 1 : if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
2937 : : RTE_CRYPTO_ASYM_OP_VERIFY, RTE_CRYPTO_SM2_PH))
2938 : 1 : asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
2939 : : else
2940 : 0 : asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
2941 : :
2942 [ + - ]: 1 : if (asym_op->sm2.hash == RTE_CRYPTO_AUTH_SM3) {
2943 : 1 : asym_op->sm2.message.data = input_params.message.data;
2944 : 1 : asym_op->sm2.message.length = input_params.message.length;
2945 : 1 : asym_op->sm2.id.data = input_params.id.data;
2946 : 1 : asym_op->sm2.id.length = input_params.id.length;
2947 : : } else {
2948 : 0 : asym_op->sm2.message.data = input_params.digest.data;
2949 : 0 : asym_op->sm2.message.length = input_params.digest.length;
2950 : 0 : asym_op->sm2.id.data = NULL;
2951 : 0 : asym_op->sm2.id.length = 0;
2952 : : }
2953 : :
2954 : 1 : asym_op->sm2.r.data = input_params.sign_r.data;
2955 : 1 : asym_op->sm2.r.length = input_params.sign_r.length;
2956 : 1 : asym_op->sm2.s.data = input_params.sign_s.data;
2957 : 1 : asym_op->sm2.s.length = input_params.sign_s.length;
2958 : :
2959 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2960 : :
2961 : : /* Process crypto operation */
2962 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2963 : 0 : RTE_LOG(ERR, USER1,
2964 : : "line %u FAILED: %s", __LINE__,
2965 : : "Error sending packet for operation\n");
2966 : : status = TEST_FAILED;
2967 : 0 : goto exit;
2968 : : }
2969 : :
2970 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2971 : : rte_pause();
2972 : :
2973 [ - + ]: 1 : if (result_op == NULL) {
2974 : 0 : RTE_LOG(ERR, USER1,
2975 : : "line %u FAILED: %s", __LINE__,
2976 : : "Failed to process asym crypto op\n");
2977 : : status = TEST_FAILED;
2978 : 0 : goto exit;
2979 : : }
2980 : :
2981 [ + - ]: 1 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2982 : 0 : RTE_LOG(ERR, USER1,
2983 : : "line %u FAILED: %s", __LINE__,
2984 : : "Failed to process asym crypto op\n");
2985 : : status = TEST_FAILED;
2986 : 0 : goto exit;
2987 : : }
2988 : :
2989 : 1 : exit:
2990 [ + - ]: 1 : if (sess != NULL)
2991 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
2992 : 1 : rte_crypto_op_free(op);
2993 : 1 : return status;
2994 : : };
2995 : :
2996 : : static int
2997 : 1 : test_sm2_enc(void)
2998 : : {
2999 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
3000 : 1 : struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
3001 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
3002 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
3003 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
3004 : : uint8_t output_buf[TEST_DATA_SIZE], *pbuf = NULL;
3005 : : struct rte_cryptodev_asym_capability_idx idx;
3006 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
3007 : 1 : struct rte_crypto_op *result_op = NULL;
3008 : : struct rte_crypto_asym_xform xform;
3009 : : struct rte_crypto_asym_op *asym_op;
3010 : 1 : struct rte_crypto_op *op = NULL;
3011 : : int ret, status = TEST_SUCCESS;
3012 : 1 : void *sess = NULL;
3013 : :
3014 : : /* Check SM2 capability */
3015 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
3016 : 1 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
3017 [ + - ]: 1 : if (capa == NULL)
3018 : : return -ENOTSUP;
3019 : :
3020 : : /* Setup crypto op data structure */
3021 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
3022 [ - + ]: 1 : if (op == NULL) {
3023 : 0 : RTE_LOG(ERR, USER1,
3024 : : "line %u FAILED: %s", __LINE__,
3025 : : "Failed to allocate asymmetric crypto "
3026 : : "operation struct\n");
3027 : : status = TEST_FAILED;
3028 : 0 : goto exit;
3029 : : }
3030 : : asym_op = op->asym;
3031 : :
3032 : : /* Setup asym xform */
3033 : 1 : xform.next = NULL;
3034 : 1 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
3035 : 1 : xform.ec.curve_id = input_params.curve;
3036 : 1 : xform.ec.pkey.data = input_params.pkey.data;
3037 : 1 : xform.ec.pkey.length = input_params.pkey.length;
3038 : 1 : xform.ec.q.x.data = input_params.pubkey_qx.data;
3039 : 1 : xform.ec.q.x.length = input_params.pubkey_qx.length;
3040 : 1 : xform.ec.q.y.data = input_params.pubkey_qy.data;
3041 : 1 : xform.ec.q.y.length = input_params.pubkey_qy.length;
3042 : :
3043 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
3044 [ - + ]: 1 : if (ret < 0) {
3045 : 0 : RTE_LOG(ERR, USER1,
3046 : : "line %u FAILED: %s", __LINE__,
3047 : : "Session creation failed\n");
3048 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
3049 : 0 : goto exit;
3050 : : }
3051 : :
3052 : : /* Attach asymmetric crypto session to crypto operations */
3053 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
3054 : :
3055 : : /* Compute encrypt */
3056 : :
3057 : : /* Populate op with operational details */
3058 : 1 : asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
3059 [ - + ]: 1 : if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
3060 : : RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_PH))
3061 : 0 : asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
3062 : : else
3063 : 1 : asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
3064 : :
3065 : 1 : asym_op->sm2.message.data = input_params.message.data;
3066 : 1 : asym_op->sm2.message.length = input_params.message.length;
3067 : :
3068 [ + - ]: 1 : if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
3069 : : RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_RNG)) {
3070 : 1 : asym_op->sm2.k.data = NULL;
3071 : 1 : asym_op->sm2.k.length = 0;
3072 : : } else {
3073 : 0 : asym_op->sm2.k.data = input_params.k.data;
3074 : 0 : asym_op->sm2.k.length = input_params.k.length;
3075 : : }
3076 : :
3077 : : /* Init out buf */
3078 : 1 : asym_op->sm2.cipher.data = output_buf;
3079 : :
3080 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
3081 : :
3082 : : /* Process crypto operation */
3083 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
3084 : 0 : RTE_LOG(ERR, USER1,
3085 : : "line %u FAILED: %s", __LINE__,
3086 : : "Error sending packet for operation\n");
3087 : : status = TEST_FAILED;
3088 : 0 : goto exit;
3089 : : }
3090 : :
3091 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
3092 : : rte_pause();
3093 : :
3094 [ - + ]: 1 : if (result_op == NULL) {
3095 : 0 : RTE_LOG(ERR, USER1,
3096 : : "line %u FAILED: %s", __LINE__,
3097 : : "Failed to process asym crypto op\n");
3098 : : status = TEST_FAILED;
3099 : 0 : goto exit;
3100 : : }
3101 : :
3102 [ - + ]: 1 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
3103 : 0 : RTE_LOG(ERR, USER1,
3104 : : "line %u FAILED: %s", __LINE__,
3105 : : "Failed to process asym crypto op\n");
3106 : : status = TEST_FAILED;
3107 : 0 : goto exit;
3108 : : }
3109 : :
3110 : : asym_op = result_op->asym;
3111 : :
3112 : 1 : debug_hexdump(stdout, "cipher:",
3113 : 1 : asym_op->sm2.cipher.data, asym_op->sm2.cipher.length);
3114 : :
3115 [ - + ]: 1 : if (!rte_cryptodev_asym_xform_capability_check_opcap(capa,
3116 : : RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_RNG)) {
3117 [ # # ]: 0 : if (memcmp(input_params.cipher.data, asym_op->sm2.cipher.data,
3118 : : asym_op->sm2.cipher.length) != 0) {
3119 : : status = TEST_FAILED;
3120 : 0 : RTE_LOG(ERR, USER1, "line %u FAILED: %s", __LINE__,
3121 : : "SM2 encrypt failed.\n");
3122 : 0 : goto exit;
3123 : : }
3124 : : } else {
3125 : : /* Verify cipher (in roundtrip).
3126 : : * Due to random number used per message, encrypt op
3127 : : * would produce different output for same message
3128 : : * every time. Hence, we can't have expected output
3129 : : * to match, instead reverse op to decrypt.
3130 : : */
3131 : :
3132 : : /* Populate op with operational details */
3133 : 1 : op->asym->sm2.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
3134 : 1 : pbuf = rte_malloc(NULL, TEST_DATA_SIZE, 0);
3135 : 1 : op->asym->sm2.message.data = pbuf;
3136 : 1 : op->asym->sm2.message.length = TEST_DATA_SIZE;
3137 : :
3138 : : /* Enqueue cipher result for decrypt */
3139 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
3140 : : status = TEST_FAILED;
3141 : 0 : RTE_LOG(ERR, USER1,
3142 : : "line %u FAILED: %s", __LINE__,
3143 : : "Error sending packet for operation\n");
3144 : 0 : goto exit;
3145 : : }
3146 : :
3147 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
3148 : : rte_pause();
3149 : :
3150 [ - + ]: 1 : if (result_op == NULL) {
3151 : : status = TEST_FAILED;
3152 : 0 : goto exit;
3153 : : }
3154 [ - + ]: 1 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
3155 : : status = TEST_FAILED;
3156 : 0 : RTE_LOG(ERR, USER1,
3157 : : "line %u FAILED: %s", __LINE__,
3158 : : "SM2 encrypt failed.\n");
3159 : 0 : goto exit;
3160 : : }
3161 : :
3162 : : asym_op = result_op->asym;
3163 [ + - ]: 1 : if (memcmp(input_params.message.data, asym_op->sm2.message.data,
3164 : : asym_op->sm2.message.length) != 0) {
3165 : : status = TEST_FAILED;
3166 : 0 : RTE_LOG(ERR, USER1, "line %u FAILED: %s", __LINE__,
3167 : : "SM2 encrypt failed.\n");
3168 : 0 : goto exit;
3169 : : }
3170 : : }
3171 : 1 : exit:
3172 : 1 : rte_free(pbuf);
3173 : :
3174 [ + - ]: 1 : if (sess != NULL)
3175 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
3176 : 1 : rte_crypto_op_free(op);
3177 : 1 : return status;
3178 : : };
3179 : :
3180 : : static int
3181 : 1 : test_sm2_dec(void)
3182 : : {
3183 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
3184 : 1 : struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
3185 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
3186 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
3187 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
3188 : : struct rte_cryptodev_asym_capability_idx idx;
3189 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
3190 : 1 : struct rte_crypto_op *result_op = NULL;
3191 : : uint8_t output_buf_m[TEST_DATA_SIZE];
3192 : : struct rte_crypto_asym_xform xform;
3193 : : struct rte_crypto_asym_op *asym_op;
3194 : 1 : struct rte_crypto_op *op = NULL;
3195 : : int ret, status = TEST_SUCCESS;
3196 : 1 : void *sess = NULL;
3197 : :
3198 : : /* Check SM2 capability */
3199 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
3200 : 1 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
3201 [ + - ]: 1 : if (capa == NULL)
3202 : : return -ENOTSUP;
3203 : :
3204 : : /* Setup crypto op data structure */
3205 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
3206 [ - + ]: 1 : if (op == NULL) {
3207 : 0 : RTE_LOG(ERR, USER1,
3208 : : "line %u FAILED: %s", __LINE__,
3209 : : "Failed to allocate asymmetric crypto "
3210 : : "operation struct\n");
3211 : : status = TEST_FAILED;
3212 : 0 : goto exit;
3213 : : }
3214 : : asym_op = op->asym;
3215 : :
3216 : : /* Setup asym xform */
3217 : 1 : xform.next = NULL;
3218 : 1 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
3219 : 1 : xform.ec.curve_id = input_params.curve;
3220 : 1 : xform.ec.pkey.data = input_params.pkey.data;
3221 : 1 : xform.ec.pkey.length = input_params.pkey.length;
3222 : 1 : xform.ec.q.x.data = input_params.pubkey_qx.data;
3223 : 1 : xform.ec.q.x.length = input_params.pubkey_qx.length;
3224 : 1 : xform.ec.q.y.data = input_params.pubkey_qy.data;
3225 : 1 : xform.ec.q.y.length = input_params.pubkey_qy.length;
3226 : :
3227 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
3228 [ - + ]: 1 : if (ret < 0) {
3229 : 0 : RTE_LOG(ERR, USER1,
3230 : : "line %u FAILED: %s", __LINE__,
3231 : : "Session creation failed\n");
3232 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
3233 : 0 : goto exit;
3234 : : }
3235 : :
3236 : : /* Attach asymmetric crypto session to crypto operations */
3237 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
3238 : :
3239 : : /* Compute decrypt */
3240 : :
3241 : : /* Populate op with operational details */
3242 : 1 : asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
3243 [ - + ]: 1 : if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
3244 : : RTE_CRYPTO_ASYM_OP_DECRYPT, RTE_CRYPTO_SM2_PH))
3245 : 0 : asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
3246 : : else
3247 : 1 : asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
3248 : :
3249 : 1 : asym_op->sm2.cipher.data = input_params.cipher.data;
3250 : 1 : asym_op->sm2.cipher.length = input_params.cipher.length;
3251 : :
3252 : : /* Init out buf */
3253 : 1 : asym_op->sm2.message.data = output_buf_m;
3254 : 1 : asym_op->sm2.message.length = RTE_DIM(output_buf_m);
3255 : :
3256 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
3257 : :
3258 : : /* Process crypto operation */
3259 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
3260 : 0 : RTE_LOG(ERR, USER1,
3261 : : "line %u FAILED: %s", __LINE__,
3262 : : "Error sending packet for operation\n");
3263 : : status = TEST_FAILED;
3264 : 0 : goto exit;
3265 : : }
3266 : :
3267 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
3268 : : rte_pause();
3269 : :
3270 [ - + ]: 1 : if (result_op == NULL) {
3271 : 0 : RTE_LOG(ERR, USER1,
3272 : : "line %u FAILED: %s", __LINE__,
3273 : : "Failed to process asym crypto op\n");
3274 : : status = TEST_FAILED;
3275 : 0 : goto exit;
3276 : : }
3277 : :
3278 [ - + ]: 1 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
3279 : 0 : RTE_LOG(ERR, USER1,
3280 : : "line %u FAILED: %s", __LINE__,
3281 : : "Failed to process asym crypto op\n");
3282 : : status = TEST_FAILED;
3283 : 0 : goto exit;
3284 : : }
3285 : :
3286 : : asym_op = result_op->asym;
3287 : :
3288 : 1 : debug_hexdump(stdout, "message:",
3289 : 1 : asym_op->sm2.message.data, asym_op->sm2.message.length);
3290 : :
3291 : 1 : if (memcmp(input_params.message.data, asym_op->sm2.message.data,
3292 [ + - ]: 1 : op->asym->sm2.message.length)) {
3293 : : status = TEST_FAILED;
3294 : 0 : RTE_LOG(ERR, USER1,
3295 : : "line %u FAILED: %s", __LINE__,
3296 : : "SM2 decrypt failed.\n");
3297 : 0 : goto exit;
3298 : : }
3299 : 1 : exit:
3300 [ + - ]: 1 : if (sess != NULL)
3301 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
3302 : 1 : rte_crypto_op_free(op);
3303 : 1 : return status;
3304 : : };
3305 : :
3306 : : static int
3307 : 9 : test_eddsa_sign(struct crypto_testsuite_eddsa_params *input_params)
3308 : : {
3309 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
3310 : 9 : enum rte_crypto_edward_instance instance = input_params->instance;
3311 : 9 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
3312 : 9 : struct rte_mempool *op_mpool = ts_params->op_mpool;
3313 : 9 : uint8_t dev_id = ts_params->valid_devs[0];
3314 : 9 : struct rte_crypto_op *result_op = NULL;
3315 : : uint8_t output_buf_r[TEST_DATA_SIZE];
3316 : : struct rte_crypto_asym_xform xform;
3317 : : struct rte_crypto_asym_op *asym_op;
3318 : 9 : struct rte_crypto_op *op = NULL;
3319 : : int ret, status = TEST_FAILED;
3320 : 9 : void *sess = NULL;
3321 : : bool ctx = false;
3322 : :
3323 [ + + ]: 9 : if (instance == RTE_CRYPTO_EDCURVE_25519CTX)
3324 : : ctx = true;
3325 : :
3326 : : /* Setup crypto op data structure */
3327 : 9 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
3328 [ - + ]: 9 : if (op == NULL) {
3329 : 0 : RTE_LOG(ERR, USER1,
3330 : : "line %u FAILED: %s", __LINE__,
3331 : : "Failed to allocate asymmetric crypto "
3332 : : "operation struct\n");
3333 : : status = TEST_FAILED;
3334 : 0 : goto exit;
3335 : : }
3336 : :
3337 : : asym_op = op->asym;
3338 : :
3339 : : /* Setup asym xform */
3340 : 9 : xform.next = NULL;
3341 : 9 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
3342 : 9 : xform.ec.curve_id = input_params->curve;
3343 : 9 : xform.ec.pkey.data = input_params->pkey.data;
3344 : 9 : xform.ec.pkey.length = input_params->pkey.length;
3345 : 9 : xform.ec.q.x.data = input_params->pubkey.data;
3346 : 9 : xform.ec.q.x.length = input_params->pubkey.length;
3347 : :
3348 : 9 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
3349 [ + - ]: 9 : if (ret < 0) {
3350 : 9 : RTE_LOG(ERR, USER1,
3351 : : "line %u FAILED: %s", __LINE__,
3352 : : "Session creation failed\n");
3353 [ - + ]: 9 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
3354 : 9 : goto exit;
3355 : : }
3356 : :
3357 : : /* Attach asymmetric crypto session to crypto operations */
3358 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
3359 : :
3360 : : /* Compute sign */
3361 : :
3362 : : /* Populate op with operational details */
3363 : 0 : asym_op->eddsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
3364 : 0 : asym_op->eddsa.instance = input_params->instance;
3365 : 0 : asym_op->eddsa.message.data = input_params->message.data;
3366 : 0 : asym_op->eddsa.message.length = input_params->message.length;
3367 : 0 : asym_op->eddsa.context.length = 0;
3368 [ # # ]: 0 : if (ctx) {
3369 : 0 : asym_op->eddsa.context.data = input_params->context.data;
3370 : 0 : asym_op->eddsa.context.length = input_params->context.length;
3371 : : }
3372 : :
3373 : : /* Init out buf */
3374 : 0 : asym_op->eddsa.sign.data = output_buf_r;
3375 : :
3376 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
3377 : :
3378 : : /* Process crypto operation */
3379 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
3380 : 0 : RTE_LOG(ERR, USER1,
3381 : : "line %u FAILED: %s", __LINE__,
3382 : : "Error sending packet for operation\n");
3383 : 0 : goto exit;
3384 : : }
3385 : :
3386 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
3387 : : rte_pause();
3388 : :
3389 [ # # ]: 0 : if (result_op == NULL) {
3390 : 0 : RTE_LOG(ERR, USER1,
3391 : : "line %u FAILED: %s", __LINE__,
3392 : : "Failed to process asym crypto op\n");
3393 : 0 : goto exit;
3394 : : }
3395 : :
3396 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
3397 : 0 : RTE_LOG(ERR, USER1,
3398 : : "line %u FAILED: %s", __LINE__,
3399 : : "Failed to process asym crypto op\n");
3400 : 0 : goto exit;
3401 : : }
3402 : :
3403 : : asym_op = result_op->asym;
3404 : :
3405 : 0 : debug_hexdump(stdout, "sign:",
3406 : 0 : asym_op->eddsa.sign.data, asym_op->eddsa.sign.length);
3407 : :
3408 : : /* Verify sign (by comparison). */
3409 [ # # ]: 0 : if (memcmp(input_params->sign.data, asym_op->eddsa.sign.data,
3410 : : asym_op->eddsa.sign.length) != 0) {
3411 : 0 : RTE_LOG(ERR, USER1,
3412 : : "line %u FAILED: %s", __LINE__,
3413 : : "EdDSA sign failed.\n");
3414 : 0 : goto exit;
3415 : : }
3416 : :
3417 : : status = TEST_SUCCESS;
3418 : 9 : exit:
3419 [ + - ]: 9 : if (sess != NULL)
3420 : 9 : rte_cryptodev_asym_session_free(dev_id, sess);
3421 : 9 : rte_crypto_op_free(op);
3422 : 9 : return status;
3423 : : };
3424 : :
3425 : : static int
3426 : 9 : test_eddsa_verify(struct crypto_testsuite_eddsa_params *input_params)
3427 : : {
3428 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
3429 : 9 : enum rte_crypto_edward_instance instance = input_params->instance;
3430 : 9 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
3431 : 9 : struct rte_mempool *op_mpool = ts_params->op_mpool;
3432 : 9 : uint8_t dev_id = ts_params->valid_devs[0];
3433 : 9 : struct rte_crypto_op *result_op = NULL;
3434 : : struct rte_crypto_asym_xform xform;
3435 : : struct rte_crypto_asym_op *asym_op;
3436 : 9 : struct rte_crypto_op *op = NULL;
3437 : : int ret, status = TEST_FAILED;
3438 : 9 : void *sess = NULL;
3439 : : bool ctx = false;
3440 : :
3441 [ + + ]: 9 : if (instance == RTE_CRYPTO_EDCURVE_25519CTX)
3442 : : ctx = true;
3443 : :
3444 : : /* Setup crypto op data structure */
3445 : 9 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
3446 [ - + ]: 9 : if (op == NULL) {
3447 : 0 : RTE_LOG(ERR, USER1,
3448 : : "line %u FAILED: %s", __LINE__,
3449 : : "Failed to allocate asymmetric crypto "
3450 : : "operation struct\n");
3451 : 0 : goto exit;
3452 : : }
3453 : :
3454 : : asym_op = op->asym;
3455 : :
3456 : : /* Setup asym xform */
3457 : 9 : xform.next = NULL;
3458 : 9 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
3459 : 9 : xform.ec.curve_id = input_params->curve;
3460 : 9 : xform.ec.pkey.length = 0;
3461 : 9 : xform.ec.q.x.data = input_params->pubkey.data;
3462 : 9 : xform.ec.q.x.length = input_params->pubkey.length;
3463 : :
3464 : 9 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
3465 [ + - ]: 9 : if (ret < 0) {
3466 : 9 : RTE_LOG(ERR, USER1,
3467 : : "line %u FAILED: %s", __LINE__,
3468 : : "Session creation failed\n");
3469 [ - + ]: 9 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
3470 : 9 : goto exit;
3471 : : }
3472 : :
3473 : : /* Attach asymmetric crypto session to crypto operations */
3474 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
3475 : :
3476 : : /* Compute sign */
3477 : :
3478 : : /* Populate op with operational details */
3479 : 0 : asym_op->eddsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
3480 : 0 : asym_op->eddsa.instance = input_params->instance;
3481 : 0 : asym_op->eddsa.message.data = input_params->message.data;
3482 : 0 : asym_op->eddsa.message.length = input_params->message.length;
3483 : 0 : asym_op->eddsa.context.length = 0;
3484 [ # # ]: 0 : if (ctx) {
3485 : 0 : asym_op->eddsa.context.data = input_params->context.data;
3486 : 0 : asym_op->eddsa.context.length = input_params->context.length;
3487 : : }
3488 : :
3489 : 0 : asym_op->eddsa.sign.data = input_params->sign.data;
3490 : 0 : asym_op->eddsa.sign.length = input_params->sign.length;
3491 : :
3492 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
3493 : :
3494 : : /* Process crypto operation */
3495 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
3496 : 0 : RTE_LOG(ERR, USER1,
3497 : : "line %u FAILED: %s", __LINE__,
3498 : : "Error sending packet for operation\n");
3499 : 0 : goto exit;
3500 : : }
3501 : :
3502 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
3503 : : rte_pause();
3504 : :
3505 [ # # ]: 0 : if (result_op == NULL) {
3506 : 0 : RTE_LOG(ERR, USER1,
3507 : : "line %u FAILED: %s", __LINE__,
3508 : : "Failed to process asym crypto op\n");
3509 : 0 : goto exit;
3510 : : }
3511 : :
3512 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
3513 : 0 : RTE_LOG(ERR, USER1,
3514 : : "line %u FAILED: %s", __LINE__,
3515 : : "Failed to process asym crypto op\n");
3516 : 0 : goto exit;
3517 : : }
3518 : :
3519 : : status = TEST_SUCCESS;
3520 : 9 : exit:
3521 [ + - ]: 9 : if (sess != NULL)
3522 : 9 : rte_cryptodev_asym_session_free(dev_id, sess);
3523 : 9 : rte_crypto_op_free(op);
3524 : 9 : return status;
3525 : : };
3526 : :
3527 : : static int
3528 : 1 : test_eddsa_sign_verify_all_curve(void)
3529 : : {
3530 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
3531 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
3532 : : struct crypto_testsuite_eddsa_params input_params;
3533 : : struct rte_cryptodev_asym_capability_idx idx;
3534 : : int status, overall_status = TEST_SUCCESS;
3535 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
3536 : : uint8_t i, tc = 0;
3537 : : const char *msg;
3538 : :
3539 : : /* Check EdDSA capability */
3540 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
3541 : 1 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
3542 [ + - ]: 1 : if (capa == NULL)
3543 : : return TEST_SKIPPED;
3544 : :
3545 : : /* Sign tests */
3546 [ + + ]: 9 : for (i = 0; i < RTE_DIM(eddsa_test_params); i++) {
3547 : 8 : memcpy(&input_params, &eddsa_test_params[i],
3548 : : sizeof(input_params));
3549 : 8 : status = test_eddsa_sign(&input_params);
3550 [ + - ]: 8 : if (status == TEST_SUCCESS) {
3551 : : msg = "succeeded";
3552 : : } else {
3553 : : msg = "failed";
3554 : : overall_status = status;
3555 : : }
3556 : 8 : printf(" %u) TestCase Sign %s %s\n",
3557 : 8 : tc++, input_params.description, msg);
3558 : : }
3559 : :
3560 : : /* Verify tests */
3561 [ + + ]: 9 : for (i = 0; i < RTE_DIM(eddsa_test_params); i++) {
3562 : 8 : memcpy(&input_params, &eddsa_test_params[i],
3563 : : sizeof(input_params));
3564 : 8 : status = test_eddsa_verify(&input_params);
3565 [ + - ]: 8 : if (status == TEST_SUCCESS) {
3566 : : msg = "succeeded";
3567 : : } else {
3568 : : msg = "failed";
3569 : : overall_status = status;
3570 : : }
3571 : 8 : printf(" %u) TestCase Verify %s %s\n",
3572 : 8 : tc++, input_params.description, msg);
3573 : : }
3574 : :
3575 : : /* Negative tests */
3576 : : memcpy(&input_params, &eddsa_test_params[1],
3577 : : sizeof(input_params));
3578 : 1 : input_params.pubkey.data[0] ^= 0x01;
3579 : :
3580 : 1 : status = test_eddsa_sign(&input_params);
3581 [ + - ]: 1 : if (status == TEST_FAILED) {
3582 : : msg = "succeeded";
3583 : : } else {
3584 : : msg = "failed";
3585 : : overall_status = status;
3586 : : }
3587 : 1 : printf(" %u) TestCase Negative Sign %s %s\n",
3588 : 1 : tc++, input_params.description, msg);
3589 : :
3590 : 1 : status = test_eddsa_verify(&input_params);
3591 [ + - ]: 1 : if (status == TEST_FAILED) {
3592 : : msg = "succeeded";
3593 : : } else {
3594 : : msg = "failed";
3595 : : overall_status = status;
3596 : : }
3597 : 1 : printf(" %u) TestCase Negative Verify %s %s\n",
3598 : : tc++, input_params.description, msg);
3599 : :
3600 : 1 : return overall_status;
3601 : : }
3602 : :
3603 : 10 : static int send_one(void)
3604 : : {
3605 : : int ticks = 0;
3606 : :
3607 [ - + ]: 10 : if (rte_cryptodev_enqueue_burst(params->valid_devs[0], 0,
3608 : 10 : &self->op, 1) != 1) {
3609 : 0 : RTE_LOG(ERR, USER1,
3610 : : "line %u FAILED: Error sending packet for operation on device %d",
3611 : : __LINE__, params->valid_devs[0]);
3612 : 0 : return TEST_FAILED;
3613 : : }
3614 : 10 : while (rte_cryptodev_dequeue_burst(params->valid_devs[0], 0,
3615 [ - + ]: 10 : &self->result_op, 1) == 0) {
3616 : : rte_delay_ms(1);
3617 : 0 : ticks++;
3618 [ # # ]: 0 : if (ticks >= DEQ_TIMEOUT) {
3619 : 0 : RTE_LOG(ERR, USER1,
3620 : : "line %u FAILED: Cannot dequeue the crypto op on device %d",
3621 : : __LINE__, params->valid_devs[0]);
3622 : 0 : return TEST_FAILED;
3623 : : }
3624 : : }
3625 [ - + ]: 10 : TEST_ASSERT_NOT_NULL(self->result_op,
3626 : : "Failed to process asym crypto op");
3627 [ - + ]: 10 : TEST_ASSERT_SUCCESS(self->result_op->status,
3628 : : "Failed to process asym crypto op, error status received");
3629 : : return TEST_SUCCESS;
3630 : : }
3631 : :
3632 : : static int
3633 : 10 : modular_cmpeq(const uint8_t *a, size_t a_len, const uint8_t *b, size_t b_len)
3634 : : {
3635 : : const uint8_t *new_a, *new_b;
3636 : : size_t i, j;
3637 : :
3638 : : /* Strip leading NUL bytes */
3639 [ + - ]: 10 : for (i = 0; i < a_len; i++)
3640 [ + - ]: 10 : if (a[i] != 0)
3641 : : break;
3642 : :
3643 [ + - ]: 10 : for (j = 0; j < b_len; j++)
3644 [ - + ]: 10 : if (b[j] != 0)
3645 : : break;
3646 : :
3647 [ + - ]: 10 : if (a_len - i != b_len - j)
3648 : : return 1;
3649 : :
3650 : 10 : new_a = &a[i];
3651 : 10 : new_b = &b[j];
3652 [ - + ]: 10 : if (memcmp(new_a, new_b, a_len - i))
3653 : 0 : return 1;
3654 : :
3655 : : return 0;
3656 : : }
3657 : :
3658 : : static int
3659 : 10 : modular_exponentiation(const void *test_data)
3660 : : {
3661 : : const struct modex_test_data *vector = test_data;
3662 : 10 : uint8_t input[TEST_DATA_SIZE] = { 0 };
3663 : 10 : uint8_t exponent[TEST_DATA_SIZE] = { 0 };
3664 : 10 : uint8_t modulus[TEST_DATA_SIZE] = { 0 };
3665 : 10 : uint8_t result[TEST_DATA_SIZE] = { 0 };
3666 : 10 : struct rte_crypto_asym_xform xform = { };
3667 : 10 : const uint8_t dev_id = params->valid_devs[0];
3668 : :
3669 : 10 : memcpy(input, vector->base.data, vector->base.len);
3670 : 10 : memcpy(exponent, vector->exponent.data, vector->exponent.len);
3671 : 10 : memcpy(modulus, vector->modulus.data, vector->modulus.len);
3672 : :
3673 : 10 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX;
3674 : 10 : xform.modex.exponent.data = exponent;
3675 : 10 : xform.modex.exponent.length = vector->exponent.len;
3676 : 10 : xform.modex.modulus.data = modulus;
3677 : 10 : xform.modex.modulus.length = vector->modulus.len;
3678 : :
3679 [ - + ]: 10 : if (rte_cryptodev_asym_session_create(dev_id, &xform,
3680 : 10 : params->session_mpool, &self->sess) < 0) {
3681 : 0 : RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed",
3682 : : __LINE__);
3683 : 0 : return TEST_FAILED;
3684 : : }
3685 [ + - ]: 10 : rte_crypto_op_attach_asym_session(self->op, self->sess);
3686 : 10 : self->op->asym->modex.base.data = input;
3687 : 10 : self->op->asym->modex.base.length = vector->base.len;
3688 : 10 : self->op->asym->modex.result.data = result;
3689 : :
3690 [ - + ]: 10 : TEST_ASSERT_SUCCESS(send_one(),
3691 : : "Failed to process crypto op");
3692 [ - + ]: 10 : TEST_ASSERT_SUCCESS(modular_cmpeq(vector->reminder.data, vector->reminder.len,
3693 : : self->result_op->asym->modex.result.data,
3694 : : self->result_op->asym->modex.result.length),
3695 : : "operation verification failed\n");
3696 : :
3697 : : return TEST_SUCCESS;
3698 : : }
3699 : :
3700 : : static int
3701 : 0 : modular_multiplicative_inverse(const void *test_data)
3702 : : {
3703 : : const struct modinv_test_data *vector = test_data;
3704 : 0 : uint8_t input[TEST_DATA_SIZE] = { 0 };
3705 : 0 : uint8_t modulus[TEST_DATA_SIZE] = { 0 };
3706 : 0 : uint8_t result[TEST_DATA_SIZE] = { 0 };
3707 : 0 : struct rte_crypto_asym_xform xform = { };
3708 : 0 : const uint8_t dev_id = params->valid_devs[0];
3709 : :
3710 : 0 : memcpy(input, vector->base.data, vector->base.len);
3711 : 0 : memcpy(modulus, vector->modulus.data, vector->modulus.len);
3712 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODINV;
3713 : 0 : xform.modex.modulus.data = modulus;
3714 : 0 : xform.modex.modulus.length = vector->modulus.len;
3715 [ # # ]: 0 : if (rte_cryptodev_asym_session_create(dev_id, &xform,
3716 : 0 : params->session_mpool, &self->sess) < 0) {
3717 : 0 : RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed",
3718 : : __LINE__);
3719 : 0 : return TEST_FAILED;
3720 : : }
3721 [ # # ]: 0 : rte_crypto_op_attach_asym_session(self->op, self->sess);
3722 : :
3723 : 0 : self->op->asym->modinv.base.data = input;
3724 : 0 : self->op->asym->modinv.base.length = vector->base.len;
3725 : 0 : self->op->asym->modinv.result.data = result;
3726 : 0 : self->op->asym->modinv.result.length = vector->modulus.len;
3727 : :
3728 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one(),
3729 : : "Failed to process crypto op");
3730 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->inverse.data,
3731 : : self->result_op->asym->modinv.result.data,
3732 : : self->result_op->asym->modinv.result.length,
3733 : : "Incorrect reminder\n");
3734 : :
3735 : : return TEST_SUCCESS;
3736 : : }
3737 : :
3738 : : #define SET_RSA_PARAM(arg, vector, coef) \
3739 : : uint8_t coef[TEST_DATA_SIZE] = { }; \
3740 : : memcpy(coef, vector->coef.data, vector->coef.len); \
3741 : : arg.coef.data = coef; \
3742 : : arg.coef.length = vector->coef.len
3743 : :
3744 : : #define SET_RSA_PARAM_QT(arg, vector, coef) \
3745 : : uint8_t coef[TEST_DATA_SIZE] = { }; \
3746 : : memcpy(coef, vector->coef.data, vector->coef.len); \
3747 : : arg.qt.coef.data = coef; \
3748 : : arg.qt.coef.length = vector->coef.len
3749 : :
3750 : : static int
3751 : 0 : rsa_encrypt(const struct rsa_test_data_2 *vector, uint8_t *cipher_buf)
3752 : : {
3753 : 0 : self->result_op = NULL;
3754 : : /* Compute encryption on the test vector */
3755 : 0 : self->op->asym->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
3756 : 0 : self->op->asym->rsa.cipher.data = cipher_buf;
3757 : 0 : self->op->asym->rsa.cipher.length = 0;
3758 [ # # ]: 0 : SET_RSA_PARAM(self->op->asym->rsa, vector, message);
3759 : :
3760 [ # # ]: 0 : rte_crypto_op_attach_asym_session(self->op, self->sess);
3761 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one(),
3762 : : "Failed to process crypto op (Enryption)");
3763 : :
3764 : : return 0;
3765 : : }
3766 : :
3767 : : static int
3768 : 0 : rsa_decrypt(const struct rsa_test_data_2 *vector, uint8_t *plaintext,
3769 : : const int use_op)
3770 : : {
3771 : 0 : uint8_t cipher[TEST_DATA_SIZE] = { 0 };
3772 : :
3773 [ # # ]: 0 : if (use_op == 0) {
3774 : 0 : memcpy(cipher, vector->cipher.data, vector->cipher.len);
3775 : 0 : self->op->asym->rsa.cipher.data = cipher;
3776 : 0 : self->op->asym->rsa.cipher.length = vector->cipher.len;
3777 : : }
3778 : 0 : self->result_op = NULL;
3779 : 0 : self->op->asym->rsa.message.data = plaintext;
3780 : 0 : self->op->asym->rsa.message.length = 0;
3781 : 0 : self->op->asym->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
3782 [ # # ]: 0 : rte_crypto_op_attach_asym_session(self->op, self->sess);
3783 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one(),
3784 : : "Failed to process crypto op (Decryption)");
3785 : : return 0;
3786 : : }
3787 : :
3788 : : static int
3789 : 0 : rsa_init_session(struct rte_crypto_asym_xform *xform)
3790 : : {
3791 : 0 : const uint8_t dev_id = params->valid_devs[0];
3792 : : struct rte_cryptodev_info dev_info;
3793 : : int ret = 0;
3794 : :
3795 : 0 : xform->xform_type = RTE_CRYPTO_ASYM_XFORM_RSA;
3796 : :
3797 : 0 : rte_cryptodev_info_get(dev_id, &dev_info);
3798 [ # # ]: 0 : if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
3799 : 0 : RTE_LOG(INFO, USER1,
3800 : : "Device doesn't support decrypt op with quintuple key type. Test skipped\n");
3801 : 0 : return TEST_SKIPPED;
3802 : : }
3803 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, xform,
3804 : 0 : params->session_mpool, &self->sess);
3805 [ # # ]: 0 : if (ret < 0) {
3806 : 0 : RTE_LOG(ERR, USER1,
3807 : : "Session creation failed for enc_dec_crt\n");
3808 [ # # ]: 0 : return (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
3809 : : }
3810 : : return 0;
3811 : : }
3812 : :
3813 : : static int
3814 : 0 : kat_rsa_encrypt(const void *data)
3815 : : {
3816 : 0 : uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
3817 : : const struct rsa_test_data_2 *vector = data;
3818 : 0 : struct rte_crypto_asym_xform xform = { };
3819 : :
3820 : 0 : SET_RSA_PARAM(xform.rsa, vector, n);
3821 : 0 : SET_RSA_PARAM(xform.rsa, vector, e);
3822 : 0 : SET_RSA_PARAM(xform.rsa, vector, d);
3823 : 0 : xform.rsa.padding.type = vector->padding;
3824 : : xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
3825 : 0 : int ret = rsa_init_session(&xform);
3826 : :
3827 [ # # ]: 0 : if (ret) {
3828 : 0 : RTE_LOG(ERR, USER1, "Failed to init session for RSA\n");
3829 : 0 : return ret;
3830 : : }
3831 [ # # ]: 0 : TEST_ASSERT_SUCCESS(rsa_encrypt(vector, cipher_buf),
3832 : : "RSA: Failed to encrypt");
3833 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->cipher.data,
3834 : : self->result_op->asym->rsa.cipher.data,
3835 : : self->result_op->asym->rsa.cipher.length,
3836 : : "operation verification failed\n");
3837 : : return 0;
3838 : : }
3839 : :
3840 : : static int
3841 : 0 : kat_rsa_encrypt_crt(const void *data)
3842 : : {
3843 : 0 : uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
3844 : : const struct rsa_test_data_2 *vector = data;
3845 : 0 : struct rte_crypto_asym_xform xform = { };
3846 : :
3847 : 0 : SET_RSA_PARAM(xform.rsa, vector, n);
3848 : 0 : SET_RSA_PARAM(xform.rsa, vector, e);
3849 : 0 : SET_RSA_PARAM_QT(xform.rsa, vector, p);
3850 : 0 : SET_RSA_PARAM_QT(xform.rsa, vector, q);
3851 : 0 : SET_RSA_PARAM_QT(xform.rsa, vector, dP);
3852 : 0 : SET_RSA_PARAM_QT(xform.rsa, vector, dQ);
3853 : 0 : SET_RSA_PARAM_QT(xform.rsa, vector, qInv);
3854 : 0 : xform.rsa.padding.type = vector->padding;
3855 : 0 : xform.rsa.key_type = RTE_RSA_KEY_TYPE_QT;
3856 : 0 : int ret = rsa_init_session(&xform);
3857 [ # # ]: 0 : if (ret) {
3858 : 0 : RTE_LOG(ERR, USER1, "Failed to init session for RSA\n");
3859 : 0 : return ret;
3860 : : }
3861 [ # # ]: 0 : TEST_ASSERT_SUCCESS(rsa_encrypt(vector, cipher_buf),
3862 : : "RSA: Failed to encrypt");
3863 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->cipher.data,
3864 : : self->result_op->asym->rsa.cipher.data,
3865 : : self->result_op->asym->rsa.cipher.length,
3866 : : "operation verification failed\n");
3867 : : return 0;
3868 : : }
3869 : :
3870 : : static int
3871 : 0 : kat_rsa_decrypt(const void *data)
3872 : : {
3873 : 0 : uint8_t message[TEST_DATA_SIZE] = {0};
3874 : : const struct rsa_test_data_2 *vector = data;
3875 : 0 : struct rte_crypto_asym_xform xform = { };
3876 : :
3877 : 0 : SET_RSA_PARAM(xform.rsa, vector, n);
3878 : 0 : SET_RSA_PARAM(xform.rsa, vector, e);
3879 : 0 : SET_RSA_PARAM(xform.rsa, vector, d);
3880 : 0 : xform.rsa.padding.type = vector->padding;
3881 : : xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
3882 : 0 : int ret = rsa_init_session(&xform);
3883 : :
3884 [ # # ]: 0 : if (ret) {
3885 : 0 : RTE_LOG(ERR, USER1, "Failed to init session for RSA\n");
3886 : 0 : return ret;
3887 : : }
3888 [ # # ]: 0 : TEST_ASSERT_SUCCESS(rsa_decrypt(vector, message, 0),
3889 : : "RSA: Failed to encrypt");
3890 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->message.data,
3891 : : self->result_op->asym->rsa.message.data,
3892 : : self->result_op->asym->rsa.message.length,
3893 : : "operation verification failed\n");
3894 : : return 0;
3895 : : }
3896 : :
3897 : : static int
3898 : 0 : kat_rsa_decrypt_crt(const void *data)
3899 : : {
3900 : 0 : uint8_t message[TEST_DATA_SIZE] = {0};
3901 : : const struct rsa_test_data_2 *vector = data;
3902 : 0 : struct rte_crypto_asym_xform xform = { };
3903 : :
3904 : 0 : SET_RSA_PARAM(xform.rsa, vector, n);
3905 : 0 : SET_RSA_PARAM(xform.rsa, vector, e);
3906 : 0 : SET_RSA_PARAM_QT(xform.rsa, vector, p);
3907 : 0 : SET_RSA_PARAM_QT(xform.rsa, vector, q);
3908 : 0 : SET_RSA_PARAM_QT(xform.rsa, vector, dP);
3909 : 0 : SET_RSA_PARAM_QT(xform.rsa, vector, dQ);
3910 : 0 : SET_RSA_PARAM_QT(xform.rsa, vector, qInv);
3911 : 0 : xform.rsa.padding.type = vector->padding;
3912 : 0 : xform.rsa.key_type = RTE_RSA_KEY_TYPE_QT;
3913 : 0 : int ret = rsa_init_session(&xform);
3914 [ # # ]: 0 : if (ret) {
3915 : 0 : RTE_LOG(ERR, USER1, "Failed to init session for RSA\n");
3916 : 0 : return ret;
3917 : : }
3918 [ # # ]: 0 : TEST_ASSERT_SUCCESS(rsa_decrypt(vector, message, 0),
3919 : : "RSA: Failed to encrypt");
3920 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->message.data,
3921 : : self->result_op->asym->rsa.message.data,
3922 : : self->result_op->asym->rsa.message.length,
3923 : : "operation verification failed\n");
3924 : : return 0;
3925 : : }
3926 : :
3927 : : static struct unit_test_suite cryptodev_openssl_asym_testsuite = {
3928 : : .suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
3929 : : .setup = testsuite_setup,
3930 : : .teardown = testsuite_teardown,
3931 : : .unit_test_cases = {
3932 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
3933 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_dsa),
3934 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
3935 : : test_dh_key_generation),
3936 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_sign),
3937 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_verify),
3938 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_enc),
3939 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_dec),
3940 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec),
3941 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
3942 : : test_rsa_sign_verify),
3943 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
3944 : : test_rsa_enc_dec_crt),
3945 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
3946 : : test_rsa_sign_verify_crt),
3947 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_inv),
3948 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
3949 : : TEST_CASE_NAMED_WITH_DATA(
3950 : : "Modex test for zero padding",
3951 : : ut_setup_asym, ut_teardown_asym,
3952 : : modular_exponentiation, &modex_test_cases[0]),
3953 : : TEST_CASE_NAMED_WITH_DATA(
3954 : : "Modex test for zero padding (2)",
3955 : : ut_setup_asym, ut_teardown_asym,
3956 : : modular_exponentiation, &modex_test_cases[1]),
3957 : : TEST_CASE_NAMED_WITH_DATA(
3958 : : "Modex Group 5 test",
3959 : : ut_setup_asym, ut_teardown_asym,
3960 : : modular_exponentiation, &modex_group_test_cases[0]),
3961 : : TEST_CASE_NAMED_WITH_DATA(
3962 : : "Modex Group 14 test",
3963 : : ut_setup_asym, ut_teardown_asym,
3964 : : modular_exponentiation, &modex_group_test_cases[1]),
3965 : : TEST_CASE_NAMED_WITH_DATA(
3966 : : "Modex Group 15 test",
3967 : : ut_setup_asym, ut_teardown_asym,
3968 : : modular_exponentiation, &modex_group_test_cases[2]),
3969 : : TEST_CASE_NAMED_WITH_DATA(
3970 : : "Modex Group 16 test",
3971 : : ut_setup_asym, ut_teardown_asym,
3972 : : modular_exponentiation, &modex_group_test_cases[3]),
3973 : : TEST_CASE_NAMED_WITH_DATA(
3974 : : "Modex Group 17 test",
3975 : : ut_setup_asym, ut_teardown_asym,
3976 : : modular_exponentiation, &modex_group_test_cases[4]),
3977 : : TEST_CASE_NAMED_WITH_DATA(
3978 : : "Modex Group 18 test",
3979 : : ut_setup_asym, ut_teardown_asym,
3980 : : modular_exponentiation, &modex_group_test_cases[5]),
3981 : : TEST_CASE_NAMED_WITH_DATA(
3982 : : "Modex Group 24 test",
3983 : : ut_setup_asym, ut_teardown_asym,
3984 : : modular_exponentiation, &modex_group_test_cases[6]),
3985 : : TEST_CASE_NAMED_WITH_DATA(
3986 : : "Modex Group 24 subgroup test",
3987 : : ut_setup_asym, ut_teardown_asym,
3988 : : modular_exponentiation, &modex_group_test_cases[7]),
3989 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_eddsa_sign_verify_all_curve),
3990 : : TEST_CASES_END() /**< NULL terminate unit test array */
3991 : : }
3992 : : };
3993 : :
3994 : : static struct unit_test_suite cryptodev_qat_asym_testsuite = {
3995 : : .suite_name = "Crypto Device QAT ASYM Unit Test Suite",
3996 : : .setup = testsuite_setup,
3997 : : .teardown = testsuite_teardown,
3998 : : .unit_test_cases = {
3999 : : TEST_CASE_NAMED_WITH_DATA(
4000 : : "Modular Exponentiation (mod=128, base=20, exp=3, res=128)",
4001 : : ut_setup_asym, ut_teardown_asym,
4002 : : modular_exponentiation, &modex_test_case_m128_b20_e3),
4003 : : /* Modular Multiplicative Inverse */
4004 : : TEST_CASE_NAMED_WITH_DATA(
4005 : : "Modular Inverse (mod=128, base=20, exp=3, inv=128)",
4006 : : ut_setup_asym, ut_teardown_asym,
4007 : : modular_multiplicative_inverse, &modinv_test_case),
4008 : : /* RSA EXP */
4009 : : TEST_CASE_NAMED_WITH_DATA(
4010 : : "RSA Encryption (n=128, pt=20, e=3) EXP, Padding: NONE",
4011 : : ut_setup_asym, ut_teardown_asym,
4012 : : kat_rsa_encrypt, &rsa_vector_128_20_3_none),
4013 : : TEST_CASE_NAMED_WITH_DATA(
4014 : : "RSA Decryption (n=128, pt=20, e=3) EXP, Padding: NONE",
4015 : : ut_setup_asym, ut_teardown_asym,
4016 : : kat_rsa_decrypt, &rsa_vector_128_20_3_none),
4017 : : /* RSA CRT */
4018 : : TEST_CASE_NAMED_WITH_DATA(
4019 : : "RSA Encryption (n=128, pt=20, e=3) CRT, Padding: NONE",
4020 : : ut_setup_asym, ut_teardown_asym,
4021 : : kat_rsa_encrypt_crt, &rsa_vector_128_20_3_none),
4022 : : TEST_CASE_NAMED_WITH_DATA(
4023 : : "RSA Decryption (n=128, pt=20, e=3) CRT, Padding: NONE",
4024 : : ut_setup_asym, ut_teardown_asym,
4025 : : kat_rsa_decrypt_crt, &rsa_vector_128_20_3_none),
4026 : : TEST_CASES_END() /**< NULL terminate unit test array */
4027 : : }
4028 : : };
4029 : :
4030 : : static struct unit_test_suite cryptodev_octeontx_asym_testsuite = {
4031 : : .suite_name = "Crypto Device OCTEONTX ASYM Unit Test Suite",
4032 : : .setup = testsuite_setup,
4033 : : .teardown = testsuite_teardown,
4034 : : .unit_test_cases = {
4035 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
4036 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
4037 : : test_rsa_enc_dec_crt),
4038 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
4039 : : test_rsa_sign_verify_crt),
4040 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec),
4041 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
4042 : : test_rsa_sign_verify),
4043 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
4044 : : TEST_CASE_NAMED_WITH_DATA(
4045 : : "Modex test for zero padding",
4046 : : ut_setup_asym, ut_teardown_asym,
4047 : : modular_exponentiation, &modex_test_cases[0]),
4048 : : TEST_CASE_NAMED_WITH_DATA(
4049 : : "Modex test for zero padding (2)",
4050 : : ut_setup_asym, ut_teardown_asym,
4051 : : modular_exponentiation, &modex_test_cases[1]),
4052 : : TEST_CASE_NAMED_WITH_DATA(
4053 : : "Modex Group 5 test",
4054 : : ut_setup_asym, ut_teardown_asym,
4055 : : modular_exponentiation, &modex_group_test_cases[0]),
4056 : : TEST_CASE_NAMED_WITH_DATA(
4057 : : "Modex Group 14 test",
4058 : : ut_setup_asym, ut_teardown_asym,
4059 : : modular_exponentiation, &modex_group_test_cases[1]),
4060 : : TEST_CASE_NAMED_WITH_DATA(
4061 : : "Modex Group 15 test",
4062 : : ut_setup_asym, ut_teardown_asym,
4063 : : modular_exponentiation, &modex_group_test_cases[2]),
4064 : : TEST_CASE_NAMED_WITH_DATA(
4065 : : "Modex Group 16 test",
4066 : : ut_setup_asym, ut_teardown_asym,
4067 : : modular_exponentiation, &modex_group_test_cases[3]),
4068 : : TEST_CASE_NAMED_WITH_DATA(
4069 : : "Modex Group 17 test",
4070 : : ut_setup_asym, ut_teardown_asym,
4071 : : modular_exponentiation, &modex_group_test_cases[4]),
4072 : : TEST_CASE_NAMED_WITH_DATA(
4073 : : "Modex Group 18 test",
4074 : : ut_setup_asym, ut_teardown_asym,
4075 : : modular_exponentiation, &modex_group_test_cases[5]),
4076 : : TEST_CASE_NAMED_WITH_DATA(
4077 : : "Modex Group 24 test",
4078 : : ut_setup_asym, ut_teardown_asym,
4079 : : modular_exponentiation, &modex_group_test_cases[6]),
4080 : : TEST_CASE_NAMED_WITH_DATA(
4081 : : "Modex Group 24 subgroup test",
4082 : : ut_setup_asym, ut_teardown_asym,
4083 : : modular_exponentiation, &modex_group_test_cases[7]),
4084 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
4085 : : test_ecdsa_sign_verify_all_curve),
4086 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_sign),
4087 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_verify),
4088 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
4089 : : test_ecdh_all_curve),
4090 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
4091 : : test_ecpm_all_curve),
4092 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_eddsa_sign_verify_all_curve),
4093 : : TEST_CASES_END() /**< NULL terminate unit test array */
4094 : : }
4095 : : };
4096 : :
4097 : : static struct unit_test_suite cryptodev_virtio_asym_testsuite = {
4098 : : .suite_name = "Crypto Device VIRTIO ASYM Unit Test Suite",
4099 : : .setup = testsuite_setup,
4100 : : .teardown = testsuite_teardown,
4101 : : .unit_test_cases = {
4102 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
4103 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
4104 : : test_rsa_sign_verify_crt),
4105 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec_crt),
4106 : : TEST_CASES_END() /**< NULL terminate unit test array */
4107 : : }
4108 : : };
4109 : :
4110 : : static int
4111 : 1 : test_cryptodev_openssl_asym(void)
4112 : : {
4113 : 1 : gbl_driver_id = rte_cryptodev_driver_id_get(
4114 : : RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
4115 : :
4116 [ - + ]: 1 : if (gbl_driver_id == -1) {
4117 : 0 : RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n");
4118 : 0 : return TEST_SKIPPED;
4119 : : }
4120 : :
4121 : 1 : return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
4122 : : }
4123 : :
4124 : : static int
4125 : 0 : test_cryptodev_qat_asym(void)
4126 : : {
4127 : 0 : gbl_driver_id = rte_cryptodev_driver_id_get(
4128 : : RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
4129 : :
4130 [ # # ]: 0 : if (gbl_driver_id == -1) {
4131 : 0 : RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n");
4132 : 0 : return TEST_SKIPPED;
4133 : : }
4134 : :
4135 : 0 : return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
4136 : : }
4137 : :
4138 : : static int
4139 : 0 : test_cryptodev_octeontx_asym(void)
4140 : : {
4141 : 0 : gbl_driver_id = rte_cryptodev_driver_id_get(
4142 : : RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
4143 [ # # ]: 0 : if (gbl_driver_id == -1) {
4144 : 0 : RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n");
4145 : 0 : return TEST_SKIPPED;
4146 : : }
4147 : 0 : return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
4148 : : }
4149 : :
4150 : : static int
4151 : 0 : test_cryptodev_cn9k_asym(void)
4152 : : {
4153 : 0 : gbl_driver_id = rte_cryptodev_driver_id_get(
4154 : : RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
4155 [ # # ]: 0 : if (gbl_driver_id == -1) {
4156 : 0 : RTE_LOG(ERR, USER1, "CN9K PMD must be loaded.\n");
4157 : 0 : return TEST_SKIPPED;
4158 : : }
4159 : :
4160 : : /* Use test suite registered for crypto_octeontx PMD */
4161 : 0 : return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
4162 : : }
4163 : :
4164 : : static int
4165 : 0 : test_cryptodev_cn10k_asym(void)
4166 : : {
4167 : 0 : gbl_driver_id = rte_cryptodev_driver_id_get(
4168 : : RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
4169 [ # # ]: 0 : if (gbl_driver_id == -1) {
4170 : 0 : RTE_LOG(ERR, USER1, "CN10K PMD must be loaded.\n");
4171 : 0 : return TEST_SKIPPED;
4172 : : }
4173 : :
4174 : : /* Use test suite registered for crypto_octeontx PMD */
4175 : 0 : return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
4176 : : }
4177 : :
4178 : : static int
4179 : 0 : test_cryptodev_virtio_asym(void)
4180 : : {
4181 : 0 : gbl_driver_id = rte_cryptodev_driver_id_get(
4182 : : RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
4183 [ # # ]: 0 : if (gbl_driver_id == -1) {
4184 : 0 : RTE_LOG(ERR, USER1, "virtio PMD must be loaded.\n");
4185 : 0 : return TEST_SKIPPED;
4186 : : }
4187 : :
4188 : : /* Use test suite registered for crypto_virtio PMD */
4189 : 0 : return unit_test_suite_runner(&cryptodev_virtio_asym_testsuite);
4190 : : }
4191 : :
4192 : : static int
4193 : 0 : test_cryptodev_virtio_user_asym(void)
4194 : : {
4195 : 0 : gbl_driver_id = rte_cryptodev_driver_id_get(
4196 : : RTE_STR(CRYPTODEV_NAME_VIRTIO_USER_PMD));
4197 [ # # ]: 0 : if (gbl_driver_id == -1) {
4198 : 0 : RTE_LOG(ERR, USER1, "virtio user PMD must be loaded.\n");
4199 : 0 : return TEST_SKIPPED;
4200 : : }
4201 : :
4202 : : /* Use test suite registered for crypto_virtio_user PMD */
4203 : 0 : return unit_test_suite_runner(&cryptodev_virtio_asym_testsuite);
4204 : : }
4205 : :
4206 : 253 : REGISTER_DRIVER_TEST(cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym);
4207 : 253 : REGISTER_DRIVER_TEST(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
4208 : 253 : REGISTER_DRIVER_TEST(cryptodev_octeontx_asym_autotest, test_cryptodev_octeontx_asym);
4209 : 253 : REGISTER_DRIVER_TEST(cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym);
4210 : 253 : REGISTER_DRIVER_TEST(cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym);
4211 : 253 : REGISTER_DRIVER_TEST(cryptodev_virtio_asym_autotest, test_cryptodev_virtio_asym);
4212 : 253 : REGISTER_DRIVER_TEST(cryptodev_virtio_user_asym_autotest, test_cryptodev_virtio_user_asym);
|