Rizin
unix-like reverse engineering framework and cli tools
xxhash.h File Reference
#include <stddef.h>

Go to the source code of this file.

Classes

struct  XXH32_canonical_t
 
struct  XXH64_canonical_t
 

Macros

#define XXH_PUBLIC_API   /* do nothing */
 
#define XXH_VERSION_MAJOR   0
 
#define XXH_VERSION_MINOR   6
 
#define XXH_VERSION_RELEASE   5
 
#define XXH_VERSION_NUMBER   (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
 

Typedefs

typedef unsigned int XXH32_hash_t
 
typedef struct XXH32_state_s XXH32_state_t
 
typedef unsigned long long XXH64_hash_t
 
typedef struct XXH64_state_s XXH64_state_t
 

Enumerations

enum  XXH_errorcode { XXH_OK =0 , XXH_ERROR , XXH_OK =0 , XXH_ERROR }
 

Functions

XXH_PUBLIC_API unsigned XXH_versionNumber (void)
 
XXH_PUBLIC_API XXH32_hash_t XXH32 (const void *input, size_t length, unsigned int seed)
 
XXH_PUBLIC_API XXH32_state_tXXH32_createState (void)
 
XXH_PUBLIC_API XXH_errorcode XXH32_freeState (XXH32_state_t *statePtr)
 
XXH_PUBLIC_API void XXH32_copyState (XXH32_state_t *dst_state, const XXH32_state_t *src_state)
 
XXH_PUBLIC_API XXH_errorcode XXH32_reset (XXH32_state_t *statePtr, unsigned int seed)
 
XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t *statePtr, const void *input, size_t length)
 
XXH_PUBLIC_API XXH32_hash_t XXH32_digest (const XXH32_state_t *statePtr)
 
XXH_PUBLIC_API void XXH32_canonicalFromHash (XXH32_canonical_t *dst, XXH32_hash_t hash)
 
XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical (const XXH32_canonical_t *src)
 
XXH_PUBLIC_API XXH64_hash_t XXH64 (const void *input, size_t length, unsigned long long seed)
 
XXH_PUBLIC_API XXH64_state_tXXH64_createState (void)
 
XXH_PUBLIC_API XXH_errorcode XXH64_freeState (XXH64_state_t *statePtr)
 
XXH_PUBLIC_API void XXH64_copyState (XXH64_state_t *dst_state, const XXH64_state_t *src_state)
 
XXH_PUBLIC_API XXH_errorcode XXH64_reset (XXH64_state_t *statePtr, unsigned long long seed)
 
XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t *statePtr, const void *input, size_t length)
 
XXH_PUBLIC_API XXH64_hash_t XXH64_digest (const XXH64_state_t *statePtr)
 
XXH_PUBLIC_API void XXH64_canonicalFromHash (XXH64_canonical_t *dst, XXH64_hash_t hash)
 
XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical (const XXH64_canonical_t *src)
 

Macro Definition Documentation

◆ XXH_PUBLIC_API

#define XXH_PUBLIC_API   /* do nothing */

XXH_INLINE_ALL (and XXH_PRIVATE_API) This is useful to include xxhash functions in static mode in order to inline them, and remove their symbol from the public list. Inlining can offer dramatic performance improvement on small keys. Methodology : #define XXH_INLINE_ALL #include "xxhash.h" xxhash.c is automatically included. It's not useful to compile and link it as a separate module.

Definition at line 113 of file xxhash.h.

◆ XXH_VERSION_MAJOR

#define XXH_VERSION_MAJOR   0

XXH_NAMESPACE, aka Namespace Emulation :

If you want to include and expose xxHash functions from within your own library, but also want to avoid symbol collisions with other libraries which may also include xxHash,

you can use XXH_NAMESPACE, to automatically prefix any public symbol from xxhash library with the value of XXH_NAMESPACE (therefore, avoid NULL and numeric values).

Note that no change is required within the calling program as long as it includes xxhash.h : regular symbol name will be automatically translated by this header.

Definition at line 155 of file xxhash.h.

◆ XXH_VERSION_MINOR

#define XXH_VERSION_MINOR   6

Definition at line 156 of file xxhash.h.

◆ XXH_VERSION_NUMBER

#define XXH_VERSION_NUMBER   (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)

Definition at line 158 of file xxhash.h.

◆ XXH_VERSION_RELEASE

#define XXH_VERSION_RELEASE   5

Definition at line 157 of file xxhash.h.

Typedef Documentation

◆ XXH32_hash_t

Definition at line 165 of file xxhash.h.

◆ XXH32_state_t

typedef struct XXH32_state_s XXH32_state_t

Definition at line 172 of file xxhash.h.

◆ XXH64_hash_t

Definition at line 222 of file xxhash.h.

◆ XXH64_state_t

typedef struct XXH64_state_s XXH64_state_t

Definition at line 229 of file xxhash.h.

Enumeration Type Documentation

◆ XXH_errorcode

Enumerator
XXH_OK 
XXH_ERROR 
XXH_OK 
XXH_ERROR 

Definition at line 82 of file xxhash.h.

XXH_errorcode
Definition: xxhash.h:79
@ XXH_ERROR
Definition: xxhash.h:79
@ XXH_OK
Definition: xxhash.h:79

Function Documentation

◆ XXH32()

XXH_PUBLIC_API XXH32_hash_t XXH32 ( const void *  input,
size_t  length,
unsigned int  seed 
)

XXH32() : Calculate the 32-bit hash of sequence "length" bytes stored at memory address "input". The memory between input & input+length must be valid (allocated and read-accessible). "seed" can be used to alter the result predictably. Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s

Definition at line 392 of file xxhash.c.

393 {
394 #if 0
395  /* Simple version, good for code maintenance, but unfortunately slow for small inputs */
397  XXH32_reset(&state, seed);
399  return XXH32_digest(&state);
400 #else
402 
403  if (XXH_FORCE_ALIGN_CHECK) {
404  if ((((size_t)input) & 3) == 0) { /* Input is 4-bytes aligned, leverage the speed benefit */
405  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
407  else
409  } }
410 
411  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
413  else
415 #endif
416 }
size_t len
Definition: 6502dis.c:15
XXH_PUBLIC_API unsigned int XXH32_digest(const XXH32_state_t *state_in)
Definition: xxhash.c:546
FORCE_INLINE U32 XXH32_endian_align(const void *input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align)
Definition: xxhash.c:352
XXH_endianess
Definition: xxhash.c:216
@ XXH_littleEndian
Definition: xxhash.c:216
@ XXH_bigEndian
Definition: xxhash.c:216
#define XXH_CPU_LITTLE_ENDIAN
Definition: xxhash.c:225
XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t *statePtr, unsigned int seed)
Definition: xxhash.c:437
@ XXH_aligned
Definition: xxhash.c:232
@ XXH_unaligned
Definition: xxhash.c:232
#define XXH_FORCE_ALIGN_CHECK
Definition: xxhash.c:97
XXH_PUBLIC_API XXH_errorcode XXH32_update(XXH32_state_t *state_in, const void *input, size_t len)
Definition: xxhash.c:515
#define XXH_FORCE_NATIVE_FORMAT
Definition: xxhash.c:83
struct XXH32_state_s XXH32_state_t
Definition: xxhash.h:172
Definition: dis.h:43
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)

References input(), len, XXH32_digest(), XXH32_endian_align(), XXH32_reset(), XXH32_update(), XXH_aligned, XXH_bigEndian, XXH_CPU_LITTLE_ENDIAN, XXH_FORCE_ALIGN_CHECK, XXH_FORCE_NATIVE_FORMAT, XXH_littleEndian, and XXH_unaligned.

Referenced by fullSpeedBench(), FUZ_test(), FUZ_unitTests(), FUZZ_seed(), fuzzerTests(), LZ4F_decompress(), LZ4F_headerChecksum(), LZ4F_makeBlock(), main(), plugin_xxhash32_small_block(), rz_hash_xxhash(), and select_clevel().

◆ XXH32_canonicalFromHash()

XXH_PUBLIC_API void XXH32_canonicalFromHash ( XXH32_canonical_t dst,
XXH32_hash_t  hash 
)

Default XXH result types are basic unsigned 32 and 64 bits. The canonical representation follows human-readable write convention, aka big-endian (large digits first). These functions allow transformation of hash result into and from its canonical format. This way, hash values can be written into a file or buffer, remaining comparable across different systems.

Definition at line 565 of file xxhash.c.

566 {
568  if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap32(hash);
569  memcpy(dst, &hash, sizeof(*dst));
570 }
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
#define XXH_STATIC_ASSERT(c)
Definition: xxhash.c:256
static U32 XXH_swap32(U32 x)
Definition: xxhash.c:203
unsigned int XXH32_hash_t
Definition: xxhash.h:162
char * dst
Definition: lz4.h:724

References dst, memcpy(), XXH_CPU_LITTLE_ENDIAN, XXH_STATIC_ASSERT, and XXH_swap32().

◆ XXH32_copyState()

XXH_PUBLIC_API void XXH32_copyState ( XXH32_state_t dst_state,
const XXH32_state_t src_state 
)

Definition at line 432 of file xxhash.c.

433 {
434  memcpy(dstState, srcState, sizeof(*dstState));
435 }

References memcpy().

◆ XXH32_createState()

XXH_PUBLIC_API XXH32_state_t* XXH32_createState ( void  )

Definition at line 422 of file xxhash.c.

423 {
424  return (XXH32_state_t*)XXH_malloc(sizeof(XXH32_state_t));
425 }
static void * XXH_malloc(size_t s)
Definition: xxhash.c:108

References XXH_malloc().

Referenced by plugin_xxhash32_context_new().

◆ XXH32_digest()

XXH_PUBLIC_API XXH32_hash_t XXH32_digest ( const XXH32_state_t statePtr)

Definition at line 546 of file xxhash.c.

547 {
549 
550  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
551  return XXH32_digest_endian(state_in, XXH_littleEndian);
552  else
553  return XXH32_digest_endian(state_in, XXH_bigEndian);
554 }
FORCE_INLINE U32 XXH32_digest_endian(const XXH32_state_t *state, XXH_endianess endian)
Definition: xxhash.c:527

References XXH32_digest_endian(), XXH_bigEndian, XXH_CPU_LITTLE_ENDIAN, XXH_FORCE_NATIVE_FORMAT, and XXH_littleEndian.

Referenced by LZ4F_compressEnd(), LZ4F_decompress(), plugin_xxhash32_final(), and XXH32().

◆ XXH32_freeState()

XXH_PUBLIC_API XXH_errorcode XXH32_freeState ( XXH32_state_t statePtr)

Definition at line 426 of file xxhash.c.

427 {
428  XXH_free(statePtr);
429  return XXH_OK;
430 }
static void XXH_free(void *p)
Definition: xxhash.c:109

References XXH_free(), and XXH_OK.

Referenced by plugin_xxhash32_context_free().

◆ XXH32_hashFromCanonical()

XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical ( const XXH32_canonical_t src)

Definition at line 572 of file xxhash.c.

573 {
574  return XXH_readBE32(src);
575 }
lzma_index * src
Definition: index.h:567
static U32 XXH_readBE32(const void *ptr)
Definition: xxhash.c:247

References src, and XXH_readBE32().

◆ XXH32_reset()

XXH_PUBLIC_API XXH_errorcode XXH32_reset ( XXH32_state_t statePtr,
unsigned int  seed 
)

Definition at line 437 of file xxhash.c.

438 {
439  XXH32_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
440  memset(&state, 0, sizeof(state));
441  state.v1 = seed + PRIME32_1 + PRIME32_2;
442  state.v2 = seed + PRIME32_2;
443  state.v3 = seed + 0;
444  state.v4 = seed - PRIME32_1;
445  /* do not write into reserved, planned to be removed in a future version */
446  memcpy(statePtr, &state, sizeof(state) - sizeof(state.reserved));
447  return XXH_OK;
448 }
return memset(p, 0, total)
static const U32 PRIME32_1
Definition: xxhash.c:263
static const U32 PRIME32_2
Definition: xxhash.c:264

References memcpy(), memset(), PRIME32_1, PRIME32_2, and XXH_OK.

Referenced by LZ4F_compressBegin_usingCDict(), LZ4F_decompress(), plugin_xxhash32_init(), and XXH32().

◆ XXH32_update()

XXH_PUBLIC_API XXH_errorcode XXH32_update ( XXH32_state_t statePtr,
const void *  input,
size_t  length 
)

Definition at line 515 of file xxhash.c.

516 {
518 
519  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
520  return XXH32_update_endian(state_in, input, len, XXH_littleEndian);
521  else
522  return XXH32_update_endian(state_in, input, len, XXH_bigEndian);
523 }
FORCE_INLINE XXH_errorcode XXH32_update_endian(XXH32_state_t *state, const void *input, size_t len, XXH_endianess endian)
Definition: xxhash.c:452

References input(), len, XXH32_update_endian(), XXH_bigEndian, XXH_CPU_LITTLE_ENDIAN, XXH_FORCE_NATIVE_FORMAT, and XXH_littleEndian.

Referenced by LZ4F_compressUpdate(), LZ4F_decompress(), plugin_xxhash32_update(), and XXH32().

◆ XXH64()

XXH_PUBLIC_API XXH64_hash_t XXH64 ( const void *  input,
size_t  length,
unsigned long long  seed 
)

XXH64() : Calculate the 64-bit hash of sequence of length "len" stored at memory address "input". "seed" can be used to alter the result predictably. This function runs faster on 64-bit systems, but slower on 32-bit systems (see benchmark).

Definition at line 855 of file xxhash.c.

856 {
857 #if 0
858  /* Simple version, good for code maintenance, but unfortunately slow for small inputs */
860  XXH64_reset(&state, seed);
862  return XXH64_digest(&state);
863 #else
865 
866  if (XXH_FORCE_ALIGN_CHECK) {
867  if ((((size_t)input) & 7)==0) { /* Input is aligned, let's leverage the speed advantage */
868  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
870  else
872  } }
873 
874  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
876  else
878 #endif
879 }
XXH_PUBLIC_API XXH_errorcode XXH64_update(XXH64_state_t *state_in, const void *input, size_t len)
Definition: xxhash.c:971
XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t *statePtr, unsigned long long seed)
Definition: xxhash.c:898
XXH_PUBLIC_API unsigned long long XXH64_digest(const XXH64_state_t *state_in)
Definition: xxhash.c:1005
FORCE_INLINE U64 XXH64_endian_align(const void *input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align)
Definition: xxhash.c:811
struct XXH64_state_s XXH64_state_t
Definition: xxhash.h:229

References input(), len, XXH64_digest(), XXH64_endian_align(), XXH64_reset(), XXH64_update(), XXH_aligned, XXH_bigEndian, XXH_CPU_LITTLE_ENDIAN, XXH_FORCE_ALIGN_CHECK, XXH_FORCE_NATIVE_FORMAT, XXH_littleEndian, and XXH_unaligned.

Referenced by basicTests(), BMK_benchMem(), FUZ_unitTests(), and fuzzerTests().

◆ XXH64_canonicalFromHash()

XXH_PUBLIC_API void XXH64_canonicalFromHash ( XXH64_canonical_t dst,
XXH64_hash_t  hash 
)

Definition at line 1018 of file xxhash.c.

1019 {
1020  XXH_STATIC_ASSERT(sizeof(XXH64_canonical_t) == sizeof(XXH64_hash_t));
1021  if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap64(hash);
1022  memcpy(dst, &hash, sizeof(*dst));
1023 }
static U64 XXH_swap64(U64 x)
Definition: xxhash.c:632
unsigned long long XXH64_hash_t
Definition: xxhash.h:219

References dst, memcpy(), XXH_CPU_LITTLE_ENDIAN, XXH_STATIC_ASSERT, and XXH_swap64().

◆ XXH64_copyState()

XXH_PUBLIC_API void XXH64_copyState ( XXH64_state_t dst_state,
const XXH64_state_t src_state 
)

Definition at line 893 of file xxhash.c.

894 {
895  memcpy(dstState, srcState, sizeof(*dstState));
896 }

References memcpy().

◆ XXH64_createState()

XXH_PUBLIC_API XXH64_state_t* XXH64_createState ( void  )

Definition at line 883 of file xxhash.c.

884 {
885  return (XXH64_state_t*)XXH_malloc(sizeof(XXH64_state_t));
886 }

References XXH_malloc().

◆ XXH64_digest()

XXH_PUBLIC_API XXH64_hash_t XXH64_digest ( const XXH64_state_t statePtr)

Definition at line 1005 of file xxhash.c.

1006 {
1008 
1009  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
1010  return XXH64_digest_endian(state_in, XXH_littleEndian);
1011  else
1012  return XXH64_digest_endian(state_in, XXH_bigEndian);
1013 }
FORCE_INLINE U64 XXH64_digest_endian(const XXH64_state_t *state, XXH_endianess endian)
Definition: xxhash.c:981

References XXH64_digest_endian(), XXH_bigEndian, XXH_CPU_LITTLE_ENDIAN, XXH_FORCE_NATIVE_FORMAT, and XXH_littleEndian.

Referenced by FUZ_unitTests(), test_lz4f_decompression_wBuffers(), and XXH64().

◆ XXH64_freeState()

XXH_PUBLIC_API XXH_errorcode XXH64_freeState ( XXH64_state_t statePtr)

Definition at line 887 of file xxhash.c.

888 {
889  XXH_free(statePtr);
890  return XXH_OK;
891 }

References XXH_free(), and XXH_OK.

◆ XXH64_hashFromCanonical()

XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical ( const XXH64_canonical_t src)

Definition at line 1025 of file xxhash.c.

1026 {
1027  return XXH_readBE64(src);
1028 }
static U64 XXH_readBE64(const void *ptr)
Definition: xxhash.c:658

References src, and XXH_readBE64().

◆ XXH64_reset()

XXH_PUBLIC_API XXH_errorcode XXH64_reset ( XXH64_state_t statePtr,
unsigned long long  seed 
)

Definition at line 898 of file xxhash.c.

899 {
900  XXH64_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
901  memset(&state, 0, sizeof(state));
902  state.v1 = seed + PRIME64_1 + PRIME64_2;
903  state.v2 = seed + PRIME64_2;
904  state.v3 = seed + 0;
905  state.v4 = seed - PRIME64_1;
906  /* do not write into reserved, planned to be removed in a future version */
907  memcpy(statePtr, &state, sizeof(state) - sizeof(state.reserved));
908  return XXH_OK;
909 }
static const U64 PRIME64_2
Definition: xxhash.c:667
static const U64 PRIME64_1
Definition: xxhash.c:666

References memcpy(), memset(), PRIME64_1, PRIME64_2, and XXH_OK.

Referenced by FUZ_unitTests(), test_lz4f_decompression_wBuffers(), and XXH64().

◆ XXH64_update()

XXH_PUBLIC_API XXH_errorcode XXH64_update ( XXH64_state_t statePtr,
const void *  input,
size_t  length 
)

Definition at line 971 of file xxhash.c.

972 {
974 
975  if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
976  return XXH64_update_endian(state_in, input, len, XXH_littleEndian);
977  else
978  return XXH64_update_endian(state_in, input, len, XXH_bigEndian);
979 }
FORCE_INLINE XXH_errorcode XXH64_update_endian(XXH64_state_t *state, const void *input, size_t len, XXH_endianess endian)
Definition: xxhash.c:912

References input(), len, XXH64_update_endian(), XXH_bigEndian, XXH_CPU_LITTLE_ENDIAN, XXH_FORCE_NATIVE_FORMAT, and XXH_littleEndian.

Referenced by FUZ_unitTests(), test_lz4f_decompression_wBuffers(), and XXH64().

◆ XXH_versionNumber()

XXH_PUBLIC_API unsigned XXH_versionNumber ( void  )

Definition at line 257 of file xxhash.c.

257 { return XXH_VERSION_NUMBER; }
#define XXH_VERSION_NUMBER
Definition: xxhash.h:155

References XXH_VERSION_NUMBER.