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