RzHash: rename everything in librz/hash to RzHash prefix

This commit is contained in:
Riccardo Schirone 2022-06-08 09:11:41 +02:00 committed by Anton Kochkov
parent 969dfd0496
commit 9ea7c2fa5a
46 changed files with 627 additions and 627 deletions

View file

@ -3,7 +3,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_analysis.h>
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <ht_uu.h>
#include <assert.h>

View file

@ -4,7 +4,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_bin.h>
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_log.h>
#include "i/private.h"
@ -368,12 +368,12 @@ RZ_API bool rz_bin_file_close(RzBin *bin, int bd) {
return false;
}
static inline bool add_file_hash(RzMsgDigest *md, const char *name, RzList *list) {
static inline bool add_file_hash(RzHashCfg *md, const char *name, RzList *list) {
char hash[128];
const ut8 *digest = NULL;
RzMsgDigestSize digest_size = 0;
RzHashSize digest_size = 0;
digest = rz_msg_digest_get_result(md, name, &digest_size);
digest = rz_hash_cfg_get_result(md, name, &digest_size);
if (!digest) {
return false;
}
@ -407,7 +407,7 @@ RZ_API RZ_OWN RzList *rz_bin_file_compute_hashes(RzBin *bin, RzBinFile *bf, ut64
RzBinObject *o = bf->o;
RzList *file_hashes = NULL;
ut8 *buf = NULL;
RzMsgDigest *md = NULL;
RzHashCfg *md = NULL;
const size_t blocksize = 64000;
RzIODesc *iod = rz_io_desc_get(bin->iob.io, bf->fd);
@ -434,19 +434,19 @@ RZ_API RZ_OWN RzList *rz_bin_file_compute_hashes(RzBin *bin, RzBinFile *bf, ut64
goto rz_bin_file_compute_hashes_bad;
}
md = rz_msg_digest_new();
md = rz_hash_cfg_new();
if (!md) {
goto rz_bin_file_compute_hashes_bad;
}
if (!rz_msg_digest_configure(md, "md5") ||
!rz_msg_digest_configure(md, "sha1") ||
!rz_msg_digest_configure(md, "sha256") ||
!rz_msg_digest_configure(md, "crc32") ||
!rz_msg_digest_configure(md, "entropy")) {
if (!rz_hash_cfg_configure(md, "md5") ||
!rz_hash_cfg_configure(md, "sha1") ||
!rz_hash_cfg_configure(md, "sha256") ||
!rz_hash_cfg_configure(md, "crc32") ||
!rz_hash_cfg_configure(md, "entropy")) {
goto rz_bin_file_compute_hashes_bad;
}
if (!rz_msg_digest_init(md)) {
if (!rz_hash_cfg_init(md)) {
goto rz_bin_file_compute_hashes_bad;
}
@ -456,7 +456,7 @@ RZ_API RZ_OWN RzList *rz_bin_file_compute_hashes(RzBin *bin, RzBinFile *bf, ut64
if (b < 0) {
RZ_LOG_ERROR("rz_io_desc_read: can't read\n");
goto rz_bin_file_compute_hashes_bad;
} else if (!rz_msg_digest_update(md, buf, b)) {
} else if (!rz_hash_cfg_update(md, buf, b)) {
goto rz_bin_file_compute_hashes_bad;
}
r += b;
@ -467,12 +467,12 @@ RZ_API RZ_OWN RzList *rz_bin_file_compute_hashes(RzBin *bin, RzBinFile *bf, ut64
int b = rz_io_desc_read(iod, buf, rem_len);
if (b < 1) {
RZ_LOG_ERROR("rz_io_desc_read: can't read\n");
} else if (!rz_msg_digest_update(md, buf, b)) {
} else if (!rz_hash_cfg_update(md, buf, b)) {
goto rz_bin_file_compute_hashes_bad;
}
}
if (!rz_msg_digest_final(md)) {
if (!rz_hash_cfg_final(md)) {
goto rz_bin_file_compute_hashes_bad;
}
@ -492,12 +492,12 @@ RZ_API RZ_OWN RzList *rz_bin_file_compute_hashes(RzBin *bin, RzBinFile *bf, ut64
// TODO: add here more rows
free(buf);
rz_msg_digest_free(md);
rz_hash_cfg_free(md);
return file_hashes;
rz_bin_file_compute_hashes_bad:
free(buf);
rz_msg_digest_free(md);
rz_hash_cfg_free(md);
rz_list_free(file_hashes);
return NULL;
}

View file

@ -6,7 +6,7 @@
#include <rz_types.h>
#include <rz_util.h>
#include "mach0.h"
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include "mach0_utils.inc"
@ -749,7 +749,7 @@ static void parseCodeDirectory(RzBuffer *b, int offset, int datasize) {
}
// computed cdhash
RzMsgDigestSize digest_size = 0;
RzHashSize digest_size = 0;
ut8 *digest = NULL;
int fofsz = cscd.length;
@ -761,7 +761,7 @@ static void parseCodeDirectory(RzBuffer *b, int offset, int datasize) {
goto parseCodeDirectory_end;
}
digest = rz_msg_digest_calculate_small_block(digest_algo, fofbuf, fofsz, &digest_size);
digest = rz_hash_cfg_calculate_small_block(digest_algo, fofbuf, fofsz, &digest_size);
if (!digest) {
goto parseCodeDirectory_end;
}
@ -791,7 +791,7 @@ static void parseCodeDirectory(RzBuffer *b, int offset, int datasize) {
int fofsz = RZ_MIN(sizeof(fofbuf), cscd.codeLimit - fof);
rz_buf_read_at(b, fof, fofbuf, sizeof(fofbuf));
digest = rz_msg_digest_calculate_small_block(digest_algo, fofbuf, fofsz, &digest_size);
digest = rz_hash_cfg_calculate_small_block(digest_algo, fofbuf, fofsz, &digest_size);
if (!digest) {
goto parseCodeDirectory_end;
}

View file

@ -4,7 +4,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include "pe.h"
#include <rz_msg_digest.h>
#include <rz_hash.h>
static const char *PE_(bin_pe_get_claimed_authentihash)(RzBinPEObj *bin) {
if (!bin->spcinfo) {
@ -15,7 +15,7 @@ static const char *PE_(bin_pe_get_claimed_authentihash)(RzBinPEObj *bin) {
}
static ut64 buf_fwd_hash(const ut8 *buf, ut64 size, void *user) {
return rz_msg_digest_update((RzMsgDigest *)user, buf, size) ? size : 0;
return rz_hash_cfg_update((RzHashCfg *)user, buf, size) ? size : 0;
}
char *PE_(bin_pe_compute_authentihash)(RzBinPEObj *bin) {
@ -26,7 +26,7 @@ char *PE_(bin_pe_compute_authentihash)(RzBinPEObj *bin) {
char *hashtype = strdup(bin->spcinfo->messageDigest.digestAlgorithm.algorithm->string);
rz_str_replace_char(hashtype, '-', 0);
RzMsgDigest *md = rz_msg_digest_new_with_algo2(hashtype);
RzHashCfg *md = rz_hash_cfg_new_with_algo2(hashtype);
if (!md) {
free(hashtype);
return NULL;
@ -41,19 +41,19 @@ char *PE_(bin_pe_compute_authentihash)(RzBinPEObj *bin) {
rz_buf_fwd_scan(bin->b, security_entry_offset + 8, security_dir_offset - security_entry_offset - 8, buf_fwd_hash, md);
rz_buf_fwd_scan(bin->b, security_dir_offset + security_dir_size, rz_buf_size(bin->b) - security_dir_offset - security_dir_size, buf_fwd_hash, md);
RzMsgDigestSize digest_size = 0;
RzHashSize digest_size = 0;
const ut8 *digest = NULL;
if (!rz_msg_digest_final(md) ||
!(digest = rz_msg_digest_get_result(md, hashtype, &digest_size))) {
if (!rz_hash_cfg_final(md) ||
!(digest = rz_hash_cfg_get_result(md, hashtype, &digest_size))) {
free(hashtype);
rz_msg_digest_free(md);
rz_hash_cfg_free(md);
return NULL;
}
char *hashstr = rz_hex_bin2strdup(digest, digest_size);
free(hashtype);
rz_msg_digest_free(md);
rz_hash_cfg_free(md);
return hashstr;
}

View file

@ -1653,7 +1653,7 @@ RZ_API RZ_OWN HtPP *rz_core_bin_create_digests(RzCore *core, ut64 paddr, ut64 si
return NULL;
}
rz_io_pread_at(core->io, paddr, data, size);
char *chkstr = rz_msg_digest_calculate_small_block_string(digest, data, size, NULL, false);
char *chkstr = rz_hash_cfg_calculate_small_block_string(digest, data, size, NULL, false);
if (!chkstr) {
continue;
}
@ -2462,7 +2462,7 @@ static void sections_headers_setup(RzCore *core, RzCmdStateOutput *state, RzList
rz_cmd_state_output_set_columnsf(state, "XxXxssssx", "paddr", "size", "vaddr", "vsize", "align", "perm", "name", "type", "flags");
rz_list_foreach (hashes, iter, hashname) {
const RzMsgDigestPlugin *msg_plugin = rz_msg_digest_plugin_by_name(hashname);
const RzHashPlugin *msg_plugin = rz_hash_plugin_by_name(hashname);
if (msg_plugin) {
rz_cmd_state_output_set_columnsf(state, "s", msg_plugin->name);
}
@ -2609,7 +2609,7 @@ RZ_API bool rz_core_bin_segments_print(RzCore *core, RzBinFile *bf, RzCmdStateOu
rz_cmd_state_output_set_columnsf(state, "XxXxssx", "paddr", "size", "vaddr", "vsize", "align", "perm", "name");
rz_list_foreach (hashes, iter, hashname) {
const RzMsgDigestPlugin *msg_plugin = rz_msg_digest_plugin_by_name(hashname);
const RzHashPlugin *msg_plugin = rz_hash_plugin_by_name(hashname);
if (msg_plugin) {
rz_cmd_state_output_set_columnsf(state, "s", msg_plugin->name);
}
@ -5053,7 +5053,7 @@ RZ_API bool rz_core_bin_resources_print(RZ_NONNULL RzCore *core, RZ_NONNULL RzBi
rz_cmd_state_output_set_columnsf(state, "dssXxss", "index", "name", "type", "vaddr", "size", "lang", "timestamp");
rz_list_foreach (hashes, it, hashname) {
const RzMsgDigestPlugin *msg_plugin = rz_msg_digest_plugin_by_name(hashname);
const RzHashPlugin *msg_plugin = rz_hash_plugin_by_name(hashname);
if (msg_plugin) {
rz_cmd_state_output_set_columnsf(state, "s", msg_plugin->name);
}

View file

@ -3,7 +3,7 @@
#include <rz_core.h>
RZ_API RzCmdStatus rz_core_hash_plugin_print(RzCmdStateOutput *state, const RzMsgDigestPlugin *plugin) {
RZ_API RzCmdStatus rz_core_hash_plugin_print(RzCmdStateOutput *state, const RzHashPlugin *plugin) {
PJ *pj = state->d.pj;
switch (state->mode) {
case RZ_OUTPUT_MODE_QUIET: {
@ -32,13 +32,13 @@ RZ_API RzCmdStatus rz_core_hash_plugin_print(RzCmdStateOutput *state, const RzMs
}
RZ_API RzCmdStatus rz_core_hash_plugins_print(RzCmdStateOutput *state) {
const RzMsgDigestPlugin *plugin = NULL;
const RzHashPlugin *plugin = NULL;
RzCmdStatus status;
rz_cmd_state_output_array_start(state);
if (state->mode == RZ_OUTPUT_MODE_STANDARD) {
rz_cons_println("algorithm license author");
}
for (size_t j = 0; (plugin = rz_msg_digest_plugin_by_index(j)); ++j) {
for (size_t j = 0; (plugin = rz_hash_plugin_by_index(j)); ++j) {
status = rz_core_hash_plugin_print(state, plugin);
if (status != RZ_CMD_STATUS_OK) {
return status;

View file

@ -10,7 +10,7 @@ typedef void (*DigestHandler)(const char *name, const ut8 *block, int len);
typedef struct {
const char *name;
DigestHandler handler;
RzMsgDigestPlugin *plugin;
RzHashPlugin *plugin;
} MsgDigestCaller;
RZ_IPI RzCmdDescDetail *rz_hash_bang_details_cb(RzCore *core, int argc, const char **argv) {

View file

@ -3052,8 +3052,8 @@ restore_conf:
}
static void handle_entropy(const char *name, const ut8 *block, int len) {
RzMsgDigestSize digest_size = 0;
ut8 *digest = rz_msg_digest_calculate_small_block(name, block, len, &digest_size);
RzHashSize digest_size = 0;
ut8 *digest = rz_hash_cfg_calculate_small_block(name, block, len, &digest_size);
if (!digest) {
return;
}
@ -3072,15 +3072,15 @@ static inline void hexprint(const ut8 *data, int len) {
rz_cons_newline();
}
static void handle_msg_digest(const char *name, const ut8 *block, int len) {
RzMsgDigestSize digest_size = 0;
ut8 *digest = rz_msg_digest_calculate_small_block(name, block, len, &digest_size);
static void handle_hash_cfg(const char *name, const ut8 *block, int len) {
RzHashSize digest_size = 0;
ut8 *digest = rz_hash_cfg_calculate_small_block(name, block, len, &digest_size);
hexprint(digest, digest_size);
free(digest);
}
RZ_IPI RzCmdStatus rz_cmd_print_msg_digest_handler(RzCore *core, int argc, const char **argv) {
const RzMsgDigestPlugin *plugin = rz_msg_digest_plugin_by_name(argv[1]);
RZ_IPI RzCmdStatus rz_cmd_print_hash_cfg_handler(RzCore *core, int argc, const char **argv) {
const RzHashPlugin *plugin = rz_hash_plugin_by_name(argv[1]);
if (!plugin) {
RZ_LOG_ERROR("algorithm '%s' does not exists\n", argv[1]);
@ -3090,13 +3090,13 @@ RZ_IPI RzCmdStatus rz_cmd_print_msg_digest_handler(RzCore *core, int argc, const
if (!strncmp(plugin->name, "entropy", 7)) {
handle_entropy(plugin->name, core->block, core->blocksize);
} else {
handle_msg_digest(plugin->name, core->block, core->blocksize);
handle_hash_cfg(plugin->name, core->block, core->blocksize);
}
return RZ_CMD_STATUS_OK;
}
RZ_IPI RzCmdStatus rz_cmd_print_msg_digest_algo_list_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state) {
RZ_IPI RzCmdStatus rz_cmd_print_hash_cfg_algo_list_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state) {
return rz_core_hash_plugins_print(state);
}
@ -6918,7 +6918,7 @@ RZ_IPI int rz_cmd_print(void *data, const char *input) {
rz_list_free(pids);
} else if (l > 0) {
len = len > core->blocksize ? core->blocksize : len;
char *s = rz_msg_digest_randomart(block, len, core->offset);
char *s = rz_hash_cfg_randomart(block, len, core->offset);
rz_cons_println(s);
free(s);
}
@ -6945,7 +6945,7 @@ RZ_IPI int rz_cmd_print(void *data, const char *input) {
rz_cons_canvas_gotoxy(c, j * 20, i * 11);
core->offset += len;
rz_io_read_at(core->io, core->offset, core->block, len);
s = rz_msg_digest_randomart(core->block, len, core->offset);
s = rz_hash_cfg_randomart(core->block, len, core->offset);
rz_cons_canvas_write(c, s);
free(s);
}

View file

@ -213,7 +213,7 @@ static int search_hash(RzCore *core, const char *hashname, const char *hashstr,
if (rz_cons_is_breaked()) {
break;
}
char *s = rz_msg_digest_calculate_small_block_string(hashname, buf + i, len, NULL, false);
char *s = rz_hash_cfg_calculate_small_block_string(hashname, buf + i, len, NULL, false);
if (!s) {
eprintf("Hash fail\n");
break;
@ -2741,7 +2741,7 @@ static void incDigitBuffer(ut8 *buf, int bufsz) {
static void search_collisions(RzCore *core, const char *hashName, const ut8 *hashValue, int hashLength, int mode) {
ut8 RZ_ALIGNED(8) cmphash[128];
const RzMsgDigestPlugin *crc32 = rz_msg_digest_plugin_by_name("crc32");
const RzHashPlugin *crc32 = rz_hash_plugin_by_name("crc32");
ut8 *digest = NULL;
int i = 0;

View file

@ -460,7 +460,7 @@ static const RzCmdDescArg cmd_disassemble_summarize_n_bytes_args[2];
static const RzCmdDescArg cmd_disassemble_summarize_block_args[2];
static const RzCmdDescArg cmd_print_gadget_add_args[6];
static const RzCmdDescArg cmd_print_gadget_move_args[6];
static const RzCmdDescArg cmd_print_msg_digest_args[2];
static const RzCmdDescArg cmd_print_hash_cfg_args[2];
static const RzCmdDescArg cmd_print_magic_args[2];
static const RzCmdDescArg print_utf16le_args[2];
static const RzCmdDescArg print_utf32le_args[2];
@ -10837,7 +10837,7 @@ static const RzCmdDescHelp cmd_print_gadget_move_help = {
static const RzCmdDescHelp cmd_print_default_help = {
.summary = "Print hash/message digest or entropy",
};
static const RzCmdDescArg cmd_print_msg_digest_args[] = {
static const RzCmdDescArg cmd_print_hash_cfg_args[] = {
{
.name = "algo",
.type = RZ_CMD_ARG_TYPE_STRING,
@ -10846,17 +10846,17 @@ static const RzCmdDescArg cmd_print_msg_digest_args[] = {
},
{ 0 },
};
static const RzCmdDescHelp cmd_print_msg_digest_help = {
static const RzCmdDescHelp cmd_print_hash_cfg_help = {
.summary = "Prints a hash/message digest or entropy (use @! to change the block size)",
.args = cmd_print_msg_digest_args,
.args = cmd_print_hash_cfg_args,
};
static const RzCmdDescArg cmd_print_msg_digest_algo_list_args[] = {
static const RzCmdDescArg cmd_print_hash_cfg_algo_list_args[] = {
{ 0 },
};
static const RzCmdDescHelp cmd_print_msg_digest_algo_list_help = {
static const RzCmdDescHelp cmd_print_hash_cfg_algo_list_help = {
.summary = "Lists all the supported algorithms",
.args = cmd_print_msg_digest_algo_list_args,
.args = cmd_print_hash_cfg_algo_list_args,
};
static const RzCmdDescHelp cmd_print_timestamp_help = {
@ -16591,10 +16591,10 @@ RZ_IPI void rzshell_cmddescs_init(RzCore *core) {
RzCmdDesc *cmd_print_gadget_move_cd = rz_cmd_desc_argv_new(core->rcmd, cmd_print_gadget_cd, "pgm", rz_cmd_print_gadget_move_handler, &cmd_print_gadget_move_help);
rz_warn_if_fail(cmd_print_gadget_move_cd);
RzCmdDesc *cmd_print_default_cd = rz_cmd_desc_group_new(core->rcmd, cmd_print_cd, "ph", rz_cmd_print_msg_digest_handler, &cmd_print_msg_digest_help, &cmd_print_default_help);
RzCmdDesc *cmd_print_default_cd = rz_cmd_desc_group_new(core->rcmd, cmd_print_cd, "ph", rz_cmd_print_hash_cfg_handler, &cmd_print_hash_cfg_help, &cmd_print_default_help);
rz_warn_if_fail(cmd_print_default_cd);
RzCmdDesc *cmd_print_msg_digest_algo_list_cd = rz_cmd_desc_argv_state_new(core->rcmd, cmd_print_default_cd, "phl", RZ_OUTPUT_MODE_STANDARD | RZ_OUTPUT_MODE_RIZIN | RZ_OUTPUT_MODE_JSON | RZ_OUTPUT_MODE_QUIET, rz_cmd_print_msg_digest_algo_list_handler, &cmd_print_msg_digest_algo_list_help);
rz_warn_if_fail(cmd_print_msg_digest_algo_list_cd);
RzCmdDesc *cmd_print_hash_cfg_algo_list_cd = rz_cmd_desc_argv_state_new(core->rcmd, cmd_print_default_cd, "phl", RZ_OUTPUT_MODE_STANDARD | RZ_OUTPUT_MODE_RIZIN | RZ_OUTPUT_MODE_JSON | RZ_OUTPUT_MODE_QUIET, rz_cmd_print_hash_cfg_algo_list_handler, &cmd_print_hash_cfg_algo_list_help);
rz_warn_if_fail(cmd_print_hash_cfg_algo_list_cd);
RzCmdDesc *cmd_print_timestamp_cd = rz_cmd_desc_group_new(core->rcmd, cmd_print_cd, "pt", rz_cmd_print_timestamp_unix_handler, &cmd_print_timestamp_unix_help, &cmd_print_timestamp_help);
rz_warn_if_fail(cmd_print_timestamp_cd);

View file

@ -790,8 +790,8 @@ RZ_IPI RzCmdStatus rz_cmd_print_gadget_add_handler(RzCore *core, int argc, const
RZ_IPI RzCmdStatus rz_cmd_print_gadget_print_as_rizin_handler(RzCore *core, int argc, const char **argv);
RZ_IPI RzCmdStatus rz_cmd_print_gadget_remove_handler(RzCore *core, int argc, const char **argv);
RZ_IPI RzCmdStatus rz_cmd_print_gadget_move_handler(RzCore *core, int argc, const char **argv);
RZ_IPI RzCmdStatus rz_cmd_print_msg_digest_handler(RzCore *core, int argc, const char **argv);
RZ_IPI RzCmdStatus rz_cmd_print_msg_digest_algo_list_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state);
RZ_IPI RzCmdStatus rz_cmd_print_hash_cfg_handler(RzCore *core, int argc, const char **argv);
RZ_IPI RzCmdStatus rz_cmd_print_hash_cfg_algo_list_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state);
RZ_IPI RzCmdStatus rz_cmd_print_timestamp_unix_handler(RzCore *core, int argc, const char **argv);
RZ_IPI RzCmdStatus rz_cmd_print_timestamp_current_handler(RzCore *core, int argc, const char **argv);
RZ_IPI RzCmdStatus rz_cmd_print_timestamp_dos_handler(RzCore *core, int argc, const char **argv);

View file

@ -323,13 +323,13 @@ commands:
subcommands:
- name: ph
summary: Prints a hash/message digest or entropy (use @! to change the block size)
cname: cmd_print_msg_digest
cname: cmd_print_hash_cfg
args:
- name: algo
type: RZ_CMD_ARG_TYPE_STRING
- name: phl
summary: Lists all the supported algorithms
cname: cmd_print_msg_digest_algo_list
cname: cmd_print_hash_cfg_algo_list
type: RZ_CMD_DESC_TYPE_ARGV_STATE
modes:
- RZ_OUTPUT_MODE_STANDARD
@ -409,4 +409,4 @@ commands:
args:
- name: type
type: RZ_CMD_ARG_TYPE_NUM
optional: true
optional: true

View file

@ -183,7 +183,7 @@ RZ_API void rz_debug_session_restore_reg_mem(RzDebug *dbg, ut32 cnum) {
}
RZ_API void rz_debug_session_list_memory(RzDebug *dbg) {
RzMsgDigestSize dsize;
RzHashSize dsize;
RzListIter *iter;
RzDebugMap *map;
rz_debug_map_sync(dbg);

View file

@ -47,8 +47,8 @@ RZ_API bool rz_debug_snap_contains(RzDebugSnap *snap, ut64 addr) {
return (snap->addr <= addr && addr >= snap->addr_end);
}
RZ_API ut8 *rz_debug_snap_get_hash(RzDebugSnap *snap, RzMsgDigestSize *size) {
ut8 *digest = rz_msg_digest_calculate_small_block("sha256", snap->data, snap->size, size);
RZ_API ut8 *rz_debug_snap_get_hash(RzDebugSnap *snap, RzHashSize *size) {
ut8 *digest = rz_hash_cfg_calculate_small_block("sha256", snap->data, snap->size, size);
if (!digest) {
return NULL;
}
@ -56,7 +56,7 @@ RZ_API ut8 *rz_debug_snap_get_hash(RzDebugSnap *snap, RzMsgDigestSize *size) {
}
RZ_API bool rz_debug_snap_is_equal(RzDebugSnap *a, RzDebugSnap *b) {
RzMsgDigestSize digest_size = 0;
RzHashSize digest_size = 0;
ut8 *a_dgst = rz_debug_snap_get_hash(a, &digest_size);
ut8 *b_dgst = rz_debug_snap_get_hash(b, NULL);

View file

@ -37,12 +37,12 @@ EVP_sha512
}
#define rz_openssl_plugin_digest_size(pluginname, evpmd) \
static RzMsgDigestSize openssl_plugin_##pluginname##_digest_size(void *context) { \
static RzHashSize openssl_plugin_##pluginname##_digest_size(void *context) { \
return EVP_MD_size(evpmd()); \
}
#define rz_openssl_plugin_block_size(pluginname, evpmd) \
static RzMsgDigestSize openssl_plugin_##pluginname##_block_size(void *context) { \
static RzHashSize openssl_plugin_##pluginname##_block_size(void *context) { \
return EVP_MD_block_size(evpmd()); \
}
@ -77,13 +77,13 @@ EVP_sha512
}
#define rz_openssl_plugin_small_block(pluginname, evpmd) \
static bool openssl_plugin_##pluginname##_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) { \
static bool openssl_plugin_##pluginname##_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) { \
rz_return_val_if_fail((data) && (digest), false); \
const EVP_MD *evp_md = evpmd(); \
if (!evp_md) { \
return false; \
} \
RzMsgDigestSize dgst_size = EVP_MD_size(evp_md); \
RzHashSize dgst_size = EVP_MD_size(evp_md); \
ut8 *dgst = malloc(dgst_size); \
if (!dgst) { \
return false; \
@ -116,7 +116,7 @@ EVP_sha512
return true; \
}
#define rz_openssl_plugin_define_msg_digest(pluginname, evpmd, canhmac) \
#define rz_openssl_plugin_define_hash_cfg(pluginname, evpmd, canhmac) \
rz_openssl_plugin_context_new(pluginname); \
rz_openssl_plugin_context_free(pluginname); \
rz_openssl_plugin_digest_size(pluginname, evpmd); \
@ -125,7 +125,7 @@ EVP_sha512
rz_openssl_plugin_update(pluginname); \
rz_openssl_plugin_final(pluginname); \
rz_openssl_plugin_small_block(pluginname, evpmd); \
RzMsgDigestPlugin rz_msg_digest_plugin_##pluginname = { \
RzHashPlugin rz_hash_plugin_##pluginname = { \
.name = #pluginname, \
.license = "Apache 2.0", \
.author = "OpenSSL Team", \

View file

@ -1,95 +1,95 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util.h>
#include <xxhash.h>
RZ_LIB_VERSION(rz_msg_digest);
RZ_LIB_VERSION(rz_hash);
#define msg_digest_can_hmac(c) ((c)->status == RZ_MSG_DIGEST_STATUS_ALLOC)
#define msg_digest_can_init(c) ((c)->status == RZ_MSG_DIGEST_STATUS_FINAL || (c)->status == RZ_MSG_DIGEST_STATUS_ALLOC)
#define msg_digest_can_update(c) ((c)->status == RZ_MSG_DIGEST_STATUS_INIT || (c)->status == RZ_MSG_DIGEST_STATUS_UPDATE)
#define msg_digest_can_final(c) ((c)->status == RZ_MSG_DIGEST_STATUS_ALLOC || (c)->status == RZ_MSG_DIGEST_STATUS_INIT || (c)->status == RZ_MSG_DIGEST_STATUS_UPDATE)
#define msg_digest_has_finshed(c) ((c)->status == RZ_MSG_DIGEST_STATUS_FINAL)
#define hash_cfg_can_hmac(c) ((c)->status == RZ_MSG_DIGEST_STATUS_ALLOC)
#define hash_cfg_can_init(c) ((c)->status == RZ_MSG_DIGEST_STATUS_FINAL || (c)->status == RZ_MSG_DIGEST_STATUS_ALLOC)
#define hash_cfg_can_update(c) ((c)->status == RZ_MSG_DIGEST_STATUS_INIT || (c)->status == RZ_MSG_DIGEST_STATUS_UPDATE)
#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)
#define hash_cfg_has_finshed(c) ((c)->status == RZ_MSG_DIGEST_STATUS_FINAL)
typedef struct msg_digest_config_t {
typedef struct hash_cfg_config_t {
void *context;
ut8 *digest;
ut8 *hmac_key;
RzMsgDigestSize digest_size;
const RzMsgDigestPlugin *plugin;
} MsgDigestConfig;
RzHashSize digest_size;
const RzHashPlugin *plugin;
} HashCfgConfig;
const static RzMsgDigestPlugin *msg_digest_plugins[] = {
&rz_msg_digest_plugin_md4,
&rz_msg_digest_plugin_md5,
&rz_msg_digest_plugin_sha1,
&rz_msg_digest_plugin_sha256,
&rz_msg_digest_plugin_sha384,
&rz_msg_digest_plugin_sha512,
&rz_msg_digest_plugin_fletcher8,
&rz_msg_digest_plugin_fletcher16,
&rz_msg_digest_plugin_fletcher32,
&rz_msg_digest_plugin_fletcher64,
&rz_msg_digest_plugin_adler32,
&rz_msg_digest_plugin_crca_crc8smbus,
&rz_msg_digest_plugin_crca_crc8cdma2000,
&rz_msg_digest_plugin_crca_crc8darc,
&rz_msg_digest_plugin_crca_crc8dvbs2,
&rz_msg_digest_plugin_crca_crc8ebu,
&rz_msg_digest_plugin_crca_crc8icode,
&rz_msg_digest_plugin_crca_crc8itu,
&rz_msg_digest_plugin_crca_crc8maxim,
&rz_msg_digest_plugin_crca_crc8rohc,
&rz_msg_digest_plugin_crca_crc8wcdma,
&rz_msg_digest_plugin_crca_crc15can,
&rz_msg_digest_plugin_crca_crc16,
&rz_msg_digest_plugin_crca_crc16citt,
&rz_msg_digest_plugin_crca_crc16usb,
&rz_msg_digest_plugin_crca_crc16hdlc,
&rz_msg_digest_plugin_crca_crc16augccitt,
&rz_msg_digest_plugin_crca_crc16buypass,
&rz_msg_digest_plugin_crca_crc16cdma2000,
&rz_msg_digest_plugin_crca_crc16dds110,
&rz_msg_digest_plugin_crca_crc16dectr,
&rz_msg_digest_plugin_crca_crc16dectx,
&rz_msg_digest_plugin_crca_crc16dnp,
&rz_msg_digest_plugin_crca_crc16en13757,
&rz_msg_digest_plugin_crca_crc16genibus,
&rz_msg_digest_plugin_crca_crc16maxim,
&rz_msg_digest_plugin_crca_crc16mcrf4xx,
&rz_msg_digest_plugin_crca_crc16riello,
&rz_msg_digest_plugin_crca_crc16t10dif,
&rz_msg_digest_plugin_crca_crc16teledisk,
&rz_msg_digest_plugin_crca_crc16tms37157,
&rz_msg_digest_plugin_crca_crca,
&rz_msg_digest_plugin_crca_crc16kermit,
&rz_msg_digest_plugin_crca_crc16modbus,
&rz_msg_digest_plugin_crca_crc16x25,
&rz_msg_digest_plugin_crca_crc16xmodem,
&rz_msg_digest_plugin_crca_crc24,
&rz_msg_digest_plugin_crca_crc32,
&rz_msg_digest_plugin_crca_crc32ecma267,
&rz_msg_digest_plugin_crca_crc32c,
&rz_msg_digest_plugin_crca_crc32bzip2,
&rz_msg_digest_plugin_crca_crc32d,
&rz_msg_digest_plugin_crca_crc32mpeg2,
&rz_msg_digest_plugin_crca_crc32posix,
&rz_msg_digest_plugin_crca_crc32q,
&rz_msg_digest_plugin_crca_crc32jamcrc,
&rz_msg_digest_plugin_crca_crc32xfer,
&rz_msg_digest_plugin_crca_crc64,
&rz_msg_digest_plugin_crca_crc64ecma182,
&rz_msg_digest_plugin_crca_crc64we,
&rz_msg_digest_plugin_crca_crc64xz,
&rz_msg_digest_plugin_crca_crc64iso,
&rz_msg_digest_plugin_xor8,
&rz_msg_digest_plugin_xor16,
&rz_msg_digest_plugin_xxhash32,
&rz_msg_digest_plugin_parity,
&rz_msg_digest_plugin_entropy,
&rz_msg_digest_plugin_entropy_fract,
const static RzHashPlugin *hash_cfg_plugins[] = {
&rz_hash_plugin_md4,
&rz_hash_plugin_md5,
&rz_hash_plugin_sha1,
&rz_hash_plugin_sha256,
&rz_hash_plugin_sha384,
&rz_hash_plugin_sha512,
&rz_hash_plugin_fletcher8,
&rz_hash_plugin_fletcher16,
&rz_hash_plugin_fletcher32,
&rz_hash_plugin_fletcher64,
&rz_hash_plugin_adler32,
&rz_hash_plugin_crca_crc8smbus,
&rz_hash_plugin_crca_crc8cdma2000,
&rz_hash_plugin_crca_crc8darc,
&rz_hash_plugin_crca_crc8dvbs2,
&rz_hash_plugin_crca_crc8ebu,
&rz_hash_plugin_crca_crc8icode,
&rz_hash_plugin_crca_crc8itu,
&rz_hash_plugin_crca_crc8maxim,
&rz_hash_plugin_crca_crc8rohc,
&rz_hash_plugin_crca_crc8wcdma,
&rz_hash_plugin_crca_crc15can,
&rz_hash_plugin_crca_crc16,
&rz_hash_plugin_crca_crc16citt,
&rz_hash_plugin_crca_crc16usb,
&rz_hash_plugin_crca_crc16hdlc,
&rz_hash_plugin_crca_crc16augccitt,
&rz_hash_plugin_crca_crc16buypass,
&rz_hash_plugin_crca_crc16cdma2000,
&rz_hash_plugin_crca_crc16dds110,
&rz_hash_plugin_crca_crc16dectr,
&rz_hash_plugin_crca_crc16dectx,
&rz_hash_plugin_crca_crc16dnp,
&rz_hash_plugin_crca_crc16en13757,
&rz_hash_plugin_crca_crc16genibus,
&rz_hash_plugin_crca_crc16maxim,
&rz_hash_plugin_crca_crc16mcrf4xx,
&rz_hash_plugin_crca_crc16riello,
&rz_hash_plugin_crca_crc16t10dif,
&rz_hash_plugin_crca_crc16teledisk,
&rz_hash_plugin_crca_crc16tms37157,
&rz_hash_plugin_crca_crca,
&rz_hash_plugin_crca_crc16kermit,
&rz_hash_plugin_crca_crc16modbus,
&rz_hash_plugin_crca_crc16x25,
&rz_hash_plugin_crca_crc16xmodem,
&rz_hash_plugin_crca_crc24,
&rz_hash_plugin_crca_crc32,
&rz_hash_plugin_crca_crc32ecma267,
&rz_hash_plugin_crca_crc32c,
&rz_hash_plugin_crca_crc32bzip2,
&rz_hash_plugin_crca_crc32d,
&rz_hash_plugin_crca_crc32mpeg2,
&rz_hash_plugin_crca_crc32posix,
&rz_hash_plugin_crca_crc32q,
&rz_hash_plugin_crca_crc32jamcrc,
&rz_hash_plugin_crca_crc32xfer,
&rz_hash_plugin_crca_crc64,
&rz_hash_plugin_crca_crc64ecma182,
&rz_hash_plugin_crca_crc64we,
&rz_hash_plugin_crca_crc64xz,
&rz_hash_plugin_crca_crc64iso,
&rz_hash_plugin_xor8,
&rz_hash_plugin_xor16,
&rz_hash_plugin_xxhash32,
&rz_hash_plugin_parity,
&rz_hash_plugin_entropy,
&rz_hash_plugin_entropy_fract,
};
RZ_API ut32 rz_hash_xxhash(const ut8 *input, size_t size) {
@ -99,7 +99,7 @@ RZ_API ut32 rz_hash_xxhash(const ut8 *input, size_t size) {
RZ_API double rz_hash_entropy(const ut8 *data, ut64 len) {
rz_return_val_if_fail(data, 0.0);
const RzMsgDigestPlugin *plugin = &rz_msg_digest_plugin_entropy;
const RzHashPlugin *plugin = &rz_hash_plugin_entropy;
ut8 *digest = NULL;
if (!plugin->small_block(data, len, &digest, NULL)) {
RZ_LOG_ERROR("msg digest: cannot calculate entropy\n");
@ -112,7 +112,7 @@ RZ_API double rz_hash_entropy(const ut8 *data, ut64 len) {
RZ_API double rz_hash_entropy_fraction(const ut8 *data, ut64 len) {
rz_return_val_if_fail(data, 0.0);
const RzMsgDigestPlugin *plugin = &rz_msg_digest_plugin_entropy_fract;
const RzHashPlugin *plugin = &rz_hash_plugin_entropy_fract;
ut8 *digest = NULL;
if (!plugin->small_block(data, len, &digest, NULL)) {
RZ_LOG_ERROR("msg digest: cannot calculate entropy fraction\n");
@ -123,13 +123,13 @@ RZ_API double rz_hash_entropy_fraction(const ut8 *data, ut64 len) {
return e;
}
static int msg_digest_config_compare(const void *value, const void *data) {
const MsgDigestConfig *mdc = (const MsgDigestConfig *)data;
static int hash_cfg_config_compare(const void *value, const void *data) {
const HashCfgConfig *mdc = (const HashCfgConfig *)data;
const char *name = (const char *)value;
return strcmp(name, mdc->plugin->name);
}
static void msg_digest_config_free(MsgDigestConfig *mdc) {
static void hash_cfg_config_free(HashCfgConfig *mdc) {
rz_return_if_fail(mdc && mdc->plugin);
mdc->plugin->context_free(mdc->context);
@ -138,10 +138,10 @@ static void msg_digest_config_free(MsgDigestConfig *mdc) {
free(mdc);
}
static MsgDigestConfig *msg_digest_config_new(const RzMsgDigestPlugin *plugin) {
static HashCfgConfig *hash_cfg_config_new(const RzHashPlugin *plugin) {
rz_return_val_if_fail(plugin, NULL);
MsgDigestConfig *mdc = RZ_NEW0(MsgDigestConfig);
HashCfgConfig *mdc = RZ_NEW0(HashCfgConfig);
if (!mdc) {
RZ_LOG_ERROR("msg digest: cannot allocate memory for config.\n");
return NULL;
@ -169,20 +169,20 @@ static MsgDigestConfig *msg_digest_config_new(const RzMsgDigestPlugin *plugin) {
return mdc;
}
RZ_API const RzMsgDigestPlugin *rz_msg_digest_plugin_by_index(size_t index) {
const size_t size = RZ_ARRAY_SIZE(msg_digest_plugins);
RZ_API const RzHashPlugin *rz_hash_plugin_by_index(size_t index) {
const size_t size = RZ_ARRAY_SIZE(hash_cfg_plugins);
if (index >= size) {
return NULL;
}
return msg_digest_plugins[index];
return hash_cfg_plugins[index];
}
RZ_API const RzMsgDigestPlugin *rz_msg_digest_plugin_by_name(const char *name) {
RZ_API const RzHashPlugin *rz_hash_plugin_by_name(const char *name) {
rz_return_val_if_fail(name, NULL);
const RzMsgDigestPlugin *plugin = NULL;
for (ut32 i = 0; i < RZ_ARRAY_SIZE(msg_digest_plugins); ++i) {
plugin = msg_digest_plugins[i];
const RzHashPlugin *plugin = NULL;
for (ut32 i = 0; i < RZ_ARRAY_SIZE(hash_cfg_plugins); ++i) {
plugin = hash_cfg_plugins[i];
if (!strcmp(plugin->name, name)) {
return plugin;
}
@ -190,14 +190,14 @@ RZ_API const RzMsgDigestPlugin *rz_msg_digest_plugin_by_name(const char *name) {
return NULL;
}
RZ_API RzMsgDigest *rz_msg_digest_new() {
RzMsgDigest *md = RZ_NEW0(RzMsgDigest);
RZ_API RzHashCfg *rz_hash_cfg_new() {
RzHashCfg *md = RZ_NEW0(RzHashCfg);
if (!md) {
RZ_LOG_ERROR("msg digest: cannot allocate memory.\n");
return NULL;
}
md->configurations = rz_list_newf((RzListFree)msg_digest_config_free);
md->configurations = rz_list_newf((RzListFree)hash_cfg_config_free);
if (!md->configurations) {
RZ_LOG_ERROR("msg digest: cannot allocate memory for the configurations.\n");
free(md);
@ -214,32 +214,32 @@ RZ_API RzMsgDigest *rz_msg_digest_new() {
* with the given algorithm and runs also the algo init.
* when fails to allocate or configure or initialize, returns NULL.
* */
RZ_API RzMsgDigest *rz_msg_digest_new_with_algo(const char *name, const ut8 *key, ut64 key_size) {
RZ_API RzHashCfg *rz_hash_cfg_new_with_algo(const char *name, const ut8 *key, ut64 key_size) {
rz_return_val_if_fail(name, NULL);
RzMsgDigest *md = rz_msg_digest_new();
RzHashCfg *md = rz_hash_cfg_new();
if (!md) {
return NULL;
}
if (!rz_msg_digest_configure(md, name)) {
rz_msg_digest_free(md);
if (!rz_hash_cfg_configure(md, name)) {
rz_hash_cfg_free(md);
return NULL;
}
if (key && !rz_msg_digest_hmac(md, key, key_size)) {
rz_msg_digest_free(md);
if (key && !rz_hash_cfg_hmac(md, key, key_size)) {
rz_hash_cfg_free(md);
return NULL;
}
if (!rz_msg_digest_init(md)) {
rz_msg_digest_free(md);
if (!rz_hash_cfg_init(md)) {
rz_hash_cfg_free(md);
return NULL;
}
return md;
}
RZ_API void rz_msg_digest_free(RzMsgDigest *md) {
RZ_API void rz_hash_cfg_free(RzHashCfg *md) {
rz_return_if_fail(md);
rz_list_free(md->configurations);
@ -249,13 +249,13 @@ RZ_API void rz_msg_digest_free(RzMsgDigest *md) {
/**
* \brief Allocates and configures the plugin message digest context
*
* message digest allocates internally a MsgDigestConfig which
* message digest allocates internally a HashCfgConfig which
* contains all the needed informations to the plugin to work.
* */
RZ_API bool rz_msg_digest_configure(RzMsgDigest *md, const char *name) {
RZ_API bool rz_hash_cfg_configure(RzHashCfg *md, const char *name) {
rz_return_val_if_fail(md && name, false);
if (rz_list_find(md->configurations, name, msg_digest_config_compare)) {
if (rz_list_find(md->configurations, name, hash_cfg_config_compare)) {
RZ_LOG_WARN("msg digest: '%s' was already configured; skipping.\n", name);
return false;
}
@ -267,20 +267,20 @@ RZ_API bool rz_msg_digest_configure(RzMsgDigest *md, const char *name) {
return false;
}
MsgDigestConfig *mdc = NULL;
const RzMsgDigestPlugin *plugin = NULL;
HashCfgConfig *mdc = NULL;
const RzHashPlugin *plugin = NULL;
for (ut32 i = 0; i < RZ_ARRAY_SIZE(msg_digest_plugins); ++i) {
plugin = msg_digest_plugins[i];
for (ut32 i = 0; i < RZ_ARRAY_SIZE(hash_cfg_plugins); ++i) {
plugin = hash_cfg_plugins[i];
if (is_all || !strcmp(plugin->name, name)) {
mdc = msg_digest_config_new(plugin);
mdc = hash_cfg_config_new(plugin);
if (!mdc) {
return false;
}
if (!rz_list_append(md->configurations, mdc)) {
RZ_LOG_ERROR("msg digest: cannot allocate memory for list entry.\n");
msg_digest_config_free(mdc);
hash_cfg_config_free(mdc);
return false;
}
@ -303,12 +303,12 @@ RZ_API bool rz_msg_digest_configure(RzMsgDigest *md, const char *name) {
*
* message digest sets the hmac key
* */
RZ_API bool rz_msg_digest_hmac(RzMsgDigest *md, const ut8 *key, ut64 key_size) {
rz_return_val_if_fail(md && key && key_size && msg_digest_can_hmac(md), false);
RZ_API bool rz_hash_cfg_hmac(RzHashCfg *md, const ut8 *key, ut64 key_size) {
rz_return_val_if_fail(md && key && key_size && hash_cfg_can_hmac(md), false);
RzMsgDigestSize block_size = 0;
RzHashSize block_size = 0;
RzListIter *iter = NULL;
MsgDigestConfig *mdc = NULL;
HashCfgConfig *mdc = NULL;
rz_list_foreach (md->configurations, iter, mdc) {
if (!mdc->plugin->support_hmac) {
// RZ_LOG_ERROR("msg digest: hmac is not supported by %s.\n", mdc->plugin->name);
@ -329,7 +329,7 @@ RZ_API bool rz_msg_digest_hmac(RzMsgDigest *md, const ut8 *key, ut64 key_size) {
memset(mdc->hmac_key, 0, block_size);
if (block_size < key_size) {
RzMsgDigestSize tmp_size;
RzHashSize tmp_size;
ut8 *tmp = NULL;
if (!mdc->plugin->small_block(key, key_size, &tmp, &tmp_size)) {
RZ_LOG_ERROR("msg digest: failed to call init for hmac %s key.\n", mdc->plugin->name);
@ -348,21 +348,21 @@ RZ_API bool rz_msg_digest_hmac(RzMsgDigest *md, const ut8 *key, ut64 key_size) {
/**
* \brief Resets/initialize the message digest contextes
*
* RzMsgDigest contains a list of configurations; this method will call
* RzHashCfg contains a list of configurations; this method will call
* the init method of all the plugins stored in its list.
* */
RZ_API bool rz_msg_digest_init(RzMsgDigest *md) {
rz_return_val_if_fail(md && msg_digest_can_init(md), false);
RZ_API bool rz_hash_cfg_init(RzHashCfg *md) {
rz_return_val_if_fail(md && hash_cfg_can_init(md), false);
RzListIter *iter = NULL;
MsgDigestConfig *mdc = NULL;
HashCfgConfig *mdc = NULL;
rz_list_foreach (md->configurations, iter, mdc) {
if (!mdc->plugin->init(mdc->context)) {
RZ_LOG_ERROR("msg digest: failed to call init for %s.\n", mdc->plugin->name);
return false;
}
if (mdc->hmac_key) {
RzMsgDigestSize block_size = mdc->plugin->block_size(mdc->context);
RzHashSize block_size = mdc->plugin->block_size(mdc->context);
ut8 *i_pad = malloc(block_size);
if (!i_pad) {
RZ_LOG_ERROR("msg digest: failed to allocate memory for ipad.\n");
@ -387,14 +387,14 @@ RZ_API bool rz_msg_digest_init(RzMsgDigest *md) {
/**
* \brief Inserts data into each the message digest contextes
*
* RzMsgDigest contains a list of configurations; this method will call
* RzHashCfg contains a list of configurations; this method will call
* the update method of all the plugins stored in its list.
* */
RZ_API bool rz_msg_digest_update(RzMsgDigest *md, const ut8 *data, ut64 size) {
rz_return_val_if_fail(md && msg_digest_can_update(md), false);
RZ_API bool rz_hash_cfg_update(RzHashCfg *md, const ut8 *data, ut64 size) {
rz_return_val_if_fail(md && hash_cfg_can_update(md), false);
RzListIter *iter = NULL;
MsgDigestConfig *mdc = NULL;
HashCfgConfig *mdc = NULL;
rz_list_foreach (md->configurations, iter, mdc) {
if (!mdc->plugin->update(mdc->context, data, size)) {
RZ_LOG_ERROR("msg digest: failed to call update for %s.\n", mdc->plugin->name);
@ -409,14 +409,14 @@ RZ_API bool rz_msg_digest_update(RzMsgDigest *md, const ut8 *data, ut64 size) {
/**
* \brief Generates the final value of the message digest contextes
*
* RzMsgDigest contains a list of configurations; this method will call
* RzHashCfg contains a list of configurations; this method will call
* the final method of all the plugins stored in its list.
* */
RZ_API bool rz_msg_digest_final(RzMsgDigest *md) {
rz_return_val_if_fail(md && msg_digest_can_final(md), false);
RZ_API bool rz_hash_cfg_final(RzHashCfg *md) {
rz_return_val_if_fail(md && hash_cfg_can_final(md), false);
RzListIter *iter = NULL;
MsgDigestConfig *mdc = NULL;
HashCfgConfig *mdc = NULL;
rz_list_foreach (md->configurations, iter, mdc) {
if (!mdc->plugin->final(mdc->context, mdc->digest)) {
RZ_LOG_ERROR("msg digest: failed to call final for %s.\n", mdc->plugin->name);
@ -424,7 +424,7 @@ RZ_API bool rz_msg_digest_final(RzMsgDigest *md) {
}
if (mdc->hmac_key) {
RzMsgDigestSize block_size = mdc->plugin->block_size(mdc->context);
RzHashSize block_size = mdc->plugin->block_size(mdc->context);
ut8 *o_pad = malloc(block_size);
if (!o_pad) {
RZ_LOG_ERROR("msg digest: failed to allocate memory for opad.\n");
@ -464,14 +464,14 @@ RZ_API bool rz_msg_digest_final(RzMsgDigest *md) {
/**
* \brief Calculate the final hash by iterating its result N times.
*
* RzMsgDigest contains a list of configurations; this method will iterate N times
* RzHashCfg contains a list of configurations; this method will iterate N times
* each configuration final result.
* */
RZ_API bool rz_msg_digest_iterate(RzMsgDigest *md, size_t iterate) {
rz_return_val_if_fail(md && msg_digest_has_finshed(md), false);
RZ_API bool rz_hash_cfg_iterate(RzHashCfg *md, size_t iterate) {
rz_return_val_if_fail(md && hash_cfg_has_finshed(md), false);
RzListIter *iter = NULL;
MsgDigestConfig *mdc = NULL;
HashCfgConfig *mdc = NULL;
rz_list_foreach (md->configurations, iter, mdc) {
for (size_t i = 0; i < iterate; ++i) {
if (!mdc->plugin->init(mdc->context)) {
@ -495,19 +495,19 @@ RZ_API bool rz_msg_digest_iterate(RzMsgDigest *md, size_t iterate) {
/**
* \brief Returns the digest value of the requested algorithm name
*
* RzMsgDigest contains a list of configurations; this method will search
* RzHashCfg contains a list of configurations; this method will search
* for the configuration with the given name and if found return the digest value.
* */
RZ_API const ut8 *rz_msg_digest_get_result(RzMsgDigest *md, const char *name, ut32 *size) {
rz_return_val_if_fail(md && name && msg_digest_has_finshed(md), false);
RZ_API const ut8 *rz_hash_cfg_get_result(RzHashCfg *md, const char *name, ut32 *size) {
rz_return_val_if_fail(md && name && hash_cfg_has_finshed(md), false);
RzListIter *it = rz_list_find(md->configurations, name, msg_digest_config_compare);
RzListIter *it = rz_list_find(md->configurations, name, hash_cfg_config_compare);
if (!it) {
RZ_LOG_ERROR("msg digest: cannot find configuration for '%s' algorithm.\n", name);
return NULL;
}
MsgDigestConfig *mdc = (MsgDigestConfig *)rz_list_iter_get_data(it);
HashCfgConfig *mdc = (HashCfgConfig *)rz_list_iter_get_data(it);
rz_return_val_if_fail(mdc, NULL);
if (size) {
@ -519,20 +519,20 @@ RZ_API const ut8 *rz_msg_digest_get_result(RzMsgDigest *md, const char *name, ut
/**
* \brief Returns the digest value of the requested algorithm name
*
* RzMsgDigest contains a list of configurations; this method will search
* RzHashCfg contains a list of configurations; this method will search
* for the configuration with the given name and if found return the digest value.
* */
RZ_API char *rz_msg_digest_get_result_string(RzMsgDigest *md, const char *name, ut32 *size, bool invert) {
rz_return_val_if_fail(md && name && msg_digest_has_finshed(md), false);
RZ_API char *rz_hash_cfg_get_result_string(RzHashCfg *md, const char *name, ut32 *size, bool invert) {
rz_return_val_if_fail(md && name && hash_cfg_has_finshed(md), false);
ut32 pos = 0;
RzListIter *it = rz_list_find(md->configurations, name, msg_digest_config_compare);
RzListIter *it = rz_list_find(md->configurations, name, hash_cfg_config_compare);
if (!it) {
RZ_LOG_ERROR("msg digest: cannot find configuration for '%s' algorithm.\n", name);
return NULL;
}
MsgDigestConfig *mdc = (MsgDigestConfig *)rz_list_iter_get_data(it);
HashCfgConfig *mdc = (HashCfgConfig *)rz_list_iter_get_data(it);
rz_return_val_if_fail(mdc, NULL);
if (!strncmp(name, "entropy", 7)) {
@ -563,16 +563,16 @@ RZ_API char *rz_msg_digest_get_result_string(RzMsgDigest *md, const char *name,
*
* Returns the digest size of the initialized configuration.
* */
RZ_API RzMsgDigestSize rz_msg_digest_size(RzMsgDigest *md, const char *name) {
RZ_API RzHashSize rz_hash_cfg_size(RzHashCfg *md, const char *name) {
rz_return_val_if_fail(md && name, 0);
RzListIter *it = rz_list_find(md->configurations, name, msg_digest_config_compare);
RzListIter *it = rz_list_find(md->configurations, name, hash_cfg_config_compare);
if (!it) {
RZ_LOG_ERROR("msg digest: cannot find configuration for '%s' algorithm.\n", name);
return 0;
}
MsgDigestConfig *mdc = (MsgDigestConfig *)rz_list_iter_get_data(it);
HashCfgConfig *mdc = (HashCfgConfig *)rz_list_iter_get_data(it);
rz_return_val_if_fail(mdc, 0);
return mdc->plugin->digest_size(mdc->context);
}
@ -582,14 +582,14 @@ RZ_API RzMsgDigestSize rz_msg_digest_size(RzMsgDigest *md, const char *name) {
*
* Returns the digest size of the initialized configuration.
* */
RZ_API ut8 *rz_msg_digest_calculate_small_block(const char *name, const ut8 *buffer, ut64 bsize, RzMsgDigestSize *osize) {
RZ_API ut8 *rz_hash_cfg_calculate_small_block(const char *name, const ut8 *buffer, ut64 bsize, RzHashSize *osize) {
rz_return_val_if_fail(name && buffer, NULL);
ut8 *result = NULL;
const RzMsgDigestPlugin *plugin = NULL;
const RzHashPlugin *plugin = NULL;
for (ut32 i = 0; i < RZ_ARRAY_SIZE(msg_digest_plugins); ++i) {
plugin = msg_digest_plugins[i];
for (ut32 i = 0; i < RZ_ARRAY_SIZE(hash_cfg_plugins); ++i) {
plugin = hash_cfg_plugins[i];
if (!strcmp(plugin->name, name)) {
if (!plugin->small_block(buffer, bsize, &result, osize)) {
RZ_LOG_ERROR("msg digest: cannot calculate small block with %s.\n", plugin->name);
@ -602,13 +602,13 @@ RZ_API ut8 *rz_msg_digest_calculate_small_block(const char *name, const ut8 *buf
return NULL;
}
RZ_API char *rz_msg_digest_calculate_small_block_string(const char *name, const ut8 *buffer, ut64 bsize, ut32 *size, bool invert) {
RZ_API char *rz_hash_cfg_calculate_small_block_string(const char *name, const ut8 *buffer, ut64 bsize, ut32 *size, bool invert) {
rz_return_val_if_fail(name && buffer, NULL);
ut32 pos = 0;
RzMsgDigestSize digest_size = 0;
RzHashSize digest_size = 0;
ut8 *digest = NULL;
if (!(digest = rz_msg_digest_calculate_small_block(name, buffer, bsize, &digest_size))) {
if (!(digest = rz_hash_cfg_calculate_small_block(name, buffer, bsize, &digest_size))) {
return NULL;
}

View file

@ -1,5 +1,5 @@
rz_hash_sources = [
'msg_digest.c',
'hash.c',
'randomart.c',
'p/algo_crca.c',
'p/algo_adler32.c',

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#include "../algorithms/adler32/adler32.h"
@ -14,11 +14,11 @@ static void plugin_adler32_context_free(void *context) {
free(context);
}
static RzMsgDigestSize plugin_adler32_digest_size(void *context) {
static RzHashSize plugin_adler32_digest_size(void *context) {
return RZ_HASH_ADLER32_DIGEST_SIZE;
}
static RzMsgDigestSize plugin_adler32_block_size(void *context) {
static RzHashSize plugin_adler32_block_size(void *context) {
return RZ_HASH_ADLER32_BLOCK_LENGTH;
}
@ -43,7 +43,7 @@ static bool plugin_adler32_final(void *context, ut8 *digest) {
return true;
}
static bool plugin_adler32_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) {
static bool plugin_adler32_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
rz_return_val_if_fail(data && digest, false);
ut8 *dgst = malloc(RZ_HASH_ADLER32_DIGEST_SIZE);
if (!dgst) {
@ -62,7 +62,7 @@ static bool plugin_adler32_small_block(const ut8 *data, ut64 size, ut8 **digest,
return true;
}
RzMsgDigestPlugin rz_msg_digest_plugin_adler32 = {
RzHashPlugin rz_hash_plugin_adler32 = {
.name = "adler32",
.license = "LGPL3",
.author = "deroad",
@ -79,8 +79,8 @@ RzMsgDigestPlugin rz_msg_digest_plugin_adler32 = {
#ifndef RZ_PLUGIN_INCORE
RZ_API RzLibStruct rizin_plugin = {
.type = RZ_LIB_TYPE_MD,
.data = &rz_msg_digest_plugin_adler32,
.type = RZ_LIB_TYPE_HASH,
.data = &rz_hash_plugin_adler32,
.version = RZ_VERSION
};
#endif

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#include "../algorithms/crc/crca.h"
@ -24,7 +24,7 @@
}
#define plugin_crca_preset_small_block(crcalgo, preset) \
static bool plugin_crca_##crcalgo##_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) { \
static bool plugin_crca_##crcalgo##_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) { \
rz_return_val_if_fail(data &&digest, false); \
RzCrc ctx; \
crc_init_preset(&ctx, preset); \
@ -45,7 +45,7 @@ static void plugin_crca_context_free(void *context) {
free(context);
}
static RzMsgDigestSize plugin_crca_digest_size(void *context) {
static RzHashSize plugin_crca_digest_size(void *context) {
rz_return_val_if_fail(context, 0);
RzCrc *ctx = (RzCrc *)context;
if (ctx->size <= 8) {
@ -61,7 +61,7 @@ static RzMsgDigestSize plugin_crca_digest_size(void *context) {
return 0;
}
static RzMsgDigestSize plugin_crca_block_size(void *context) {
static RzHashSize plugin_crca_block_size(void *context) {
return 0;
}
@ -91,11 +91,11 @@ static bool plugin_crca_final(void *context, ut8 *digest) {
return true;
}
#define rz_msg_digest_plugin_crca_preset(crcalgo, preset) \
#define rz_hash_plugin_crca_preset(crcalgo, preset) \
plugin_crca_preset_context_new(crcalgo, preset); \
plugin_crca_preset_init(crcalgo, preset); \
plugin_crca_preset_small_block(crcalgo, preset); \
RzMsgDigestPlugin rz_msg_digest_plugin_crca_##crcalgo = { \
RzHashPlugin rz_hash_plugin_crca_##crcalgo = { \
.name = #crcalgo, \
.license = "LGPL3", \
.author = "deroad", \
@ -113,8 +113,8 @@ static bool plugin_crca_final(void *context, ut8 *digest) {
#ifndef RZ_PLUGIN_INCORE
#define rz_lib_plugin_crca_preset(crcalgo) \
RZ_API RzLibStruct rizin_plugin = { \
.type = RZ_LIB_TYPE_MD, \
.data = &rz_msg_digest_plugin_crca_##crcalgo, \
.type = RZ_LIB_TYPE_HASH, \
.data = &rz_hash_plugin_crca_##crcalgo, \
.version = RZ_VERSION \
}
#else
@ -122,7 +122,7 @@ static bool plugin_crca_final(void *context, ut8 *digest) {
#endif
#define rz_plugin_crca_preset_definition(crcalgo, preset) \
rz_msg_digest_plugin_crca_preset(crcalgo, preset); \
rz_hash_plugin_crca_preset(crcalgo, preset); \
rz_lib_plugin_crca_preset(crcalgo)
rz_plugin_crca_preset_definition(crc8smbus, /* */ CRC_PRESET_8_SMBUS);

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#include "../algorithms/entropy/entropy.h"
@ -14,11 +14,11 @@ static void plugin_entropy_context_free(void *context) {
free(context);
}
static RzMsgDigestSize plugin_entropy_digest_size(void *context) {
static RzHashSize plugin_entropy_digest_size(void *context) {
return RZ_HASH_ENTROPY_DIGEST_SIZE;
}
static RzMsgDigestSize plugin_entropy_block_size(void *context) {
static RzHashSize plugin_entropy_block_size(void *context) {
return RZ_HASH_ENTROPY_BLOCK_LENGTH;
}
@ -43,7 +43,7 @@ static bool plugin_entropy_final(void *context, ut8 *digest) {
return true;
}
static bool plugin_entropy_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) {
static bool plugin_entropy_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
rz_return_val_if_fail(data && digest, false);
ut8 *dgst = malloc(RZ_HASH_ENTROPY_DIGEST_SIZE);
if (!dgst) {
@ -62,7 +62,7 @@ static bool plugin_entropy_small_block(const ut8 *data, ut64 size, ut8 **digest,
return true;
}
RzMsgDigestPlugin rz_msg_digest_plugin_entropy = {
RzHashPlugin rz_hash_plugin_entropy = {
.name = "entropy",
.license = "LGPL3",
.author = "deroad",
@ -79,8 +79,8 @@ RzMsgDigestPlugin rz_msg_digest_plugin_entropy = {
#ifndef RZ_PLUGIN_INCORE
RZ_API RzLibStruct rizin_plugin = {
.type = RZ_LIB_TYPE_MD,
.data = &rz_msg_digest_plugin_entropy,
.type = RZ_LIB_TYPE_HASH,
.data = &rz_hash_plugin_entropy,
.version = RZ_VERSION
};
#endif

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#include "../algorithms/entropy/entropy.h"
@ -14,11 +14,11 @@ static void plugin_entropy_context_free(void *context) {
free(context);
}
static RzMsgDigestSize plugin_entropy_digest_size(void *context) {
static RzHashSize plugin_entropy_digest_size(void *context) {
return sizeof(double);
}
static RzMsgDigestSize plugin_entropy_block_size(void *context) {
static RzHashSize plugin_entropy_block_size(void *context) {
return 0;
}
@ -43,7 +43,7 @@ static bool plugin_entropy_final(void *context, ut8 *digest) {
return true;
}
static bool plugin_entropy_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) {
static bool plugin_entropy_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
rz_return_val_if_fail(data && digest, false);
ut8 *dgst = malloc(sizeof(double));
if (!dgst) {
@ -62,7 +62,7 @@ static bool plugin_entropy_small_block(const ut8 *data, ut64 size, ut8 **digest,
return true;
}
RzMsgDigestPlugin rz_msg_digest_plugin_entropy_fract = {
RzHashPlugin rz_hash_plugin_entropy_fract = {
.name = "entropy_fract",
.license = "LGPL3",
.author = "deroad",
@ -79,8 +79,8 @@ RzMsgDigestPlugin rz_msg_digest_plugin_entropy_fract = {
#ifndef RZ_PLUGIN_INCORE
RZ_API RzLibStruct rizin_plugin = {
.type = RZ_LIB_TYPE_MD,
.data = &rz_msg_digest_plugin_entropy_fract,
.type = RZ_LIB_TYPE_HASH,
.data = &rz_hash_plugin_entropy_fract,
.version = RZ_VERSION
};
#endif

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#include "../algorithms/fletcher/fletcher.h"
@ -17,7 +17,7 @@
}
#define rz_fletcher_common_plugin_digest_size(bits) \
static RzMsgDigestSize plugin_fletcher##bits##_digest_size(void *context) { \
static RzHashSize plugin_fletcher##bits##_digest_size(void *context) { \
return RZ_HASH_FLETCHER##bits##_DIGEST_SIZE; \
}
@ -43,7 +43,7 @@
}
#define rz_fletcher_common_plugin_small_block(bits) \
static bool plugin_fletcher##bits##_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) { \
static bool plugin_fletcher##bits##_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) { \
rz_return_val_if_fail(data &&digest, false); \
ut8 *dgst = malloc(RZ_HASH_FLETCHER##bits##_DIGEST_SIZE); \
if (!dgst) { \
@ -63,15 +63,15 @@
#ifndef RZ_PLUGIN_INCORE
#define rz_lib_fletcher_common(bits) \
RZ_API RzLibStruct rizin_plugin = { \
.type = RZ_LIB_TYPE_MD, \
.data = &rz_msg_digest_plugin_fletcher##bits, \
.type = RZ_LIB_TYPE_HASH, \
.data = &rz_hash_plugin_fletcher##bits, \
.version = RZ_VERSION \
}
#else
#define rz_lib_fletcher_common(bits)
#endif
#define rz_fletcher_common_plugin_define_msg_digest(bits) \
#define rz_fletcher_common_plugin_define_hash_cfg(bits) \
rz_fletcher_common_plugin_context_new(bits); \
rz_fletcher_common_plugin_context_free(bits); \
rz_fletcher_common_plugin_digest_size(bits); \
@ -79,7 +79,7 @@
rz_fletcher_common_plugin_update(bits); \
rz_fletcher_common_plugin_final(bits); \
rz_fletcher_common_plugin_small_block(bits); \
RzMsgDigestPlugin rz_msg_digest_plugin_fletcher##bits = { \
RzHashPlugin rz_hash_plugin_fletcher##bits = { \
.name = "fletcher" #bits, \
.license = "LGPL3", \
.author = "deroad", \
@ -95,11 +95,11 @@
}; \
rz_lib_fletcher_common(bits)
static RzMsgDigestSize plugin_fletcher_block_size(void *context) {
static RzHashSize plugin_fletcher_block_size(void *context) {
return RZ_HASH_FLETCHER_BLOCK_LENGTH;
}
rz_fletcher_common_plugin_define_msg_digest(8);
rz_fletcher_common_plugin_define_msg_digest(16);
rz_fletcher_common_plugin_define_msg_digest(32);
rz_fletcher_common_plugin_define_msg_digest(64);
rz_fletcher_common_plugin_define_hash_cfg(8);
rz_fletcher_common_plugin_define_hash_cfg(16);
rz_fletcher_common_plugin_define_hash_cfg(32);
rz_fletcher_common_plugin_define_hash_cfg(64);

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#if HAVE_LIB_SSL
@ -10,7 +10,7 @@
*/
#include "../algorithms/openssl_common.h"
rz_openssl_plugin_define_msg_digest(md4, EVP_md4, true);
rz_openssl_plugin_define_hash_cfg(md4, EVP_md4, true);
#else /* HAVE_LIB_SSL */
/**
@ -27,11 +27,11 @@ static void plugin_md4_context_free(void *context) {
free(context);
}
static RzMsgDigestSize plugin_md4_digest_size(void *context) {
static RzHashSize plugin_md4_digest_size(void *context) {
return RZ_HASH_MD4_DIGEST_SIZE;
}
static RzMsgDigestSize plugin_md4_block_size(void *context) {
static RzHashSize plugin_md4_block_size(void *context) {
return RZ_HASH_MD4_BLOCK_LENGTH;
}
@ -56,7 +56,7 @@ static bool plugin_md4_final(void *context, ut8 *digest) {
return true;
}
static bool plugin_md4_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) {
static bool plugin_md4_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
rz_return_val_if_fail(data && digest, false);
ut8 *dgst = malloc(RZ_HASH_MD4_DIGEST_SIZE);
if (!dgst) {
@ -75,7 +75,7 @@ static bool plugin_md4_small_block(const ut8 *data, ut64 size, ut8 **digest, RzM
return true;
}
RzMsgDigestPlugin rz_msg_digest_plugin_md4 = {
RzHashPlugin rz_hash_plugin_md4 = {
.name = "md4",
.license = "LGPL3",
.author = "deroad",
@ -94,8 +94,8 @@ RzMsgDigestPlugin rz_msg_digest_plugin_md4 = {
#ifndef RZ_PLUGIN_INCORE
RZ_API RzLibStruct rizin_plugin = {
.type = RZ_LIB_TYPE_MD,
.data = &rz_msg_digest_plugin_md4,
.type = RZ_LIB_TYPE_HASH,
.data = &rz_hash_plugin_md4,
.version = RZ_VERSION
};
#endif

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#if HAVE_LIB_SSL
@ -10,7 +10,7 @@
*/
#include "../algorithms/openssl_common.h"
rz_openssl_plugin_define_msg_digest(md5, EVP_md5, true);
rz_openssl_plugin_define_hash_cfg(md5, EVP_md5, true);
#else /* HAVE_LIB_SSL */
/**
@ -27,11 +27,11 @@ static void plugin_md5_context_free(void *context) {
free(context);
}
static RzMsgDigestSize plugin_md5_digest_size(void *context) {
static RzHashSize plugin_md5_digest_size(void *context) {
return RZ_HASH_MD5_DIGEST_SIZE;
}
static RzMsgDigestSize plugin_md5_block_size(void *context) {
static RzHashSize plugin_md5_block_size(void *context) {
return RZ_HASH_MD5_BLOCK_LENGTH;
}
@ -56,7 +56,7 @@ static bool plugin_md5_final(void *context, ut8 *digest) {
return true;
}
static bool plugin_md5_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) {
static bool plugin_md5_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
rz_return_val_if_fail(data && digest, false);
ut8 *dgst = malloc(RZ_HASH_MD5_DIGEST_SIZE);
if (!dgst) {
@ -75,7 +75,7 @@ static bool plugin_md5_small_block(const ut8 *data, ut64 size, ut8 **digest, RzM
return true;
}
RzMsgDigestPlugin rz_msg_digest_plugin_md5 = {
RzHashPlugin rz_hash_plugin_md5 = {
.name = "md5",
.license = "LGPL2",
.author = "Alan DeKok (md5 algorithm implementation), deroad (plugin)",
@ -94,8 +94,8 @@ RzMsgDigestPlugin rz_msg_digest_plugin_md5 = {
#ifndef RZ_PLUGIN_INCORE
RZ_API RzLibStruct rizin_plugin = {
.type = RZ_LIB_TYPE_MD,
.data = &rz_msg_digest_plugin_md5,
.type = RZ_LIB_TYPE_HASH,
.data = &rz_hash_plugin_md5,
.version = RZ_VERSION
};
#endif

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#include "../algorithms/mod255/mod255.h"
@ -14,11 +14,11 @@ static void plugin_mod255_context_free(void *context) {
free(context);
}
static RzMsgDigestSize plugin_mod255_digest_size(void *context) {
static RzHashSize plugin_mod255_digest_size(void *context) {
return RZ_HASH_MOD255_DIGEST_SIZE;
}
static RzMsgDigestSize plugin_mod255_block_size(void *context) {
static RzHashSize plugin_mod255_block_size(void *context) {
return RZ_HASH_MOD255_BLOCK_LENGTH;
}
@ -43,7 +43,7 @@ static bool plugin_mod255_final(void *context, ut8 *digest) {
return true;
}
static bool plugin_mod255_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) {
static bool plugin_mod255_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
rz_return_val_if_fail(data && digest, false);
ut8 *dgst = malloc(RZ_HASH_MOD255_DIGEST_SIZE);
if (!dgst) {
@ -62,7 +62,7 @@ static bool plugin_mod255_small_block(const ut8 *data, ut64 size, ut8 **digest,
return true;
}
RzMsgDigestPlugin rz_msg_digest_plugin_mod255 = {
RzHashPlugin rz_hash_plugin_mod255 = {
.name = "mod255",
.license = "LGPL3",
.author = "deroad",
@ -79,8 +79,8 @@ RzMsgDigestPlugin rz_msg_digest_plugin_mod255 = {
#ifndef RZ_PLUGIN_INCORE
RZ_API RzLibStruct rizin_plugin = {
.type = RZ_LIB_TYPE_MD,
.data = &rz_msg_digest_plugin_mod255,
.type = RZ_LIB_TYPE_HASH,
.data = &rz_hash_plugin_mod255,
.version = RZ_VERSION
};
#endif

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#include "../algorithms/parity/parity.h"
@ -14,11 +14,11 @@ static void plugin_parity_context_free(void *context) {
free(context);
}
static RzMsgDigestSize plugin_parity_digest_size(void *context) {
static RzHashSize plugin_parity_digest_size(void *context) {
return RZ_HASH_PARITY_DIGEST_SIZE;
}
static RzMsgDigestSize plugin_parity_block_size(void *context) {
static RzHashSize plugin_parity_block_size(void *context) {
return RZ_HASH_PARITY_BLOCK_LENGTH;
}
@ -43,7 +43,7 @@ static bool plugin_parity_final(void *context, ut8 *digest) {
return true;
}
static bool plugin_parity_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) {
static bool plugin_parity_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
rz_return_val_if_fail(data && digest, false);
ut8 *dgst = malloc(RZ_HASH_PARITY_DIGEST_SIZE);
if (!dgst) {
@ -62,7 +62,7 @@ static bool plugin_parity_small_block(const ut8 *data, ut64 size, ut8 **digest,
return true;
}
RzMsgDigestPlugin rz_msg_digest_plugin_parity = {
RzHashPlugin rz_hash_plugin_parity = {
.name = "parity",
.license = "LGPL3",
.author = "deroad",
@ -79,8 +79,8 @@ RzMsgDigestPlugin rz_msg_digest_plugin_parity = {
#ifndef RZ_PLUGIN_INCORE
RZ_API RzLibStruct rizin_plugin = {
.type = RZ_LIB_TYPE_MD,
.data = &rz_msg_digest_plugin_parity,
.type = RZ_LIB_TYPE_HASH,
.data = &rz_hash_plugin_parity,
.version = RZ_VERSION
};
#endif

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#if HAVE_LIB_SSL
@ -10,7 +10,7 @@
*/
#include "../algorithms/openssl_common.h"
rz_openssl_plugin_define_msg_digest(sha1, EVP_sha1, true);
rz_openssl_plugin_define_hash_cfg(sha1, EVP_sha1, true);
#else /* HAVE_LIB_SSL */
/**
@ -27,11 +27,11 @@ static void plugin_sha1_context_free(void *context) {
free(context);
}
static RzMsgDigestSize plugin_sha1_digest_size(void *context) {
static RzHashSize plugin_sha1_digest_size(void *context) {
return RZ_HASH_SHA1_DIGEST_SIZE;
}
static RzMsgDigestSize plugin_sha1_block_size(void *context) {
static RzHashSize plugin_sha1_block_size(void *context) {
return RZ_HASH_SHA1_BLOCK_LENGTH;
}
@ -56,7 +56,7 @@ static bool plugin_sha1_final(void *context, ut8 *digest) {
return true;
}
static bool plugin_sha1_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) {
static bool plugin_sha1_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
rz_return_val_if_fail(data && digest, false);
ut8 *dgst = malloc(RZ_HASH_SHA1_DIGEST_SIZE);
if (!dgst) {
@ -75,7 +75,7 @@ static bool plugin_sha1_small_block(const ut8 *data, ut64 size, ut8 **digest, Rz
return true;
}
RzMsgDigestPlugin rz_msg_digest_plugin_sha1 = {
RzHashPlugin rz_hash_plugin_sha1 = {
.name = "sha1",
.license = "LGPL3",
.author = "deroad",
@ -94,8 +94,8 @@ RzMsgDigestPlugin rz_msg_digest_plugin_sha1 = {
#ifndef RZ_PLUGIN_INCORE
RZ_API RzLibStruct rizin_plugin = {
.type = RZ_LIB_TYPE_MD,
.data = &rz_msg_digest_plugin_sha1,
.type = RZ_LIB_TYPE_HASH,
.data = &rz_hash_plugin_sha1,
.version = RZ_VERSION
};
#endif

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#if HAVE_LIB_SSL
@ -10,7 +10,7 @@
*/
#include "../algorithms/openssl_common.h"
rz_openssl_plugin_define_msg_digest(sha256, EVP_sha256, true);
rz_openssl_plugin_define_hash_cfg(sha256, EVP_sha256, true);
#else /* HAVE_LIB_SSL */
/**
@ -27,11 +27,11 @@ static void plugin_sha256_context_free(void *context) {
free(context);
}
static RzMsgDigestSize plugin_sha256_digest_size(void *context) {
static RzHashSize plugin_sha256_digest_size(void *context) {
return SHA256_DIGEST_LENGTH;
}
static RzMsgDigestSize plugin_sha256_block_size(void *context) {
static RzHashSize plugin_sha256_block_size(void *context) {
return SHA256_BLOCK_LENGTH;
}
@ -56,7 +56,7 @@ static bool plugin_sha256_final(void *context, ut8 *digest) {
return true;
}
static bool plugin_sha256_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) {
static bool plugin_sha256_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
rz_return_val_if_fail(data && digest, false);
ut8 *dgst = malloc(SHA256_DIGEST_LENGTH);
if (!dgst) {
@ -75,7 +75,7 @@ static bool plugin_sha256_small_block(const ut8 *data, ut64 size, ut8 **digest,
return true;
}
RzMsgDigestPlugin rz_msg_digest_plugin_sha256 = {
RzHashPlugin rz_hash_plugin_sha256 = {
.name = "sha256",
.author = "Aaron D. Gifford",
.license = "BSD-3",
@ -94,8 +94,8 @@ RzMsgDigestPlugin rz_msg_digest_plugin_sha256 = {
#ifndef RZ_PLUGIN_INCORE
RZ_API RzLibStruct rizin_plugin = {
.type = RZ_LIB_TYPE_MD,
.data = &rz_msg_digest_plugin_sha256,
.type = RZ_LIB_TYPE_HASH,
.data = &rz_hash_plugin_sha256,
.version = RZ_VERSION
};
#endif

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#if HAVE_LIB_SSL
@ -10,7 +10,7 @@
*/
#include "../algorithms/openssl_common.h"
rz_openssl_plugin_define_msg_digest(sha384, EVP_sha384, true);
rz_openssl_plugin_define_hash_cfg(sha384, EVP_sha384, true);
#else /* HAVE_LIB_SSL */
/**
@ -27,11 +27,11 @@ static void plugin_sha384_context_free(void *context) {
free(context);
}
static RzMsgDigestSize plugin_sha384_digest_size(void *context) {
static RzHashSize plugin_sha384_digest_size(void *context) {
return SHA384_DIGEST_LENGTH;
}
static RzMsgDigestSize plugin_sha384_block_size(void *context) {
static RzHashSize plugin_sha384_block_size(void *context) {
return SHA384_BLOCK_LENGTH;
}
@ -56,7 +56,7 @@ static bool plugin_sha384_final(void *context, ut8 *digest) {
return true;
}
static bool plugin_sha384_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) {
static bool plugin_sha384_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
rz_return_val_if_fail(data && digest, false);
ut8 *dgst = malloc(SHA384_DIGEST_LENGTH);
if (!dgst) {
@ -75,7 +75,7 @@ static bool plugin_sha384_small_block(const ut8 *data, ut64 size, ut8 **digest,
return true;
}
RzMsgDigestPlugin rz_msg_digest_plugin_sha384 = {
RzHashPlugin rz_hash_plugin_sha384 = {
.name = "sha384",
.author = "Aaron D. Gifford",
.license = "BSD-3",
@ -94,8 +94,8 @@ RzMsgDigestPlugin rz_msg_digest_plugin_sha384 = {
#ifndef RZ_PLUGIN_INCORE
RZ_API RzLibStruct rizin_plugin = {
.type = RZ_LIB_TYPE_MD,
.data = &rz_msg_digest_plugin_sha384,
.type = RZ_LIB_TYPE_HASH,
.data = &rz_hash_plugin_sha384,
.version = RZ_VERSION
};
#endif

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#if HAVE_LIB_SSL
@ -10,7 +10,7 @@
*/
#include "../algorithms/openssl_common.h"
rz_openssl_plugin_define_msg_digest(sha512, EVP_sha512, true);
rz_openssl_plugin_define_hash_cfg(sha512, EVP_sha512, true);
#else /* HAVE_LIB_SSL */
/**
@ -27,11 +27,11 @@ static void plugin_sha512_context_free(void *context) {
free(context);
}
static RzMsgDigestSize plugin_sha512_digest_size(void *context) {
static RzHashSize plugin_sha512_digest_size(void *context) {
return SHA512_DIGEST_LENGTH;
}
static RzMsgDigestSize plugin_sha512_block_size(void *context) {
static RzHashSize plugin_sha512_block_size(void *context) {
return SHA512_BLOCK_LENGTH;
}
@ -56,7 +56,7 @@ static bool plugin_sha512_final(void *context, ut8 *digest) {
return true;
}
static bool plugin_sha512_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) {
static bool plugin_sha512_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
rz_return_val_if_fail(data && digest, false);
ut8 *dgst = malloc(SHA512_DIGEST_LENGTH);
if (!dgst) {
@ -75,7 +75,7 @@ static bool plugin_sha512_small_block(const ut8 *data, ut64 size, ut8 **digest,
return true;
}
RzMsgDigestPlugin rz_msg_digest_plugin_sha512 = {
RzHashPlugin rz_hash_plugin_sha512 = {
.name = "sha512",
.author = "Aaron D. Gifford",
.license = "BSD-3",
@ -94,8 +94,8 @@ RzMsgDigestPlugin rz_msg_digest_plugin_sha512 = {
#ifndef RZ_PLUGIN_INCORE
RZ_API RzLibStruct rizin_plugin = {
.type = RZ_LIB_TYPE_MD,
.data = &rz_msg_digest_plugin_sha512,
.type = RZ_LIB_TYPE_HASH,
.data = &rz_hash_plugin_sha512,
.version = RZ_VERSION
};
#endif

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#include "../algorithms/xor/xor.h"
@ -14,11 +14,11 @@ static void plugin_xor16_context_free(void *context) {
free(context);
}
static RzMsgDigestSize plugin_xor16_digest_size(void *context) {
static RzHashSize plugin_xor16_digest_size(void *context) {
return RZ_HASH_XOR16_DIGEST_SIZE;
}
static RzMsgDigestSize plugin_xor16_block_size(void *context) {
static RzHashSize plugin_xor16_block_size(void *context) {
return RZ_HASH_XOR_BLOCK_LENGTH;
}
@ -43,7 +43,7 @@ static bool plugin_xor16_final(void *context, ut8 *digest) {
return true;
}
static bool plugin_xor16_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) {
static bool plugin_xor16_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
rz_return_val_if_fail(data && digest, false);
ut8 *dgst = malloc(RZ_HASH_XOR16_DIGEST_SIZE);
if (!dgst) {
@ -62,7 +62,7 @@ static bool plugin_xor16_small_block(const ut8 *data, ut64 size, ut8 **digest, R
return true;
}
RzMsgDigestPlugin rz_msg_digest_plugin_xor16 = {
RzHashPlugin rz_hash_plugin_xor16 = {
.name = "xor16",
.license = "LGPL3",
.author = "deroad",
@ -79,8 +79,8 @@ RzMsgDigestPlugin rz_msg_digest_plugin_xor16 = {
#ifndef RZ_PLUGIN_INCORE
RZ_API RzLibStruct rizin_plugin = {
.type = RZ_LIB_TYPE_MD,
.data = &rz_msg_digest_plugin_xor16,
.type = RZ_LIB_TYPE_HASH,
.data = &rz_hash_plugin_xor16,
.version = RZ_VERSION
};
#endif

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#include "../algorithms/xor/xor.h"
@ -14,11 +14,11 @@ static void plugin_xor8_context_free(void *context) {
free(context);
}
static RzMsgDigestSize plugin_xor8_digest_size(void *context) {
static RzHashSize plugin_xor8_digest_size(void *context) {
return RZ_HASH_XOR8_DIGEST_SIZE;
}
static RzMsgDigestSize plugin_xor8_block_size(void *context) {
static RzHashSize plugin_xor8_block_size(void *context) {
return RZ_HASH_XOR_BLOCK_LENGTH;
}
@ -43,7 +43,7 @@ static bool plugin_xor8_final(void *context, ut8 *digest) {
return true;
}
static bool plugin_xor8_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) {
static bool plugin_xor8_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
rz_return_val_if_fail(data && digest, false);
ut8 *dgst = malloc(RZ_HASH_XOR8_DIGEST_SIZE);
if (!dgst) {
@ -62,7 +62,7 @@ static bool plugin_xor8_small_block(const ut8 *data, ut64 size, ut8 **digest, Rz
return true;
}
RzMsgDigestPlugin rz_msg_digest_plugin_xor8 = {
RzHashPlugin rz_hash_plugin_xor8 = {
.name = "xor8",
.license = "LGPL3",
.author = "deroad",
@ -79,8 +79,8 @@ RzMsgDigestPlugin rz_msg_digest_plugin_xor8 = {
#ifndef RZ_PLUGIN_INCORE
RZ_API RzLibStruct rizin_plugin = {
.type = RZ_LIB_TYPE_MD,
.data = &rz_msg_digest_plugin_xor8,
.type = RZ_LIB_TYPE_HASH,
.data = &rz_hash_plugin_xor8,
.version = RZ_VERSION
};
#endif

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_assert.h>
#include <xxhash.h>
@ -16,11 +16,11 @@ static void plugin_xxhash32_context_free(void *context) {
XXH32_freeState((XXH32_state_t *)context);
}
static RzMsgDigestSize plugin_xxhash32_digest_size(void *context) {
static RzHashSize plugin_xxhash32_digest_size(void *context) {
return RZ_HASH_XXHASH32_DIGEST_SIZE;
}
static RzMsgDigestSize plugin_xxhash32_block_size(void *context) {
static RzHashSize plugin_xxhash32_block_size(void *context) {
return RZ_HASH_XXHASH32_BLOCK_LENGTH;
}
@ -46,7 +46,7 @@ static bool plugin_xxhash32_final(void *context, ut8 *digest) {
return true;
}
static bool plugin_xxhash32_small_block(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size) {
static bool plugin_xxhash32_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
rz_return_val_if_fail(data && digest, false);
ut8 *dgst = malloc(RZ_HASH_XXHASH32_DIGEST_SIZE);
if (!dgst) {
@ -63,7 +63,7 @@ static bool plugin_xxhash32_small_block(const ut8 *data, ut64 size, ut8 **digest
return true;
}
RzMsgDigestPlugin rz_msg_digest_plugin_xxhash32 = {
RzHashPlugin rz_hash_plugin_xxhash32 = {
.name = "xxhash32",
.license = "LGPL3",
.author = "deroad",
@ -80,8 +80,8 @@ RzMsgDigestPlugin rz_msg_digest_plugin_xxhash32 = {
#ifndef RZ_PLUGIN_INCORE
RZ_API RzLibStruct rizin_plugin = {
.type = RZ_LIB_TYPE_MD,
.data = &rz_msg_digest_plugin_xxhash32,
.type = RZ_LIB_TYPE_HASH,
.data = &rz_hash_plugin_xxhash32,
.version = RZ_VERSION
};
#endif

View file

@ -37,7 +37,7 @@
* Else pictures would be too dense, and drawing the frame would
* fail, too, because the key type would not fit in anymore.
*/
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util.h>
#define FLDBASE 8
@ -52,7 +52,7 @@
* \param addr The location of the hash (when unknown can be set to 0).
* \return
*/
RZ_API RZ_OWN char *rz_msg_digest_randomart(RZ_NONNULL const ut8 *buffer, ut32 length, ut64 address) {
RZ_API RZ_OWN char *rz_hash_cfg_randomart(RZ_NONNULL const ut8 *buffer, ut32 length, ut64 address) {
rz_return_val_if_fail(buffer && length > 0, NULL);
/*
* Chars to be used after each other every time the worm

View file

@ -31,7 +31,7 @@ include_files = [
'rz_list.h',
'rz_magic.h',
'rz_main.h',
'rz_msg_digest.h',
'rz_hash.h',
'rz_parse.h',
'rz_pdb.h',
'rz_platform.h',

View file

@ -24,7 +24,7 @@
#include <rz_flag.h>
#include <rz_config.h>
#include <rz_bin.h>
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util.h>
#include <ht_uu.h>
#include <rz_util/rz_print.h>

View file

@ -9,7 +9,7 @@
#include <rz_egg.h>
#include <rz_bp.h>
#include <rz_io.h>
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_syscall.h>
#include <rz_cmd.h>
@ -591,7 +591,7 @@ RZ_API void rz_debug_session_free(RzDebugSession *session);
RZ_API RzDebugSnap *rz_debug_snap_map(RzDebug *dbg, RzDebugMap *map);
RZ_API bool rz_debug_snap_contains(RzDebugSnap *snap, ut64 addr);
RZ_API ut8 *rz_debug_snap_get_hash(RzDebugSnap *snap, RzMsgDigestSize *size);
RZ_API ut8 *rz_debug_snap_get_hash(RzDebugSnap *snap, RzHashSize *size);
RZ_API bool rz_debug_snap_is_equal(RzDebugSnap *a, RzDebugSnap *b);
RZ_API void rz_debug_snap_free(RzDebugSnap *snap);

148
librz/include/rz_hash.h Normal file
View file

@ -0,0 +1,148 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#ifndef RZ_MSG_DIGEST_H
#define RZ_MSG_DIGEST_H
#include <rz_types.h>
#include <rz_list.h>
#include <rz_util/rz_mem.h>
#ifdef __cplusplus
extern "C" {
#endif
RZ_LIB_VERSION_HEADER(rz_hash);
typedef enum {
RZ_MSG_DIGEST_STATUS_ALLOC = 0,
RZ_MSG_DIGEST_STATUS_INIT,
RZ_MSG_DIGEST_STATUS_UPDATE,
RZ_MSG_DIGEST_STATUS_FINAL,
} RzHashStatus;
typedef ut32 RzHashSize;
typedef struct rz_hash_plugin_t {
const char *name;
const char *license;
const char *author;
bool support_hmac;
void *(*context_new)();
void (*context_free)(void *context);
RzHashSize (*digest_size)(void *context);
RzHashSize (*block_size)(void *context);
bool (*init)(void *context);
bool (*update)(void *context, const ut8 *data, ut64 size);
bool (*final)(void *context, ut8 *digest);
bool (*small_block)(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size);
} RzHashPlugin;
typedef struct rz_hash_cfg_t {
RzList *configurations;
RzHashStatus status;
} RzHashCfg;
#ifdef RZ_API
RZ_API ut32 rz_hash_xxhash(RZ_NONNULL const ut8 *input, size_t size);
RZ_API double rz_hash_entropy(RZ_NONNULL const ut8 *data, ut64 len);
RZ_API double rz_hash_entropy_fraction(RZ_NONNULL const ut8 *data, ut64 len);
RZ_API RZ_BORROW const RzHashPlugin *rz_hash_plugin_by_index(size_t index);
RZ_API RZ_BORROW const RzHashPlugin *rz_hash_plugin_by_name(RZ_NONNULL const char *name);
RZ_API RZ_OWN RzHashCfg *rz_hash_cfg_new();
RZ_API RZ_OWN RzHashCfg *rz_hash_cfg_new_with_algo(RZ_NONNULL const char *name, RZ_NULLABLE const ut8 *key, ut64 key_size);
#define rz_hash_cfg_new_with_algo2(name) rz_hash_cfg_new_with_algo(name, NULL, 0);
RZ_API void rz_hash_cfg_free(RZ_NULLABLE RzHashCfg *md);
RZ_API bool rz_hash_cfg_configure(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const char *name);
RZ_API bool rz_hash_cfg_hmac(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const ut8 *key, ut64 key_size);
RZ_API bool rz_hash_cfg_init(RZ_NONNULL RzHashCfg *md);
RZ_API bool rz_hash_cfg_update(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const ut8 *data, ut64 size);
RZ_API bool rz_hash_cfg_final(RZ_NONNULL RzHashCfg *md);
RZ_API bool rz_hash_cfg_iterate(RZ_NONNULL RzHashCfg *md, size_t iterate);
RZ_API RZ_BORROW const ut8 *rz_hash_cfg_get_result(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const char *name, RZ_NONNULL RzHashSize *size);
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);
RZ_API RzHashSize rz_hash_cfg_size(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const char *name);
RZ_API RZ_OWN ut8 *rz_hash_cfg_calculate_small_block(RZ_NONNULL const char *name, RZ_NONNULL const ut8 *buffer, ut64 bsize, RZ_NONNULL RzHashSize *osize);
RZ_API RZ_OWN char *rz_hash_cfg_calculate_small_block_string(RZ_NONNULL const char *name, RZ_NONNULL const ut8 *buffer, ut64 bsize, RZ_NULLABLE ut32 *size, bool invert);
RZ_API RZ_OWN char *rz_hash_cfg_randomart(RZ_NONNULL const ut8 *buffer, ut32 length, ut64 address);
#endif
/* importing all message digest plugins */
extern RzHashPlugin rz_hash_plugin_md4;
extern RzHashPlugin rz_hash_plugin_md5;
extern RzHashPlugin rz_hash_plugin_sha1;
extern RzHashPlugin rz_hash_plugin_sha256;
extern RzHashPlugin rz_hash_plugin_sha384;
extern RzHashPlugin rz_hash_plugin_sha512;
extern RzHashPlugin rz_hash_plugin_fletcher8;
extern RzHashPlugin rz_hash_plugin_fletcher16;
extern RzHashPlugin rz_hash_plugin_fletcher32;
extern RzHashPlugin rz_hash_plugin_fletcher64;
extern RzHashPlugin rz_hash_plugin_adler32;
extern RzHashPlugin rz_hash_plugin_crca_crc8smbus;
extern RzHashPlugin rz_hash_plugin_crca_crc8cdma2000;
extern RzHashPlugin rz_hash_plugin_crca_crc8darc;
extern RzHashPlugin rz_hash_plugin_crca_crc8dvbs2;
extern RzHashPlugin rz_hash_plugin_crca_crc8ebu;
extern RzHashPlugin rz_hash_plugin_crca_crc8icode;
extern RzHashPlugin rz_hash_plugin_crca_crc8itu;
extern RzHashPlugin rz_hash_plugin_crca_crc8maxim;
extern RzHashPlugin rz_hash_plugin_crca_crc8rohc;
extern RzHashPlugin rz_hash_plugin_crca_crc8wcdma;
extern RzHashPlugin rz_hash_plugin_crca_crc15can;
extern RzHashPlugin rz_hash_plugin_crca_crc16;
extern RzHashPlugin rz_hash_plugin_crca_crc16citt;
extern RzHashPlugin rz_hash_plugin_crca_crc16usb;
extern RzHashPlugin rz_hash_plugin_crca_crc16hdlc;
extern RzHashPlugin rz_hash_plugin_crca_crc16augccitt;
extern RzHashPlugin rz_hash_plugin_crca_crc16buypass;
extern RzHashPlugin rz_hash_plugin_crca_crc16cdma2000;
extern RzHashPlugin rz_hash_plugin_crca_crc16dds110;
extern RzHashPlugin rz_hash_plugin_crca_crc16dectr;
extern RzHashPlugin rz_hash_plugin_crca_crc16dectx;
extern RzHashPlugin rz_hash_plugin_crca_crc16dnp;
extern RzHashPlugin rz_hash_plugin_crca_crc16en13757;
extern RzHashPlugin rz_hash_plugin_crca_crc16genibus;
extern RzHashPlugin rz_hash_plugin_crca_crc16maxim;
extern RzHashPlugin rz_hash_plugin_crca_crc16mcrf4xx;
extern RzHashPlugin rz_hash_plugin_crca_crc16riello;
extern RzHashPlugin rz_hash_plugin_crca_crc16t10dif;
extern RzHashPlugin rz_hash_plugin_crca_crc16teledisk;
extern RzHashPlugin rz_hash_plugin_crca_crc16tms37157;
extern RzHashPlugin rz_hash_plugin_crca_crca;
extern RzHashPlugin rz_hash_plugin_crca_crc16kermit;
extern RzHashPlugin rz_hash_plugin_crca_crc16modbus;
extern RzHashPlugin rz_hash_plugin_crca_crc16x25;
extern RzHashPlugin rz_hash_plugin_crca_crc16xmodem;
extern RzHashPlugin rz_hash_plugin_crca_crc24;
extern RzHashPlugin rz_hash_plugin_crca_crc32;
extern RzHashPlugin rz_hash_plugin_crca_crc32ecma267;
extern RzHashPlugin rz_hash_plugin_crca_crc32c;
extern RzHashPlugin rz_hash_plugin_crca_crc32bzip2;
extern RzHashPlugin rz_hash_plugin_crca_crc32d;
extern RzHashPlugin rz_hash_plugin_crca_crc32mpeg2;
extern RzHashPlugin rz_hash_plugin_crca_crc32posix;
extern RzHashPlugin rz_hash_plugin_crca_crc32q;
extern RzHashPlugin rz_hash_plugin_crca_crc32jamcrc;
extern RzHashPlugin rz_hash_plugin_crca_crc32xfer;
extern RzHashPlugin rz_hash_plugin_crca_crc64;
extern RzHashPlugin rz_hash_plugin_crca_crc64ecma182;
extern RzHashPlugin rz_hash_plugin_crca_crc64we;
extern RzHashPlugin rz_hash_plugin_crca_crc64xz;
extern RzHashPlugin rz_hash_plugin_crca_crc64iso;
extern RzHashPlugin rz_hash_plugin_xor8;
extern RzHashPlugin rz_hash_plugin_xor16;
extern RzHashPlugin rz_hash_plugin_xxhash32;
extern RzHashPlugin rz_hash_plugin_parity;
extern RzHashPlugin rz_hash_plugin_entropy;
extern RzHashPlugin rz_hash_plugin_entropy_fract;
#ifdef __cplusplus
}
#endif
#endif /* RZ_MSG_DIGEST_H */

View file

@ -79,7 +79,7 @@ typedef enum {
RZ_LIB_TYPE_SYSCALL, /* syscall */
RZ_LIB_TYPE_FASTCALL, /* fastcall */
RZ_LIB_TYPE_CRYPTO, /* cryptography */
RZ_LIB_TYPE_MD, /* message digests */
RZ_LIB_TYPE_HASH, /* message digests */
RZ_LIB_TYPE_CORE, /* RzCore commands */
RZ_LIB_TYPE_EGG, /* rz_egg plugin */
RZ_LIB_TYPE_DEMANGLER, /* demanglers */

View file

@ -1,148 +0,0 @@
// SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
// SPDX-License-Identifier: LGPL-3.0-only
#ifndef RZ_MSG_DIGEST_H
#define RZ_MSG_DIGEST_H
#include <rz_types.h>
#include <rz_list.h>
#include <rz_util/rz_mem.h>
#ifdef __cplusplus
extern "C" {
#endif
RZ_LIB_VERSION_HEADER(rz_msg_digest);
typedef enum {
RZ_MSG_DIGEST_STATUS_ALLOC = 0,
RZ_MSG_DIGEST_STATUS_INIT,
RZ_MSG_DIGEST_STATUS_UPDATE,
RZ_MSG_DIGEST_STATUS_FINAL,
} RzMsgDigestStatus;
typedef ut32 RzMsgDigestSize;
typedef struct rz_msg_digest_plugin_t {
const char *name;
const char *license;
const char *author;
bool support_hmac;
void *(*context_new)();
void (*context_free)(void *context);
RzMsgDigestSize (*digest_size)(void *context);
RzMsgDigestSize (*block_size)(void *context);
bool (*init)(void *context);
bool (*update)(void *context, const ut8 *data, ut64 size);
bool (*final)(void *context, ut8 *digest);
bool (*small_block)(const ut8 *data, ut64 size, ut8 **digest, RzMsgDigestSize *digest_size);
} RzMsgDigestPlugin;
typedef struct rz_msg_digest_t {
RzList *configurations;
RzMsgDigestStatus status;
} RzMsgDigest;
#ifdef RZ_API
RZ_API ut32 rz_hash_xxhash(RZ_NONNULL const ut8 *input, size_t size);
RZ_API double rz_hash_entropy(RZ_NONNULL const ut8 *data, ut64 len);
RZ_API double rz_hash_entropy_fraction(RZ_NONNULL const ut8 *data, ut64 len);
RZ_API RZ_BORROW const RzMsgDigestPlugin *rz_msg_digest_plugin_by_index(size_t index);
RZ_API RZ_BORROW const RzMsgDigestPlugin *rz_msg_digest_plugin_by_name(RZ_NONNULL const char *name);
RZ_API RZ_OWN RzMsgDigest *rz_msg_digest_new();
RZ_API RZ_OWN RzMsgDigest *rz_msg_digest_new_with_algo(RZ_NONNULL const char *name, RZ_NULLABLE const ut8 *key, ut64 key_size);
#define rz_msg_digest_new_with_algo2(name) rz_msg_digest_new_with_algo(name, NULL, 0);
RZ_API void rz_msg_digest_free(RZ_NULLABLE RzMsgDigest *md);
RZ_API bool rz_msg_digest_configure(RZ_NONNULL RzMsgDigest *md, RZ_NONNULL const char *name);
RZ_API bool rz_msg_digest_hmac(RZ_NONNULL RzMsgDigest *md, RZ_NONNULL const ut8 *key, ut64 key_size);
RZ_API bool rz_msg_digest_init(RZ_NONNULL RzMsgDigest *md);
RZ_API bool rz_msg_digest_update(RZ_NONNULL RzMsgDigest *md, RZ_NONNULL const ut8 *data, ut64 size);
RZ_API bool rz_msg_digest_final(RZ_NONNULL RzMsgDigest *md);
RZ_API bool rz_msg_digest_iterate(RZ_NONNULL RzMsgDigest *md, size_t iterate);
RZ_API RZ_BORROW const ut8 *rz_msg_digest_get_result(RZ_NONNULL RzMsgDigest *md, RZ_NONNULL const char *name, RZ_NONNULL RzMsgDigestSize *size);
RZ_API RZ_OWN char *rz_msg_digest_get_result_string(RZ_NONNULL RzMsgDigest *md, RZ_NONNULL const char *name, RZ_NULLABLE ut32 *size, bool invert);
RZ_API RzMsgDigestSize rz_msg_digest_size(RZ_NONNULL RzMsgDigest *md, RZ_NONNULL const char *name);
RZ_API RZ_OWN ut8 *rz_msg_digest_calculate_small_block(RZ_NONNULL const char *name, RZ_NONNULL const ut8 *buffer, ut64 bsize, RZ_NONNULL RzMsgDigestSize *osize);
RZ_API RZ_OWN char *rz_msg_digest_calculate_small_block_string(RZ_NONNULL const char *name, RZ_NONNULL const ut8 *buffer, ut64 bsize, RZ_NULLABLE ut32 *size, bool invert);
RZ_API RZ_OWN char *rz_msg_digest_randomart(RZ_NONNULL const ut8 *buffer, ut32 length, ut64 address);
#endif
/* importing all message digest plugins */
extern RzMsgDigestPlugin rz_msg_digest_plugin_md4;
extern RzMsgDigestPlugin rz_msg_digest_plugin_md5;
extern RzMsgDigestPlugin rz_msg_digest_plugin_sha1;
extern RzMsgDigestPlugin rz_msg_digest_plugin_sha256;
extern RzMsgDigestPlugin rz_msg_digest_plugin_sha384;
extern RzMsgDigestPlugin rz_msg_digest_plugin_sha512;
extern RzMsgDigestPlugin rz_msg_digest_plugin_fletcher8;
extern RzMsgDigestPlugin rz_msg_digest_plugin_fletcher16;
extern RzMsgDigestPlugin rz_msg_digest_plugin_fletcher32;
extern RzMsgDigestPlugin rz_msg_digest_plugin_fletcher64;
extern RzMsgDigestPlugin rz_msg_digest_plugin_adler32;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc8smbus;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc8cdma2000;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc8darc;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc8dvbs2;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc8ebu;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc8icode;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc8itu;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc8maxim;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc8rohc;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc8wcdma;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc15can;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16citt;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16usb;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16hdlc;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16augccitt;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16buypass;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16cdma2000;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16dds110;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16dectr;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16dectx;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16dnp;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16en13757;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16genibus;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16maxim;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16mcrf4xx;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16riello;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16t10dif;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16teledisk;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16tms37157;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crca;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16kermit;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16modbus;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16x25;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc16xmodem;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc24;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc32;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc32ecma267;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc32c;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc32bzip2;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc32d;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc32mpeg2;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc32posix;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc32q;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc32jamcrc;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc32xfer;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc64;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc64ecma182;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc64we;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc64xz;
extern RzMsgDigestPlugin rz_msg_digest_plugin_crca_crc64iso;
extern RzMsgDigestPlugin rz_msg_digest_plugin_xor8;
extern RzMsgDigestPlugin rz_msg_digest_plugin_xor16;
extern RzMsgDigestPlugin rz_msg_digest_plugin_xxhash32;
extern RzMsgDigestPlugin rz_msg_digest_plugin_parity;
extern RzMsgDigestPlugin rz_msg_digest_plugin_entropy;
extern RzMsgDigestPlugin rz_msg_digest_plugin_entropy_fract;
#ifdef __cplusplus
}
#endif
#endif /* RZ_MSG_DIGEST_H */

View file

@ -49,7 +49,7 @@ static int rz_main_version_verify(int show) {
{ "rz_bp", rz_bp_version },
{ "rz_debug", rz_debug_version },
{ "rz_main", rz_main_version },
{ "rz_msg_digest", rz_msg_digest_version },
{ "rz_hash", rz_hash_version },
{ "rz_io", rz_io_version },
#if !USE_LIB_MAGIC
{ "rz_magic", rz_magic_version },

View file

@ -5,7 +5,7 @@
#include <string.h>
#include <rz_io.h>
#include <rz_main.h>
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_util/rz_print.h>
#include <rz_util.h>
#include <rz_crypto.h>
@ -109,8 +109,8 @@ static void rz_hash_show_algorithms() {
printf("flags algorithm license author\n");
const RzMsgDigestPlugin *rmdp;
for (size_t i = 0; (rmdp = rz_msg_digest_plugin_by_index(i)); ++i) {
const RzHashPlugin *rmdp;
for (size_t i = 0; (rmdp = rz_hash_plugin_by_index(i)); ++i) {
snprintf(flags, sizeof(flags), "____h%c", rmdp->support_hmac ? 'm' : '_');
printf("%6s %-14s %-10s %s\n", flags, rmdp->name, rmdp->license, rmdp->author);
}
@ -712,14 +712,14 @@ static void rz_hash_print_crypto(RzHashContext *ctx, const char *hname, const ut
free(value);
}
static void rz_hash_print_digest(RzHashContext *ctx, RzMsgDigest *md, const char *hname, ut64 from, ut64 to, const char *filename) {
RzMsgDigestSize len = 0;
static void rz_hash_print_digest(RzHashContext *ctx, RzHashCfg *md, const char *hname, ut64 from, ut64 to, const char *filename) {
RzHashSize len = 0;
char *value = NULL;
char *rndart = NULL;
const ut8 *buffer;
buffer = rz_msg_digest_get_result(md, hname, &len);
value = rz_msg_digest_get_result_string(md, hname, NULL, ctx->little_endian);
buffer = rz_hash_cfg_get_result(md, hname, &len);
value = rz_hash_cfg_get_result_string(md, hname, NULL, ctx->little_endian);
if (!value || !buffer) {
free(value);
return;
@ -741,7 +741,7 @@ static void rz_hash_print_digest(RzHashContext *ctx, RzMsgDigest *md, const char
printf("%s: 0x%08" PFMT64x "-0x%08" PFMT64x " %s%s: %s%s\n", filename, from, to, hmac, hname, value, has_seed ? " with seed" : "");
break;
case RZ_HASH_MODE_RANDOMART:
rndart = rz_msg_digest_randomart(buffer, len, from);
rndart = rz_hash_cfg_randomart(buffer, len, from);
printf("%s%s\n%s\n", hmac, hname, rndart);
break;
case RZ_HASH_MODE_QUIET:
@ -782,12 +782,12 @@ static void rz_hash_context_compare_hashes(RzHashContext *ctx, size_t filesize,
static RzList *parse_hash_algorithms(RzHashContext *ctx) {
if (!strcmp(ctx->algorithm, "all")) {
const RzMsgDigestPlugin *plugin;
const RzHashPlugin *plugin;
RzList *list = rz_list_newf(NULL);
if (!list) {
return NULL;
}
for (ut64 i = 0; (plugin = rz_msg_digest_plugin_by_index(i)); ++i) {
for (ut64 i = 0; (plugin = rz_hash_plugin_by_index(i)); ++i) {
rz_list_append(list, (void *)plugin->name);
}
return list;
@ -800,13 +800,13 @@ static bool calculate_hash(RzHashContext *ctx, RzIO *io, const char *filename) {
const char *algorithm;
RzList *algorithms = NULL;
RzListIter *it;
RzMsgDigest *md = NULL;
RzHashCfg *md = NULL;
ut64 bsize = 0;
ut64 filesize;
ut8 *block = NULL;
ut8 *cmphash = NULL;
const ut8 *digest = NULL;
RzMsgDigestSize digest_size = 0;
RzHashSize digest_size = 0;
algorithms = parse_hash_algorithms(ctx);
if (!algorithms || rz_list_length(algorithms) < 1) {
@ -816,7 +816,7 @@ static bool calculate_hash(RzHashContext *ctx, RzIO *io, const char *filename) {
filesize = rz_io_desc_size(io->desc);
md = rz_msg_digest_new();
md = rz_hash_cfg_new();
if (!md) {
RZ_LOG_ERROR("rz-hash: error, cannot allocate hash context memory\n");
goto calculate_hash_end;
@ -840,12 +840,12 @@ static bool calculate_hash(RzHashContext *ctx, RzIO *io, const char *filename) {
}
rz_list_foreach (algorithms, it, algorithm) {
if (!rz_msg_digest_configure(md, algorithm)) {
if (!rz_hash_cfg_configure(md, algorithm)) {
goto calculate_hash_end;
}
}
if (ctx->key.len > 0 && !rz_msg_digest_hmac(md, ctx->key.buf, ctx->key.len)) {
if (ctx->key.len > 0 && !rz_hash_cfg_hmac(md, ctx->key.buf, ctx->key.len)) {
goto calculate_hash_end;
}
@ -859,33 +859,33 @@ static bool calculate_hash(RzHashContext *ctx, RzIO *io, const char *filename) {
goto calculate_hash_end;
}
if (!rz_msg_digest_init(md)) {
if (!rz_hash_cfg_init(md)) {
goto calculate_hash_end;
}
if (ctx->as_prefix && ctx->seed.buf &&
!rz_msg_digest_update(md, ctx->seed.buf, ctx->seed.len)) {
!rz_hash_cfg_update(md, ctx->seed.buf, ctx->seed.len)) {
goto calculate_hash_end;
}
for (ut64 j = ctx->offset.from; j < to; j += bsize) {
int read = rz_io_pread_at(io, j, block, to - j > bsize ? bsize : (to - j));
if (!rz_msg_digest_update(md, block, read)) {
if (!rz_hash_cfg_update(md, block, read)) {
goto calculate_hash_end;
}
}
if (!ctx->as_prefix && ctx->seed.buf &&
!rz_msg_digest_update(md, ctx->seed.buf, ctx->seed.len)) {
!rz_hash_cfg_update(md, ctx->seed.buf, ctx->seed.len)) {
goto calculate_hash_end;
}
if (!rz_msg_digest_final(md) ||
!rz_msg_digest_iterate(md, ctx->iterate)) {
if (!rz_hash_cfg_final(md) ||
!rz_hash_cfg_iterate(md, ctx->iterate)) {
goto calculate_hash_end;
}
rz_list_foreach (algorithms, it, algorithm) {
digest = rz_msg_digest_get_result(md, algorithm, &digest_size);
digest = rz_hash_cfg_get_result(md, algorithm, &digest_size);
if (digest_size != cmphashlen) {
result = false;
} else {
@ -904,15 +904,15 @@ static bool calculate_hash(RzHashContext *ctx, RzIO *io, const char *filename) {
ut64 to = ctx->offset.to ? ctx->offset.to : filesize;
for (ut64 j = ctx->offset.from; j < to; j += bsize) {
int read = rz_io_pread_at(io, j, block, to - j > bsize ? bsize : (to - j));
if (!rz_msg_digest_init(md) ||
!rz_msg_digest_update(md, block, read) ||
!rz_msg_digest_final(md) ||
!rz_msg_digest_iterate(md, ctx->iterate)) {
if (!rz_hash_cfg_init(md) ||
!rz_hash_cfg_update(md, block, read) ||
!rz_hash_cfg_final(md) ||
!rz_hash_cfg_iterate(md, ctx->iterate)) {
goto calculate_hash_end;
}
rz_list_foreach (algorithms, it, algorithm) {
digest = rz_msg_digest_get_result(md, algorithm, &digest_size);
digest = rz_hash_cfg_get_result(md, algorithm, &digest_size);
if (ctx->mode == RZ_HASH_MODE_JSON) {
pj_o(ctx->pj);
}
@ -924,34 +924,34 @@ static bool calculate_hash(RzHashContext *ctx, RzIO *io, const char *filename) {
}
} else {
ut64 to = ctx->offset.to ? ctx->offset.to : filesize;
if (!rz_msg_digest_init(md)) {
if (!rz_hash_cfg_init(md)) {
goto calculate_hash_end;
}
if (ctx->as_prefix && ctx->seed.buf &&
!rz_msg_digest_update(md, ctx->seed.buf, ctx->seed.len)) {
!rz_hash_cfg_update(md, ctx->seed.buf, ctx->seed.len)) {
goto calculate_hash_end;
}
for (ut64 j = ctx->offset.from; j < to; j += bsize) {
int read = rz_io_pread_at(io, j, block, to - j > bsize ? bsize : (to - j));
if (!rz_msg_digest_update(md, block, read)) {
if (!rz_hash_cfg_update(md, block, read)) {
goto calculate_hash_end;
}
}
if (!ctx->as_prefix && ctx->seed.buf &&
!rz_msg_digest_update(md, ctx->seed.buf, ctx->seed.len)) {
!rz_hash_cfg_update(md, ctx->seed.buf, ctx->seed.len)) {
goto calculate_hash_end;
}
if (!rz_msg_digest_final(md) ||
!rz_msg_digest_iterate(md, ctx->iterate)) {
if (!rz_hash_cfg_final(md) ||
!rz_hash_cfg_iterate(md, ctx->iterate)) {
goto calculate_hash_end;
}
rz_list_foreach (algorithms, it, algorithm) {
digest = rz_msg_digest_get_result(md, algorithm, &digest_size);
digest = rz_hash_cfg_get_result(md, algorithm, &digest_size);
if (ctx->mode == RZ_HASH_MODE_JSON) {
pj_o(ctx->pj);
@ -968,7 +968,7 @@ calculate_hash_end:
rz_list_free(algorithms);
free(block);
free(cmphash);
rz_msg_digest_free(md);
rz_hash_cfg_free(md);
return result;
}

View file

@ -5,7 +5,7 @@
#include <rz_analysis.h>
#include <rz_sign.h>
#include <rz_search.h>
#include <rz_msg_digest.h>
#include <rz_hash.h>
#define SIGN_DIFF_MATCH_BYTES_THRESHOLD 1.0
#define SIGN_DIFF_MATCH_GRAPH_THRESHOLD 1.0
@ -2093,12 +2093,12 @@ RZ_API char *rz_sign_calc_bbhash(RzAnalysis *a, RzAnalysisFunction *fcn) {
RzListIter *iter = NULL;
RzAnalysisBlock *bbi = NULL;
char *digest_hex = NULL;
RzMsgDigestSize digest_size = 0;
RzHashSize digest_size = 0;
const ut8 *digest = NULL;
RzMsgDigest *md = NULL;
RzHashCfg *md = NULL;
ut8 *buf = NULL;
md = rz_msg_digest_new_with_algo2(ZIGN_HASH);
md = rz_hash_cfg_new_with_algo2(ZIGN_HASH);
if (!md) {
goto beach;
}
@ -2112,21 +2112,21 @@ RZ_API char *rz_sign_calc_bbhash(RzAnalysis *a, RzAnalysisFunction *fcn) {
if (!a->iob.read_at(a->iob.io, bbi->addr, buf, bbi->size)) {
goto beach;
}
if (!rz_msg_digest_update(md, buf, bbi->size)) {
if (!rz_hash_cfg_update(md, buf, bbi->size)) {
goto beach;
}
RZ_FREE(buf);
}
if (!rz_msg_digest_final(md) ||
!(digest = rz_msg_digest_get_result(md, ZIGN_HASH, &digest_size))) {
if (!rz_hash_cfg_final(md) ||
!(digest = rz_hash_cfg_get_result(md, ZIGN_HASH, &digest_size))) {
goto beach;
}
digest_hex = rz_hex_bin2strdup(digest, digest_size);
beach:
rz_msg_digest_free(md);
rz_hash_cfg_free(md);
free(buf);
return digest_hex;
}

View file

@ -26,7 +26,7 @@ static RzLibTypeName rz_lib_types[] = {
{ RZ_LIB_TYPE_SYSCALL, "syscall" },
{ RZ_LIB_TYPE_FASTCALL, "fastcall" },
{ RZ_LIB_TYPE_CRYPTO, "crypto" },
{ RZ_LIB_TYPE_MD, "msgdigest" },
{ RZ_LIB_TYPE_HASH, "msgdigest" },
{ RZ_LIB_TYPE_CORE, "core" },
{ RZ_LIB_TYPE_EGG, "egg" },
{ RZ_LIB_TYPE_DEMANGLER, "demangler" },

View file

@ -3,7 +3,7 @@
#include <errno.h>
#include <rz_crypto.h>
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include <rz_socket.h>
#include <rz_util.h>
@ -85,24 +85,24 @@ static ut64 base36_decode(const char *str) {
* @param resbuf, the buffer that contains the KDNet Data of a Response packet.
*/
static bool _initializeDatakey(iobnet_t *obj, ut8 *resbuf, int size) {
RzMsgDigestSize digest_size = 0;
RzHashSize digest_size = 0;
const ut8 *digest = NULL;
RzMsgDigest *md = rz_msg_digest_new_with_algo2("sha256");
RzHashCfg *md = rz_hash_cfg_new_with_algo2("sha256");
if (!md) {
return false;
}
if (!rz_msg_digest_update(md, obj->key, 32) ||
!rz_msg_digest_update(md, resbuf, size) ||
!rz_msg_digest_final(md) ||
!(digest = rz_msg_digest_get_result(md, "sha256", &digest_size))) {
if (!rz_hash_cfg_update(md, obj->key, 32) ||
!rz_hash_cfg_update(md, resbuf, size) ||
!rz_hash_cfg_final(md) ||
!(digest = rz_hash_cfg_get_result(md, "sha256", &digest_size))) {
rz_msg_digest_free(md);
rz_hash_cfg_free(md);
return false;
}
memcpy(obj->datakey, digest, digest_size);
rz_msg_digest_free(md);
rz_hash_cfg_free(md);
return true;
}
@ -263,22 +263,22 @@ static ut8 *_createKDNetPacket(iobnet_t *obj, const ut8 *buf, int size, int *osi
int off = sizeof(kdnet_packet_t) + KDNET_DATA_SIZE + size + padsize;
const ut8 *digest = NULL;
RzMsgDigest *md = rz_msg_digest_new_with_algo("sha256", obj->hmackey, KDNET_HMACKEY_SIZE);
RzHashCfg *md = rz_hash_cfg_new_with_algo("sha256", obj->hmackey, KDNET_HMACKEY_SIZE);
if (!md) {
free(encbuf);
return NULL;
}
if (!rz_msg_digest_update(md, encbuf, off) ||
!rz_msg_digest_final(md) ||
!(digest = rz_msg_digest_get_result(md, "sha256", NULL))) {
if (!rz_hash_cfg_update(md, encbuf, off) ||
!rz_hash_cfg_final(md) ||
!(digest = rz_hash_cfg_get_result(md, "sha256", NULL))) {
free(encbuf);
rz_msg_digest_free(md);
rz_hash_cfg_free(md);
return NULL;
}
memcpy(encbuf + off, digest, KDNET_HMAC_SIZE);
rz_msg_digest_free(md);
rz_hash_cfg_free(md);
// Encrypt the KDNet Data, KD Packet and padding
if (!_encrypt(obj, encbuf + sizeof(kdnet_packet_t), encsize - sizeof(kdnet_packet_t), type)) {
@ -416,20 +416,20 @@ static bool _processControlPacket(iobnet_t *obj, const ut8 *ctrlbuf, int size) {
bool _verifyhmac(iobnet_t *obj) {
const ut8 *digest = NULL;
RzMsgDigest *md = rz_msg_digest_new_with_algo("sha256", obj->hmackey, KDNET_HMACKEY_SIZE);
RzHashCfg *md = rz_hash_cfg_new_with_algo("sha256", obj->hmackey, KDNET_HMACKEY_SIZE);
if (!md) {
return false;
}
if (!rz_msg_digest_update(md, obj->read_buf, obj->read_size - KDNET_HMAC_SIZE) ||
!rz_msg_digest_final(md) ||
!(digest = rz_msg_digest_get_result(md, "sha256", NULL))) {
rz_msg_digest_free(md);
if (!rz_hash_cfg_update(md, obj->read_buf, obj->read_size - KDNET_HMAC_SIZE) ||
!rz_hash_cfg_final(md) ||
!(digest = rz_hash_cfg_get_result(md, "sha256", NULL))) {
rz_hash_cfg_free(md);
return false;
}
bool result = !memcmp(digest, obj->read_buf + obj->read_size - KDNET_HMAC_SIZE, KDNET_HMAC_SIZE);
rz_msg_digest_free(md);
rz_hash_cfg_free(md);
return result;
}

View file

@ -2,7 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_util.h>
#include <rz_msg_digest.h>
#include <rz_hash.h>
#include "minunit.h"
typedef struct {
@ -107,36 +107,36 @@ static hash_data_t hashes_to_test[] = {
bool test_message_digest_configure() {
bool boolean;
RzMsgDigest *md = NULL;
RzHashCfg *md = NULL;
md = rz_msg_digest_new();
mu_assert_notnull(md, "rz_msg_digest_new");
md = rz_hash_cfg_new();
mu_assert_notnull(md, "rz_hash_cfg_new");
boolean = rz_msg_digest_configure(md, "gibberish");
mu_assert_false(boolean, "rz_msg_digest_configure 'gibberish'");
boolean = rz_hash_cfg_configure(md, "gibberish");
mu_assert_false(boolean, "rz_hash_cfg_configure 'gibberish'");
boolean = rz_msg_digest_configure(md, "");
mu_assert_false(boolean, "rz_msg_digest_configure ''");
boolean = rz_hash_cfg_configure(md, "");
mu_assert_false(boolean, "rz_hash_cfg_configure ''");
boolean = rz_msg_digest_configure(md, "md5");
mu_assert_true(boolean, "rz_msg_digest_configure 'md5'");
boolean = rz_hash_cfg_configure(md, "md5");
mu_assert_true(boolean, "rz_hash_cfg_configure 'md5'");
boolean = rz_msg_digest_configure(md, "sha1");
mu_assert_true(boolean, "rz_msg_digest_configure 'sha1'");
boolean = rz_hash_cfg_configure(md, "sha1");
mu_assert_true(boolean, "rz_hash_cfg_configure 'sha1'");
boolean = rz_msg_digest_configure(md, "sha1");
mu_assert_false(boolean, "rz_msg_digest_configure 'sha1' again");
boolean = rz_hash_cfg_configure(md, "sha1");
mu_assert_false(boolean, "rz_hash_cfg_configure 'sha1' again");
boolean = rz_msg_digest_configure(md, "all");
mu_assert_false(boolean, "rz_msg_digest_configure can't configure 'all' when other algos has been configured");
boolean = rz_hash_cfg_configure(md, "all");
mu_assert_false(boolean, "rz_hash_cfg_configure can't configure 'all' when other algos has been configured");
rz_msg_digest_free(md);
rz_hash_cfg_free(md);
md = rz_msg_digest_new_with_algo2("gibberish");
mu_assert_null(md, "rz_msg_digest_new_with_algo2 with gibberish algo");
md = rz_hash_cfg_new_with_algo2("gibberish");
mu_assert_null(md, "rz_hash_cfg_new_with_algo2 with gibberish algo");
md = rz_msg_digest_new_with_algo2("");
mu_assert_null(md, "rz_msg_digest_new_with_algo2 with '' algo");
md = rz_hash_cfg_new_with_algo2("");
mu_assert_null(md, "rz_hash_cfg_new_with_algo2 with '' algo");
mu_end;
}
@ -145,31 +145,31 @@ bool test_message_digest_hmac_stringified() {
char message[256];
char *result = NULL;
bool boolean;
RzMsgDigestSize size;
RzMsgDigest *md = NULL;
RzHashSize size;
RzHashCfg *md = NULL;
for (size_t i = 0; i < RZ_ARRAY_SIZE(hmacs_to_test); ++i) {
hmac_data_t *hd = &hmacs_to_test[i];
md = rz_msg_digest_new_with_algo(hd->algo, hd->key, hd->key_size);
snprintf(message, sizeof(message), "rz_msg_digest_new_with_algo hmac-%s digest", hd->algo);
md = rz_hash_cfg_new_with_algo(hd->algo, hd->key, hd->key_size);
snprintf(message, sizeof(message), "rz_hash_cfg_new_with_algo hmac-%s digest", hd->algo);
mu_assert_notnull(md, message);
boolean = rz_msg_digest_update(md, hd->input, hd->input_size);
snprintf(message, sizeof(message), "rz_msg_digest_update hmac-%s digest", hd->algo);
boolean = rz_hash_cfg_update(md, hd->input, hd->input_size);
snprintf(message, sizeof(message), "rz_hash_cfg_update hmac-%s digest", hd->algo);
mu_assert_true(boolean, message);
boolean = rz_msg_digest_final(md);
snprintf(message, sizeof(message), "rz_msg_digest_final hmac-%s digest", hd->algo);
boolean = rz_hash_cfg_final(md);
snprintf(message, sizeof(message), "rz_hash_cfg_final hmac-%s digest", hd->algo);
mu_assert_true(boolean, message);
result = rz_msg_digest_get_result_string(md, hd->algo, &size, false);
snprintf(message, sizeof(message), "rz_msg_digest_get_result_string hmac-%s digest", hd->algo);
result = rz_hash_cfg_get_result_string(md, hd->algo, &size, false);
snprintf(message, sizeof(message), "rz_hash_cfg_get_result_string hmac-%s digest", hd->algo);
mu_assert_streq(result, hd->expected, message);
free(result);
result = NULL;
rz_msg_digest_free(md);
rz_hash_cfg_free(md);
}
free(result);
@ -180,31 +180,31 @@ bool test_message_digest_api_stringified() {
char message[256];
char *result = NULL;
bool boolean;
RzMsgDigestSize size;
RzMsgDigest *md = NULL;
RzHashSize size;
RzHashCfg *md = NULL;
for (size_t i = 0; i < RZ_ARRAY_SIZE(hashes_to_test); ++i) {
hash_data_t *hd = &hashes_to_test[i];
md = rz_msg_digest_new_with_algo2(hd->algo);
snprintf(message, sizeof(message), "rz_msg_digest_new_with_algo %s digest", hd->algo);
md = rz_hash_cfg_new_with_algo2(hd->algo);
snprintf(message, sizeof(message), "rz_hash_cfg_new_with_algo %s digest", hd->algo);
mu_assert_notnull(md, message);
boolean = rz_msg_digest_update(md, hd->input, hd->input_size);
snprintf(message, sizeof(message), "rz_msg_digest_update %s digest", hd->algo);
boolean = rz_hash_cfg_update(md, hd->input, hd->input_size);
snprintf(message, sizeof(message), "rz_hash_cfg_update %s digest", hd->algo);
mu_assert_true(boolean, message);
boolean = rz_msg_digest_final(md);
snprintf(message, sizeof(message), "rz_msg_digest_final %s digest", hd->algo);
boolean = rz_hash_cfg_final(md);
snprintf(message, sizeof(message), "rz_hash_cfg_final %s digest", hd->algo);
mu_assert_true(boolean, message);
result = rz_msg_digest_get_result_string(md, hd->algo, &size, false);
snprintf(message, sizeof(message), "rz_msg_digest_get_result_string %s digest", hd->algo);
result = rz_hash_cfg_get_result_string(md, hd->algo, &size, false);
snprintf(message, sizeof(message), "rz_hash_cfg_get_result_string %s digest", hd->algo);
mu_assert_streq(result, hd->expected, message);
free(result);
result = NULL;
rz_msg_digest_free(md);
rz_hash_cfg_free(md);
}
free(result);
@ -214,12 +214,12 @@ bool test_message_digest_api_stringified() {
bool test_message_digest_small_block_stringified() {
char message[256];
char *result = NULL;
RzMsgDigestSize size;
RzHashSize size;
for (size_t i = 0; i < RZ_ARRAY_SIZE(hashes_to_test); ++i) {
hash_data_t *hd = &hashes_to_test[i];
snprintf(message, sizeof(message), "calculate %s digest", hd->algo);
result = rz_msg_digest_calculate_small_block_string(hd->algo, hd->input, hd->input_size, &size, false);
result = rz_hash_cfg_calculate_small_block_string(hd->algo, hd->input, hd->input_size, &size, false);
mu_assert_streq(result, hd->expected, message);
free(result);
result = NULL;
@ -237,4 +237,4 @@ bool all_tests() {
return tests_passed != tests_run;
}
mu_main(all_tests)
mu_main(all_tests)