AP_Math: add method for generating hash

This commit is contained in:
Siddharth Purohit 2019-10-06 11:06:19 +05:30 committed by Andrew Tridgell
parent 2b410479af
commit fb48d8ee1b
2 changed files with 15 additions and 0 deletions

View File

@ -255,3 +255,14 @@ uint16_t calc_crc_modbus(uint8_t *buf, uint16_t len)
}
return crc;
}
// FNV-1a implementation
#define FNV_1_PRIME_64 1099511628211UL
void hash_fnv_1a(uint32_t len, const uint8_t* buf, uint64_t* hash)
{
uint32_t i;
for (i=0; i<len; i++) {
*hash ^= (uint64_t)buf[i];
*hash *= FNV_1_PRIME_64;
}
}

View File

@ -29,3 +29,7 @@ uint16_t crc16_ccitt(const uint8_t *buf, uint32_t len, uint16_t crc);
uint16_t calc_crc_modbus(uint8_t *buf, uint16_t len);
// generate 64bit FNV1a hash from buffer
#define FNV_1_OFFSET_BASIS_64 14695981039346656037UL
void hash_fnv_1a(uint32_t len, const uint8_t* buf, uint64_t* hash);