crypto/qat: add symmetric session file
[dpdk.git] / drivers / crypto / qat / qat_sym_session.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 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
27 #define QAT_AES_HW_CONFIG_CBC_ENC(alg) \
28         ICP_QAT_HW_CIPHER_CONFIG_BUILD(ICP_QAT_HW_CIPHER_CBC_MODE, alg, \
29                                         ICP_QAT_HW_CIPHER_NO_CONVERT, \
30                                         ICP_QAT_HW_CIPHER_ENCRYPT)
31
32 #define QAT_AES_HW_CONFIG_CBC_DEC(alg) \
33         ICP_QAT_HW_CIPHER_CONFIG_BUILD(ICP_QAT_HW_CIPHER_CBC_MODE, alg, \
34                                         ICP_QAT_HW_CIPHER_KEY_CONVERT, \
35                                         ICP_QAT_HW_CIPHER_DECRYPT)
36
37 enum qat_crypto_proto_flag {
38         QAT_CRYPTO_PROTO_FLAG_NONE = 0,
39         QAT_CRYPTO_PROTO_FLAG_CCM = 1,
40         QAT_CRYPTO_PROTO_FLAG_GCM = 2,
41         QAT_CRYPTO_PROTO_FLAG_SNOW3G = 3,
42         QAT_CRYPTO_PROTO_FLAG_ZUC = 4
43 };
44
45 /* Common content descriptor */
46 struct qat_alg_cd {
47         struct icp_qat_hw_cipher_algo_blk cipher;
48         struct icp_qat_hw_auth_algo_blk hash;
49 } __rte_packed __rte_cache_aligned;
50
51 struct qat_session {
52         enum icp_qat_fw_la_cmd_id qat_cmd;
53         enum icp_qat_hw_cipher_algo qat_cipher_alg;
54         enum icp_qat_hw_cipher_dir qat_dir;
55         enum icp_qat_hw_cipher_mode qat_mode;
56         enum icp_qat_hw_auth_algo qat_hash_alg;
57         enum icp_qat_hw_auth_op auth_op;
58         void *bpi_ctx;
59         struct qat_alg_cd cd;
60         uint8_t *cd_cur_ptr;
61         phys_addr_t cd_paddr;
62         struct icp_qat_fw_la_bulk_req fw_req;
63         uint8_t aad_len;
64         struct qat_crypto_instance *inst;
65         struct {
66                 uint16_t offset;
67                 uint16_t length;
68         } cipher_iv;
69         struct {
70                 uint16_t offset;
71                 uint16_t length;
72         } auth_iv;
73         uint16_t digest_length;
74         rte_spinlock_t lock;    /* protects this struct */
75         enum qat_device_gen min_qat_dev_gen;
76 };
77
78 int
79 qat_crypto_sym_configure_session(struct rte_cryptodev *dev,
80                 struct rte_crypto_sym_xform *xform,
81                 struct rte_cryptodev_sym_session *sess,
82                 struct rte_mempool *mempool);
83
84 int
85 qat_crypto_set_session_parameters(struct rte_cryptodev *dev,
86                 struct rte_crypto_sym_xform *xform, void *session_private);
87
88 int
89 qat_crypto_sym_configure_session_aead(struct rte_crypto_sym_xform *xform,
90                                 struct qat_session *session);
91
92 int
93 qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
94                 struct rte_crypto_sym_xform *xform,
95                 struct qat_session *session);
96
97 int
98 qat_crypto_sym_configure_session_auth(struct rte_cryptodev *dev,
99                                 struct rte_crypto_sym_xform *xform,
100                                 struct qat_session *session);
101
102 int
103 qat_alg_aead_session_create_content_desc_cipher(struct qat_session *cd,
104                                                 uint8_t *enckey,
105                                                 uint32_t enckeylen);
106
107 int
108 qat_alg_aead_session_create_content_desc_auth(struct qat_session *cdesc,
109                                                 uint8_t *authkey,
110                                                 uint32_t authkeylen,
111                                                 uint32_t aad_length,
112                                                 uint32_t digestsize,
113                                                 unsigned int operation);
114
115 int
116 qat_pmd_session_mempool_create(struct rte_cryptodev *dev,
117         unsigned int nb_objs, unsigned int obj_cache_size, int socket_id);
118
119 void
120 qat_crypto_sym_clear_session(struct rte_cryptodev *dev,
121                 struct rte_cryptodev_sym_session *session);
122
123 unsigned int
124 qat_crypto_sym_get_session_private_size(struct rte_cryptodev *dev);
125
126 int qat_get_inter_state_size(enum icp_qat_hw_auth_algo qat_hash_alg);
127
128
129 void qat_alg_init_common_hdr(struct icp_qat_fw_comn_req_hdr *header,
130                                         enum qat_crypto_proto_flag proto_flags);
131
132 int qat_alg_validate_aes_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
133 int qat_alg_validate_aes_docsisbpi_key(int key_len,
134                                         enum icp_qat_hw_cipher_algo *alg);
135 int qat_alg_validate_snow3g_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
136 int qat_alg_validate_kasumi_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
137 int qat_alg_validate_3des_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
138 int qat_alg_validate_des_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
139 int qat_cipher_get_block_size(enum icp_qat_hw_cipher_algo qat_cipher_alg);
140 int qat_alg_validate_zuc_key(int key_len, enum icp_qat_hw_cipher_algo *alg);
141
142 #endif /* _QAT_SYM_SESSION_H_ */