1#ifndef BACKENDS_TOFINO_BF_UTILS_INCLUDE_DYNAMIC_HASH_BFN_HASH_ALGORITHM_H_
2#define BACKENDS_TOFINO_BF_UTILS_INCLUDE_DYNAMIC_HASH_BFN_HASH_ALGORITHM_H_
14#define BF_UTILS_ALGO_NAME_LEN 30
61typedef enum { IDENTITY_DYN, CRC_DYN, RANDOM_DYN, XOR_DYN, INVALID_DYN } bfn_hash_alg_type_t;
63static inline void crc_alg_type_to_str(bfn_crc_alg_t crc_type,
char *crc_name) {
69 strncpy(crc_name,
"CRC_8\0", BF_UTILS_ALGO_NAME_LEN);
72 strncpy(crc_name,
"CRC_8_DARC\0", BF_UTILS_ALGO_NAME_LEN);
75 strncpy(crc_name,
"CRC_8_I_CODE\0", BF_UTILS_ALGO_NAME_LEN);
78 strncpy(crc_name,
"CRC_8_ITU\0", BF_UTILS_ALGO_NAME_LEN);
81 strncpy(crc_name,
"CRC_8_MAXIM\0", BF_UTILS_ALGO_NAME_LEN);
84 strncpy(crc_name,
"CRC_8_ROHC\0", BF_UTILS_ALGO_NAME_LEN);
87 strncpy(crc_name,
"CRC_8_WCDMA\0", BF_UTILS_ALGO_NAME_LEN);
90 strncpy(crc_name,
"CRC_16\0", BF_UTILS_ALGO_NAME_LEN);
93 strncpy(crc_name,
"CRC_16_BYPASS\0", BF_UTILS_ALGO_NAME_LEN);
96 strncpy(crc_name,
"CRC_16_DDS_110\0", BF_UTILS_ALGO_NAME_LEN);
99 strncpy(crc_name,
"CRC_16_DECT\0", BF_UTILS_ALGO_NAME_LEN);
102 strncpy(crc_name,
"CRC_16_DECT_R\0", BF_UTILS_ALGO_NAME_LEN);
105 strncpy(crc_name,
"CRC_16_DECT_X\0", BF_UTILS_ALGO_NAME_LEN);
108 strncpy(crc_name,
"CRC_16_DNP\0", BF_UTILS_ALGO_NAME_LEN);
110 case CRC_16_EN_13757:
111 strncpy(crc_name,
"CRC_16_EN_13757\0", BF_UTILS_ALGO_NAME_LEN);
114 strncpy(crc_name,
"CRC_16_GENIBUS\0", BF_UTILS_ALGO_NAME_LEN);
117 strncpy(crc_name,
"CRC_16_MAXIM\0", BF_UTILS_ALGO_NAME_LEN);
120 strncpy(crc_name,
"CRC_16_MCRF4XX\0", BF_UTILS_ALGO_NAME_LEN);
123 strncpy(crc_name,
"CRC_16_RIELLO\0", BF_UTILS_ALGO_NAME_LEN);
126 strncpy(crc_name,
"CRC_16_T10_DIF\0", BF_UTILS_ALGO_NAME_LEN);
128 case CRC_16_TELEDISK:
129 strncpy(crc_name,
"CRC_16_TELEDISK\0", BF_UTILS_ALGO_NAME_LEN);
132 strncpy(crc_name,
"CRC_16_USB\0", BF_UTILS_ALGO_NAME_LEN);
135 strncpy(crc_name,
"X_25\0", BF_UTILS_ALGO_NAME_LEN);
138 strncpy(crc_name,
"XMODEM\0", BF_UTILS_ALGO_NAME_LEN);
141 strncpy(crc_name,
"MODBUS\0", BF_UTILS_ALGO_NAME_LEN);
144 strncpy(crc_name,
"KERMIT\0", BF_UTILS_ALGO_NAME_LEN);
146 case CRC_CCITT_FALSE:
147 strncpy(crc_name,
"CRC_CCITT_FALSE\0", BF_UTILS_ALGO_NAME_LEN);
150 strncpy(crc_name,
"CRC_AUG_CCITT\0", BF_UTILS_ALGO_NAME_LEN);
153 strncpy(crc_name,
"CRC_32\0", BF_UTILS_ALGO_NAME_LEN);
156 strncpy(crc_name,
"CRC_32_BZIP2\0", BF_UTILS_ALGO_NAME_LEN);
159 strncpy(crc_name,
"CRC_32C\0", BF_UTILS_ALGO_NAME_LEN);
162 strncpy(crc_name,
"CRC_32D\0", BF_UTILS_ALGO_NAME_LEN);
165 strncpy(crc_name,
"CRC_32_MPEG\0", BF_UTILS_ALGO_NAME_LEN);
168 strncpy(crc_name,
"POSIX\0", BF_UTILS_ALGO_NAME_LEN);
171 strncpy(crc_name,
"CRC_32Q\0", BF_UTILS_ALGO_NAME_LEN);
174 strncpy(crc_name,
"JAMCRC\0", BF_UTILS_ALGO_NAME_LEN);
177 strncpy(crc_name,
"XFER\0", BF_UTILS_ALGO_NAME_LEN);
180 strncpy(crc_name,
"CRC_64\0", BF_UTILS_ALGO_NAME_LEN);
183 strncpy(crc_name,
"CRC_64_GO_ISO\0", BF_UTILS_ALGO_NAME_LEN);
186 strncpy(crc_name,
"CRC_64_WE\0", BF_UTILS_ALGO_NAME_LEN);
189 strncpy(crc_name,
"CRC_64_JONES\0", BF_UTILS_ALGO_NAME_LEN);
193 strncpy(crc_name,
"CRC_INVALID\0", BF_UTILS_ALGO_NAME_LEN);
199static inline bfn_crc_alg_t crc_alg_str_to_type(
const char *crc_name) {
200 if (crc_name == NULL) {
203 if (!strcmp(crc_name,
"crc_8") || !strcmp(crc_name,
"CRC_8")) {
206 if (!strcmp(crc_name,
"crc_8_darc") || !strcmp(crc_name,
"CRC_8_DARC")) {
209 if (!strcmp(crc_name,
"crc_8_i_code") || !strcmp(crc_name,
"CRC_8_I_CODE")) {
212 if (!strcmp(crc_name,
"crc_8_itu") || !strcmp(crc_name,
"CRC_8_ITU")) {
215 if (!strcmp(crc_name,
"crc_8_maxim") || !strcmp(crc_name,
"CRC_8_MAXIM")) {
218 if (!strcmp(crc_name,
"crc_8_rohc") || !strcmp(crc_name,
"CRC_8_ROHC")) {
221 if (!strcmp(crc_name,
"crc_8_wcdma") || !strcmp(crc_name,
"CRC_8_WCDMA")) {
224 if (!strcmp(crc_name,
"crc_16") || !strcmp(crc_name,
"CRC_16")) {
227 if (!strcmp(crc_name,
"crc_16_bypass") || !strcmp(crc_name,
"CRC_16_BYPASS")) {
228 return CRC_16_BYPASS;
230 if (!strcmp(crc_name,
"crc_16_dds_110") || !strcmp(crc_name,
"CRC_16_DDS_110")) {
231 return CRC_16_DDS_110;
233 if (!strcmp(crc_name,
"crc_16_dect") || !strcmp(crc_name,
"CRC_16_DECT")) {
236 if (!strcmp(crc_name,
"crc_16_dect_r") || !strcmp(crc_name,
"CRC_16_DECT_R")) {
237 return CRC_16_DECT_R;
239 if (!strcmp(crc_name,
"crc_16_dect_x") || !strcmp(crc_name,
"CRC_16_DECT_X")) {
240 return CRC_16_DECT_X;
242 if (!strcmp(crc_name,
"crc_16_dnp") || !strcmp(crc_name,
"CRC_16_DNP")) {
245 if (!strcmp(crc_name,
"crc_16_en_13757") || !strcmp(crc_name,
"CRC_16_EN_13757")) {
246 return CRC_16_EN_13757;
248 if (!strcmp(crc_name,
"crc_16_genibus") || !strcmp(crc_name,
"CRC_16_GENIBUS")) {
249 return CRC_16_GENIBUS;
251 if (!strcmp(crc_name,
"crc_16_maxim") || !strcmp(crc_name,
"CRC_16_MAXIM")) {
254 if (!strcmp(crc_name,
"crc_16_mcrf4xx") || !strcmp(crc_name,
"CRC_16_MCRF4XX")) {
255 return CRC_16_MCRF4XX;
257 if (!strcmp(crc_name,
"crc_16_riello") || !strcmp(crc_name,
"CRC_16_RIELLO")) {
258 return CRC_16_RIELLO;
260 if (!strcmp(crc_name,
"crc_16_t10_dif") || !strcmp(crc_name,
"CRC_16_T10_DIF")) {
261 return CRC_16_T10_DIF;
263 if (!strcmp(crc_name,
"crc_16_teledisk") || !strcmp(crc_name,
"CRC_16_TELEDISK")) {
264 return CRC_16_TELEDISK;
266 if (!strcmp(crc_name,
"crc_16_usb") || !strcmp(crc_name,
"CRC_16_USB")) {
269 if (!strcmp(crc_name,
"x_25") || !strcmp(crc_name,
"X_25")) {
272 if (!strcmp(crc_name,
"xmodem") || !strcmp(crc_name,
"XMODEM")) {
275 if (!strcmp(crc_name,
"modbus") || !strcmp(crc_name,
"MODBUS")) {
278 if (!strcmp(crc_name,
"kermit") || !strcmp(crc_name,
"KERMIT")) {
281 if (!strcmp(crc_name,
"crc_ccitt_false") || !strcmp(crc_name,
"CRC_CCITT_FALSE")) {
282 return CRC_CCITT_FALSE;
284 if (!strcmp(crc_name,
"crc_aug_ccitt") || !strcmp(crc_name,
"CRC_AUG_CCITT")) {
285 return CRC_AUG_CCITT;
287 if (!strcmp(crc_name,
"crc_32") || !strcmp(crc_name,
"CRC_32")) {
290 if (!strcmp(crc_name,
"crc_32_bzip2") || !strcmp(crc_name,
"CRC_32_BZIP2")) {
293 if (!strcmp(crc_name,
"crc_32c") || !strcmp(crc_name,
"CRC_32C")) {
296 if (!strcmp(crc_name,
"crc_32d") || !strcmp(crc_name,
"CRC_32D")) {
299 if (!strcmp(crc_name,
"crc_32_mpeg") || !strcmp(crc_name,
"CRC_32_MPEG")) {
302 if (!strcmp(crc_name,
"posix") || !strcmp(crc_name,
"POSIX")) {
305 if (!strcmp(crc_name,
"crc_32q") || !strcmp(crc_name,
"CRC_32Q")) {
308 if (!strcmp(crc_name,
"jamcrc") || !strcmp(crc_name,
"JAMCRC")) {
311 if (!strcmp(crc_name,
"xfer") || !strcmp(crc_name,
"XFER")) {
314 if (!strcmp(crc_name,
"crc_64") || !strcmp(crc_name,
"CRC_64")) {
317 if (!strcmp(crc_name,
"crc_64_go_iso") || !strcmp(crc_name,
"CRC_64_GO_ISO")) {
318 return CRC_64_GO_ISO;
320 if (!strcmp(crc_name,
"crc_64_we") || !strcmp(crc_name,
"CRC_64_WE")) {
323 if (!strcmp(crc_name,
"crc_64_jones") || !strcmp(crc_name,
"CRC_64_JONES")) {
329static inline void hash_alg_type_to_str(bfn_hash_alg_type_t alg_type,
char *alg_name) {
330 if (alg_name == NULL) {
335 strncpy(alg_name,
"IDENTITY\0", BF_UTILS_ALGO_NAME_LEN);
338 strncpy(alg_name,
"CRC\0", BF_UTILS_ALGO_NAME_LEN);
341 strncpy(alg_name,
"RANDOM\0", BF_UTILS_ALGO_NAME_LEN);
344 strncpy(alg_name,
"XOR\0", BF_UTILS_ALGO_NAME_LEN);
348 strncpy(alg_name,
"INVALID\0", BF_UTILS_ALGO_NAME_LEN);
354static inline bfn_hash_alg_type_t hash_alg_str_to_type(
const char *alg_name) {
355 if (alg_name == NULL) {
358 if (!strcmp(alg_name,
"identity") || !strcmp(alg_name,
"IDENTITY")) {
361 if (!strcmp(alg_name,
"crc") || !strcmp(alg_name,
"CRC")) {
364 if (!strcmp(alg_name,
"random") || !strcmp(alg_name,
"RANDOM")) {
367 if (!strcmp(alg_name,
"xor") || !strcmp(alg_name,
"XOR")) {
386 bfn_hash_alg_type_t hash_alg;
392 bfn_crc_alg_t crc_type;
398 uint8_t **crc_matrix;
418void initialize_algorithm(
bfn_hash_algorithm_t *alg, bfn_hash_alg_type_t hash_alg_type,
bool msb,
419 bool extend, bfn_crc_alg_t crc_alg);
424 uint32_t stream_len, uint8_t *crc);
Definition bfn_hash_algorithm.h:385
Definition bfn_hash_algorithm.h:377