051fb203daf9b853749fc09944ffa098ae9b39ff
[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 /** OPENSSL PMD LOGTYPE DRIVER */
16 int openssl_logtype_driver;
17 #define OPENSSL_LOG(level, fmt, ...)  \
18         rte_log(RTE_LOG_ ## level, openssl_logtype_driver,  \
19                         "%s() line %u: " fmt "\n", __func__, __LINE__,  \
20                                         ## __VA_ARGS__)
21
22 /* Maximum length for digest (SHA-512 needs 64 bytes) */
23 #define DIGEST_LENGTH_MAX 64
24
25 /** OPENSSL operation order mode enumerator */
26 enum openssl_chain_order {
27         OPENSSL_CHAIN_ONLY_CIPHER,
28         OPENSSL_CHAIN_ONLY_AUTH,
29         OPENSSL_CHAIN_CIPHER_BPI,
30         OPENSSL_CHAIN_CIPHER_AUTH,
31         OPENSSL_CHAIN_AUTH_CIPHER,
32         OPENSSL_CHAIN_COMBINED,
33         OPENSSL_CHAIN_NOT_SUPPORTED
34 };
35
36 /** OPENSSL cipher mode enumerator */
37 enum openssl_cipher_mode {
38         OPENSSL_CIPHER_LIB,
39         OPENSSL_CIPHER_DES3CTR,
40 };
41
42 /** OPENSSL auth mode enumerator */
43 enum openssl_auth_mode {
44         OPENSSL_AUTH_AS_AUTH,
45         OPENSSL_AUTH_AS_HMAC,
46 };
47
48 /** private data structure for each OPENSSL crypto device */
49 struct openssl_private {
50         unsigned int max_nb_qpairs;
51         /**< Max number of queue pairs */
52         unsigned int max_nb_sessions;
53         /**< Max number of sessions */
54 };
55
56 /** OPENSSL crypto queue pair */
57 struct openssl_qp {
58         uint16_t id;
59         /**< Queue Pair Identifier */
60         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
61         /**< Unique Queue Pair Name */
62         struct rte_ring *processed_ops;
63         /**< Ring for placing process packets */
64         struct rte_mempool *sess_mp;
65         /**< Session Mempool */
66         struct rte_cryptodev_stats stats;
67         /**< Queue pair statistics */
68         uint8_t temp_digest[DIGEST_LENGTH_MAX];
69         /**< Buffer used to store the digest generated
70          * by the driver when verifying a digest provided
71          * by the user (using authentication verify operation)
72          */
73 } __rte_cache_aligned;
74
75 /** OPENSSL crypto private session structure */
76 struct openssl_session {
77         enum openssl_chain_order chain_order;
78         /**< chain order mode */
79
80         struct {
81                 uint16_t length;
82                 uint16_t offset;
83         } iv;
84         /**< IV parameters */
85
86         enum rte_crypto_aead_algorithm aead_algo;
87         /**< AEAD algorithm */
88
89         /** Cipher Parameters */
90         struct {
91                 enum rte_crypto_cipher_operation direction;
92                 /**< cipher operation direction */
93                 enum openssl_cipher_mode mode;
94                 /**< cipher operation mode */
95                 enum rte_crypto_cipher_algorithm algo;
96                 /**< cipher algorithm */
97
98                 struct {
99                         uint8_t data[32];
100                         /**< key data */
101                         size_t length;
102                         /**< key length in bytes */
103                 } key;
104
105                 const EVP_CIPHER *evp_algo;
106                 /**< pointer to EVP algorithm function */
107                 EVP_CIPHER_CTX *ctx;
108                 /**< pointer to EVP context structure */
109                 EVP_CIPHER_CTX *bpi_ctx;
110         } cipher;
111
112         /** Authentication Parameters */
113         struct {
114                 enum rte_crypto_auth_operation operation;
115                 /**< auth operation generate or verify */
116                 enum openssl_auth_mode mode;
117                 /**< auth operation mode */
118                 enum rte_crypto_auth_algorithm algo;
119                 /**< cipher algorithm */
120
121                 union {
122                         struct {
123                                 const EVP_MD *evp_algo;
124                                 /**< pointer to EVP algorithm function */
125                                 EVP_MD_CTX *ctx;
126                                 /**< pointer to EVP context structure */
127                         } auth;
128
129                         struct {
130                                 EVP_PKEY *pkey;
131                                 /**< pointer to EVP key */
132                                 const EVP_MD *evp_algo;
133                                 /**< pointer to EVP algorithm function */
134                                 HMAC_CTX *ctx;
135                                 /**< pointer to EVP context structure */
136                         } hmac;
137                 };
138
139                 uint16_t aad_length;
140                 /**< AAD length */
141                 uint16_t digest_length;
142                 /**< digest length */
143         } auth;
144
145 } __rte_cache_aligned;
146
147 /** Set and validate OPENSSL crypto session parameters */
148 extern int
149 openssl_set_session_parameters(struct openssl_session *sess,
150                 const struct rte_crypto_sym_xform *xform);
151
152 /** Reset OPENSSL crypto session parameters */
153 extern void
154 openssl_reset_session(struct openssl_session *sess);
155
156 /** device specific operations function pointer structure */
157 extern struct rte_cryptodev_ops *rte_openssl_pmd_ops;
158
159 #endif /* _OPENSSL_PMD_PRIVATE_H_ */