annotate libpurple/cipher.c @ 29531:33715feb7b8d

Add media_caps to PurpleBuddy structure and use it to determine the old caps in purple_prpl_got_media_caps.
author maiku@pidgin.im
date Tue, 20 Oct 2009 21:00:23 +0000
parents da33da2e1a1e
children 279c6cfe6966
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /*
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2 * purple
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
4 * Purple is the legal property of its developers, whose names are too numerous
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
6 * source distribution.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 * Original md5
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 * Copyright (C) 2001-2003 Christophe Devine <c.devine@cr0.net>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 * Original md4 taken from linux kernel
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 * MD4 Message Digest Algorithm (RFC1320).
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 * Implementation derived from Andrew Tridgell and Steve French's
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 * CIFS MD4 implementation, and the cryptoapi implementation
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 * originally based on the public domain implementation written
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 * by Colin Plumb in 1993.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 * Copyright (c) Andrew Tridgell 1997-1998.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 * Modified by Steve French (sfrench@us.ibm.com) 2002
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 * Copyright (c) Cryptoapi developers.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 * Copyright (c) 2002 David S. Miller (davem@redhat.com)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 * Original des taken from gpg
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 * des.c - DES and Triple-DES encryption/decryption Algorithm
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 * Copyright (C) 1998 Free Software Foundation, Inc.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 * Please see below for more legal information!
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 * According to the definition of DES in FIPS PUB 46-2 from December 1993.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 * For a description of triple encryption, see:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 * Bruce Schneier: Applied Cryptography. Second Edition.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 * John Wiley & Sons, 1996. ISBN 0-471-12845-7. Pages 358 ff.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 * This file is part of GnuPG.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 * This program is free software; you can redistribute it and/or modify
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 * it under the terms of the GNU General Public License as published by
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 * the Free Software Foundation; either version 2 of the License, or
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 * (at your option) any later version.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 * This program is distributed in the hope that it will be useful,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 * GNU General Public License for more details.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 * You should have received a copy of the GNU General Public License
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 * along with this program; if not, write to the Free Software
19680
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19653
diff changeset
51 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 #include <glib.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 #include <string.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 #include <stdio.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 #include "internal.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 #include "cipher.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 #include "dbus-maybe.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 #include "debug.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61 #include "signals.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 #include "value.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63
27390
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
64 #if GLIB_CHECK_VERSION(2,16,0)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
65 static void
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
66 purple_g_checksum_init(PurpleCipherContext *context, GChecksumType type)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
67 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
68 GChecksum *checksum;
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
69
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
70 checksum = g_checksum_new(type);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
71 purple_cipher_context_set_data(context, checksum);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
72 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
73
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
74 static void
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
75 purple_g_checksum_reset(PurpleCipherContext *context, GChecksumType type)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
76 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
77 GChecksum *checksum;
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
78
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
79 checksum = purple_cipher_context_get_data(context);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
80 g_return_if_fail(checksum != NULL);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
81
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
82 #if GLIB_CHECK_VERSION(2,18,0)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
83 g_checksum_reset(checksum);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
84 #else
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
85 g_checksum_free(checksum);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
86 checksum = g_checksum_new(type);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
87 purple_cipher_context_set_data(context, checksum);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
88 #endif
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
89 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
90
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
91 static void
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
92 purple_g_checksum_uninit(PurpleCipherContext *context)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
93 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
94 GChecksum *checksum;
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
95
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
96 checksum = purple_cipher_context_get_data(context);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
97 g_return_if_fail(checksum != NULL);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
98
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
99 g_checksum_free(checksum);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
100 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
101
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
102 static void
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
103 purple_g_checksum_append(PurpleCipherContext *context, const guchar *data,
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
104 gsize len)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
105 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
106 GChecksum *checksum;
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
107
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
108 checksum = purple_cipher_context_get_data(context);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
109 g_return_if_fail(checksum != NULL);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
110
27392
304fef974f28 Elliott's code looks nicer.
Paul Aurich <paul@darkrain42.org>
parents: 27390
diff changeset
111 while (len >= G_MAXSSIZE) {
304fef974f28 Elliott's code looks nicer.
Paul Aurich <paul@darkrain42.org>
parents: 27390
diff changeset
112 g_checksum_update(checksum, data, G_MAXSSIZE);
304fef974f28 Elliott's code looks nicer.
Paul Aurich <paul@darkrain42.org>
parents: 27390
diff changeset
113 len -= G_MAXSSIZE;
304fef974f28 Elliott's code looks nicer.
Paul Aurich <paul@darkrain42.org>
parents: 27390
diff changeset
114 data += G_MAXSSIZE;
304fef974f28 Elliott's code looks nicer.
Paul Aurich <paul@darkrain42.org>
parents: 27390
diff changeset
115 }
304fef974f28 Elliott's code looks nicer.
Paul Aurich <paul@darkrain42.org>
parents: 27390
diff changeset
116
304fef974f28 Elliott's code looks nicer.
Paul Aurich <paul@darkrain42.org>
parents: 27390
diff changeset
117 if (len)
27390
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
118 g_checksum_update(checksum, data, len);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
119 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
120
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
121 static gboolean
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
122 purple_g_checksum_digest(PurpleCipherContext *context, GChecksumType type,
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
123 gsize len, guchar *digest, gsize *out_len)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
124 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
125 GChecksum *checksum;
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
126 const gssize required_length = g_checksum_type_get_length(type);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
127
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
128 checksum = purple_cipher_context_get_data(context);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
129
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
130 g_return_val_if_fail(len >= required_length, FALSE);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
131 g_return_val_if_fail(checksum != NULL, FALSE);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
132
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
133 g_checksum_get_digest(checksum, digest, &len);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
134
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
135 purple_cipher_context_reset(context, NULL);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
136
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
137 if (out_len)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
138 *out_len = len;
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
139
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
140 return TRUE;
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
141 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
142 #endif
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
143
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
144
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145 /*******************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 * MD5
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147 ******************************************************************************/
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
148 #define MD5_HMAC_BLOCK_SIZE 64
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
149
27390
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
150 static size_t
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
151 md5_get_block_size(PurpleCipherContext *context)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
152 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
153 /* This does not change (in this case) */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
154 return MD5_HMAC_BLOCK_SIZE;
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
155 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
156
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
157 #if GLIB_CHECK_VERSION(2,16,0)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
158
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
159 static void
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
160 md5_init(PurpleCipherContext *context, void *extra)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
161 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
162 purple_g_checksum_init(context, G_CHECKSUM_MD5);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
163 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
164
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
165 static void
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
166 md5_reset(PurpleCipherContext *context, void *extra)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
167 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
168 purple_g_checksum_reset(context, G_CHECKSUM_MD5);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
169 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
170
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
171 static gboolean
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
172 md5_digest(PurpleCipherContext *context, gsize in_len, guchar digest[16],
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
173 size_t *out_len)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
174 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
175 return purple_g_checksum_digest(context, G_CHECKSUM_MD5, in_len,
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
176 digest, out_len);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
177 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
178
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
179 static PurpleCipherOps MD5Ops = {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
180 NULL, /* Set Option */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
181 NULL, /* Get Option */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
182 md5_init, /* init */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
183 md5_reset, /* reset */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
184 purple_g_checksum_uninit, /* uninit */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
185 NULL, /* set iv */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
186 purple_g_checksum_append, /* append */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
187 md5_digest, /* digest */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
188 NULL, /* encrypt */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
189 NULL, /* decrypt */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
190 NULL, /* set salt */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
191 NULL, /* get salt size */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
192 NULL, /* set key */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
193 NULL, /* get key size */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
194 NULL, /* set batch mode */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
195 NULL, /* get batch mode */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
196 md5_get_block_size, /* get block size */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
197 NULL /* set key with len */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
198 };
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
199
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
200 #else /* GLIB_CHECK_VERSION(2,16,0) */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
201
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
202 struct MD5Context {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
203 guint32 total[2];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204 guint32 state[4];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205 guchar buffer[64];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
207
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
208 #define MD5_GET_GUINT32(n,b,i) { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
209 (n) = ((guint32)(b) [(i) ] ) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
210 | ((guint32)(b) [(i) + 1] << 8) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
211 | ((guint32)(b) [(i) + 2] << 16) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
212 | ((guint32)(b) [(i) + 3] << 24); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
214 #define MD5_PUT_GUINT32(n,b,i) { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
215 (b)[(i) ] = (guchar)((n) ); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
216 (b)[(i) + 1] = (guchar)((n) >> 8); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
217 (b)[(i) + 2] = (guchar)((n) >> 16); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218 (b)[(i) + 3] = (guchar)((n) >> 24); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
219 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
220
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
221 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
222 md5_init(PurpleCipherContext *context, gpointer extra) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
223 struct MD5Context *md5_context;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
224
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
225 md5_context = g_new0(struct MD5Context, 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
226
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
227 purple_cipher_context_set_data(context, md5_context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
228
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
229 purple_cipher_context_reset(context, extra);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
230 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
231
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
232 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
233 md5_reset(PurpleCipherContext *context, gpointer extra) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
234 struct MD5Context *md5_context;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
235
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
236 md5_context = purple_cipher_context_get_data(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
237
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
238 md5_context->total[0] = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
239 md5_context->total[1] = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
240
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
241 md5_context->state[0] = 0x67452301;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
242 md5_context->state[1] = 0xEFCDAB89;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
243 md5_context->state[2] = 0x98BADCFE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
244 md5_context->state[3] = 0x10325476;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
245
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
246 memset(md5_context->buffer, 0, sizeof(md5_context->buffer));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
247 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
248
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
249 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
250 md5_uninit(PurpleCipherContext *context) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
251 struct MD5Context *md5_context;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
252
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
253 purple_cipher_context_reset(context, NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
254
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
255 md5_context = purple_cipher_context_get_data(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
256 memset(md5_context, 0, sizeof(md5_context));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
257
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
258 g_free(md5_context);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
259 md5_context = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
260 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
261
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
262 static void
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
263 md5_process(struct MD5Context *md5_context, const guchar data[64]) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
264 guint32 X[16], A, B, C, D;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
265
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
266 A = md5_context->state[0];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
267 B = md5_context->state[1];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
268 C = md5_context->state[2];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
269 D = md5_context->state[3];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
270
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
271 MD5_GET_GUINT32(X[ 0], data, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
272 MD5_GET_GUINT32(X[ 1], data, 4);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
273 MD5_GET_GUINT32(X[ 2], data, 8);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
274 MD5_GET_GUINT32(X[ 3], data, 12);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
275 MD5_GET_GUINT32(X[ 4], data, 16);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
276 MD5_GET_GUINT32(X[ 5], data, 20);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
277 MD5_GET_GUINT32(X[ 6], data, 24);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
278 MD5_GET_GUINT32(X[ 7], data, 28);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
279 MD5_GET_GUINT32(X[ 8], data, 32);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
280 MD5_GET_GUINT32(X[ 9], data, 36);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
281 MD5_GET_GUINT32(X[10], data, 40);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
282 MD5_GET_GUINT32(X[11], data, 44);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
283 MD5_GET_GUINT32(X[12], data, 48);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
284 MD5_GET_GUINT32(X[13], data, 52);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
285 MD5_GET_GUINT32(X[14], data, 56);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
286 MD5_GET_GUINT32(X[15], data, 60);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
287
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
288 #define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
289 #define P(a,b,c,d,k,s,t) { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
290 a += F(b,c,d) + X[k] + t; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
291 a = S(a,s) + b; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
292 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
293
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
294 /* first pass */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
295 #define F(x,y,z) (z ^ (x & (y ^ z)))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
296 P(A, B, C, D, 0, 7, 0xD76AA478);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
297 P(D, A, B, C, 1, 12, 0xE8C7B756);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
298 P(C, D, A, B, 2, 17, 0x242070DB);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
299 P(B, C, D, A, 3, 22, 0xC1BDCEEE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
300 P(A, B, C, D, 4, 7, 0xF57C0FAF);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
301 P(D, A, B, C, 5, 12, 0x4787C62A);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
302 P(C, D, A, B, 6, 17, 0xA8304613);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
303 P(B, C, D, A, 7, 22, 0xFD469501);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
304 P(A, B, C, D, 8, 7, 0x698098D8);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
305 P(D, A, B, C, 9, 12, 0x8B44F7AF);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
306 P(C, D, A, B, 10, 17, 0xFFFF5BB1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
307 P(B, C, D, A, 11, 22, 0x895CD7BE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
308 P(A, B, C, D, 12, 7, 0x6B901122);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
309 P(D, A, B, C, 13, 12, 0xFD987193);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
310 P(C, D, A, B, 14, 17, 0xA679438E);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
311 P(B, C, D, A, 15, 22, 0x49B40821);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
312 #undef F
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
313
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
314 /* second pass */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
315 #define F(x,y,z) (y ^ (z & (x ^ y)))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
316 P(A, B, C, D, 1, 5, 0xF61E2562);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
317 P(D, A, B, C, 6, 9, 0xC040B340);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
318 P(C, D, A, B, 11, 14, 0x265E5A51);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
319 P(B, C, D, A, 0, 20, 0xE9B6C7AA);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
320 P(A, B, C, D, 5, 5, 0xD62F105D);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
321 P(D, A, B, C, 10, 9, 0x02441453);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
322 P(C, D, A, B, 15, 14, 0xD8A1E681);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
323 P(B, C, D, A, 4, 20, 0xE7D3FBC8);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
324 P(A, B, C, D, 9, 5, 0x21E1CDE6);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
325 P(D, A, B, C, 14, 9, 0xC33707D6);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
326 P(C, D, A, B, 3, 14, 0xF4D50D87);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
327 P(B, C, D, A, 8, 20, 0x455A14ED);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
328 P(A, B, C, D, 13, 5, 0xA9E3E905);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
329 P(D, A, B, C, 2, 9, 0xFCEFA3F8);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
330 P(C, D, A, B, 7, 14, 0x676F02D9);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
331 P(B, C, D, A, 12, 20, 0x8D2A4C8A);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
332 #undef F
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
333
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
334 /* third pass */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
335 #define F(x,y,z) (x ^ y ^ z)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
336 P(A, B, C, D, 5, 4, 0xFFFA3942);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
337 P(D, A, B, C, 8, 11, 0x8771F681);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
338 P(C, D, A, B, 11, 16, 0x6D9D6122);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
339 P(B, C, D, A, 14, 23, 0xFDE5380C);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
340 P(A, B, C, D, 1, 4, 0xA4BEEA44);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
341 P(D, A, B, C, 4, 11, 0x4BDECFA9);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
342 P(C, D, A, B, 7, 16, 0xF6BB4B60);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
343 P(B, C, D, A, 10, 23, 0xBEBFBC70);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
344 P(A, B, C, D, 13, 4, 0x289B7EC6);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
345 P(D, A, B, C, 0, 11, 0xEAA127FA);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
346 P(C, D, A, B, 3, 16, 0xD4EF3085);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
347 P(B, C, D, A, 6, 23, 0x04881D05);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
348 P(A, B, C, D, 9, 4, 0xD9D4D039);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
349 P(D, A, B, C, 12, 11, 0xE6DB99E5);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
350 P(C, D, A, B, 15, 16, 0x1FA27CF8);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
351 P(B, C, D, A, 2, 23, 0xC4AC5665);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
352 #undef F
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
353
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
354 /* forth pass */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
355 #define F(x,y,z) (y ^ (x | ~z))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
356 P(A, B, C, D, 0, 6, 0xF4292244);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
357 P(D, A, B, C, 7, 10, 0x432AFF97);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
358 P(C, D, A, B, 14, 15, 0xAB9423A7);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
359 P(B, C, D, A, 5, 21, 0xFC93A039);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
360 P(A, B, C, D, 12, 6, 0x655B59C3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
361 P(D, A, B, C, 3, 10, 0x8F0CCC92);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
362 P(C, D, A, B, 10, 15, 0xFFEFF47D);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
363 P(B, C, D, A, 1, 21, 0x85845DD1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
364 P(A, B, C, D, 8, 6, 0x6FA87E4F);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
365 P(D, A, B, C, 15, 10, 0xFE2CE6E0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
366 P(C, D, A, B, 6, 15, 0xA3014314);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
367 P(B, C, D, A, 13, 21, 0x4E0811A1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
368 P(A, B, C, D, 4, 6, 0xF7537E82);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
369 P(D, A, B, C, 11, 10, 0xBD3AF235);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
370 P(C, D, A, B, 2, 15, 0x2AD7D2BB);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
371 P(B, C, D, A, 9, 21, 0xEB86D391);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
372 #undef F
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
373 #undef P
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
374 #undef S
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
375
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
376 md5_context->state[0] += A;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
377 md5_context->state[1] += B;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
378 md5_context->state[2] += C;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
379 md5_context->state[3] += D;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
380 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
381
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
382 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
383 md5_append(PurpleCipherContext *context, const guchar *data, size_t len) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
384 struct MD5Context *md5_context = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
385 guint32 left = 0, fill = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
386
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
387 g_return_if_fail(context != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
388
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
389 md5_context = purple_cipher_context_get_data(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
390 g_return_if_fail(md5_context != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
391
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
392 left = md5_context->total[0] & 0x3F;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
393 fill = 64 - left;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
394
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
395 md5_context->total[0] += len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
396 md5_context->total[0] &= 0xFFFFFFFF;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
397
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
398 if(md5_context->total[0] < len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
399 md5_context->total[1]++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
400
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
401 if(left && len >= fill) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
402 memcpy((md5_context->buffer + left), data, fill);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
403 md5_process(md5_context, md5_context->buffer);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
404 len -= fill;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
405 data += fill;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
406 left = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
407 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
408
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
409 while(len >= 64) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
410 md5_process(md5_context, data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
411 len -= 64;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
412 data += 64;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
413 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
414
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
415 if(len) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
416 memcpy((md5_context->buffer + left), data, len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
417 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
418 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
419
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
420 static gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
421 md5_digest(PurpleCipherContext *context, size_t in_len, guchar digest[16],
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
422 size_t *out_len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
423 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
424 struct MD5Context *md5_context = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
425 guint32 last, pad;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
426 guint32 high, low;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
427 guchar message[8];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
428 guchar padding[64] = {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
429 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
430 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
431 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
432 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
433 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
434
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
435 g_return_val_if_fail(in_len >= 16, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
436
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
437 md5_context = purple_cipher_context_get_data(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
438
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
439 high = (md5_context->total[0] >> 29)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
440 | (md5_context->total[1] << 3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
441 low = (md5_context->total[0] << 3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
442
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
443 MD5_PUT_GUINT32(low, message, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
444 MD5_PUT_GUINT32(high, message, 4);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
445
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
446 last = md5_context->total[0] & 0x3F;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
447 pad = (last < 56) ? (56 - last) : (120 - last);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
448
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
449 md5_append(context, padding, pad);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
450 md5_append(context, message, 8);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
451
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
452 MD5_PUT_GUINT32(md5_context->state[0], digest, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
453 MD5_PUT_GUINT32(md5_context->state[1], digest, 4);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
454 MD5_PUT_GUINT32(md5_context->state[2], digest, 8);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
455 MD5_PUT_GUINT32(md5_context->state[3], digest, 12);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
456
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
457 if(out_len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
458 *out_len = 16;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
459
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
460 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
461 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
462
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
463 static PurpleCipherOps MD5Ops = {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
464 NULL, /* Set option */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
465 NULL, /* Get option */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
466 md5_init, /* init */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
467 md5_reset, /* reset */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
468 md5_uninit, /* uninit */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
469 NULL, /* set iv */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
470 md5_append, /* append */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
471 md5_digest, /* digest */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
472 NULL, /* encrypt */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
473 NULL, /* decrypt */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
474 NULL, /* set salt */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
475 NULL, /* get salt size */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
476 NULL, /* set key */
16676
07cf49a0f404 I _think_ this is it for libpurple's padding...
Gary Kramlich <grim@reaperworld.com>
parents: 15823
diff changeset
477 NULL, /* get key size */
21907
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
478 NULL, /* set batch mode */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
479 NULL, /* get batch mode */
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
480 md5_get_block_size, /* get block size */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
481 NULL /* set key with len */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
482 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
483
27390
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
484 #endif /* GLIB_CHECK_VERSION(2,16,0) */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
485
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
486 /*******************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
487 * MD4
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
488 ******************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
489 #define MD4_DIGEST_SIZE 16
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
490 #define MD4_HMAC_BLOCK_SIZE 64
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
491 #define MD4_BLOCK_WORDS 16
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
492 #define MD4_HASH_WORDS 4
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
493
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
494
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
495
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
496 struct MD4_Context {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
497 guint32 hash[MD4_HASH_WORDS];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
498 guint32 block[MD4_BLOCK_WORDS];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
499 guint64 byte_count;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
500 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
501
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
502 static inline guint32 lshift(guint32 x, unsigned int s)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
503 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
504 x &= 0xFFFFFFFF;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
505 return ((x << s) & 0xFFFFFFFF) | (x >> (32 - s));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
506 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
507
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
508 static inline guint32 F(guint32 x, guint32 y, guint32 z)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
509 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
510 return (x & y) | ((~x) & z);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
511 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
512
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
513 static inline guint32 G(guint32 x, guint32 y, guint32 z)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
514 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
515 return (x & y) | (x & z) | (y & z);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
516 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
517
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
518 static inline guint32 H(guint32 x, guint32 y, guint32 z)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
519 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
520 return x ^ y ^ z;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
521 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
522
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
523 #define ROUND1(a,b,c,d,k,s) (a = lshift(a + F(b,c,d) + k, s))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
524 #define ROUND2(a,b,c,d,k,s) (a = lshift(a + G(b,c,d) + k + (guint32)0x5A827999,s))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
525 #define ROUND3(a,b,c,d,k,s) (a = lshift(a + H(b,c,d) + k + (guint32)0x6ED9EBA1,s))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
526
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
527 static inline void le32_to_cpu_array(guint32 *buf, unsigned int words)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
528 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
529 while (words--) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
530 *buf=GUINT_FROM_LE(*buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
531 buf++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
532 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
533 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
534
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
535 static inline void cpu_to_le32_array(guint32 *buf, unsigned int words)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
536 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
537 while (words--) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
538 *buf=GUINT_TO_LE(*buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
539 buf++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
540 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
541 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
542
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
543 static void md4_transform(guint32 *hash, guint32 const *in)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
544 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
545 guint32 a, b, c, d;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
546
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
547 a = hash[0];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
548 b = hash[1];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
549 c = hash[2];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
550 d = hash[3];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
551
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
552 ROUND1(a, b, c, d, in[0], 3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
553 ROUND1(d, a, b, c, in[1], 7);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
554 ROUND1(c, d, a, b, in[2], 11);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
555 ROUND1(b, c, d, a, in[3], 19);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
556 ROUND1(a, b, c, d, in[4], 3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
557 ROUND1(d, a, b, c, in[5], 7);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
558 ROUND1(c, d, a, b, in[6], 11);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
559 ROUND1(b, c, d, a, in[7], 19);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
560 ROUND1(a, b, c, d, in[8], 3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
561 ROUND1(d, a, b, c, in[9], 7);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
562 ROUND1(c, d, a, b, in[10], 11);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
563 ROUND1(b, c, d, a, in[11], 19);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
564 ROUND1(a, b, c, d, in[12], 3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
565 ROUND1(d, a, b, c, in[13], 7);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
566 ROUND1(c, d, a, b, in[14], 11);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
567 ROUND1(b, c, d, a, in[15], 19);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
568
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
569 ROUND2(a, b, c, d,in[ 0], 3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
570 ROUND2(d, a, b, c, in[4], 5);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
571 ROUND2(c, d, a, b, in[8], 9);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
572 ROUND2(b, c, d, a, in[12], 13);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
573 ROUND2(a, b, c, d, in[1], 3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
574 ROUND2(d, a, b, c, in[5], 5);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
575 ROUND2(c, d, a, b, in[9], 9);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
576 ROUND2(b, c, d, a, in[13], 13);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
577 ROUND2(a, b, c, d, in[2], 3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
578 ROUND2(d, a, b, c, in[6], 5);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
579 ROUND2(c, d, a, b, in[10], 9);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
580 ROUND2(b, c, d, a, in[14], 13);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
581 ROUND2(a, b, c, d, in[3], 3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
582 ROUND2(d, a, b, c, in[7], 5);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
583 ROUND2(c, d, a, b, in[11], 9);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
584 ROUND2(b, c, d, a, in[15], 13);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
585
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
586 ROUND3(a, b, c, d,in[ 0], 3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
587 ROUND3(d, a, b, c, in[8], 9);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
588 ROUND3(c, d, a, b, in[4], 11);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
589 ROUND3(b, c, d, a, in[12], 15);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
590 ROUND3(a, b, c, d, in[2], 3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
591 ROUND3(d, a, b, c, in[10], 9);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
592 ROUND3(c, d, a, b, in[6], 11);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
593 ROUND3(b, c, d, a, in[14], 15);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
594 ROUND3(a, b, c, d, in[1], 3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
595 ROUND3(d, a, b, c, in[9], 9);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
596 ROUND3(c, d, a, b, in[5], 11);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
597 ROUND3(b, c, d, a, in[13], 15);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
598 ROUND3(a, b, c, d, in[3], 3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
599 ROUND3(d, a, b, c, in[11], 9);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
600 ROUND3(c, d, a, b, in[7], 11);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
601 ROUND3(b, c, d, a, in[15], 15);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
602
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
603 hash[0] += a;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
604 hash[1] += b;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
605 hash[2] += c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
606 hash[3] += d;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
607 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
608
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
609 static inline void md4_transform_helper(struct MD4_Context *ctx)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
610 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
611 le32_to_cpu_array(ctx->block, sizeof(ctx->block) / sizeof(guint32));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
612 md4_transform(ctx->hash, ctx->block);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
613 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
614
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
615 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
616 md4_init(PurpleCipherContext *context, gpointer extra) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
617 struct MD4_Context *mctx;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
618 mctx = g_new0(struct MD4_Context, 1);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
619 purple_cipher_context_set_data(context, mctx);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
620 purple_cipher_context_reset(context, extra);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
621
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
622 mctx->hash[0] = 0x67452301;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
623 mctx->hash[1] = 0xefcdab89;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
624 mctx->hash[2] = 0x98badcfe;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
625 mctx->hash[3] = 0x10325476;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
626 mctx->byte_count = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
627 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
628
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
629 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
630 md4_reset(PurpleCipherContext *context, gpointer extra) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
631 struct MD4_Context *mctx;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
632
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
633 mctx = purple_cipher_context_get_data(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
634
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
635 mctx->hash[0] = 0x67452301;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
636 mctx->hash[1] = 0xefcdab89;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
637 mctx->hash[2] = 0x98badcfe;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
638 mctx->hash[3] = 0x10325476;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
639 mctx->byte_count = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
640 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
641
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
642 static void
25415
584063555949 Remove trailing whitespace
Mark Doliner <mark@kingant.net>
parents: 25385
diff changeset
643 md4_append(PurpleCipherContext *context, const guchar *data, size_t len)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
644 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
645 struct MD4_Context *mctx = purple_cipher_context_get_data(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
646 const guint32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
647
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
648 mctx->byte_count += len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
649
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
650 if (avail > len) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
651 memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
652 data, len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
653 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
654 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
655
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
656 memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
657 data, avail);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
658
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
659 md4_transform_helper(mctx);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
660 data += avail;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
661 len -= avail;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
662
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
663 while (len >= sizeof(mctx->block)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
664 memcpy(mctx->block, data, sizeof(mctx->block));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
665 md4_transform_helper(mctx);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
666 data += sizeof(mctx->block);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
667 len -= sizeof(mctx->block);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
668 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
669
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
670 memcpy(mctx->block, data, len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
671 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
672
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
673 static gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
674 md4_digest(PurpleCipherContext *context, size_t in_len, guchar *out,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
675 size_t *out_len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
676 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
677 struct MD4_Context *mctx = purple_cipher_context_get_data(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
678 const unsigned int offset = mctx->byte_count & 0x3f;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
679 char *p = (char *)mctx->block + offset;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
680 int padding = 56 - (offset + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
681
25415
584063555949 Remove trailing whitespace
Mark Doliner <mark@kingant.net>
parents: 25385
diff changeset
682
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
683 if(in_len<16) return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
684 if(out_len) *out_len = 16;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
685 *p++ = 0x80;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
686 if (padding < 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
687 memset(p, 0x00, padding + sizeof (guint64));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
688 md4_transform_helper(mctx);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
689 p = (char *)mctx->block;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
690 padding = 56;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
691 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
692
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
693 memset(p, 0, padding);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
694 mctx->block[14] = mctx->byte_count << 3;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
695 mctx->block[15] = mctx->byte_count >> 29;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
696 le32_to_cpu_array(mctx->block, (sizeof(mctx->block) -
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
697 sizeof(guint64)) / sizeof(guint32));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
698 md4_transform(mctx->hash, mctx->block);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
699 cpu_to_le32_array(mctx->hash, sizeof(mctx->hash) / sizeof(guint32));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
700 memcpy(out, mctx->hash, sizeof(mctx->hash));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
701 memset(mctx, 0, sizeof(*mctx));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
702 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
703 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
704
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
705 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
706 md4_uninit(PurpleCipherContext *context) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
707 struct MD4_Context *md4_context;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
708
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
709 purple_cipher_context_reset(context, NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
710
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
711 md4_context = purple_cipher_context_get_data(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
712 memset(md4_context, 0, sizeof(md4_context));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
713
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
714 g_free(md4_context);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
715 md4_context = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
716 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
717
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
718 static size_t
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
719 md4_get_block_size(PurpleCipherContext *context)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
720 {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
721 /* This does not change (in this case) */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
722 return MD4_HMAC_BLOCK_SIZE;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
723 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
724
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
725 static PurpleCipherOps MD4Ops = {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
726 NULL, /* Set option */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
727 NULL, /* Get option */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
728 md4_init, /* init */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
729 md4_reset, /* reset */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
730 md4_uninit, /* uninit */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
731 NULL, /* set iv */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
732 md4_append, /* append */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
733 md4_digest, /* digest */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
734 NULL, /* encrypt */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
735 NULL, /* decrypt */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
736 NULL, /* set salt */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
737 NULL, /* get salt size */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
738 NULL, /* set key */
16676
07cf49a0f404 I _think_ this is it for libpurple's padding...
Gary Kramlich <grim@reaperworld.com>
parents: 15823
diff changeset
739 NULL, /* get key size */
21907
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
740 NULL, /* set batch mode */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
741 NULL, /* get batch mode */
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
742 md4_get_block_size, /* get block size */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
743 NULL /* set key with len */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
744 };
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
745
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
746 /*******************************************************************************
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
747 * HMAC
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
748 ******************************************************************************/
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
749
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
750 struct HMAC_Context {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
751 PurpleCipherContext *hash;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
752 char *name;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
753 int blocksize;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
754 guchar *opad;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
755 };
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
756
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
757 static void
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
758 hmac_init(PurpleCipherContext *context, gpointer extra)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
759 {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
760 struct HMAC_Context *hctx;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
761 hctx = g_new0(struct HMAC_Context, 1);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
762 purple_cipher_context_set_data(context, hctx);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
763 purple_cipher_context_reset(context, extra);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
764 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
765
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
766 static void
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
767 hmac_reset(PurpleCipherContext *context, gpointer extra)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
768 {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
769 struct HMAC_Context *hctx;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
770
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
771 hctx = purple_cipher_context_get_data(context);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
772
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
773 g_free(hctx->name);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
774 hctx->name = NULL;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
775 if (hctx->hash)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
776 purple_cipher_context_destroy(hctx->hash);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
777 hctx->hash = NULL;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
778 hctx->blocksize = 0;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
779 g_free(hctx->opad);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
780 hctx->opad = NULL;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
781 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
782
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
783 static void
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
784 hmac_set_opt(PurpleCipherContext *context, const gchar *name, void *value)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
785 {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
786 struct HMAC_Context *hctx;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
787
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
788 hctx = purple_cipher_context_get_data(context);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
789
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 23600
diff changeset
790 if (purple_strequal(name, "hash")) {
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
791 g_free(hctx->name);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
792 if (hctx->hash)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
793 purple_cipher_context_destroy(hctx->hash);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
794 hctx->name = g_strdup((char*)value);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
795 hctx->hash = purple_cipher_context_new_by_name((char *)value, NULL);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
796 hctx->blocksize = purple_cipher_context_get_block_size(hctx->hash);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
797 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
798 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
799
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
800 static void *
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
801 hmac_get_opt(PurpleCipherContext *context, const gchar *name)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
802 {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
803 struct HMAC_Context *hctx;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
804
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
805 hctx = purple_cipher_context_get_data(context);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
806
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 23600
diff changeset
807 if (purple_strequal(name, "hash")) {
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
808 return hctx->name;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
809 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
810
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
811 return NULL;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
812 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
813
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
814 static void
25415
584063555949 Remove trailing whitespace
Mark Doliner <mark@kingant.net>
parents: 25385
diff changeset
815 hmac_append(PurpleCipherContext *context, const guchar *data, size_t len)
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
816 {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
817 struct HMAC_Context *hctx = purple_cipher_context_get_data(context);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
818
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
819 g_return_if_fail(hctx->hash != NULL);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
820
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
821 purple_cipher_context_append(hctx->hash, data, len);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
822 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
823
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
824 static gboolean
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
825 hmac_digest(PurpleCipherContext *context, size_t in_len, guchar *out, size_t *out_len)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
826 {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
827 struct HMAC_Context *hctx = purple_cipher_context_get_data(context);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
828 PurpleCipherContext *hash = hctx->hash;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
829 guchar *inner_hash;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
830 size_t hash_len;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
831 gboolean result;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
832
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
833 g_return_val_if_fail(hash != NULL, FALSE);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
834
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
835 inner_hash = g_malloc(100); /* TODO: Should be enough for now... */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
836 result = purple_cipher_context_digest(hash, 100, inner_hash, &hash_len);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
837
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
838 purple_cipher_context_reset(hash, NULL);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
839
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
840 purple_cipher_context_append(hash, hctx->opad, hctx->blocksize);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
841 purple_cipher_context_append(hash, inner_hash, hash_len);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
842
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
843 g_free(inner_hash);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
844
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
845 result = result && purple_cipher_context_digest(hash, in_len, out, out_len);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
846
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
847 return result;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
848 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
849
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
850 static void
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
851 hmac_uninit(PurpleCipherContext *context)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
852 {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
853 struct HMAC_Context *hctx;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
854
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
855 purple_cipher_context_reset(context, NULL);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
856
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
857 hctx = purple_cipher_context_get_data(context);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
858
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
859 g_free(hctx);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
860 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
861
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
862 static void
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
863 hmac_set_key_with_len(PurpleCipherContext *context, const guchar * key, size_t key_len)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
864 {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
865 struct HMAC_Context *hctx = purple_cipher_context_get_data(context);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
866 int blocksize, i;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
867 guchar *ipad;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
868 guchar *full_key;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
869
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
870 g_return_if_fail(hctx->hash != NULL);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
871
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
872 g_free(hctx->opad);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
873
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
874 blocksize = hctx->blocksize;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
875 ipad = g_malloc(blocksize);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
876 hctx->opad = g_malloc(blocksize);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
877
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
878 if (key_len > blocksize) {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
879 purple_cipher_context_reset(hctx->hash, NULL);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
880 purple_cipher_context_append(hctx->hash, key, key_len);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
881 full_key = g_malloc(100); /* TODO: Should be enough for now... */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
882 purple_cipher_context_digest(hctx->hash, 100, full_key, &key_len);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
883 } else
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
884 full_key = g_memdup(key, key_len);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
885
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
886 if (key_len < blocksize) {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
887 full_key = g_realloc(full_key, blocksize);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
888 memset(full_key + key_len, 0, blocksize - key_len);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
889 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
890
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
891 for(i = 0; i < blocksize; i++) {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
892 ipad[i] = 0x36 ^ full_key[i];
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
893 hctx->opad[i] = 0x5c ^ full_key[i];
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
894 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
895
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
896 g_free(full_key);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
897
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
898 purple_cipher_context_reset(hctx->hash, NULL);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
899 purple_cipher_context_append(hctx->hash, ipad, blocksize);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
900 g_free(ipad);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
901 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
902
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
903 static void
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
904 hmac_set_key(PurpleCipherContext *context, const guchar * key)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
905 {
22011
76e0463db3aa Squash some compiler warnings, some from my -Wstrict-prototypes fixing.
Richard Laager <rlaager@wiktel.com>
parents: 21908
diff changeset
906 hmac_set_key_with_len(context, key, strlen((char *)key));
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
907 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
908
25415
584063555949 Remove trailing whitespace
Mark Doliner <mark@kingant.net>
parents: 25385
diff changeset
909 static size_t
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
910 hmac_get_block_size(PurpleCipherContext *context)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
911 {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
912 struct HMAC_Context *hctx = purple_cipher_context_get_data(context);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
913
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
914 return hctx->blocksize;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
915 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
916
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
917 static PurpleCipherOps HMACOps = {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
918 hmac_set_opt, /* Set option */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
919 hmac_get_opt, /* Get option */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
920 hmac_init, /* init */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
921 hmac_reset, /* reset */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
922 hmac_uninit, /* uninit */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
923 NULL, /* set iv */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
924 hmac_append, /* append */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
925 hmac_digest, /* digest */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
926 NULL, /* encrypt */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
927 NULL, /* decrypt */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
928 NULL, /* set salt */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
929 NULL, /* get salt size */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
930 hmac_set_key, /* set key */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
931 NULL, /* get key size */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
932 NULL, /* set batch mode */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
933 NULL, /* get batch mode */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
934 hmac_get_block_size, /* get block size */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
935 hmac_set_key_with_len /* set key with len */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
936 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
937
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
938 /******************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
939 * DES
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
940 *****************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
941
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
942 typedef struct _des_ctx
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
943 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
944 guint32 encrypt_subkeys[32];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
945 guint32 decrypt_subkeys[32];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
946 } des_ctx[1];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
947
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
948 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
949 * The s-box values are permuted according to the 'primitive function P'
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
950 */
21015
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 19680
diff changeset
951 static const guint32 sbox1[64] =
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
952 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
953 0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
954 0x00000200, 0x00808200, 0x00808202, 0x00000200, 0x00800202, 0x00808002, 0x00800000, 0x00000002,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
955 0x00000202, 0x00800200, 0x00800200, 0x00008200, 0x00008200, 0x00808000, 0x00808000, 0x00800202,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
956 0x00008002, 0x00800002, 0x00800002, 0x00008002, 0x00000000, 0x00000202, 0x00008202, 0x00800000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
957 0x00008000, 0x00808202, 0x00000002, 0x00808000, 0x00808200, 0x00800000, 0x00800000, 0x00000200,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
958 0x00808002, 0x00008000, 0x00008200, 0x00800002, 0x00000200, 0x00000002, 0x00800202, 0x00008202,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
959 0x00808202, 0x00008002, 0x00808000, 0x00800202, 0x00800002, 0x00000202, 0x00008202, 0x00808200,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
960 0x00000202, 0x00800200, 0x00800200, 0x00000000, 0x00008002, 0x00008200, 0x00000000, 0x00808002
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
961 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
962
21015
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 19680
diff changeset
963 static const guint32 sbox2[64] =
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
964 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
965 0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x00080000, 0x00000010, 0x40080010, 0x40004010,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
966 0x40000010, 0x40084010, 0x40084000, 0x40000000, 0x40004000, 0x00080000, 0x00000010, 0x40080010,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
967 0x00084000, 0x00080010, 0x40004010, 0x00000000, 0x40000000, 0x00004000, 0x00084010, 0x40080000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
968 0x00080010, 0x40000010, 0x00000000, 0x00084000, 0x00004010, 0x40084000, 0x40080000, 0x00004010,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
969 0x00000000, 0x00084010, 0x40080010, 0x00080000, 0x40004010, 0x40080000, 0x40084000, 0x00004000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
970 0x40080000, 0x40004000, 0x00000010, 0x40084010, 0x00084010, 0x00000010, 0x00004000, 0x40000000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
971 0x00004010, 0x40084000, 0x00080000, 0x40000010, 0x00080010, 0x40004010, 0x40000010, 0x00080010,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
972 0x00084000, 0x00000000, 0x40004000, 0x00004010, 0x40000000, 0x40080010, 0x40084010, 0x00084000
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
973 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
974
21015
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 19680
diff changeset
975 static const guint32 sbox3[64] =
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
976 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
977 0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x04000100, 0x00000000, 0x00010104, 0x04000100,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
978 0x00010004, 0x04000004, 0x04000004, 0x00010000, 0x04010104, 0x00010004, 0x04010000, 0x00000104,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
979 0x04000000, 0x00000004, 0x04010100, 0x00000100, 0x00010100, 0x04010000, 0x04010004, 0x00010104,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
980 0x04000104, 0x00010100, 0x00010000, 0x04000104, 0x00000004, 0x04010104, 0x00000100, 0x04000000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
981 0x04010100, 0x04000000, 0x00010004, 0x00000104, 0x00010000, 0x04010100, 0x04000100, 0x00000000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
982 0x00000100, 0x00010004, 0x04010104, 0x04000100, 0x04000004, 0x00000100, 0x00000000, 0x04010004,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
983 0x04000104, 0x00010000, 0x04000000, 0x04010104, 0x00000004, 0x00010104, 0x00010100, 0x04000004,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
984 0x04010000, 0x04000104, 0x00000104, 0x04010000, 0x00010104, 0x00000004, 0x04010004, 0x00010100
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
985 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
986
21015
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 19680
diff changeset
987 static const guint32 sbox4[64] =
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
988 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
989 0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x00401040, 0x80400040, 0x80400000, 0x80001000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
990 0x00000000, 0x00401000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00400040, 0x80400000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
991 0x80000000, 0x00001000, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x80001000, 0x00001040,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
992 0x80400040, 0x80000000, 0x00001040, 0x00400040, 0x00001000, 0x00401040, 0x80401040, 0x80000040,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
993 0x00400040, 0x80400000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00000000, 0x00401000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
994 0x00001040, 0x00400040, 0x80400040, 0x80000000, 0x80401000, 0x80001040, 0x80001040, 0x00000040,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
995 0x80401040, 0x80000040, 0x80000000, 0x00001000, 0x80400000, 0x80001000, 0x00401040, 0x80400040,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
996 0x80001000, 0x00001040, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x00001000, 0x00401040
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
997 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
998
21015
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 19680
diff changeset
999 static const guint32 sbox5[64] =
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1000 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1001 0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00040000, 0x00000080, 0x20000000, 0x01040000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1002 0x20040080, 0x00040000, 0x01000080, 0x20040080, 0x21000080, 0x21040000, 0x00040080, 0x20000000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1003 0x01000000, 0x20040000, 0x20040000, 0x00000000, 0x20000080, 0x21040080, 0x21040080, 0x01000080,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1004 0x21040000, 0x20000080, 0x00000000, 0x21000000, 0x01040080, 0x01000000, 0x21000000, 0x00040080,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1005 0x00040000, 0x21000080, 0x00000080, 0x01000000, 0x20000000, 0x01040000, 0x21000080, 0x20040080,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1006 0x01000080, 0x20000000, 0x21040000, 0x01040080, 0x20040080, 0x00000080, 0x01000000, 0x21040000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1007 0x21040080, 0x00040080, 0x21000000, 0x21040080, 0x01040000, 0x00000000, 0x20040000, 0x21000000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1008 0x00040080, 0x01000080, 0x20000080, 0x00040000, 0x00000000, 0x20040000, 0x01040080, 0x20000080
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1009 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1010
21015
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 19680
diff changeset
1011 static const guint32 sbox6[64] =
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1012 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1013 0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10200000, 0x00000008, 0x10202008, 0x00200000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1014 0x10002000, 0x00202008, 0x00200000, 0x10000008, 0x00200008, 0x10002000, 0x10000000, 0x00002008,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1015 0x00000000, 0x00200008, 0x10002008, 0x00002000, 0x00202000, 0x10002008, 0x00000008, 0x10200008,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1016 0x10200008, 0x00000000, 0x00202008, 0x10202000, 0x00002008, 0x00202000, 0x10202000, 0x10000000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1017 0x10002000, 0x00000008, 0x10200008, 0x00202000, 0x10202008, 0x00200000, 0x00002008, 0x10000008,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1018 0x00200000, 0x10002000, 0x10000000, 0x00002008, 0x10000008, 0x10202008, 0x00202000, 0x10200000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1019 0x00202008, 0x10202000, 0x00000000, 0x10200008, 0x00000008, 0x00002000, 0x10200000, 0x00202008,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1020 0x00002000, 0x00200008, 0x10002008, 0x00000000, 0x10202000, 0x10000000, 0x00200008, 0x10002008
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1021 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1022
21015
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 19680
diff changeset
1023 static const guint32 sbox7[64] =
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1024 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1025 0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00000400, 0x02000401, 0x00100401, 0x02100400,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1026 0x02100401, 0x00100000, 0x00000000, 0x02000001, 0x00000001, 0x02000000, 0x02100001, 0x00000401,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1027 0x02000400, 0x00100401, 0x00100001, 0x02000400, 0x02000001, 0x02100000, 0x02100400, 0x00100001,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1028 0x02100000, 0x00000400, 0x00000401, 0x02100401, 0x00100400, 0x00000001, 0x02000000, 0x00100400,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1029 0x02000000, 0x00100400, 0x00100000, 0x02000401, 0x02000401, 0x02100001, 0x02100001, 0x00000001,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1030 0x00100001, 0x02000000, 0x02000400, 0x00100000, 0x02100400, 0x00000401, 0x00100401, 0x02100400,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1031 0x00000401, 0x02000001, 0x02100401, 0x02100000, 0x00100400, 0x00000000, 0x00000001, 0x02100401,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1032 0x00000000, 0x00100401, 0x02100000, 0x00000400, 0x02000001, 0x02000400, 0x00000400, 0x00100001
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1033 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1034
21015
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 19680
diff changeset
1035 static const guint32 sbox8[64] =
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1036 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1037 0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000000, 0x08000820, 0x00000020, 0x08000000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1038 0x00020020, 0x08020000, 0x08020820, 0x00020800, 0x08020800, 0x00020820, 0x00000800, 0x00000020,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1039 0x08020000, 0x08000020, 0x08000800, 0x00000820, 0x00020800, 0x00020020, 0x08020020, 0x08020800,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1040 0x00000820, 0x00000000, 0x00000000, 0x08020020, 0x08000020, 0x08000800, 0x00020820, 0x00020000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1041 0x00020820, 0x00020000, 0x08020800, 0x00000800, 0x00000020, 0x08020020, 0x00000800, 0x00020820,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1042 0x08000800, 0x00000020, 0x08000020, 0x08020000, 0x08020020, 0x08000000, 0x00020000, 0x08000820,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1043 0x00000000, 0x08020820, 0x00020020, 0x08000020, 0x08020000, 0x08000800, 0x08000820, 0x00000000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1044 0x08020820, 0x00020800, 0x00020800, 0x00000820, 0x00000820, 0x00020020, 0x08000000, 0x08020800
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1045 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1046
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1047
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1048
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1049 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1050 * * These two tables are part of the 'permuted choice 1' function.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1051 * * In this implementation several speed improvements are done.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1052 * */
21015
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 19680
diff changeset
1053 static const guint32 leftkey_swap[16] =
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1054 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1055 0x00000000, 0x00000001, 0x00000100, 0x00000101,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1056 0x00010000, 0x00010001, 0x00010100, 0x00010101,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1057 0x01000000, 0x01000001, 0x01000100, 0x01000101,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1058 0x01010000, 0x01010001, 0x01010100, 0x01010101
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1059 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1060
21015
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 19680
diff changeset
1061 static const guint32 rightkey_swap[16] =
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1062 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1063 0x00000000, 0x01000000, 0x00010000, 0x01010000,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1064 0x00000100, 0x01000100, 0x00010100, 0x01010100,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1065 0x00000001, 0x01000001, 0x00010001, 0x01010001,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1066 0x00000101, 0x01000101, 0x00010101, 0x01010101,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1067 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1068
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1069
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1070
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1071 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1072 * Numbers of left shifts per round for encryption subkey schedule
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1073 * To calculate the decryption key scheduling we just reverse the
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1074 * ordering of the subkeys so we can omit the table for decryption
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1075 * subkey schedule.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1076 */
21015
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 19680
diff changeset
1077 static const guint8 encrypt_rotate_tab[16] =
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1078 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1079 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1080 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1081
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1082 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1083 * Macro to swap bits across two words
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1084 **/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1085 #define DO_PERMUTATION(a, temp, b, offset, mask) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1086 temp = ((a>>offset) ^ b) & mask; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1087 b ^= temp; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1088 a ^= temp<<offset;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1089
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1090
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1091 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1092 * This performs the 'initial permutation' for the data to be encrypted or decrypted
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1093 **/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1094 #define INITIAL_PERMUTATION(left, temp, right) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1095 DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1096 DO_PERMUTATION(left, temp, right, 16, 0x0000ffff) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1097 DO_PERMUTATION(right, temp, left, 2, 0x33333333) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1098 DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1099 DO_PERMUTATION(left, temp, right, 1, 0x55555555)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1100
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1101
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1102 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1103 * The 'inverse initial permutation'
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1104 **/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1105 #define FINAL_PERMUTATION(left, temp, right) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1106 DO_PERMUTATION(left, temp, right, 1, 0x55555555) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1107 DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1108 DO_PERMUTATION(right, temp, left, 2, 0x33333333) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1109 DO_PERMUTATION(left, temp, right, 16, 0x0000ffff) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1110 DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1111
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1112
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1113 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1114 * A full DES round including 'expansion function', 'sbox substitution'
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1115 * and 'primitive function P' but without swapping the left and right word.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1116 **/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1117 #define DES_ROUND(from, to, work, subkey) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1118 work = ((from<<1) | (from>>31)) ^ *subkey++; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1119 to ^= sbox8[ work & 0x3f ]; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1120 to ^= sbox6[ (work>>8) & 0x3f ]; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1121 to ^= sbox4[ (work>>16) & 0x3f ]; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1122 to ^= sbox2[ (work>>24) & 0x3f ]; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1123 work = ((from>>3) | (from<<29)) ^ *subkey++; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1124 to ^= sbox7[ work & 0x3f ]; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1125 to ^= sbox5[ (work>>8) & 0x3f ]; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1126 to ^= sbox3[ (work>>16) & 0x3f ]; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1127 to ^= sbox1[ (work>>24) & 0x3f ];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1128
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1129
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1130 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1131 * Macros to convert 8 bytes from/to 32bit words
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1132 **/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1133 #define READ_64BIT_DATA(data, left, right) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1134 left = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1135 right = (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | data[7];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1136
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1137 #define WRITE_64BIT_DATA(data, left, right) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1138 data[0] = (left >> 24) &0xff; data[1] = (left >> 16) &0xff; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1139 data[2] = (left >> 8) &0xff; data[3] = left &0xff; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1140 data[4] = (right >> 24) &0xff; data[5] = (right >> 16) &0xff; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1141 data[6] = (right >> 8) &0xff; data[7] = right &0xff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1142
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1143
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1144
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1145
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1146
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1147
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1148 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1149 * des_key_schedule(): Calculate 16 subkeys pairs (even/odd) for
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1150 * 16 encryption rounds.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1151 * To calculate subkeys for decryption the caller
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1152 * have to reorder the generated subkeys.
25415
584063555949 Remove trailing whitespace
Mark Doliner <mark@kingant.net>
parents: 25385
diff changeset
1153 *
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1154 * rawkey: 8 Bytes of key data
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1155 * subkey: Array of at least 32 guint32s. Will be filled
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1156 * with calculated subkeys.
25415
584063555949 Remove trailing whitespace
Mark Doliner <mark@kingant.net>
parents: 25385
diff changeset
1157 *
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1158 **/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1159 static void
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1160 des_key_schedule (const guint8 * rawkey, guint32 * subkey)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1161 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1162 guint32 left, right, work;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1163 int round;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1164
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1165 READ_64BIT_DATA (rawkey, left, right)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1166
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1167 DO_PERMUTATION (right, work, left, 4, 0x0f0f0f0f)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1168 DO_PERMUTATION (right, work, left, 0, 0x10101010)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1169
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1170 left = (leftkey_swap[(left >> 0) & 0xf] << 3) | (leftkey_swap[(left >> 8) & 0xf] << 2)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1171 | (leftkey_swap[(left >> 16) & 0xf] << 1) | (leftkey_swap[(left >> 24) & 0xf])
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1172 | (leftkey_swap[(left >> 5) & 0xf] << 7) | (leftkey_swap[(left >> 13) & 0xf] << 6)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1173 | (leftkey_swap[(left >> 21) & 0xf] << 5) | (leftkey_swap[(left >> 29) & 0xf] << 4);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1174
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1175 left &= 0x0fffffff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1176
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1177 right = (rightkey_swap[(right >> 1) & 0xf] << 3) | (rightkey_swap[(right >> 9) & 0xf] << 2)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1178 | (rightkey_swap[(right >> 17) & 0xf] << 1) | (rightkey_swap[(right >> 25) & 0xf])
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1179 | (rightkey_swap[(right >> 4) & 0xf] << 7) | (rightkey_swap[(right >> 12) & 0xf] << 6)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1180 | (rightkey_swap[(right >> 20) & 0xf] << 5) | (rightkey_swap[(right >> 28) & 0xf] << 4);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1181
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1182 right &= 0x0fffffff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1183
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1184 for (round = 0; round < 16; ++round)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1185 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1186 left = ((left << encrypt_rotate_tab[round]) | (left >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1187 right = ((right << encrypt_rotate_tab[round]) | (right >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1188
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1189 *subkey++ = ((left << 4) & 0x24000000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1190 | ((left << 28) & 0x10000000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1191 | ((left << 14) & 0x08000000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1192 | ((left << 18) & 0x02080000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1193 | ((left << 6) & 0x01000000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1194 | ((left << 9) & 0x00200000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1195 | ((left >> 1) & 0x00100000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1196 | ((left << 10) & 0x00040000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1197 | ((left << 2) & 0x00020000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1198 | ((left >> 10) & 0x00010000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1199 | ((right >> 13) & 0x00002000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1200 | ((right >> 4) & 0x00001000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1201 | ((right << 6) & 0x00000800)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1202 | ((right >> 1) & 0x00000400)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1203 | ((right >> 14) & 0x00000200)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1204 | (right & 0x00000100)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1205 | ((right >> 5) & 0x00000020)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1206 | ((right >> 10) & 0x00000010)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1207 | ((right >> 3) & 0x00000008)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1208 | ((right >> 18) & 0x00000004)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1209 | ((right >> 26) & 0x00000002)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1210 | ((right >> 24) & 0x00000001);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1211
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1212 *subkey++ = ((left << 15) & 0x20000000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1213 | ((left << 17) & 0x10000000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1214 | ((left << 10) & 0x08000000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1215 | ((left << 22) & 0x04000000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1216 | ((left >> 2) & 0x02000000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1217 | ((left << 1) & 0x01000000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1218 | ((left << 16) & 0x00200000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1219 | ((left << 11) & 0x00100000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1220 | ((left << 3) & 0x00080000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1221 | ((left >> 6) & 0x00040000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1222 | ((left << 15) & 0x00020000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1223 | ((left >> 4) & 0x00010000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1224 | ((right >> 2) & 0x00002000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1225 | ((right << 8) & 0x00001000)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1226 | ((right >> 14) & 0x00000808)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1227 | ((right >> 9) & 0x00000400)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1228 | ((right) & 0x00000200)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1229 | ((right << 7) & 0x00000100)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1230 | ((right >> 7) & 0x00000020)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1231 | ((right >> 3) & 0x00000011)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1232 | ((right << 2) & 0x00000004)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1233 | ((right >> 21) & 0x00000002);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1234 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1235 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1236
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1237
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1238
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1239 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1240 * Fill a DES context with subkeys calculated from a 64bit key.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1241 * Does not check parity bits, but simply ignore them.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1242 * Does not check for weak keys.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1243 **/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1244 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1245 des_set_key (PurpleCipherContext *context, const guchar * key)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1246 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1247 struct _des_ctx *ctx = purple_cipher_context_get_data(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1248 int i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1249
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1250 des_key_schedule (key, ctx->encrypt_subkeys);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1251
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1252 for(i=0; i<32; i+=2)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1253 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1254 ctx->decrypt_subkeys[i] = ctx->encrypt_subkeys[30-i];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1255 ctx->decrypt_subkeys[i+1] = ctx->encrypt_subkeys[31-i];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1256 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1257 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1258
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1259
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1260
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1261 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1262 * Electronic Codebook Mode DES encryption/decryption of data according
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1263 * to 'mode'.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1264 **/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1265 static int
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1266 des_ecb_crypt (struct _des_ctx *ctx, const guint8 * from, guint8 * to, int mode)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1267 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1268 guint32 left, right, work;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1269 guint32 *keys;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1270
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1271 keys = mode ? ctx->decrypt_subkeys : ctx->encrypt_subkeys;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1272
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1273 READ_64BIT_DATA (from, left, right)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1274 INITIAL_PERMUTATION (left, work, right)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1275
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1276 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1277 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1278 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1279 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1280 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1281 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1282 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1283 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1284
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1285 FINAL_PERMUTATION (right, work, left)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1286 WRITE_64BIT_DATA (to, right, left)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1287
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1288 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1289 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1290
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1291 static gint
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1292 des_encrypt(PurpleCipherContext *context, const guchar data[],
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1293 size_t len, guchar output[], size_t *outlen) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1294 int offset = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1295 int i = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1296 int tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1297 guint8 buf[8] = {0,0,0,0,0,0,0,0};
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1298 while(offset+8<=len) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1299 des_ecb_crypt(purple_cipher_context_get_data(context),
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1300 data+offset,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1301 output+offset,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1302 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1303 offset+=8;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1304 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1305 *outlen = len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1306 if(offset<len) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1307 *outlen += len - offset;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1308 tmp = offset;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1309 while(tmp<len) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1310 buf[i++] = data[tmp];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1311 tmp++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1312 }
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1313 des_ecb_crypt(purple_cipher_context_get_data(context),
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1314 buf,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1315 output+offset,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1316 0);
25415
584063555949 Remove trailing whitespace
Mark Doliner <mark@kingant.net>
parents: 25385
diff changeset
1317 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1318 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1319 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1320
21907
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1321 static gint
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1322 des_decrypt(PurpleCipherContext *context, const guchar data[],
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1323 size_t len, guchar output[], size_t *outlen) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1324 int offset = 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1325 int i = 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1326 int tmp;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1327 guint8 buf[8] = {0,0,0,0,0,0,0,0};
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1328 while(offset+8<=len) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1329 des_ecb_crypt(purple_cipher_context_get_data(context),
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1330 data+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1331 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1332 1);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1333 offset+=8;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1334 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1335 *outlen = len;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1336 if(offset<len) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1337 *outlen += len - offset;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1338 tmp = offset;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1339 while(tmp<len) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1340 buf[i++] = data[tmp];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1341 tmp++;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1342 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1343 des_ecb_crypt(purple_cipher_context_get_data(context),
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1344 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1345 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1346 1);
25415
584063555949 Remove trailing whitespace
Mark Doliner <mark@kingant.net>
parents: 25385
diff changeset
1347 }
21907
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1348 return 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1349 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1350
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1351 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1352 des_init(PurpleCipherContext *context, gpointer extra) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1353 struct _des_ctx *mctx;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1354 mctx = g_new0(struct _des_ctx, 1);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1355 purple_cipher_context_set_data(context, mctx);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1356 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1357
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1358 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1359 des_uninit(PurpleCipherContext *context) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1360 struct _des_ctx *des_context;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1361
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1362 des_context = purple_cipher_context_get_data(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1363 memset(des_context, 0, sizeof(des_context));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1364
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1365 g_free(des_context);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1366 des_context = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1367 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1368
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1369 static PurpleCipherOps DESOps = {
21907
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1370 NULL, /* Set option */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1371 NULL, /* Get option */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1372 des_init, /* init */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1373 NULL, /* reset */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1374 des_uninit, /* uninit */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1375 NULL, /* set iv */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1376 NULL, /* append */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1377 NULL, /* digest */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1378 des_encrypt, /* encrypt */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1379 des_decrypt, /* decrypt */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1380 NULL, /* set salt */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1381 NULL, /* get salt size */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1382 des_set_key, /* set key */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1383 NULL, /* get key size */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1384 NULL, /* set batch mode */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1385 NULL, /* get batch mode */
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
1386 NULL, /* get block size */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
1387 NULL /* set key with len */
21907
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1388 };
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1389
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1390 /******************************************************************************
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1391 * Triple-DES
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1392 *****************************************************************************/
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1393
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1394 typedef struct _des3_ctx
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1395 {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1396 PurpleCipherBatchMode mode;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1397 guchar iv[8];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1398 /* First key for encryption */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1399 struct _des_ctx key1;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1400 /* Second key for decryption */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1401 struct _des_ctx key2;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1402 /* Third key for encryption */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1403 struct _des_ctx key3;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1404 } des3_ctx[1];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1405
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1406 /*
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1407 * Fill a DES3 context with subkeys calculated from 3 64bit key.
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1408 * Does not check parity bits, but simply ignore them.
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1409 * Does not check for weak keys.
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1410 **/
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1411 static void
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1412 des3_set_key(PurpleCipherContext *context, const guchar * key)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1413 {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1414 struct _des3_ctx *ctx = purple_cipher_context_get_data(context);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1415 int i;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1416
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1417 des_key_schedule (key + 0, ctx->key1.encrypt_subkeys);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1418 des_key_schedule (key + 8, ctx->key2.encrypt_subkeys);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1419 des_key_schedule (key + 16, ctx->key3.encrypt_subkeys);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1420
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1421 for (i = 0; i < 32; i += 2)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1422 {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1423 ctx->key1.decrypt_subkeys[i] = ctx->key1.encrypt_subkeys[30-i];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1424 ctx->key1.decrypt_subkeys[i+1] = ctx->key1.encrypt_subkeys[31-i];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1425 ctx->key2.decrypt_subkeys[i] = ctx->key2.encrypt_subkeys[30-i];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1426 ctx->key2.decrypt_subkeys[i+1] = ctx->key2.encrypt_subkeys[31-i];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1427 ctx->key3.decrypt_subkeys[i] = ctx->key3.encrypt_subkeys[30-i];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1428 ctx->key3.decrypt_subkeys[i+1] = ctx->key3.encrypt_subkeys[31-i];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1429 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1430 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1431
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1432 static gint
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1433 des3_ecb_encrypt(struct _des3_ctx *ctx, const guchar data[],
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1434 size_t len, guchar output[], size_t *outlen)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1435 {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1436 int offset = 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1437 int i = 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1438 int tmp;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1439 guint8 buf[8] = {0,0,0,0,0,0,0,0};
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1440 while (offset + 8 <= len) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1441 des_ecb_crypt(&ctx->key1,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1442 data+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1443 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1444 0);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1445 des_ecb_crypt(&ctx->key2,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1446 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1447 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1448 1);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1449 des_ecb_crypt(&ctx->key3,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1450 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1451 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1452 0);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1453 offset += 8;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1454 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1455 *outlen = len;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1456 if (offset < len) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1457 *outlen += len - offset;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1458 tmp = offset;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1459 memset(buf, 0, 8);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1460 while (tmp < len) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1461 buf[i++] = data[tmp];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1462 tmp++;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1463 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1464 des_ecb_crypt(&ctx->key1,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1465 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1466 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1467 0);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1468 des_ecb_crypt(&ctx->key2,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1469 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1470 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1471 1);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1472 des_ecb_crypt(&ctx->key3,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1473 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1474 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1475 0);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1476 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1477 return 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1478 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1479
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1480 static gint
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1481 des3_cbc_encrypt(struct _des3_ctx *ctx, const guchar data[],
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1482 size_t len, guchar output[], size_t *outlen)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1483 {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1484 int offset = 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1485 int i = 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1486 int tmp;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1487 guint8 buf[8];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1488 memcpy(buf, ctx->iv, 8);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1489 while (offset + 8 <= len) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1490 for (i = 0; i < 8; i++)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1491 buf[i] ^= data[offset + i];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1492 des_ecb_crypt(&ctx->key1,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1493 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1494 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1495 0);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1496 des_ecb_crypt(&ctx->key2,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1497 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1498 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1499 1);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1500 des_ecb_crypt(&ctx->key3,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1501 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1502 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1503 0);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1504 memcpy(buf, output+offset, 8);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1505 offset += 8;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1506 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1507 *outlen = len;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1508 if (offset < len) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1509 *outlen += len - offset;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1510 tmp = offset;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1511 i = 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1512 while (tmp < len) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1513 buf[i++] ^= data[tmp];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1514 tmp++;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1515 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1516 des_ecb_crypt(&ctx->key1,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1517 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1518 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1519 0);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1520 des_ecb_crypt(&ctx->key2,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1521 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1522 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1523 1);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1524 des_ecb_crypt(&ctx->key3,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1525 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1526 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1527 0);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1528 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1529 return 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1530 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1531
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1532 static gint
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1533 des3_encrypt(PurpleCipherContext *context, const guchar data[],
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1534 size_t len, guchar output[], size_t *outlen)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1535 {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1536 struct _des3_ctx *ctx = purple_cipher_context_get_data(context);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1537
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1538 if (ctx->mode == PURPLE_CIPHER_BATCH_MODE_ECB) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1539 return des3_ecb_encrypt(ctx, data, len, output, outlen);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1540 } else if (ctx->mode == PURPLE_CIPHER_BATCH_MODE_CBC) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1541 return des3_cbc_encrypt(ctx, data, len, output, outlen);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1542 } else {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1543 g_return_val_if_reached(0);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1544 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1545
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1546 return 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1547 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1548
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1549 static gint
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1550 des3_ecb_decrypt(struct _des3_ctx *ctx, const guchar data[],
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1551 size_t len, guchar output[], size_t *outlen)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1552 {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1553 int offset = 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1554 int i = 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1555 int tmp;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1556 guint8 buf[8] = {0,0,0,0,0,0,0,0};
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1557 while (offset + 8 <= len) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1558 /* NOTE: Apply key in reverse */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1559 des_ecb_crypt(&ctx->key3,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1560 data+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1561 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1562 1);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1563 des_ecb_crypt(&ctx->key2,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1564 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1565 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1566 0);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1567 des_ecb_crypt(&ctx->key1,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1568 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1569 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1570 1);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1571 offset+=8;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1572 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1573 *outlen = len;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1574 if (offset < len) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1575 *outlen += len - offset;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1576 tmp = offset;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1577 memset(buf, 0, 8);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1578 while (tmp < len) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1579 buf[i++] = data[tmp];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1580 tmp++;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1581 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1582 des_ecb_crypt(&ctx->key3,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1583 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1584 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1585 1);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1586 des_ecb_crypt(&ctx->key2,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1587 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1588 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1589 0);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1590 des_ecb_crypt(&ctx->key1,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1591 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1592 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1593 1);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1594 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1595 return 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1596 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1597
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1598 static gint
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1599 des3_cbc_decrypt(struct _des3_ctx *ctx, const guchar data[],
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1600 size_t len, guchar output[], size_t *outlen)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1601 {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1602 int offset = 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1603 int i = 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1604 int tmp;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1605 guint8 buf[8] = {0,0,0,0,0,0,0,0};
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1606 guint8 link[8];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1607 memcpy(link, ctx->iv, 8);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1608 while (offset + 8 <= len) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1609 des_ecb_crypt(&ctx->key3,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1610 data+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1611 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1612 1);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1613 des_ecb_crypt(&ctx->key2,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1614 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1615 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1616 0);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1617 des_ecb_crypt(&ctx->key1,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1618 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1619 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1620 1);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1621 for (i = 0; i < 8; i++)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1622 output[offset + i] ^= link[i];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1623 memcpy(link, data + offset, 8);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1624 offset+=8;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1625 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1626 *outlen = len;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1627 if(offset<len) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1628 *outlen += len - offset;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1629 tmp = offset;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1630 memset(buf, 0, 8);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1631 i = 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1632 while(tmp<len) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1633 buf[i++] = data[tmp];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1634 tmp++;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1635 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1636 des_ecb_crypt(&ctx->key3,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1637 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1638 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1639 1);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1640 des_ecb_crypt(&ctx->key2,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1641 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1642 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1643 0);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1644 des_ecb_crypt(&ctx->key1,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1645 buf,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1646 output+offset,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1647 1);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1648 for (i = 0; i < 8; i++)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1649 output[offset + i] ^= link[i];
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1650 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1651 return 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1652 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1653
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1654 static gint
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1655 des3_decrypt(PurpleCipherContext *context, const guchar data[],
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1656 size_t len, guchar output[], size_t *outlen)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1657 {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1658 struct _des3_ctx *ctx = purple_cipher_context_get_data(context);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1659
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1660 if (ctx->mode == PURPLE_CIPHER_BATCH_MODE_ECB) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1661 return des3_ecb_decrypt(ctx, data, len, output, outlen);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1662 } else if (ctx->mode == PURPLE_CIPHER_BATCH_MODE_CBC) {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1663 return des3_cbc_decrypt(ctx, data, len, output, outlen);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1664 } else {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1665 g_return_val_if_reached(0);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1666 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1667
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1668 return 0;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1669 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1670
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1671 static void
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1672 des3_set_batch(PurpleCipherContext *context, PurpleCipherBatchMode mode)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1673 {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1674 struct _des3_ctx *ctx = purple_cipher_context_get_data(context);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1675
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1676 ctx->mode = mode;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1677 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1678
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1679 static PurpleCipherBatchMode
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1680 des3_get_batch(PurpleCipherContext *context)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1681 {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1682 struct _des3_ctx *ctx = purple_cipher_context_get_data(context);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1683
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1684 return ctx->mode;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1685 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1686
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1687 static void
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1688 des3_set_iv(PurpleCipherContext *context, guchar *iv, size_t len)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1689 {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1690 struct _des3_ctx *ctx;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1691
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1692 g_return_if_fail(len == 8);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1693
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1694 ctx = purple_cipher_context_get_data(context);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1695
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1696 memcpy(ctx->iv, iv, len);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1697 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1698
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1699 static void
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1700 des3_init(PurpleCipherContext *context, gpointer extra)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1701 {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1702 struct _des3_ctx *mctx;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1703 mctx = g_new0(struct _des3_ctx, 1);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1704 purple_cipher_context_set_data(context, mctx);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1705 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1706
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1707 static void
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1708 des3_uninit(PurpleCipherContext *context)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1709 {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1710 struct _des3_ctx *des3_context;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1711
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1712 des3_context = purple_cipher_context_get_data(context);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1713 memset(des3_context, 0, sizeof(des3_context));
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1714
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1715 g_free(des3_context);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1716 des3_context = NULL;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1717 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1718
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1719 static PurpleCipherOps DES3Ops = {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1720 NULL, /* Set option */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1721 NULL, /* Get option */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1722 des3_init, /* init */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1723 NULL, /* reset */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1724 des3_uninit, /* uninit */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1725 des3_set_iv, /* set iv */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1726 NULL, /* append */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1727 NULL, /* digest */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1728 des3_encrypt, /* encrypt */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1729 des3_decrypt, /* decrypt */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1730 NULL, /* set salt */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1731 NULL, /* get salt size */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1732 des3_set_key, /* set key */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1733 NULL, /* get key size */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1734 des3_set_batch, /* set batch mode */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
1735 des3_get_batch, /* get batch mode */
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
1736 NULL, /* get block size */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
1737 NULL /* set key with len */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1738 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1739
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1740 /*******************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1741 * SHA-1
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1742 ******************************************************************************/
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
1743 #define SHA1_HMAC_BLOCK_SIZE 64
27390
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1744
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1745 static size_t
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1746 sha1_get_block_size(PurpleCipherContext *context)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1747 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1748 /* This does not change (in this case) */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1749 return SHA1_HMAC_BLOCK_SIZE;
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1750 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1751
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1752
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1753 #if GLIB_CHECK_VERSION(2,16,0)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1754
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1755 static void
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1756 sha1_init(PurpleCipherContext *context, void *extra)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1757 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1758 purple_g_checksum_init(context, G_CHECKSUM_SHA1);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1759 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1760
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1761 static void
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1762 sha1_reset(PurpleCipherContext *context, void *extra)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1763 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1764 purple_g_checksum_reset(context, G_CHECKSUM_SHA1);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1765 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1766
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1767 static gboolean
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1768 sha1_digest(PurpleCipherContext *context, gsize in_len, guchar digest[20],
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1769 gsize *out_len)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1770 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1771 return purple_g_checksum_digest(context, G_CHECKSUM_SHA1, in_len,
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1772 digest, out_len);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1773 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1774
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1775 static PurpleCipherOps SHA1Ops = {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1776 NULL, /* Set Option */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1777 NULL, /* Get Option */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1778 sha1_init, /* init */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1779 sha1_reset, /* reset */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1780 purple_g_checksum_uninit, /* uninit */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1781 NULL, /* set iv */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1782 purple_g_checksum_append, /* append */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1783 sha1_digest, /* digest */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1784 NULL, /* encrypt */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1785 NULL, /* decrypt */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1786 NULL, /* set salt */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1787 NULL, /* get salt size */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1788 NULL, /* set key */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1789 NULL, /* get key size */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1790 NULL, /* set batch mode */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1791 NULL, /* get batch mode */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1792 sha1_get_block_size, /* get block size */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1793 NULL /* set key with len */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1794 };
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1795
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1796 #else /* GLIB_CHECK_VERSION(2,16,0) */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1797
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
1798 #define SHA1_HMAC_BLOCK_SIZE 64
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1799 #define SHA1_ROTL(X,n) ((((X) << (n)) | ((X) >> (32-(n)))) & 0xFFFFFFFF)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1800
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1801 struct SHA1Context {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1802 guint32 H[5];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1803 guint32 W[80];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1804
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1805 gint lenW;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1806
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1807 guint32 sizeHi;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1808 guint32 sizeLo;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1809 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1810
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1811 static void
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1812 sha1_hash_block(struct SHA1Context *sha1_ctx) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1813 gint i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1814 guint32 A, B, C, D, E, T;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1815
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1816 for(i = 16; i < 80; i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1817 sha1_ctx->W[i] = SHA1_ROTL(sha1_ctx->W[i - 3] ^
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1818 sha1_ctx->W[i - 8] ^
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1819 sha1_ctx->W[i - 14] ^
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1820 sha1_ctx->W[i - 16], 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1821 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1822
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1823 A = sha1_ctx->H[0];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1824 B = sha1_ctx->H[1];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1825 C = sha1_ctx->H[2];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1826 D = sha1_ctx->H[3];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1827 E = sha1_ctx->H[4];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1828
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1829 for(i = 0; i < 20; i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1830 T = (SHA1_ROTL(A, 5) + (((C ^ D) & B) ^ D) + E + sha1_ctx->W[i] + 0x5A827999) & 0xFFFFFFFF;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1831 E = D;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1832 D = C;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1833 C = SHA1_ROTL(B, 30);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1834 B = A;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1835 A = T;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1836 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1837
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1838 for(i = 20; i < 40; i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1839 T = (SHA1_ROTL(A, 5) + (B ^ C ^ D) + E + sha1_ctx->W[i] + 0x6ED9EBA1) & 0xFFFFFFFF;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1840 E = D;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1841 D = C;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1842 C = SHA1_ROTL(B, 30);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1843 B = A;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1844 A = T;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1845 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1846
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1847 for(i = 40; i < 60; i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1848 T = (SHA1_ROTL(A, 5) + ((B & C) | (D & (B | C))) + E + sha1_ctx->W[i] + 0x8F1BBCDC) & 0xFFFFFFFF;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1849 E = D;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1850 D = C;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1851 C = SHA1_ROTL(B, 30);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1852 B = A;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1853 A = T;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1854 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1855
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1856 for(i = 60; i < 80; i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1857 T = (SHA1_ROTL(A, 5) + (B ^ C ^ D) + E + sha1_ctx->W[i] + 0xCA62C1D6) & 0xFFFFFFFF;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1858 E = D;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1859 D = C;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1860 C = SHA1_ROTL(B, 30);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1861 B = A;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1862 A = T;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1863 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1864
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1865 sha1_ctx->H[0] += A;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1866 sha1_ctx->H[1] += B;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1867 sha1_ctx->H[2] += C;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1868 sha1_ctx->H[3] += D;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1869 sha1_ctx->H[4] += E;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1870 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1871
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1872 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1873 sha1_set_opt(PurpleCipherContext *context, const gchar *name, void *value) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1874 struct SHA1Context *ctx;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1875
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1876 ctx = purple_cipher_context_get_data(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1877
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 23600
diff changeset
1878 if(purple_strequal(name, "sizeHi")) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1879 ctx->sizeHi = GPOINTER_TO_INT(value);
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 23600
diff changeset
1880 } else if(purple_strequal(name, "sizeLo")) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1881 ctx->sizeLo = GPOINTER_TO_INT(value);
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 23600
diff changeset
1882 } else if(purple_strequal(name, "lenW")) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1883 ctx->lenW = GPOINTER_TO_INT(value);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1884 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1885 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1886
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1887 static void *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1888 sha1_get_opt(PurpleCipherContext *context, const gchar *name) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1889 struct SHA1Context *ctx;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1890
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1891 ctx = purple_cipher_context_get_data(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1892
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 23600
diff changeset
1893 if(purple_strequal(name, "sizeHi")) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1894 return GINT_TO_POINTER(ctx->sizeHi);
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 23600
diff changeset
1895 } else if(purple_strequal(name, "sizeLo")) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1896 return GINT_TO_POINTER(ctx->sizeLo);
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 23600
diff changeset
1897 } else if(purple_strequal(name, "lenW")) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1898 return GINT_TO_POINTER(ctx->lenW);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1899 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1900
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1901 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1902 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1903
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1904 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1905 sha1_init(PurpleCipherContext *context, void *extra) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1906 struct SHA1Context *sha1_ctx;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1907
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1908 sha1_ctx = g_new0(struct SHA1Context, 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1909
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1910 purple_cipher_context_set_data(context, sha1_ctx);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1911
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1912 purple_cipher_context_reset(context, extra);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1913 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1914
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1915 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1916 sha1_reset(PurpleCipherContext *context, void *extra) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1917 struct SHA1Context *sha1_ctx;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1918 gint i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1919
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1920 sha1_ctx = purple_cipher_context_get_data(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1921
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1922 g_return_if_fail(sha1_ctx);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1923
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1924 sha1_ctx->lenW = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1925 sha1_ctx->sizeHi = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1926 sha1_ctx->sizeLo = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1927
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1928 sha1_ctx->H[0] = 0x67452301;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1929 sha1_ctx->H[1] = 0xEFCDAB89;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1930 sha1_ctx->H[2] = 0x98BADCFE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1931 sha1_ctx->H[3] = 0x10325476;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1932 sha1_ctx->H[4] = 0xC3D2E1F0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1933
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1934 for(i = 0; i < 80; i++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1935 sha1_ctx->W[i] = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1936 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1937
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1938 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1939 sha1_uninit(PurpleCipherContext *context) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1940 struct SHA1Context *sha1_ctx;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1941
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1942 purple_cipher_context_reset(context, NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1943
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1944 sha1_ctx = purple_cipher_context_get_data(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1945
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1946 memset(sha1_ctx, 0, sizeof(struct SHA1Context));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1947
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1948 g_free(sha1_ctx);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1949 sha1_ctx = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1950 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1951
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1952
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1953 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1954 sha1_append(PurpleCipherContext *context, const guchar *data, size_t len) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1955 struct SHA1Context *sha1_ctx;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1956 gint i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1957
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1958 sha1_ctx = purple_cipher_context_get_data(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1959
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1960 g_return_if_fail(sha1_ctx);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1961
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1962 for(i = 0; i < len; i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1963 sha1_ctx->W[sha1_ctx->lenW / 4] <<= 8;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1964 sha1_ctx->W[sha1_ctx->lenW / 4] |= data[i];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1965
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1966 if((++sha1_ctx->lenW) % 64 == 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1967 sha1_hash_block(sha1_ctx);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1968 sha1_ctx->lenW = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1969 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1970
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1971 sha1_ctx->sizeLo += 8;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1972 sha1_ctx->sizeHi += (sha1_ctx->sizeLo < 8);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1973 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1974 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1975
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1976 static gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1977 sha1_digest(PurpleCipherContext *context, size_t in_len, guchar digest[20],
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1978 size_t *out_len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1979 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1980 struct SHA1Context *sha1_ctx;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1981 guchar pad0x80 = 0x80, pad0x00 = 0x00;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1982 guchar padlen[8];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1983 gint i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1984
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1985 g_return_val_if_fail(in_len >= 20, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1986
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
1987 sha1_ctx = purple_cipher_context_get_data(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1988
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1989 g_return_val_if_fail(sha1_ctx, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1990
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1991 padlen[0] = (guchar)((sha1_ctx->sizeHi >> 24) & 255);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1992 padlen[1] = (guchar)((sha1_ctx->sizeHi >> 16) & 255);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1993 padlen[2] = (guchar)((sha1_ctx->sizeHi >> 8) & 255);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1994 padlen[3] = (guchar)((sha1_ctx->sizeHi >> 0) & 255);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1995 padlen[4] = (guchar)((sha1_ctx->sizeLo >> 24) & 255);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1996 padlen[5] = (guchar)((sha1_ctx->sizeLo >> 16) & 255);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1997 padlen[6] = (guchar)((sha1_ctx->sizeLo >> 8) & 255);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1998 padlen[7] = (guchar)((sha1_ctx->sizeLo >> 0) & 255);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1999
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2000 /* pad with a 1, then zeroes, then length */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2001 purple_cipher_context_append(context, &pad0x80, 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2002 while(sha1_ctx->lenW != 56)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2003 purple_cipher_context_append(context, &pad0x00, 1);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2004 purple_cipher_context_append(context, padlen, 8);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2005
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2006 for(i = 0; i < 20; i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2007 digest[i] = (guchar)(sha1_ctx->H[i / 4] >> 24);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2008 sha1_ctx->H[i / 4] <<= 8;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2009 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2010
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2011 purple_cipher_context_reset(context, NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2012
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2013 if(out_len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2014 *out_len = 20;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2015
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2016 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2017 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2018
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2019 static PurpleCipherOps SHA1Ops = {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2020 sha1_set_opt, /* Set Option */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2021 sha1_get_opt, /* Get Option */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2022 sha1_init, /* init */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2023 sha1_reset, /* reset */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2024 sha1_uninit, /* uninit */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2025 NULL, /* set iv */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2026 sha1_append, /* append */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2027 sha1_digest, /* digest */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2028 NULL, /* encrypt */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2029 NULL, /* decrypt */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2030 NULL, /* set salt */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2031 NULL, /* get salt size */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2032 NULL, /* set key */
16676
07cf49a0f404 I _think_ this is it for libpurple's padding...
Gary Kramlich <grim@reaperworld.com>
parents: 15823
diff changeset
2033 NULL, /* get key size */
21907
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
2034 NULL, /* set batch mode */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
2035 NULL, /* get batch mode */
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
2036 sha1_get_block_size, /* get block size */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
2037 NULL /* set key with len */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2038 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2039
27390
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2040 #endif /* GLIB_CHECK_VERSION(2,16,0) */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2041
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2042 /*******************************************************************************
27241
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2043 * SHA-256
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2044 ******************************************************************************/
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2045 #define SHA256_HMAC_BLOCK_SIZE 64
27390
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2046
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2047 static size_t
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2048 sha256_get_block_size(PurpleCipherContext *context)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2049 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2050 /* This does not change (in this case) */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2051 return SHA256_HMAC_BLOCK_SIZE;
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2052 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2053
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2054 #if GLIB_CHECK_VERSION(2,16,0)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2055
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2056 static void
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2057 sha256_init(PurpleCipherContext *context, void *extra)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2058 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2059 purple_g_checksum_init(context, G_CHECKSUM_SHA256);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2060 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2061
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2062 static void
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2063 sha256_reset(PurpleCipherContext *context, void *extra)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2064 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2065 purple_g_checksum_reset(context, G_CHECKSUM_SHA256);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2066 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2067
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2068 static gboolean
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2069 sha256_digest(PurpleCipherContext *context, gsize in_len, guchar digest[20],
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2070 gsize *out_len)
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2071 {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2072 return purple_g_checksum_digest(context, G_CHECKSUM_SHA256, in_len,
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2073 digest, out_len);
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2074 }
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2075
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2076 static PurpleCipherOps SHA256Ops = {
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2077 NULL, /* Set Option */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2078 NULL, /* Get Option */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2079 sha256_init, /* init */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2080 sha256_reset, /* reset */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2081 purple_g_checksum_uninit, /* uninit */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2082 NULL, /* set iv */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2083 purple_g_checksum_append, /* append */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2084 sha256_digest, /* digest */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2085 NULL, /* encrypt */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2086 NULL, /* decrypt */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2087 NULL, /* set salt */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2088 NULL, /* get salt size */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2089 NULL, /* set key */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2090 NULL, /* get key size */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2091 NULL, /* set batch mode */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2092 NULL, /* get batch mode */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2093 sha256_get_block_size, /* get block size */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2094 NULL /* set key with len */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2095 };
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2096
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2097 #else /* GLIB_CHECK_VERSION(2,16,0) */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2098
27241
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2099 #define SHA256_ROTR(X,n) ((((X) >> (n)) | ((X) << (32-(n)))) & 0xFFFFFFFF)
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2100
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2101 static const guint32 sha256_K[64] =
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2102 {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2103 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2104 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2105 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2106 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2107 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2108 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2109 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2110 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2111 };
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2112
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2113 struct SHA256Context {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2114 guint32 H[8];
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2115 guint32 W[64];
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2116
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2117 gint lenW;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2118
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2119 guint32 sizeHi;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2120 guint32 sizeLo;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2121 };
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2122
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2123 static void
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2124 sha256_hash_block(struct SHA256Context *sha256_ctx) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2125 gint i;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2126 guint32 A, B, C, D, E, F, G, H, T1, T2;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2127
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2128 for(i = 16; i < 64; i++) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2129 sha256_ctx->W[i] =
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2130 (SHA256_ROTR(sha256_ctx->W[i-2], 17) ^ SHA256_ROTR(sha256_ctx->W[i-2], 19) ^ (sha256_ctx->W[i-2] >> 10))
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2131 + sha256_ctx->W[i-7]
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2132 + (SHA256_ROTR(sha256_ctx->W[i-15], 7) ^ SHA256_ROTR(sha256_ctx->W[i-15], 18) ^ (sha256_ctx->W[i-15] >> 3))
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2133 + sha256_ctx->W[i-16];
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2134 }
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2135
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2136 A = sha256_ctx->H[0];
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2137 B = sha256_ctx->H[1];
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2138 C = sha256_ctx->H[2];
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2139 D = sha256_ctx->H[3];
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2140 E = sha256_ctx->H[4];
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2141 F = sha256_ctx->H[5];
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2142 G = sha256_ctx->H[6];
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2143 H = sha256_ctx->H[7];
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2144
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2145 for(i = 0; i < 64; i++) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2146 T1 = H
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2147 + (SHA256_ROTR(E, 6) ^ SHA256_ROTR(E, 11) ^ SHA256_ROTR(E, 25))
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2148 + ((E & F) ^ ((~E) & G))
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2149 + sha256_K[i] + sha256_ctx->W[i];
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2150 T2 = (SHA256_ROTR(A, 2) ^ SHA256_ROTR(A, 13) ^ SHA256_ROTR(A, 22))
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2151 + ((A & B) ^ (A & C) ^ (B & C));
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2152 H = G;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2153 G = F;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2154 F = E;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2155 E = D + T1;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2156 D = C;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2157 C = B;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2158 B = A;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2159 A = T1 + T2;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2160 }
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2161
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2162 sha256_ctx->H[0] += A;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2163 sha256_ctx->H[1] += B;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2164 sha256_ctx->H[2] += C;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2165 sha256_ctx->H[3] += D;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2166 sha256_ctx->H[4] += E;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2167 sha256_ctx->H[5] += F;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2168 sha256_ctx->H[6] += G;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2169 sha256_ctx->H[7] += H;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2170 }
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2171
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2172 static void
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2173 sha256_set_opt(PurpleCipherContext *context, const gchar *name, void *value) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2174 struct SHA256Context *ctx;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2175
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2176 ctx = purple_cipher_context_get_data(context);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2177
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2178 if(!strcmp(name, "sizeHi")) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2179 ctx->sizeHi = GPOINTER_TO_INT(value);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2180 } else if(!strcmp(name, "sizeLo")) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2181 ctx->sizeLo = GPOINTER_TO_INT(value);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2182 } else if(!strcmp(name, "lenW")) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2183 ctx->lenW = GPOINTER_TO_INT(value);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2184 }
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2185 }
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2186
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2187 static void *
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2188 sha256_get_opt(PurpleCipherContext *context, const gchar *name) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2189 struct SHA256Context *ctx;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2190
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2191 ctx = purple_cipher_context_get_data(context);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2192
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2193 if(!strcmp(name, "sizeHi")) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2194 return GINT_TO_POINTER(ctx->sizeHi);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2195 } else if(!strcmp(name, "sizeLo")) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2196 return GINT_TO_POINTER(ctx->sizeLo);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2197 } else if(!strcmp(name, "lenW")) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2198 return GINT_TO_POINTER(ctx->lenW);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2199 }
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2200
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2201 return NULL;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2202 }
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2203
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2204 static void
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2205 sha256_init(PurpleCipherContext *context, void *extra) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2206 struct SHA256Context *sha256_ctx;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2207
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2208 sha256_ctx = g_new0(struct SHA256Context, 1);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2209
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2210 purple_cipher_context_set_data(context, sha256_ctx);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2211
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2212 purple_cipher_context_reset(context, extra);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2213 }
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2214
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2215 static void
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2216 sha256_reset(PurpleCipherContext *context, void *extra) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2217 struct SHA256Context *sha256_ctx;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2218 gint i;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2219
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2220 sha256_ctx = purple_cipher_context_get_data(context);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2221
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2222 g_return_if_fail(sha256_ctx);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2223
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2224 sha256_ctx->lenW = 0;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2225 sha256_ctx->sizeHi = 0;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2226 sha256_ctx->sizeLo = 0;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2227
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2228 sha256_ctx->H[0] = 0x6a09e667;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2229 sha256_ctx->H[1] = 0xbb67ae85;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2230 sha256_ctx->H[2] = 0x3c6ef372;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2231 sha256_ctx->H[3] = 0xa54ff53a;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2232 sha256_ctx->H[4] = 0x510e527f;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2233 sha256_ctx->H[5] = 0x9b05688c;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2234 sha256_ctx->H[6] = 0x1f83d9ab;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2235 sha256_ctx->H[7] = 0x5be0cd19;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2236
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2237 for(i = 0; i < 64; i++)
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2238 sha256_ctx->W[i] = 0;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2239 }
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2240
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2241 static void
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2242 sha256_uninit(PurpleCipherContext *context) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2243 struct SHA256Context *sha256_ctx;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2244
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2245 purple_cipher_context_reset(context, NULL);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2246
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2247 sha256_ctx = purple_cipher_context_get_data(context);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2248
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2249 memset(sha256_ctx, 0, sizeof(struct SHA256Context));
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2250
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2251 g_free(sha256_ctx);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2252 sha256_ctx = NULL;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2253 }
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2254
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2255
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2256 static void
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2257 sha256_append(PurpleCipherContext *context, const guchar *data, size_t len) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2258 struct SHA256Context *sha256_ctx;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2259 gint i;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2260
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2261 sha256_ctx = purple_cipher_context_get_data(context);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2262
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2263 g_return_if_fail(sha256_ctx);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2264
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2265 for(i = 0; i < len; i++) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2266 sha256_ctx->W[sha256_ctx->lenW / 4] <<= 8;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2267 sha256_ctx->W[sha256_ctx->lenW / 4] |= data[i];
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2268
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2269 if((++sha256_ctx->lenW) % 64 == 0) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2270 sha256_hash_block(sha256_ctx);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2271 sha256_ctx->lenW = 0;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2272 }
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2273
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2274 sha256_ctx->sizeLo += 8;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2275 sha256_ctx->sizeHi += (sha256_ctx->sizeLo < 8);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2276 }
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2277 }
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2278
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2279 static gboolean
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2280 sha256_digest(PurpleCipherContext *context, size_t in_len, guchar digest[32],
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2281 size_t *out_len)
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2282 {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2283 struct SHA256Context *sha256_ctx;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2284 guchar pad0x80 = 0x80, pad0x00 = 0x00;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2285 guchar padlen[8];
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2286 gint i;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2287
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2288 g_return_val_if_fail(in_len >= 32, FALSE);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2289
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2290 sha256_ctx = purple_cipher_context_get_data(context);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2291
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2292 g_return_val_if_fail(sha256_ctx, FALSE);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2293
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2294 padlen[0] = (guchar)((sha256_ctx->sizeHi >> 24) & 255);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2295 padlen[1] = (guchar)((sha256_ctx->sizeHi >> 16) & 255);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2296 padlen[2] = (guchar)((sha256_ctx->sizeHi >> 8) & 255);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2297 padlen[3] = (guchar)((sha256_ctx->sizeHi >> 0) & 255);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2298 padlen[4] = (guchar)((sha256_ctx->sizeLo >> 24) & 255);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2299 padlen[5] = (guchar)((sha256_ctx->sizeLo >> 16) & 255);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2300 padlen[6] = (guchar)((sha256_ctx->sizeLo >> 8) & 255);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2301 padlen[7] = (guchar)((sha256_ctx->sizeLo >> 0) & 255);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2302
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2303 /* pad with a 1, then zeroes, then length */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2304 purple_cipher_context_append(context, &pad0x80, 1);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2305 while(sha256_ctx->lenW != 56)
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2306 purple_cipher_context_append(context, &pad0x00, 1);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2307 purple_cipher_context_append(context, padlen, 8);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2308
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2309 for(i = 0; i < 32; i++) {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2310 digest[i] = (guchar)(sha256_ctx->H[i / 4] >> 24);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2311 sha256_ctx->H[i / 4] <<= 8;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2312 }
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2313
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2314 purple_cipher_context_reset(context, NULL);
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2315
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2316 if(out_len)
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2317 *out_len = 32;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2318
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2319 return TRUE;
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2320 }
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2321
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2322 static PurpleCipherOps SHA256Ops = {
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2323 sha256_set_opt, /* Set Option */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2324 sha256_get_opt, /* Get Option */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2325 sha256_init, /* init */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2326 sha256_reset, /* reset */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2327 sha256_uninit, /* uninit */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2328 NULL, /* set iv */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2329 sha256_append, /* append */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2330 sha256_digest, /* digest */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2331 NULL, /* encrypt */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2332 NULL, /* decrypt */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2333 NULL, /* set salt */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2334 NULL, /* get salt size */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2335 NULL, /* set key */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2336 NULL, /* get key size */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2337 NULL, /* set batch mode */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2338 NULL, /* get batch mode */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2339 sha256_get_block_size, /* get block size */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2340 NULL /* set key with len */
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2341 };
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2342
27390
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2343 #endif /* GLIB_CHECK_VERSION(2,16,0) */
fc5508709e74 Use glib's SHA1, SHA256, and MD5 implementations when available (glib 2.16)
Paul Aurich <paul@darkrain42.org>
parents: 27313
diff changeset
2344
27241
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2345 /*******************************************************************************
17008
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2346 * RC4
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2347 ******************************************************************************/
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2348
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2349 struct RC4Context {
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2350 guchar state[256];
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2351 guchar x;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2352 guchar y;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2353 gint key_len;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2354 };
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2355
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2356 static void
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2357 rc4_init(PurpleCipherContext *context, void *extra) {
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2358 struct RC4Context *rc4_ctx;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2359 rc4_ctx = g_new0(struct RC4Context, 1);
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2360 purple_cipher_context_set_data(context, rc4_ctx);
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2361 purple_cipher_context_reset(context, extra);
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2362 }
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2363
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2364
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2365 static void
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2366 rc4_reset(PurpleCipherContext *context, void *extra) {
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2367 struct RC4Context *rc4_ctx;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2368 guint i;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2369
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2370 rc4_ctx = purple_cipher_context_get_data(context);
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2371
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2372 g_return_if_fail(rc4_ctx);
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2373
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2374 for(i = 0; i < 256; i++)
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2375 rc4_ctx->state[i] = i;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2376 rc4_ctx->x = 0;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2377 rc4_ctx->y = 0;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2378
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2379 /* default is 5 bytes (40bit key) */
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2380 rc4_ctx->key_len = 5;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2381
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2382 }
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2383
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2384 static void
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2385 rc4_uninit(PurpleCipherContext *context) {
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2386 struct RC4Context *rc4_ctx;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2387
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2388 rc4_ctx = purple_cipher_context_get_data(context);
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2389 memset(rc4_ctx, 0, sizeof(rc4_ctx));
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2390
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2391 g_free(rc4_ctx);
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2392 rc4_ctx = NULL;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2393 }
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2394
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2395
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2396
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2397 static void
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2398 rc4_set_key (PurpleCipherContext *context, const guchar * key) {
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2399 struct RC4Context *ctx;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2400 guchar *state;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2401 guchar temp_swap;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2402 guchar x, y;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2403 guint i;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2404
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2405 ctx = purple_cipher_context_get_data(context);
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2406
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2407 x = 0;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2408 y = 0;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2409 state = &ctx->state[0];
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2410 for(i = 0; i < 256; i++)
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2411 {
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2412 y = (key[x] + state[i] + y) % 256;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2413 temp_swap = state[i];
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2414 state[i] = state[y];
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2415 state[y] = temp_swap;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2416 x = (x + 1) % ctx->key_len;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2417 }
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2418 }
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2419
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2420 static void
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2421 rc4_set_opt(PurpleCipherContext *context, const gchar *name, void *value) {
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2422 struct RC4Context *ctx;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2423
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2424 ctx = purple_cipher_context_get_data(context);
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2425
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 23600
diff changeset
2426 if(purple_strequal(name, "key_len")) {
17008
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2427 ctx->key_len = GPOINTER_TO_INT(value);
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2428 }
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2429 }
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2430
25415
584063555949 Remove trailing whitespace
Mark Doliner <mark@kingant.net>
parents: 25385
diff changeset
2431 static size_t
17008
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2432 rc4_get_key_size (PurpleCipherContext *context)
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2433 {
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2434 struct RC4Context *ctx;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2435
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2436 g_return_val_if_fail(context, -1);
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2437
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2438 ctx = purple_cipher_context_get_data(context);
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2439
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2440 g_return_val_if_fail(ctx, -1);
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2441
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2442 return ctx->key_len;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2443 }
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2444
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2445 static void *
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2446 rc4_get_opt(PurpleCipherContext *context, const gchar *name) {
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2447 struct RC4Context *ctx;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2448
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2449 ctx = purple_cipher_context_get_data(context);
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2450
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 23600
diff changeset
2451 if(purple_strequal(name, "key_len")) {
17008
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2452 return GINT_TO_POINTER(ctx->key_len);
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2453 }
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2454
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2455 return NULL;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2456 }
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2457
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2458 static gint
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2459 rc4_encrypt(PurpleCipherContext *context, const guchar data[],
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2460 size_t len, guchar output[], size_t *outlen) {
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2461 struct RC4Context *ctx;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2462 guchar temp_swap;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2463 guchar x, y, z;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2464 guchar *state;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2465 guint i;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2466
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2467 ctx = purple_cipher_context_get_data(context);
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2468
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2469 x = ctx->x;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2470 y = ctx->y;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2471 state = &ctx->state[0];
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2472
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2473 for(i = 0; i < len; i++)
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2474 {
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2475 x = (x + 1) % 256;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2476 y = (state[x] + y) % 256;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2477 temp_swap = state[x];
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2478 state[x] = state[y];
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2479 state[y] = temp_swap;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2480 z = state[x] + (state[y]) % 256;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2481 output[i] = data[i] ^ state[z];
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2482 }
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2483 ctx->x = x;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2484 ctx->y = y;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2485 if(outlen)
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2486 *outlen = len;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2487
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2488 return 0;
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2489 }
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2490
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2491 static PurpleCipherOps RC4Ops = {
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2492 rc4_set_opt, /* Set Option */
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2493 rc4_get_opt, /* Get Option */
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2494 rc4_init, /* init */
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2495 rc4_reset, /* reset */
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2496 rc4_uninit, /* uninit */
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2497 NULL, /* set iv */
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2498 NULL, /* append */
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2499 NULL, /* digest */
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2500 rc4_encrypt, /* encrypt */
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2501 NULL, /* decrypt */
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2502 NULL, /* set salt */
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2503 NULL, /* get salt size */
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2504 rc4_set_key, /* set key */
17027
ba8de77ec9b8 Add padding to the RC4Ops struct to fix a compiler warning.
Richard Laager <rlaager@wiktel.com>
parents: 17008
diff changeset
2505 rc4_get_key_size, /* get key size */
21907
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
2506 NULL, /* set batch mode */
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
2507 NULL, /* get batch mode */
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
2508 NULL, /* get block size */
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
2509 NULL /* set key with len */
17008
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2510 };
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2511
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2512 /*******************************************************************************
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2513 * Structs
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2514 ******************************************************************************/
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2515 struct _PurpleCipher {
17465
103a37dd9398 applied changes from b0f6005b1330af13bce0bcb189a2c887036b5ea3
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17095
diff changeset
2516 gchar *name; /**< Internal name - used for searching */
103a37dd9398 applied changes from b0f6005b1330af13bce0bcb189a2c887036b5ea3
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17095
diff changeset
2517 PurpleCipherOps *ops; /**< Operations supported by this cipher */
103a37dd9398 applied changes from b0f6005b1330af13bce0bcb189a2c887036b5ea3
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17095
diff changeset
2518 guint ref; /**< Reference count */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2519 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2520
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2521 struct _PurpleCipherContext {
17465
103a37dd9398 applied changes from b0f6005b1330af13bce0bcb189a2c887036b5ea3
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17095
diff changeset
2522 PurpleCipher *cipher; /**< Cipher this context is under */
103a37dd9398 applied changes from b0f6005b1330af13bce0bcb189a2c887036b5ea3
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17095
diff changeset
2523 gpointer data; /**< Internal cipher state data */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2524 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2525
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2526 /******************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2527 * Globals
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2528 *****************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2529 static GList *ciphers = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2530
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2531 /******************************************************************************
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2532 * PurpleCipher API
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2533 *****************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2534 const gchar *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2535 purple_cipher_get_name(PurpleCipher *cipher) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2536 g_return_val_if_fail(cipher, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2537
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2538 return cipher->name;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2539 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2540
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2541 guint
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2542 purple_cipher_get_capabilities(PurpleCipher *cipher) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2543 PurpleCipherOps *ops = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2544 guint caps = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2545
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2546 g_return_val_if_fail(cipher, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2547
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2548 ops = cipher->ops;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2549 g_return_val_if_fail(ops, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2550
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2551 if(ops->set_option)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2552 caps |= PURPLE_CIPHER_CAPS_SET_OPT;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2553 if(ops->get_option)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2554 caps |= PURPLE_CIPHER_CAPS_GET_OPT;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2555 if(ops->init)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2556 caps |= PURPLE_CIPHER_CAPS_INIT;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2557 if(ops->reset)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2558 caps |= PURPLE_CIPHER_CAPS_RESET;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2559 if(ops->uninit)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2560 caps |= PURPLE_CIPHER_CAPS_UNINIT;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2561 if(ops->set_iv)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2562 caps |= PURPLE_CIPHER_CAPS_SET_IV;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2563 if(ops->append)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2564 caps |= PURPLE_CIPHER_CAPS_APPEND;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2565 if(ops->digest)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2566 caps |= PURPLE_CIPHER_CAPS_DIGEST;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2567 if(ops->encrypt)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2568 caps |= PURPLE_CIPHER_CAPS_ENCRYPT;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2569 if(ops->decrypt)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2570 caps |= PURPLE_CIPHER_CAPS_DECRYPT;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2571 if(ops->set_salt)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2572 caps |= PURPLE_CIPHER_CAPS_SET_SALT;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2573 if(ops->get_salt_size)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2574 caps |= PURPLE_CIPHER_CAPS_GET_SALT_SIZE;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2575 if(ops->set_key)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2576 caps |= PURPLE_CIPHER_CAPS_SET_KEY;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2577 if(ops->get_key_size)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2578 caps |= PURPLE_CIPHER_CAPS_GET_KEY_SIZE;
21907
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
2579 if(ops->set_batch_mode)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
2580 caps |= PURPLE_CIPHER_CAPS_SET_BATCH_MODE;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
2581 if(ops->get_batch_mode)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
2582 caps |= PURPLE_CIPHER_CAPS_GET_BATCH_MODE;
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
2583 if(ops->get_block_size)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
2584 caps |= PURPLE_CIPHER_CAPS_GET_BLOCK_SIZE;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
2585 if(ops->set_key_with_len)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
2586 caps |= PURPLE_CIPHER_CAPS_SET_KEY_WITH_LEN;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2587
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2588 return caps;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2589 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2590
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2591 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2592 purple_cipher_digest_region(const gchar *name, const guchar *data,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2593 size_t data_len, size_t in_len,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2594 guchar digest[], size_t *out_len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2595 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2596 PurpleCipher *cipher;
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2597 PurpleCipherContext *context;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2598 gboolean ret = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2599
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2600 g_return_val_if_fail(name, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2601 g_return_val_if_fail(data, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2602
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2603 cipher = purple_ciphers_find_cipher(name);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2604
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2605 g_return_val_if_fail(cipher, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2606
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2607 if(!cipher->ops->append || !cipher->ops->digest) {
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27241
diff changeset
2608 purple_debug_warning("cipher", "purple_cipher_region failed: "
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2609 "the %s cipher does not support appending and or "
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2610 "digesting.", cipher->name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2611 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2612 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2613
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2614 context = purple_cipher_context_new(cipher, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2615 purple_cipher_context_append(context, data, data_len);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2616 ret = purple_cipher_context_digest(context, in_len, digest, out_len);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2617 purple_cipher_context_destroy(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2618
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2619 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2620 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2621
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2622 /******************************************************************************
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2623 * PurpleCiphers API
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2624 *****************************************************************************/
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2625 PurpleCipher *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2626 purple_ciphers_find_cipher(const gchar *name) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2627 PurpleCipher *cipher;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2628 GList *l;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2629
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2630 g_return_val_if_fail(name, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2631
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2632 for(l = ciphers; l; l = l->next) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2633 cipher = PURPLE_CIPHER(l->data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2634
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2635 if(!g_ascii_strcasecmp(cipher->name, name))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2636 return cipher;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2637 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2638
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2639 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2640 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2641
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2642 PurpleCipher *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2643 purple_ciphers_register_cipher(const gchar *name, PurpleCipherOps *ops) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2644 PurpleCipher *cipher = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2645
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2646 g_return_val_if_fail(name, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2647 g_return_val_if_fail(ops, NULL);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2648 g_return_val_if_fail(!purple_ciphers_find_cipher(name), NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2649
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2650 cipher = g_new0(PurpleCipher, 1);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2651 PURPLE_DBUS_REGISTER_POINTER(cipher, PurpleCipher);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2652
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2653 cipher->name = g_strdup(name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2654 cipher->ops = ops;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2655
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2656 ciphers = g_list_append(ciphers, cipher);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2657
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2658 purple_signal_emit(purple_ciphers_get_handle(), "cipher-added", cipher);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2659
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2660 return cipher;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2661 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2662
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2663 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2664 purple_ciphers_unregister_cipher(PurpleCipher *cipher) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2665 g_return_val_if_fail(cipher, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2666 g_return_val_if_fail(cipher->ref == 0, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2667
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2668 purple_signal_emit(purple_ciphers_get_handle(), "cipher-removed", cipher);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2669
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2670 ciphers = g_list_remove(ciphers, cipher);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2671
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2672 g_free(cipher->name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2673
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2674 PURPLE_DBUS_UNREGISTER_POINTER(cipher);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2675 g_free(cipher);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2676
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2677 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2678 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2679
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2680 GList *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2681 purple_ciphers_get_ciphers() {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2682 return ciphers;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2683 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2684
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2685 /******************************************************************************
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2686 * PurpleCipher Subsystem API
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2687 *****************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2688 gpointer
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2689 purple_ciphers_get_handle() {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2690 static gint handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2691
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2692 return &handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2693 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2694
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2695 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2696 purple_ciphers_init() {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2697 gpointer handle;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2698
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2699 handle = purple_ciphers_get_handle();
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2700
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2701 purple_signal_register(handle, "cipher-added",
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2702 purple_marshal_VOID__POINTER, NULL, 1,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2703 purple_value_new(PURPLE_TYPE_SUBTYPE,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2704 PURPLE_SUBTYPE_CIPHER));
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2705 purple_signal_register(handle, "cipher-removed",
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2706 purple_marshal_VOID__POINTER, NULL, 1,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2707 purple_value_new(PURPLE_TYPE_SUBTYPE,
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2708 PURPLE_SUBTYPE_CIPHER));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2709
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2710 purple_ciphers_register_cipher("md5", &MD5Ops);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2711 purple_ciphers_register_cipher("sha1", &SHA1Ops);
27241
8487bf2c306e An implementation of SHA-256. Created by copying libpurple's SHA-1
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2712 purple_ciphers_register_cipher("sha256", &SHA256Ops);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2713 purple_ciphers_register_cipher("md4", &MD4Ops);
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
2714 purple_ciphers_register_cipher("hmac", &HMACOps);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2715 purple_ciphers_register_cipher("des", &DESOps);
21907
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
2716 purple_ciphers_register_cipher("des3", &DES3Ops);
17008
34d9037a228c RC4 support to libpurple's cipher.c.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16676
diff changeset
2717 purple_ciphers_register_cipher("rc4", &RC4Ops);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2718 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2719
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2720 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2721 purple_ciphers_uninit() {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2722 PurpleCipher *cipher;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2723 GList *l, *ll;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2724
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2725 for(l = ciphers; l; l = ll) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2726 ll = l->next;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2727
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2728 cipher = PURPLE_CIPHER(l->data);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2729 purple_ciphers_unregister_cipher(cipher);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2730 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2731
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2732 g_list_free(ciphers);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2733
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2734 purple_signals_unregister_by_instance(purple_ciphers_get_handle());
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2735 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2736 /******************************************************************************
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2737 * PurpleCipherContext API
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2738 *****************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2739 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2740 purple_cipher_context_set_option(PurpleCipherContext *context, const gchar *name,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2741 gpointer value)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2742 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2743 PurpleCipher *cipher = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2744
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2745 g_return_if_fail(context);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2746 g_return_if_fail(name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2747
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2748 cipher = context->cipher;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2749 g_return_if_fail(cipher);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2750
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2751 if(cipher->ops && cipher->ops->set_option)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2752 cipher->ops->set_option(context, name, value);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2753 else
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27241
diff changeset
2754 purple_debug_warning("cipher", "the %s cipher does not support the "
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2755 "set_option operation\n", cipher->name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2756 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2757
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2758 gpointer
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2759 purple_cipher_context_get_option(PurpleCipherContext *context, const gchar *name) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2760 PurpleCipher *cipher = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2761
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2762 g_return_val_if_fail(context, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2763 g_return_val_if_fail(name, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2764
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2765 cipher = context->cipher;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2766 g_return_val_if_fail(cipher, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2767
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2768 if(cipher->ops && cipher->ops->get_option)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2769 return cipher->ops->get_option(context, name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2770 else {
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27241
diff changeset
2771 purple_debug_warning("cipher", "the %s cipher does not support the "
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2772 "get_option operation\n", cipher->name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2773
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2774 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2775 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2776 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2777
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2778 PurpleCipherContext *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2779 purple_cipher_context_new(PurpleCipher *cipher, void *extra) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2780 PurpleCipherContext *context = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2781
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2782 g_return_val_if_fail(cipher, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2783
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2784 cipher->ref++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2785
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2786 context = g_new0(PurpleCipherContext, 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2787 context->cipher = cipher;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2788
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2789 if(cipher->ops->init)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2790 cipher->ops->init(context, extra);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2791
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2792 return context;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2793 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2794
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2795 PurpleCipherContext *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2796 purple_cipher_context_new_by_name(const gchar *name, void *extra) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2797 PurpleCipher *cipher;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2798
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2799 g_return_val_if_fail(name, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2800
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2801 cipher = purple_ciphers_find_cipher(name);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2802
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2803 g_return_val_if_fail(cipher, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2804
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2805 return purple_cipher_context_new(cipher, extra);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2806 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2807
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2808 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2809 purple_cipher_context_reset(PurpleCipherContext *context, void *extra) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2810 PurpleCipher *cipher = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2811
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2812 g_return_if_fail(context);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2813
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2814 cipher = context->cipher;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2815 g_return_if_fail(cipher);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2816
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2817 if(cipher->ops && cipher->ops->reset)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2818 context->cipher->ops->reset(context, extra);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2819 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2820
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2821 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2822 purple_cipher_context_destroy(PurpleCipherContext *context) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2823 PurpleCipher *cipher = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2824
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2825 g_return_if_fail(context);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2826
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2827 cipher = context->cipher;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2828 g_return_if_fail(cipher);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2829
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2830 cipher->ref--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2831
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2832 if(cipher->ops && cipher->ops->uninit)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2833 cipher->ops->uninit(context);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2834
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2835 memset(context, 0, sizeof(context));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2836 g_free(context);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2837 context = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2838 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2839
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2840 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2841 purple_cipher_context_set_iv(PurpleCipherContext *context, guchar *iv, size_t len)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2842 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2843 PurpleCipher *cipher = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2844
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2845 g_return_if_fail(context);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2846 g_return_if_fail(iv);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2847
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2848 cipher = context->cipher;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2849 g_return_if_fail(cipher);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2850
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2851 if(cipher->ops && cipher->ops->set_iv)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2852 cipher->ops->set_iv(context, iv, len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2853 else
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27241
diff changeset
2854 purple_debug_warning("cipher", "the %s cipher does not support the set"
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2855 "initialization vector operation\n", cipher->name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2856 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2857
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2858 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2859 purple_cipher_context_append(PurpleCipherContext *context, const guchar *data,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2860 size_t len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2861 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2862 PurpleCipher *cipher = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2863
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2864 g_return_if_fail(context);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2865
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2866 cipher = context->cipher;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2867 g_return_if_fail(cipher);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2868
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2869 if(cipher->ops && cipher->ops->append)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2870 cipher->ops->append(context, data, len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2871 else
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27241
diff changeset
2872 purple_debug_warning("cipher", "the %s cipher does not support the append "
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2873 "operation\n", cipher->name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2874 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2875
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2876 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2877 purple_cipher_context_digest(PurpleCipherContext *context, size_t in_len,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2878 guchar digest[], size_t *out_len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2879 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2880 PurpleCipher *cipher = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2881
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2882 g_return_val_if_fail(context, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2883
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2884 cipher = context->cipher;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2885
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2886 if(cipher->ops && cipher->ops->digest)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2887 return cipher->ops->digest(context, in_len, digest, out_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2888 else {
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27241
diff changeset
2889 purple_debug_warning("cipher", "the %s cipher does not support the digest "
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2890 "operation\n", cipher->name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2891 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2892 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2893 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2894
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2895 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2896 purple_cipher_context_digest_to_str(PurpleCipherContext *context, size_t in_len,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2897 gchar digest_s[], size_t *out_len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2898 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2899 /* 8k is a bit excessive, will tweak later. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2900 guchar digest[BUF_LEN * 4];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2901 gint n = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2902 size_t dlen = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2903
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2904 g_return_val_if_fail(context, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2905 g_return_val_if_fail(digest_s, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2906
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2907 if(!purple_cipher_context_digest(context, sizeof(digest), digest, &dlen))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2908 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2909
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2910 /* in_len must be greater than dlen * 2 so we have room for the NUL. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2911 if(in_len <= dlen * 2)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2912 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2913
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2914 for(n = 0; n < dlen; n++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2915 sprintf(digest_s + (n * 2), "%02x", digest[n]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2916
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2917 digest_s[n * 2] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2918
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2919 if(out_len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2920 *out_len = dlen * 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2921
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2922 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2923 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2924
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2925 gint
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2926 purple_cipher_context_encrypt(PurpleCipherContext *context, const guchar data[],
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2927 size_t len, guchar output[], size_t *outlen)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2928 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2929 PurpleCipher *cipher = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2930
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2931 g_return_val_if_fail(context, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2932
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2933 cipher = context->cipher;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2934 g_return_val_if_fail(cipher, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2935
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2936 if(cipher->ops && cipher->ops->encrypt)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2937 return cipher->ops->encrypt(context, data, len, output, outlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2938 else {
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27241
diff changeset
2939 purple_debug_warning("cipher", "the %s cipher does not support the encrypt"
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2940 "operation\n", cipher->name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2941
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2942 if(outlen)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2943 *outlen = -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2944
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2945 return -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2946 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2947 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2948
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2949 gint
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2950 purple_cipher_context_decrypt(PurpleCipherContext *context, const guchar data[],
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2951 size_t len, guchar output[], size_t *outlen)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2952 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2953 PurpleCipher *cipher = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2954
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2955 g_return_val_if_fail(context, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2956
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2957 cipher = context->cipher;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2958 g_return_val_if_fail(cipher, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2959
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2960 if(cipher->ops && cipher->ops->decrypt)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2961 return cipher->ops->decrypt(context, data, len, output, outlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2962 else {
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27241
diff changeset
2963 purple_debug_warning("cipher", "the %s cipher does not support the decrypt"
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2964 "operation\n", cipher->name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2965
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2966 if(outlen)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2967 *outlen = -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2968
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2969 return -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2970 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2971 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2972
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2973 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2974 purple_cipher_context_set_salt(PurpleCipherContext *context, guchar *salt) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2975 PurpleCipher *cipher = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2976
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2977 g_return_if_fail(context);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2978
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2979 cipher = context->cipher;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2980 g_return_if_fail(cipher);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2981
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2982 if(cipher->ops && cipher->ops->set_salt)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2983 cipher->ops->set_salt(context, salt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2984 else
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27241
diff changeset
2985 purple_debug_warning("cipher", "the %s cipher does not support the "
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2986 "set_salt operation\n", cipher->name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2987 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2988
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2989 size_t
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2990 purple_cipher_context_get_salt_size(PurpleCipherContext *context) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
2991 PurpleCipher *cipher = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2992
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2993 g_return_val_if_fail(context, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2994
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2995 cipher = context->cipher;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2996 g_return_val_if_fail(cipher, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2997
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2998 if(cipher->ops && cipher->ops->get_salt_size)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2999 return cipher->ops->get_salt_size(context);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3000 else {
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27241
diff changeset
3001 purple_debug_warning("cipher", "the %s cipher does not support the "
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3002 "get_salt_size operation\n", cipher->name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3003
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3004 return -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3005 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3006 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3007
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3008 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3009 purple_cipher_context_set_key(PurpleCipherContext *context, const guchar *key) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3010 PurpleCipher *cipher = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3011
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3012 g_return_if_fail(context);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3013
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3014 cipher = context->cipher;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3015 g_return_if_fail(cipher);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3016
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3017 if(cipher->ops && cipher->ops->set_key)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3018 cipher->ops->set_key(context, key);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3019 else
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27241
diff changeset
3020 purple_debug_warning("cipher", "the %s cipher does not support the "
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3021 "set_key operation\n", cipher->name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3022 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3023
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3024 size_t
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3025 purple_cipher_context_get_key_size(PurpleCipherContext *context) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3026 PurpleCipher *cipher = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3027
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3028 g_return_val_if_fail(context, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3029
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3030 cipher = context->cipher;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3031 g_return_val_if_fail(cipher, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3032
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3033 if(cipher->ops && cipher->ops->get_key_size)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3034 return cipher->ops->get_key_size(context);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3035 else {
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27241
diff changeset
3036 purple_debug_warning("cipher", "the %s cipher does not support the "
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3037 "get_key_size operation\n", cipher->name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3038
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3039 return -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3040 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3041 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3042
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3043 void
21907
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3044 purple_cipher_context_set_batch_mode(PurpleCipherContext *context,
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3045 PurpleCipherBatchMode mode)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3046 {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3047 PurpleCipher *cipher = NULL;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3048
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3049 g_return_if_fail(context);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3050
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3051 cipher = context->cipher;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3052 g_return_if_fail(cipher);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3053
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3054 if(cipher->ops && cipher->ops->set_batch_mode)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3055 cipher->ops->set_batch_mode(context, mode);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3056 else
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27241
diff changeset
3057 purple_debug_warning("cipher", "The %s cipher does not support the "
21907
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3058 "set_batch_mode operation\n", cipher->name);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3059 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3060
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3061 PurpleCipherBatchMode
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3062 purple_cipher_context_get_batch_mode(PurpleCipherContext *context)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3063 {
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3064 PurpleCipher *cipher = NULL;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3065
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3066 g_return_val_if_fail(context, -1);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3067
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3068 cipher = context->cipher;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3069 g_return_val_if_fail(cipher, -1);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3070
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3071 if(cipher->ops && cipher->ops->get_batch_mode)
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3072 return cipher->ops->get_batch_mode(context);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3073 else {
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27241
diff changeset
3074 purple_debug_warning("cipher", "The %s cipher does not support the "
21907
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3075 "get_batch_mode operation\n", cipher->name);
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3076 return -1;
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3077 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3078 }
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3079
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3080 size_t
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3081 purple_cipher_context_get_block_size(PurpleCipherContext *context)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3082 {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3083 PurpleCipher *cipher = NULL;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3084
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3085 g_return_val_if_fail(context, -1);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3086
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3087 cipher = context->cipher;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3088 g_return_val_if_fail(cipher, -1);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3089
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3090 if(cipher->ops && cipher->ops->get_block_size)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3091 return cipher->ops->get_block_size(context);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3092 else {
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27241
diff changeset
3093 purple_debug_warning("cipher", "The %s cipher does not support the "
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3094 "get_block_size operation\n", cipher->name);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3095 return -1;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3096 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3097 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3098
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3099 void
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3100 purple_cipher_context_set_key_with_len(PurpleCipherContext *context,
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3101 const guchar *key, size_t len)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3102 {
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3103 PurpleCipher *cipher = NULL;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3104
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3105 g_return_if_fail(context);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3106
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3107 cipher = context->cipher;
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3108 g_return_if_fail(cipher);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3109
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3110 if(cipher->ops && cipher->ops->set_key_with_len)
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3111 cipher->ops->set_key_with_len(context, key, len);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3112 else
27313
627d23bfdb05 Increase the logging level of some debugging messages that seemed to be a
mauro.brasil@tqi.com.br
parents: 27241
diff changeset
3113 purple_debug_warning("cipher", "The %s cipher does not support the "
21908
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3114 "set_key_with_len operation\n", cipher->name);
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3115 }
f786e478e08b HMAC digest support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21907
diff changeset
3116
21907
03463c52b9d7 Triple DES cipher support from Elliott Sales de Andrade
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 21015
diff changeset
3117 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3118 purple_cipher_context_set_data(PurpleCipherContext *context, gpointer data) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3119 g_return_if_fail(context);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3120
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3121 context->data = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3122 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3123
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3124 gpointer
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3125 purple_cipher_context_get_data(PurpleCipherContext *context) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3126 g_return_val_if_fail(context, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3127
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3128 return context->data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3129 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3130
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3131 gchar *purple_cipher_http_digest_calculate_session_key(
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3132 const gchar *algorithm,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3133 const gchar *username,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3134 const gchar *realm,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3135 const gchar *password,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3136 const gchar *nonce,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3137 const gchar *client_nonce)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3138 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3139 PurpleCipher *cipher;
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3140 PurpleCipherContext *context;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3141 gchar hash[33]; /* We only support MD5. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3142
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3143 g_return_val_if_fail(username != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3144 g_return_val_if_fail(realm != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3145 g_return_val_if_fail(password != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3146 g_return_val_if_fail(nonce != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3147
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3148 /* Check for a supported algorithm. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3149 g_return_val_if_fail(algorithm == NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3150 *algorithm == '\0' ||
17095
7ade887fd3f6 Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@wiktel.com>
parents: 17027
diff changeset
3151 g_ascii_strcasecmp(algorithm, "MD5") ||
7ade887fd3f6 Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@wiktel.com>
parents: 17027
diff changeset
3152 g_ascii_strcasecmp(algorithm, "MD5-sess"), NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3153
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3154 cipher = purple_ciphers_find_cipher("md5");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3155 g_return_val_if_fail(cipher != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3156
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3157 context = purple_cipher_context_new(cipher, NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3158
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3159 purple_cipher_context_append(context, (guchar *)username, strlen(username));
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3160 purple_cipher_context_append(context, (guchar *)":", 1);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3161 purple_cipher_context_append(context, (guchar *)realm, strlen(realm));
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3162 purple_cipher_context_append(context, (guchar *)":", 1);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3163 purple_cipher_context_append(context, (guchar *)password, strlen(password));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3164
17095
7ade887fd3f6 Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@wiktel.com>
parents: 17027
diff changeset
3165 if (algorithm != NULL && !g_ascii_strcasecmp(algorithm, "MD5-sess"))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3166 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3167 guchar digest[16];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3168
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3169 if (client_nonce == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3170 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3171 purple_cipher_context_destroy(context);
19653
941965d6fd88 Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17465
diff changeset
3172 purple_debug_error("cipher", "Required client_nonce missing for MD5-sess digest calculation.\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3173 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3174 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3175
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3176 purple_cipher_context_digest(context, sizeof(digest), digest, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3177 purple_cipher_context_destroy(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3178
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3179 context = purple_cipher_context_new(cipher, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3180 purple_cipher_context_append(context, digest, sizeof(digest));
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3181 purple_cipher_context_append(context, (guchar *)":", 1);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3182 purple_cipher_context_append(context, (guchar *)nonce, strlen(nonce));
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3183 purple_cipher_context_append(context, (guchar *)":", 1);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3184 purple_cipher_context_append(context, (guchar *)client_nonce, strlen(client_nonce));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3185 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3186
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3187 purple_cipher_context_digest_to_str(context, sizeof(hash), hash, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3188 purple_cipher_context_destroy(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3189
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3190 return g_strdup(hash);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3191 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3192
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3193 gchar *purple_cipher_http_digest_calculate_response(
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3194 const gchar *algorithm,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3195 const gchar *method,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3196 const gchar *digest_uri,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3197 const gchar *qop,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3198 const gchar *entity,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3199 const gchar *nonce,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3200 const gchar *nonce_count,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3201 const gchar *client_nonce,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3202 const gchar *session_key)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3203 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3204 PurpleCipher *cipher;
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3205 PurpleCipherContext *context;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3206 static gchar hash2[33]; /* We only support MD5. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3207
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3208 g_return_val_if_fail(method != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3209 g_return_val_if_fail(digest_uri != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3210 g_return_val_if_fail(nonce != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3211 g_return_val_if_fail(session_key != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3212
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3213 /* Check for a supported algorithm. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3214 g_return_val_if_fail(algorithm == NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3215 *algorithm == '\0' ||
17095
7ade887fd3f6 Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@wiktel.com>
parents: 17027
diff changeset
3216 g_ascii_strcasecmp(algorithm, "MD5") ||
7ade887fd3f6 Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@wiktel.com>
parents: 17027
diff changeset
3217 g_ascii_strcasecmp(algorithm, "MD5-sess"), NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3218
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3219 /* Check for a supported "quality of protection". */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3220 g_return_val_if_fail(qop == NULL ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3221 *qop == '\0' ||
17095
7ade887fd3f6 Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@wiktel.com>
parents: 17027
diff changeset
3222 g_ascii_strcasecmp(qop, "auth") ||
7ade887fd3f6 Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@wiktel.com>
parents: 17027
diff changeset
3223 g_ascii_strcasecmp(qop, "auth-int"), NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3224
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3225 cipher = purple_ciphers_find_cipher("md5");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3226 g_return_val_if_fail(cipher != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3227
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3228 context = purple_cipher_context_new(cipher, NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3229
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3230 purple_cipher_context_append(context, (guchar *)method, strlen(method));
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3231 purple_cipher_context_append(context, (guchar *)":", 1);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3232 purple_cipher_context_append(context, (guchar *)digest_uri, strlen(digest_uri));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3233
17095
7ade887fd3f6 Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@wiktel.com>
parents: 17027
diff changeset
3234 if (qop != NULL && !g_ascii_strcasecmp(qop, "auth-int"))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3235 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3236 PurpleCipherContext *context2;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3237 gchar entity_hash[33];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3238
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3239 if (entity == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3240 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3241 purple_cipher_context_destroy(context);
19653
941965d6fd88 Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17465
diff changeset
3242 purple_debug_error("cipher", "Required entity missing for auth-int digest calculation.\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3243 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3244 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3245
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3246 context2 = purple_cipher_context_new(cipher, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3247 purple_cipher_context_append(context2, (guchar *)entity, strlen(entity));
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3248 purple_cipher_context_digest_to_str(context2, sizeof(entity_hash), entity_hash, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3249 purple_cipher_context_destroy(context2);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3250
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3251 purple_cipher_context_append(context, (guchar *)":", 1);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3252 purple_cipher_context_append(context, (guchar *)entity_hash, strlen(entity_hash));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3253 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3254
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3255 purple_cipher_context_digest_to_str(context, sizeof(hash2), hash2, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3256 purple_cipher_context_destroy(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3257
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3258 context = purple_cipher_context_new(cipher, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3259 purple_cipher_context_append(context, (guchar *)session_key, strlen(session_key));
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3260 purple_cipher_context_append(context, (guchar *)":", 1);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3261 purple_cipher_context_append(context, (guchar *)nonce, strlen(nonce));
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3262 purple_cipher_context_append(context, (guchar *)":", 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3263
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3264 if (qop != NULL && *qop != '\0')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3265 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3266 if (nonce_count == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3267 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3268 purple_cipher_context_destroy(context);
19653
941965d6fd88 Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17465
diff changeset
3269 purple_debug_error("cipher", "Required nonce_count missing for digest calculation.\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3270 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3271 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3272
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3273 if (client_nonce == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3274 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3275 purple_cipher_context_destroy(context);
19653
941965d6fd88 Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17465
diff changeset
3276 purple_debug_error("cipher", "Required client_nonce missing for digest calculation.\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3277 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3278 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3279
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3280 purple_cipher_context_append(context, (guchar *)nonce_count, strlen(nonce_count));
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3281 purple_cipher_context_append(context, (guchar *)":", 1);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3282 purple_cipher_context_append(context, (guchar *)client_nonce, strlen(client_nonce));
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3283 purple_cipher_context_append(context, (guchar *)":", 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3284
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3285 purple_cipher_context_append(context, (guchar *)qop, strlen(qop));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3286
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3287 purple_cipher_context_append(context, (guchar *)":", 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3288 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3289
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3290 purple_cipher_context_append(context, (guchar *)hash2, strlen(hash2));
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3291 purple_cipher_context_digest_to_str(context, sizeof(hash2), hash2, NULL);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15374
diff changeset
3292 purple_cipher_context_destroy(context);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3293
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3294 return g_strdup(hash2);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3295 }