xref: /dpdk/drivers/crypto/openssl/openssl_pmd_private.h (revision 10b71caecbe1cddcbb65c050ca775fba575e88db)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2017 Intel Corporation
3  */
4 
5 #ifndef _OPENSSL_PMD_PRIVATE_H_
6 #define _OPENSSL_PMD_PRIVATE_H_
7 
8 #include <openssl/evp.h>
9 #include <openssl/hmac.h>
10 #include <openssl/des.h>
11 #include <openssl/rsa.h>
12 #include <openssl/dh.h>
13 #include <openssl/dsa.h>
14 
15 #define CRYPTODEV_NAME_OPENSSL_PMD	crypto_openssl
16 /**< Open SSL Crypto PMD device name */
17 
18 /** OPENSSL PMD LOGTYPE DRIVER */
19 extern int openssl_logtype_driver;
20 #define OPENSSL_LOG(level, fmt, ...)  \
21 	rte_log(RTE_LOG_ ## level, openssl_logtype_driver,  \
22 			"%s() line %u: " fmt "\n", __func__, __LINE__,  \
23 					## __VA_ARGS__)
24 
25 /* Maximum length for digest (SHA-512 needs 64 bytes) */
26 #define DIGEST_LENGTH_MAX 64
27 
28 /** OPENSSL operation order mode enumerator */
29 enum openssl_chain_order {
30 	OPENSSL_CHAIN_ONLY_CIPHER,
31 	OPENSSL_CHAIN_ONLY_AUTH,
32 	OPENSSL_CHAIN_CIPHER_BPI,
33 	OPENSSL_CHAIN_CIPHER_AUTH,
34 	OPENSSL_CHAIN_AUTH_CIPHER,
35 	OPENSSL_CHAIN_COMBINED,
36 	OPENSSL_CHAIN_NOT_SUPPORTED
37 };
38 
39 /** OPENSSL cipher mode enumerator */
40 enum openssl_cipher_mode {
41 	OPENSSL_CIPHER_LIB,
42 	OPENSSL_CIPHER_DES3CTR,
43 };
44 
45 /** OPENSSL auth mode enumerator */
46 enum openssl_auth_mode {
47 	OPENSSL_AUTH_AS_AUTH,
48 	OPENSSL_AUTH_AS_HMAC,
49 };
50 
51 /** private data structure for each OPENSSL crypto device */
52 struct openssl_private {
53 	unsigned int max_nb_qpairs;
54 	/**< Max number of queue pairs */
55 };
56 
57 /** OPENSSL crypto queue pair */
58 struct openssl_qp {
59 	uint16_t id;
60 	/**< Queue Pair Identifier */
61 	char name[RTE_CRYPTODEV_NAME_MAX_LEN];
62 	/**< Unique Queue Pair Name */
63 	struct rte_ring *processed_ops;
64 	/**< Ring for placing process packets */
65 	struct rte_mempool *sess_mp;
66 	/**< Session Mempool */
67 	struct rte_mempool *sess_mp_priv;
68 	/**< Session Private Data Mempool */
69 	struct rte_cryptodev_stats stats;
70 	/**< Queue pair statistics */
71 	uint8_t temp_digest[DIGEST_LENGTH_MAX];
72 	/**< Buffer used to store the digest generated
73 	 * by the driver when verifying a digest provided
74 	 * by the user (using authentication verify operation)
75 	 */
76 } __rte_cache_aligned;
77 
78 /** OPENSSL crypto private session structure */
79 struct openssl_session {
80 	enum openssl_chain_order chain_order;
81 	/**< chain order mode */
82 
83 	struct {
84 		uint16_t length;
85 		uint16_t offset;
86 	} iv;
87 	/**< IV parameters */
88 
89 	enum rte_crypto_aead_algorithm aead_algo;
90 	/**< AEAD algorithm */
91 
92 	/** Cipher Parameters */
93 	struct {
94 		enum rte_crypto_cipher_operation direction;
95 		/**< cipher operation direction */
96 		enum openssl_cipher_mode mode;
97 		/**< cipher operation mode */
98 		enum rte_crypto_cipher_algorithm algo;
99 		/**< cipher algorithm */
100 
101 		struct {
102 			uint8_t data[32];
103 			/**< key data */
104 			size_t length;
105 			/**< key length in bytes */
106 		} key;
107 
108 		const EVP_CIPHER *evp_algo;
109 		/**< pointer to EVP algorithm function */
110 		EVP_CIPHER_CTX *ctx;
111 		/**< pointer to EVP context structure */
112 		EVP_CIPHER_CTX *bpi_ctx;
113 	} cipher;
114 
115 	/** Authentication Parameters */
116 	struct {
117 		enum rte_crypto_auth_operation operation;
118 		/**< auth operation generate or verify */
119 		enum openssl_auth_mode mode;
120 		/**< auth operation mode */
121 		enum rte_crypto_auth_algorithm algo;
122 		/**< cipher algorithm */
123 
124 		union {
125 			struct {
126 				const EVP_MD *evp_algo;
127 				/**< pointer to EVP algorithm function */
128 				EVP_MD_CTX *ctx;
129 				/**< pointer to EVP context structure */
130 			} auth;
131 
132 			struct {
133 				EVP_PKEY *pkey;
134 				/**< pointer to EVP key */
135 				const EVP_MD *evp_algo;
136 				/**< pointer to EVP algorithm function */
137 				HMAC_CTX *ctx;
138 				/**< pointer to EVP context structure */
139 			} hmac;
140 		};
141 
142 		uint16_t aad_length;
143 		/**< AAD length */
144 		uint16_t digest_length;
145 		/**< digest length */
146 	} auth;
147 
148 } __rte_cache_aligned;
149 
150 /** OPENSSL crypto private asymmetric session structure */
151 struct openssl_asym_session {
152 	enum rte_crypto_asym_xform_type xfrm_type;
153 	union {
154 		struct rsa {
155 			RSA *rsa;
156 		} r;
157 		struct exp {
158 			BIGNUM *exp;
159 			BIGNUM *mod;
160 			BN_CTX *ctx;
161 		} e;
162 		struct mod {
163 			BIGNUM *modulus;
164 			BN_CTX *ctx;
165 		} m;
166 		struct dh {
167 			DH *dh_key;
168 			uint32_t key_op;
169 		} dh;
170 		struct {
171 			DSA *dsa;
172 		} s;
173 	} u;
174 } __rte_cache_aligned;
175 /** Set and validate OPENSSL crypto session parameters */
176 extern int
177 openssl_set_session_parameters(struct openssl_session *sess,
178 		const struct rte_crypto_sym_xform *xform);
179 
180 /** Reset OPENSSL crypto session parameters */
181 extern void
182 openssl_reset_session(struct openssl_session *sess);
183 
184 /** device specific operations function pointer structure */
185 extern struct rte_cryptodev_ops *rte_openssl_pmd_ops;
186 
187 #endif /* _OPENSSL_PMD_PRIVATE_H_ */
188