xref: /dpdk/lib/cryptodev/rte_crypto_asym.h (revision 6d66f08e794257cdb30c566bbc1c360b529e4665)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Cavium Networks
3  */
4 
5 #ifndef _RTE_CRYPTO_ASYM_H_
6 #define _RTE_CRYPTO_ASYM_H_
7 
8 /**
9  * @file rte_crypto_asym.h
10  *
11  * RTE Definitions for Asymmetric Cryptography
12  *
13  * Defines asymmetric algorithms and modes, as well as supported
14  * asymmetric crypto operations.
15  */
16 
17 #include <string.h>
18 #include <stdint.h>
19 
20 #include <rte_memory.h>
21 #include <rte_mempool.h>
22 #include <rte_common.h>
23 
24 #include "rte_crypto_sym.h"
25 
26 struct rte_cryptodev_asym_session;
27 
28 /** asym key exchange operation type name strings */
29 extern const char *
30 rte_crypto_asym_ke_strings[];
31 
32 /** asym operations type name strings */
33 extern const char *
34 rte_crypto_asym_op_strings[];
35 
36 #define RTE_CRYPTO_ASYM_FLAG_PUB_KEY_NO_PADDING		RTE_BIT32(0)
37 /**<
38  * Flag to denote public key will be returned without leading zero bytes
39  * and if the flag is not set, public key will be padded to the left with
40  * zeros to the size of the underlying algorithm (default)
41  */
42 #define RTE_CRYPTO_ASYM_FLAG_SHARED_KEY_NO_PADDING	RTE_BIT32(1)
43 /**<
44  * Flag to denote shared secret will be returned without leading zero bytes
45  * and if the flag is not set, shared secret will be padded to the left with
46  * zeros to the size of the underlying algorithm (default)
47  */
48 #define RTE_CRYPTO_ASYM_FLAG_PUB_KEY_COMPRESSED		RTE_BIT32(2)
49 /**<
50  * Flag to denote public key will be returned in compressed form
51  */
52 
53 /**
54  * List of elliptic curves. This enum aligns with
55  * TLS "Supported Groups" registry (previously known  as
56  * NamedCurve registry). FFDH groups are not, and will not
57  * be included in this list.
58  * Deprecation for selected curve in TLS does not deprecate
59  * the selected curve in Cryptodev.
60  * https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml
61  */
62 enum rte_crypto_curve_id {
63 	RTE_CRYPTO_EC_GROUP_SECP192R1 = 19,
64 	RTE_CRYPTO_EC_GROUP_SECP224R1 = 21,
65 	RTE_CRYPTO_EC_GROUP_SECP256R1 = 23,
66 	RTE_CRYPTO_EC_GROUP_SECP384R1 = 24,
67 	RTE_CRYPTO_EC_GROUP_SECP521R1 = 25,
68 	RTE_CRYPTO_EC_GROUP_ED25519   = 29,
69 	RTE_CRYPTO_EC_GROUP_ED448     = 30,
70 	RTE_CRYPTO_EC_GROUP_SM2       = 41,
71 };
72 
73 /**
74  * List of Edwards curve instances as per RFC 8032 (Section 5).
75  */
76 enum rte_crypto_edward_instance {
77 	RTE_CRYPTO_EDCURVE_25519,
78 	RTE_CRYPTO_EDCURVE_25519CTX,
79 	RTE_CRYPTO_EDCURVE_25519PH,
80 	RTE_CRYPTO_EDCURVE_448,
81 	RTE_CRYPTO_EDCURVE_448PH
82 };
83 
84 /**
85  * Asymmetric crypto transformation types.
86  * Each xform type maps to one asymmetric algorithm
87  * performing specific operation
88  */
89 enum rte_crypto_asym_xform_type {
90 	RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED = 0,
91 	/**< Invalid xform. */
92 	RTE_CRYPTO_ASYM_XFORM_NONE,
93 	/**< Xform type None.
94 	 * May be supported by PMD to support
95 	 * passthrough op for debugging purpose.
96 	 * if xform_type none , op_type is disregarded.
97 	 */
98 	RTE_CRYPTO_ASYM_XFORM_RSA,
99 	/**< RSA. Performs Encrypt, Decrypt, Sign and Verify.
100 	 * Refer to rte_crypto_asym_op_type
101 	 */
102 	RTE_CRYPTO_ASYM_XFORM_DH,
103 	/**< Diffie-Hellman.
104 	 * Performs Key Generate and Shared Secret Compute.
105 	 * Refer to rte_crypto_asym_op_type
106 	 */
107 	RTE_CRYPTO_ASYM_XFORM_DSA,
108 	/**< Digital Signature Algorithm
109 	 * Performs Signature Generation and Verification.
110 	 * Refer to rte_crypto_asym_op_type
111 	 */
112 	RTE_CRYPTO_ASYM_XFORM_MODINV,
113 	/**< Modular Multiplicative Inverse
114 	 * Perform Modular Multiplicative Inverse b^(-1) mod n
115 	 */
116 	RTE_CRYPTO_ASYM_XFORM_MODEX,
117 	/**< Modular Exponentiation
118 	 * Perform Modular Exponentiation b^e mod n
119 	 */
120 	RTE_CRYPTO_ASYM_XFORM_ECDSA,
121 	/**< Elliptic Curve Digital Signature Algorithm
122 	 * Perform Signature Generation and Verification.
123 	 */
124 	RTE_CRYPTO_ASYM_XFORM_ECDH,
125 	/**< Elliptic Curve Diffie Hellman */
126 	RTE_CRYPTO_ASYM_XFORM_ECPM,
127 	/**< Elliptic Curve Point Multiplication */
128 	RTE_CRYPTO_ASYM_XFORM_ECFPM,
129 	/**< Elliptic Curve Fixed Point Multiplication */
130 	RTE_CRYPTO_ASYM_XFORM_SM2,
131 	/**< ShangMi 2
132 	 * Performs Encrypt, Decrypt, Sign and Verify.
133 	 * Refer to rte_crypto_asym_op_type.
134 	 */
135 	RTE_CRYPTO_ASYM_XFORM_EDDSA,
136 	/**< Edwards Curve Digital Signature Algorithm
137 	 * Perform Signature Generation and Verification.
138 	 */
139 };
140 
141 /**
142  * Asymmetric crypto operation type variants
143  */
144 enum rte_crypto_asym_op_type {
145 	RTE_CRYPTO_ASYM_OP_ENCRYPT,
146 	/**< Asymmetric Encrypt operation */
147 	RTE_CRYPTO_ASYM_OP_DECRYPT,
148 	/**< Asymmetric Decrypt operation */
149 	RTE_CRYPTO_ASYM_OP_SIGN,
150 	/**< Signature Generation operation */
151 	RTE_CRYPTO_ASYM_OP_VERIFY,
152 	/**< Signature Verification operation */
153 	RTE_CRYPTO_ASYM_OP_LIST_END
154 };
155 
156 /**
157  * Asymmetric crypto key exchange operation type
158  */
159 enum rte_crypto_asym_ke_type {
160 	RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE,
161 	/**< Private Key generation operation */
162 	RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE,
163 	/**< Public Key generation operation */
164 	RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE,
165 	/**< Shared Secret compute operation */
166 	RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY
167 	/**< Public Key Verification - can be used for
168 	 * elliptic curve point validation.
169 	 */
170 };
171 
172 /**
173  * Padding types for RSA signature.
174  */
175 enum rte_crypto_rsa_padding_type {
176 	RTE_CRYPTO_RSA_PADDING_NONE = 0,
177 	/**< RSA no padding scheme */
178 	RTE_CRYPTO_RSA_PADDING_PKCS1_5,
179 	/**< RSA PKCS#1 PKCS1-v1_5 padding scheme. For signatures block type 01,
180 	 * for encryption block type 02 are used.
181 	 */
182 	RTE_CRYPTO_RSA_PADDING_OAEP,
183 	/**< RSA PKCS#1 OAEP padding scheme */
184 	RTE_CRYPTO_RSA_PADDING_PSS,
185 	/**< RSA PKCS#1 PSS padding scheme */
186 };
187 
188 /**
189  * RSA private key type enumeration
190  *
191  * enumerates private key format required to perform RSA crypto
192  * transform.
193  */
194 enum rte_crypto_rsa_priv_key_type {
195 	RTE_RSA_KEY_TYPE_EXP,
196 	/**< RSA private key is an exponent */
197 	RTE_RSA_KEY_TYPE_QT,
198 	/**< RSA private key is in quintuple format
199 	 * See rte_crypto_rsa_priv_key_qt
200 	 */
201 };
202 
203 /**
204  * Buffer to hold crypto params required for asym operations.
205  *
206  * These buffers can be used for both input to PMD and output from PMD. When
207  * used for output from PMD, application has to ensure the buffer is large
208  * enough to hold the target data.
209  *
210  * If an operation requires the PMD to generate a random number,
211  * and the device supports CSRNG, 'data' should be set to NULL.
212  * The crypto parameter in question will not be used by the PMD,
213  * as it is internally generated.
214  */
215 typedef struct rte_crypto_param_t {
216 	uint8_t *data;
217 	/**< pointer to buffer holding data */
218 	rte_iova_t iova;
219 	/**< IO address of data buffer */
220 	size_t length;
221 	/**< length of data in bytes */
222 } rte_crypto_param;
223 
224 /** Unsigned big-integer in big-endian format */
225 typedef rte_crypto_param rte_crypto_uint;
226 
227 /**
228  * Structure for elliptic curve point
229  */
230 struct rte_crypto_ec_point {
231 	rte_crypto_param x;
232 	/**< X coordinate */
233 	rte_crypto_param y;
234 	/**< Y coordinate */
235 };
236 
237 /**
238  * Structure describing RSA private key in quintuple format.
239  * See PKCS V1.5 RSA Cryptography Standard.
240  */
241 struct rte_crypto_rsa_priv_key_qt {
242 	rte_crypto_uint p;
243 	/**< the first factor */
244 	rte_crypto_uint q;
245 	/**< the second factor */
246 	rte_crypto_uint dP;
247 	/**< the first factor's CRT exponent */
248 	rte_crypto_uint dQ;
249 	/**< the second's factor's CRT exponent */
250 	rte_crypto_uint qInv;
251 	/**< the CRT coefficient */
252 };
253 
254 /**
255  * RSA padding type
256  */
257 struct rte_crypto_rsa_padding {
258 	enum rte_crypto_rsa_padding_type type;
259 	/**< RSA padding scheme to be used for transform */
260 	enum rte_crypto_auth_algorithm hash;
261 	/**<
262 	 * RSA padding hash algorithm
263 	 * Valid hash algorithms are:
264 	 * MD5, SHA1, SHA224, SHA256, SHA384, SHA512
265 	 *
266 	 * When a specific padding type is selected, the following rules apply:
267 	 * - RTE_CRYPTO_RSA_PADDING_NONE:
268 	 * This field is ignored by the PMD
269 	 *
270 	 * - RTE_CRYPTO_RSA_PADDING_PKCS1_5:
271 	 * When signing an operation this field is used to determine value
272 	 * of the DigestInfo structure, therefore specifying which algorithm
273 	 * was used to create the message digest.
274 	 * When doing encryption/decryption this field is ignored for this
275 	 * padding type.
276 	 *
277 	 * - RTE_CRYPTO_RSA_PADDING_OAEP
278 	 * This field shall be set with the hash algorithm used
279 	 * in the padding scheme
280 	 *
281 	 * - RTE_CRYPTO_RSA_PADDING_PSS
282 	 * This field shall be set with the hash algorithm used
283 	 * in the padding scheme (and to create the input message digest)
284 	 */
285 	enum rte_crypto_auth_algorithm mgf1hash;
286 	/**<
287 	 * Hash algorithm to be used for mask generation if the
288 	 * padding scheme is either OAEP or PSS. If the padding
289 	 * scheme is unspecified a data hash algorithm is used
290 	 * for mask generation. Valid hash algorithms are:
291 	 * MD5, SHA1, SHA224, SHA256, SHA384, SHA512
292 	 */
293 	uint16_t pss_saltlen;
294 	/**<
295 	 * RSA PSS padding salt length
296 	 *
297 	 * Used only when RTE_CRYPTO_RSA_PADDING_PSS padding is selected,
298 	 * otherwise ignored.
299 	 */
300 	rte_crypto_param oaep_label;
301 	/**<
302 	 * RSA OAEP padding optional label
303 	 *
304 	 * Used only when RTE_CRYPTO_RSA_PADDING_OAEP padding is selected,
305 	 * otherwise ignored. If label.data == NULL, a default
306 	 * label (empty string) is used.
307 	 */
308 };
309 
310 /**
311  * Asymmetric RSA transform data
312  *
313  * Structure describing RSA xform params
314  */
315 struct rte_crypto_rsa_xform {
316 	rte_crypto_uint n;
317 	/**< the RSA modulus */
318 	rte_crypto_uint e;
319 	/**< the RSA public exponent */
320 
321 	enum rte_crypto_rsa_priv_key_type key_type;
322 
323 	struct {
324 		rte_crypto_uint d;
325 		/**< the RSA private exponent */
326 		struct rte_crypto_rsa_priv_key_qt qt;
327 		/**< qt - Private key in quintuple format */
328 	};
329 
330 	struct rte_crypto_rsa_padding padding;
331 	/**< RSA padding information */
332 };
333 
334 /**
335  * Asymmetric Modular exponentiation transform data
336  *
337  * Structure describing modular exponentiation xform param
338  */
339 struct rte_crypto_modex_xform {
340 	rte_crypto_uint modulus;
341 	/**< Modulus data for modexp transform operation */
342 	rte_crypto_uint exponent;
343 	/**< Exponent of the modexp transform operation */
344 };
345 
346 /**
347  * Asymmetric modular multiplicative inverse transform operation
348  *
349  * Structure describing modular multiplicative inverse transform
350  */
351 struct rte_crypto_modinv_xform {
352 	rte_crypto_uint modulus;
353 	/**< Modulus data for modular multiplicative inverse operation */
354 };
355 
356 /**
357  * Asymmetric DH transform data
358  *
359  * Structure describing deffie-hellman xform params
360  */
361 struct rte_crypto_dh_xform {
362 	rte_crypto_uint p;
363 	/**< Prime modulus data */
364 	rte_crypto_uint g;
365 	/**< DH Generator */
366 };
367 
368 /**
369  * Asymmetric Digital Signature transform operation
370  *
371  * Structure describing DSA xform params
372  */
373 struct rte_crypto_dsa_xform {
374 	rte_crypto_uint p;
375 	/**< Prime modulus */
376 	rte_crypto_uint q;
377 	/**< Order of the subgroup */
378 	rte_crypto_uint g;
379 	/**< Generator of the subgroup */
380 	rte_crypto_uint x;
381 	/**< x: Private key of the signer */
382 };
383 
384 /**
385  * Asymmetric elliptic curve transform data
386  *
387  * Structure describing all EC based xform params
388  */
389 struct rte_crypto_ec_xform {
390 	enum rte_crypto_curve_id curve_id;
391 	/**< Pre-defined ec groups */
392 
393 	rte_crypto_uint pkey;
394 	/**< Private key */
395 
396 	struct rte_crypto_ec_point q;
397 	/**< Public key */
398 };
399 
400 /**
401  * Operations params for modular operations:
402  * exponentiation and multiplicative inverse
403  */
404 struct rte_crypto_mod_op_param {
405 	rte_crypto_uint base;
406 	/**< Base of modular exponentiation/multiplicative inverse. */
407 	rte_crypto_uint result;
408 	/**< Result of modular exponentiation/multiplicative inverse. */
409 };
410 
411 /**
412  * RSA operation params
413  */
414 struct rte_crypto_rsa_op_param {
415 	enum rte_crypto_asym_op_type op_type;
416 	/**< Type of RSA operation for transform */
417 
418 	rte_crypto_param message;
419 	/**<
420 	 * Pointer to input data
421 	 * - to be encrypted for RSA public encrypt.
422 	 * - to be signed for RSA sign generation.
423 	 * - to be authenticated for RSA sign verification.
424 	 *
425 	 * Pointer to output data
426 	 * - for RSA private decrypt.
427 	 * In this case the underlying array should have been
428 	 * allocated with enough memory to hold plaintext output
429 	 * (i.e. must be at least RSA key size). The message.length
430 	 * field could be either 0 or minimal length expected from PMD.
431 	 * This could be validated and overwritten by the PMD
432 	 * with the decrypted length.
433 	 */
434 
435 	rte_crypto_param cipher;
436 	/**<
437 	 * Pointer to input data
438 	 * - to be decrypted for RSA private decrypt.
439 	 *
440 	 * Pointer to output data
441 	 * - for RSA public encrypt.
442 	 * In this case the underlying array should have been allocated
443 	 * with enough memory to hold ciphertext output (i.e. must be
444 	 * at least RSA key size). The cipher.length field could be
445 	 * either 0 or minimal length expected from PMD.
446 	 * This could be validated and overwritten by the PMD
447 	 * with the encrypted length.
448 	 *
449 	 * When RTE_CRYPTO_RSA_PADDING_NONE and RTE_CRYPTO_ASYM_OP_VERIFY
450 	 * selected, this is an output of decrypted signature.
451 	 */
452 
453 	rte_crypto_param sign;
454 	/**<
455 	 * Pointer to input data
456 	 * - to be verified for RSA public decrypt.
457 	 *
458 	 * Pointer to output data
459 	 * - for RSA private encrypt.
460 	 * In this case the underlying array should have been allocated
461 	 * with enough memory to hold signature output (i.e. must be
462 	 * at least RSA key size). The sign.length field could be
463 	 * either 0 or minimal length expected from PMD.
464 	 * This could be validated and overwritten by the PMD
465 	 * with the signature length.
466 	 */
467 };
468 
469 /**
470  * Diffie-Hellman Operations params.
471  * @note:
472  */
473 struct rte_crypto_dh_op_param {
474 	enum rte_crypto_asym_ke_type ke_type;
475 	/**< Key exchange operation type */
476 	rte_crypto_uint priv_key;
477 	/**<
478 	 * Output - generated private key when ke_type is
479 	 * RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE.
480 	 *
481 	 * Input - private key when ke_type is one of:
482 	 * RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE,
483 	 * RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE.
484 	 *
485 	 * In case priv_key.length is 0 and ke_type is set with
486 	 * RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE, CSRNG capable
487 	 * device will generate a private key and use it for public
488 	 * key generation.
489 	 */
490 	rte_crypto_uint pub_key;
491 	/**<
492 	 * Output - generated public key when ke_type is
493 	 * RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE.
494 	 *
495 	 * Input - peer's public key when ke_type is
496 	 * RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE.
497 	 */
498 	rte_crypto_uint shared_secret;
499 	/**<
500 	 * Output - calculated shared secret when ke_type is
501 	 * RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE.
502 	 */
503 };
504 
505 /**
506  * Elliptic Curve Diffie-Hellman Operations params.
507  */
508 struct rte_crypto_ecdh_op_param {
509 	enum rte_crypto_asym_ke_type ke_type;
510 	/**< Key exchange operation type */
511 	rte_crypto_uint priv_key;
512 	/**<
513 	 * Output - generated private key when ke_type is
514 	 * RTE_CRYPTO_ASYM_KE_PRIVATE_KEY_GENERATE.
515 	 *
516 	 * Input - private key when ke_type is one of:
517 	 * RTE_CRYPTO_ASYM_KE_PUBLIC_KEY_GENERATE,
518 	 * RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE.
519 	 *
520 	 * In case priv_key.length is 0 and ke_type is set with
521 	 * RTE_CRYPTO_ASYM_KE_PUBLIC_KEY_GENERATE, CSRNG capable
522 	 * device will generate private key and use it for public
523 	 * key generation.
524 	 */
525 	struct rte_crypto_ec_point pub_key;
526 	/**<
527 	 * Output - generated public key when ke_type is
528 	 * RTE_CRYPTO_ASYM_KE_PUBLIC_KEY_GENERATE.
529 	 *
530 	 * Input - peer's public key, when ke_type is one of:
531 	 * RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE,
532 	 * RTE_CRYPTO_ASYM_KE_EC_PUBLIC_KEY_VERIFY.
533 	 */
534 	struct rte_crypto_ec_point shared_secret;
535 	/**<
536 	 * Output - calculated shared secret when ke_type is
537 	 * RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE.
538 	 */
539 };
540 
541 /**
542  * DSA Operations params
543  */
544 struct rte_crypto_dsa_op_param {
545 	enum rte_crypto_asym_op_type op_type;
546 	/**< Signature Generation or Verification */
547 	rte_crypto_param message;
548 	/**< input message to be signed or verified */
549 	rte_crypto_uint k;
550 	/**< Per-message secret number, which is an integer
551 	 * in the interval (1, q-1).
552 	 * If the random number is generated by the PMD,
553 	 * the 'rte_crypto_param.data' parameter should be set to NULL.
554 	 */
555 	rte_crypto_uint r;
556 	/**< dsa sign component 'r' value
557 	 *
558 	 * output if op_type = sign generate,
559 	 * input if op_type = sign verify
560 	 */
561 	rte_crypto_uint s;
562 	/**< dsa sign component 's' value
563 	 *
564 	 * output if op_type = sign generate,
565 	 * input if op_type = sign verify
566 	 */
567 	rte_crypto_uint y;
568 	/**< y : Public key of the signer.
569 	 * y = g^x mod p
570 	 */
571 };
572 
573 /**
574  * ECDSA operation params
575  */
576 struct rte_crypto_ecdsa_op_param {
577 	enum rte_crypto_asym_op_type op_type;
578 	/**< Signature generation or verification */
579 
580 	rte_crypto_param message;
581 	/**< Input message digest to be signed or verified */
582 
583 	rte_crypto_uint k;
584 	/**< The ECDSA per-message secret number, which is an integer
585 	 * in the interval (1, n-1).
586 	 * If the random number is generated by the PMD,
587 	 * the 'rte_crypto_param.data' parameter should be set to NULL.
588 	 */
589 
590 	rte_crypto_uint r;
591 	/**< r component of elliptic curve signature
592 	 *     output : for signature generation
593 	 *     input  : for signature verification
594 	 */
595 	rte_crypto_uint s;
596 	/**< s component of elliptic curve signature
597 	 *     output : for signature generation
598 	 *     input  : for signature verification
599 	 */
600 };
601 
602 /**
603  * EdDSA operation params
604  */
605 struct rte_crypto_eddsa_op_param {
606 	enum rte_crypto_asym_op_type op_type;
607 	/**< Signature generation or verification */
608 
609 	rte_crypto_param message;
610 	/**< Input message digest to be signed or verified */
611 
612 	rte_crypto_param context;
613 	/**< Context value for the sign op.
614 	 *   Must not be empty for Ed25519ctx instance.
615 	 */
616 
617 	enum rte_crypto_edward_instance instance;
618 	/**< Type of Edwards curve. */
619 
620 	rte_crypto_uint sign;
621 	/**< Edward curve signature
622 	 *     output : for signature generation
623 	 *     input  : for signature verification
624 	 */
625 };
626 
627 /**
628  * Structure for EC point multiplication operation param
629  */
630 struct rte_crypto_ecpm_op_param {
631 	struct rte_crypto_ec_point p;
632 	/**< x and y coordinates of input point */
633 
634 	struct rte_crypto_ec_point r;
635 	/**< x and y coordinates of resultant point */
636 
637 	rte_crypto_param scalar;
638 	/**< Scalar to multiply the input point */
639 };
640 
641 /**
642  * SM2 operation capabilities
643  */
644 enum rte_crypto_sm2_op_capa {
645 	RTE_CRYPTO_SM2_RNG,
646 	/**< Random number generator supported in SM2 ops. */
647 	RTE_CRYPTO_SM2_PH,
648 	/**< Prehash message before crypto op. */
649 };
650 
651 /**
652  * SM2 operation params.
653  */
654 struct rte_crypto_sm2_op_param {
655 	enum rte_crypto_asym_op_type op_type;
656 	/**< Signature generation or verification. */
657 
658 	enum rte_crypto_auth_algorithm hash;
659 	/**< Hash algorithm used in EC op. */
660 
661 	rte_crypto_param message;
662 	/**<
663 	 * Pointer to input data
664 	 * - to be encrypted for SM2 public encrypt.
665 	 * - to be signed for SM2 sign generation.
666 	 * - to be authenticated for SM2 sign verification.
667 	 *
668 	 * Pointer to output data
669 	 * - for SM2 private decrypt.
670 	 * In this case the underlying array should have been
671 	 * allocated with enough memory to hold plaintext output
672 	 * (at least encrypted text length). The message.length field
673 	 * will be overwritten by the PMD with the decrypted length.
674 	 */
675 
676 	rte_crypto_param cipher;
677 	/**<
678 	 * Pointer to input data
679 	 * - to be decrypted for SM2 private decrypt.
680 	 *
681 	 * Pointer to output data
682 	 * - for SM2 public encrypt.
683 	 * In this case the underlying array should have been allocated
684 	 * with enough memory to hold ciphertext output (at least X bytes
685 	 * for prime field curve of N bytes and for message M bytes,
686 	 * where X = (C1 || C2 || C3) and computed based on SM2 RFC as
687 	 * C1 (1 + N + N), C2 = M, C3 = N. The cipher.length field will
688 	 * be overwritten by the PMD with the encrypted length.
689 	 */
690 
691 	rte_crypto_uint id;
692 	/**< The SM2 id used by signer and verifier. */
693 
694 	rte_crypto_uint k;
695 	/**< The SM2 per-message secret number, which is an integer
696 	 * in the interval (1, n-1).
697 	 * If the random number is generated by the PMD,
698 	 * the 'rte_crypto_param.data' parameter should be set to NULL.
699 	 */
700 
701 	rte_crypto_uint r;
702 	/**< r component of elliptic curve signature
703 	 *     output : for signature generation (of at least N bytes
704 	 *              where prime field length is N bytes)
705 	 *     input  : for signature verification
706 	 */
707 	rte_crypto_uint s;
708 	/**< s component of elliptic curve signature
709 	 *     output : for signature generation (of at least N bytes
710 	 *              where prime field length is N bytes)
711 	 *     input  : for signature verification
712 	 */
713 };
714 
715 /**
716  * Asymmetric crypto transform data
717  *
718  * Structure describing asym xforms.
719  */
720 struct rte_crypto_asym_xform {
721 	struct rte_crypto_asym_xform *next;
722 	/**< Pointer to next xform to set up xform chain.*/
723 	enum rte_crypto_asym_xform_type xform_type;
724 	/**< Asymmetric crypto transform */
725 
726 	union {
727 		struct rte_crypto_rsa_xform rsa;
728 		/**< RSA xform parameters */
729 
730 		struct rte_crypto_modex_xform modex;
731 		/**< Modular Exponentiation xform parameters */
732 
733 		struct rte_crypto_modinv_xform modinv;
734 		/**< Modular Multiplicative Inverse xform parameters */
735 
736 		struct rte_crypto_dh_xform dh;
737 		/**< DH xform parameters */
738 
739 		struct rte_crypto_dsa_xform dsa;
740 		/**< DSA xform parameters */
741 
742 		struct rte_crypto_ec_xform ec;
743 		/**< EC xform parameters, used by elliptic curve based
744 		 * operations.
745 		 */
746 	};
747 };
748 
749 /**
750  * Asymmetric Cryptographic Operation.
751  *
752  * Structure describing asymmetric crypto operation params.
753  */
754 struct rte_crypto_asym_op {
755 	union {
756 		struct rte_cryptodev_asym_session *session;
757 		/**< Handle for the initialised session context */
758 		struct rte_crypto_asym_xform *xform;
759 		/**< Session-less API crypto operation parameters */
760 	};
761 
762 	union {
763 		struct rte_crypto_rsa_op_param rsa;
764 		struct rte_crypto_mod_op_param modex;
765 		struct rte_crypto_mod_op_param modinv;
766 		struct rte_crypto_dh_op_param dh;
767 		struct rte_crypto_ecdh_op_param ecdh;
768 		struct rte_crypto_dsa_op_param dsa;
769 		struct rte_crypto_ecdsa_op_param ecdsa;
770 		struct rte_crypto_ecpm_op_param ecpm;
771 		struct rte_crypto_sm2_op_param sm2;
772 		struct rte_crypto_eddsa_op_param eddsa;
773 	};
774 	uint16_t flags;
775 	/**<
776 	 * Asymmetric crypto operation flags.
777 	 * Please refer to the RTE_CRYPTO_ASYM_FLAG_*.
778 	 */
779 };
780 
781 #endif /* _RTE_CRYPTO_ASYM_H_ */
782