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