summaryrefslogtreecommitdiff
path: root/dev-util/rizin/files/rizin-0.3.0-md4-openssl.patch
blob: d2c3135d1c723ff4e3949aa32e0bfccfad2ff3a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
From 6a1edf5fb6967d57d1dcc8cf21ea3a6bbdf8a5b8 Mon Sep 17 00:00:00 2001
From: wargio <wargio@libero.it>
Date: Sat, 2 Oct 2021 22:36:32 +0200
Subject: [PATCH 1/2] Fix nullptr due missing small_block method when openssl
 is used.

---
 librz/hash/algorithms/openssl_common.h | 42 ++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/librz/hash/algorithms/openssl_common.h b/librz/hash/algorithms/openssl_common.h
index b29a1ae1221..e2399cff68d 100644
--- a/librz/hash/algorithms/openssl_common.h
+++ b/librz/hash/algorithms/openssl_common.h
@@ -76,6 +76,46 @@ EVP_sha512
 		return true; \
 	}
 
+#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) { \
+		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); \
+		ut8 *dgst = malloc(dgst_size); \
+		if (!dgst) { \
+			return false; \
+		} \
+		EVP_MD_CTX *context = EVP_MD_CTX_new(); \
+		if (!context) { \
+			free(dgst); \
+			return false; \
+		} \
+		if (EVP_DigestInit_ex(context, evp_md, NULL) != 1) { \
+			EVP_MD_CTX_free(context); \
+			free(dgst); \
+			return false; \
+		} \
+		if (EVP_DigestUpdate(context, data, size) != 1) { \
+			EVP_MD_CTX_free(context); \
+			free(dgst); \
+			return false; \
+		} \
+		if (EVP_DigestFinal_ex(context, dgst, NULL) != 1) { \
+			EVP_MD_CTX_free(context); \
+			free(dgst); \
+			return false; \
+		} \
+		*digest = dgst; \
+		if (digest_size) { \
+			*digest_size = dgst_size; \
+		} \
+		EVP_MD_CTX_free(context); \
+		return true; \
+	}
+
 #define rz_openssl_plugin_define_msg_digest(pluginname, evpmd, canhmac) \
 	rz_openssl_plugin_context_new(pluginname); \
 	rz_openssl_plugin_context_free(pluginname); \
@@ -84,6 +124,7 @@ EVP_sha512
 	rz_openssl_plugin_init(pluginname, evpmd); \
 	rz_openssl_plugin_update(pluginname); \
 	rz_openssl_plugin_final(pluginname); \
+	rz_openssl_plugin_small_block(pluginname, evpmd); \
 	RzMsgDigestPlugin rz_msg_digest_plugin_##pluginname = { \
 		.name = #pluginname, \
 		.license = "Apache 2.0", \
@@ -96,6 +137,7 @@ EVP_sha512
 		.init = openssl_plugin_##pluginname##_init, \
 		.update = openssl_plugin_##pluginname##_update, \
 		.final = openssl_plugin_##pluginname##_final, \
+		.small_block = openssl_plugin_##pluginname##_small_block, \
 	}
 
 #endif /* RZ_OPENSSL_COMMON_H */

From f4a8e2c86be861f33327c2a8f1d181b42232069e Mon Sep 17 00:00:00 2001
From: wargio <wargio@libero.it>
Date: Sat, 2 Oct 2021 23:07:54 +0200
Subject: [PATCH 2/2] Fix style

---
 librz/hash/algorithms/openssl_common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/librz/hash/algorithms/openssl_common.h b/librz/hash/algorithms/openssl_common.h
index e2399cff68d..0091fef2fa3 100644
--- a/librz/hash/algorithms/openssl_common.h
+++ b/librz/hash/algorithms/openssl_common.h
@@ -78,7 +78,7 @@ 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) { \
-		rz_return_val_if_fail(data &&digest, false); \
+		rz_return_val_if_fail((data) && (digest), false); \
 		const EVP_MD *evp_md = evpmd(); \
 		if (!evp_md) { \
 			return false; \