mempool: introduce helpers for populate and required size
[dpdk.git] / drivers / crypto / qat / qat_sym_session.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2019 Intel Corporation
3  */
4 #ifndef _QAT_SYM_SESSION_H_
5 #define _QAT_SYM_SESSION_H_
6
7 #include <rte_crypto.h>
8 #include <rte_cryptodev_pmd.h>
9
10 #include "qat_common.h"
11 #include "icp_qat_hw.h"
12 #include "icp_qat_fw.h"
13 #include "icp_qat_fw_la.h"
14
15 /*
16  * Key Modifier (KM) value used in KASUMI algorithm in F9 mode to XOR
17  * Integrity Key (IK)
18  */
19 #define KASUMI_F9_KEY_MODIFIER_4_BYTES   0xAAAAAAAA
20
21 #define KASUMI_F8_KEY_MODIFIER_4_BYTES   0x55555555
22
23 /* 3DES key sizes */
24 #define QAT_3DES_KEY_SZ_OPT1 24 /* Keys are independent */
25 #define QAT_3DES_KEY_SZ_OPT2 16 /* K3=K1 */
26 #define QAT_3DES_KEY_SZ_OPT3 8 /* K1=K2=K3 */
27
28 /* 96-bit case of IV for CCP/GCM single pass algorithm */
29 #define QAT_AES_GCM_SPC_IV_SIZE 12
30
31
32 #define QAT_AES_HW_CONFIG_CBC_ENC(alg) \
33         ICP_QAT_HW_CIPHER_CONFIG_BUILD(ICP_QAT_HW_CIPHER_CBC_MODE, alg, \
34                                         ICP_QAT_HW_CIPHER_NO_CONVERT, \
35                                         ICP_QAT_HW_CIPHER_ENCRYPT)
36
37 #define QAT_AES_HW_CONFIG_CBC_DEC(alg) \
38         ICP_QAT_HW_CIPHER_CONFIG_BUILD(ICP_QAT_HW_CIPHER_CBC_MODE, alg, \
39                                         ICP_QAT_HW_CIPHER_KEY_CONVERT, \
40                                         ICP_QAT_HW_CIPHER_DECRYPT)
41
42 #define QAT_AES_CMAC_CONST_RB 0x87
43
44 enum qat_sym_proto_flag {
45         QAT_CRYPTO_PROTO_FLAG_NONE = 0,
46         QAT_CRYPTO_PROTO_FLAG_CCM = 1,
47         QAT_CRYPTO_PROTO_FLAG_GCM = 2,
48         QAT_CRYPTO_PROTO_FLAG_SNOW3G = 3,
49         QAT_CRYPTO_PROTO_FLAG_ZUC = 4
50 };
51
52 /* Common content descriptor */
53 struct qat_sym_cd {
54         struct icp_qat_hw_cipher_algo_blk cipher;
55         struct icp_qat_hw_auth_algo_blk hash;
56 } __rte_packed __rte_cache_aligned;
57
58 struct qat_sym_session {
59         enum icp_qat_fw_la_cmd_id qat_cmd;
60         enum icp_qat_hw_cipher_algo qat_cipher_alg;
61         enum icp_qat_hw_cipher_dir qat_dir;
62         enum icp_qat_hw_cipher_mode qat_mode;
63         enum icp_qat_hw_auth_algo qat_hash_alg;
64         enum icp_qat_hw_auth_op auth_op;
65         void *bpi_ctx;
66         struct qat_sym_cd cd;
67         uint8_t *cd_cur_ptr;
68         phys_addr_t cd_paddr;
69         struct icp_qat_fw_la_bulk_req fw_req;
70         uint8_t aad_len;
71         struct qat_crypto_instance *inst;
72         struct {
73                 uint16_t offset;
74                 uint16_t length;
75         } cipher_iv;
76         struct {
77                 uint16_t offset;
78                 uint16_t length;
79         } auth_iv;
80         uint16_t digest_length;
81         rte_spinlock_t lock;    /* protects this struct */
82         enum qat_device_gen min_qat_dev_gen;
83         uint8_t aes_cmac;
84         uint8_t is_single_pass;
85 };
86
87 int
88 qat_sym_session_configure(struct rte_cryptodev *dev,
89                 struct rte_crypto_sym_xform *xform,
90                 struct rte_cryptodev_sym_session *sess,
91                 struct rte_mempool *mempool);
92
93 int
94 qat_sym_session_set_parameters(struct rte_cryptodev *dev,
95                 struct rte_crypto_sym_xform *xform, void *session_private);
96
97 int
98 qat_sym_session_configure_aead(struct rte_cryptodev *dev,
99                                 struct rte_crypto_sym_xform *xform,
100                                 struct qat_sym_session *session);
101
102 int
103 qat_sym_session_configure_cipher(struct rte_cryptodev *dev,
104                 struct rte_crypto_sym_xform *xform,
105                 struct qat_sym_session *session);
106
107 int
108 qat_sym_session_configure_auth(struct rte_cryptodev *dev,
109                                 struct rte_crypto_sym_xform *xform,
110                                 struct qat_sym_session *session);
111
112 int
113 qat_sym_session_aead_create_cd_cipher(struct qat_sym_session *cd,
114                                                 const uint8_t *enckey,
115                                                 uint32_t enckeylen);
116
117 int
118 qat_sym_session_aead_create_cd_auth(struct qat_sym_session *cdesc,
119                                                 const uint8_t *authkey,
120                                                 uint32_t authkeylen,
121                                                 uint32_t aad_length,
122                                                 uint32_t digestsize,
123                                                 unsigned int operation);
124
125 void
126 qat_sym_session_clear(struct rte_cryptodev *dev,
127                 struct rte_cryptodev_sym_session *session);
128
129 unsigned int
130 qat_sym_session_get_private_size(struct rte_cryptodev *dev);
131
132 void
133 qat_sym_sesssion_init_common_hdr(struct icp_qat_fw_comn_req_hdr *header,
134                                         enum qat_sym_proto_flag proto_flags);
135 int
136 qat_sym_validate_aes_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
137 int
138 qat_sym_validate_aes_docsisbpi_key(int key_len,
139                                         enum icp_qat_hw_cipher_algo *alg);
140 int
141 qat_sym_validate_snow3g_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
142 int
143 qat_sym_validate_kasumi_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
144 int
145 qat_sym_validate_3des_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
146 int
147 qat_sym_validate_des_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
148 int
149 qat_cipher_get_block_size(enum icp_qat_hw_cipher_algo qat_cipher_alg);
150 int
151 qat_sym_validate_zuc_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
152
153 #endif /* _QAT_SYM_SESSION_H_ */