fnv1a.hHeader
This file provides the implementation of the FNV-1a (Fowler-Noll-Vo) hashing algorithm, which is widely used for fast and effective hash computation in various applications. More...
Defines
Type | Name |
---|---|
ANTISPY_FNV1A | |
ANTISPY_FNV1A_RT |
Detailed Description
The FNV-1a hash function is a non-cryptographic hash algorithm known for its simplicity and speed, making it ideal for use in hash tables, data integrity checks, and other scenarios where quick and reliable hashing is required. This file includes the fnv1a
class template, which supports both compile-time and runtime hash computation, providing flexibility for different use cases.
Key Features:
FNV-1a Hash Algorithm : Implements the FNV-1a variant of the Fowler-Noll-Vo hash function, known for its good distribution properties and efficiency.
Compile-Time and Runtime Hashing : Supports both compile-time hash computation for constant expressions and runtime computation for dynamic data.
Type-Generic : The class template can handle various data types, making it versatile for different applications.
Security Considerations : The implementation includes mechanisms for structural randomization and secure storage of hash values.
Usage Scenarios:
The FNV-1a hash function is commonly used in:
Hash Tables : For generating hash codes for keys in hash maps or hash sets.
Data Integrity : For creating checksums that verify the integrity of data.
Unique Identifiers : For generating deterministic and unique identifiers for objects.
Example Usage:
Compile-Time Hashing:
int
Runtime Hashing:
int
This file is intended for use within the antispy SDK
library, ensuring consistent and efficient hash computation across the project.
Defines
ANTISPY_FNV1A
Macro to create an fnv1a
hash object for a given input.
Detailed Description
The ANTISPY_FNV1A
macro is designed to simplify the creation of an fnv1a
hash object. It automatically deduces the type of the input parameter and constructs an fnv1a
object with the appropriate type, which is used to compute a secure FNV-1a hash value.
Parameters
t
: The input value to be hashed. This can be a string, array, or any other object that is compatible with the FNV-1a hash algorithm.
Example Usage:
int
In this example, the ANTISPY_FNV1A
macro deduces the type of the input string "example" and creates an fnv1a
object, which computes the FNV-1a hash value of the string.
Implementation Details:
The macro uses the following type transformations:
std::remove_reference<decltype(t)>::type
: Removes any reference from the type oft
.std::remove_const<...>
: Removes anyconst
qualifier from the type.std::remove_all_extents<...>
: Removes any array extents from the type, making it suitable for hashing.
After performing these transformations, the macro creates an fnv1a
object with the resulting type and passes the input t
to it for hashing.
This macro is intended for use in scenarios where the type of t
may not be known in advance, and automatic type deduction is required to create the appropriate fnv1a
object.
ANTISPY_FNV1A_RT
Macro to create an fnv1a
hash object for a given runtime input.
Detailed Description
The ANTISPY_FNV1A_RT
macro is designed to simplify the creation of an fnv1a
hash object when the input and its size are determined at runtime. It automatically deduces the type of the input parameter and constructs an fnv1a
object with the appropriate type, which is used to compute a secure FNV-1a hash value.
Parameters
t
: The input value to be hashed. This can be a runtime-determined string, array, or any other object that is compatible with the FNV-1a hash algorithm.N
: The size of the input. This represents the number of elements in the input array or the length of the input string.
Example Usage:
int
In this example, the ANTISPY_FNV1A_RT
macro deduces the type of the runtime string runtime_string
and creates an fnv1a
object, which computes the FNV-1a hash value of the string with the given length.
Implementation Details:
The macro uses the following type transformations:
std::remove_reference<decltype(t)>::type
: Removes any reference from the type oft
.std::remove_const<...>
: Removes anyconst
qualifier from the type.std::remove_all_extents<...>
: Removes any array extents from the type, making it suitable for hashing.
After performing these transformations, the macro creates an fnv1a
object with the resulting type and passes the input t
and its size N
to it for hashing.
This macro is intended for use in scenarios where the input and its size are determined at runtime, and automatic type deduction is required to create the appropriate fnv1a
object.