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 operations type name strings */
38 rte_crypto_asym_op_strings[];
41 * List of elliptic curves. This enum aligns with
42 * TLS "Supported Groups" registry (previously known as
43 * NamedCurve registry). FFDH groups are not, and will not
44 * be included in this list.
45 * Deprecation for selected curve in TLS does not deprecate
46 * the selected curve in Cryptodev.
47 * https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml
49 enum rte_crypto_curve_id {
50 RTE_CRYPTO_EC_GROUP_SECP192R1 = 19,
51 RTE_CRYPTO_EC_GROUP_SECP224R1 = 21,
52 RTE_CRYPTO_EC_GROUP_SECP256R1 = 23,
53 RTE_CRYPTO_EC_GROUP_SECP384R1 = 24,
54 RTE_CRYPTO_EC_GROUP_SECP521R1 = 25
58 * Asymmetric crypto transformation types.
59 * Each xform type maps to one asymmetric algorithm
60 * performing specific operation
63 enum rte_crypto_asym_xform_type {
64 RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED = 0,
65 /**< Invalid xform. */
66 RTE_CRYPTO_ASYM_XFORM_NONE,
68 * May be supported by PMD to support
69 * passthrough op for debugging purpose.
70 * if xform_type none , op_type is disregarded.
72 RTE_CRYPTO_ASYM_XFORM_RSA,
73 /**< RSA. Performs Encrypt, Decrypt, Sign and Verify.
74 * Refer to rte_crypto_asym_op_type
76 RTE_CRYPTO_ASYM_XFORM_DH,
78 * Performs Key Generate and Shared Secret Compute.
79 * Refer to rte_crypto_asym_op_type
81 RTE_CRYPTO_ASYM_XFORM_DSA,
82 /**< Digital Signature Algorithm
83 * Performs Signature Generation and Verification.
84 * Refer to rte_crypto_asym_op_type
86 RTE_CRYPTO_ASYM_XFORM_MODINV,
87 /**< Modular Multiplicative Inverse
88 * Perform Modular Multiplicative Inverse b^(-1) mod n
90 RTE_CRYPTO_ASYM_XFORM_MODEX,
91 /**< Modular Exponentiation
92 * Perform Modular Exponentiation b^e mod n
94 RTE_CRYPTO_ASYM_XFORM_ECDSA,
95 /**< Elliptic Curve Digital Signature Algorithm
96 * Perform Signature Generation and Verification.
98 RTE_CRYPTO_ASYM_XFORM_ECPM,
99 /**< Elliptic Curve Point Multiplication */
100 RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
105 * Asymmetric crypto operation type variants
107 enum rte_crypto_asym_op_type {
108 RTE_CRYPTO_ASYM_OP_ENCRYPT,
109 /**< Asymmetric Encrypt operation */
110 RTE_CRYPTO_ASYM_OP_DECRYPT,
111 /**< Asymmetric Decrypt operation */
112 RTE_CRYPTO_ASYM_OP_SIGN,
113 /**< Signature Generation operation */
114 RTE_CRYPTO_ASYM_OP_VERIFY,
115 /**< Signature Verification operation */
116 RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE,
117 /**< DH Private Key generation operation */
118 RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE,
119 /**< DH Public Key generation operation */
120 RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE,
121 /**< DH Shared Secret compute operation */
122 RTE_CRYPTO_ASYM_OP_LIST_END
126 * Padding types for RSA signature.
128 enum rte_crypto_rsa_padding_type {
129 RTE_CRYPTO_RSA_PADDING_NONE = 0,
130 /**< RSA no padding scheme */
131 RTE_CRYPTO_RSA_PADDING_PKCS1_5,
132 /**< RSA PKCS#1 PKCS1-v1_5 padding scheme. For signatures block type 01,
133 * for encryption block type 02 are used.
135 RTE_CRYPTO_RSA_PADDING_OAEP,
136 /**< RSA PKCS#1 OAEP padding scheme */
137 RTE_CRYPTO_RSA_PADDING_PSS,
138 /**< RSA PKCS#1 PSS padding scheme */
139 RTE_CRYPTO_RSA_PADDING_TYPE_LIST_END
143 * RSA private key type enumeration
145 * enumerates private key format required to perform RSA crypto
149 enum rte_crypto_rsa_priv_key_type {
150 RTE_RSA_KEY_TYPE_EXP,
151 /**< RSA private key is an exponent */
153 /**< RSA private key is in quintuple format
154 * See rte_crypto_rsa_priv_key_qt
159 * Buffer to hold crypto params required for asym operations.
161 * These buffers can be used for both input to PMD and output from PMD. When
162 * used for output from PMD, application has to ensure the buffer is large
163 * enough to hold the target data.
165 * If an operation requires the PMD to generate a random number,
166 * and the device supports CSRNG, 'data' should be set to NULL.
167 * The crypto parameter in question will not be used by the PMD,
168 * as it is internally generated.
170 typedef struct rte_crypto_param_t {
172 /**< pointer to buffer holding data */
174 /**< IO address of data buffer */
176 /**< length of data in bytes */
179 /** Unsigned big-integer in big-endian format */
180 typedef rte_crypto_param rte_crypto_uint;
183 * Structure for elliptic curve point
185 struct rte_crypto_ec_point {
193 * Structure describing RSA private key in quintuple format.
194 * See PKCS V1.5 RSA Cryptography Standard.
196 struct rte_crypto_rsa_priv_key_qt {
198 /**< the first factor */
200 /**< the second factor */
202 /**< the first factor's CRT exponent */
204 /**< the second's factor's CRT exponent */
205 rte_crypto_uint qInv;
206 /**< the CRT coefficient */
210 * Asymmetric RSA transform data
212 * Structure describing RSA xform params
215 struct rte_crypto_rsa_xform {
217 /**< the RSA modulus */
219 /**< the RSA public exponent */
221 enum rte_crypto_rsa_priv_key_type key_type;
226 /**< the RSA private exponent */
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_uint modulus;
240 /**< Modulus data for modexp transform operation */
241 rte_crypto_uint exponent;
242 /**< Exponent of the modexp transform operation */
246 * Asymmetric modular multiplicative inverse transform operation
248 * Structure describing modular multiplicative inverse transform
251 struct rte_crypto_modinv_xform {
252 rte_crypto_uint modulus;
253 /**< Modulus data for modular multiplicative inverse operation */
257 * Asymmetric DH transform data
259 * Structure describing deffie-hellman xform params
262 struct rte_crypto_dh_xform {
263 enum rte_crypto_asym_op_type type;
264 /**< Setup xform for key generate or shared secret compute */
266 /**< Prime modulus data */
272 * Asymmetric Digital Signature transform operation
274 * Structure describing DSA xform params
277 struct rte_crypto_dsa_xform {
279 /**< Prime modulus */
281 /**< Order of the subgroup */
283 /**< Generator of the subgroup */
285 /**< x: Private key of the signer in octet-string network
287 * Used when app has pre-defined private key.
288 * Valid only when xform chain is DSA ONLY.
289 * if xform chain is DH private key generate + DSA, then DSA sign
290 * compute will use internally generated key.
295 * Asymmetric elliptic curve transform data
297 * Structure describing all EC based xform params
300 struct rte_crypto_ec_xform {
301 enum rte_crypto_curve_id curve_id;
302 /**< Pre-defined ec groups */
306 * Operations params for modular operations:
307 * exponentiation and multiplicative inverse
310 struct rte_crypto_mod_op_param {
311 rte_crypto_uint base;
312 /** Base of modular exponentiation/multiplicative inverse */
313 rte_crypto_uint result;
314 /** Result of modular exponentiation/multiplicative inverse */
318 * RSA operation params
321 struct rte_crypto_rsa_op_param {
322 enum rte_crypto_asym_op_type op_type;
323 /**< Type of RSA operation for transform */
325 rte_crypto_param message;
327 * Pointer to input data
328 * - to be encrypted for RSA public encrypt.
329 * - to be signed for RSA sign generation.
330 * - to be authenticated for RSA sign verification.
332 * Pointer to output data
333 * - for RSA private decrypt.
334 * In this case the underlying array should have been
335 * allocated with enough memory to hold plaintext output
336 * (i.e. must be at least RSA key size). The message.length
337 * field should be 0 and will be overwritten by the PMD
338 * with the decrypted length.
340 * All data is in Octet-string network byte order format.
343 rte_crypto_param cipher;
345 * Pointer to input data
346 * - to be decrypted for RSA private decrypt.
348 * Pointer to output data
349 * - for RSA public encrypt.
350 * In this case the underlying array should have been allocated
351 * with enough memory to hold ciphertext output (i.e. must be
352 * at least RSA key size). The cipher.length field should
353 * be 0 and will be overwritten by the PMD with the encrypted length.
355 * All data is in Octet-string network byte order format.
358 rte_crypto_param sign;
360 * Pointer to input data
361 * - to be verified for RSA public decrypt.
363 * Pointer to output data
364 * - for RSA private encrypt.
365 * In this case the underlying array should have been allocated
366 * with enough memory to hold signature output (i.e. must be
367 * at least RSA key size). The sign.length field should
368 * be 0 and will be overwritten by the PMD with the signature length.
370 * All data is in Octet-string network byte order format.
373 enum rte_crypto_rsa_padding_type pad;
374 /**< RSA padding scheme to be used for transform */
376 enum rte_crypto_auth_algorithm md;
377 /**< Hash algorithm to be used for data hash if padding
378 * scheme is either OAEP or PSS. Valid hash algorithms
380 * MD5, SHA1, SHA224, SHA256, SHA384, SHA512
383 enum rte_crypto_auth_algorithm mgf1md;
385 * Hash algorithm to be used for mask generation if
386 * padding scheme is either OAEP or PSS. If padding
387 * scheme is unspecified data hash algorithm is used
388 * for mask generation. Valid hash algorithms are:
389 * MD5, SHA1, SHA224, SHA256, SHA384, SHA512
394 * Diffie-Hellman Operations params.
397 struct rte_crypto_dh_op_param {
398 rte_crypto_uint pub_key;
400 * Output generated public key when xform type is
401 * DH PUB_KEY_GENERATION.
402 * Input peer public key when xform type is DH
403 * SHARED_SECRET_COMPUTATION
407 rte_crypto_uint priv_key;
409 * Output generated private key if xform type is
410 * DH PRIVATE_KEY_GENERATION
411 * Input when xform type is DH SHARED_SECRET_COMPUTATION.
415 rte_crypto_uint shared_secret;
417 * Output with calculated shared secret
418 * when dh xform set up with op type = SHARED_SECRET_COMPUTATION.
424 * DSA Operations params
427 struct rte_crypto_dsa_op_param {
428 enum rte_crypto_asym_op_type op_type;
429 /**< Signature Generation or Verification */
430 rte_crypto_param message;
431 /**< input message to be signed or verified */
433 /**< Per-message secret number, which is an integer
434 * in the interval (1, q-1).
435 * If the random number is generated by the PMD,
436 * the 'rte_crypto_param.data' parameter should be set to NULL.
439 /**< dsa sign component 'r' value
441 * output if op_type = sign generate,
442 * input if op_type = sign verify
445 /**< dsa sign component 's' value
447 * output if op_type = sign generate,
448 * input if op_type = sign verify
451 /**< y : Public key of the signer.
457 * ECDSA operation params
459 struct rte_crypto_ecdsa_op_param {
460 enum rte_crypto_asym_op_type op_type;
461 /**< Signature generation or verification */
463 rte_crypto_uint pkey;
464 /**< Private key of the signer for signature generation */
466 struct rte_crypto_ec_point q;
467 /**< Public key of the signer for verification */
469 rte_crypto_param message;
470 /**< Input message digest to be signed or verified */
473 /**< The ECDSA per-message secret number, which is an integer
474 * in the interval (1, n-1).
475 * If the random number is generated by the PMD,
476 * the 'rte_crypto_param.data' parameter should be set to NULL.
480 /**< r component of elliptic curve signature
481 * output : for signature generation
482 * input : for signature verification
485 /**< s component of elliptic curve signature
486 * output : for signature generation
487 * input : for signature verification
492 * Structure for EC point multiplication operation param
494 struct rte_crypto_ecpm_op_param {
495 struct rte_crypto_ec_point p;
496 /**< x and y coordinates of input point */
498 struct rte_crypto_ec_point r;
499 /**< x and y coordinates of resultant point */
501 rte_crypto_param scalar;
502 /**< Scalar to multiply the input point */
506 * Asymmetric crypto transform data
508 * Structure describing asym xforms.
510 struct rte_crypto_asym_xform {
511 struct rte_crypto_asym_xform *next;
512 /**< Pointer to next xform to set up xform chain.*/
513 enum rte_crypto_asym_xform_type xform_type;
514 /**< Asymmetric crypto transform */
518 struct rte_crypto_rsa_xform rsa;
519 /**< RSA xform parameters */
521 struct rte_crypto_modex_xform modex;
522 /**< Modular Exponentiation xform parameters */
524 struct rte_crypto_modinv_xform modinv;
525 /**< Modular Multiplicative Inverse xform parameters */
527 struct rte_crypto_dh_xform dh;
528 /**< DH xform parameters */
530 struct rte_crypto_dsa_xform dsa;
531 /**< DSA xform parameters */
533 struct rte_crypto_ec_xform ec;
534 /**< EC xform parameters, used by elliptic curve based
541 * Asymmetric Cryptographic Operation.
543 * Structure describing asymmetric crypto operation params.
546 struct rte_crypto_asym_op {
549 struct rte_cryptodev_asym_session *session;
550 /**< Handle for the initialised session context */
551 struct rte_crypto_asym_xform *xform;
552 /**< Session-less API crypto operation parameters */
557 struct rte_crypto_rsa_op_param rsa;
558 struct rte_crypto_mod_op_param modex;
559 struct rte_crypto_mod_op_param modinv;
560 struct rte_crypto_dh_op_param dh;
561 struct rte_crypto_dsa_op_param dsa;
562 struct rte_crypto_ecdsa_op_param ecdsa;
563 struct rte_crypto_ecpm_op_param ecpm;
571 #endif /* _RTE_CRYPTO_ASYM_H_ */