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 typedef struct rte_crypto_param_t {
32 /**< pointer to buffer holding data */
34 /**< IO address of data buffer */
36 /**< length of data in bytes */
39 /** asym xform type name strings */
41 rte_crypto_asym_xform_strings[];
43 /** asym operations type name strings */
45 rte_crypto_asym_op_strings[];
48 * Asymmetric crypto transformation types.
49 * Each xform type maps to one asymmetric algorithm
50 * performing specific operation
53 enum rte_crypto_asym_xform_type {
54 RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED = 0,
55 /**< Invalid xform. */
56 RTE_CRYPTO_ASYM_XFORM_NONE,
58 * May be supported by PMD to support
59 * passthrough op for debugging purpose.
60 * if xform_type none , op_type is disregarded.
62 RTE_CRYPTO_ASYM_XFORM_RSA,
63 /**< RSA. Performs Encrypt, Decrypt, Sign and Verify.
64 * Refer to rte_crypto_asym_op_type
66 RTE_CRYPTO_ASYM_XFORM_DH,
68 * Performs Key Generate and Shared Secret Compute.
69 * Refer to rte_crypto_asym_op_type
71 RTE_CRYPTO_ASYM_XFORM_DSA,
72 /**< Digital Signature Algorithm
73 * Performs Signature Generation and Verification.
74 * Refer to rte_crypto_asym_op_type
76 RTE_CRYPTO_ASYM_XFORM_MODINV,
77 /**< Modular Multiplicative Inverse
78 * Perform Modular Multiplicative Inverse b^(-1) mod n
80 RTE_CRYPTO_ASYM_XFORM_MODEX,
81 /**< Modular Exponentiation
82 * Perform Modular Exponentiation b^e mod n
84 RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
89 * Asymmetric crypto operation type variants
91 enum rte_crypto_asym_op_type {
92 RTE_CRYPTO_ASYM_OP_ENCRYPT,
93 /**< Asymmetric Encrypt operation */
94 RTE_CRYPTO_ASYM_OP_DECRYPT,
95 /**< Asymmetric Decrypt operation */
96 RTE_CRYPTO_ASYM_OP_SIGN,
97 /**< Signature Generation operation */
98 RTE_CRYPTO_ASYM_OP_VERIFY,
99 /**< Signature Verification operation */
100 RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE,
101 /**< DH Private Key generation operation */
102 RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE,
103 /**< DH Public Key generation operation */
104 RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE,
105 /**< DH Shared Secret compute operation */
106 RTE_CRYPTO_ASYM_OP_LIST_END
110 * Padding types for RSA signature.
112 enum rte_crypto_rsa_padding_type {
113 RTE_CRYPTO_RSA_PADDING_NONE = 0,
114 /**< RSA no padding scheme */
115 RTE_CRYPTO_RSA_PKCS1_V1_5_BT0,
116 /**< RSA PKCS#1 V1.5 Block Type 0 padding scheme
117 * as described in rfc2313
119 RTE_CRYPTO_RSA_PKCS1_V1_5_BT1,
120 /**< RSA PKCS#1 V1.5 Block Type 01 padding scheme
121 * as described in rfc2313
123 RTE_CRYPTO_RSA_PKCS1_V1_5_BT2,
124 /**< RSA PKCS#1 V1.5 Block Type 02 padding scheme
125 * as described in rfc2313
127 RTE_CRYPTO_RSA_PADDING_OAEP,
128 /**< RSA PKCS#1 OAEP padding scheme */
129 RTE_CRYPTO_RSA_PADDING_PSS,
130 /**< RSA PKCS#1 PSS padding scheme */
131 RTE_CRYPTO_RSA_PADDING_TYPE_LIST_END
135 * RSA private key type enumeration
137 * enumerates private key format required to perform RSA crypto
141 enum rte_crypto_rsa_priv_key_type {
142 RTE_RSA_KEY_TYPE_EXP,
143 /**< RSA private key is an exponent */
145 /**< RSA private key is in quintuple format
146 * See rte_crypto_rsa_priv_key_qt
151 * Structure describing RSA private key in quintuple format.
152 * See PKCS V1.5 RSA Cryptography Standard.
154 struct rte_crypto_rsa_priv_key_qt {
156 /**< p - Private key component P
157 * Private key component of RSA parameter required for CRT method
158 * of private key operations in Octet-string network byte order
163 /**< q - Private key component Q
164 * Private key component of RSA parameter required for CRT method
165 * of private key operations in Octet-string network byte order
170 /**< dP - Private CRT component
171 * Private CRT component of RSA parameter required for CRT method
172 * RSA private key operations in Octet-string network byte order
174 * dP = d mod ( p - 1 )
178 /**< dQ - Private CRT component
179 * Private CRT component of RSA parameter required for CRT method
180 * RSA private key operations in Octet-string network byte order
182 * dQ = d mod ( q - 1 )
185 rte_crypto_param qInv;
186 /**< qInv - Private CRT component
187 * Private CRT component of RSA parameter required for CRT method
188 * RSA private key operations in Octet-string network byte order
195 * Asymmetric RSA transform data
197 * Structure describing RSA xform params
200 struct rte_crypto_rsa_xform {
202 /**< n - Prime modulus
203 * Prime modulus data of RSA operation in Octet-string network
208 /**< e - Public key exponent
209 * Public key exponent used for RSA public key operations in Octet-
210 * string network byte order format.
213 enum rte_crypto_rsa_priv_key_type key_type;
218 /**< d - Private key exponent
219 * Private key exponent used for RSA
220 * private key operations in
221 * Octet-string network byte order format.
224 struct rte_crypto_rsa_priv_key_qt qt;
225 /**< qt - Private key in quintuple format */
230 * Asymmetric Modular exponentiation transform data
232 * Structure describing modular exponentiation xform param
235 struct rte_crypto_modex_xform {
236 rte_crypto_param modulus;
238 * Pointer to the modulus data for modexp transform operation
239 * in octet-string network byte order format
241 * In case this number is equal to zero the driver shall set
242 * the crypto op status field to RTE_CRYPTO_OP_STATUS_ERROR
245 rte_crypto_param exponent;
247 * Exponent of the modexp transform operation in
248 * octet-string network byte order format
253 * Asymmetric modular multiplicative inverse transform operation
255 * Structure describing modular multiplicative inverse transform
258 struct rte_crypto_modinv_xform {
259 rte_crypto_param modulus;
261 * Pointer to the modulus data for modular multiplicative inverse
262 * operation in octet-string network byte order format
264 * In case this number is equal to zero the driver shall set
265 * the crypto op status field to RTE_CRYPTO_OP_STATUS_ERROR
267 * This number shall be relatively prime to base
268 * in corresponding Modular Multiplicative Inverse
269 * rte_crypto_mod_op_param
274 * Asymmetric DH transform data
276 * Structure describing deffie-hellman xform params
279 struct rte_crypto_dh_xform {
280 enum rte_crypto_asym_op_type type;
281 /**< Setup xform for key generate or shared secret compute */
284 /**< p : Prime modulus data
285 * DH prime modulus data in octet-string network byte order format.
291 * DH group generator data in octet-string network byte order
298 * Asymmetric Digital Signature transform operation
300 * Structure describing DSA xform params
303 struct rte_crypto_dsa_xform {
305 /**< p - Prime modulus
306 * Prime modulus data for DSA operation in Octet-string network byte
310 /**< q : Order of the subgroup.
311 * Order of the subgroup data in Octet-string network byte order
316 /**< g: Generator of the subgroup
317 * Generator data in Octet-string network byte order format.
320 /**< x: Private key of the signer in octet-string network
322 * Used when app has pre-defined private key.
323 * Valid only when xform chain is DSA ONLY.
324 * if xform chain is DH private key generate + DSA, then DSA sign
325 * compute will use internally generated key.
330 * Operations params for modular operations:
331 * exponentiation and multiplicative inverse
334 struct rte_crypto_mod_op_param {
335 rte_crypto_param base;
337 * Pointer to base of modular exponentiation/multiplicative
338 * inverse data in octet-string network byte order format
340 * In case Multiplicative Inverse is used this number shall
341 * be relatively prime to modulus in corresponding Modular
342 * Multiplicative Inverse rte_crypto_modinv_xform
345 rte_crypto_param result;
347 * Pointer to the result of modular exponentiation/multiplicative inverse
348 * data in octet-string network byte order format.
350 * This field shall be big enough to hold the result of Modular
351 * Exponentiation or Modular Multiplicative Inverse
352 * (bigger or equal to length of modulus)
357 * Asymmetric crypto transform data
359 * Structure describing asym xforms.
361 struct rte_crypto_asym_xform {
362 struct rte_crypto_asym_xform *next;
363 /**< Pointer to next xform to set up xform chain.*/
364 enum rte_crypto_asym_xform_type xform_type;
365 /**< Asymmetric crypto transform */
369 struct rte_crypto_rsa_xform rsa;
370 /**< RSA xform parameters */
372 struct rte_crypto_modex_xform modex;
373 /**< Modular Exponentiation xform parameters */
375 struct rte_crypto_modinv_xform modinv;
376 /**< Modular Multiplicative Inverse xform parameters */
378 struct rte_crypto_dh_xform dh;
379 /**< DH xform parameters */
381 struct rte_crypto_dsa_xform dsa;
382 /**< DSA xform parameters */
386 struct rte_cryptodev_asym_session;
389 * RSA operation params
392 struct rte_crypto_rsa_op_param {
393 enum rte_crypto_asym_op_type op_type;
394 /**< Type of RSA operation for transform */;
396 rte_crypto_param message;
399 * - to be encrypted for RSA public encrypt.
400 * - to be decrypted for RSA private decrypt.
401 * - to be signed for RSA sign generation.
402 * - to be authenticated for RSA sign verification.
405 rte_crypto_param sign;
407 * Pointer to RSA signature data. If operation is RSA
408 * sign @ref RTE_CRYPTO_ASYM_OP_SIGN, buffer will be
409 * over-written with generated signature.
411 * Length of the signature data will be equal to the
412 * RSA prime modulus length.
415 enum rte_crypto_rsa_padding_type pad;
416 /**< RSA padding scheme to be used for transform */
418 enum rte_crypto_auth_algorithm md;
419 /**< Hash algorithm to be used for data hash if padding
420 * scheme is either OAEP or PSS. Valid hash algorithms
422 * MD5, SHA1, SHA224, SHA256, SHA384, SHA512
425 enum rte_crypto_auth_algorithm mgf1md;
427 * Hash algorithm to be used for mask generation if
428 * padding scheme is either OAEP or PSS. If padding
429 * scheme is unspecified data hash algorithm is used
430 * for mask generation. Valid hash algorithms are:
431 * MD5, SHA1, SHA224, SHA256, SHA384, SHA512
436 * Diffie-Hellman Operations params.
439 struct rte_crypto_dh_op_param {
440 rte_crypto_param pub_key;
442 * Output generated public key when xform type is
443 * DH PUB_KEY_GENERATION.
444 * Input peer public key when xform type is DH
445 * SHARED_SECRET_COMPUTATION
446 * pub_key is in octet-string network byte order format.
450 rte_crypto_param priv_key;
452 * Output generated private key if xform type is
453 * DH PRIVATE_KEY_GENERATION
454 * Input when xform type is DH SHARED_SECRET_COMPUTATION.
455 * priv_key is in octet-string network byte order format.
459 rte_crypto_param shared_secret;
461 * Output with calculated shared secret
462 * when dh xform set up with op type = SHARED_SECRET_COMPUTATION.
463 * shared_secret is an octet-string network byte order format.
469 * DSA Operations params
472 struct rte_crypto_dsa_op_param {
473 enum rte_crypto_asym_op_type op_type;
474 /**< Signature Generation or Verification */
475 rte_crypto_param message;
476 /**< input message to be signed or verified */
478 /**< dsa sign component 'r' value
480 * output if op_type = sign generate,
481 * input if op_type = sign verify
484 /**< dsa sign component 's' value
486 * output if op_type = sign generate,
487 * input if op_type = sign verify
490 /**< y : Public key of the signer.
491 * Public key data of the signer in Octet-string network byte order
498 * Asymmetric Cryptographic Operation.
500 * Structure describing asymmetric crypto operation params.
503 struct rte_crypto_asym_op {
504 struct rte_cryptodev_asym_session *session;
505 /**< Handle for the initialised session context */
509 struct rte_crypto_rsa_op_param rsa;
510 struct rte_crypto_mod_op_param modex;
511 struct rte_crypto_mod_op_param modinv;
512 struct rte_crypto_dh_op_param dh;
513 struct rte_crypto_dsa_op_param dsa;
521 #endif /* _RTE_CRYPTO_ASYM_H_ */