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