b7f747521a1a3803ddad1e2a7e5e820c17d05bc7
[deb_dpdk.git] / drivers / crypto / openssl / rte_openssl_pmd_private.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
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
15  *       distribution.
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.
19  *
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.
31  */
32
33 #ifndef _OPENSSL_PMD_PRIVATE_H_
34 #define _OPENSSL_PMD_PRIVATE_H_
35
36 #include <openssl/evp.h>
37 #include <openssl/des.h>
38
39 #define CRYPTODEV_NAME_OPENSSL_PMD      crypto_openssl
40 /**< Open SSL Crypto PMD device name */
41
42 #define OPENSSL_LOG_ERR(fmt, args...) \
43         RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n",  \
44                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), \
45                         __func__, __LINE__, ## args)
46
47 #ifdef RTE_LIBRTE_OPENSSL_DEBUG
48 #define OPENSSL_LOG_INFO(fmt, args...) \
49         RTE_LOG(INFO, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
50                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), \
51                         __func__, __LINE__, ## args)
52
53 #define OPENSSL_LOG_DBG(fmt, args...) \
54         RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
55                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), \
56                         __func__, __LINE__, ## args)
57 #else
58 #define OPENSSL_LOG_INFO(fmt, args...)
59 #define OPENSSL_LOG_DBG(fmt, args...)
60 #endif
61
62
63 /** OPENSSL operation order mode enumerator */
64 enum openssl_chain_order {
65         OPENSSL_CHAIN_ONLY_CIPHER,
66         OPENSSL_CHAIN_ONLY_AUTH,
67         OPENSSL_CHAIN_CIPHER_BPI,
68         OPENSSL_CHAIN_CIPHER_AUTH,
69         OPENSSL_CHAIN_AUTH_CIPHER,
70         OPENSSL_CHAIN_COMBINED,
71         OPENSSL_CHAIN_NOT_SUPPORTED
72 };
73
74 /** OPENSSL cipher mode enumerator */
75 enum openssl_cipher_mode {
76         OPENSSL_CIPHER_LIB,
77         OPENSSL_CIPHER_DES3CTR,
78 };
79
80 /** OPENSSL auth mode enumerator */
81 enum openssl_auth_mode {
82         OPENSSL_AUTH_AS_AUTH,
83         OPENSSL_AUTH_AS_HMAC,
84 };
85
86 /** private data structure for each OPENSSL crypto device */
87 struct openssl_private {
88         unsigned int max_nb_qpairs;
89         /**< Max number of queue pairs */
90         unsigned int max_nb_sessions;
91         /**< Max number of sessions */
92 };
93
94 /** OPENSSL crypto queue pair */
95 struct openssl_qp {
96         uint16_t id;
97         /**< Queue Pair Identifier */
98         char name[RTE_CRYPTODEV_NAME_LEN];
99         /**< Unique Queue Pair Name */
100         struct rte_ring *processed_ops;
101         /**< Ring for placing process packets */
102         struct rte_mempool *sess_mp;
103         /**< Session Mempool */
104         struct rte_cryptodev_stats stats;
105         /**< Queue pair statistics */
106 } __rte_cache_aligned;
107
108 /** OPENSSL crypto private session structure */
109 struct openssl_session {
110         enum openssl_chain_order chain_order;
111         /**< chain order mode */
112
113         struct {
114                 uint16_t length;
115                 uint16_t offset;
116         } iv;
117         /**< IV parameters */
118
119         enum rte_crypto_aead_algorithm aead_algo;
120         /**< AEAD algorithm */
121
122         /** Cipher Parameters */
123         struct {
124                 enum rte_crypto_cipher_operation direction;
125                 /**< cipher operation direction */
126                 enum openssl_cipher_mode mode;
127                 /**< cipher operation mode */
128                 enum rte_crypto_cipher_algorithm algo;
129                 /**< cipher algorithm */
130
131                 struct {
132                         uint8_t data[32];
133                         /**< key data */
134                         size_t length;
135                         /**< key length in bytes */
136                 } key;
137
138                 const EVP_CIPHER *evp_algo;
139                 /**< pointer to EVP algorithm function */
140                 EVP_CIPHER_CTX *ctx;
141                 /**< pointer to EVP context structure */
142                 EVP_CIPHER_CTX *bpi_ctx;
143         } cipher;
144
145         /** Authentication Parameters */
146         struct {
147                 enum rte_crypto_auth_operation operation;
148                 /**< auth operation generate or verify */
149                 enum openssl_auth_mode mode;
150                 /**< auth operation mode */
151                 enum rte_crypto_auth_algorithm algo;
152                 /**< cipher algorithm */
153
154                 union {
155                         struct {
156                                 const EVP_MD *evp_algo;
157                                 /**< pointer to EVP algorithm function */
158                                 EVP_MD_CTX *ctx;
159                                 /**< pointer to EVP context structure */
160                         } auth;
161
162                         struct {
163                                 EVP_PKEY *pkey;
164                                 /**< pointer to EVP key */
165                                 const EVP_MD *evp_algo;
166                                 /**< pointer to EVP algorithm function */
167                                 EVP_MD_CTX *ctx;
168                                 /**< pointer to EVP context structure */
169                         } hmac;
170                 };
171
172                 uint16_t aad_length;
173                 /**< AAD length */
174                 uint16_t digest_length;
175                 /**< digest length */
176         } auth;
177
178 } __rte_cache_aligned;
179
180 /** Set and validate OPENSSL crypto session parameters */
181 extern int
182 openssl_set_session_parameters(struct openssl_session *sess,
183                 const struct rte_crypto_sym_xform *xform);
184
185 /** Reset OPENSSL crypto session parameters */
186 extern void
187 openssl_reset_session(struct openssl_session *sess);
188
189 /** device specific operations function pointer structure */
190 extern struct rte_cryptodev_ops *rte_openssl_pmd_ops;
191
192 #endif /* _OPENSSL_PMD_PRIVATE_H_ */