Rizin
unix-like reverse engineering framework and cli tools
|
Go to the source code of this file.
Classes | |
struct | hash_cfg_config_t |
Macros | |
#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) |
Typedefs | |
typedef struct hash_cfg_config_t | HashCfgConfig |
Variables | |
static const RzHashPlugin * | hash_static_plugins [] = { RZ_HASH_STATIC_PLUGINS } |
#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_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_has_finshed | ( | c | ) | ((c)->status == RZ_MSG_DIGEST_STATUS_FINAL) |
typedef struct hash_cfg_config_t HashCfgConfig |
Definition at line 58 of file hash.c.
References rz_hash_plugin_t::name, hash_cfg_config_t::plugin, and value.
Referenced by rz_hash_cfg_configure(), rz_hash_cfg_get_result(), rz_hash_cfg_get_result_string(), and rz_hash_cfg_size().
|
static |
Definition at line 64 of file hash.c.
References hash_cfg_config_t::context, rz_hash_plugin_t::context_free, hash_cfg_config_t::digest, free(), hash_cfg_config_t::hmac_key, hash_cfg_config_t::plugin, and rz_return_if_fail.
Referenced by rz_hash_cfg_configure(), and rz_hash_cfg_new().
|
static |
Definition at line 73 of file hash.c.
References hash_cfg_config_t::context, rz_hash_plugin_t::context_free, rz_hash_plugin_t::context_new, hash_cfg_config_t::digest, hash_cfg_config_t::digest_size, rz_hash_plugin_t::digest_size, free(), NULL, hash_cfg_config_t::plugin, RZ_LOG_ERROR, RZ_NEW0, RZ_NEWS0, rz_return_val_if_fail, and rz_warn_if_fail.
Referenced by rz_hash_cfg_configure().
RZ_API RZ_OWN ut8* rz_hash_cfg_calculate_small_block | ( | RZ_NONNULL RzHash * | rh, |
RZ_NONNULL const char * | name, | ||
RZ_NONNULL const ut8 * | buffer, | ||
ut64 | bsize, | ||
RZ_NONNULL RzHashSize * | osize | ||
) |
Returns the digest size of the requested algorithm name.
Returns the digest size of the initialized configuration.
Definition at line 529 of file hash.c.
References rz_hash_plugin_t::name, NULL, rz_hash_plugin_by_name(), RZ_LOG_ERROR, rz_return_val_if_fail, and rz_hash_plugin_t::small_block.
Referenced by handle_entropy(), handle_hash_cfg(), parseCodeDirectory(), rz_debug_snap_get_hash(), and rz_hash_cfg_calculate_small_block_string().
RZ_API RZ_OWN char* rz_hash_cfg_calculate_small_block_string | ( | RZ_NONNULL RzHash * | rh, |
RZ_NONNULL const char * | name, | ||
RZ_NONNULL const ut8 * | buffer, | ||
ut64 | bsize, | ||
RZ_NULLABLE ut32 * | size, | ||
bool | invert | ||
) |
Definition at line 545 of file hash.c.
References free(), i, invert(), malloc(), NULL, pos, rz_hash_cfg_calculate_small_block(), RZ_LOG_ERROR, rz_read_be_double(), rz_return_val_if_fail, rz_str_newf(), and sprintf.
Referenced by rz_core_bin_create_digests(), and search_hash().
RZ_API bool rz_hash_cfg_configure | ( | RZ_NONNULL RzHashCfg * | md, |
RZ_NONNULL const char * | name | ||
) |
Allocates and configures the plugin message digest context.
message digest allocates internally a HashCfgConfig which contains all the needed informations to the plugin to work.
Definition at line 199 of file hash.c.
References hash_cfg_config_compare(), hash_cfg_config_free(), hash_cfg_config_new(), benchmark::md, rz_hash_plugin_t::name, NULL, rz_list_append(), rz_list_find(), rz_list_length(), RZ_LOG_ERROR, RZ_LOG_WARN, and rz_return_val_if_fail.
Referenced by calculate_hash(), rz_bin_file_compute_hashes(), and rz_hash_cfg_new_with_algo().
RZ_API bool rz_hash_cfg_final | ( | RZ_NONNULL RzHashCfg * | md | ) |
Generates the final value of the message digest contextes.
RzHashCfg contains a list of configurations; this method will call the final method of all the plugins stored in its list.
Definition at line 359 of file hash.c.
References rz_hash_plugin_t::block_size, hash_cfg_config_t::context, hash_cfg_config_t::digest, hash_cfg_config_t::digest_size, rz_hash_plugin_t::final, free(), hash_cfg_can_final, hash_cfg_config_t::hmac_key, i, rz_hash_plugin_t::init, malloc(), benchmark::md, rz_hash_plugin_t::name, NULL, hash_cfg_config_t::plugin, RZ_LOG_ERROR, RZ_MSG_DIGEST_STATUS_FINAL, rz_return_val_if_fail, and rz_hash_plugin_t::update.
Referenced by _createKDNetPacket(), _initializeDatakey(), _verifyhmac(), bin_pe_compute_authentihash(), calculate_hash(), and rz_bin_file_compute_hashes().
RZ_API void rz_hash_cfg_free | ( | RZ_NONNULL RzHashCfg * | md | ) |
Definition at line 186 of file hash.c.
References free(), benchmark::md, rz_list_free(), and rz_return_if_fail.
Referenced by _createKDNetPacket(), _initializeDatakey(), _verifyhmac(), bin_pe_compute_authentihash(), calculate_hash(), rz_bin_file_compute_hashes(), and rz_hash_cfg_new_with_algo().
RZ_API RZ_BORROW const ut8* rz_hash_cfg_get_result | ( | RZ_NONNULL RzHashCfg * | md, |
RZ_NONNULL const char * | name, | ||
RZ_NONNULL ut32 * | size | ||
) |
Returns the digest value of the requested algorithm name.
RzHashCfg contains a list of configurations; this method will search for the configuration with the given name and if found return the digest value.
Definition at line 445 of file hash.c.
References hash_cfg_config_t::digest, hash_cfg_config_t::digest_size, hash_cfg_config_compare(), hash_cfg_has_finshed, benchmark::md, NULL, rz_list_find(), rz_list_iter_get_data(), RZ_LOG_ERROR, and rz_return_val_if_fail.
Referenced by _createKDNetPacket(), _initializeDatakey(), _verifyhmac(), add_file_hash(), bin_pe_compute_authentihash(), calculate_hash(), and hash_print_digest().
RZ_API RZ_OWN char* rz_hash_cfg_get_result_string | ( | RZ_NONNULL RzHashCfg * | md, |
RZ_NONNULL const char * | name, | ||
RZ_NULLABLE ut32 * | size, | ||
bool | invert | ||
) |
Returns the digest value of the requested algorithm name.
RzHashCfg contains a list of configurations; this method will search for the configuration with the given name and if found return the digest value.
Definition at line 469 of file hash.c.
References hash_cfg_config_t::digest, hash_cfg_config_t::digest_size, hash_cfg_config_compare(), hash_cfg_has_finshed, i, invert(), malloc(), benchmark::md, NULL, pos, rz_list_find(), rz_list_iter_get_data(), RZ_LOG_ERROR, rz_read_be_double(), rz_return_val_if_fail, rz_str_newf(), and sprintf.
Referenced by hash_print_digest().
RZ_API bool rz_hash_cfg_hmac | ( | RZ_NONNULL RzHashCfg * | md, |
RZ_NONNULL const ut8 * | key, | ||
ut64 | key_size | ||
) |
Sets the key for the hmac algorithm.
message digest sets the hmac key
Definition at line 250 of file hash.c.
References rz_hash_plugin_t::block_size, hash_cfg_config_t::context, free(), hash_cfg_can_hmac, hash_cfg_config_t::hmac_key, key, malloc(), benchmark::md, memcpy(), memset(), rz_hash_plugin_t::name, NULL, hash_cfg_config_t::plugin, RZ_LOG_ERROR, rz_return_val_if_fail, rz_hash_plugin_t::small_block, rz_hash_plugin_t::support_hmac, and autogen_x86imm::tmp.
Referenced by calculate_hash(), and rz_hash_cfg_new_with_algo().
RZ_API bool rz_hash_cfg_init | ( | RZ_NONNULL RzHashCfg * | md | ) |
Resets/initialize the message digest contextes.
RzHashCfg contains a list of configurations; this method will call the init method of all the plugins stored in its list.
Definition at line 298 of file hash.c.
References rz_hash_plugin_t::block_size, hash_cfg_config_t::context, free(), hash_cfg_can_init, hash_cfg_config_t::hmac_key, i, rz_hash_plugin_t::init, malloc(), benchmark::md, rz_hash_plugin_t::name, NULL, hash_cfg_config_t::plugin, RZ_LOG_ERROR, RZ_MSG_DIGEST_STATUS_INIT, rz_return_val_if_fail, and rz_hash_plugin_t::update.
Referenced by calculate_hash(), rz_bin_file_compute_hashes(), and rz_hash_cfg_new_with_algo().
RZ_API bool rz_hash_cfg_iterate | ( | RZ_NONNULL RzHashCfg * | md, |
size_t | iterate | ||
) |
Calculate the final hash by iterating its result N times.
RzHashCfg contains a list of configurations; this method will iterate N times each configuration final result.
Definition at line 414 of file hash.c.
References hash_cfg_config_t::context, hash_cfg_config_t::digest, hash_cfg_config_t::digest_size, rz_hash_plugin_t::final, hash_cfg_has_finshed, i, rz_hash_plugin_t::init, benchmark::md, rz_hash_plugin_t::name, NULL, hash_cfg_config_t::plugin, RZ_LOG_ERROR, rz_return_val_if_fail, and rz_hash_plugin_t::update.
Referenced by calculate_hash().
RZ_API RZ_OWN RzHashCfg* rz_hash_cfg_new | ( | RZ_NONNULL RzHash * | rh | ) |
Definition at line 134 of file hash.c.
References free(), hash_cfg_config_free(), benchmark::md, NULL, rz_list_newf(), RZ_LOG_ERROR, RZ_NEW0, and rz_return_val_if_fail.
Referenced by calculate_hash(), rz_bin_file_compute_hashes(), and rz_hash_cfg_new_with_algo().
RZ_API RZ_OWN RzHashCfg* rz_hash_cfg_new_with_algo | ( | RZ_NONNULL RzHash * | rh, |
RZ_NONNULL const char * | name, | ||
RZ_NULLABLE const ut8 * | key, | ||
ut64 | key_size | ||
) |
Returns a message digest context with the give algo already configured.
message digest allocates and configures already the structure with the given algorithm and runs also the algo init. when fails to allocate or configure or initialize, returns NULL.
Definition at line 161 of file hash.c.
References key, benchmark::md, NULL, rz_hash_cfg_configure(), rz_hash_cfg_free(), rz_hash_cfg_hmac(), rz_hash_cfg_init(), rz_hash_cfg_new(), and rz_return_val_if_fail.
Referenced by _createKDNetPacket(), and _verifyhmac().
RZ_API RzHashSize rz_hash_cfg_size | ( | RZ_NONNULL RzHashCfg * | md, |
RZ_NONNULL const char * | name | ||
) |
Returns the digest size of the requested algorithm name.
Returns the digest size of the initialized configuration.
Definition at line 510 of file hash.c.
References hash_cfg_config_t::context, rz_hash_plugin_t::digest_size, hash_cfg_config_compare(), benchmark::md, hash_cfg_config_t::plugin, rz_list_find(), rz_list_iter_get_data(), RZ_LOG_ERROR, and rz_return_val_if_fail.
RZ_API bool rz_hash_cfg_update | ( | RZ_NONNULL RzHashCfg * | md, |
RZ_NONNULL const ut8 * | data, | ||
ut64 | size | ||
) |
Inserts data into each the message digest contextes.
RzHashCfg contains a list of configurations; this method will call the update method of all the plugins stored in its list.
Definition at line 337 of file hash.c.
References hash_cfg_config_t::context, hash_cfg_can_update, benchmark::md, rz_hash_plugin_t::name, NULL, hash_cfg_config_t::plugin, RZ_LOG_ERROR, RZ_MSG_DIGEST_STATUS_UPDATE, rz_return_val_if_fail, and rz_hash_plugin_t::update.
Referenced by _createKDNetPacket(), _initializeDatakey(), _verifyhmac(), buf_compute_hashes(), buf_fwd_hash(), and calculate_hash().
RZ_API double rz_hash_entropy | ( | RZ_NONNULL RzHash * | rh, |
RZ_NONNULL const ut8 * | data, | ||
ut64 | len | ||
) |
Definition at line 32 of file hash.c.
References e, free(), len, NULL, rz_hash_plugin_entropy, RZ_LOG_ERROR, rz_read_be_double(), rz_return_val_if_fail, and rz_hash_plugin_t::small_block.
Referenced by do_section_search().
RZ_API double rz_hash_entropy_fraction | ( | RZ_NONNULL RzHash * | rh, |
RZ_NONNULL const ut8 * | data, | ||
ut64 | len | ||
) |
Definition at line 45 of file hash.c.
References e, free(), len, NULL, rz_hash_plugin_entropy_fract, RZ_LOG_ERROR, rz_read_be_double(), rz_return_val_if_fail, and rz_hash_plugin_t::small_block.
Referenced by cmd_p_minus_e(), and cmd_print_bars().
Definition at line 597 of file hash.c.
References free(), rz_hash_t::plugins, and rz_list_free().
Referenced by hash_context_fini(), iob_net_close(), mach0_free(), rz_analysis_free(), rz_bin_free(), rz_bin_pe_free(), rz_core_fini(), and rz_debug_free().
Create a new RzHash object where plugins can be registered and specific configurations can be created from.
Definition at line 585 of file hash.c.
References hash_static_plugins, i, NULL, rz_hash_t::plugins, RZ_ARRAY_SIZE, rz_hash_plugin_add(), rz_list_new(), and RZ_NEW0.
Referenced by iob_net_open(), rz_analysis_new(), rz_bin_new(), rz_bin_pe_new_buf(), rz_core_init(), rz_debug_new(), and rz_main_rz_hash().
RZ_API bool rz_hash_plugin_add | ( | RZ_NONNULL RzHash * | rh, |
RZ_NONNULL RZ_OWN const RzHashPlugin * | plugin | ||
) |
Add a new plugin to rh
so that RzHashCfg
can be created using specific algorithms.
Definition at line 609 of file hash.c.
References p, and rz_list_append().
Referenced by lib_hash_cb(), and rz_hash_new().
RZ_API RZ_BORROW const RzHashPlugin* rz_hash_plugin_by_index | ( | RZ_NONNULL RzHash * | rh, |
size_t | index | ||
) |
Definition at line 104 of file hash.c.
References i, NULL, and rz_return_val_if_fail.
Referenced by parse_hash_algorithms(), and rz_hash_show_algorithms().
RZ_API RZ_BORROW const RzHashPlugin* rz_hash_plugin_by_name | ( | RZ_NONNULL RzHash * | rh, |
RZ_NONNULL const char * | name | ||
) |
Definition at line 120 of file hash.c.
References rz_hash_plugin_t::name, NULL, and rz_return_val_if_fail.
Referenced by rz_cmd_print_hash_cfg_handler(), rz_core_bin_resources_print(), rz_core_bin_segments_print(), rz_hash_cfg_calculate_small_block(), search_collisions(), and sections_headers_setup().
RZ_API ut32 rz_hash_xxhash | ( | RZ_NONNULL RzHash * | rh, |
RZ_NONNULL const ut8 * | input, | ||
size_t | size | ||
) |
Definition at line 27 of file hash.c.
References input(), rz_return_val_if_fail, and XXH32().
Referenced by rz_analysis_block_update_hash(), and rz_analysis_block_was_modified().
RZ_LIB_VERSION | ( | rz_hash | ) |
|
static |
Definition at line 25 of file hash.c.
Referenced by rz_hash_new().