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