Rizin
unix-like reverse engineering framework and cli tools
algo_entropy.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 
7 #include "../algorithms/entropy/entropy.h"
8 
9 static void *plugin_entropy_context_new() {
10  return RZ_NEW0(RzEntropy);
11 }
12 
14  free(context);
15 }
16 
19 }
20 
23 }
24 
25 static bool plugin_entropy_init(void *context) {
27 
29  return true;
30 }
31 
32 static bool plugin_entropy_update(void *context, const ut8 *data, ut64 size) {
33  rz_return_val_if_fail(context && data, false);
34 
36  return true;
37 }
38 
39 static bool plugin_entropy_final(void *context, ut8 *digest) {
40  rz_return_val_if_fail(context && digest, false);
41 
42  rz_entropy_final(digest, (RzEntropy *)context, false);
43  return true;
44 }
45 
46 static bool plugin_entropy_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
47  rz_return_val_if_fail(data && digest, false);
49  if (!dgst) {
50  return false;
51  }
52 
53  RzEntropy ctx;
55  rz_entropy_update(&ctx, data, size);
56  rz_entropy_final(dgst, &ctx, false);
57 
58  *digest = dgst;
59  if (digest_size) {
60  *digest_size = RZ_HASH_ENTROPY_DIGEST_SIZE;
61  }
62  return true;
63 }
64 
66  .name = "entropy",
67  .license = "LGPL3",
68  .author = "deroad",
69  .support_hmac = false,
70  .context_new = plugin_entropy_context_new,
71  .context_free = plugin_entropy_context_free,
72  .digest_size = plugin_entropy_digest_size,
73  .block_size = plugin_entropy_block_size,
74  .init = plugin_entropy_init,
75  .update = plugin_entropy_update,
76  .final = plugin_entropy_final,
77  .small_block = plugin_entropy_small_block,
78 };
79 
80 #ifndef RZ_PLUGIN_INCORE
83  .data = &rz_hash_plugin_entropy,
84  .version = RZ_VERSION
85 };
86 #endif
static bool plugin_entropy_init(void *context)
Definition: algo_entropy.c:25
static void plugin_entropy_context_free(void *context)
Definition: algo_entropy.c:13
static RzHashSize plugin_entropy_block_size(void *context)
Definition: algo_entropy.c:21
static void * plugin_entropy_context_new()
Definition: algo_entropy.c:9
static RzHashSize plugin_entropy_digest_size(void *context)
Definition: algo_entropy.c:17
RZ_API RzLibStruct rizin_plugin
Definition: algo_entropy.c:81
static bool plugin_entropy_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size)
Definition: algo_entropy.c:46
RzHashPlugin rz_hash_plugin_entropy
Definition: algo_entropy.c:65
static bool plugin_entropy_final(void *context, ut8 *digest)
Definition: algo_entropy.c:39
static bool plugin_entropy_update(void *context, const ut8 *data, ut64 size)
Definition: algo_entropy.c:32
#define RZ_API
bool rz_entropy_init(RzEntropy *ctx)
Definition: entropy.c:9
bool rz_entropy_final(ut8 *digest, RzEntropy *ctx, bool fraction)
Definition: entropy.c:24
bool rz_entropy_update(RzEntropy *ctx, const ut8 *data, size_t len)
Definition: entropy.c:15
#define RZ_HASH_ENTROPY_BLOCK_LENGTH
Definition: entropy.h:10
#define RZ_HASH_ENTROPY_DIGEST_SIZE
Definition: entropy.h:9
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * malloc(size_t size)
Definition: malloc.c:123
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
ut32 RzHashSize
Definition: rz_hash.h:24
@ RZ_LIB_TYPE_HASH
Definition: rz_lib.h:82
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_VERSION
Definition: rz_version.h:8
const char * name
Definition: rz_hash.h:27
ut64(WINAPI *w32_GetEnabledXStateFeatures)()