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