1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /* $FreeBSD$ */
4 
5 /**
6  *****************************************************************************
7  * @file lac_sym_qat_hash.h
8  *
9  * @defgroup LacSymQatHash  Hash QAT
10  *
11  * @ingroup LacSymQat
12  *
13  * interfaces for populating qat structures for a hash operation
14  *
15  *****************************************************************************/
16 
17 /*****************************************************************************/
18 
19 #ifndef LAC_SYM_QAT_HASH_H
20 #define LAC_SYM_QAT_HASH_H
21 
22 /*
23 ******************************************************************************
24 * Include public/global header files
25 ******************************************************************************
26 */
27 
28 #include "cpa.h"
29 #include "cpa_cy_sym.h"
30 #include "icp_qat_fw_la.h"
31 #include "icp_qat_hw.h"
32 
33 /*
34 *******************************************************************************
35 * Include private header files
36 *******************************************************************************
37 */
38 #include "lac_common.h"
39 
40 /**
41  ******************************************************************************
42  * @ingroup LacSymQatHash
43  *      hash precomputes
44  *
45  * @description
46  *      This structure contains infomation on the hash precomputes
47  *
48  *****************************************************************************/
49 typedef struct lac_sym_qat_hash_precompute_info_s {
50 	Cpa8U *pState1;
51 	/**< state1 pointer */
52 	Cpa32U state1Size;
53 	/**< state1 size */
54 	Cpa8U *pState2;
55 	/**< state2 pointer */
56 	Cpa32U state2Size;
57 	/**< state2 size */
58 } lac_sym_qat_hash_precompute_info_t;
59 
60 /**
61  ******************************************************************************
62  * @ingroup LacSymQatHash
63  *      hash state prefix buffer info
64  *
65  * @description
66  *      This structure contains infomation on the hash state prefix aad buffer
67  *
68  *****************************************************************************/
69 typedef struct lac_sym_qat_hash_state_buffer_info_s {
70 	Cpa64U pDataPhys;
71 	/**< Physical pointer to the hash state prefix buffer */
72 	Cpa8U *pData;
73 	/**< Virtual pointer to the hash state prefix buffer */
74 	Cpa8U stateStorageSzQuadWords;
75 	/**< hash state storage size in quad words */
76 	Cpa8U prefixAadSzQuadWords;
77 	/**< inner prefix/aad and outer prefix size in quad words */
78 } lac_sym_qat_hash_state_buffer_info_t;
79 
80 /**
81  ******************************************************************************
82  * @ingroup LacSymQatHash
83  *      Init the hash specific part of the content descriptor.
84  *
85  * @description
86  *      This function populates the hash specific fields of the control block
87  *      and the hardware setup block for a digest session. This function sets
88  *      the size param to hold the size of the hash setup block.
89  *
90  *      In the case of hash only, the content descriptor will contain just a
91  *      hash control block and hash setup block. In the case of chaining it
92  *      will contain the hash control block and setup block along with the
93  *      control block and setup blocks of additional services.
94  *
95  *      Note: The memory for the content descriptor MUST be allocated prior to
96  *      calling this function. The memory for the hash control block and hash
97  *      setup block MUST be set to 0 prior to calling this function.
98  *
99  * @image html contentDescriptor.png "Content Descriptor"
100  *
101  * @param[in] pMsg                      Pointer to req Parameter Footer
102  *
103  * @param[in] pHashSetupData            Pointer to the hash setup data as
104  *                                      defined in the LAC API.
105  *
106  * @param[in] pHwBlockBase              Pointer to the base of the hardware
107  *                                      setup block
108  *
109  * @param[in] hashBlkOffsetInHwBlock    Offset in quad-words from the base of
110  *                                      the hardware setup block where the
111  *                                      hash block will start. This offset
112  *                                      is stored in the control block. It
113  *                                      is used to figure out where to write
114  *                                      that hash setup block.
115  *
116  * @param[in] nextSlice                 SliceID for next control block
117  *                                      entry This value is known only by
118  *                                      the calling component
119  *
120  * @param[in] qatHashMode               QAT hash mode
121  *
122  * @param[in] useSymConstantsTable      Indicate if Shared-SRAM constants table
123  *                                      is used for this session. If TRUE, the
124  *                                      h/w setup block is NOT populated
125  *
126  * @param[in] useOptimisedContentDesc   Indicate if optimised content desc
127  *                                      is used for this session.
128  *
129  * @param[in] useStatefulSha3ContentDesc
130  *                                      Indicate if stateful SHA3 content desc
131  *                                      is used for this session.
132  *
133  * @param[in] pPrecompute               For auth mode, this is the pointer
134  *                                      to the precompute data. Otherwise this
135  *                                      should be set to NULL
136  *
137  * @param[out] pHashBlkSizeInBytes      size in bytes of hash setup block
138  *
139  * @return void
140  *
141  *****************************************************************************/
142 void
143 LacSymQat_HashContentDescInit(icp_qat_la_bulk_req_ftr_t *pMsg,
144 			      CpaInstanceHandle instanceHandle,
145 			      const CpaCySymHashSetupData *pHashSetupData,
146 			      void *pHwBlockBase,
147 			      Cpa32U hashBlkOffsetInHwBlock,
148 			      icp_qat_fw_slice_t nextSlice,
149 			      icp_qat_hw_auth_mode_t qatHashMode,
150 			      CpaBoolean useSymConstantsTable,
151 			      CpaBoolean useOptimisedContentDesc,
152 			      CpaBoolean useStatefulSha3ContentDesc,
153 			      lac_sym_qat_hash_precompute_info_t *pPrecompute,
154 			      Cpa32U *pHashBlkSizeInBytes);
155 
156 /**
157  ******************************************************************************
158  * @ingroup LacSymQatHash
159  *      Calculate the size of the hash state prefix aad buffer
160  *
161  * @description
162  *      This function inspects the hash control block and based on the values
163  *      in the fields, it calculates the size of the hash state prefix aad
164  *      buffer.
165  *
166  *      A partial packet processing request is possible at any stage during a
167  *      hash session. In this case, there will always be space for the hash
168  *      state storage field of the hash state prefix buffer. When there is
169  *      AAD data just the inner prefix AAD data field is used.
170  *
171  * @param[in]  pMsg                 Pointer to the Request Message
172  *
173  * @param[out] pHashStateBuf        Pointer to hash state prefix buffer info
174  *                                  structure.
175  *
176  * @return None
177  *
178  *****************************************************************************/
179 void LacSymQat_HashStatePrefixAadBufferSizeGet(
180     icp_qat_la_bulk_req_ftr_t *pMsg,
181     lac_sym_qat_hash_state_buffer_info_t *pHashStateBuf);
182 
183 /**
184  ******************************************************************************
185  * @ingroup LacSymQatHash
186  *      Populate the fields of the hash state prefix buffer
187  *
188  * @description
189  *      This function populates the inner prefix/aad fields and/or the outer
190  *      prefix field of the hash state prefix buffer.
191  *
192  * @param[in] pHashStateBuf         Pointer to hash state prefix buffer info
193  *                                  structure.
194  *
195  * @param[in] pMsg                  Pointer to the Request Message
196  *
197  * @param[in] pInnerPrefixAad       Pointer to the Inner Prefix or Aad data
198  *                                  This is NULL where if the data size is 0
199  *
200  * @param[in] innerPrefixSize       Size of inner prefix/aad data in bytes
201  *
202  * @param[in] pOuterPrefix          Pointer to the Outer Prefix data. This is
203  *                                  NULL where the data size is 0.
204  *
205  * @param[in] outerPrefixSize       Size of the outer prefix data in bytes
206  *
207  * @return void
208  *
209  *****************************************************************************/
210 void LacSymQat_HashStatePrefixAadBufferPopulate(
211     lac_sym_qat_hash_state_buffer_info_t *pHashStateBuf,
212     icp_qat_la_bulk_req_ftr_t *pMsg,
213     Cpa8U *pInnerPrefixAad,
214     Cpa8U innerPrefixSize,
215     Cpa8U *pOuterPrefix,
216     Cpa8U outerPrefixSize);
217 
218 /**
219  ******************************************************************************
220  * @ingroup LacSymQatHash
221  *      Populate the hash request params structure
222  *
223  * @description
224  *      This function is passed a pointer to the 128B Request block.
225  *      (This memory must be allocated prior to calling this function). It
226  *      populates the fields of this block using the parameters as described
227  *      below. It is also expected that this structure has been set to 0
228  *      prior to calling this function.
229  *
230  *
231  * @param[in] pReq                  Pointer to 128B request block.
232  *
233  * @param[in] authOffsetInBytes     start offset of data that the digest is to
234  *                                  be computed on.
235  *
236  * @param[in] authLenInBytes        Length of data digest calculated on
237  *
238  * @param[in] pService              Pointer to service data
239  *
240  * @param[in] pHashStateBuf         Pointer to hash state buffer info. This
241  *                                  structure contains the pointers and sizes.
242  *                                  If there is no hash state prefix buffer
243  *                                  required, this parameter can be set to NULL
244  *
245  * @param[in] qatPacketType         Packet type using QAT macros. The hash
246  *                                  state buffer pointer and state size will be
247  *                                  different depending on the packet type
248  *
249  * @param[in] hashResultSize        Size of the final hash result in bytes.
250  *
251  * @param[in] digestVerify          Indicates if verify is enabled or not
252  *
253  * @param[in] pAuthResult           Virtual pointer to digest
254  *
255  * @return CPA_STATUS_SUCCESS or CPA_STATUS_FAIL
256  *
257  *****************************************************************************/
258 CpaStatus LacSymQat_HashRequestParamsPopulate(
259     icp_qat_fw_la_bulk_req_t *pReq,
260     Cpa32U authOffsetInBytes,
261     Cpa32U authLenInBytes,
262     sal_service_t *pService,
263     lac_sym_qat_hash_state_buffer_info_t *pHashStateBuf,
264     Cpa32U qatPacketType,
265     Cpa32U hashResultSize,
266     CpaBoolean digestVerify,
267     Cpa8U *pAuthResult,
268     CpaCySymHashAlgorithm alg,
269     void *data);
270 
271 /**
272  ******************************************************************************
273  * @ingroup LacSymQatHash
274  *
275  *
276  * @description
277  *      This fn returns the QAT values for hash algorithm and nested fields
278  *
279  *
280  * @param[in] pInstance              Pointer to service instance.
281  *
282  * @param[in] qatHashMode            value for hash mode on the fw qat
283  *interface.
284  *
285  * @param[in] apiHashMode            value for hash mode on the QA API.
286  *
287  * @param[in] apiHashAlgorithm       value for hash algorithm on the QA API.
288  *
289  * @param[out] pQatAlgorithm         Pointer to return fw qat value for
290  *algorithm.
291  *
292  * @param[out] pQatNested            Pointer to return fw qat value for nested.
293  *
294  *
295  * @return
296  *      none
297  *
298  *****************************************************************************/
299 void LacSymQat_HashGetCfgData(CpaInstanceHandle pInstance,
300 			      icp_qat_hw_auth_mode_t qatHashMode,
301 			      CpaCySymHashMode apiHashMode,
302 			      CpaCySymHashAlgorithm apiHashAlgorithm,
303 			      icp_qat_hw_auth_algo_t *pQatAlgorithm,
304 			      CpaBoolean *pQatNested);
305 
306 void LacSymQat_HashSetupReqParamsMetaData(
307     icp_qat_la_bulk_req_ftr_t *pMsg,
308     CpaInstanceHandle instanceHandle,
309     const CpaCySymHashSetupData *pHashSetupData,
310     CpaBoolean hashStateBuffer,
311     icp_qat_hw_auth_mode_t qatHashMode,
312     CpaBoolean digestVerify);
313 
314 #endif /* LAC_SYM_QAT_HASH_H */
315