1#ifndef BACKENDS_TOFINO_BF_UTILS_DYNAMIC_HASH_BFN_HASH_ALGORITHM_H_
2#define BACKENDS_TOFINO_BF_UTILS_DYNAMIC_HASH_BFN_HASH_ALGORITHM_H_
10#define BF_UTILS_ALGO_NAME_LEN 30
57typedef enum { IDENTITY_DYN, CRC_DYN, RANDOM_DYN, XOR_DYN, INVALID_DYN } bfn_hash_alg_type_t;
59static inline void crc_alg_type_to_str(bfn_crc_alg_t crc_type,
char *crc_name) {
65 strncpy(crc_name,
"CRC_8\0", BF_UTILS_ALGO_NAME_LEN);
68 strncpy(crc_name,
"CRC_8_DARC\0", BF_UTILS_ALGO_NAME_LEN);
71 strncpy(crc_name,
"CRC_8_I_CODE\0", BF_UTILS_ALGO_NAME_LEN);
74 strncpy(crc_name,
"CRC_8_ITU\0", BF_UTILS_ALGO_NAME_LEN);
77 strncpy(crc_name,
"CRC_8_MAXIM\0", BF_UTILS_ALGO_NAME_LEN);
80 strncpy(crc_name,
"CRC_8_ROHC\0", BF_UTILS_ALGO_NAME_LEN);
83 strncpy(crc_name,
"CRC_8_WCDMA\0", BF_UTILS_ALGO_NAME_LEN);
86 strncpy(crc_name,
"CRC_16\0", BF_UTILS_ALGO_NAME_LEN);
89 strncpy(crc_name,
"CRC_16_BYPASS\0", BF_UTILS_ALGO_NAME_LEN);
92 strncpy(crc_name,
"CRC_16_DDS_110\0", BF_UTILS_ALGO_NAME_LEN);
95 strncpy(crc_name,
"CRC_16_DECT\0", BF_UTILS_ALGO_NAME_LEN);
98 strncpy(crc_name,
"CRC_16_DECT_R\0", BF_UTILS_ALGO_NAME_LEN);
101 strncpy(crc_name,
"CRC_16_DECT_X\0", BF_UTILS_ALGO_NAME_LEN);
104 strncpy(crc_name,
"CRC_16_DNP\0", BF_UTILS_ALGO_NAME_LEN);
106 case CRC_16_EN_13757:
107 strncpy(crc_name,
"CRC_16_EN_13757\0", BF_UTILS_ALGO_NAME_LEN);
110 strncpy(crc_name,
"CRC_16_GENIBUS\0", BF_UTILS_ALGO_NAME_LEN);
113 strncpy(crc_name,
"CRC_16_MAXIM\0", BF_UTILS_ALGO_NAME_LEN);
116 strncpy(crc_name,
"CRC_16_MCRF4XX\0", BF_UTILS_ALGO_NAME_LEN);
119 strncpy(crc_name,
"CRC_16_RIELLO\0", BF_UTILS_ALGO_NAME_LEN);
122 strncpy(crc_name,
"CRC_16_T10_DIF\0", BF_UTILS_ALGO_NAME_LEN);
124 case CRC_16_TELEDISK:
125 strncpy(crc_name,
"CRC_16_TELEDISK\0", BF_UTILS_ALGO_NAME_LEN);
128 strncpy(crc_name,
"CRC_16_USB\0", BF_UTILS_ALGO_NAME_LEN);
131 strncpy(crc_name,
"X_25\0", BF_UTILS_ALGO_NAME_LEN);
134 strncpy(crc_name,
"XMODEM\0", BF_UTILS_ALGO_NAME_LEN);
137 strncpy(crc_name,
"MODBUS\0", BF_UTILS_ALGO_NAME_LEN);
140 strncpy(crc_name,
"KERMIT\0", BF_UTILS_ALGO_NAME_LEN);
142 case CRC_CCITT_FALSE:
143 strncpy(crc_name,
"CRC_CCITT_FALSE\0", BF_UTILS_ALGO_NAME_LEN);
146 strncpy(crc_name,
"CRC_AUG_CCITT\0", BF_UTILS_ALGO_NAME_LEN);
149 strncpy(crc_name,
"CRC_32\0", BF_UTILS_ALGO_NAME_LEN);
152 strncpy(crc_name,
"CRC_32_BZIP2\0", BF_UTILS_ALGO_NAME_LEN);
155 strncpy(crc_name,
"CRC_32C\0", BF_UTILS_ALGO_NAME_LEN);
158 strncpy(crc_name,
"CRC_32D\0", BF_UTILS_ALGO_NAME_LEN);
161 strncpy(crc_name,
"CRC_32_MPEG\0", BF_UTILS_ALGO_NAME_LEN);
164 strncpy(crc_name,
"POSIX\0", BF_UTILS_ALGO_NAME_LEN);
167 strncpy(crc_name,
"CRC_32Q\0", BF_UTILS_ALGO_NAME_LEN);
170 strncpy(crc_name,
"JAMCRC\0", BF_UTILS_ALGO_NAME_LEN);
173 strncpy(crc_name,
"XFER\0", BF_UTILS_ALGO_NAME_LEN);
176 strncpy(crc_name,
"CRC_64\0", BF_UTILS_ALGO_NAME_LEN);
179 strncpy(crc_name,
"CRC_64_GO_ISO\0", BF_UTILS_ALGO_NAME_LEN);
182 strncpy(crc_name,
"CRC_64_WE\0", BF_UTILS_ALGO_NAME_LEN);
185 strncpy(crc_name,
"CRC_64_JONES\0", BF_UTILS_ALGO_NAME_LEN);
189 strncpy(crc_name,
"CRC_INVALID\0", BF_UTILS_ALGO_NAME_LEN);
195static inline bfn_crc_alg_t crc_alg_str_to_type(
const char *crc_name) {
196 if (crc_name == NULL) {
199 if (!strcmp(crc_name,
"crc_8") || !strcmp(crc_name,
"CRC_8")) {
202 if (!strcmp(crc_name,
"crc_8_darc") || !strcmp(crc_name,
"CRC_8_DARC")) {
205 if (!strcmp(crc_name,
"crc_8_i_code") || !strcmp(crc_name,
"CRC_8_I_CODE")) {
208 if (!strcmp(crc_name,
"crc_8_itu") || !strcmp(crc_name,
"CRC_8_ITU")) {
211 if (!strcmp(crc_name,
"crc_8_maxim") || !strcmp(crc_name,
"CRC_8_MAXIM")) {
214 if (!strcmp(crc_name,
"crc_8_rohc") || !strcmp(crc_name,
"CRC_8_ROHC")) {
217 if (!strcmp(crc_name,
"crc_8_wcdma") || !strcmp(crc_name,
"CRC_8_WCDMA")) {
220 if (!strcmp(crc_name,
"crc_16") || !strcmp(crc_name,
"CRC_16")) {
223 if (!strcmp(crc_name,
"crc_16_bypass") || !strcmp(crc_name,
"CRC_16_BYPASS")) {
224 return CRC_16_BYPASS;
226 if (!strcmp(crc_name,
"crc_16_dds_110") || !strcmp(crc_name,
"CRC_16_DDS_110")) {
227 return CRC_16_DDS_110;
229 if (!strcmp(crc_name,
"crc_16_dect") || !strcmp(crc_name,
"CRC_16_DECT")) {
232 if (!strcmp(crc_name,
"crc_16_dect_r") || !strcmp(crc_name,
"CRC_16_DECT_R")) {
233 return CRC_16_DECT_R;
235 if (!strcmp(crc_name,
"crc_16_dect_x") || !strcmp(crc_name,
"CRC_16_DECT_X")) {
236 return CRC_16_DECT_X;
238 if (!strcmp(crc_name,
"crc_16_dnp") || !strcmp(crc_name,
"CRC_16_DNP")) {
241 if (!strcmp(crc_name,
"crc_16_en_13757") || !strcmp(crc_name,
"CRC_16_EN_13757")) {
242 return CRC_16_EN_13757;
244 if (!strcmp(crc_name,
"crc_16_genibus") || !strcmp(crc_name,
"CRC_16_GENIBUS")) {
245 return CRC_16_GENIBUS;
247 if (!strcmp(crc_name,
"crc_16_maxim") || !strcmp(crc_name,
"CRC_16_MAXIM")) {
250 if (!strcmp(crc_name,
"crc_16_mcrf4xx") || !strcmp(crc_name,
"CRC_16_MCRF4XX")) {
251 return CRC_16_MCRF4XX;
253 if (!strcmp(crc_name,
"crc_16_riello") || !strcmp(crc_name,
"CRC_16_RIELLO")) {
254 return CRC_16_RIELLO;
256 if (!strcmp(crc_name,
"crc_16_t10_dif") || !strcmp(crc_name,
"CRC_16_T10_DIF")) {
257 return CRC_16_T10_DIF;
259 if (!strcmp(crc_name,
"crc_16_teledisk") || !strcmp(crc_name,
"CRC_16_TELEDISK")) {
260 return CRC_16_TELEDISK;
262 if (!strcmp(crc_name,
"crc_16_usb") || !strcmp(crc_name,
"CRC_16_USB")) {
265 if (!strcmp(crc_name,
"x_25") || !strcmp(crc_name,
"X_25")) {
268 if (!strcmp(crc_name,
"xmodem") || !strcmp(crc_name,
"XMODEM")) {
271 if (!strcmp(crc_name,
"modbus") || !strcmp(crc_name,
"MODBUS")) {
274 if (!strcmp(crc_name,
"kermit") || !strcmp(crc_name,
"KERMIT")) {
277 if (!strcmp(crc_name,
"crc_ccitt_false") || !strcmp(crc_name,
"CRC_CCITT_FALSE")) {
278 return CRC_CCITT_FALSE;
280 if (!strcmp(crc_name,
"crc_aug_ccitt") || !strcmp(crc_name,
"CRC_AUG_CCITT")) {
281 return CRC_AUG_CCITT;
283 if (!strcmp(crc_name,
"crc_32") || !strcmp(crc_name,
"CRC_32")) {
286 if (!strcmp(crc_name,
"crc_32_bzip2") || !strcmp(crc_name,
"CRC_32_BZIP2")) {
289 if (!strcmp(crc_name,
"crc_32c") || !strcmp(crc_name,
"CRC_32C")) {
292 if (!strcmp(crc_name,
"crc_32d") || !strcmp(crc_name,
"CRC_32D")) {
295 if (!strcmp(crc_name,
"crc_32_mpeg") || !strcmp(crc_name,
"CRC_32_MPEG")) {
298 if (!strcmp(crc_name,
"posix") || !strcmp(crc_name,
"POSIX")) {
301 if (!strcmp(crc_name,
"crc_32q") || !strcmp(crc_name,
"CRC_32Q")) {
304 if (!strcmp(crc_name,
"jamcrc") || !strcmp(crc_name,
"JAMCRC")) {
307 if (!strcmp(crc_name,
"xfer") || !strcmp(crc_name,
"XFER")) {
310 if (!strcmp(crc_name,
"crc_64") || !strcmp(crc_name,
"CRC_64")) {
313 if (!strcmp(crc_name,
"crc_64_go_iso") || !strcmp(crc_name,
"CRC_64_GO_ISO")) {
314 return CRC_64_GO_ISO;
316 if (!strcmp(crc_name,
"crc_64_we") || !strcmp(crc_name,
"CRC_64_WE")) {
319 if (!strcmp(crc_name,
"crc_64_jones") || !strcmp(crc_name,
"CRC_64_JONES")) {
325static inline void hash_alg_type_to_str(bfn_hash_alg_type_t alg_type,
char *alg_name) {
326 if (alg_name == NULL) {
331 strncpy(alg_name,
"IDENTITY\0", BF_UTILS_ALGO_NAME_LEN);
334 strncpy(alg_name,
"CRC\0", BF_UTILS_ALGO_NAME_LEN);
337 strncpy(alg_name,
"RANDOM\0", BF_UTILS_ALGO_NAME_LEN);
340 strncpy(alg_name,
"XOR\0", BF_UTILS_ALGO_NAME_LEN);
344 strncpy(alg_name,
"INVALID\0", BF_UTILS_ALGO_NAME_LEN);
350static inline bfn_hash_alg_type_t hash_alg_str_to_type(
const char *alg_name) {
351 if (alg_name == NULL) {
354 if (!strcmp(alg_name,
"identity") || !strcmp(alg_name,
"IDENTITY")) {
357 if (!strcmp(alg_name,
"crc") || !strcmp(alg_name,
"CRC")) {
360 if (!strcmp(alg_name,
"random") || !strcmp(alg_name,
"RANDOM")) {
363 if (!strcmp(alg_name,
"xor") || !strcmp(alg_name,
"XOR")) {
374 const char *crc_name;
382 bfn_hash_alg_type_t hash_alg;
388 bfn_crc_alg_t crc_type;
394 uint8_t **crc_matrix;
395} bfn_hash_algorithm_t;
402bool verify_algorithm(bfn_hash_algorithm_t *alg,
const char **error_message);
414void initialize_algorithm(bfn_hash_algorithm_t *alg, bfn_hash_alg_type_t hash_alg_type,
bool msb,
415 bool extend, bfn_crc_alg_t crc_alg);
417void initialize_crc_matrix(bfn_hash_algorithm_t *alg);
419void calculate_crc(bfn_hash_algorithm_t *alg, uint32_t hash_output_bits, uint8_t *stream,
420 uint32_t stream_len, uint8_t *crc);
Definition bfn_hash_algorithm.h:381
Definition bfn_hash_algorithm.h:373