Rizin
unix-like reverse engineering framework and cli tools
algo_xxhash32.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_hash.h>
5 #include <rz_util/rz_assert.h>
6 #include <xxhash.h>
7 
8 #define RZ_HASH_XXHASH32_DIGEST_SIZE 4
9 #define RZ_HASH_XXHASH32_BLOCK_LENGTH 0
10 
12  return XXH32_createState();
13 }
14 
17 }
18 
21 }
22 
25 }
26 
27 static bool plugin_xxhash32_init(void *context) {
29 
31  return true;
32 }
33 
34 static bool plugin_xxhash32_update(void *context, const ut8 *data, ut64 size) {
35  rz_return_val_if_fail(context && data, false);
36 
38  return true;
39 }
40 
41 static bool plugin_xxhash32_final(void *context, ut8 *digest) {
42  rz_return_val_if_fail(context && digest, false);
43 
45  rz_write_le32(digest, dgst);
46  return true;
47 }
48 
49 static bool plugin_xxhash32_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
50  rz_return_val_if_fail(data && digest, false);
52  if (!dgst) {
53  return false;
54  }
55 
56  ut32 result = XXH32(data, size, 0);
57  rz_write_le32(dgst, result);
58 
59  *digest = dgst;
60  if (digest_size) {
61  *digest_size = RZ_HASH_XXHASH32_DIGEST_SIZE;
62  }
63  return true;
64 }
65 
67  .name = "xxhash32",
68  .license = "LGPL3",
69  .author = "deroad",
70  .support_hmac = false,
71  .context_new = plugin_xxhash32_context_new,
72  .context_free = plugin_xxhash32_context_free,
73  .digest_size = plugin_xxhash32_digest_size,
74  .block_size = plugin_xxhash32_block_size,
75  .init = plugin_xxhash32_init,
76  .update = plugin_xxhash32_update,
77  .final = plugin_xxhash32_final,
78  .small_block = plugin_xxhash32_small_block,
79 };
80 
81 #ifndef RZ_PLUGIN_INCORE
84  .data = &rz_hash_plugin_xxhash32,
85  .version = RZ_VERSION
86 };
87 #endif
static void plugin_xxhash32_context_free(void *context)
Definition: algo_xxhash32.c:15
static bool plugin_xxhash32_init(void *context)
Definition: algo_xxhash32.c:27
static void * plugin_xxhash32_context_new()
Definition: algo_xxhash32.c:11
RzHashPlugin rz_hash_plugin_xxhash32
Definition: algo_xxhash32.c:66
RZ_API RzLibStruct rizin_plugin
Definition: algo_xxhash32.c:82
#define RZ_HASH_XXHASH32_DIGEST_SIZE
Definition: algo_xxhash32.c:8
static bool plugin_xxhash32_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size)
Definition: algo_xxhash32.c:49
#define RZ_HASH_XXHASH32_BLOCK_LENGTH
Definition: algo_xxhash32.c:9
static bool plugin_xxhash32_update(void *context, const ut8 *data, ut64 size)
Definition: algo_xxhash32.c:34
static RzHashSize plugin_xxhash32_digest_size(void *context)
Definition: algo_xxhash32.c:19
static bool plugin_xxhash32_final(void *context, ut8 *digest)
Definition: algo_xxhash32.c:41
static RzHashSize plugin_xxhash32_block_size(void *context)
Definition: algo_xxhash32.c:23
#define RZ_API
uint32_t ut32
voidpf void uLong size
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * malloc(size_t size)
Definition: malloc.c:123
XXH_PUBLIC_API unsigned int XXH32_digest(const XXH32_state_t *state_in)
Definition: xxhash.c:546
XXH_PUBLIC_API XXH32_state_t * XXH32_createState(void)
Definition: xxhash.c:422
XXH_PUBLIC_API unsigned int XXH32(const void *input, size_t len, unsigned int seed)
Definition: xxhash.c:392
XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t *statePtr, unsigned int seed)
Definition: xxhash.c:437
XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t *statePtr)
Definition: xxhash.c:426
XXH_PUBLIC_API XXH_errorcode XXH32_update(XXH32_state_t *state_in, const void *input, size_t len)
Definition: xxhash.c:515
struct XXH32_state_s XXH32_state_t
Definition: xxhash.h:172
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
static void rz_write_le32(void *dest, ut32 val)
Definition: rz_endian.h:256
ut32 RzHashSize
Definition: rz_hash.h:24
@ RZ_LIB_TYPE_HASH
Definition: rz_lib.h:82
#define RZ_VERSION
Definition: rz_version.h:8
const char * name
Definition: rz_hash.h:27
ut64(WINAPI *w32_GetEnabledXStateFeatures)()