comparison libpurple/protocols/jabber/auth_scram.c @ 28703:338eeaf371e2

jabber: Add the Hi() function (PBKDF2). The single test is taken from draft-josefsson-pbkdf2-test-vectors.
author Paul Aurich <paul@darkrain42.org>
date Sun, 08 Nov 2009 03:36:14 +0000
parents
children 398ff52e7d62
comparison
equal deleted inserted replaced
28702:f3c65de7d864 28703:338eeaf371e2
1 /*
2 * purple - Jabber Protocol Plugin
3 *
4 * Purple is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
21 *
22 */
23 #include "internal.h"
24
25 #include "auth.h"
26 #include "auth_scram.h"
27
28 #include "cipher.h"
29 #include "debug.h"
30
31
32 GString *jabber_auth_scram_hi(const gchar *hash, const GString *str,
33 GString *salt, guint iterations)
34 {
35 PurpleCipherContext *context;
36 GString *result;
37 guint i;
38
39 g_return_val_if_fail(hash != NULL, NULL);
40 g_return_val_if_fail(str != NULL && str->len > 0, NULL);
41 g_return_val_if_fail(salt != NULL && salt->len > 0, NULL);
42 g_return_val_if_fail(iterations > 0, NULL);
43
44 context = purple_cipher_context_new_by_name("hmac", NULL);
45
46 /* Append INT(1), a four-octet encoding of the integer 1, most significant
47 * octet first. */
48 g_string_append_len(salt, "\0\0\0\1", 4);
49
50 result = g_string_sized_new(20); /* FIXME: Hardcoded 20 */
51
52 /* Compute U0 */
53 purple_cipher_context_set_option(context, "hash", (gpointer)hash);
54 purple_cipher_context_set_key_with_len(context, (guchar *)str->str, str->len);
55 purple_cipher_context_append(context, (guchar *)salt->str, salt->len);
56 purple_cipher_context_digest(context, result->allocated_len, (guchar *)result->str, &(result->len));
57
58 /* Compute U1...Ui */
59 for (i = 1; i < iterations; ++i) {
60 guchar tmp[20]; /* FIXME: hardcoded 20 */
61 guint j;
62 purple_cipher_context_set_option(context, "hash", (gpointer)hash);
63 purple_cipher_context_set_key_with_len(context, (guchar *)str->str, str->len);
64 purple_cipher_context_append(context, (guchar *)result->str, result->len);
65 purple_cipher_context_digest(context, sizeof(tmp), tmp, NULL);
66
67 for (j = 0; j < 20; ++j)
68 result->str[j] ^= tmp[j];
69 }
70
71 purple_cipher_context_destroy(context);
72 return result;
73 }