New upstream version 18.02
[deb_dpdk.git] / drivers / crypto / openssl / rte_openssl_pmd_private.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2017 Intel Corporation
3  */
4
5 #ifndef _OPENSSL_PMD_PRIVATE_H_
6 #define _OPENSSL_PMD_PRIVATE_H_
7
8 #include <openssl/evp.h>
9 #include <openssl/hmac.h>
10 #include <openssl/des.h>
11
12 #define CRYPTODEV_NAME_OPENSSL_PMD      crypto_openssl
13 /**< Open SSL Crypto PMD device name */
14
15 #define OPENSSL_LOG_ERR(fmt, args...) \
16         RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n",  \
17                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), \
18                         __func__, __LINE__, ## args)
19
20 #ifdef RTE_LIBRTE_OPENSSL_DEBUG
21 #define OPENSSL_LOG_INFO(fmt, args...) \
22         RTE_LOG(INFO, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
23                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), \
24                         __func__, __LINE__, ## args)
25
26 #define OPENSSL_LOG_DBG(fmt, args...) \
27         RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
28                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), \
29                         __func__, __LINE__, ## args)
30 #else
31 #define OPENSSL_LOG_INFO(fmt, args...)
32 #define OPENSSL_LOG_DBG(fmt, args...)
33 #endif
34
35 /* Maximum length for digest (SHA-512 needs 64 bytes) */
36 #define DIGEST_LENGTH_MAX 64
37
38 /** OPENSSL operation order mode enumerator */
39 enum openssl_chain_order {
40         OPENSSL_CHAIN_ONLY_CIPHER,
41         OPENSSL_CHAIN_ONLY_AUTH,
42         OPENSSL_CHAIN_CIPHER_BPI,
43         OPENSSL_CHAIN_CIPHER_AUTH,
44         OPENSSL_CHAIN_AUTH_CIPHER,
45         OPENSSL_CHAIN_COMBINED,
46         OPENSSL_CHAIN_NOT_SUPPORTED
47 };
48
49 /** OPENSSL cipher mode enumerator */
50 enum openssl_cipher_mode {
51         OPENSSL_CIPHER_LIB,
52         OPENSSL_CIPHER_DES3CTR,
53 };
54
55 /** OPENSSL auth mode enumerator */
56 enum openssl_auth_mode {
57         OPENSSL_AUTH_AS_AUTH,
58         OPENSSL_AUTH_AS_HMAC,
59 };
60
61 /** private data structure for each OPENSSL crypto device */
62 struct openssl_private {
63         unsigned int max_nb_qpairs;
64         /**< Max number of queue pairs */
65         unsigned int max_nb_sessions;
66         /**< Max number of sessions */
67 };
68
69 /** OPENSSL crypto queue pair */
70 struct openssl_qp {
71         uint16_t id;
72         /**< Queue Pair Identifier */
73         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
74         /**< Unique Queue Pair Name */
75         struct rte_ring *processed_ops;
76         /**< Ring for placing process packets */
77         struct rte_mempool *sess_mp;
78         /**< Session Mempool */
79         struct rte_cryptodev_stats stats;
80         /**< Queue pair statistics */
81         uint8_t temp_digest[DIGEST_LENGTH_MAX];
82         /**< Buffer used to store the digest generated
83          * by the driver when verifying a digest provided
84          * by the user (using authentication verify operation)
85          */
86 } __rte_cache_aligned;
87
88 /** OPENSSL crypto private session structure */
89 struct openssl_session {
90         enum openssl_chain_order chain_order;
91         /**< chain order mode */
92
93         struct {
94                 uint16_t length;
95                 uint16_t offset;
96         } iv;
97         /**< IV parameters */
98
99         enum rte_crypto_aead_algorithm aead_algo;
100         /**< AEAD algorithm */
101
102         /** Cipher Parameters */
103         struct {
104                 enum rte_crypto_cipher_operation direction;
105                 /**< cipher operation direction */
106                 enum openssl_cipher_mode mode;
107                 /**< cipher operation mode */
108                 enum rte_crypto_cipher_algorithm algo;
109                 /**< cipher algorithm */
110
111                 struct {
112                         uint8_t data[32];
113                         /**< key data */
114                         size_t length;
115                         /**< key length in bytes */
116                 } key;
117
118                 const EVP_CIPHER *evp_algo;
119                 /**< pointer to EVP algorithm function */
120                 EVP_CIPHER_CTX *ctx;
121                 /**< pointer to EVP context structure */
122                 EVP_CIPHER_CTX *bpi_ctx;
123         } cipher;
124
125         /** Authentication Parameters */
126         struct {
127                 enum rte_crypto_auth_operation operation;
128                 /**< auth operation generate or verify */
129                 enum openssl_auth_mode mode;
130                 /**< auth operation mode */
131                 enum rte_crypto_auth_algorithm algo;
132                 /**< cipher algorithm */
133
134                 union {
135                         struct {
136                                 const EVP_MD *evp_algo;
137                                 /**< pointer to EVP algorithm function */
138                                 EVP_MD_CTX *ctx;
139                                 /**< pointer to EVP context structure */
140                         } auth;
141
142                         struct {
143                                 EVP_PKEY *pkey;
144                                 /**< pointer to EVP key */
145                                 const EVP_MD *evp_algo;
146                                 /**< pointer to EVP algorithm function */
147                                 HMAC_CTX *ctx;
148                                 /**< pointer to EVP context structure */
149                         } hmac;
150                 };
151
152                 uint16_t aad_length;
153                 /**< AAD length */
154                 uint16_t digest_length;
155                 /**< digest length */
156         } auth;
157
158 } __rte_cache_aligned;
159
160 /** Set and validate OPENSSL crypto session parameters */
161 extern int
162 openssl_set_session_parameters(struct openssl_session *sess,
163                 const struct rte_crypto_sym_xform *xform);
164
165 /** Reset OPENSSL crypto session parameters */
166 extern void
167 openssl_reset_session(struct openssl_session *sess);
168
169 /** device specific operations function pointer structure */
170 extern struct rte_cryptodev_ops *rte_openssl_pmd_ops;
171
172 #endif /* _OPENSSL_PMD_PRIVATE_H_ */