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