core/hash/xxhash
xxhash
Types
20Alignment
Alignment :: enum int {
Aligned = 0,
Unaligned = 1,
}SourceError
Error :: enum int {
None = 0,
Error = 1,
}SourceXXH128_canonical
XXH128_canonical :: struct {
digest: [size_of(XXH128_hash_t)]u8,
}SourceXXH128_hash_t
XXH128_hash_t :: struct #raw_union {
raw: struct {
low: XXH64_hash,
high: XXH64_hash,
},
h: xxh_u128,
}SourceXXH32_canonical
XXH32_canonical :: struct {
digest: [4]u8,
}SourceXXH32_hash
XXH32_hash :: u32Source32-bit hash functions
XXH32_state
XXH32_state :: struct {
total_len_32: XXH32_hash,
large_len: XXH32_hash,
v1: XXH32_hash,
v2: XXH32_hash,
v3: XXH32_hash,
v4: XXH32_hash,
mem32: [4]XXH32_hash,
memsize: XXH32_hash,
reserved: XXH32_hash,
}SourceXXH3_128_hash
XXH3_128_hash :: u128SourceXXH3_accumulate_512_f
XXH3_accumulate_512_f :: proc(acc: []xxh_u64, input: []u8, secret: []u8)SourceXXH3_accumulate_512 is the tightest loop for long inputs, and it is the most optimized. *
- It is a hardened version of UMAC, based off of FARSH's implementation.
*
- This was chosen because it adapts quite well to 32-bit, 64-bit, and SIMD
- implementations, and it is ridiculously fast.
*
- We harden it by mixing the original input to the accumulators as well as the product.
*
- This means that in the (relatively likely) case of a multiply by zero, the
- original input is preserved.
*
- On 128-bit inputs, we swap 64-bit pairs when we add the input to improve
- cross-pollination, as otherwise the upper and lower halves would be
- essentially independent.
*
- This doesn't matter on 64-bit hashes since they all get merged together in
- the end, so we skip the extra step.
*
- Both XXH3_64bits and XXH3_128bits use this subroutine.
XXH3_hashLong128_f
XXH3_hashLong128_f :: proc(input: []u8, seed: xxh_u64, secret: []u8) -> (res: XXH3_128_hash)SourceXXH3_hashLong64_f
XXH3_hashLong64_f :: proc(input: []u8, seed: xxh_u64, secret: []u8) -> (res: xxh_u64)SourceXXH3_init_custom_secret_f
XXH3_init_custom_secret_f :: proc(custom_secret: []u8, seed64: xxh_u64)SourceXXH3_scramble_accumulator_f
XXH3_scramble_accumulator_f :: proc(acc: []xxh_u64, secret: []u8)SourceXXH3_state
XXH3_state :: struct {
acc: [8]u64,
custom_secret: [XXH_SECRET_DEFAULT_SIZE]u8,
buffer: [256]u8,
buffered_size: u32,
reserved32: u32,
stripes_so_far: uint,
total_length: u64,
stripes_per_block: uint,
secret_limit: uint,
seed: u64,
reserved64: u64,
external_secret: []u8,
}SourceStreaming state.
IMPORTANT: This structure has a strict alignment requirement of 64 bytes!! **
Default allocators will align it correctly if created via `new`, as will
placing this struct on the stack, but if using a custom allocator make sure
that it handles the alignment correctly!XXH64_canonical
XXH64_canonical :: struct {
digest: [8]u8,
}SourceXXH64_hash
XXH64_hash :: u64Source64-bit hash functions
XXH64_state
XXH64_state :: struct {
total_len: XXH64_hash,
v1: XXH64_hash,
v2: XXH64_hash,
v3: XXH64_hash,
v4: XXH64_hash,
mem64: [4]XXH64_hash,
memsize: XXH32_hash,
reserved32: XXH32_hash,
reserved64: XXH64_hash,
}Sourcexxh_u128
xxh_u128 :: u128Source** XXH3 128-bit variant ** Stored in little endian order, although the fields themselves are in native endianness.
xxh_u32
xxh_u32 :: u32Sourcexxh_u64
xxh_u64 :: u64SourceConstants
37XXH32_DEFAULT_SEED
XXH32_DEFAULT_SEED :: u32 = XXH32_hash(0)SourceXXH3_INIT_ACC
XXH3_INIT_ACC :: [XXH_ACC_NB]xxh_u64SourceXXH3_INTERNAL_BUFFER_SIZE
XXH3_INTERNAL_BUFFER_SIZE :: 256SourceThis is the optimal update size for incremental hashing.
XXH3_MIDSIZE_LASTOFFSET
XXH3_MIDSIZE_LASTOFFSET :: 17SourceXXH3_MIDSIZE_MAX
XXH3_MIDSIZE_MAX :: 240SourceXXH3_MIDSIZE_STARTOFFSET
XXH3_MIDSIZE_STARTOFFSET :: 3SourceXXH3_SECRET_SIZE_MIN
XXH3_SECRET_SIZE_MIN :: 136SourceDo not change this constant.
XXH64_DEFAULT_SEED
XXH64_DEFAULT_SEED :: u64 = XXH64_hash(0)SourceXXH_ACC_ALIGN
XXH_ACC_ALIGN :: 8SourceXXH_ACC_NB
XXH_ACC_NB :: (XXH_STRIPE_LEN / size_of(xxh_u64))SourceXXH_DISABLE_PREFETCH
XXH_DISABLE_PREFETCH :: _ = #config(XXH_DISABLE_PREFETCH, true)SourceXXH_FORCE_ALIGN_CHECK
XXH_FORCE_ALIGN_CHECK :: _ = #config(XXH_FORCE_ALIGN_CHECK, false)Sourcefalse - Use this on platforms where unaligned reads are fast
`true` - Use this on platforms where unaligned reads are slowXXH_FORCE_MEMORY_ACCESS
XXH_FORCE_MEMORY_ACCESS :: #config(XXH_FORCE_MEMORY_ACCESS, 2)Source0 - Use memcopy, for platforms where unaligned reads are a problem
2 - Direct cast, for platforms where unaligned are allowed (default)XXH_MAX_WIDTH
XXH_MAX_WIDTH :: _ = #config(XXH_MAX_WIDTH, 512) / 64SourceXXH_NATIVE_WIDTH
XXH_NATIVE_WIDTH :: _ = min(XXH_MAX_WIDTH,
8 when intrinsics.has_target_feature(AVX512_FEATURES) else
4 when intrinsics.has_target_feature(AVX2_FEATURES) else
2 when intrinsics.has_target_feature(SSE2_FEATURES) else 1)SourceXXH_PREFETCH_DIST
XXH_PREFETCH_DIST :: 320SourceXXH_PRIME32_1
XXH_PRIME32_1 :: 0x9E3779B1SourceXXH_PRIME32_2
XXH_PRIME32_2 :: 0x85EBCA77SourceXXH_PRIME32_3
XXH_PRIME32_3 :: 0xC2B2AE3DSourceXXH_PRIME32_4
XXH_PRIME32_4 :: 0x27D4EB2FSourceXXH_PRIME32_5
XXH_PRIME32_5 :: 0x165667B1SourceXXH_PRIME64_1
XXH_PRIME64_1 :: 0x9E3779B185EBCA87SourceXXH_PRIME64_2
XXH_PRIME64_2 :: 0xC2B2AE3D27D4EB4FSourceXXH_PRIME64_3
XXH_PRIME64_3 :: 0x165667B19E3779F9SourceXXH_PRIME64_4
XXH_PRIME64_4 :: 0x85EBCA77C2B2AE63SourceXXH_PRIME64_5
XXH_PRIME64_5 :: 0x27D4EB2F165667C5SourceXXH_SECRET_CONSUME_RATE
XXH_SECRET_CONSUME_RATE :: 8SourceXXH_SECRET_DEFAULT_SIZE
XXH_SECRET_DEFAULT_SIZE :: max(XXH3_SECRET_SIZE_MIN, #config(XXH_SECRET_DEFAULT_SIZE, 192))SourceXXH3 New generation hash designed for speed on small keys and vectorization One goal of XXH3 is to make it fast on both 32-bit and 64-bit, while remaining a true 64-bit/128-bit hash function. ========================================== XXH3 default settings ========================================== Custom secrets have a default length of 192, but can be set to a different size.
The minimum secret size is 136 bytes. It must also be a multiple of 64.XXH_SECRET_LASTACC_START
XXH_SECRET_LASTACC_START :: 7SourceXXH_SECRET_MERGEACCS_START
XXH_SECRET_MERGEACCS_START :: 11SourceXXH_STRIPE_LEN
XXH_STRIPE_LEN :: 64Source======= Long Keys =======
XXH_VERSION_MAJOR
XXH_VERSION_MAJOR :: 0SourceVersion definition
XXH_VERSION_MINOR
XXH_VERSION_MINOR :: 8SourceXXH_VERSION_NUMBER
XXH_VERSION_NUMBER :: XXH_VERSION_MAJOR * 100 * 100 + XXH_VERSION_MINOR * 100 + XXH_VERSION_RELEASESourceXXH_VERSION_RELEASE
XXH_VERSION_RELEASE :: 1Sourcebyte_swap
byte_swap :: intrinsics.byte_swapSourcemem_copy
mem_copy :: runtime.mem_copySourceVariables
1XXH3_kSecret
XXH3_kSecret :: [XXH_SECRET_DEFAULT_SIZE]u8 = [XXH_SECRET_DEFAULT_SIZE]u8{
0xb8, 0xfe, 0x6c, 0x39, 0x23, 0xa4, 0x4b, 0xbe, 0x7c, 0x01, 0x81, 0x2c, 0xf7, 0x21, 0xad, 0x1c,
0xde, 0xd4, 0x6d, 0xe9, 0x83, 0x90, 0x97, 0xdb, 0x72, 0x40, 0xa4, 0xa4, 0xb7, 0xb3, 0x67, 0x1f,
0xcb, 0x79, 0xe6, 0x4e, 0xcc, 0xSourceProcedures
104XXH128_mix32B
XXH128_mix32B :: proc(acc: xxh_u128, input_1: []u8, input_2: []u8, secret: []u8, seed: xxh_u64) -> (res: xxh_u128)SourceA bit slower than XXH3_mix16B, but handles multiply by zero better.
XXH32
XXH32 :: proc(input: []u8, seed = XXH32_DEFAULT_SEED) -> (digest: XXH32_hash)SourceXXH32_avalanche
XXH32_avalanche :: proc(h32: u32) -> (res: u32)SourceMix all bits
XXH32_canonical_from_hash
XXH32_canonical_from_hash :: proc(hash: XXH32_hash) -> (canonical: XXH32_canonical)SourceCanonical representation
The default return values from XXH functions are unsigned 32 and 64 bit integers.
The canonical representation uses big endian convention,
the same convention as human-readable numbers (large digits first).
This way, hash values can be written into a file or buffer, remaining
comparable across different systems.
The following functions allow transformation of hash values to and from their
canonical format.XXH32_copy_state
XXH32_copy_state :: proc(dest: ^XXH32_state, src: ^XXH32_state)SourceXXH32_create_state
XXH32_create_state :: proc(allocator: mem.Allocator = context.allocator) -> (res: ^XXH32_state, err: Error)SourceHash streaming
XXH32_destroy_state
XXH32_destroy_state :: proc(state: ^XXH32_state, allocator: mem.Allocator = context.allocator) -> (err: Error)SourceXXH32_digest
XXH32_digest :: proc(state: ^XXH32_state) -> (res: XXH32_hash)SourceXXH32_endian_align
XXH32_endian_align :: proc(input: []u8, seed = XXH32_DEFAULT_SEED, alignment: Alignment) -> (res: XXH32_hash)SourceXXH32_finalize
XXH32_finalize :: proc(h32: u32, buf: []u8, alignment: Alignment) -> (res: u32)SourceXXH32_hash_from_canonical
XXH32_hash_from_canonical :: proc(canonical: ^XXH32_canonical) -> (hash: XXH32_hash)SourceXXH32_read32
XXH32_read32 :: proc(buf: []u8, alignment = Alignment.Unaligned) -> (res: u32)SourceXXH32_reset_state
XXH32_reset_state :: proc(state_ptr: ^XXH32_state, seed = XXH32_DEFAULT_SEED) -> (err: Error)SourceXXH32_round
XXH32_round :: proc(seed: XXH32_hash, input: XXH32_hash) -> (res: XXH32_hash)SourceXXH32_update
XXH32_update :: proc(state: ^XXH32_state, input: []u8) -> (err: Error)SourceXXH3_128_canonical_from_hash
XXH3_128_canonical_from_hash :: proc(hash: XXH128_hash_t) -> (canonical: XXH128_canonical)Source====== Canonical representation ======
XXH3_128_default
XXH3_128_default :: proc(input: []u8) -> (hash: XXH3_128_hash)Source=== Public XXH128 API ===
XXH3_128_digest
XXH3_128_digest :: proc(state: ^XXH3_state) -> (hash: XXH3_128_hash)SourceXXH3_128_hash_from_canonical
XXH3_128_hash_from_canonical :: proc(src: ^XXH128_canonical) -> (hash: u128)SourceXXH3_128_reset
XXH3_128_reset :: proc(state: ^XXH3_state) -> (err: Error)Source=== XXH3 128-bit streaming ===
All the functions are actually the same as for 64-bit streaming variant.
The only difference is the finalization routine.XXH3_128_reset_with_secret
XXH3_128_reset_with_secret :: proc(state: ^XXH3_state, secret: []u8) -> (err: Error)SourceXXH3_128_reset_with_seed
XXH3_128_reset_with_seed :: proc(state: ^XXH3_state, seed: XXH64_hash) -> (err: Error)SourceXXH3_128_update
XXH3_128_update :: proc(state: ^XXH3_state, input: []u8) -> (err: Error)SourceXXH3_128_with_secret
XXH3_128_with_secret :: proc(input: []u8, secret: []u8) -> (hash: XXH3_128_hash)SourceXXH3_128_with_seed
XXH3_128_with_seed :: proc(input: []u8, seed: xxh_u64) -> (hash: XXH3_128_hash)SourceXXH3_128bits_internal
XXH3_128bits_internal :: proc(input: []u8, seed: xxh_u64, secret: []u8, f_hl128: XXH3_hashLong128_f) -> (res: XXH3_128_hash)SourceXXH3_64_default
XXH3_64_default :: proc(input: []u8) -> (hash: xxh_u64)Source=== Public entry point ===
XXH3_64_digest
XXH3_64_digest :: proc(state: ^XXH3_state) -> (hash: XXH64_hash)SourceXXH3_64_reset
XXH3_64_reset :: proc(state: ^XXH3_state) -> (err: Error)SourceXXH3_64_reset_with_secret
XXH3_64_reset_with_secret :: proc(state: ^XXH3_state, secret: []u8) -> (err: Error)SourceXXH3_64_reset_with_seed
XXH3_64_reset_with_seed :: proc(state: ^XXH3_state, seed: XXH64_hash) -> (err: Error)SourceXXH3_64_update
XXH3_64_update :: proc(state: ^XXH3_state, input: []u8) -> (err: Error)SourceXXH3_64_with_secret
XXH3_64_with_secret :: proc(input: []u8, secret: []u8) -> (hash: xxh_u64)SourceXXH3_64_with_seed
XXH3_64_with_seed :: proc(input: []u8, seed: xxh_u64) -> (hash: xxh_u64)SourceXXH3_64bits_internal
XXH3_64bits_internal :: proc(input: []u8, seed: xxh_u64, secret: []u8, f_hashLong: XXH3_hashLong64_f) -> (hash: xxh_u64)SourceXXH3_accumulate
XXH3_accumulate :: proc(acc: []xxh_u64, input: []u8, secret: []u8, nbStripes: uint, f_acc512: XXH3_accumulate_512_f)SourceXXH3_accumulate()
- Loops over XXH3_accumulate_512().
- Assumption: nbStripes will not overflow the secret size
XXH3_accumulate_512
XXH3_accumulate_512 :: proc(acc: []xxh_u64, input: []u8, secret: []u8)SourceXXH3_accumulate_512_scalar
XXH3_accumulate_512_scalar :: proc(acc: []xxh_u64, input: []u8, secret: []u8)Sourcescalar variants - universal
XXH3_accumulate_512_simd_generic
XXH3_accumulate_512_simd_generic :: proc(acc: []xxh_u64, input: []u8, secret: []u8, W: uint)Sourcegeneralized SIMD variants
XXH3_avalanche
XXH3_avalanche :: proc(h64: xxh_u64) -> (res: xxh_u64)SourceThis is a fast avalanche stage, suitable when input bits are already partially mixed
XXH3_consume_stripes
XXH3_consume_stripes :: proc(
acc: []xxh_u64,
stripes_so_far: ^uint,
stripes_per_block: uint,
input: []u8,
number_of_stripes: uint,
secret: []u8,
secret_limit: uint,
f_acc512: XXH3_accumulate_512_f,
f_scramble: XXH3_scramble_accumulator_f,
)SourceNote: when XXH3_consumeStripes() is invoked, there must be a guarantee that at least
one more byte must be consumed from input so that the function can blindly consume
all stripes using the "normal" secret segment.XXH3_copy_state
XXH3_copy_state :: proc(dest: ^XXH3_state, src: ^XXH3_state)SourceXXH3_create_state
XXH3_create_state :: proc(allocator: mem.Allocator = context.allocator) -> (res: ^XXH3_state, err: Error)SourceXXH3_destroy_state
XXH3_destroy_state :: proc(state: ^XXH3_state, allocator: mem.Allocator = context.allocator) -> (err: Error)SourceXXH3_digest_long
XXH3_digest_long :: proc(acc: []u64, state: ^XXH3_state, secret: []u8)SourceXXH3_generate_secret
XXH3_generate_secret :: proc(secret_buffer: []u8, custom_seed: []u8)SourceXXH3_hashLong_128b_default
XXH3_hashLong_128b_default :: proc(input: []u8, seed: xxh_u64, secret: []u8) -> (res: XXH3_128_hash)SourceIt's important for performance that XXH3_hashLong is not inlined.
XXH3_hashLong_128b_internal
XXH3_hashLong_128b_internal :: proc(input: []u8, secret: []u8, f_acc512: XXH3_accumulate_512_f, f_scramble: XXH3_scramble_accumulator_f) -> (res: XXH3_128_hash)SourceXXH3_hashLong_128b_withSecret
XXH3_hashLong_128b_withSecret :: proc(input: []u8, seed: xxh_u64, secret: []u8) -> (res: XXH3_128_hash)SourceIt's important for performance that XXH3_hashLong is not inlined.
XXH3_hashLong_128b_withSeed
XXH3_hashLong_128b_withSeed :: proc(input: []u8, seed: xxh_u64, secret: []u8) -> (res: XXH3_128_hash)SourceIt's important for performance that XXH3_hashLong is not inlined.
XXH3_hashLong_128b_withSeed_internal
XXH3_hashLong_128b_withSeed_internal :: proc(
input: []u8,
seed: xxh_u64,
secret: []u8,
f_acc512: XXH3_accumulate_512_f,
f_scramble: XXH3_scramble_accumulator_f,
f_initSec: XXH3_init_custom_secret_f,
) -> (res: XXH3_128_hash)SourceXXH3_hashLong_64b_default
XXH3_hashLong_64b_default :: proc(input: []u8, seed64: xxh_u64, secret: []u8) -> (hash: xxh_u64)SourceIt's important for performance that XXH3_hashLong is not inlined.
Since the function is not inlined, the compiler may not be able to understand that,
in some scenarios, its `secret` argument is actually a compile time constant.
This variant enforces that the compiler can detect that,
and uses this opportunity to streamline the generated code for better performance.XXH3_hashLong_64b_internal
XXH3_hashLong_64b_internal :: proc(input: []u8, secret: []u8, f_acc512: XXH3_accumulate_512_f, f_scramble: XXH3_scramble_accumulator_f) -> (hash: xxh_u64)SourceXXH3_hashLong_64b_withSecret
XXH3_hashLong_64b_withSecret :: proc(input: []u8, seed64: xxh_u64, secret: []u8) -> (hash: xxh_u64)SourceIt's important for performance that XXH3_hashLong is not inlined.
XXH3_hashLong_64b_withSeed
XXH3_hashLong_64b_withSeed :: proc(input: []u8, seed: xxh_u64, secret: []u8) -> (hash: xxh_u64)SourceXXH3_hashLong_64b_withSeed():
Generate a custom key based on alteration of default XXH3_kSecret with the seed,
and then use this key for long mode hashing.
This operation is decently fast but nonetheless costs a little bit of time.
Try to avoid it whenever possible (typically when seed==0).
It's important for performance that XXH3_hashLong is not inlined. Not sure
why (uop cache maybe?), but the difference is large and easily measurable.XXH3_hashLong_64b_withSeed_internal
XXH3_hashLong_64b_withSeed_internal :: proc(input: []u8, seed: xxh_u64, f_acc512: XXH3_accumulate_512_f, f_scramble: XXH3_scramble_accumulator_f, f_init_sec: XXH3_init_custom_secret_f) -> (hash: xxh_u64)SourceXXH3_hashLong_internal_loop
XXH3_hashLong_internal_loop :: proc(acc: []xxh_u64, input: []u8, secret: []u8, f_acc512: XXH3_accumulate_512_f, f_scramble: XXH3_scramble_accumulator_f)SourceXXH3_init_custom_secret
XXH3_init_custom_secret :: proc(custom_secret: []u8, seed64: xxh_u64)SourceXXH3_init_custom_secret_scalar
XXH3_init_custom_secret_scalar :: proc(custom_secret: []u8, seed64: xxh_u64)SourceXXH3_init_custom_secret_simd_generic
XXH3_init_custom_secret_simd_generic :: proc(custom_secret: []u8, seed64: xxh_u64, W: uint)SourceXXH3_init_state
XXH3_init_state :: proc(state: ^XXH3_state)Source=== XXH3 streaming ===
XXH3_len_0to16_128b
XXH3_len_0to16_128b :: proc(input: []u8, secret: []u8, seed: xxh_u64) -> (res: xxh_u128)SourceAssumption: secret size is >= XXH3_SECRET_SIZE_MIN
XXH3_len_0to16_64b
XXH3_len_0to16_64b :: proc(input: []u8, secret: []u8, seed: xxh_u64) -> (res: xxh_u64)SourceXXH3_len_129to240_128b
XXH3_len_129to240_128b :: proc(input: []u8, secret: []u8, seed: xxh_u64) -> (res: xxh_u128)SourceXXH3_len_129to240_64b
XXH3_len_129to240_64b :: proc(input: []u8, secret: []u8, seed: xxh_u64) -> (res: xxh_u64)SourceXXH3_len_17to128_128b
XXH3_len_17to128_128b :: proc(input: []u8, secret: []u8, seed: xxh_u64) -> (res: xxh_u128)SourceXXH3_len_17to128_64b
XXH3_len_17to128_64b :: proc(input: []u8, secret: []u8, seed: xxh_u64) -> (res: xxh_u64)SourceFor mid range keys, XXH3 uses a Mum-hash variant.
XXH3_len_1to3_128b
XXH3_len_1to3_128b :: proc(input: []u8, secret: []u8, seed: xxh_u64) -> (res: xxh_u128)Source==========================================
XXH3 128 bits (a.k.a XXH128)
==========================================
XXH3's 128-bit variant has better mixing and strength than the 64-bit variant,
even without counting the significantly larger output size.
For example, extra steps are taken to avoid the seed-dependent collisions
in 17-240 byte inputs (See XXH3_mix16B and XXH128_mix32B).
This strength naturally comes at the cost of some speed, especially on short
lengths. Note that longer hashes are about as fast as the 64-bit version
due to it using only a slight modification of the 64-bit loop.
XXH128 is also more oriented towards 64-bit machines. It is still extremely
fast for a _128-bit_ hash on 32-bit (it usually clears XXH64).XXH3_len_1to3_64b
XXH3_len_1to3_64b :: proc(input: []u8, secret: []u8, seed: xxh_u64) -> (res: xxh_u64)Source==========================================
Short keys
==========================================
One of the shortcomings of XXH32 and XXH64 was that their performance was
sub-optimal on short lengths. It used an iterative algorithm which strongly
favored lengths that were a multiple of 4 or 8.
Instead of iterating over individual inputs, we use a set of single shot
functions which piece together a range of lengths and operate in constant time.
Additionally, the number of multiplies has been significantly reduced. This
reduces latency, especially when emulating 64-bit multiplies on 32-bit.
Depending on the platform, this may or may not be faster than XXH32, but it
is almost guaranteed to be faster than XXH64.
At very short lengths, there isn't enough input to fully hide secrets, or use the entire secret.
There is also only a limited amount of mixing we can do before significantly impacting performance.
Therefore, we use different sections of the secret and always mix two secret samples with an XOR.
This should have no effect on performance on the seedless or withSeed variants because everything
_should_ be constant folded by modern compilers.
The XOR mixing hides individual parts of the secret and increases entropy.
This adds an extra layer of strength for custom secrets.XXH3_len_4to8_128b
XXH3_len_4to8_128b :: proc(input: []u8, secret: []u8, seed: xxh_u64) -> (res: xxh_u128)SourceXXH3_len_4to8_64b
XXH3_len_4to8_64b :: proc(input: []u8, secret: []u8, seed: xxh_u64) -> (res: xxh_u64)SourceXXH3_len_9to16_128b
XXH3_len_9to16_128b :: proc(input: []u8, secret: []u8, seed: xxh_u64) -> (res: xxh_u128)SourceXXH3_len_9to16_64b
XXH3_len_9to16_64b :: proc(input: []u8, secret: []u8, seed: xxh_u64) -> (res: xxh_u64)SourceXXH3_mergeAccs
XXH3_mergeAccs :: proc(acc: []xxh_u64, secret: []u8, start: xxh_u64) -> (res: xxh_u64)SourceXXH3_mix16B
XXH3_mix16B :: proc(input: []u8, secret: []u8, seed: xxh_u64) -> (res: xxh_u64)SourceDISCLAIMER: There are known seed-dependent multicollisions here due to
multiplication by zero, affecting hashes of lengths 17 to 240.
However, they are very unlikely.
Keep this in mind when using the unseeded XXH3_64bits() variant: As with all
unseeded non-cryptographic hashes, it does not attempt to defend itself
against specially crafted inputs, only random inputs.
Compared to classic UMAC where a 1 in 2^31 chance of 4 consecutive bytes
cancelling out the secret is taken an arbitrary number of times (addressed
in XXH3_accumulate_512), this collision is very unlikely with random inputs
and/or proper seeding:
This only has a 1 in 2^63 chance of 8 consecutive bytes cancelling out, in a
function that is only called up to 16 times per hash with up to 240 bytes of
input.
This is not too bad for a non-cryptographic hash function, especially with
only 64 bit outputs.
The 128-bit variant (which trades some speed for strength) is NOT affected
by this, although it is always a good idea to use a proper seed if you care
about strength.XXH3_mix2Accs
XXH3_mix2Accs :: proc(acc: []xxh_u64, secret: []u8) -> (res: xxh_u64)SourceXXH3_reset_internal
XXH3_reset_internal :: proc(state: ^XXH3_state, seed: XXH64_hash, secret: []u8, secret_size: uint)SourceXXH3_rrmxmx
XXH3_rrmxmx :: proc(h64: xxh_u64, length: xxh_u64) -> (res: xxh_u64)SourceThis is a stronger avalanche, inspired by Pelle Evensen's rrmxmx
preferable when input has not been previously mixedXXH3_scramble_accumulator
XXH3_scramble_accumulator :: proc(acc: []xxh_u64, secret: []u8)SourceXXH3_scramble_accumulator_scalar
XXH3_scramble_accumulator_scalar :: proc(acc: []xxh_u64, secret: []u8)SourceXXH3_scramble_accumulator_simd_generic
XXH3_scramble_accumulator_simd_generic :: proc(acc: []xxh_u64, secret: []u8, W: uint)SourceXXH3_update
XXH3_update :: proc(state: ^XXH3_state, input: []u8, f_acc512: XXH3_accumulate_512_f, f_scramble: XXH3_scramble_accumulator_f) -> (err: Error)SourceBoth XXH3_64bits_update and XXH3_128bits_update use this routine.
XXH64
XXH64 :: proc(input: []u8, seed = XXH64_DEFAULT_SEED) -> (digest: XXH64_hash)SourceXXH64_avalanche
XXH64_avalanche :: proc(h64: xxh_u64) -> (res: xxh_u64)SourceXXH64_canonical_from_hash
XXH64_canonical_from_hash :: proc(hash: XXH64_hash) -> (canonical: XXH64_canonical)SourceCanonical representation
The default return values from XXH functions are unsigned 32 and 64 bit integers.
The canonical representation uses big endian convention,
the same convention as human-readable numbers (large digits first).
This way, hash values can be written into a file or buffer, remaining
comparable across different systems.
The following functions allow transformation of hash values to and from their
canonical format.XXH64_copy_state
XXH64_copy_state :: proc(dest: ^XXH64_state, src: ^XXH64_state)SourceXXH64_create_state
XXH64_create_state :: proc(allocator: mem.Allocator = context.allocator) -> (res: ^XXH64_state, err: Error)SourceHash Streaming
XXH64_destroy_state
XXH64_destroy_state :: proc(state: ^XXH64_state, allocator: mem.Allocator = context.allocator) -> (err: Error)SourceXXH64_digest
XXH64_digest :: proc(state: ^XXH64_state) -> (res: XXH64_hash)SourceXXH64_endian_align
XXH64_endian_align :: proc(input: []u8, seed = XXH64_DEFAULT_SEED, alignment = Alignment.Unaligned) -> (res: xxh_u64)SourceXXH64_finalize
XXH64_finalize :: proc(h64: xxh_u64, buf: []u8, alignment: Alignment) -> (res: xxh_u64)SourceXXH64_hash_from_canonical
XXH64_hash_from_canonical :: proc(canonical: ^XXH64_canonical) -> (hash: XXH64_hash)SourceXXH64_mergeRound
XXH64_mergeRound :: proc(acc: xxh_u64, val: xxh_u64) -> (res: xxh_u64)SourceXXH64_read64
XXH64_read64 :: proc(buf: []u8, alignment = Alignment.Unaligned) -> (res: u64)SourceXXH64_read64_simd
XXH64_read64_simd :: proc(buf: []E, W: uint, alignment = Alignment.Unaligned) -> (res)SourceXXH64_reset_state
XXH64_reset_state :: proc(state_ptr: ^XXH64_state, seed = XXH64_DEFAULT_SEED) -> (err: Error)SourceXXH64_round
XXH64_round :: proc(acc: xxh_u64, input: xxh_u64) -> (res: xxh_u64)SourceXXH64_update
XXH64_update :: proc(state: ^XXH64_state, input: []u8) -> (err: Error)SourceXXH64_write64_simd
XXH64_write64_simd :: proc(buf: []E, value, alignment = Alignment.Unaligned)SourceXXH_mul_64_to_128_fold_64
XXH_mul_64_to_128_fold_64 :: proc(lhs: xxh_u64, rhs: xxh_u64) -> (res: xxh_u64)SourceThe reason for the separate function is to prevent passing too many structs
around by value. This will hopefully inline the multiply, but we don't force it.
@param lhs, rhs The 64-bit integers to multiply
@return The low 64 bits of the product XOR'd by the high 64 bits.XXH_rotl32
XXH_rotl32 :: proc(x: u32, r: u32) -> (res: u32)SourceXXH_rotl64
XXH_rotl64 :: proc(x: u64, r: u64) -> (res: u64)SourceXXH_writeLE64
XXH_writeLE64 :: proc(dst: []u8, v64: u64le)SourceXXH_xorshift_64
XXH_xorshift_64 :: proc(v: xxh_u64, shift: uint) -> (res: xxh_u64)Source