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"
30 struct rte_cryptodev_asym_session;
32 /** asym xform type name strings */
34 rte_crypto_asym_xform_strings[];
36 /** asym key exchange operation type name strings */
38 rte_crypto_asym_ke_strings[];
40 /** asym operations type name strings */
42 rte_crypto_asym_op_strings[];
45 * List of elliptic curves. This enum aligns with
46 * TLS "Supported Groups" registry (previously known as
47 * NamedCurve registry). FFDH groups are not, and will not
48 * be included in this list.
49 * Deprecation for selected curve in TLS does not deprecate
50 * the selected curve in Cryptodev.
51 * https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml
53 enum rte_crypto_curve_id {
54 RTE_CRYPTO_EC_GROUP_SECP192R1 = 19,
55 RTE_CRYPTO_EC_GROUP_SECP224R1 = 21,
56 RTE_CRYPTO_EC_GROUP_SECP256R1 = 23,
57 RTE_CRYPTO_EC_GROUP_SECP384R1 = 24,
58 RTE_CRYPTO_EC_GROUP_SECP521R1 = 25
62 * Asymmetric crypto transformation types.
63 * Each xform type maps to one asymmetric algorithm
64 * performing specific operation
67 enum rte_crypto_asym_xform_type {
68 RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED = 0,
69 /**< Invalid xform. */
70 RTE_CRYPTO_ASYM_XFORM_NONE,
72 * May be supported by PMD to support
73 * passthrough op for debugging purpose.
74 * if xform_type none , op_type is disregarded.
76 RTE_CRYPTO_ASYM_XFORM_RSA,
77 /**< RSA. Performs Encrypt, Decrypt, Sign and Verify.
78 * Refer to rte_crypto_asym_op_type
80 RTE_CRYPTO_ASYM_XFORM_DH,
82 * Performs Key Generate and Shared Secret Compute.
83 * Refer to rte_crypto_asym_op_type
85 RTE_CRYPTO_ASYM_XFORM_DSA,
86 /**< Digital Signature Algorithm
87 * Performs Signature Generation and Verification.
88 * Refer to rte_crypto_asym_op_type
90 RTE_CRYPTO_ASYM_XFORM_MODINV,
91 /**< Modular Multiplicative Inverse
92 * Perform Modular Multiplicative Inverse b^(-1) mod n
94 RTE_CRYPTO_ASYM_XFORM_MODEX,
95 /**< Modular Exponentiation
96 * Perform Modular Exponentiation b^e mod n
98 RTE_CRYPTO_ASYM_XFORM_ECDSA,
99 /**< Elliptic Curve Digital Signature Algorithm
100 * Perform Signature Generation and Verification.
102 RTE_CRYPTO_ASYM_XFORM_ECPM,
103 /**< Elliptic Curve Point Multiplication */
104 RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
109 * Asymmetric crypto operation type variants
111 enum rte_crypto_asym_op_type {
112 RTE_CRYPTO_ASYM_OP_ENCRYPT,
113 /**< Asymmetric Encrypt operation */
114 RTE_CRYPTO_ASYM_OP_DECRYPT,
115 /**< Asymmetric Decrypt operation */
116 RTE_CRYPTO_ASYM_OP_SIGN,
117 /**< Signature Generation operation */
118 RTE_CRYPTO_ASYM_OP_VERIFY,
119 /**< Signature Verification operation */
120 RTE_CRYPTO_ASYM_OP_LIST_END
124 * Asymmetric crypto key exchange operation type
126 enum rte_crypto_asym_ke_type {
127 RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE,
128 /**< Private Key generation operation */
129 RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE,
130 /**< Public Key generation operation */
131 RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE
132 /**< Shared Secret compute operation */
136 * Padding types for RSA signature.
138 enum rte_crypto_rsa_padding_type {
139 RTE_CRYPTO_RSA_PADDING_NONE = 0,
140 /**< RSA no padding scheme */
141 RTE_CRYPTO_RSA_PADDING_PKCS1_5,
142 /**< RSA PKCS#1 PKCS1-v1_5 padding scheme. For signatures block type 01,
143 * for encryption block type 02 are used.
145 RTE_CRYPTO_RSA_PADDING_OAEP,
146 /**< RSA PKCS#1 OAEP padding scheme */
147 RTE_CRYPTO_RSA_PADDING_PSS,
148 /**< RSA PKCS#1 PSS padding scheme */
149 RTE_CRYPTO_RSA_PADDING_TYPE_LIST_END
153 * RSA private key type enumeration
155 * enumerates private key format required to perform RSA crypto
159 enum rte_crypto_rsa_priv_key_type {
160 RTE_RSA_KEY_TYPE_EXP,
161 /**< RSA private key is an exponent */
163 /**< RSA private key is in quintuple format
164 * See rte_crypto_rsa_priv_key_qt
169 * Buffer to hold crypto params required for asym operations.
171 * These buffers can be used for both input to PMD and output from PMD. When
172 * used for output from PMD, application has to ensure the buffer is large
173 * enough to hold the target data.
175 * If an operation requires the PMD to generate a random number,
176 * and the device supports CSRNG, 'data' should be set to NULL.
177 * The crypto parameter in question will not be used by the PMD,
178 * as it is internally generated.
180 typedef struct rte_crypto_param_t {
182 /**< pointer to buffer holding data */
184 /**< IO address of data buffer */
186 /**< length of data in bytes */
189 /** Unsigned big-integer in big-endian format */
190 typedef rte_crypto_param rte_crypto_uint;
193 * Structure for elliptic curve point
195 struct rte_crypto_ec_point {
203 * Structure describing RSA private key in quintuple format.
204 * See PKCS V1.5 RSA Cryptography Standard.
206 struct rte_crypto_rsa_priv_key_qt {
208 /**< the first factor */
210 /**< the second factor */
212 /**< the first factor's CRT exponent */
214 /**< the second's factor's CRT exponent */
215 rte_crypto_uint qInv;
216 /**< the CRT coefficient */
220 * Asymmetric RSA transform data
222 * Structure describing RSA xform params
225 struct rte_crypto_rsa_xform {
227 /**< the RSA modulus */
229 /**< the RSA public exponent */
231 enum rte_crypto_rsa_priv_key_type key_type;
236 /**< the RSA private exponent */
237 struct rte_crypto_rsa_priv_key_qt qt;
238 /**< qt - Private key in quintuple format */
243 * Asymmetric Modular exponentiation transform data
245 * Structure describing modular exponentiation xform param
248 struct rte_crypto_modex_xform {
249 rte_crypto_uint modulus;
250 /**< Modulus data for modexp transform operation */
251 rte_crypto_uint exponent;
252 /**< Exponent of the modexp transform operation */
256 * Asymmetric modular multiplicative inverse transform operation
258 * Structure describing modular multiplicative inverse transform
261 struct rte_crypto_modinv_xform {
262 rte_crypto_uint modulus;
263 /**< Modulus data for modular multiplicative inverse operation */
267 * Asymmetric DH transform data
269 * Structure describing deffie-hellman xform params
272 struct rte_crypto_dh_xform {
273 enum rte_crypto_asym_ke_type ke_type;
274 /**< Setup xform for key generate or shared secret compute */
276 /**< Prime modulus data */
282 * Asymmetric Digital Signature transform operation
284 * Structure describing DSA xform params
287 struct rte_crypto_dsa_xform {
289 /**< Prime modulus */
291 /**< Order of the subgroup */
293 /**< Generator of the subgroup */
295 /**< x: Private key of the signer */
299 * Asymmetric elliptic curve transform data
301 * Structure describing all EC based xform params
304 struct rte_crypto_ec_xform {
305 enum rte_crypto_curve_id curve_id;
306 /**< Pre-defined ec groups */
310 * Operations params for modular operations:
311 * exponentiation and multiplicative inverse
314 struct rte_crypto_mod_op_param {
315 rte_crypto_uint base;
316 /** Base of modular exponentiation/multiplicative inverse */
317 rte_crypto_uint result;
318 /** Result of modular exponentiation/multiplicative inverse */
322 * RSA operation params
325 struct rte_crypto_rsa_op_param {
326 enum rte_crypto_asym_op_type op_type;
327 /**< Type of RSA operation for transform */
329 rte_crypto_param message;
331 * Pointer to input data
332 * - to be encrypted for RSA public encrypt.
333 * - to be signed for RSA sign generation.
334 * - to be authenticated for RSA sign verification.
336 * Pointer to output data
337 * - for RSA private decrypt.
338 * In this case the underlying array should have been
339 * allocated with enough memory to hold plaintext output
340 * (i.e. must be at least RSA key size). The message.length
341 * field should be 0 and will be overwritten by the PMD
342 * with the decrypted length.
344 * All data is in Octet-string network byte order format.
347 rte_crypto_param cipher;
349 * Pointer to input data
350 * - to be decrypted for RSA private decrypt.
352 * Pointer to output data
353 * - for RSA public encrypt.
354 * In this case the underlying array should have been allocated
355 * with enough memory to hold ciphertext output (i.e. must be
356 * at least RSA key size). The cipher.length field should
357 * be 0 and will be overwritten by the PMD with the encrypted length.
359 * All data is in Octet-string network byte order format.
362 rte_crypto_param sign;
364 * Pointer to input data
365 * - to be verified for RSA public decrypt.
367 * Pointer to output data
368 * - for RSA private encrypt.
369 * In this case the underlying array should have been allocated
370 * with enough memory to hold signature output (i.e. must be
371 * at least RSA key size). The sign.length field should
372 * be 0 and will be overwritten by the PMD with the signature length.
374 * All data is in Octet-string network byte order format.
377 enum rte_crypto_rsa_padding_type pad;
378 /**< RSA padding scheme to be used for transform */
380 enum rte_crypto_auth_algorithm md;
381 /**< Hash algorithm to be used for data hash if padding
382 * scheme is either OAEP or PSS. Valid hash algorithms
384 * MD5, SHA1, SHA224, SHA256, SHA384, SHA512
387 enum rte_crypto_auth_algorithm mgf1md;
389 * Hash algorithm to be used for mask generation if
390 * padding scheme is either OAEP or PSS. If padding
391 * scheme is unspecified data hash algorithm is used
392 * for mask generation. Valid hash algorithms are:
393 * MD5, SHA1, SHA224, SHA256, SHA384, SHA512
398 * Diffie-Hellman Operations params.
401 struct rte_crypto_dh_op_param {
402 rte_crypto_uint pub_key;
404 * Output - generated public key, when dh xform ke_type is
405 * RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE.
407 * Input - peer's public key, when dh xform ke_type is
408 * RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE.
411 rte_crypto_uint priv_key;
413 * Output - generated private key, when dh xform ke_type is
414 * RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE.
416 * Input - private key, when dh xform ke_type is one of:
417 * RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE,
418 * RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE.
421 rte_crypto_uint shared_secret;
423 * Output - calculated shared secret when dh xform ke_type is
424 * RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE.
429 * DSA Operations params
432 struct rte_crypto_dsa_op_param {
433 enum rte_crypto_asym_op_type op_type;
434 /**< Signature Generation or Verification */
435 rte_crypto_param message;
436 /**< input message to be signed or verified */
438 /**< Per-message secret number, which is an integer
439 * in the interval (1, q-1).
440 * If the random number is generated by the PMD,
441 * the 'rte_crypto_param.data' parameter should be set to NULL.
444 /**< dsa sign component 'r' value
446 * output if op_type = sign generate,
447 * input if op_type = sign verify
450 /**< dsa sign component 's' value
452 * output if op_type = sign generate,
453 * input if op_type = sign verify
456 /**< y : Public key of the signer.
462 * ECDSA operation params
464 struct rte_crypto_ecdsa_op_param {
465 enum rte_crypto_asym_op_type op_type;
466 /**< Signature generation or verification */
468 rte_crypto_uint pkey;
469 /**< Private key of the signer for signature generation */
471 struct rte_crypto_ec_point q;
472 /**< Public key of the signer for verification */
474 rte_crypto_param message;
475 /**< Input message digest to be signed or verified */
478 /**< The ECDSA per-message secret number, which is an integer
479 * in the interval (1, n-1).
480 * If the random number is generated by the PMD,
481 * the 'rte_crypto_param.data' parameter should be set to NULL.
485 /**< r component of elliptic curve signature
486 * output : for signature generation
487 * input : for signature verification
490 /**< s component of elliptic curve signature
491 * output : for signature generation
492 * input : for signature verification
497 * Structure for EC point multiplication operation param
499 struct rte_crypto_ecpm_op_param {
500 struct rte_crypto_ec_point p;
501 /**< x and y coordinates of input point */
503 struct rte_crypto_ec_point r;
504 /**< x and y coordinates of resultant point */
506 rte_crypto_param scalar;
507 /**< Scalar to multiply the input point */
511 * Asymmetric crypto transform data
513 * Structure describing asym xforms.
515 struct rte_crypto_asym_xform {
516 struct rte_crypto_asym_xform *next;
517 /**< Pointer to next xform to set up xform chain.*/
518 enum rte_crypto_asym_xform_type xform_type;
519 /**< Asymmetric crypto transform */
523 struct rte_crypto_rsa_xform rsa;
524 /**< RSA xform parameters */
526 struct rte_crypto_modex_xform modex;
527 /**< Modular Exponentiation xform parameters */
529 struct rte_crypto_modinv_xform modinv;
530 /**< Modular Multiplicative Inverse xform parameters */
532 struct rte_crypto_dh_xform dh;
533 /**< DH xform parameters */
535 struct rte_crypto_dsa_xform dsa;
536 /**< DSA xform parameters */
538 struct rte_crypto_ec_xform ec;
539 /**< EC xform parameters, used by elliptic curve based
546 * Asymmetric Cryptographic Operation.
548 * Structure describing asymmetric crypto operation params.
551 struct rte_crypto_asym_op {
554 struct rte_cryptodev_asym_session *session;
555 /**< Handle for the initialised session context */
556 struct rte_crypto_asym_xform *xform;
557 /**< Session-less API crypto operation parameters */
562 struct rte_crypto_rsa_op_param rsa;
563 struct rte_crypto_mod_op_param modex;
564 struct rte_crypto_mod_op_param modinv;
565 struct rte_crypto_dh_op_param dh;
566 struct rte_crypto_dsa_op_param dsa;
567 struct rte_crypto_ecdsa_op_param ecdsa;
568 struct rte_crypto_ecpm_op_param ecpm;
576 #endif /* _RTE_CRYPTO_ASYM_H_ */