cryptodev: use AES-GCM/CCM as AEAD algorithms
[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
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         struct {
112                 uint16_t length;
113                 uint16_t offset;
114         } iv;
115         /**< IV parameters */
116
117         enum rte_crypto_aead_algorithm aead_algo;
118         /**< AEAD algorithm */
119
120         /** Cipher Parameters */
121         struct {
122                 enum rte_crypto_cipher_operation direction;
123                 /**< cipher operation direction */
124                 enum openssl_cipher_mode mode;
125                 /**< cipher operation mode */
126                 enum rte_crypto_cipher_algorithm algo;
127                 /**< cipher algorithm */
128
129                 struct {
130                         uint8_t data[32];
131                         /**< key data */
132                         size_t length;
133                         /**< key length in bytes */
134                 } key;
135
136                 const EVP_CIPHER *evp_algo;
137                 /**< pointer to EVP algorithm function */
138                 EVP_CIPHER_CTX *ctx;
139                 /**< pointer to EVP context structure */
140                 EVP_CIPHER_CTX *bpi_ctx;
141         } cipher;
142
143         /** Authentication Parameters */
144         struct {
145                 enum rte_crypto_auth_operation operation;
146                 /**< auth operation generate or verify */
147                 enum openssl_auth_mode mode;
148                 /**< auth operation mode */
149                 enum rte_crypto_auth_algorithm algo;
150                 /**< cipher algorithm */
151
152                 union {
153                         struct {
154                                 const EVP_MD *evp_algo;
155                                 /**< pointer to EVP algorithm function */
156                                 EVP_MD_CTX *ctx;
157                                 /**< pointer to EVP context structure */
158                         } auth;
159
160                         struct {
161                                 EVP_PKEY *pkey;
162                                 /**< pointer to EVP key */
163                                 const EVP_MD *evp_algo;
164                                 /**< pointer to EVP algorithm function */
165                                 EVP_MD_CTX *ctx;
166                                 /**< pointer to EVP context structure */
167                         } hmac;
168                 };
169
170                 uint16_t aad_length;
171                 /**< AAD length */
172                 uint16_t digest_length;
173                 /**< digest length */
174         } auth;
175
176 } __rte_cache_aligned;
177
178 /** Set and validate OPENSSL crypto session parameters */
179 extern int
180 openssl_set_session_parameters(struct openssl_session *sess,
181                 const struct rte_crypto_sym_xform *xform);
182
183 /** Reset OPENSSL crypto session parameters */
184 extern void
185 openssl_reset_session(struct openssl_session *sess);
186
187 /** device specific operations function pointer structure */
188 extern struct rte_cryptodev_ops *rte_openssl_pmd_ops;
189
190 #endif /* _OPENSSL_PMD_PRIVATE_H_ */