Skip to content

File dp_hash64.h

FileList > doppler > dp_hash64.h

Go to the source code of this file

FNV-1a 64 over bytes, incrementally: the one content hash in doppler. More...

  • #include <stddef.h>
  • #include <stdint.h>

Public Static Functions

Type Name
uint64_t dp_hash64 (uint64_t h, const void * data, size_t n)
Continue an FNV-1a 64 hash over n more bytes.

Macros

Type Name
define DP_HASH64_INIT UINT64\_C (0xcbf29ce484222325)
The FNV-1a 64 offset basis: the hash of no bytes, and where a hash starts.
define DP_HASH64_PRIME UINT64\_C (0x100000001b3)
The FNV-1a 64 prime.

Detailed Description

It identifies content and does not protect it. A record names a --data-from-file source by its path, its length in bits and this hash, and a replay refuses a file whose hash differs (docs/design/payload-data-source.md ยง4.8). A path alone replays whatever the file holds on the day, and a length alone misses an edit of the same size.

FNV-1a rather than xxHash64 because identity needs no speed: the hash runs at the rate a file is read, and a file is read at the rate frames are sent. FNV-1a is a few lines, works a byte at a time and so is incremental by construction, and has published test vectors. Not for anything an adversary chooses: a collision can be constructed.

Header-only, for the reason dp_crc16.h gives: no component grows a link-line dependency for a few lines of arithmetic.

Public Static Functions Documentation

function dp_hash64

Continue an FNV-1a 64 hash over n more bytes.

static inline uint64_t dp_hash64 (
    uint64_t h,
    const void * data,
    size_t n
) 

Pass DP_HASH64_INIT to start, then feed each block as it is read, passing back what the last call returned. The result does not depend on where the input was split, so a file hashed read by read gives the same value as the whole file hashed at once, and is never read twice. The state is the returned uint64_t itself, so a source that serializes its state carries the hash by value.

Parameters:

  • h the hash so far; DP_HASH64_INIT for none.
  • data the next bytes; may be NULL when n is 0.
  • n how many.

Returns:

the hash over everything fed so far.

uint64_t h = DP_HASH64_INIT;
h = dp_hash64 (h, "foo", 3);
h = dp_hash64 (h, "bar", 3);   // 0x85944171f73967e8, as for "foobar"

Macro Definition Documentation

define DP_HASH64_INIT

The FNV-1a 64 offset basis: the hash of no bytes, and where a hash starts.

#define DP_HASH64_INIT `UINT64_C (0xcbf29ce484222325)`


define DP_HASH64_PRIME

The FNV-1a 64 prime.

#define DP_HASH64_PRIME `UINT64_C (0x100000001b3)`



The documentation for this class was generated from the following file native/inc/doppler/dp_hash64.h