1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* Copyright(c) 2007-2022 Intel Corporation */ 3 4 /** 5 *************************************************************************** 6 * @file lac_sym_qat_constants_table.c 7 * 8 * @ingroup LacSymQat 9 ***************************************************************************/ 10 11 /* 12 ******************************************************************************* 13 * Include public/global header files 14 ******************************************************************************* 15 */ 16 17 #include "cpa.h" 18 19 /* 20 ******************************************************************************* 21 * Include private header files 22 ******************************************************************************* 23 */ 24 25 #include "lac_common.h" 26 #include "icp_qat_fw_la.h" 27 #include "lac_log.h" 28 #include "lac_mem.h" 29 #include "sal_string_parse.h" 30 #include "lac_sal_types_crypto.h" 31 #include "sal_types_compression.h" 32 33 static uint8_t icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_DELIMITER] 34 [ICP_QAT_HW_CIPHER_MODE_DELIMITER][2] 35 [2]; /* IA version */ 36 static uint8_t icp_qat_hw_auth_lookup_tbl[ICP_QAT_HW_AUTH_ALGO_DELIMITER] 37 [ICP_QAT_HW_AUTH_MODE_DELIMITER] 38 [2]; /* IA version */ 39 40 #define ICP_QAT_HW_FILL_LOOKUP_TBLS \ 41 { \ 42 \ 43 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_DES] \ 44 [ICP_QAT_HW_CIPHER_ECB_MODE] \ 45 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 46 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 47 9; \ 48 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_DES] \ 49 [ICP_QAT_HW_CIPHER_ECB_MODE] \ 50 [ICP_QAT_HW_CIPHER_DECRYPT] \ 51 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 52 10; \ 53 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_DES] \ 54 [ICP_QAT_HW_CIPHER_CBC_MODE] \ 55 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 56 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 57 11; \ 58 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_DES] \ 59 [ICP_QAT_HW_CIPHER_CBC_MODE] \ 60 [ICP_QAT_HW_CIPHER_DECRYPT] \ 61 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 62 12; \ 63 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_DES] \ 64 [ICP_QAT_HW_CIPHER_CTR_MODE] \ 65 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 66 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 67 13; \ 68 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 69 [ICP_QAT_HW_CIPHER_ECB_MODE] \ 70 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 71 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 72 14; \ 73 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 74 [ICP_QAT_HW_CIPHER_ECB_MODE] \ 75 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 76 [ICP_QAT_HW_CIPHER_KEY_CONVERT] = \ 77 15; \ 78 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 79 [ICP_QAT_HW_CIPHER_ECB_MODE] \ 80 [ICP_QAT_HW_CIPHER_DECRYPT] \ 81 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 82 16; \ 83 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 84 [ICP_QAT_HW_CIPHER_ECB_MODE] \ 85 [ICP_QAT_HW_CIPHER_DECRYPT] \ 86 [ICP_QAT_HW_CIPHER_KEY_CONVERT] = \ 87 17; \ 88 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 89 [ICP_QAT_HW_CIPHER_CBC_MODE] \ 90 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 91 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 92 18; \ 93 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 94 [ICP_QAT_HW_CIPHER_CBC_MODE] \ 95 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 96 [ICP_QAT_HW_CIPHER_KEY_CONVERT] = \ 97 19; \ 98 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 99 [ICP_QAT_HW_CIPHER_CBC_MODE] \ 100 [ICP_QAT_HW_CIPHER_DECRYPT] \ 101 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 102 20; \ 103 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 104 [ICP_QAT_HW_CIPHER_CBC_MODE] \ 105 [ICP_QAT_HW_CIPHER_DECRYPT] \ 106 [ICP_QAT_HW_CIPHER_KEY_CONVERT] = \ 107 21; \ 108 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 109 [ICP_QAT_HW_CIPHER_CTR_MODE] \ 110 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 111 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 112 22; \ 113 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 114 [ICP_QAT_HW_CIPHER_F8_MODE] \ 115 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 116 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 117 23; \ 118 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_ARC4] \ 119 [ICP_QAT_HW_CIPHER_ECB_MODE] \ 120 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 121 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 122 24; \ 123 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_ARC4] \ 124 [ICP_QAT_HW_CIPHER_ECB_MODE] \ 125 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 126 [ICP_QAT_HW_CIPHER_KEY_CONVERT] = \ 127 25; \ 128 \ 129 icp_qat_hw_auth_lookup_tbl \ 130 [ICP_QAT_HW_AUTH_ALGO_MD5][ICP_QAT_HW_AUTH_MODE0] \ 131 [ICP_QAT_FW_AUTH_HDR_FLAG_NO_NESTED] = 37; \ 132 icp_qat_hw_auth_lookup_tbl \ 133 [ICP_QAT_HW_AUTH_ALGO_SHA1][ICP_QAT_HW_AUTH_MODE0] \ 134 [ICP_QAT_FW_AUTH_HDR_FLAG_NO_NESTED] = 41; \ 135 icp_qat_hw_auth_lookup_tbl \ 136 [ICP_QAT_HW_AUTH_ALGO_SHA1][ICP_QAT_HW_AUTH_MODE1] \ 137 [ICP_QAT_FW_AUTH_HDR_FLAG_NO_NESTED] = 46; \ 138 icp_qat_hw_auth_lookup_tbl \ 139 [ICP_QAT_HW_AUTH_ALGO_SHA224][ICP_QAT_HW_AUTH_MODE0] \ 140 [ICP_QAT_FW_AUTH_HDR_FLAG_NO_NESTED] = 48; \ 141 icp_qat_hw_auth_lookup_tbl \ 142 [ICP_QAT_HW_AUTH_ALGO_SHA256][ICP_QAT_HW_AUTH_MODE0] \ 143 [ICP_QAT_FW_AUTH_HDR_FLAG_NO_NESTED] = 54; \ 144 icp_qat_hw_auth_lookup_tbl \ 145 [ICP_QAT_HW_AUTH_ALGO_SHA384][ICP_QAT_HW_AUTH_MODE0] \ 146 [ICP_QAT_FW_AUTH_HDR_FLAG_NO_NESTED] = 60; \ 147 icp_qat_hw_auth_lookup_tbl \ 148 [ICP_QAT_HW_AUTH_ALGO_SHA512][ICP_QAT_HW_AUTH_MODE0] \ 149 [ICP_QAT_FW_AUTH_HDR_FLAG_NO_NESTED] = 70; \ 150 } 151 152 /** 153 ***************************************************************************** 154 * @ingroup LacSymQat 155 * LacSymQat_ConstantsInitLookupTables 156 * 157 * 158 *****************************************************************************/ 159 void 160 LacSymQat_ConstantsInitLookupTables(CpaInstanceHandle instanceHandle) 161 { 162 sal_service_t *pService = (sal_service_t *)instanceHandle; 163 lac_sym_qat_constants_t *pConstantsLookupTables; 164 165 /* Note the global tables are initialised first, then copied 166 * to the service which probably seems like a waste of memory 167 * and processing cycles as the global tables are never needed again 168 * but this allows use of the ICP_QAT_HW_FILL_LOOKUP_TBLS macro 169 * supplied by FW without modification */ 170 171 if (SAL_SERVICE_TYPE_COMPRESSION == pService->type) { 172 /* DC chaining not supported yet */ 173 return; 174 } else { 175 pConstantsLookupTables = &( 176 ((sal_crypto_service_t *)pService)->constantsLookupTables); 177 } 178 179 /* First fill the global lookup tables with zeroes. */ 180 memset(icp_qat_hw_cipher_lookup_tbl, 181 0, 182 sizeof(icp_qat_hw_cipher_lookup_tbl)); 183 memset(icp_qat_hw_auth_lookup_tbl, 184 0, 185 sizeof(icp_qat_hw_auth_lookup_tbl)); 186 187 /* Override lookup tables with the offsets into the SHRAM table 188 * for supported algorithms/modes */ 189 ICP_QAT_HW_FILL_LOOKUP_TBLS; 190 191 /* Copy the global tables to the service instance */ 192 memcpy(pConstantsLookupTables->cipher_offset, 193 icp_qat_hw_cipher_lookup_tbl, 194 sizeof(pConstantsLookupTables->cipher_offset)); 195 memcpy(pConstantsLookupTables->auth_offset, 196 icp_qat_hw_auth_lookup_tbl, 197 sizeof(pConstantsLookupTables->auth_offset)); 198 } 199 200 /** 201 ***************************************************************************** 202 * @ingroup LacSymQat 203 * LacSymQat_ConstantsGetCipherOffset 204 * 205 * 206 *****************************************************************************/ 207 void 208 LacSymQat_ConstantsGetCipherOffset(CpaInstanceHandle instanceHandle, 209 uint8_t algo, 210 uint8_t mode, 211 uint8_t direction, 212 uint8_t convert, 213 uint8_t *poffset) 214 { 215 sal_service_t *pService = (sal_service_t *)instanceHandle; 216 lac_sym_qat_constants_t *pConstantsLookupTables; 217 218 if (SAL_SERVICE_TYPE_COMPRESSION == pService->type) { 219 /* DC chaining not supported yet */ 220 return; 221 } else { 222 pConstantsLookupTables = &( 223 ((sal_crypto_service_t *)pService)->constantsLookupTables); 224 } 225 226 *poffset = pConstantsLookupTables 227 ->cipher_offset[algo][mode][direction][convert]; 228 } 229 230 /** 231 ***************************************************************************** 232 * @ingroup LacSymQat 233 * LacSymQat_ConstantsGetAuthOffset 234 * 235 * 236 *****************************************************************************/ 237 void 238 LacSymQat_ConstantsGetAuthOffset(CpaInstanceHandle instanceHandle, 239 uint8_t algo, 240 uint8_t mode, 241 uint8_t nested, 242 uint8_t *poffset) 243 { 244 sal_service_t *pService = (sal_service_t *)instanceHandle; 245 lac_sym_qat_constants_t *pConstantsLookupTables; 246 247 if (SAL_SERVICE_TYPE_COMPRESSION == pService->type) { 248 /* DC chaining not supported yet */ 249 return; 250 } else { 251 pConstantsLookupTables = &( 252 ((sal_crypto_service_t *)pService)->constantsLookupTables); 253 } 254 255 *poffset = pConstantsLookupTables->auth_offset[algo][mode][nested]; 256 } 257