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 typedef struct rte_crypto_param_t {
30 /**< pointer to buffer holding data */
32 /**< IO address of data buffer */
34 /**< length of data in bytes */
37 /** asym xform type name strings */
39 rte_crypto_asym_xform_strings[];
41 /** asym operations type name strings */
43 rte_crypto_asym_op_strings[];
46 * Asymmetric crypto transformation types.
47 * Each xform type maps to one asymmetric algorithm
48 * performing specific operation
51 enum rte_crypto_asym_xform_type {
52 RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED = 0,
53 /**< Invalid xform. */
54 RTE_CRYPTO_ASYM_XFORM_NONE,
56 * May be supported by PMD to support
57 * passthrough op for debugging purpose.
58 * if xform_type none , op_type is disregarded.
60 RTE_CRYPTO_ASYM_XFORM_RSA,
61 /**< RSA. Performs Encrypt, Decrypt, Sign and Verify.
62 * Refer to rte_crypto_asym_op_type
64 RTE_CRYPTO_ASYM_XFORM_DH,
66 * Performs Key Generate and Shared Secret Compute.
67 * Refer to rte_crypto_asym_op_type
69 RTE_CRYPTO_ASYM_XFORM_DSA,
70 /**< Digital Signature Algorithm
71 * Performs Signature Generation and Verification.
72 * Refer to rte_crypto_asym_op_type
74 RTE_CRYPTO_ASYM_XFORM_MODINV,
76 * Perform Modulus inverse b^(-1) mod n
78 RTE_CRYPTO_ASYM_XFORM_MODEX,
79 /**< Modular Exponentiation
80 * Perform Modular Exponentiation b^e mod n
82 RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
87 * Asymmetric crypto operation type variants
89 enum rte_crypto_asym_op_type {
90 RTE_CRYPTO_ASYM_OP_ENCRYPT,
91 /**< Asymmetric Encrypt operation */
92 RTE_CRYPTO_ASYM_OP_DECRYPT,
93 /**< Asymmetric Decrypt operation */
94 RTE_CRYPTO_ASYM_OP_SIGN,
95 /**< Signature Generation operation */
96 RTE_CRYPTO_ASYM_OP_VERIFY,
97 /**< Signature Verification operation */
98 RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE,
99 /**< DH Private Key generation operation */
100 RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE,
101 /**< DH Public Key generation operation */
102 RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE,
103 /**< DH Shared Secret compute operation */
104 RTE_CRYPTO_ASYM_OP_LIST_END
108 * Padding types for RSA signature.
110 enum rte_crypto_rsa_padding_type {
111 RTE_CRYPTO_RSA_PADDING_NONE = 0,
112 /**< RSA no padding scheme */
113 RTE_CRYPTO_RSA_PKCS1_V1_5_BT0,
114 /**< RSA PKCS#1 V1.5 Block Type 0 padding scheme
115 * as descibed in rfc2313
117 RTE_CRYPTO_RSA_PKCS1_V1_5_BT1,
118 /**< RSA PKCS#1 V1.5 Block Type 01 padding scheme
119 * as descibed in rfc2313
121 RTE_CRYPTO_RSA_PKCS1_V1_5_BT2,
122 /**< RSA PKCS#1 V1.5 Block Type 02 padding scheme
123 * as descibed in rfc2313
125 RTE_CRYPTO_RSA_PADDING_OAEP,
126 /**< RSA PKCS#1 OAEP padding scheme */
127 RTE_CRYPTO_RSA_PADDING_PSS,
128 /**< RSA PKCS#1 PSS padding scheme */
129 RTE_CRYPTO_RSA_PADDING_TYPE_LIST_END
133 * RSA private key type enumeration
135 * enumerates private key format required to perform RSA crypto
139 enum rte_crypto_rsa_priv_key_type {
140 RTE_RSA_KEY_TYPE_EXP,
141 /**< RSA private key is an exponent */
143 /**< RSA private key is in quintuple format
144 * See rte_crypto_rsa_priv_key_qt
149 * Structure describing RSA private key in quintuple format.
150 * See PKCS V1.5 RSA Cryptography Standard.
152 struct rte_crypto_rsa_priv_key_qt {
154 /**< p - Private key component P
155 * Private key component of RSA parameter required for CRT method
156 * of private key operations in Octet-string network byte order
161 /**< q - Private key component Q
162 * Private key component of RSA parameter required for CRT method
163 * of private key operations in Octet-string network byte order
168 /**< dP - Private CRT component
169 * Private CRT component of RSA parameter required for CRT method
170 * RSA private key operations in Octet-string network byte order
172 * dP = d mod ( p - 1 )
176 /**< dQ - Private CRT component
177 * Private CRT component of RSA parameter required for CRT method
178 * RSA private key operations in Octet-string network byte order
180 * dQ = d mod ( q - 1 )
183 rte_crypto_param qInv;
184 /**< qInv - Private CRT component
185 * Private CRT component of RSA parameter required for CRT method
186 * RSA private key operations in Octet-string network byte order
193 * Asymmetric RSA transform data
195 * Structure describing RSA xform params
198 struct rte_crypto_rsa_xform {
200 /**< n - Prime modulus
201 * Prime modulus data of RSA operation in Octet-string network
206 /**< e - Public key exponent
207 * Public key exponent used for RSA public key operations in Octet-
208 * string network byte order format.
211 enum rte_crypto_rsa_priv_key_type key_type;
216 /**< d - Private key exponent
217 * Private key exponent used for RSA
218 * private key operations in
219 * Octet-string network byte order format.
222 struct rte_crypto_rsa_priv_key_qt qt;
223 /**< qt - Private key in quintuple format */
228 * Asymmetric Modular exponentiation transform data
230 * Structure describing modular exponentation xform param
233 struct rte_crypto_modex_xform {
234 rte_crypto_param modulus;
236 * Prime modulus of the modexp transform operation in octet-string
237 * network byte order format.
240 rte_crypto_param exponent;
242 * Private exponent of the modexp transform operation in
243 * octet-string network byte order format.
248 * Asymmetric modular inverse transform operation
250 * Structure describing modulus inverse xform params
253 struct rte_crypto_modinv_xform {
254 rte_crypto_param modulus;
256 * Pointer to the prime modulus data for modular
257 * inverse operation in octet-string network byte
263 * Asymmetric DH transform data
265 * Structure describing deffie-hellman xform params
268 struct rte_crypto_dh_xform {
269 enum rte_crypto_asym_op_type type;
270 /**< Setup xform for key generate or shared secret compute */
273 /**< p : Prime modulus data
274 * DH prime modulous data in octet-string network byte order format.
280 * DH group generator data in octet-string network byte order
287 * Asymmetric Digital Signature transform operation
289 * Structure describing DSA xform params
292 struct rte_crypto_dsa_xform {
294 /**< p - Prime modulus
295 * Prime modulus data for DSA operation in Octet-string network byte
299 /**< q : Order of the subgroup.
300 * Order of the subgroup data in Octet-string network byte order
305 /**< g: Generator of the subgroup
306 * Generator data in Octet-string network byte order format.
309 /**< x: Private key of the signer in octet-string network
311 * Used when app has pre-defined private key.
312 * Valid only when xform chain is DSA ONLY.
313 * if xform chain is DH private key generate + DSA, then DSA sign
314 * compute will use internally generated key.
319 * Operations params for modular operations:
320 * exponentiation and invert
323 struct rte_crypto_mod_op_param {
324 rte_crypto_param base;
326 * Pointer to base of modular exponentiation/inversion data in
327 * Octet-string network byte order format.
332 * Asymmetric crypto transform data
334 * Structure describing asym xforms.
336 struct rte_crypto_asym_xform {
337 struct rte_crypto_asym_xform *next;
338 /**< Pointer to next xform to set up xform chain.*/
339 enum rte_crypto_asym_xform_type xform_type;
340 /**< Asymmetric crypto transform */
344 struct rte_crypto_rsa_xform rsa;
345 /**< RSA xform parameters */
347 struct rte_crypto_modex_xform modex;
348 /**< Modular Exponentiation xform parameters */
350 struct rte_crypto_modinv_xform modinv;
351 /**< Modulus Inverse xform parameters */
353 struct rte_crypto_dh_xform dh;
354 /**< DH xform parameters */
356 struct rte_crypto_dsa_xform dsa;
357 /**< DSA xform parameters */
361 struct rte_cryptodev_asym_session;
364 * RSA operation params
367 struct rte_crypto_rsa_op_param {
368 enum rte_crypto_asym_op_type op_type;
369 /**< Type of RSA operation for transform */;
371 rte_crypto_param message;
374 * - to be encrypted for RSA public encrypt.
375 * - to be decrypted for RSA private decrypt.
376 * - to be signed for RSA sign generation.
377 * - to be authenticated for RSA sign verification.
380 rte_crypto_param sign;
382 * Pointer to RSA signature data. If operation is RSA
383 * sign @ref RTE_CRYPTO_ASYM_OP_SIGN, buffer will be
384 * over-written with generated signature.
386 * Length of the signature data will be equal to the
387 * RSA prime modulus length.
390 enum rte_crypto_rsa_padding_type pad;
391 /**< RSA padding scheme to be used for transform */
393 enum rte_crypto_auth_algorithm md;
394 /**< Hash algorithm to be used for data hash if padding
395 * scheme is either OAEP or PSS. Valid hash algorithms
397 * MD5, SHA1, SHA224, SHA256, SHA384, SHA512
400 enum rte_crypto_auth_algorithm mgf1md;
402 * Hash algorithm to be used for mask generation if
403 * padding scheme is either OAEP or PSS. If padding
404 * scheme is unspecified data hash algorithm is used
405 * for mask generation. Valid hash algorithms are:
406 * MD5, SHA1, SHA224, SHA256, SHA384, SHA512
411 * Diffie-Hellman Operations params.
414 struct rte_crypto_dh_op_param {
415 rte_crypto_param pub_key;
417 * Output generated public key when xform type is
418 * DH PUB_KEY_GENERATION.
419 * Input peer public key when xform type is DH
420 * SHARED_SECRET_COMPUTATION
421 * pub_key is in octet-string network byte order format.
425 rte_crypto_param priv_key;
427 * Output generated private key if xform type is
428 * DH PRIVATE_KEY_GENERATION
429 * Input when xform type is DH SHARED_SECRET_COMPUTATION.
430 * priv_key is in octet-string network byte order format.
434 rte_crypto_param shared_secret;
436 * Output with calculated shared secret
437 * when dh xform set up with op type = SHARED_SECRET_COMPUTATION.
438 * shared_secret is an octet-string network byte order format.
444 * DSA Operations params
447 struct rte_crypto_dsa_op_param {
448 enum rte_crypto_asym_op_type op_type;
449 /**< Signature Generation or Verification */
450 rte_crypto_param message;
451 /**< input message to be signed or verified */
453 /**< dsa sign component 'r' value
455 * output if op_type = sign generate,
456 * input if op_type = sign verify
459 /**< dsa sign component 's' value
461 * output if op_type = sign generate,
462 * input if op_type = sign verify
465 /**< y : Public key of the signer.
466 * Public key data of the signer in Octet-string network byte order
473 * Asymmetric Cryptographic Operation.
475 * Structure describing asymmetric crypto operation params.
478 struct rte_crypto_asym_op {
479 struct rte_cryptodev_asym_session *session;
480 /**< Handle for the initialised session context */
484 struct rte_crypto_rsa_op_param rsa;
485 struct rte_crypto_mod_op_param modex;
486 struct rte_crypto_mod_op_param modinv;
487 struct rte_crypto_dh_op_param dh;
488 struct rte_crypto_dsa_op_param dsa;
490 } __rte_cache_aligned;
496 #endif /* _RTE_CRYPTO_ASYM_H_ */