Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_Hash.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Oct 30, 2019
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7#pragma once
8
9#include <cstddef>
10#include <cstdint>
11
42uint32_t Fletcher(const uint8_t* const data, const size_t len, uint32_t previousFletcherHash = 0);
43
53inline uint16_t Djb2(const uint8_t* data, const uint16_t size) {
54 uint16_t hash = 5381;
55 for (int i = 0; i < size; ++i) {
56 hash = ((hash << 5) + hash) + data[i];
57 }
58 return hash;
59}
uint16_t Djb2(const uint8_t *data, const uint16_t size)
Calculates a djb2 hash of given data.
Definition: cs_Hash.h:53
uint32_t Fletcher(const uint8_t *const data, const size_t len, uint32_t previousFletcherHash=0)
Computes a Fletcher32 hash for the given data, interpreting it as a stream of little endian uint16_t.