/* * Verify that hash functions return what they are expected to return * (using precalculated values stored above) */ static int verify_precalculated_hash_func_tests(void) { unsigned i, j; uint8_t key[64]; uint32_t hash; for (i = 0; i < 64; i++) key[i] = (uint8_t) i; for (i = 0; i < sizeof(hashtest_key_lens) / sizeof(uint32_t); i++) { for (j = 0; j < sizeof(hashtest_initvals) / sizeof(uint32_t); j++) { hash = rte_jhash(key, hashtest_key_lens[i], hashtest_initvals[j]); if (hash != hash_values_jhash[j][i]) { printf("jhash for %u bytes with initial value 0x%x." "Expected 0x%x, but got 0x%x\n", hashtest_key_lens[i], hashtest_initvals[j], hash_values_jhash[j][i], hash); return -1; } hash = rte_hash_crc(key, hashtest_key_lens[i], hashtest_initvals[j]); if (hash != hash_values_crc[j][i]) { printf("CRC for %u bytes with initial value 0x%x." "Expected 0x%x, but got 0x%x\n", hashtest_key_lens[i], hashtest_initvals[j], hash_values_crc[j][i], hash); return -1; } } } return 0; }
// Make rte_hash_crc available to Rust. This adds some cost, will look into producing a pure Rust version. uint32_t crc_hash_native(const void* data, uint32_t len, uint32_t initial) { return rte_hash_crc(data, len, initial); }