app/test: add crypto continual performance tests
[dpdk.git] / drivers / crypto / libcrypto / rte_libcrypto_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 _LIBCRYPTO_PMD_PRIVATE_H_
34 #define _LIBCRYPTO_PMD_PRIVATE_H_
35
36 #include <openssl/evp.h>
37 #include <openssl/des.h>
38
39
40 #define LIBCRYPTO_LOG_ERR(fmt, args...) \
41         RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n",  \
42                         RTE_STR(CRYPTODEV_NAME_LIBCRYPTO_PMD), \
43                         __func__, __LINE__, ## args)
44
45 #ifdef RTE_LIBRTE_LIBCRYPTO_DEBUG
46 #define LIBCRYPTO_LOG_INFO(fmt, args...) \
47         RTE_LOG(INFO, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
48                         RTE_STR(CRYPTODEV_NAME_LIBCRYPTO_PMD), \
49                         __func__, __LINE__, ## args)
50
51 #define LIBCRYPTO_LOG_DBG(fmt, args...) \
52         RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
53                         RTE_STR(CRYPTODEV_NAME_LIBCRYPTO_PMD), \
54                         __func__, __LINE__, ## args)
55 #else
56 #define LIBCRYPTO_LOG_INFO(fmt, args...)
57 #define LIBCRYPTO_LOG_DBG(fmt, args...)
58 #endif
59
60
61 /** LIBCRYPTO operation order mode enumerator */
62 enum libcrypto_chain_order {
63         LIBCRYPTO_CHAIN_ONLY_CIPHER,
64         LIBCRYPTO_CHAIN_ONLY_AUTH,
65         LIBCRYPTO_CHAIN_CIPHER_AUTH,
66         LIBCRYPTO_CHAIN_AUTH_CIPHER,
67         LIBCRYPTO_CHAIN_COMBINED,
68         LIBCRYPTO_CHAIN_NOT_SUPPORTED
69 };
70
71 /** LIBCRYPTO cipher mode enumerator */
72 enum libcrypto_cipher_mode {
73         LIBCRYPTO_CIPHER_LIB,
74         LIBCRYPTO_CIPHER_DES3CTR,
75 };
76
77 /** LIBCRYPTO auth mode enumerator */
78 enum libcrypto_auth_mode {
79         LIBCRYPTO_AUTH_AS_AUTH,
80         LIBCRYPTO_AUTH_AS_HMAC,
81 };
82
83 /** private data structure for each LIBCRYPTO crypto device */
84 struct libcrypto_private {
85         unsigned int max_nb_qpairs;
86         /**< Max number of queue pairs */
87         unsigned int max_nb_sessions;
88         /**< Max number of sessions */
89 };
90
91 /** LIBCRYPTO crypto queue pair */
92 struct libcrypto_qp {
93         uint16_t id;
94         /**< Queue Pair Identifier */
95         char name[RTE_CRYPTODEV_NAME_LEN];
96         /**< Unique Queue Pair Name */
97         struct rte_ring *processed_ops;
98         /**< Ring for placing process packets */
99         struct rte_mempool *sess_mp;
100         /**< Session Mempool */
101         struct rte_cryptodev_stats stats;
102         /**< Queue pair statistics */
103 } __rte_cache_aligned;
104
105 /** LIBCRYPTO crypto private session structure */
106 struct libcrypto_session {
107         enum libcrypto_chain_order chain_order;
108         /**< chain order mode */
109
110         /** Cipher Parameters */
111         struct {
112                 enum rte_crypto_cipher_operation direction;
113                 /**< cipher operation direction */
114                 enum libcrypto_cipher_mode mode;
115                 /**< cipher operation mode */
116                 enum rte_crypto_cipher_algorithm algo;
117                 /**< cipher algorithm */
118
119                 struct {
120                         uint8_t data[32];
121                         /**< key data */
122                         size_t length;
123                         /**< key length in bytes */
124                 } key;
125
126                 const EVP_CIPHER *evp_algo;
127                 /**< pointer to EVP algorithm function */
128                 EVP_CIPHER_CTX *ctx;
129                 /**< pointer to EVP context structure */
130         } cipher;
131
132         /** Authentication Parameters */
133         struct {
134                 enum rte_crypto_auth_operation operation;
135                 /**< auth operation generate or verify */
136                 enum libcrypto_auth_mode mode;
137                 /**< auth operation mode */
138                 enum rte_crypto_auth_algorithm algo;
139                 /**< cipher algorithm */
140
141                 union {
142                         struct {
143                                 const EVP_MD *evp_algo;
144                                 /**< pointer to EVP algorithm function */
145                                 EVP_MD_CTX *ctx;
146                                 /**< pointer to EVP context structure */
147                         } auth;
148
149                         struct {
150                                 EVP_PKEY *pkey;
151                                 /**< pointer to EVP key */
152                                 const EVP_MD *evp_algo;
153                                 /**< pointer to EVP algorithm function */
154                                 EVP_MD_CTX *ctx;
155                                 /**< pointer to EVP context structure */
156                         } hmac;
157                 };
158         } auth;
159
160 } __rte_cache_aligned;
161
162 /** Set and validate LIBCRYPTO crypto session parameters */
163 extern int
164 libcrypto_set_session_parameters(struct libcrypto_session *sess,
165                 const struct rte_crypto_sym_xform *xform);
166
167 /** Reset LIBCRYPTO crypto session parameters */
168 extern void
169 libcrypto_reset_session(struct libcrypto_session *sess);
170
171 /** device specific operations function pointer structure */
172 extern struct rte_cryptodev_ops *rte_libcrypto_pmd_ops;
173
174 #endif /* _LIBCRYPTO_PMD_PRIVATE_H_ */