Index: lib/md5.c
===================================================================
--- lib/md5.c	(revision 7342cae060d2ac7e6c32d5609978e0e72f5eba3a)
+++ lib/md5.c	(revision 1bdc6696aefb617873b56001f81d649d6ca3aa8e)
@@ -28,7 +28,9 @@
 void md5_digest_keep(md5_state_t *ctx, guint8 digest[MD5_HASH_SIZE])
 {
-	md5_state_t copy = g_checksum_copy(*ctx);
+	gsize digest_len = MD5_HASH_SIZE;
+	GChecksum *copy = g_checksum_copy(*ctx);
 
-	md5_finish(&copy, digest);
+	g_checksum_get_digest(copy, digest, &digest_len);
+	g_checksum_free(copy);
 }
 
Index: lib/md5.h
===================================================================
--- lib/md5.h	(revision 7342cae060d2ac7e6c32d5609978e0e72f5eba3a)
+++ lib/md5.h	(revision 1bdc6696aefb617873b56001f81d649d6ca3aa8e)
@@ -8,12 +8,17 @@
 typedef GChecksum *md5_state_t;
 
-
 #define MD5_HASH_SIZE 16
 
-void md5_init(md5_state_t *);
-void md5_append(md5_state_t *, const guint8 *, unsigned int);
-void md5_finish(md5_state_t *, guint8 digest[MD5_HASH_SIZE]);
-void md5_digest_keep(md5_state_t *, guint8 digest[MD5_HASH_SIZE]);
-void md5_free(md5_state_t *);
+#ifdef __GNUC__
+#define __MD5_NON_PUBLIC_DEPRECATION__ __attribute__((deprecated("md5.h will be removed from Bitlbee's public API. Please use another library (such as GLib's gchecksum) instead")))
+#else
+#define __MD5_NON_PUBLIC_DEPRECATION__
+#endif
+
+void md5_init(md5_state_t *) __MD5_NON_PUBLIC_DEPRECATION__;
+void md5_append(md5_state_t *, const guint8 *, unsigned int) __MD5_NON_PUBLIC_DEPRECATION__;
+void md5_finish(md5_state_t *, guint8 digest[MD5_HASH_SIZE]) __MD5_NON_PUBLIC_DEPRECATION__;
+void md5_digest_keep(md5_state_t *, guint8 digest[MD5_HASH_SIZE]) __MD5_NON_PUBLIC_DEPRECATION__;
+void md5_free(md5_state_t *) __MD5_NON_PUBLIC_DEPRECATION__;
 
 #endif
Index: lib/misc.c
===================================================================
--- lib/misc.c	(revision 7342cae060d2ac7e6c32d5609978e0e72f5eba3a)
+++ lib/misc.c	(revision 1bdc6696aefb617873b56001f81d649d6ca3aa8e)
@@ -34,5 +34,4 @@
 #include "nogaim.h"
 #include "base64.h"
-#include "md5.h"
 #include <stdio.h>
 #include <stdlib.h>
@@ -47,5 +46,4 @@
 #endif
 
-#include "md5.h"
 #include "ssl_client.h"
 
@@ -576,14 +574,16 @@
 int md5_verify_password(char *password, char *hash)
 {
-	md5_byte_t *pass_dec = NULL;
-	md5_byte_t pass_md5[16];
-	md5_state_t md5_state;
+	guint8 *pass_dec = NULL;
+	guint8 pass_md5[16];
+	GChecksum *md5_state;
+	gsize digest_len = MD5_HASH_SIZE;
 	int ret = -1, i;
 
 	if (base64_decode(hash, &pass_dec) == 21) {
-		md5_init(&md5_state);
-		md5_append(&md5_state, (md5_byte_t *) password, strlen(password));
-		md5_append(&md5_state, (md5_byte_t *) pass_dec + 16, 5);  /* Hmmm, salt! */
-		md5_finish(&md5_state, pass_md5);
+		md5_state = g_checksum_new(G_CHECKSUM_MD5);
+		g_checksum_update(md5_state, (guint8 *) password, strlen(password));
+		g_checksum_update(md5_state, (guint8 *) pass_dec + 16, 5);  /* Hmmm, salt! */
+		g_checksum_get_digest(md5_state, pass_md5, &digest_len);
+		g_checksum_free(md5_state);
 
 		for (i = 0; i < 16; i++) {
Index: protocols/jabber/jabber.c
===================================================================
--- protocols/jabber/jabber.c	(revision 7342cae060d2ac7e6c32d5609978e0e72f5eba3a)
+++ protocols/jabber/jabber.c	(revision 1bdc6696aefb617873b56001f81d649d6ca3aa8e)
@@ -33,5 +33,4 @@
 #include "jabber.h"
 #include "oauth.h"
-#include "md5.h"
 
 GSList *jabber_connections;
@@ -301,18 +300,18 @@
 }
 
-/* This generates an unfinished md5_state_t variable. Every time we generate
+/* This generates an unfinished g_checksum variable. Every time we generate
    an ID, we finish the state by adding a sequence number and take the hash. */
 static void jabber_generate_id_hash(struct jabber_data *jd)
 {
-	md5_byte_t binbuf[4];
+	guint8 binbuf[4];
 	char *s;
 
-	md5_init(&jd->cached_id_prefix);
-	md5_append(&jd->cached_id_prefix, (unsigned char *) jd->username, strlen(jd->username));
-	md5_append(&jd->cached_id_prefix, (unsigned char *) jd->server, strlen(jd->server));
+	jd->cached_id_prefix = g_checksum_new(G_CHECKSUM_MD5);
+	g_checksum_update(jd->cached_id_prefix, jd->username, strlen(jd->username));
+	g_checksum_update(jd->cached_id_prefix, jd->server, strlen(jd->server));
 	s = set_getstr(&jd->ic->acc->set, "resource");
-	md5_append(&jd->cached_id_prefix, (unsigned char *) s, strlen(s));
+	g_checksum_update(jd->cached_id_prefix, s, strlen(s));
 	random_bytes(binbuf, 4);
-	md5_append(&jd->cached_id_prefix, binbuf, 4);
+	g_checksum_update(jd->cached_id_prefix, binbuf, 4);
 }
 
@@ -371,5 +370,5 @@
 	xt_free(jd->xt);
 
-	md5_free(&jd->cached_id_prefix);
+	g_checksum_free(jd->cached_id_prefix);
 
 	g_free(jd->oauth2_access_token);
Index: protocols/jabber/jabber.h
===================================================================
--- protocols/jabber/jabber.h	(revision 7342cae060d2ac7e6c32d5609978e0e72f5eba3a)
+++ protocols/jabber/jabber.h	(revision 1bdc6696aefb617873b56001f81d649d6ca3aa8e)
@@ -28,5 +28,4 @@
 
 #include "bitlbee.h"
-#include "md5.h"
 #include "xmltree.h"
 
@@ -105,5 +104,5 @@
 	char *gmail_tid;
 
-	md5_state_t cached_id_prefix;
+	GChecksum *cached_id_prefix;
 	GHashTable *node_cache;
 	GHashTable *buddies;
Index: protocols/jabber/jabber_util.c
===================================================================
--- protocols/jabber/jabber_util.c	(revision 7342cae060d2ac7e6c32d5609978e0e72f5eba3a)
+++ protocols/jabber/jabber_util.c	(revision 1bdc6696aefb617873b56001f81d649d6ca3aa8e)
@@ -23,5 +23,4 @@
 
 #include "jabber.h"
-#include "md5.h"
 #include "base64.h"
 
@@ -141,6 +140,7 @@
 	struct jabber_data *jd = ic->proto_data;
 	struct jabber_cache_entry *entry = g_new0(struct jabber_cache_entry, 1);
-	md5_state_t id_hash;
-	md5_byte_t id_sum[16];
+	GChecksum *id_hash;
+	gsize digest_len = MD5_HASH_SIZE;
+	guint8 id_sum[MD5_HASH_SIZE];
 	char *id, *asc_hash;
 
@@ -148,6 +148,8 @@
 
 	id_hash = jd->cached_id_prefix;
-	md5_append(&id_hash, (md5_byte_t *) &next_id, sizeof(next_id));
-	md5_digest_keep(&id_hash, id_sum);
+	g_checksum_update(id_hash, (guint8 *) &next_id, sizeof(next_id));
+	g_checksum_get_digest(id_hash, id_sum, &digest_len);
+	g_checksum_free(id_hash);
+
 	asc_hash = base64_encode(id_sum, 12);
 
Index: protocols/jabber/sasl.c
===================================================================
--- protocols/jabber/sasl.c	(revision 7342cae060d2ac7e6c32d5609978e0e72f5eba3a)
+++ protocols/jabber/sasl.c	(revision 1bdc6696aefb617873b56001f81d649d6ca3aa8e)
@@ -302,6 +302,7 @@
 	if (!(s = sasl_get_part(dec, "rspauth"))) {
 		/* See RFC 2831 for for information. */
-		md5_state_t A1, A2, H;
-		md5_byte_t A1r[16], A2r[16], Hr[16];
+		GChecksum *A1, *A2, *H;
+		gsize digest_len = MD5_HASH_SIZE;
+		guint8 A1r[16], A2r[16], Hr[16];
 		char A1h[33], A2h[33], Hh[33];
 		int i;
@@ -327,17 +328,20 @@
 		/* Generate the MD5 hash of username:realm:password,
 		   I decided to call it H. */
-		md5_init(&H);
+		H = g_checksum_new(G_CHECKSUM_MD5);
 		s = g_strdup_printf("%s:%s:%s", jd->username, realm, ic->acc->pass);
-		md5_append(&H, (unsigned char *) s, strlen(s));
+		g_checksum_update(H, (guint8 *)s, strlen(s));
 		g_free(s);
-		md5_finish(&H, Hr);
+
+		g_checksum_get_digest(H, Hr, &digest_len);
+		g_checksum_free(H);
 
 		/* Now generate the hex. MD5 hash of H:nonce:cnonce, called A1. */
-		md5_init(&A1);
+		A1 = g_checksum_new(G_CHECKSUM_MD5);
 		s = g_strdup_printf(":%s:%s", nonce, cnonce);
-		md5_append(&A1, Hr, 16);
-		md5_append(&A1, (unsigned char *) s, strlen(s));
+		g_checksum_update(A1, Hr, 16);
+		g_checksum_update(A1, (guint8 *)s, strlen(s));
 		g_free(s);
-		md5_finish(&A1, A1r);
+		g_checksum_get_digest(A1, A1r, &digest_len);
+		g_checksum_free(A1);
 		for (i = 0; i < 16; i++) {
 			sprintf(A1h + i * 2, "%02x", A1r[i]);
@@ -345,9 +349,10 @@
 
 		/* A2... */
-		md5_init(&A2);
+		A2 = g_checksum_new(G_CHECKSUM_MD5);
 		s = g_strdup_printf("%s:%s", "AUTHENTICATE", digest_uri);
-		md5_append(&A2, (unsigned char *) s, strlen(s));
+		g_checksum_update(A2, (guint8 *)s, strlen(s));
 		g_free(s);
-		md5_finish(&A2, A2r);
+		g_checksum_get_digest(A2, A2r, &digest_len);
+		g_checksum_free(A2);
 		for (i = 0; i < 16; i++) {
 			sprintf(A2h + i * 2, "%02x", A2r[i]);
@@ -355,9 +360,11 @@
 
 		/* Final result: A1:nonce:00000001:cnonce:auth:A2. Let's reuse H for it. */
-		md5_init(&H);
+		H = g_checksum_new(G_CHECKSUM_MD5);
 		s = g_strdup_printf("%s:%s:%s:%s:%s:%s", A1h, nonce, "00000001", cnonce, "auth", A2h);
-		md5_append(&H, (unsigned char *) s, strlen(s));
+		g_checksum_update(H, (guint8 *)s, strlen(s));
 		g_free(s);
-		md5_finish(&H, Hr);
+		g_checksum_get_digest(H, Hr, &digest_len);
+		g_checksum_free(H);
+
 		for (i = 0; i < 16; i++) {
 			sprintf(Hh + i * 2, "%02x", Hr[i]);
Index: storage_xml.c
===================================================================
--- storage_xml.c	(revision 7342cae060d2ac7e6c32d5609978e0e72f5eba3a)
+++ storage_xml.c	(revision 1bdc6696aefb617873b56001f81d649d6ca3aa8e)
@@ -28,5 +28,4 @@
 #include "base64.h"
 #include "arc.h"
-#include "md5.h"
 #include "xmltree.h"
 
@@ -323,8 +322,9 @@
 	char *pass_buf = NULL;
 	account_t *acc;
-	md5_byte_t pass_md5[21];
-	md5_state_t md5_state;
+	guint8 pass_md5[21];
+	GChecksum *md5_state;
 	GSList *l;
 	struct xt_node *root, *cur;
+	gsize digest_len = MD5_HASH_SIZE;
 
 	root = cur = xt_new_node("user", NULL, NULL);
@@ -336,8 +336,9 @@
 		   byte password hash, more convenient for base64 encoding. */
 		random_bytes(pass_md5 + 16, 5);
-		md5_init(&md5_state);
-		md5_append(&md5_state, (md5_byte_t *) irc->password, strlen(irc->password));
-		md5_append(&md5_state, pass_md5 + 16, 5);   /* Add the salt. */
-		md5_finish(&md5_state, pass_md5);
+		md5_state = g_checksum_new(G_CHECKSUM_MD5);
+		g_checksum_update(md5_state, (guint8 *) irc->password, strlen(irc->password));
+		g_checksum_update(md5_state, pass_md5 + 16, 5);   /* Add the salt. */
+		g_checksum_get_digest(md5_state, pass_md5, &digest_len);
+		g_checksum_free(md5_state);
 		/* Save the hash in base64-encoded form. */
 		pass_buf = base64_encode(pass_md5, 21);
Index: unix.c
===================================================================
--- unix.c	(revision 7342cae060d2ac7e6c32d5609978e0e72f5eba3a)
+++ unix.c	(revision 1bdc6696aefb617873b56001f81d649d6ca3aa8e)
@@ -261,13 +261,15 @@
 		g_free(pass_cl);
 	} else if (strcmp(argv[2], "hash") == 0) {
-		md5_byte_t pass_md5[21];
-		md5_state_t md5_state;
+		guint8 pass_md5[21];
+		GChecksum *md5_state;
+		gsize digest_len = MD5_HASH_SIZE;
 		char *encoded;
 
 		random_bytes(pass_md5 + 16, 5);
-		md5_init(&md5_state);
-		md5_append(&md5_state, (md5_byte_t *) argv[3], strlen(argv[3]));
-		md5_append(&md5_state, pass_md5 + 16, 5);   /* Add the salt. */
-		md5_finish(&md5_state, pass_md5);
+		md5_state = g_checksum_new(G_CHECKSUM_MD5);
+		g_checksum_update(md5_state, (guint8 *) argv[3], strlen(argv[3]));
+		g_checksum_update(md5_state, pass_md5 + 16, 5);   /* Add the salt. */
+		g_checksum_get_digest(md5_state, pass_md5, &digest_len);
+		g_checksum_free(md5_state);
 
 		encoded = base64_encode(pass_md5, 21);
