1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Cavium Networks
5 #ifndef _RTE_CRYPTO_ASYM_H_
6 #define _RTE_CRYPTO_ASYM_H_
9 * @file rte_crypto_asym.h
11 * RTE Definitions for Asymmetric Cryptography
13 * Defines asymmetric algorithms and modes, as well as supported
14 * asymmetric crypto operations.
24 #include <rte_memory.h>
25 #include <rte_mempool.h>
26 #include <rte_common.h>
28 #include "rte_crypto_sym.h"
31 * Buffer to hold crypto params required for asym operations.
33 * These buffers can be used for both input to PMD and output from PMD. When
34 * used for output from PMD, application has to ensure the buffer is large
35 * enough to hold the target data.
37 typedef struct rte_crypto_param_t {
39 /**< pointer to buffer holding data */
41 /**< IO address of data buffer */
43 /**< length of data in bytes */
46 /** asym xform type name strings */
48 rte_crypto_asym_xform_strings[];
50 /** asym operations type name strings */
52 rte_crypto_asym_op_strings[];
55 * Asymmetric crypto transformation types.
56 * Each xform type maps to one asymmetric algorithm
57 * performing specific operation
60 enum rte_crypto_asym_xform_type {
61 RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED = 0,
62 /**< Invalid xform. */
63 RTE_CRYPTO_ASYM_XFORM_NONE,
65 * May be supported by PMD to support
66 * passthrough op for debugging purpose.
67 * if xform_type none , op_type is disregarded.
69 RTE_CRYPTO_ASYM_XFORM_RSA,
70 /**< RSA. Performs Encrypt, Decrypt, Sign and Verify.
71 * Refer to rte_crypto_asym_op_type
73 RTE_CRYPTO_ASYM_XFORM_DH,
75 * Performs Key Generate and Shared Secret Compute.
76 * Refer to rte_crypto_asym_op_type
78 RTE_CRYPTO_ASYM_XFORM_DSA,
79 /**< Digital Signature Algorithm
80 * Performs Signature Generation and Verification.
81 * Refer to rte_crypto_asym_op_type
83 RTE_CRYPTO_ASYM_XFORM_MODINV,
84 /**< Modular Multiplicative Inverse
85 * Perform Modular Multiplicative Inverse b^(-1) mod n
87 RTE_CRYPTO_ASYM_XFORM_MODEX,
88 /**< Modular Exponentiation
89 * Perform Modular Exponentiation b^e mod n
91 RTE_CRYPTO_ASYM_XFORM_ECDSA,
92 /**< Elliptic Curve Digital Signature Algorithm
93 * Perform Signature Generation and Verification.
95 RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
100 * Asymmetric crypto operation type variants
102 enum rte_crypto_asym_op_type {
103 RTE_CRYPTO_ASYM_OP_ENCRYPT,
104 /**< Asymmetric Encrypt operation */
105 RTE_CRYPTO_ASYM_OP_DECRYPT,
106 /**< Asymmetric Decrypt operation */
107 RTE_CRYPTO_ASYM_OP_SIGN,
108 /**< Signature Generation operation */
109 RTE_CRYPTO_ASYM_OP_VERIFY,
110 /**< Signature Verification operation */
111 RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE,
112 /**< DH Private Key generation operation */
113 RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE,
114 /**< DH Public Key generation operation */
115 RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE,
116 /**< DH Shared Secret compute operation */
117 RTE_CRYPTO_ASYM_OP_LIST_END
121 * Padding types for RSA signature.
123 enum rte_crypto_rsa_padding_type {
124 RTE_CRYPTO_RSA_PADDING_NONE = 0,
125 /**< RSA no padding scheme */
126 RTE_CRYPTO_RSA_PADDING_PKCS1_5,
127 /**< RSA PKCS#1 PKCS1-v1_5 padding scheme. For signatures block type 01,
128 * for encryption block type 02 are used.
130 RTE_CRYPTO_RSA_PADDING_OAEP,
131 /**< RSA PKCS#1 OAEP padding scheme */
132 RTE_CRYPTO_RSA_PADDING_PSS,
133 /**< RSA PKCS#1 PSS padding scheme */
134 RTE_CRYPTO_RSA_PADDING_TYPE_LIST_END
138 * RSA private key type enumeration
140 * enumerates private key format required to perform RSA crypto
144 enum rte_crypto_rsa_priv_key_type {
145 RTE_RSA_KEY_TYPE_EXP,
146 /**< RSA private key is an exponent */
148 /**< RSA private key is in quintuple format
149 * See rte_crypto_rsa_priv_key_qt
154 * Structure describing RSA private key in quintuple format.
155 * See PKCS V1.5 RSA Cryptography Standard.
157 struct rte_crypto_rsa_priv_key_qt {
159 /**< p - Private key component P
160 * Private key component of RSA parameter required for CRT method
161 * of private key operations in Octet-string network byte order
166 /**< q - Private key component Q
167 * Private key component of RSA parameter required for CRT method
168 * of private key operations in Octet-string network byte order
173 /**< dP - Private CRT component
174 * Private CRT component of RSA parameter required for CRT method
175 * RSA private key operations in Octet-string network byte order
177 * dP = d mod ( p - 1 )
181 /**< dQ - Private CRT component
182 * Private CRT component of RSA parameter required for CRT method
183 * RSA private key operations in Octet-string network byte order
185 * dQ = d mod ( q - 1 )
188 rte_crypto_param qInv;
189 /**< qInv - Private CRT component
190 * Private CRT component of RSA parameter required for CRT method
191 * RSA private key operations in Octet-string network byte order
198 * Asymmetric RSA transform data
200 * Structure describing RSA xform params
203 struct rte_crypto_rsa_xform {
206 * Modulus data of RSA operation in Octet-string network
211 /**< e - Public key exponent
212 * Public key exponent used for RSA public key operations in Octet-
213 * string network byte order format.
216 enum rte_crypto_rsa_priv_key_type key_type;
221 /**< d - Private key exponent
222 * Private key exponent used for RSA
223 * private key operations in
224 * Octet-string network byte order format.
227 struct rte_crypto_rsa_priv_key_qt qt;
228 /**< qt - Private key in quintuple format */
233 * Asymmetric Modular exponentiation transform data
235 * Structure describing modular exponentiation xform param
238 struct rte_crypto_modex_xform {
239 rte_crypto_param modulus;
241 * Pointer to the modulus data for modexp transform operation
242 * in octet-string network byte order format
244 * In case this number is equal to zero the driver shall set
245 * the crypto op status field to RTE_CRYPTO_OP_STATUS_ERROR
248 rte_crypto_param exponent;
250 * Exponent of the modexp transform operation in
251 * octet-string network byte order format
256 * Asymmetric modular multiplicative inverse transform operation
258 * Structure describing modular multiplicative inverse transform
261 struct rte_crypto_modinv_xform {
262 rte_crypto_param modulus;
264 * Pointer to the modulus data for modular multiplicative inverse
265 * operation in octet-string network byte order format
267 * In case this number is equal to zero the driver shall set
268 * the crypto op status field to RTE_CRYPTO_OP_STATUS_ERROR
270 * This number shall be relatively prime to base
271 * in corresponding Modular Multiplicative Inverse
272 * rte_crypto_mod_op_param
277 * Asymmetric DH transform data
279 * Structure describing deffie-hellman xform params
282 struct rte_crypto_dh_xform {
283 enum rte_crypto_asym_op_type type;
284 /**< Setup xform for key generate or shared secret compute */
287 /**< p : Prime modulus data
288 * DH prime modulus data in octet-string network byte order format.
294 * DH group generator data in octet-string network byte order
301 * Asymmetric Digital Signature transform operation
303 * Structure describing DSA xform params
306 struct rte_crypto_dsa_xform {
308 /**< p - Prime modulus
309 * Prime modulus data for DSA operation in Octet-string network byte
313 /**< q : Order of the subgroup.
314 * Order of the subgroup data in Octet-string network byte order
319 /**< g: Generator of the subgroup
320 * Generator data in Octet-string network byte order format.
323 /**< x: Private key of the signer in octet-string network
325 * Used when app has pre-defined private key.
326 * Valid only when xform chain is DSA ONLY.
327 * if xform chain is DH private key generate + DSA, then DSA sign
328 * compute will use internally generated key.
334 * https://tools.ietf.org/html/rfc8422
336 enum rte_crypto_ec_group {
337 RTE_CRYPTO_EC_GROUP_UNKNOWN = 0,
338 RTE_CRYPTO_EC_GROUP_SECP192R1 = 19,
339 RTE_CRYPTO_EC_GROUP_SECP224R1 = 21,
340 RTE_CRYPTO_EC_GROUP_SECP256R1 = 23,
341 RTE_CRYPTO_EC_GROUP_SECP384R1 = 24,
342 RTE_CRYPTO_EC_GROUP_SECP521R1 = 25,
346 * Structure for elliptic curve point
348 struct rte_crypto_ec_point {
356 * Asymmetric elliptic curve transform data
358 * Structure describing all EC based xform params
361 struct rte_crypto_ec_xform {
362 enum rte_crypto_ec_group curve_id;
363 /**< Pre-defined ec groups */
367 * Operations params for modular operations:
368 * exponentiation and multiplicative inverse
371 struct rte_crypto_mod_op_param {
372 rte_crypto_param base;
374 * Pointer to base of modular exponentiation/multiplicative
375 * inverse data in octet-string network byte order format
377 * In case Multiplicative Inverse is used this number shall
378 * be relatively prime to modulus in corresponding Modular
379 * Multiplicative Inverse rte_crypto_modinv_xform
382 rte_crypto_param result;
384 * Pointer to the result of modular exponentiation/multiplicative inverse
385 * data in octet-string network byte order format.
387 * This field shall be big enough to hold the result of Modular
388 * Exponentiation or Modular Multiplicative Inverse
389 * (bigger or equal to length of modulus)
394 * Asymmetric crypto transform data
396 * Structure describing asym xforms.
398 struct rte_crypto_asym_xform {
399 struct rte_crypto_asym_xform *next;
400 /**< Pointer to next xform to set up xform chain.*/
401 enum rte_crypto_asym_xform_type xform_type;
402 /**< Asymmetric crypto transform */
406 struct rte_crypto_rsa_xform rsa;
407 /**< RSA xform parameters */
409 struct rte_crypto_modex_xform modex;
410 /**< Modular Exponentiation xform parameters */
412 struct rte_crypto_modinv_xform modinv;
413 /**< Modular Multiplicative Inverse xform parameters */
415 struct rte_crypto_dh_xform dh;
416 /**< DH xform parameters */
418 struct rte_crypto_dsa_xform dsa;
419 /**< DSA xform parameters */
421 struct rte_crypto_ec_xform ec;
422 /**< EC xform parameters, used by elliptic curve based
428 struct rte_cryptodev_asym_session;
431 * RSA operation params
434 struct rte_crypto_rsa_op_param {
435 enum rte_crypto_asym_op_type op_type;
436 /**< Type of RSA operation for transform */
438 rte_crypto_param message;
440 * Pointer to input data
441 * - to be encrypted for RSA public encrypt.
442 * - to be signed for RSA sign generation.
443 * - to be authenticated for RSA sign verification.
445 * Pointer to output data
446 * - for RSA private decrypt.
447 * In this case the underlying array should have been
448 * allocated with enough memory to hold plaintext output
449 * (i.e. must be at least RSA key size). The message.length
450 * field should be 0 and will be overwritten by the PMD
451 * with the decrypted length.
453 * All data is in Octet-string network byte order format.
456 rte_crypto_param cipher;
458 * Pointer to input data
459 * - to be decrypted for RSA private decrypt.
461 * Pointer to output data
462 * - for RSA public encrypt.
463 * In this case the underlying array should have been allocated
464 * with enough memory to hold ciphertext output (i.e. must be
465 * at least RSA key size). The cipher.length field should
466 * be 0 and will be overwritten by the PMD with the encrypted length.
468 * All data is in Octet-string network byte order format.
471 rte_crypto_param sign;
473 * Pointer to input data
474 * - to be verified for RSA public decrypt.
476 * Pointer to output data
477 * - for RSA private encrypt.
478 * In this case the underlying array should have been allocated
479 * with enough memory to hold signature output (i.e. must be
480 * at least RSA key size). The sign.length field should
481 * be 0 and will be overwritten by the PMD with the signature length.
483 * All data is in Octet-string network byte order format.
486 enum rte_crypto_rsa_padding_type pad;
487 /**< RSA padding scheme to be used for transform */
489 enum rte_crypto_auth_algorithm md;
490 /**< Hash algorithm to be used for data hash if padding
491 * scheme is either OAEP or PSS. Valid hash algorithms
493 * MD5, SHA1, SHA224, SHA256, SHA384, SHA512
496 enum rte_crypto_auth_algorithm mgf1md;
498 * Hash algorithm to be used for mask generation if
499 * padding scheme is either OAEP or PSS. If padding
500 * scheme is unspecified data hash algorithm is used
501 * for mask generation. Valid hash algorithms are:
502 * MD5, SHA1, SHA224, SHA256, SHA384, SHA512
507 * Diffie-Hellman Operations params.
510 struct rte_crypto_dh_op_param {
511 rte_crypto_param pub_key;
513 * Output generated public key when xform type is
514 * DH PUB_KEY_GENERATION.
515 * Input peer public key when xform type is DH
516 * SHARED_SECRET_COMPUTATION
517 * pub_key is in octet-string network byte order format.
521 rte_crypto_param priv_key;
523 * Output generated private key if xform type is
524 * DH PRIVATE_KEY_GENERATION
525 * Input when xform type is DH SHARED_SECRET_COMPUTATION.
526 * priv_key is in octet-string network byte order format.
530 rte_crypto_param shared_secret;
532 * Output with calculated shared secret
533 * when dh xform set up with op type = SHARED_SECRET_COMPUTATION.
534 * shared_secret is an octet-string network byte order format.
540 * DSA Operations params
543 struct rte_crypto_dsa_op_param {
544 enum rte_crypto_asym_op_type op_type;
545 /**< Signature Generation or Verification */
546 rte_crypto_param message;
547 /**< input message to be signed or verified */
549 /**< dsa sign component 'r' value
551 * output if op_type = sign generate,
552 * input if op_type = sign verify
555 /**< dsa sign component 's' value
557 * output if op_type = sign generate,
558 * input if op_type = sign verify
561 /**< y : Public key of the signer.
562 * Public key data of the signer in Octet-string network byte order
569 * ECDSA operation params
571 struct rte_crypto_ecdsa_op_param {
572 enum rte_crypto_asym_op_type op_type;
573 /**< Signature generation or verification */
575 rte_crypto_param pkey;
576 /**< Private key of the signer for signature generation */
578 struct rte_crypto_ec_point q;
579 /**< Public key of the signer for verification */
581 rte_crypto_param message;
582 /**< Input message digest to be signed or verified */
585 /**< The ECDSA per-message secret number, which is an integer
586 * in the interval (1, n-1)
590 /**< r component of elliptic curve signature
591 * output : for signature generation
592 * input : for signature verification
595 /**< s component of elliptic curve signature
596 * output : for signature generation
597 * input : for signature verification
602 * Asymmetric Cryptographic Operation.
604 * Structure describing asymmetric crypto operation params.
607 struct rte_crypto_asym_op {
610 struct rte_cryptodev_asym_session *session;
611 /**< Handle for the initialised session context */
612 struct rte_crypto_asym_xform *xform;
613 /**< Session-less API crypto operation parameters */
618 struct rte_crypto_rsa_op_param rsa;
619 struct rte_crypto_mod_op_param modex;
620 struct rte_crypto_mod_op_param modinv;
621 struct rte_crypto_dh_op_param dh;
622 struct rte_crypto_dsa_op_param dsa;
623 struct rte_crypto_ecdsa_op_param ecdsa;
631 #endif /* _RTE_CRYPTO_ASYM_H_ */