Rizin
unix-like reverse engineering framework and cli tools
rz_hash.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #ifndef RZ_MSG_DIGEST_H
5 #define RZ_MSG_DIGEST_H
6 
7 #include <rz_types.h>
8 #include <rz_list.h>
9 #include <rz_util/rz_mem.h>
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
16 
17 typedef enum {
22 } RzHashStatus;
23 
24 typedef ut32 RzHashSize;
25 
26 typedef struct rz_hash_plugin_t {
27  const char *name;
28  const char *license;
29  const char *author;
31  void *(*context_new)();
32  void (*context_free)(void *context);
35  bool (*init)(void *context);
36  bool (*update)(void *context, const ut8 *data, ut64 size);
37  bool (*final)(void *context, ut8 *digest);
38  bool (*small_block)(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size);
40 
41 typedef struct rz_hash_t {
42  RzList /*<RzHashPlugin *>*/ *plugins;
44 
45 typedef struct rz_hash_cfg_t {
50 
51 #ifdef RZ_API
52 
54 RZ_API void rz_hash_free(RzHash *rh);
58 
61 #define rz_hash_cfg_new_with_algo2(rh, name) rz_hash_cfg_new_with_algo(rh, name, NULL, 0);
63 
69 RZ_API bool rz_hash_cfg_iterate(RZ_NONNULL RzHashCfg *md, size_t iterate);
76 
78 RZ_API double rz_hash_entropy(RZ_NONNULL RzHash *rh, RZ_NONNULL const ut8 *data, ut64 len);
80 
81 #endif
82 
83 /* importing all message digest plugins */
152 
153 #ifdef __cplusplus
154 }
155 #endif
156 
157 #endif /* RZ_MSG_DIGEST_H */
size_t len
Definition: 6502dis.c:15
static unsigned invert(unsigned x)
Definition: aesdata.c:73
#define RZ_API
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
uint32_t ut32
RZ_API double rz_hash_entropy_fraction(RZ_NONNULL RzHash *rh, RZ_NONNULL const ut8 *data, ut64 len)
Definition: hash.c:45
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.
Definition: hash.c:445
RZ_API RZ_OWN RzHashCfg * rz_hash_cfg_new(RZ_NONNULL RzHash *rh)
Definition: hash.c:134
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: hash.c:609
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: hash.c:545
RZ_API void rz_hash_cfg_free(RZ_NONNULL RzHashCfg *md)
Definition: hash.c:186
RZ_API bool rz_hash_cfg_iterate(RZ_NONNULL RzHashCfg *md, size_t iterate)
Calculate the final hash by iterating its result N times.
Definition: hash.c:414
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.
Definition: hash.c:510
RZ_API void rz_hash_free(RzHash *rh)
Definition: hash.c:597
RZ_API RZ_BORROW const RzHashPlugin * rz_hash_plugin_by_name(RZ_NONNULL RzHash *rh, RZ_NONNULL const char *name)
Definition: hash.c:120
RZ_API RZ_BORROW const RzHashPlugin * rz_hash_plugin_by_index(RZ_NONNULL RzHash *rh, size_t index)
Definition: hash.c:104
RZ_API ut32 rz_hash_xxhash(RZ_NONNULL RzHash *rh, RZ_NONNULL const ut8 *input, size_t size)
Definition: hash.c:27
RZ_API RzHash * rz_hash_new(void)
Definition: hash.c:585
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.
Definition: hash.c:529
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.
Definition: hash.c:161
RZ_API bool rz_hash_cfg_configure(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const char *name)
Allocates and configures the plugin message digest context.
Definition: hash.c:199
RZ_API double rz_hash_entropy(RZ_NONNULL RzHash *rh, RZ_NONNULL const ut8 *data, ut64 len)
Definition: hash.c:32
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.
Definition: hash.c:250
RZ_API bool rz_hash_cfg_init(RZ_NONNULL RzHashCfg *md)
Resets/initialize the message digest contextes.
Definition: hash.c:298
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.
Definition: hash.c:337
RZ_API bool rz_hash_cfg_final(RZ_NONNULL RzHashCfg *md)
Generates the final value of the message digest contextes.
Definition: hash.c:359
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.
Definition: hash.c:469
voidpf void uLong size
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
RZ_API RZ_OWN char * rz_hash_cfg_randomart(RZ_NONNULL const ut8 *buffer, ut32 length, ut64 address)
Generates a randomart that is meant to be an easily validate buffers.
Definition: randomart.c:55
RzHashPlugin rz_hash_plugin_crca_crc32ecma267
RzHashPlugin rz_hash_plugin_adler32
Definition: algo_adler32.c:65
RZ_LIB_VERSION_HEADER(rz_hash)
RzHashPlugin rz_hash_plugin_crca_crc16dnp
RzHashPlugin rz_hash_plugin_md4
Definition: algo_md4.c:78
RzHashPlugin rz_hash_plugin_fletcher32
RzHashPlugin rz_hash_plugin_crca_crc16genibus
RzHashPlugin rz_hash_plugin_crca_crc8smbus
RzHashPlugin rz_hash_plugin_crca_crc16usb
RzHashPlugin rz_hash_plugin_crca_crc32d
RzHashPlugin rz_hash_plugin_crca_crc16modbus
RzHashPlugin rz_hash_plugin_md5
Definition: algo_md5.c:78
RzHashPlugin rz_hash_plugin_crca_crc8maxim
RzHashPlugin rz_hash_plugin_crca_crc8dvbs2
RzHashPlugin rz_hash_plugin_xxhash32
Definition: algo_xxhash32.c:66
RzHashStatus
Definition: rz_hash.h:17
@ RZ_MSG_DIGEST_STATUS_INIT
Definition: rz_hash.h:19
@ RZ_MSG_DIGEST_STATUS_ALLOC
Definition: rz_hash.h:18
@ RZ_MSG_DIGEST_STATUS_UPDATE
Definition: rz_hash.h:20
@ RZ_MSG_DIGEST_STATUS_FINAL
Definition: rz_hash.h:21
RzHashPlugin rz_hash_plugin_crca_crc16en13757
RzHashPlugin rz_hash_plugin_crca_crc32posix
RzHashPlugin rz_hash_plugin_crca_crc16maxim
RzHashPlugin rz_hash_plugin_crca_crc32
ut32 RzHashSize
Definition: rz_hash.h:24
RzHashPlugin rz_hash_plugin_fletcher8
RzHashPlugin rz_hash_plugin_crca_crc8itu
RzHashPlugin rz_hash_plugin_sha512
Definition: algo_sha512.c:78
RzHashPlugin rz_hash_plugin_crca_crc16buypass
RzHashPlugin rz_hash_plugin_crca_crc16t10dif
RzHashPlugin rz_hash_plugin_xor8
Definition: algo_xor8.c:65
RzHashPlugin rz_hash_plugin_crca_crc16dds110
RzHashPlugin rz_hash_plugin_sha1
Definition: algo_sha1.c:78
RzHashPlugin rz_hash_plugin_crca_crc8ebu
RzHashPlugin rz_hash_plugin_crca_crc16teledisk
RzHashPlugin rz_hash_plugin_crca_crc64iso
RzHashPlugin rz_hash_plugin_crca_crc32c
RzHashPlugin rz_hash_plugin_crca_crc8wcdma
RzHashPlugin rz_hash_plugin_crca_crc16tms37157
RzHashPlugin rz_hash_plugin_crca_crc16riello
RzHashPlugin rz_hash_plugin_crca_crc16x25
RzHashPlugin rz_hash_plugin_crca_crc32bzip2
RzHashPlugin rz_hash_plugin_crca_crc8rohc
RzHashPlugin rz_hash_plugin_fletcher64
RzHashPlugin rz_hash_plugin_crca_crc16mcrf4xx
RzHashPlugin rz_hash_plugin_crca_crc16cdma2000
RzHashPlugin rz_hash_plugin_crca_crc8darc
RzHashPlugin rz_hash_plugin_parity
Definition: algo_parity.c:65
RzHashPlugin rz_hash_plugin_crca_crc16dectr
RzHashPlugin rz_hash_plugin_crca_crc16dectx
RzHashPlugin rz_hash_plugin_crca_crc16xmodem
RzHashPlugin rz_hash_plugin_crca_crc32xfer
RzHashPlugin rz_hash_plugin_crca_crc32q
RzHashPlugin rz_hash_plugin_crca_crc16hdlc
RzHashPlugin rz_hash_plugin_xor16
Definition: algo_xor16.c:65
RzHashPlugin rz_hash_plugin_entropy
Definition: algo_entropy.c:65
RzHashPlugin rz_hash_plugin_crca_crc64we
RzHashPlugin rz_hash_plugin_crca_crc32jamcrc
RzHashPlugin rz_hash_plugin_entropy_fract
RzHashPlugin rz_hash_plugin_sha384
Definition: algo_sha384.c:78
RzHashPlugin rz_hash_plugin_sha256
Definition: algo_sha256.c:78
RzHashPlugin rz_hash_plugin_crca_crc15can
struct rz_hash_t RzHash
RzHashPlugin rz_hash_plugin_crca_crc24
RzHashPlugin rz_hash_plugin_crca_crc16augccitt
RzHashPlugin rz_hash_plugin_crca_crc64ecma182
RzHashPlugin rz_hash_plugin_crca_crc8icode
RzHashPlugin rz_hash_plugin_crca_crc16
struct rz_hash_cfg_t RzHashCfg
RzHashPlugin rz_hash_plugin_crca_crc16citt
RzHashPlugin rz_hash_plugin_crca_crc64xz
RzHashPlugin rz_hash_plugin_crca_crc32mpeg2
RzHashPlugin rz_hash_plugin_crca_crca
RzHashPlugin rz_hash_plugin_crca_crc8cdma2000
RzHashPlugin rz_hash_plugin_crca_crc16kermit
struct rz_hash_plugin_t RzHashPlugin
RzHashPlugin rz_hash_plugin_fletcher16
RzHashPlugin rz_hash_plugin_crca_crc64
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_BORROW
Definition: rz_types.h:63
Definition: buffer.h:15
Definition: z80asm.h:102
RzHashStatus status
Definition: rz_hash.h:47
RzList * configurations
Definition: rz_hash.h:46
RzHash * hash
Definition: rz_hash.h:48
const char * name
Definition: rz_hash.h:27
bool support_hmac
Definition: rz_hash.h:30
RzHashSize(* block_size)(void *context)
Definition: rz_hash.h:34
RzHashSize(* digest_size)(void *context)
Definition: rz_hash.h:33
bool(* small_block)(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size)
Definition: rz_hash.h:38
bool(* update)(void *context, const ut8 *data, ut64 size)
Definition: rz_hash.h:36
const char * author
Definition: rz_hash.h:29
bool(* init)(void *context)
Definition: rz_hash.h:35
const char * license
Definition: rz_hash.h:28
void(* context_free)(void *context)
Definition: rz_hash.h:32
RzList * plugins
Definition: rz_hash.h:42
#define bool
Definition: sysdefs.h:146
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)