fnv1_common.hHeader

This file provides the implementation of the core constants and utility functions used in the FNV-1 and FNV-1a hashing algorithms. More...

Detailed Description

The FNV (Fowler-Noll-Vo) hash functions are a family of non-cryptographic hash functions created by Glenn Fowler, Landon Curt Noll, and Kiem-Phong Vo. The FNV hash functions are designed to be fast while maintaining a low collision rate. This file specifically defines the seed values and multiplicators for both 32-bit and 64-bit platforms, which are essential for the hash computations in FNV-1 and FNV-1a algorithms.

Key Features:

  • Platform-Specific Constants : Provides different constants for 32-bit and 64-bit platforms, ensuring optimal performance and compatibility.

  • Compile-Time Functions : Uses constexpr functions to allow for compile-time computation of seeds and multiplicators, enhancing performance and security.

  • Template Specializations : Utilizes template specialization to automatically select the appropriate constants based on the platform's size_t size.

Usage Scenarios:

This file is used internally by the fnv1 and fnv1a classes within the antispy SDK library to provide the necessary constants for hash computation. It is not intended for direct use by end-users, but rather as a foundational component that other hashing utilities build upon.

Example Usage:

Although this file is primarily intended for internal use, an example of how the constants are used in FNV-1a hash computation is as follows:

#include <antispy/libantispy.h>

int main() {
   // Example of FNV-1a hash computation using constants from fnv1_common.hpp
   constexpr size_t seed = libantispy::detail::fnv_seed<sizeof(size_t)>();
   constexpr size_t multiplicator = libantispy::detail::fnv_multiplicator<sizeof(size_t)>();
   size_t hash = seed;
   const char* data = "example";
   for (size_t i = 0; i < strlen(data); ++i) {
      hash ^= static_cast<size_t>(data[i]);
      hash *= multiplicator;
   }
}

This example demonstrates how the seed and multiplicator constants are used in an FNV-1a hash computation loop.