7403af
From aaf322dad16235a4af7b9eb101f19153ae1c2c8a Mon Sep 17 00:00:00 2001
7403af
From: Debarshi Ray <debarshir@gnome.org>
7403af
Date: Tue, 9 Oct 2018 18:33:11 +0200
7403af
Subject: [PATCH 1/2] Drop AIM, Gadu-Gadu and ICQ
7403af
7403af
https://bugzilla.redhat.com/show_bug.cgi?id=1026505
7403af
https://bugzilla.redhat.com/show_bug.cgi?id=1500403
7403af
https://bugzilla.redhat.com/show_bug.cgi?id=1579978
7403af
https://bugzilla.redhat.com/show_bug.cgi?id=1637801
7403af
---
7403af
 configure.ac                      | 4 ++--
7403af
 libpurple/tests/Makefile.am       | 2 --
7403af
 libpurple/tests/check_libpurple.c | 1 -
7403af
 3 files changed, 2 insertions(+), 5 deletions(-)
7403af
7403af
diff --git a/configure.ac b/configure.ac
7403af
index f973af051bcb..4509a5c58b6c 100644
7403af
--- a/configure.ac
7403af
+++ b/configure.ac
7403af
@@ -1189,7 +1189,7 @@ if test "x$STATIC_PRPLS" != "x" -a "x$DYNAMIC_PRPLS" = "xall"; then
7403af
 fi
7403af
 
7403af
 if test "x$STATIC_PRPLS" = "xall" ; then
7403af
-	STATIC_PRPLS="bonjour gg irc jabber novell oscar sametime silc simple zephyr"
7403af
+	STATIC_PRPLS="bonjour irc jabber novell sametime silc simple zephyr"
7403af
 fi
7403af
 if test "x$have_meanwhile" != "xyes" ; then
7403af
 	STATIC_PRPLS=`echo $STATIC_PRPLS | $sedpath 's/sametime//'`
7403af
@@ -1260,7 +1260,7 @@ AC_DEFINE_UNQUOTED(STATIC_PROTO_INIT, $extern_init static void static_proto_init
7403af
 
7403af
 AC_ARG_WITH(dynamic_prpls, [AC_HELP_STRING([--with-dynamic-prpls], [specify which protocols to build dynamically])], [DYNAMIC_PRPLS=`echo $withval | $sedpath 's/,/ /g'`])
7403af
 if test "x$DYNAMIC_PRPLS" = "xall" ; then
7403af
-	DYNAMIC_PRPLS="bonjour gg irc jabber novell oscar sametime silc simple zephyr"
7403af
+	DYNAMIC_PRPLS="bonjour irc jabber novell sametime silc simple zephyr"
7403af
 fi
7403af
 if test "x$have_meanwhile" != "xyes"; then
7403af
 	DYNAMIC_PRPLS=`echo $DYNAMIC_PRPLS | $sedpath 's/sametime//'`
7403af
diff --git a/libpurple/tests/Makefile.am b/libpurple/tests/Makefile.am
7403af
index fa49f8a3a5c3..467c7438a766 100644
7403af
--- a/libpurple/tests/Makefile.am
7403af
+++ b/libpurple/tests/Makefile.am
7403af
@@ -14,7 +14,6 @@ check_libpurple_SOURCES=\
7403af
 		test_jabber_digest_md5.c \
7403af
 		test_jabber_jutil.c \
7403af
 		test_jabber_scram.c \
7403af
-		test_oscar_util.c \
7403af
 		test_util.c \
7403af
 		test_xmlnode.c \
7403af
 		$(top_builddir)/libpurple/util.h
7403af
@@ -30,7 +29,6 @@ check_libpurple_CFLAGS=\
7403af
 
7403af
 check_libpurple_LDADD=\
7403af
 		$(top_builddir)/libpurple/protocols/jabber/libjabber.la \
7403af
-		$(top_builddir)/libpurple/protocols/oscar/liboscar.la \
7403af
 		$(top_builddir)/libpurple/libpurple.la \
7403af
         @CHECK_LIBS@ \
7403af
 		$(GLIB_LIBS)
7403af
diff --git a/libpurple/tests/check_libpurple.c b/libpurple/tests/check_libpurple.c
7403af
index ace7d1eb9d7b..fa32d996094a 100644
7403af
--- a/libpurple/tests/check_libpurple.c
7403af
+++ b/libpurple/tests/check_libpurple.c
7403af
@@ -91,7 +91,6 @@ int main(void)
7403af
 	srunner_add_suite(sr, jabber_digest_md5_suite());
7403af
 	srunner_add_suite(sr, jabber_jutil_suite());
7403af
 	srunner_add_suite(sr, jabber_scram_suite());
7403af
-	srunner_add_suite(sr, oscar_util_suite());
7403af
 	srunner_add_suite(sr, util_suite());
7403af
 	srunner_add_suite(sr, xmlnode_suite());
7403af
 
7403af
-- 
7403af
2.20.1
7403af
7403af
7403af
From d5015b7560947a7a4f057281b1bdf6d6e114f421 Mon Sep 17 00:00:00 2001
7403af
From: Debarshi Ray <debarshir@gnome.org>
7403af
Date: Fri, 7 Jun 2019 17:47:03 +0200
7403af
Subject: [PATCH 2/2] Port to GHmac
7403af
7403af
https://bugzilla.redhat.com/show_bug.cgi?id=1637801
7403af
---
7403af
 libpurple/cipher.c                      |   2 -
7403af
 libpurple/ciphers/Makefile.am           |   1 -
7403af
 libpurple/ciphers/hmac.c                | 218 -----------------
7403af
 libpurple/protocols/jabber/auth.c       |  16 +-
7403af
 libpurple/protocols/jabber/auth_scram.c |  65 +++--
7403af
 libpurple/protocols/jabber/auth_scram.h |   3 +-
7403af
 libpurple/tests/test_cipher.c           | 311 ------------------------
7403af
 libpurple/tests/test_jabber_scram.c     |   2 +-
7403af
 8 files changed, 41 insertions(+), 577 deletions(-)
7403af
 delete mode 100644 libpurple/ciphers/hmac.c
7403af
7403af
diff --git a/libpurple/cipher.c b/libpurple/cipher.c
7403af
index d0a7bb7937ac..bc613ffab916 100644
7403af
--- a/libpurple/cipher.c
7403af
+++ b/libpurple/cipher.c
7403af
@@ -230,7 +230,6 @@ purple_ciphers_get_handle() {
7403af
  */
7403af
 PurpleCipherOps *purple_des_cipher_get_ops();
7403af
 PurpleCipherOps *purple_des3_cipher_get_ops();
7403af
-PurpleCipherOps *purple_hmac_cipher_get_ops();
7403af
 PurpleCipherOps *purple_md4_cipher_get_ops();
7403af
 PurpleCipherOps *purple_md5_cipher_get_ops();
7403af
 PurpleCipherOps *purple_rc4_cipher_get_ops();
7403af
@@ -256,7 +255,6 @@ purple_ciphers_init() {
7403af
 	purple_ciphers_register_cipher("sha1", purple_sha1_cipher_get_ops());
7403af
 	purple_ciphers_register_cipher("sha256", purple_sha256_cipher_get_ops());
7403af
 	purple_ciphers_register_cipher("md4", purple_md4_cipher_get_ops());
7403af
-	purple_ciphers_register_cipher("hmac", purple_hmac_cipher_get_ops());
7403af
 	purple_ciphers_register_cipher("des", purple_des_cipher_get_ops());
7403af
 	purple_ciphers_register_cipher("des3", purple_des3_cipher_get_ops());
7403af
 	purple_ciphers_register_cipher("rc4", purple_rc4_cipher_get_ops());
7403af
diff --git a/libpurple/ciphers/Makefile.am b/libpurple/ciphers/Makefile.am
7403af
index 9e2299d0c2e9..c187a477ebfb 100644
7403af
--- a/libpurple/ciphers/Makefile.am
7403af
+++ b/libpurple/ciphers/Makefile.am
7403af
@@ -3,7 +3,6 @@ noinst_LTLIBRARIES=libpurple-ciphers.la
7403af
 libpurple_ciphers_la_SOURCES=\
7403af
 	des.c \
7403af
 	gchecksum.c \
7403af
-	hmac.c \
7403af
 	md4.c \
7403af
 	md5.c \
7403af
 	rc4.c \
7403af
diff --git a/libpurple/ciphers/hmac.c b/libpurple/ciphers/hmac.c
7403af
deleted file mode 100644
7403af
index b09dbd7e4650..000000000000
7403af
--- a/libpurple/ciphers/hmac.c
7403af
+++ /dev/null
7403af
@@ -1,218 +0,0 @@
7403af
-/*
7403af
- * purple
7403af
- *
7403af
- * Purple is the legal property of its developers, whose names are too numerous
7403af
- * to list here.  Please refer to the COPYRIGHT file distributed with this
7403af
- * source distribution.
7403af
- *
7403af
- * This program is free software; you can redistribute it and/or modify
7403af
- * it under the terms of the GNU General Public License as published by
7403af
- * the Free Software Foundation; either version 2 of the License, or
7403af
- * (at your option) any later version.
7403af
- *
7403af
- * This program is distributed in the hope that it will be useful,
7403af
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
7403af
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7403af
- * GNU General Public License for more details.
7403af
- *
7403af
- * You should have received a copy of the GNU General Public License
7403af
- * along with this program; if not, write to the Free Software
7403af
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
7403af
- */
7403af
-#include <cipher.h>
7403af
-
7403af
-#include <util.h>
7403af
-
7403af
-struct HMAC_Context {
7403af
-	PurpleCipherContext *hash;
7403af
-	char *name;
7403af
-	int blocksize;
7403af
-	guchar *opad;
7403af
-};
7403af
-
7403af
-	static void
7403af
-hmac_init(PurpleCipherContext *context, gpointer extra)
7403af
-{
7403af
-	struct HMAC_Context *hctx;
7403af
-	hctx = g_new0(struct HMAC_Context, 1);
7403af
-	purple_cipher_context_set_data(context, hctx);
7403af
-	purple_cipher_context_reset(context, extra);
7403af
-}
7403af
-
7403af
-	static void
7403af
-hmac_reset(PurpleCipherContext *context, gpointer extra)
7403af
-{
7403af
-	struct HMAC_Context *hctx;
7403af
-
7403af
-	hctx = purple_cipher_context_get_data(context);
7403af
-
7403af
-	g_free(hctx->name);
7403af
-	hctx->name = NULL;
7403af
-	if (hctx->hash)
7403af
-		purple_cipher_context_destroy(hctx->hash);
7403af
-	hctx->hash = NULL;
7403af
-	hctx->blocksize = 0;
7403af
-	g_free(hctx->opad);
7403af
-	hctx->opad = NULL;
7403af
-}
7403af
-
7403af
-	static void
7403af
-hmac_set_opt(PurpleCipherContext *context, const gchar *name, void *value)
7403af
-{
7403af
-	struct HMAC_Context *hctx;
7403af
-
7403af
-	hctx = purple_cipher_context_get_data(context);
7403af
-
7403af
-	if (purple_strequal(name, "hash")) {
7403af
-		g_free(hctx->name);
7403af
-		if (hctx->hash)
7403af
-			purple_cipher_context_destroy(hctx->hash);
7403af
-		hctx->name = g_strdup((char*)value);
7403af
-		hctx->hash = purple_cipher_context_new_by_name((char *)value, NULL);
7403af
-		hctx->blocksize = purple_cipher_context_get_block_size(hctx->hash);
7403af
-	}
7403af
-}
7403af
-
7403af
-	static void *
7403af
-hmac_get_opt(PurpleCipherContext *context, const gchar *name)
7403af
-{
7403af
-	struct HMAC_Context *hctx;
7403af
-
7403af
-	hctx = purple_cipher_context_get_data(context);
7403af
-
7403af
-	if (purple_strequal(name, "hash")) {
7403af
-		return hctx->name;
7403af
-	}
7403af
-
7403af
-	return NULL;
7403af
-}
7403af
-
7403af
-	static void
7403af
-hmac_append(PurpleCipherContext *context, const guchar *data, size_t len)
7403af
-{
7403af
-	struct HMAC_Context *hctx = purple_cipher_context_get_data(context);
7403af
-
7403af
-	g_return_if_fail(hctx->hash != NULL);
7403af
-
7403af
-	purple_cipher_context_append(hctx->hash, data, len);
7403af
-}
7403af
-
7403af
-	static gboolean
7403af
-hmac_digest(PurpleCipherContext *context, size_t in_len, guchar *out, size_t *out_len)
7403af
-{
7403af
-	struct HMAC_Context *hctx = purple_cipher_context_get_data(context);
7403af
-	PurpleCipherContext *hash = hctx->hash;
7403af
-	guchar *inner_hash;
7403af
-	size_t hash_len;
7403af
-	gboolean result;
7403af
-
7403af
-	g_return_val_if_fail(hash != NULL, FALSE);
7403af
-
7403af
-	inner_hash = g_malloc(100); /* TODO: Should be enough for now... */
7403af
-	result = purple_cipher_context_digest(hash, 100, inner_hash, &hash_len);
7403af
-
7403af
-	purple_cipher_context_reset(hash, NULL);
7403af
-
7403af
-	purple_cipher_context_append(hash, hctx->opad, hctx->blocksize);
7403af
-	purple_cipher_context_append(hash, inner_hash, hash_len);
7403af
-
7403af
-	g_free(inner_hash);
7403af
-
7403af
-	result = result && purple_cipher_context_digest(hash, in_len, out, out_len);
7403af
-
7403af
-	return result;
7403af
-}
7403af
-
7403af
-	static void
7403af
-hmac_uninit(PurpleCipherContext *context)
7403af
-{
7403af
-	struct HMAC_Context *hctx;
7403af
-
7403af
-	purple_cipher_context_reset(context, NULL);
7403af
-
7403af
-	hctx = purple_cipher_context_get_data(context);
7403af
-
7403af
-	g_free(hctx);
7403af
-}
7403af
-
7403af
-	static void
7403af
-hmac_set_key_with_len(PurpleCipherContext *context, const guchar * key, size_t key_len)
7403af
-{
7403af
-	struct HMAC_Context *hctx = purple_cipher_context_get_data(context);
7403af
-	int blocksize, i;
7403af
-	guchar *ipad;
7403af
-	guchar *full_key;
7403af
-
7403af
-	g_return_if_fail(hctx->hash != NULL);
7403af
-
7403af
-	g_free(hctx->opad);
7403af
-
7403af
-	blocksize = hctx->blocksize;
7403af
-	ipad = g_malloc(blocksize);
7403af
-	hctx->opad = g_malloc(blocksize);
7403af
-
7403af
-	if (key_len > blocksize) {
7403af
-		purple_cipher_context_reset(hctx->hash, NULL);
7403af
-		purple_cipher_context_append(hctx->hash, key, key_len);
7403af
-		full_key = g_malloc(100); /* TODO: Should be enough for now... */
7403af
-		purple_cipher_context_digest(hctx->hash, 100, full_key, &key_len);
7403af
-	} else
7403af
-		full_key = g_memdup(key, key_len);
7403af
-
7403af
-	if (key_len < blocksize) {
7403af
-		full_key = g_realloc(full_key, blocksize);
7403af
-		memset(full_key + key_len, 0, blocksize - key_len);
7403af
-	}
7403af
-
7403af
-	for(i = 0; i < blocksize; i++) {
7403af
-		ipad[i] = 0x36 ^ full_key[i];
7403af
-		hctx->opad[i] = 0x5c ^ full_key[i];
7403af
-	}
7403af
-
7403af
-	g_free(full_key);
7403af
-
7403af
-	purple_cipher_context_reset(hctx->hash, NULL);
7403af
-	purple_cipher_context_append(hctx->hash, ipad, blocksize);
7403af
-	g_free(ipad);
7403af
-}
7403af
-
7403af
-	static void
7403af
-hmac_set_key(PurpleCipherContext *context, const guchar * key)
7403af
-{
7403af
-	hmac_set_key_with_len(context, key, strlen((char *)key));
7403af
-}
7403af
-
7403af
-	static size_t
7403af
-hmac_get_block_size(PurpleCipherContext *context)
7403af
-{
7403af
-	struct HMAC_Context *hctx = purple_cipher_context_get_data(context);
7403af
-
7403af
-	return hctx->blocksize;
7403af
-}
7403af
-
7403af
-static PurpleCipherOps HMACOps = {
7403af
-	hmac_set_opt,           /* Set option */
7403af
-	hmac_get_opt,           /* Get option */
7403af
-	hmac_init,               /* init */
7403af
-	hmac_reset,              /* reset */
7403af
-	hmac_uninit,             /* uninit */
7403af
-	NULL,                   /* set iv */
7403af
-	hmac_append,             /* append */
7403af
-	hmac_digest,             /* digest */
7403af
-	NULL,                   /* encrypt */
7403af
-	NULL,                   /* decrypt */
7403af
-	NULL,                   /* set salt */
7403af
-	NULL,                   /* get salt size */
7403af
-	hmac_set_key,           /* set key */
7403af
-	NULL,                   /* get key size */
7403af
-	NULL,                   /* set batch mode */
7403af
-	NULL,                   /* get batch mode */
7403af
-	hmac_get_block_size,    /* get block size */
7403af
-	hmac_set_key_with_len   /* set key with len */
7403af
-};
7403af
-
7403af
-PurpleCipherOps *
7403af
-purple_hmac_cipher_get_ops(void) {
7403af
-	return &HMACOps;
7403af
-}
7403af
-
7403af
diff --git a/libpurple/protocols/jabber/auth.c b/libpurple/protocols/jabber/auth.c
7403af
index e5ffb6c33d83..1ca71ea03e81 100644
7403af
--- a/libpurple/protocols/jabber/auth.c
7403af
+++ b/libpurple/protocols/jabber/auth.c
7403af
@@ -24,7 +24,6 @@
7403af
 
7403af
 #include "account.h"
7403af
 #include "debug.h"
7403af
-#include "cipher.h"
7403af
 #include "core.h"
7403af
 #include "conversation.h"
7403af
 #include "request.h"
7403af
@@ -275,17 +274,15 @@ static void auth_old_cb(JabberStream *js, const char *from,
7403af
 			 * to non-SASL authentication.
7403af
 			 */
7403af
 			const char *challenge;
7403af
-			gchar digest[33];
7403af
-			PurpleCipherContext *hmac;
7403af
+			gchar *digest;
7403af
 
7403af
 			/* Calculate the MHAC-MD5 digest */
7403af
 			challenge = xmlnode_get_attrib(x, "challenge");
7403af
-			hmac = purple_cipher_context_new_by_name("hmac", NULL);
7403af
-			purple_cipher_context_set_option(hmac, "hash", "md5");
7403af
-			purple_cipher_context_set_key(hmac, (guchar *)pw);
7403af
-			purple_cipher_context_append(hmac, (guchar *)challenge, strlen(challenge));
7403af
-			purple_cipher_context_digest_to_str(hmac, 33, digest, NULL);
7403af
-			purple_cipher_context_destroy(hmac);
7403af
+			digest = g_compute_hmac_for_string(G_CHECKSUM_MD5,
7403af
+					(guchar *)pw, strlen(pw),
7403af
+					challenge, -1);
7403af
+
7403af
+			g_return_if_fail(digest != NULL);
7403af
 
7403af
 			/* Create the response query */
7403af
 			iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:auth");
7403af
@@ -299,6 +296,7 @@ static void auth_old_cb(JabberStream *js, const char *from,
7403af
 			x = xmlnode_new_child(query, "crammd5");
7403af
 
7403af
 			xmlnode_insert_data(x, digest, 32);
7403af
+			g_free(digest);
7403af
 
7403af
 			jabber_iq_set_callback(iq, auth_old_result_cb, NULL);
7403af
 			jabber_iq_send(iq);
7403af
diff --git a/libpurple/protocols/jabber/auth_scram.c b/libpurple/protocols/jabber/auth_scram.c
7403af
index 7f2a9c827cfb..96c0eb0051e5 100644
7403af
--- a/libpurple/protocols/jabber/auth_scram.c
7403af
+++ b/libpurple/protocols/jabber/auth_scram.c
7403af
@@ -25,11 +25,10 @@
7403af
 #include "auth.h"
7403af
 #include "auth_scram.h"
7403af
 
7403af
-#include "cipher.h"
7403af
 #include "debug.h"
7403af
 
7403af
 static const JabberScramHash hashes[] = {
7403af
-	{ "-SHA-1", "sha1", 20 },
7403af
+	{ "-SHA-1", G_CHECKSUM_SHA1 },
7403af
 };
7403af
 
7403af
 static const JabberScramHash *mech_to_hash(const char *mech)
7403af
@@ -76,7 +75,8 @@ static const struct {
7403af
 guchar *jabber_scram_hi(const JabberScramHash *hash, const GString *str,
7403af
                         GString *salt, guint iterations)
7403af
 {
7403af
-	PurpleCipherContext *context;
7403af
+	GHmac *hmac;
7403af
+	gsize digest_len;
7403af
 	guchar *result;
7403af
 	guint i;
7403af
 	guchar *prev, *tmp;
7403af
@@ -86,39 +86,38 @@ guchar *jabber_scram_hi(const JabberScramHash *hash, const GString *str,
7403af
 	g_return_val_if_fail(salt != NULL && salt->len > 0, NULL);
7403af
 	g_return_val_if_fail(iterations > 0, NULL);
7403af
 
7403af
-	prev   = g_new0(guint8, hash->size);
7403af
-	tmp    = g_new0(guint8, hash->size);
7403af
-	result = g_new0(guint8, hash->size);
7403af
+	digest_len = g_checksum_type_get_length(hash->type);
7403af
+	prev   = g_new0(guint8, digest_len);
7403af
+	tmp    = g_new0(guint8, digest_len);
7403af
+	result = g_new0(guint8, digest_len);
7403af
 
7403af
-	context = purple_cipher_context_new_by_name("hmac", NULL);
7403af
+	hmac = g_hmac_new(hash->type, (guchar *)str->str, str->len);
7403af
 
7403af
 	/* Append INT(1), a four-octet encoding of the integer 1, most significant
7403af
 	 * octet first. */
7403af
 	g_string_append_len(salt, "\0\0\0\1", 4);
7403af
 
7403af
 	/* Compute U0 */
7403af
-	purple_cipher_context_set_option(context, "hash", (gpointer)hash->name);
7403af
-	purple_cipher_context_set_key_with_len(context, (guchar *)str->str, str->len);
7403af
-	purple_cipher_context_append(context, (guchar *)salt->str, salt->len);
7403af
-	purple_cipher_context_digest(context, hash->size, result, NULL);
7403af
+	g_hmac_update(hmac, (guchar *)salt->str, salt->len);
7403af
+	g_hmac_get_digest(hmac, result, &digest_len);
7403af
+	g_hmac_unref(hmac);
7403af
 
7403af
-	memcpy(prev, result, hash->size);
7403af
+	memcpy(prev, result, digest_len);
7403af
 
7403af
 	/* Compute U1...Ui */
7403af
 	for (i = 1; i < iterations; ++i) {
7403af
 		guint j;
7403af
-		purple_cipher_context_set_option(context, "hash", (gpointer)hash->name);
7403af
-		purple_cipher_context_set_key_with_len(context, (guchar *)str->str, str->len);
7403af
-		purple_cipher_context_append(context, prev, hash->size);
7403af
-		purple_cipher_context_digest(context, hash->size, tmp, NULL);
7403af
+		hmac = g_hmac_new(hash->type, (guchar *)str->str, str->len);
7403af
+		g_hmac_update(hmac, prev, digest_len);
7403af
+		g_hmac_get_digest(hmac, tmp, &digest_len);
7403af
+		g_hmac_unref(hmac);
7403af
 
7403af
-		for (j = 0; j < hash->size; ++j)
7403af
+		for (j = 0; j < digest_len; ++j)
7403af
 			result[j] ^= tmp[j];
7403af
 
7403af
-		memcpy(prev, tmp, hash->size);
7403af
+		memcpy(prev, tmp, digest_len);
7403af
 	}
7403af
 
7403af
-	purple_cipher_context_destroy(context);
7403af
 	g_free(tmp);
7403af
 	g_free(prev);
7403af
 	return result;
7403af
@@ -136,31 +135,31 @@ guchar *jabber_scram_hi(const JabberScramHash *hash, const GString *str,
7403af
 static void
7403af
 jabber_scram_hmac(const JabberScramHash *hash, guchar *out, const guchar *key, const gchar *str)
7403af
 {
7403af
-	PurpleCipherContext *context;
7403af
-
7403af
-	context = purple_cipher_context_new_by_name("hmac", NULL);
7403af
-	purple_cipher_context_set_option(context, "hash", (gpointer)hash->name);
7403af
-	purple_cipher_context_set_key_with_len(context, key, hash->size);
7403af
-	purple_cipher_context_append(context, (guchar *)str, strlen(str));
7403af
-	purple_cipher_context_digest(context, hash->size, out, NULL);
7403af
-	purple_cipher_context_destroy(context);
7403af
+	GHmac *hmac;
7403af
+	gsize digest_len = g_checksum_type_get_length(hash->type);
7403af
+
7403af
+	hmac = g_hmac_new(hash->type, key, digest_len);
7403af
+	g_hmac_update(hmac, (guchar *)str, -1);
7403af
+	g_hmac_get_digest(hmac, out, &digest_len);
7403af
+	g_hmac_unref(hmac);
7403af
 }
7403af
 
7403af
 static void
7403af
 jabber_scram_hash(const JabberScramHash *hash, guchar *out, const guchar *data)
7403af
 {
7403af
-	PurpleCipherContext *context;
7403af
+	GChecksum *checksum;
7403af
+	gsize digest_len = g_checksum_type_get_length(hash->type);
7403af
 
7403af
-	context = purple_cipher_context_new_by_name(hash->name, NULL);
7403af
-	purple_cipher_context_append(context, data, hash->size);
7403af
-	purple_cipher_context_digest(context, hash->size, out, NULL);
7403af
-	purple_cipher_context_destroy(context);
7403af
+	checksum = g_checksum_new(hash->type);
7403af
+	g_checksum_update(checksum, data, digest_len);
7403af
+	g_checksum_get_digest(checksum, out, &digest_len);
7403af
+	g_checksum_free(checksum);
7403af
 }
7403af
 
7403af
 gboolean
7403af
 jabber_scram_calc_proofs(JabberScramData *data, GString *salt, guint iterations)
7403af
 {
7403af
-	guint hash_len = data->hash->size;
7403af
+	guint hash_len = g_checksum_type_get_length(data->hash->type);
7403af
 	guint i;
7403af
 
7403af
 	GString *pass = g_string_new(data->password);
7403af
diff --git a/libpurple/protocols/jabber/auth_scram.h b/libpurple/protocols/jabber/auth_scram.h
7403af
index e1f52d1cbe31..855d4ab73b21 100644
7403af
--- a/libpurple/protocols/jabber/auth_scram.h
7403af
+++ b/libpurple/protocols/jabber/auth_scram.h
7403af
@@ -34,8 +34,7 @@
7403af
  */
7403af
 typedef struct {
7403af
 	const char *mech_substr;
7403af
-	const char *name;
7403af
-	guint size;
7403af
+	GChecksumType type;
7403af
 } JabberScramHash;
7403af
 
7403af
 typedef struct {
7403af
diff --git a/libpurple/tests/test_cipher.c b/libpurple/tests/test_cipher.c
7403af
index 45249319e125..a3148a8bd708 100644
7403af
--- a/libpurple/tests/test_cipher.c
7403af
+++ b/libpurple/tests/test_cipher.c
7403af
@@ -474,293 +474,6 @@ START_TEST(test_des3_cbc_null_key_and_text) {
7403af
 }
7403af
 END_TEST
7403af
 
7403af
-/******************************************************************************
7403af
- * HMAC Tests
7403af
- * See RFC2202 and some other NULL tests I made up
7403af
- *****************************************************************************/
7403af
-
7403af
-#define HMAC_TEST(data, data_len, key, key_len, type, digest) { \
7403af
-	PurpleCipher *cipher = NULL; \
7403af
-	PurpleCipherContext *context = NULL; \
7403af
-	gchar cdigest[41]; \
7403af
-	gboolean ret = FALSE; \
7403af
-	\
7403af
-	cipher = purple_ciphers_find_cipher("hmac"); \
7403af
-	context = purple_cipher_context_new(cipher, NULL); \
7403af
-	purple_cipher_context_set_option(context, "hash", type); \
7403af
-	purple_cipher_context_set_key_with_len(context, (guchar *)key, (key_len)); \
7403af
-	\
7403af
-	purple_cipher_context_append(context, (guchar *)(data), (data_len)); \
7403af
-	ret = purple_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \
7403af
-	                                        NULL); \
7403af
-	\
7403af
-	fail_unless(ret == TRUE, NULL); \
7403af
-	fail_unless(purple_strequal((digest), cdigest), NULL); \
7403af
-	\
7403af
-	purple_cipher_context_destroy(context); \
7403af
-}
7403af
-
7403af
-/* HMAC MD5 */
7403af
-
7403af
-START_TEST(test_hmac_md5_Hi) {
7403af
-	HMAC_TEST("Hi There",
7403af
-	          8,
7403af
-	          "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
7403af
-	          16,
7403af
-	          "md5",
7403af
-	          "9294727a3638bb1c13f48ef8158bfc9d");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_md5_what) {
7403af
-	HMAC_TEST("what do ya want for nothing?",
7403af
-	          28,
7403af
-	          "Jefe",
7403af
-	          4,
7403af
-	          "md5",
7403af
-	          "750c783e6ab0b503eaa86e310a5db738");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_md5_dd) {
7403af
-	HMAC_TEST("\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
7403af
-	          "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
7403af
-	          "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
7403af
-	          "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
7403af
-	          "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
7403af
-	          50,
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
7403af
-	          16,
7403af
-	          "md5",
7403af
-	          "56be34521d144c88dbb8c733f0e8b3f6");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_md5_cd) {
7403af
-	HMAC_TEST("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
7403af
-	          "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
7403af
-	          "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
7403af
-	          "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
7403af
-	          "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd",
7403af
-	          50,
7403af
-	          "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
7403af
-	          "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
7403af
-	          "\x15\x16\x17\x18\x19",
7403af
-	          25,
7403af
-	          "md5",
7403af
-	          "697eaf0aca3a3aea3a75164746ffaa79");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_md5_truncation) {
7403af
-	HMAC_TEST("Test With Truncation",
7403af
-	          20,
7403af
-	          "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c",
7403af
-	          16,
7403af
-	          "md5",
7403af
-	          "56461ef2342edc00f9bab995690efd4c");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_md5_large_key) {
7403af
-	HMAC_TEST("Test Using Larger Than Block-Size Key - Hash Key First",
7403af
-	          54,
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
7403af
-	          80,
7403af
-	          "md5",
7403af
-	          "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_md5_large_key_and_data) {
7403af
-	HMAC_TEST("Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
7403af
-	          73,
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
7403af
-	          80,
7403af
-	          "md5",
7403af
-	          "6f630fad67cda0ee1fb1f562db3aa53e");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_md5_null_key) {
7403af
-	HMAC_TEST("Hi There",
7403af
-	          8,
7403af
-	          "\x0a\x0b\x00\x0d\x0e\x0f\x1a\x2f\x0b\x0b"
7403af
-	          "\x0b\x00\x00\x0b\x0b\x49\x5f\x6e\x0b\x0b",
7403af
-	          20,
7403af
-	          "md5",
7403af
-	          "597bfd644b797a985561eeb03a169e59");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_md5_null_text) {
7403af
-	HMAC_TEST("Hi\x00There",
7403af
-	          8,
7403af
-	          "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
7403af
-	          "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
7403af
-	          20,
7403af
-	          "md5",
7403af
-	          "70be8e1b7b50dfcc335d6cd7992c564f");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_md5_null_key_and_text) {
7403af
-	HMAC_TEST("Hi\x00Th\x00re",
7403af
-	          8,
7403af
-	          "\x0c\x0d\x00\x0f\x10\x1a\x3a\x3a\xe6\x34"
7403af
-	          "\x0b\x00\x00\x0b\x0b\x49\x5f\x6e\x0b\x0b",
7403af
-	          20,
7403af
-	          "md5",
7403af
-	          "b31bcbba35a33a067cbba9131cba4889");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-/* HMAC SHA1 */
7403af
-
7403af
-START_TEST(test_hmac_sha1_Hi) {
7403af
-	HMAC_TEST("Hi There",
7403af
-	          8,
7403af
-	          "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
7403af
-	          "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
7403af
-	          20,
7403af
-	          "sha1",
7403af
-	          "b617318655057264e28bc0b6fb378c8ef146be00");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_sha1_what) {
7403af
-	HMAC_TEST("what do ya want for nothing?",
7403af
-	          28,
7403af
-	          "Jefe",
7403af
-	          4,
7403af
-	          "sha1",
7403af
-	          "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_sha1_dd) {
7403af
-	HMAC_TEST("\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
7403af
-	          "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
7403af
-	          "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
7403af
-	          "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
7403af
-	          "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
7403af
-	          50,
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
7403af
-	          20,
7403af
-	          "sha1",
7403af
-	          "125d7342b9ac11cd91a39af48aa17b4f63f175d3");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_sha1_cd) {
7403af
-	HMAC_TEST("\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
7403af
-	          "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
7403af
-	          "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
7403af
-	          "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
7403af
-	          "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd",
7403af
-	          50,
7403af
-	          "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
7403af
-	          "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
7403af
-	          "\x15\x16\x17\x18\x19",
7403af
-	          25,
7403af
-	          "sha1",
7403af
-	          "4c9007f4026250c6bc8414f9bf50c86c2d7235da");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_sha1_truncation) {
7403af
-	HMAC_TEST("Test With Truncation",
7403af
-	          20,
7403af
-	          "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c"
7403af
-	          "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c",
7403af
-	          20,
7403af
-	          "sha1",
7403af
-	          "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_sha1_large_key) {
7403af
-	HMAC_TEST("Test Using Larger Than Block-Size Key - Hash Key First",
7403af
-	          54,
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
7403af
-	          80,
7403af
-	          "sha1",
7403af
-	          "aa4ae5e15272d00e95705637ce8a3b55ed402112");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_sha1_large_key_and_data) {
7403af
-	HMAC_TEST("Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
7403af
-	          73,
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
7403af
-	          "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
7403af
-	          80,
7403af
-	          "sha1",
7403af
-	          "e8e99d0f45237d786d6bbaa7965c7808bbff1a91");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_sha1_null_key) {
7403af
-	HMAC_TEST("Hi There",
7403af
-	          8,
7403af
-	          "\x0a\x0b\x00\x0d\x0e\x0f\x1a\x2f\x0b\x0b"
7403af
-	          "\x0b\x00\x00\x0b\x0b\x49\x5f\x6e\x0b\x0b",
7403af
-	          20,
7403af
-	          "sha1",
7403af
-	          "eb62a2e0e33d300be669c52aab3f591bc960aac5");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_sha1_null_text) {
7403af
-	HMAC_TEST("Hi\x00There",
7403af
-	          8,
7403af
-	          "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
7403af
-	          "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
7403af
-	          20,
7403af
-	          "sha1",
7403af
-	          "31ca58d849e971e418e3439de2c6f83144b6abb7");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
-START_TEST(test_hmac_sha1_null_key_and_text) {
7403af
-	HMAC_TEST("Hi\x00Th\x00re",
7403af
-	          8,
7403af
-	          "\x0c\x0d\x00\x0f\x10\x1a\x3a\x3a\xe6\x34"
7403af
-	          "\x0b\x00\x00\x0b\x0b\x49\x5f\x6e\x0b\x0b",
7403af
-	          20,
7403af
-	          "sha1",
7403af
-	          "e6b8e2fede87aa09dcb13e554df1435e056eae36");
7403af
-}
7403af
-END_TEST
7403af
-
7403af
 /******************************************************************************
7403af
  * Suite
7403af
  *****************************************************************************/
7403af
@@ -832,30 +545,6 @@ cipher_suite(void) {
7403af
 	tcase_add_test(tc, test_des3_cbc_null_key_and_text);
7403af
 	suite_add_tcase(s, tc);
7403af
 
7403af
-	/* hmac tests */
7403af
-	tc = tcase_create("HMAC");
7403af
-	tcase_add_test(tc, test_hmac_md5_Hi);
7403af
-	tcase_add_test(tc, test_hmac_md5_what);
7403af
-	tcase_add_test(tc, test_hmac_md5_dd);
7403af
-	tcase_add_test(tc, test_hmac_md5_cd);
7403af
-	tcase_add_test(tc, test_hmac_md5_truncation);
7403af
-	tcase_add_test(tc, test_hmac_md5_large_key);
7403af
-	tcase_add_test(tc, test_hmac_md5_large_key_and_data);
7403af
-	tcase_add_test(tc, test_hmac_md5_null_key);
7403af
-	tcase_add_test(tc, test_hmac_md5_null_text);
7403af
-	tcase_add_test(tc, test_hmac_md5_null_key_and_text);
7403af
-	tcase_add_test(tc, test_hmac_sha1_Hi);
7403af
-	tcase_add_test(tc, test_hmac_sha1_what);
7403af
-	tcase_add_test(tc, test_hmac_sha1_dd);
7403af
-	tcase_add_test(tc, test_hmac_sha1_cd);
7403af
-	tcase_add_test(tc, test_hmac_sha1_truncation);
7403af
-	tcase_add_test(tc, test_hmac_sha1_large_key);
7403af
-	tcase_add_test(tc, test_hmac_sha1_large_key_and_data);
7403af
-	tcase_add_test(tc, test_hmac_sha1_null_key);
7403af
-	tcase_add_test(tc, test_hmac_sha1_null_text);
7403af
-	tcase_add_test(tc, test_hmac_sha1_null_key_and_text);
7403af
-	suite_add_tcase(s, tc);
7403af
-
7403af
 	return s;
7403af
 }
7403af
 
7403af
diff --git a/libpurple/tests/test_jabber_scram.c b/libpurple/tests/test_jabber_scram.c
7403af
index b81b3db767cd..be50d3ef754b 100644
7403af
--- a/libpurple/tests/test_jabber_scram.c
7403af
+++ b/libpurple/tests/test_jabber_scram.c
7403af
@@ -5,7 +5,7 @@
7403af
 #include "../protocols/jabber/auth_scram.h"
7403af
 #include "../protocols/jabber/jutil.h"
7403af
 
7403af
-static JabberScramHash sha1_mech = { "-SHA-1", "sha1", 20 };
7403af
+static JabberScramHash sha1_mech = { "-SHA-1", G_CHECKSUM_SHA1 };
7403af
 
7403af
 #define assert_pbkdf2_equal(password, salt, count, expected) { \
7403af
 	GString *p = g_string_new(password); \
7403af
-- 
7403af
2.20.1
7403af