cpw.darkrain42.xmpp.scram: f1adcdec: Fix the Hi() function and actually 'mtn ...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Sun Nov 8 01:10:56 EST 2009


-----------------------------------------------------------------
Revision: f1adcdecf1191aa4810fae1c92417e0f177e30ee
Ancestor: 1e59ce868593443b42a2004c4d3d30e32e56658f
Author: darkrain42 at pidgin.im
Date: 2009-11-08T06:06:54
Branch: im.pidgin.cpw.darkrain42.xmpp.scram
URL: http://d.pidgin.im/viewmtn/revision/info/f1adcdecf1191aa4810fae1c92417e0f177e30ee

Added files:
        libpurple/tests/test_jabber_scram.c
Modified files:
        libpurple/protocols/jabber/auth_scram.c

ChangeLog: 

Fix the Hi() function and actually 'mtn add' the test file.

-------------- next part --------------
============================================================
--- libpurple/tests/test_jabber_scram.c	9a0ca3018e20eaa895a8908ad5bf17f55f930d30
+++ libpurple/tests/test_jabber_scram.c	9a0ca3018e20eaa895a8908ad5bf17f55f930d30
@@ -0,0 +1,44 @@
+#include <string.h>
+
+#include "tests.h"
+#include "../util.h"
+#include "../protocols/jabber/auth_scram.h"
+
+#define assert_pbkdf2_equal(password, salt, count, expected) { \
+	GString *p = g_string_new(password); \
+	GString *s = g_string_new(salt); \
+	GString *result = jabber_auth_scram_hi("sha1", p, s, count); \
+	fail_if(result == NULL, "Hi() returned NULL"); \
+	fail_if(result->len != 20, "Hi() returned with unexpected length %u", result->len); \
+	fail_if(0 != memcmp(result->str, expected, 20), "Hi() returned invalid result"); \
+	g_string_free(result, TRUE); \
+	g_string_free(s, TRUE); \
+	g_string_free(p, TRUE); \
+}
+
+START_TEST(test_pbkdf2)
+{
+	assert_pbkdf2_equal("password", "salt", 1, "\x0c\x60\xc8\x0f\x96\x1f\x0e\x71\xf3\xa9\xb5\x24\xaf\x60\x12\x06\x2f\xe0\x37\xa6");
+	
+	assert_pbkdf2_equal("password", "salt", 2, "\xea\x6c\x01\x4d\xc7\x2d\x6f\x8c\xcd\x1e\xd9\x2a\xce\x1d\x41\xf0\xd8\xde\x89\x57");
+
+	assert_pbkdf2_equal("password", "salt", 4096, "\x4b\x00\x79\x01\xb7\x65\x48\x9a\xbe\xad\x49\xd9\x26\xf7\x21\xd0\x65\xa4\x29\xc1");
+
+#if 0
+	/* This causes libcheck to time out :-D */
+	assert_pbkdf2_equal("password", "salt", 16777216, "\xee\xfe\x3d\x61\xcd\x4d\xa4\xe4\xe9\x94\x5b\x3d\x6b\xa2\x15\x8c\x26\x34\xe9\x84");
+#endif
+}
+END_TEST
+
+Suite *
+jabber_scram_suite(void)
+{
+	Suite *s = suite_create("Jabber SASL SCRAM functions");
+
+	TCase *tc = tcase_create("PBKDF2 Functionality");
+	tcase_add_test(tc, test_pbkdf2);
+	suite_add_tcase(s, tc);
+
+	return s;
+}
============================================================
--- libpurple/protocols/jabber/auth_scram.c	29304ab202acc7b7acfbe034e27f6828b95badee
+++ libpurple/protocols/jabber/auth_scram.c	a88eda59afe86838f4fb4dec48e147f0676e3f1f
@@ -28,13 +28,13 @@
 #include "cipher.h"
 #include "debug.h"
 
-
 GString *jabber_auth_scram_hi(const gchar *hash, const GString *str,
                               GString *salt, guint iterations)
 {
 	PurpleCipherContext *context;
 	GString *result;
 	guint i;
+	guchar prev[20], tmp[20]; /* FIXME: Hardcoded 20 */
 
 	g_return_val_if_fail(hash != NULL, NULL);
 	g_return_val_if_fail(str != NULL && str->len > 0, NULL);
@@ -55,17 +55,20 @@ GString *jabber_auth_scram_hi(const gcha
 	purple_cipher_context_append(context, (guchar *)salt->str, salt->len);
 	purple_cipher_context_digest(context, result->allocated_len, (guchar *)result->str, &(result->len));
 
+	memcpy(prev, result->str, result->len);
+
 	/* Compute U1...Ui */
 	for (i = 1; i < iterations; ++i) {
-		guchar tmp[20]; /* FIXME: hardcoded 20 */
 		guint j;
 		purple_cipher_context_set_option(context, "hash", (gpointer)hash);
 		purple_cipher_context_set_key_with_len(context, (guchar *)str->str, str->len);
-		purple_cipher_context_append(context, (guchar *)result->str, result->len);
+		purple_cipher_context_append(context, prev, result->len);
 		purple_cipher_context_digest(context, sizeof(tmp), tmp, NULL);
 
 		for (j = 0; j < 20; ++j)
 			result->str[j] ^= tmp[j];
+
+		memcpy(prev, tmp, result->len);
 	}
 
 	purple_cipher_context_destroy(context);


More information about the Commits mailing list