aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremanuele-f <faranda@ntop.org>2019-11-20 11:57:21 +0100
committeremanuele-f <faranda@ntop.org>2019-11-20 11:57:21 +0100
commit68b7986d9b9f5465fc727d454c9c38f2f1d4338e (patch)
tree67887eca7684afbdefcc13191e4f2ac47e7a7035
parentead0325debc96b2d134a625b4fac184a979ccc5a (diff)
Expose API to calculate the MD5 hash
-rw-r--r--src/include/ndpi_api.h2
-rw-r--r--src/lib/ndpi_main.c11
2 files changed, 13 insertions, 0 deletions
diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h
index 7ad734e85..669f59dda 100644
--- a/src/include/ndpi_api.h
+++ b/src/include/ndpi_api.h
@@ -855,6 +855,8 @@ extern "C" {
ndpi_protocol l7_protocol,
ndpi_serializer *serializer);
+ void ndpi_md5(const u_char *data, size_t data_len, u_char hash[16]);
+
/* ptree (trie) API */
ndpi_ptree_t* ndpi_ptree_create(void);
int ndpi_ptree_insert(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, u_int8_t bits, uint user_data);
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index e7172a589..572c2a736 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -48,6 +48,7 @@
#include "ndpi_content_match.c.inc"
#include "third_party/include/ndpi_patricia.h"
#include "third_party/include/ht_hash.h"
+#include "third_party/include/ndpi_md5.h"
/* stun.c */
extern u_int32_t get_stun_lru_key(struct ndpi_flow_struct *flow, u_int8_t rev);
@@ -6711,3 +6712,13 @@ int ndpi_ptree_match_addr(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, uint *
return(-1);
}
+
+/* ******************************************************************** */
+
+void ndpi_md5(const u_char *data, size_t data_len, u_char hash[16]) {
+ ndpi_MD5_CTX ctx;
+
+ ndpi_MD5Init(&ctx);
+ ndpi_MD5Update(&ctx, data, data_len);
+ ndpi_MD5Final(hash, &ctx);
+}