11 #define hash_cfg_can_hmac(c) ((c)->status == RZ_MSG_DIGEST_STATUS_ALLOC)
12 #define hash_cfg_can_init(c) ((c)->status == RZ_MSG_DIGEST_STATUS_FINAL || (c)->status == RZ_MSG_DIGEST_STATUS_ALLOC)
13 #define hash_cfg_can_update(c) ((c)->status == RZ_MSG_DIGEST_STATUS_INIT || (c)->status == RZ_MSG_DIGEST_STATUS_UPDATE)
14 #define hash_cfg_can_final(c) ((c)->status == RZ_MSG_DIGEST_STATUS_ALLOC || (c)->status == RZ_MSG_DIGEST_STATUS_INIT || (c)->status == RZ_MSG_DIGEST_STATUS_UPDATE)
15 #define hash_cfg_has_finshed(c) ((c)->status == RZ_MSG_DIGEST_STATUS_FINAL)
50 RZ_LOG_ERROR(
"msg digest: cannot calculate entropy fraction\n");
78 RZ_LOG_ERROR(
"msg digest: cannot allocate memory for config.\n");
84 RZ_LOG_ERROR(
"msg digest: cannot allocate memory for context.\n");
94 RZ_LOG_ERROR(
"msg digest: cannot allocate memory for digest.\n");
111 rz_list_foreach (rh->plugins, it, rhp) {
126 rz_list_foreach (rh->plugins, it, rhp) {
144 if (!
md->configurations) {
145 RZ_LOG_ERROR(
"msg digest: cannot allocate memory for the configurations.\n");
203 RZ_LOG_WARN(
"msg digest: '%s' was already configured; skipping.\n",
name);
207 bool is_all = !strcmp(
name,
"all");
210 RZ_LOG_WARN(
"msg digest: '%s' was already configured; skipping.\n",
name);
218 rz_list_foreach (
md->hash->plugins, it, plugin) {
219 if (is_all || !strcmp(plugin->
name,
name)) {
226 RZ_LOG_ERROR(
"msg digest: cannot allocate memory for list entry.\n");
256 rz_list_foreach (
md->configurations,
iter, mdc) {
263 if (block_size < 1) {
270 RZ_LOG_ERROR(
"msg digest: cannot allocate memory for hmac key.\n");
275 if (block_size < key_size) {
303 rz_list_foreach (
md->configurations,
iter, mdc) {
312 RZ_LOG_ERROR(
"msg digest: failed to allocate memory for ipad.\n");
315 for (
ut32 i = 0;
i < block_size;
i++) {
342 rz_list_foreach (
md->configurations,
iter, mdc) {
364 rz_list_foreach (
md->configurations,
iter, mdc) {
374 RZ_LOG_ERROR(
"msg digest: failed to allocate memory for opad.\n");
378 for (
ut32 i = 0;
i < block_size;
i++) {
419 rz_list_foreach (
md->configurations,
iter, mdc) {
420 for (
size_t i = 0;
i < iterate; ++
i) {
450 RZ_LOG_ERROR(
"msg digest: cannot find configuration for '%s' algorithm.\n",
name);
475 RZ_LOG_ERROR(
"msg digest: cannot find configuration for '%s' algorithm.\n",
name);
482 if (!strncmp(
name,
"entropy", 7)) {
489 RZ_LOG_ERROR(
"msg digest: cannot find allocate memory for string result.\n");
515 RZ_LOG_ERROR(
"msg digest: cannot find configuration for '%s' algorithm.\n",
name);
539 RZ_LOG_ERROR(
"msg digest: cannot calculate small block with %s.\n", plugin->
name);
555 if (!strncmp(
name,
"entropy", 7)) {
561 char *
string =
malloc((digest_size * 2) + 1);
563 RZ_LOG_ERROR(
"msg digest: cannot find allocate memory for string result.\n");
568 for (
ut32 i = 0;
i < digest_size;
i++) {
572 string[digest_size * 2] = 0;
575 *
size = (digest_size * 2) + 1;
616 rz_list_foreach (rh->plugins, it,
p) {
617 if (!strcmp(
p->name, plugin->name)) {
static unsigned invert(unsigned x)
RzHashPlugin rz_hash_plugin_entropy
RzHashPlugin rz_hash_plugin_entropy_fract
#define RZ_HASH_STATIC_PLUGINS
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
RZ_API double rz_hash_entropy_fraction(RZ_NONNULL RzHash *rh, RZ_NONNULL const ut8 *data, ut64 len)
RZ_API RZ_BORROW const ut8 * rz_hash_cfg_get_result(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const char *name, RZ_NONNULL ut32 *size)
Returns the digest value of the requested algorithm name.
RZ_API RZ_OWN RzHashCfg * rz_hash_cfg_new(RZ_NONNULL RzHash *rh)
RZ_API bool rz_hash_plugin_add(RZ_NONNULL RzHash *rh, RZ_NONNULL RZ_OWN const RzHashPlugin *plugin)
Add a new plugin to rh so that RzHashCfg can be created using specific algorithms.
#define hash_cfg_can_update(c)
RZ_API RZ_OWN char * rz_hash_cfg_calculate_small_block_string(RZ_NONNULL RzHash *rh, RZ_NONNULL const char *name, RZ_NONNULL const ut8 *buffer, ut64 bsize, RZ_NULLABLE ut32 *size, bool invert)
RZ_API void rz_hash_cfg_free(RZ_NONNULL RzHashCfg *md)
#define hash_cfg_can_hmac(c)
RZ_API bool rz_hash_cfg_iterate(RZ_NONNULL RzHashCfg *md, size_t iterate)
Calculate the final hash by iterating its result N times.
RZ_API RzHashSize rz_hash_cfg_size(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const char *name)
Returns the digest size of the requested algorithm name.
RZ_API void rz_hash_free(RzHash *rh)
RZ_API RZ_BORROW const RzHashPlugin * rz_hash_plugin_by_name(RZ_NONNULL RzHash *rh, RZ_NONNULL const char *name)
#define hash_cfg_can_final(c)
#define hash_cfg_has_finshed(c)
static HashCfgConfig * hash_cfg_config_new(const RzHashPlugin *plugin)
RZ_API RZ_BORROW const RzHashPlugin * rz_hash_plugin_by_index(RZ_NONNULL RzHash *rh, size_t index)
RZ_API ut32 rz_hash_xxhash(RZ_NONNULL RzHash *rh, RZ_NONNULL const ut8 *input, size_t size)
RZ_API RzHash * rz_hash_new(void)
RZ_API RZ_OWN ut8 * rz_hash_cfg_calculate_small_block(RZ_NONNULL RzHash *rh, RZ_NONNULL const char *name, RZ_NONNULL const ut8 *buffer, ut64 bsize, RZ_NONNULL RzHashSize *osize)
Returns the digest size of the requested algorithm name.
RZ_API RZ_OWN RzHashCfg * rz_hash_cfg_new_with_algo(RZ_NONNULL RzHash *rh, RZ_NONNULL const char *name, RZ_NULLABLE const ut8 *key, ut64 key_size)
Returns a message digest context with the give algo already configured.
static int hash_cfg_config_compare(const void *value, const void *data)
struct hash_cfg_config_t HashCfgConfig
static void hash_cfg_config_free(HashCfgConfig *mdc)
RZ_API bool rz_hash_cfg_configure(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const char *name)
Allocates and configures the plugin message digest context.
RZ_API double rz_hash_entropy(RZ_NONNULL RzHash *rh, RZ_NONNULL const ut8 *data, ut64 len)
RZ_API bool rz_hash_cfg_hmac(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const ut8 *key, ut64 key_size)
Sets the key for the hmac algorithm.
#define hash_cfg_can_init(c)
RZ_API bool rz_hash_cfg_init(RZ_NONNULL RzHashCfg *md)
Resets/initialize the message digest contextes.
RZ_API bool rz_hash_cfg_update(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const ut8 *data, ut64 size)
Inserts data into each the message digest contextes.
RZ_API bool rz_hash_cfg_final(RZ_NONNULL RzHashCfg *md)
Generates the final value of the message digest contextes.
static const RzHashPlugin * hash_static_plugins[]
RZ_API RZ_OWN char * rz_hash_cfg_get_result_string(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const char *name, RZ_NULLABLE ut32 *size, bool invert)
Returns the digest value of the requested algorithm name.
RZ_API void Ht_() free(HtName_(Ht) *ht)
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
RZ_API RZ_BORROW RzListIter * rz_list_find(RZ_NONNULL const RzList *list, const void *p, RZ_NONNULL RzListComparator cmp)
Returns RzListIter element which matches via the RzListComparator.
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
RZ_API void * rz_list_iter_get_data(RzListIter *list)
returns the value stored in the list element
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
void * malloc(size_t size)
XXH_PUBLIC_API unsigned int XXH32(const void *input, size_t len, unsigned int seed)
#define rz_warn_if_fail(expr)
#define rz_return_if_fail(expr)
#define rz_return_val_if_fail(expr, val)
static double rz_read_be_double(const void *src)
@ RZ_MSG_DIGEST_STATUS_INIT
@ RZ_MSG_DIGEST_STATUS_UPDATE
@ RZ_MSG_DIGEST_STATUS_FINAL
void(* RzListFree)(void *ptr)
#define RZ_LOG_WARN(fmtstr,...)
#define RZ_LOG_ERROR(fmtstr,...)
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
const RzHashPlugin * plugin
RzHashSize(* block_size)(void *context)
RzHashSize(* digest_size)(void *context)
bool(* small_block)(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size)
bool(* update)(void *context, const ut8 *data, ut64 size)
bool(* init)(void *context)
void(* context_free)(void *context)
bool(* final)(void *context, ut8 *digest)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)