9ced93e842f64286851770f58d6ce631df06f1a6
[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/hmac.h>
38 #include <openssl/des.h>
39
40 #define CRYPTODEV_NAME_OPENSSL_PMD      crypto_openssl
41 /**< Open SSL Crypto PMD device name */
42
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)
47
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)
53
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)
58 #else
59 #define OPENSSL_LOG_INFO(fmt, args...)
60 #define OPENSSL_LOG_DBG(fmt, args...)
61 #endif
62
63
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
73 };
74
75 /** OPENSSL cipher mode enumerator */
76 enum openssl_cipher_mode {
77         OPENSSL_CIPHER_LIB,
78         OPENSSL_CIPHER_DES3CTR,
79 };
80
81 /** OPENSSL auth mode enumerator */
82 enum openssl_auth_mode {
83         OPENSSL_AUTH_AS_AUTH,
84         OPENSSL_AUTH_AS_HMAC,
85 };
86
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 */
93 };
94
95 /** OPENSSL crypto queue pair */
96 struct openssl_qp {
97         uint16_t id;
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;
108
109 /** OPENSSL crypto private session structure */
110 struct openssl_session {
111         enum openssl_chain_order chain_order;
112         /**< chain order mode */
113
114         struct {
115                 uint16_t length;
116                 uint16_t offset;
117         } iv;
118         /**< IV parameters */
119
120         enum rte_crypto_aead_algorithm aead_algo;
121         /**< AEAD algorithm */
122
123         /** Cipher Parameters */
124         struct {
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 */
131
132                 struct {
133                         uint8_t data[32];
134                         /**< key data */
135                         size_t length;
136                         /**< key length in bytes */
137                 } key;
138
139                 const EVP_CIPHER *evp_algo;
140                 /**< pointer to EVP algorithm function */
141                 EVP_CIPHER_CTX *ctx;
142                 /**< pointer to EVP context structure */
143                 EVP_CIPHER_CTX *bpi_ctx;
144         } cipher;
145
146         /** Authentication Parameters */
147         struct {
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 */
154
155                 union {
156                         struct {
157                                 const EVP_MD *evp_algo;
158                                 /**< pointer to EVP algorithm function */
159                                 EVP_MD_CTX *ctx;
160                                 /**< pointer to EVP context structure */
161                         } auth;
162
163                         struct {
164                                 EVP_PKEY *pkey;
165                                 /**< pointer to EVP key */
166                                 const EVP_MD *evp_algo;
167                                 /**< pointer to EVP algorithm function */
168                                 HMAC_CTX *ctx;
169                                 /**< pointer to EVP context structure */
170                         } hmac;
171                 };
172
173                 uint16_t aad_length;
174                 /**< AAD length */
175                 uint16_t digest_length;
176                 /**< digest length */
177         } auth;
178
179 } __rte_cache_aligned;
180
181 /** Set and validate OPENSSL crypto session parameters */
182 extern int
183 openssl_set_session_parameters(struct openssl_session *sess,
184                 const struct rte_crypto_sym_xform *xform);
185
186 /** Reset OPENSSL crypto session parameters */
187 extern void
188 openssl_reset_session(struct openssl_session *sess);
189
190 /** device specific operations function pointer structure */
191 extern struct rte_cryptodev_ops *rte_openssl_pmd_ops;
192
193 #endif /* _OPENSSL_PMD_PRIVATE_H_ */