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