skip to content
==> include/mesh/abi/fnv.h <==
1/* @ajax/mesh-abi-fnv: FNV-1a 64, the hash of program images in the mesh contract.
2 *
3 * Part of alpha-c-mesh, a C port of alpha-rust-mesh (README.md says from where). */
4#ifndef MESH_ABI_FNV_H
5#define MESH_ABI_FNV_H
6
7#include <stdbool.h>
8#include <stddef.h>
9#include <stdint.h>
10
11/* FNV-1a 64: the PTX hash in the table, `programs` and F_HELLO / F_LOAD. */
12static inline uint64_t mesh_fnv1a64(const uint8_t *b, size_t n) {
13    uint64_t h = UINT64_C(0xcbf29ce484222325);
14    for (size_t i = 0; i < n; i++) {
15        h ^= b[i];
16        h *= UINT64_C(0x100000001b3);
17    }
18    return h;
19}
20
21#endif