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