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