7#ifndef BACKENDS_TOFINO_BF_UTILS_DYNAMIC_HASH_BFN_HASH_ALGORITHM_H_
8#define BACKENDS_TOFINO_BF_UTILS_DYNAMIC_HASH_BFN_HASH_ALGORITHM_H_
16#define BF_UTILS_ALGO_NAME_LEN 30
63typedef enum { IDENTITY_DYN, CRC_DYN, RANDOM_DYN, XOR_DYN, INVALID_DYN } bfn_hash_alg_type_t;
65static inline void crc_alg_type_to_str(bfn_crc_alg_t crc_type,
char *crc_name) {
71 strncpy(crc_name,
"CRC_8\0", BF_UTILS_ALGO_NAME_LEN);
74 strncpy(crc_name,
"CRC_8_DARC\0", BF_UTILS_ALGO_NAME_LEN);
77 strncpy(crc_name,
"CRC_8_I_CODE\0", BF_UTILS_ALGO_NAME_LEN);
80 strncpy(crc_name,
"CRC_8_ITU\0", BF_UTILS_ALGO_NAME_LEN);
83 strncpy(crc_name,
"CRC_8_MAXIM\0", BF_UTILS_ALGO_NAME_LEN);
86 strncpy(crc_name,
"CRC_8_ROHC\0", BF_UTILS_ALGO_NAME_LEN);
89 strncpy(crc_name,
"CRC_8_WCDMA\0", BF_UTILS_ALGO_NAME_LEN);
92 strncpy(crc_name,
"CRC_16\0", BF_UTILS_ALGO_NAME_LEN);
95 strncpy(crc_name,
"CRC_16_BYPASS\0", BF_UTILS_ALGO_NAME_LEN);
98 strncpy(crc_name,
"CRC_16_DDS_110\0", BF_UTILS_ALGO_NAME_LEN);
101 strncpy(crc_name,
"CRC_16_DECT\0", BF_UTILS_ALGO_NAME_LEN);
104 strncpy(crc_name,
"CRC_16_DECT_R\0", BF_UTILS_ALGO_NAME_LEN);
107 strncpy(crc_name,
"CRC_16_DECT_X\0", BF_UTILS_ALGO_NAME_LEN);
110 strncpy(crc_name,
"CRC_16_DNP\0", BF_UTILS_ALGO_NAME_LEN);
112 case CRC_16_EN_13757:
113 strncpy(crc_name,
"CRC_16_EN_13757\0", BF_UTILS_ALGO_NAME_LEN);
116 strncpy(crc_name,
"CRC_16_GENIBUS\0", BF_UTILS_ALGO_NAME_LEN);
119 strncpy(crc_name,
"CRC_16_MAXIM\0", BF_UTILS_ALGO_NAME_LEN);
122 strncpy(crc_name,
"CRC_16_MCRF4XX\0", BF_UTILS_ALGO_NAME_LEN);
125 strncpy(crc_name,
"CRC_16_RIELLO\0", BF_UTILS_ALGO_NAME_LEN);
128 strncpy(crc_name,
"CRC_16_T10_DIF\0", BF_UTILS_ALGO_NAME_LEN);
130 case CRC_16_TELEDISK:
131 strncpy(crc_name,
"CRC_16_TELEDISK\0", BF_UTILS_ALGO_NAME_LEN);
134 strncpy(crc_name,
"CRC_16_USB\0", BF_UTILS_ALGO_NAME_LEN);
137 strncpy(crc_name,
"X_25\0", BF_UTILS_ALGO_NAME_LEN);
140 strncpy(crc_name,
"XMODEM\0", BF_UTILS_ALGO_NAME_LEN);
143 strncpy(crc_name,
"MODBUS\0", BF_UTILS_ALGO_NAME_LEN);
146 strncpy(crc_name,
"KERMIT\0", BF_UTILS_ALGO_NAME_LEN);
148 case CRC_CCITT_FALSE:
149 strncpy(crc_name,
"CRC_CCITT_FALSE\0", BF_UTILS_ALGO_NAME_LEN);
152 strncpy(crc_name,
"CRC_AUG_CCITT\0", BF_UTILS_ALGO_NAME_LEN);
155 strncpy(crc_name,
"CRC_32\0", BF_UTILS_ALGO_NAME_LEN);
158 strncpy(crc_name,
"CRC_32_BZIP2\0", BF_UTILS_ALGO_NAME_LEN);
161 strncpy(crc_name,
"CRC_32C\0", BF_UTILS_ALGO_NAME_LEN);
164 strncpy(crc_name,
"CRC_32D\0", BF_UTILS_ALGO_NAME_LEN);
167 strncpy(crc_name,
"CRC_32_MPEG\0", BF_UTILS_ALGO_NAME_LEN);
170 strncpy(crc_name,
"POSIX\0", BF_UTILS_ALGO_NAME_LEN);
173 strncpy(crc_name,
"CRC_32Q\0", BF_UTILS_ALGO_NAME_LEN);
176 strncpy(crc_name,
"JAMCRC\0", BF_UTILS_ALGO_NAME_LEN);
179 strncpy(crc_name,
"XFER\0", BF_UTILS_ALGO_NAME_LEN);
182 strncpy(crc_name,
"CRC_64\0", BF_UTILS_ALGO_NAME_LEN);
185 strncpy(crc_name,
"CRC_64_GO_ISO\0", BF_UTILS_ALGO_NAME_LEN);
188 strncpy(crc_name,
"CRC_64_WE\0", BF_UTILS_ALGO_NAME_LEN);
191 strncpy(crc_name,
"CRC_64_JONES\0", BF_UTILS_ALGO_NAME_LEN);
195 strncpy(crc_name,
"CRC_INVALID\0", BF_UTILS_ALGO_NAME_LEN);
201static inline bfn_crc_alg_t crc_alg_str_to_type(
const char *crc_name) {
202 if (crc_name == NULL) {
205 if (!strcmp(crc_name,
"crc_8") || !strcmp(crc_name,
"CRC_8")) {
208 if (!strcmp(crc_name,
"crc_8_darc") || !strcmp(crc_name,
"CRC_8_DARC")) {
211 if (!strcmp(crc_name,
"crc_8_i_code") || !strcmp(crc_name,
"CRC_8_I_CODE")) {
214 if (!strcmp(crc_name,
"crc_8_itu") || !strcmp(crc_name,
"CRC_8_ITU")) {
217 if (!strcmp(crc_name,
"crc_8_maxim") || !strcmp(crc_name,
"CRC_8_MAXIM")) {
220 if (!strcmp(crc_name,
"crc_8_rohc") || !strcmp(crc_name,
"CRC_8_ROHC")) {
223 if (!strcmp(crc_name,
"crc_8_wcdma") || !strcmp(crc_name,
"CRC_8_WCDMA")) {
226 if (!strcmp(crc_name,
"crc_16") || !strcmp(crc_name,
"CRC_16")) {
229 if (!strcmp(crc_name,
"crc_16_bypass") || !strcmp(crc_name,
"CRC_16_BYPASS")) {
230 return CRC_16_BYPASS;
232 if (!strcmp(crc_name,
"crc_16_dds_110") || !strcmp(crc_name,
"CRC_16_DDS_110")) {
233 return CRC_16_DDS_110;
235 if (!strcmp(crc_name,
"crc_16_dect") || !strcmp(crc_name,
"CRC_16_DECT")) {
238 if (!strcmp(crc_name,
"crc_16_dect_r") || !strcmp(crc_name,
"CRC_16_DECT_R")) {
239 return CRC_16_DECT_R;
241 if (!strcmp(crc_name,
"crc_16_dect_x") || !strcmp(crc_name,
"CRC_16_DECT_X")) {
242 return CRC_16_DECT_X;
244 if (!strcmp(crc_name,
"crc_16_dnp") || !strcmp(crc_name,
"CRC_16_DNP")) {
247 if (!strcmp(crc_name,
"crc_16_en_13757") || !strcmp(crc_name,
"CRC_16_EN_13757")) {
248 return CRC_16_EN_13757;
250 if (!strcmp(crc_name,
"crc_16_genibus") || !strcmp(crc_name,
"CRC_16_GENIBUS")) {
251 return CRC_16_GENIBUS;
253 if (!strcmp(crc_name,
"crc_16_maxim") || !strcmp(crc_name,
"CRC_16_MAXIM")) {
256 if (!strcmp(crc_name,
"crc_16_mcrf4xx") || !strcmp(crc_name,
"CRC_16_MCRF4XX")) {
257 return CRC_16_MCRF4XX;
259 if (!strcmp(crc_name,
"crc_16_riello") || !strcmp(crc_name,
"CRC_16_RIELLO")) {
260 return CRC_16_RIELLO;
262 if (!strcmp(crc_name,
"crc_16_t10_dif") || !strcmp(crc_name,
"CRC_16_T10_DIF")) {
263 return CRC_16_T10_DIF;
265 if (!strcmp(crc_name,
"crc_16_teledisk") || !strcmp(crc_name,
"CRC_16_TELEDISK")) {
266 return CRC_16_TELEDISK;
268 if (!strcmp(crc_name,
"crc_16_usb") || !strcmp(crc_name,
"CRC_16_USB")) {
271 if (!strcmp(crc_name,
"x_25") || !strcmp(crc_name,
"X_25")) {
274 if (!strcmp(crc_name,
"xmodem") || !strcmp(crc_name,
"XMODEM")) {
277 if (!strcmp(crc_name,
"modbus") || !strcmp(crc_name,
"MODBUS")) {
280 if (!strcmp(crc_name,
"kermit") || !strcmp(crc_name,
"KERMIT")) {
283 if (!strcmp(crc_name,
"crc_ccitt_false") || !strcmp(crc_name,
"CRC_CCITT_FALSE")) {
284 return CRC_CCITT_FALSE;
286 if (!strcmp(crc_name,
"crc_aug_ccitt") || !strcmp(crc_name,
"CRC_AUG_CCITT")) {
287 return CRC_AUG_CCITT;
289 if (!strcmp(crc_name,
"crc_32") || !strcmp(crc_name,
"CRC_32")) {
292 if (!strcmp(crc_name,
"crc_32_bzip2") || !strcmp(crc_name,
"CRC_32_BZIP2")) {
295 if (!strcmp(crc_name,
"crc_32c") || !strcmp(crc_name,
"CRC_32C")) {
298 if (!strcmp(crc_name,
"crc_32d") || !strcmp(crc_name,
"CRC_32D")) {
301 if (!strcmp(crc_name,
"crc_32_mpeg") || !strcmp(crc_name,
"CRC_32_MPEG")) {
304 if (!strcmp(crc_name,
"posix") || !strcmp(crc_name,
"POSIX")) {
307 if (!strcmp(crc_name,
"crc_32q") || !strcmp(crc_name,
"CRC_32Q")) {
310 if (!strcmp(crc_name,
"jamcrc") || !strcmp(crc_name,
"JAMCRC")) {
313 if (!strcmp(crc_name,
"xfer") || !strcmp(crc_name,
"XFER")) {
316 if (!strcmp(crc_name,
"crc_64") || !strcmp(crc_name,
"CRC_64")) {
319 if (!strcmp(crc_name,
"crc_64_go_iso") || !strcmp(crc_name,
"CRC_64_GO_ISO")) {
320 return CRC_64_GO_ISO;
322 if (!strcmp(crc_name,
"crc_64_we") || !strcmp(crc_name,
"CRC_64_WE")) {
325 if (!strcmp(crc_name,
"crc_64_jones") || !strcmp(crc_name,
"CRC_64_JONES")) {
331static inline void hash_alg_type_to_str(bfn_hash_alg_type_t alg_type,
char *alg_name) {
332 if (alg_name == NULL) {
337 strncpy(alg_name,
"IDENTITY\0", BF_UTILS_ALGO_NAME_LEN);
340 strncpy(alg_name,
"CRC\0", BF_UTILS_ALGO_NAME_LEN);
343 strncpy(alg_name,
"RANDOM\0", BF_UTILS_ALGO_NAME_LEN);
346 strncpy(alg_name,
"XOR\0", BF_UTILS_ALGO_NAME_LEN);
350 strncpy(alg_name,
"INVALID\0", BF_UTILS_ALGO_NAME_LEN);
356static inline bfn_hash_alg_type_t hash_alg_str_to_type(
const char *alg_name) {
357 if (alg_name == NULL) {
360 if (!strcmp(alg_name,
"identity") || !strcmp(alg_name,
"IDENTITY")) {
363 if (!strcmp(alg_name,
"crc") || !strcmp(alg_name,
"CRC")) {
366 if (!strcmp(alg_name,
"random") || !strcmp(alg_name,
"RANDOM")) {
369 if (!strcmp(alg_name,
"xor") || !strcmp(alg_name,
"XOR")) {
380 const char *crc_name;
388 bfn_hash_alg_type_t hash_alg;
394 bfn_crc_alg_t crc_type;
400 uint8_t **crc_matrix;
401} bfn_hash_algorithm_t;
408bool verify_algorithm(bfn_hash_algorithm_t *alg,
const char **error_message);
420void initialize_algorithm(bfn_hash_algorithm_t *alg, bfn_hash_alg_type_t hash_alg_type,
bool msb,
421 bool extend, bfn_crc_alg_t crc_alg);
423void initialize_crc_matrix(bfn_hash_algorithm_t *alg);
425void calculate_crc(bfn_hash_algorithm_t *alg, uint32_t hash_output_bits, uint8_t *stream,
426 uint32_t stream_len, uint8_t *crc);
Definition bfn_hash_algorithm.h:387
Definition bfn_hash_algorithm.h:379