Rizin
unix-like reverse engineering framework and cli tools
algo_md5.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_hash.h>
5 #include <rz_util/rz_assert.h>
6 
7 #if HAVE_LIB_SSL
12 #include "../algorithms/openssl_common.h"
13 rz_openssl_plugin_define_hash_cfg(md5, EVP_md5, true);
14 
15 #else /* HAVE_LIB_SSL */
20 #include "../algorithms/md5/md5.h"
21 
22 static void *plugin_md5_context_new() {
23  return RZ_NEW0(rz_MD5_CTX);
24 }
25 
26 static void plugin_md5_context_free(void *context) {
27  free(context);
28 }
29 
32 }
33 
36 }
37 
38 static bool plugin_md5_init(void *context) {
40 
42  return true;
43 }
44 
45 static bool plugin_md5_update(void *context, const ut8 *data, ut64 size) {
46  rz_return_val_if_fail(context && data, false);
47 
49  return true;
50 }
51 
52 static bool plugin_md5_final(void *context, ut8 *digest) {
53  rz_return_val_if_fail(context && digest, false);
54 
55  rz_MD5Final(digest, (rz_MD5_CTX *)context);
56  return true;
57 }
58 
59 static bool plugin_md5_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size) {
60  rz_return_val_if_fail(data && digest, false);
62  if (!dgst) {
63  return false;
64  }
65 
67  rz_MD5Init(&ctx);
68  rz_MD5Update(&ctx, data, size);
69  rz_MD5Final(dgst, &ctx);
70 
71  *digest = dgst;
72  if (digest_size) {
73  *digest_size = RZ_HASH_MD5_DIGEST_SIZE;
74  }
75  return true;
76 }
77 
79  .name = "md5",
80  .license = "LGPL2",
81  .author = "Alan DeKok (md5 algorithm implementation), deroad (plugin)",
82  .support_hmac = true,
83  .context_new = plugin_md5_context_new,
84  .context_free = plugin_md5_context_free,
85  .digest_size = plugin_md5_digest_size,
86  .block_size = plugin_md5_block_size,
87  .init = plugin_md5_init,
88  .update = plugin_md5_update,
89  .final = plugin_md5_final,
90  .small_block = plugin_md5_small_block,
91 };
92 
93 #endif /* HAVE_LIB_SSL */
94 
95 #ifndef RZ_PLUGIN_INCORE
98  .data = &rz_hash_plugin_md5,
99  .version = RZ_VERSION
100 };
101 #endif
static bool plugin_md5_update(void *context, const ut8 *data, ut64 size)
Definition: algo_md5.c:45
static RzHashSize plugin_md5_block_size(void *context)
Definition: algo_md5.c:34
static void * plugin_md5_context_new()
Definition: algo_md5.c:22
static bool plugin_md5_final(void *context, ut8 *digest)
Definition: algo_md5.c:52
RzHashPlugin rz_hash_plugin_md5
Definition: algo_md5.c:78
static void plugin_md5_context_free(void *context)
Definition: algo_md5.c:26
static RzHashSize plugin_md5_digest_size(void *context)
Definition: algo_md5.c:30
RZ_API RzLibStruct rizin_plugin
Definition: algo_md5.c:96
static bool plugin_md5_small_block(const ut8 *data, ut64 size, ut8 **digest, RzHashSize *digest_size)
Definition: algo_md5.c:59
static bool plugin_md5_init(void *context)
Definition: algo_md5.c:38
#define RZ_API
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
RZ_IPI void rz_MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], rz_MD5_CTX *ctx)
Definition: md5.c:218
RZ_IPI void rz_MD5Init(rz_MD5_CTX *ctx)
Definition: md5.c:163
RZ_IPI void rz_MD5Update(rz_MD5_CTX *ctx, const unsigned char *input, size_t len)
Definition: md5.c:176
#define RZ_HASH_MD5_DIGEST_SIZE
Definition: md5.h:9
#define RZ_HASH_MD5_BLOCK_LENGTH
Definition: md5.h:10
void * malloc(size_t size)
Definition: malloc.c:123
#define rz_openssl_plugin_define_hash_cfg(pluginname, evpmd, canhmac)
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
ut32 RzHashSize
Definition: rz_hash.h:24
@ RZ_LIB_TYPE_HASH
Definition: rz_lib.h:82
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_VERSION
Definition: rz_version.h:8
Definition: md5.h:36
const char * name
Definition: rz_hash.h:27
ut64(WINAPI *w32_GetEnabledXStateFeatures)()