4 * Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #ifndef _OPENSSL_PMD_PRIVATE_H_
34 #define _OPENSSL_PMD_PRIVATE_H_
36 #include <openssl/evp.h>
37 #include <openssl/hmac.h>
38 #include <openssl/des.h>
40 #define CRYPTODEV_NAME_OPENSSL_PMD crypto_openssl
41 /**< Open SSL Crypto PMD device name */
43 #define OPENSSL_LOG_ERR(fmt, args...) \
44 RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
45 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), \
46 __func__, __LINE__, ## args)
48 #ifdef RTE_LIBRTE_OPENSSL_DEBUG
49 #define OPENSSL_LOG_INFO(fmt, args...) \
50 RTE_LOG(INFO, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
51 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), \
52 __func__, __LINE__, ## args)
54 #define OPENSSL_LOG_DBG(fmt, args...) \
55 RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
56 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), \
57 __func__, __LINE__, ## args)
59 #define OPENSSL_LOG_INFO(fmt, args...)
60 #define OPENSSL_LOG_DBG(fmt, args...)
64 /** OPENSSL operation order mode enumerator */
65 enum openssl_chain_order {
66 OPENSSL_CHAIN_ONLY_CIPHER,
67 OPENSSL_CHAIN_ONLY_AUTH,
68 OPENSSL_CHAIN_CIPHER_BPI,
69 OPENSSL_CHAIN_CIPHER_AUTH,
70 OPENSSL_CHAIN_AUTH_CIPHER,
71 OPENSSL_CHAIN_COMBINED,
72 OPENSSL_CHAIN_NOT_SUPPORTED
75 /** OPENSSL cipher mode enumerator */
76 enum openssl_cipher_mode {
78 OPENSSL_CIPHER_DES3CTR,
81 /** OPENSSL auth mode enumerator */
82 enum openssl_auth_mode {
87 /** private data structure for each OPENSSL crypto device */
88 struct openssl_private {
89 unsigned int max_nb_qpairs;
90 /**< Max number of queue pairs */
91 unsigned int max_nb_sessions;
92 /**< Max number of sessions */
95 /** OPENSSL crypto queue pair */
98 /**< Queue Pair Identifier */
99 char name[RTE_CRYPTODEV_NAME_LEN];
100 /**< Unique Queue Pair Name */
101 struct rte_ring *processed_ops;
102 /**< Ring for placing process packets */
103 struct rte_mempool *sess_mp;
104 /**< Session Mempool */
105 struct rte_cryptodev_stats stats;
106 /**< Queue pair statistics */
107 } __rte_cache_aligned;
109 /** OPENSSL crypto private session structure */
110 struct openssl_session {
111 enum openssl_chain_order chain_order;
112 /**< chain order mode */
118 /**< IV parameters */
120 enum rte_crypto_aead_algorithm aead_algo;
121 /**< AEAD algorithm */
123 /** Cipher Parameters */
125 enum rte_crypto_cipher_operation direction;
126 /**< cipher operation direction */
127 enum openssl_cipher_mode mode;
128 /**< cipher operation mode */
129 enum rte_crypto_cipher_algorithm algo;
130 /**< cipher algorithm */
136 /**< key length in bytes */
139 const EVP_CIPHER *evp_algo;
140 /**< pointer to EVP algorithm function */
142 /**< pointer to EVP context structure */
143 EVP_CIPHER_CTX *bpi_ctx;
146 /** Authentication Parameters */
148 enum rte_crypto_auth_operation operation;
149 /**< auth operation generate or verify */
150 enum openssl_auth_mode mode;
151 /**< auth operation mode */
152 enum rte_crypto_auth_algorithm algo;
153 /**< cipher algorithm */
157 const EVP_MD *evp_algo;
158 /**< pointer to EVP algorithm function */
160 /**< pointer to EVP context structure */
165 /**< pointer to EVP key */
166 const EVP_MD *evp_algo;
167 /**< pointer to EVP algorithm function */
169 /**< pointer to EVP context structure */
175 uint16_t digest_length;
176 /**< digest length */
179 } __rte_cache_aligned;
181 /** Set and validate OPENSSL crypto session parameters */
183 openssl_set_session_parameters(struct openssl_session *sess,
184 const struct rte_crypto_sym_xform *xform);
186 /** Reset OPENSSL crypto session parameters */
188 openssl_reset_session(struct openssl_session *sess);
190 /** device specific operations function pointer structure */
191 extern struct rte_cryptodev_ops *rte_openssl_pmd_ops;
193 #endif /* _OPENSSL_PMD_PRIVATE_H_ */