CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
Hash.h
Go to the documentation of this file.
1
5
6#pragma once
7#include <cstddef>
8#include <cstdint>
9
10namespace cdc {
11namespace core {
12namespace hash {
13
20static constexpr uint32_t FNV1A_32_OFFSET_BASIS = 0x811C9DC5u; // 2166136261
21static constexpr uint32_t FNV1A_32_PRIME = 0x01000193u; // 16777619
22
28inline void fnv1a_mix_byte(uint32_t& hash, uint8_t value) {
29 hash ^= value;
31}
32
41inline void fnv1a_mix_u32(uint32_t& hash, uint32_t value) {
42 hash ^= value;
44}
45
52inline uint32_t fnv1a_32(const uint8_t* data, size_t len) {
53 uint32_t hash = FNV1A_32_OFFSET_BASIS;
54 for (size_t i = 0; i < len; i++) {
55 fnv1a_mix_byte(hash, data[i]);
56 }
57 return hash;
58}
59
60} // namespace hash
61} // namespace core
62} // namespace cdc
63
static constexpr uint32_t FNV1A_32_OFFSET_BASIS
FNV-1a 32-bit constants (Fowler/Noll/Vo).
Definition Hash.h:20
void fnv1a_mix_byte(uint32_t &hash, uint8_t value)
Mixes a single value into a running FNV-1a 32-bit hash.
Definition Hash.h:28
void fnv1a_mix_u32(uint32_t &hash, uint32_t value)
Mixes a 32-bit word into a running FNV-1a 32-bit hash.
Definition Hash.h:41
uint32_t fnv1a_32(const uint8_t *data, size_t len)
Computes FNV-1a 32-bit hash over a byte buffer.
Definition Hash.h:52
static constexpr uint32_t FNV1A_32_PRIME
Definition Hash.h:21