annotate src/cipher.c @ 13767:61a6fe79ba15

[gaim-migrate @ 16179] Fix Registry key leakage. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Fri, 12 May 2006 02:50:23 +0000
parents ff94569010f5
children 8bda65b88e49
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1 /*
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
2 * gaim
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
3 *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
4 * Gaim is the legal property of its developers, whose names are too numerous
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
6 * source distribution.
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
7 *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
8 * Original md5
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
9 * Copyright (C) 2001-2003 Christophe Devine <c.devine@cr0.net>
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
10 *
11329
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
11 * Original md4 taken from linux kernel
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
12 * MD4 Message Digest Algorithm (RFC1320).
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
13 *
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
14 * Implementation derived from Andrew Tridgell and Steve French's
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
15 * CIFS MD4 implementation, and the cryptoapi implementation
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
16 * originally based on the public domain implementation written
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
17 * by Colin Plumb in 1993.
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
18 *
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
19 * Copyright (c) Andrew Tridgell 1997-1998.
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
20 * Modified by Steve French (sfrench@us.ibm.com) 2002
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
21 * Copyright (c) Cryptoapi developers.
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
22 * Copyright (c) 2002 David S. Miller (davem@redhat.com)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
23 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
24 *
11335
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
25 * Original des taken from gpg
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
26 *
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
27 * des.c - DES and Triple-DES encryption/decryption Algorithm
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
28 * Copyright (C) 1998 Free Software Foundation, Inc.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
29 *
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
30 * Please see below for more legal information!
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
31 *
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
32 * According to the definition of DES in FIPS PUB 46-2 from December 1993.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
33 * For a description of triple encryption, see:
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
34 * Bruce Schneier: Applied Cryptography. Second Edition.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
35 * John Wiley & Sons, 1996. ISBN 0-471-12845-7. Pages 358 ff.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
36 *
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
37 * This file is part of GnuPG.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
38 *
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
39 * This program is free software; you can redistribute it and/or modify
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
40 * it under the terms of the GNU General Public License as published by
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
41 * the Free Software Foundation; either version 2 of the License, or
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
42 * (at your option) any later version.
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
43 *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
44 * This program is distributed in the hope that it will be useful,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
45 * but WITHOUT ANY WARRANTY; without even the implied warranty of
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
47 * GNU General Public License for more details.
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
48 *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
49 * You should have received a copy of the GNU General Public License
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
50 * along with this program; if not, write to the Free Software
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
51 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
52 */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
53 #include <glib.h>
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
54 #include <string.h>
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
55 #include <stdio.h>
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
56
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
57 #include "internal.h"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
58 #include "cipher.h"
13758
ff94569010f5 [gaim-migrate @ 16169]
Mark Doliner <mark@kingant.net>
parents: 13697
diff changeset
59 #include "dbus-maybe.h"
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
60 #include "debug.h"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
61 #include "signals.h"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
62 #include "value.h"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
63
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
64 /*******************************************************************************
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
65 * MD5
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
66 ******************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
67 struct MD5Context {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
68 guint32 total[2];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
69 guint32 state[4];
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
70 guchar buffer[64];
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
71 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
72
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
73 #define MD5_GET_GUINT32(n,b,i) { \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
74 (n) = ((guint32)(b) [(i) ] ) \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
75 | ((guint32)(b) [(i) + 1] << 8) \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
76 | ((guint32)(b) [(i) + 2] << 16) \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
77 | ((guint32)(b) [(i) + 3] << 24); \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
78 }
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
79 #define MD5_PUT_GUINT32(n,b,i) { \
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
80 (b)[(i) ] = (guchar)((n) ); \
13218
c01aa6ea4947 [gaim-migrate @ 15582]
Richard Laager <rlaager@wiktel.com>
parents: 12389
diff changeset
81 (b)[(i) + 1] = (guchar)((n) >> 8); \
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
82 (b)[(i) + 2] = (guchar)((n) >> 16); \
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
83 (b)[(i) + 3] = (guchar)((n) >> 24); \
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
84 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
85
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
86 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
87 md5_init(GaimCipherContext *context, gpointer extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
88 struct MD5Context *md5_context;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
89
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
90 md5_context = g_new0(struct MD5Context, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
91
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
92 gaim_cipher_context_set_data(context, md5_context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
93
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
94 gaim_cipher_context_reset(context, extra);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
95 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
96
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
97 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
98 md5_reset(GaimCipherContext *context, gpointer extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
99 struct MD5Context *md5_context;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
100
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
101 md5_context = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
102
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
103 md5_context->total[0] = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
104 md5_context->total[1] = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
105
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
106 md5_context->state[0] = 0x67452301;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
107 md5_context->state[1] = 0xEFCDAB89;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
108 md5_context->state[2] = 0x98BADCFE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
109 md5_context->state[3] = 0x10325476;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
110
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
111 memset(md5_context->buffer, 0, sizeof(md5_context->buffer));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
112 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
113
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
114 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
115 md5_uninit(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
116 struct MD5Context *md5_context;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
117
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
118 gaim_cipher_context_reset(context, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
119
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
120 md5_context = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
121 memset(md5_context, 0, sizeof(md5_context));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
122
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
123 g_free(md5_context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
124 md5_context = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
125 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
126
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
127 static void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
128 md5_process(struct MD5Context *md5_context, const guchar data[64]) {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
129 guint32 X[16], A, B, C, D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
130
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
131 A = md5_context->state[0];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
132 B = md5_context->state[1];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
133 C = md5_context->state[2];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
134 D = md5_context->state[3];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
135
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
136 MD5_GET_GUINT32(X[ 0], data, 0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
137 MD5_GET_GUINT32(X[ 1], data, 4);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
138 MD5_GET_GUINT32(X[ 2], data, 8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
139 MD5_GET_GUINT32(X[ 3], data, 12);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
140 MD5_GET_GUINT32(X[ 4], data, 16);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
141 MD5_GET_GUINT32(X[ 5], data, 20);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
142 MD5_GET_GUINT32(X[ 6], data, 24);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
143 MD5_GET_GUINT32(X[ 7], data, 28);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
144 MD5_GET_GUINT32(X[ 8], data, 32);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
145 MD5_GET_GUINT32(X[ 9], data, 36);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
146 MD5_GET_GUINT32(X[10], data, 40);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
147 MD5_GET_GUINT32(X[11], data, 44);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
148 MD5_GET_GUINT32(X[12], data, 48);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
149 MD5_GET_GUINT32(X[13], data, 52);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
150 MD5_GET_GUINT32(X[14], data, 56);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
151 MD5_GET_GUINT32(X[15], data, 60);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
152
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
153 #define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
154 #define P(a,b,c,d,k,s,t) { \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
155 a += F(b,c,d) + X[k] + t; \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
156 a = S(a,s) + b; \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
157 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
158
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
159 /* first pass */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
160 #define F(x,y,z) (z ^ (x & (y ^ z)))
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
161 P(A, B, C, D, 0, 7, 0xD76AA478);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
162 P(D, A, B, C, 1, 12, 0xE8C7B756);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
163 P(C, D, A, B, 2, 17, 0x242070DB);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
164 P(B, C, D, A, 3, 22, 0xC1BDCEEE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
165 P(A, B, C, D, 4, 7, 0xF57C0FAF);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
166 P(D, A, B, C, 5, 12, 0x4787C62A);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
167 P(C, D, A, B, 6, 17, 0xA8304613);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
168 P(B, C, D, A, 7, 22, 0xFD469501);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
169 P(A, B, C, D, 8, 7, 0x698098D8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
170 P(D, A, B, C, 9, 12, 0x8B44F7AF);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
171 P(C, D, A, B, 10, 17, 0xFFFF5BB1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
172 P(B, C, D, A, 11, 22, 0x895CD7BE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
173 P(A, B, C, D, 12, 7, 0x6B901122);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
174 P(D, A, B, C, 13, 12, 0xFD987193);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
175 P(C, D, A, B, 14, 17, 0xA679438E);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
176 P(B, C, D, A, 15, 22, 0x49B40821);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
177 #undef F
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
178
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
179 /* second pass */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
180 #define F(x,y,z) (y ^ (z & (x ^ y)))
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
181 P(A, B, C, D, 1, 5, 0xF61E2562);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
182 P(D, A, B, C, 6, 9, 0xC040B340);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
183 P(C, D, A, B, 11, 14, 0x265E5A51);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
184 P(B, C, D, A, 0, 20, 0xE9B6C7AA);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
185 P(A, B, C, D, 5, 5, 0xD62F105D);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
186 P(D, A, B, C, 10, 9, 0x02441453);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
187 P(C, D, A, B, 15, 14, 0xD8A1E681);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
188 P(B, C, D, A, 4, 20, 0xE7D3FBC8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
189 P(A, B, C, D, 9, 5, 0x21E1CDE6);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
190 P(D, A, B, C, 14, 9, 0xC33707D6);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
191 P(C, D, A, B, 3, 14, 0xF4D50D87);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
192 P(B, C, D, A, 8, 20, 0x455A14ED);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
193 P(A, B, C, D, 13, 5, 0xA9E3E905);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
194 P(D, A, B, C, 2, 9, 0xFCEFA3F8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
195 P(C, D, A, B, 7, 14, 0x676F02D9);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
196 P(B, C, D, A, 12, 20, 0x8D2A4C8A);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
197 #undef F
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
198
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
199 /* third pass */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
200 #define F(x,y,z) (x ^ y ^ z)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
201 P(A, B, C, D, 5, 4, 0xFFFA3942);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
202 P(D, A, B, C, 8, 11, 0x8771F681);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
203 P(C, D, A, B, 11, 16, 0x6D9D6122);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
204 P(B, C, D, A, 14, 23, 0xFDE5380C);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
205 P(A, B, C, D, 1, 4, 0xA4BEEA44);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
206 P(D, A, B, C, 4, 11, 0x4BDECFA9);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
207 P(C, D, A, B, 7, 16, 0xF6BB4B60);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
208 P(B, C, D, A, 10, 23, 0xBEBFBC70);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
209 P(A, B, C, D, 13, 4, 0x289B7EC6);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
210 P(D, A, B, C, 0, 11, 0xEAA127FA);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
211 P(C, D, A, B, 3, 16, 0xD4EF3085);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
212 P(B, C, D, A, 6, 23, 0x04881D05);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
213 P(A, B, C, D, 9, 4, 0xD9D4D039);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
214 P(D, A, B, C, 12, 11, 0xE6DB99E5);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
215 P(C, D, A, B, 15, 16, 0x1FA27CF8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
216 P(B, C, D, A, 2, 23, 0xC4AC5665);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
217 #undef F
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
218
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
219 /* forth pass */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
220 #define F(x,y,z) (y ^ (x | ~z))
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
221 P(A, B, C, D, 0, 6, 0xF4292244);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
222 P(D, A, B, C, 7, 10, 0x432AFF97);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
223 P(C, D, A, B, 14, 15, 0xAB9423A7);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
224 P(B, C, D, A, 5, 21, 0xFC93A039);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
225 P(A, B, C, D, 12, 6, 0x655B59C3);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
226 P(D, A, B, C, 3, 10, 0x8F0CCC92);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
227 P(C, D, A, B, 10, 15, 0xFFEFF47D);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
228 P(B, C, D, A, 1, 21, 0x85845DD1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
229 P(A, B, C, D, 8, 6, 0x6FA87E4F);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
230 P(D, A, B, C, 15, 10, 0xFE2CE6E0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
231 P(C, D, A, B, 6, 15, 0xA3014314);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
232 P(B, C, D, A, 13, 21, 0x4E0811A1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
233 P(A, B, C, D, 4, 6, 0xF7537E82);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
234 P(D, A, B, C, 11, 10, 0xBD3AF235);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
235 P(C, D, A, B, 2, 15, 0x2AD7D2BB);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
236 P(B, C, D, A, 9, 21, 0xEB86D391);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
237 #undef F
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
238 #undef P
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
239 #undef S
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
240
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
241 md5_context->state[0] += A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
242 md5_context->state[1] += B;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
243 md5_context->state[2] += C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
244 md5_context->state[3] += D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
245 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
246
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
247 static void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
248 md5_append(GaimCipherContext *context, const guchar *data, size_t len) {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
249 struct MD5Context *md5_context = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
250 guint32 left = 0, fill = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
251
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
252 g_return_if_fail(context != NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
253
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
254 md5_context = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
255 g_return_if_fail(md5_context != NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
256
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
257 left = md5_context->total[0] & 0x3F;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
258 fill = 64 - left;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
259
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
260 md5_context->total[0] += len;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
261 md5_context->total[0] &= 0xFFFFFFFF;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
262
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
263 if(md5_context->total[0] < len)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
264 md5_context->total[1]++;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
265
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
266 if(left && len >= fill) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
267 memcpy((md5_context->buffer + left), data, fill);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
268 md5_process(md5_context, md5_context->buffer);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
269 len -= fill;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
270 data += fill;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
271 left = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
272 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
273
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
274 while(len >= 64) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
275 md5_process(md5_context, data);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
276 len -= 64;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
277 data += 64;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
278 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
279
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
280 if(len) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
281 memcpy((md5_context->buffer + left), data, len);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
282 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
283 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
284
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
285 static gboolean
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
286 md5_digest(GaimCipherContext *context, size_t in_len, guchar digest[16],
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
287 size_t *out_len)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
288 {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
289 struct MD5Context *md5_context = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
290 guint32 last, pad;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
291 guint32 high, low;
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
292 guchar message[8];
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
293 guchar padding[64] = {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
294 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
295 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
296 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
297 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
298 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
299
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
300 g_return_val_if_fail(in_len >= 16, FALSE);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
301
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
302 md5_context = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
303
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
304 high = (md5_context->total[0] >> 29)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
305 | (md5_context->total[1] << 3);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
306 low = (md5_context->total[0] << 3);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
307
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
308 MD5_PUT_GUINT32(low, message, 0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
309 MD5_PUT_GUINT32(high, message, 4);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
310
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
311 last = md5_context->total[0] & 0x3F;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
312 pad = (last < 56) ? (56 - last) : (120 - last);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
313
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
314 md5_append(context, padding, pad);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
315 md5_append(context, message, 8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
316
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
317 MD5_PUT_GUINT32(md5_context->state[0], digest, 0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
318 MD5_PUT_GUINT32(md5_context->state[1], digest, 4);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
319 MD5_PUT_GUINT32(md5_context->state[2], digest, 8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
320 MD5_PUT_GUINT32(md5_context->state[3], digest, 12);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
321
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
322 if(out_len)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
323 *out_len = 16;
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
324
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
325 return TRUE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
326 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
327
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
328 static GaimCipherOps MD5Ops = {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
329 NULL, /* Set option */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
330 NULL, /* Get option */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
331 md5_init, /* init */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
332 md5_reset, /* reset */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
333 md5_uninit, /* uninit */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
334 NULL, /* set iv */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
335 md5_append, /* append */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
336 md5_digest, /* digest */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
337 NULL, /* encrypt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
338 NULL, /* decrypt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
339 NULL, /* set salt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
340 NULL, /* get salt size */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
341 NULL, /* set key */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
342 NULL /* get key size */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
343 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
344
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
345 /*******************************************************************************
11329
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
346 * MD4
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
347 ******************************************************************************/
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
348 #define MD4_DIGEST_SIZE 16
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
349 #define MD4_HMAC_BLOCK_SIZE 64
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
350 #define MD4_BLOCK_WORDS 16
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
351 #define MD4_HASH_WORDS 4
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
352
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
353
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
354
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
355 struct MD4_Context {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
356 guint32 hash[MD4_HASH_WORDS];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
357 guint32 block[MD4_BLOCK_WORDS];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
358 guint64 byte_count;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
359 };
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
360
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
361 static inline guint32 lshift(guint32 x, unsigned int s)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
362 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
363 x &= 0xFFFFFFFF;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
364 return ((x << s) & 0xFFFFFFFF) | (x >> (32 - s));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
365 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
366
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
367 static inline guint32 F(guint32 x, guint32 y, guint32 z)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
368 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
369 return (x & y) | ((~x) & z);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
370 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
371
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
372 static inline guint32 G(guint32 x, guint32 y, guint32 z)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
373 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
374 return (x & y) | (x & z) | (y & z);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
375 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
376
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
377 static inline guint32 H(guint32 x, guint32 y, guint32 z)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
378 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
379 return x ^ y ^ z;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
380 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
381
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
382 #define ROUND1(a,b,c,d,k,s) (a = lshift(a + F(b,c,d) + k, s))
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
383 #define ROUND2(a,b,c,d,k,s) (a = lshift(a + G(b,c,d) + k + (guint32)0x5A827999,s))
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
384 #define ROUND3(a,b,c,d,k,s) (a = lshift(a + H(b,c,d) + k + (guint32)0x6ED9EBA1,s))
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
385
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
386 static inline void le32_to_cpu_array(guint32 *buf, unsigned int words)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
387 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
388 while (words--) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
389 *buf=GUINT_FROM_LE(*buf);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
390 buf++;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
391 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
392 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
393
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
394 static inline void cpu_to_le32_array(guint32 *buf, unsigned int words)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
395 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
396 while (words--) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
397 *buf=GUINT_TO_LE(*buf);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
398 buf++;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
399 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
400 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
401
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
402 static void md4_transform(guint32 *hash, guint32 const *in)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
403 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
404 guint32 a, b, c, d;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
405
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
406 a = hash[0];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
407 b = hash[1];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
408 c = hash[2];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
409 d = hash[3];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
410
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
411 ROUND1(a, b, c, d, in[0], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
412 ROUND1(d, a, b, c, in[1], 7);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
413 ROUND1(c, d, a, b, in[2], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
414 ROUND1(b, c, d, a, in[3], 19);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
415 ROUND1(a, b, c, d, in[4], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
416 ROUND1(d, a, b, c, in[5], 7);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
417 ROUND1(c, d, a, b, in[6], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
418 ROUND1(b, c, d, a, in[7], 19);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
419 ROUND1(a, b, c, d, in[8], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
420 ROUND1(d, a, b, c, in[9], 7);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
421 ROUND1(c, d, a, b, in[10], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
422 ROUND1(b, c, d, a, in[11], 19);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
423 ROUND1(a, b, c, d, in[12], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
424 ROUND1(d, a, b, c, in[13], 7);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
425 ROUND1(c, d, a, b, in[14], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
426 ROUND1(b, c, d, a, in[15], 19);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
427
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
428 ROUND2(a, b, c, d,in[ 0], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
429 ROUND2(d, a, b, c, in[4], 5);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
430 ROUND2(c, d, a, b, in[8], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
431 ROUND2(b, c, d, a, in[12], 13);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
432 ROUND2(a, b, c, d, in[1], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
433 ROUND2(d, a, b, c, in[5], 5);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
434 ROUND2(c, d, a, b, in[9], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
435 ROUND2(b, c, d, a, in[13], 13);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
436 ROUND2(a, b, c, d, in[2], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
437 ROUND2(d, a, b, c, in[6], 5);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
438 ROUND2(c, d, a, b, in[10], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
439 ROUND2(b, c, d, a, in[14], 13);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
440 ROUND2(a, b, c, d, in[3], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
441 ROUND2(d, a, b, c, in[7], 5);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
442 ROUND2(c, d, a, b, in[11], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
443 ROUND2(b, c, d, a, in[15], 13);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
444
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
445 ROUND3(a, b, c, d,in[ 0], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
446 ROUND3(d, a, b, c, in[8], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
447 ROUND3(c, d, a, b, in[4], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
448 ROUND3(b, c, d, a, in[12], 15);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
449 ROUND3(a, b, c, d, in[2], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
450 ROUND3(d, a, b, c, in[10], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
451 ROUND3(c, d, a, b, in[6], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
452 ROUND3(b, c, d, a, in[14], 15);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
453 ROUND3(a, b, c, d, in[1], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
454 ROUND3(d, a, b, c, in[9], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
455 ROUND3(c, d, a, b, in[5], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
456 ROUND3(b, c, d, a, in[13], 15);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
457 ROUND3(a, b, c, d, in[3], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
458 ROUND3(d, a, b, c, in[11], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
459 ROUND3(c, d, a, b, in[7], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
460 ROUND3(b, c, d, a, in[15], 15);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
461
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
462 hash[0] += a;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
463 hash[1] += b;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
464 hash[2] += c;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
465 hash[3] += d;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
466 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
467
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
468 static inline void md4_transform_helper(struct MD4_Context *ctx)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
469 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
470 le32_to_cpu_array(ctx->block, sizeof(ctx->block) / sizeof(guint32));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
471 md4_transform(ctx->hash, ctx->block);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
472 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
473
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
474 static void
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
475 md4_init(GaimCipherContext *context, gpointer extra) {
13218
c01aa6ea4947 [gaim-migrate @ 15582]
Richard Laager <rlaager@wiktel.com>
parents: 12389
diff changeset
476 struct MD4_Context *mctx;
c01aa6ea4947 [gaim-migrate @ 15582]
Richard Laager <rlaager@wiktel.com>
parents: 12389
diff changeset
477 mctx = g_new0(struct MD4_Context, 1);
c01aa6ea4947 [gaim-migrate @ 15582]
Richard Laager <rlaager@wiktel.com>
parents: 12389
diff changeset
478 gaim_cipher_context_set_data(context, mctx);
c01aa6ea4947 [gaim-migrate @ 15582]
Richard Laager <rlaager@wiktel.com>
parents: 12389
diff changeset
479 gaim_cipher_context_reset(context, extra);
11329
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
480
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
481 mctx->hash[0] = 0x67452301;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
482 mctx->hash[1] = 0xefcdab89;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
483 mctx->hash[2] = 0x98badcfe;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
484 mctx->hash[3] = 0x10325476;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
485 mctx->byte_count = 0;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
486 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
487
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
488 static void
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
489 md4_reset(GaimCipherContext *context, gpointer extra) {
13218
c01aa6ea4947 [gaim-migrate @ 15582]
Richard Laager <rlaager@wiktel.com>
parents: 12389
diff changeset
490 struct MD4_Context *mctx;
11329
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
491
13218
c01aa6ea4947 [gaim-migrate @ 15582]
Richard Laager <rlaager@wiktel.com>
parents: 12389
diff changeset
492 mctx = gaim_cipher_context_get_data(context);
11329
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
493
13218
c01aa6ea4947 [gaim-migrate @ 15582]
Richard Laager <rlaager@wiktel.com>
parents: 12389
diff changeset
494 mctx->hash[0] = 0x67452301;
11329
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
495 mctx->hash[1] = 0xefcdab89;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
496 mctx->hash[2] = 0x98badcfe;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
497 mctx->hash[3] = 0x10325476;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
498 mctx->byte_count = 0;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
499 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
500
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
501 static void
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
502 md4_append(GaimCipherContext *context, const guchar *data, size_t len)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
503 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
504 struct MD4_Context *mctx = gaim_cipher_context_get_data(context);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
505 const guint32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
506
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
507 mctx->byte_count += len;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
508
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
509 if (avail > len) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
510 memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
511 data, len);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
512 return;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
513 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
514
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
515 memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
516 data, avail);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
517
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
518 md4_transform_helper(mctx);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
519 data += avail;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
520 len -= avail;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
521
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
522 while (len >= sizeof(mctx->block)) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
523 memcpy(mctx->block, data, sizeof(mctx->block));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
524 md4_transform_helper(mctx);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
525 data += sizeof(mctx->block);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
526 len -= sizeof(mctx->block);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
527 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
528
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
529 memcpy(mctx->block, data, len);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
530 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
531
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
532 static gboolean
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
533 md4_digest(GaimCipherContext *context, size_t in_len, guchar *out,
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
534 size_t *out_len)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
535 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
536 struct MD4_Context *mctx = gaim_cipher_context_get_data(context);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
537 const unsigned int offset = mctx->byte_count & 0x3f;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
538 char *p = (char *)mctx->block + offset;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
539 int padding = 56 - (offset + 1);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
540
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
541
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
542 if(in_len<16) return FALSE;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
543 if(out_len) *out_len = 16;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
544 *p++ = 0x80;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
545 if (padding < 0) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
546 memset(p, 0x00, padding + sizeof (guint64));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
547 md4_transform_helper(mctx);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
548 p = (char *)mctx->block;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
549 padding = 56;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
550 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
551
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
552 memset(p, 0, padding);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
553 mctx->block[14] = mctx->byte_count << 3;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
554 mctx->block[15] = mctx->byte_count >> 29;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
555 le32_to_cpu_array(mctx->block, (sizeof(mctx->block) -
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
556 sizeof(guint64)) / sizeof(guint32));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
557 md4_transform(mctx->hash, mctx->block);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
558 cpu_to_le32_array(mctx->hash, sizeof(mctx->hash) / sizeof(guint32));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
559 memcpy(out, mctx->hash, sizeof(mctx->hash));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
560 memset(mctx, 0, sizeof(*mctx));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
561 return TRUE;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
562 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
563
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
564 static void
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
565 md4_uninit(GaimCipherContext *context) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
566 struct MD4_Context *md4_context;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
567
13218
c01aa6ea4947 [gaim-migrate @ 15582]
Richard Laager <rlaager@wiktel.com>
parents: 12389
diff changeset
568 gaim_cipher_context_reset(context, NULL);
11329
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
569
13218
c01aa6ea4947 [gaim-migrate @ 15582]
Richard Laager <rlaager@wiktel.com>
parents: 12389
diff changeset
570 md4_context = gaim_cipher_context_get_data(context);
11329
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
571 memset(md4_context, 0, sizeof(md4_context));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
572
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
573 g_free(md4_context);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
574 md4_context = NULL;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
575 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
576
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
577 static GaimCipherOps MD4Ops = {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
578 NULL, /* Set option */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
579 NULL, /* Get option */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
580 md4_init, /* init */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
581 md4_reset, /* reset */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
582 md4_uninit, /* uninit */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
583 NULL, /* set iv */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
584 md4_append, /* append */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
585 md4_digest, /* digest */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
586 NULL, /* encrypt */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
587 NULL, /* decrypt */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
588 NULL, /* set salt */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
589 NULL, /* get salt size */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
590 NULL, /* set key */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
591 NULL /* get key size */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
592 };
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
593
11335
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
594 /******************************************************************************
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
595 * DES
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
596 *****************************************************************************/
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
597
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
598 typedef struct _des_ctx
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
599 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
600 guint32 encrypt_subkeys[32];
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
601 guint32 decrypt_subkeys[32];
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
602 } des_ctx[1];
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
603
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
604 /*
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
605 * The s-box values are permuted according to the 'primitive function P'
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
606 */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
607 static guint32 sbox1[64] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
608 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
609 0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
610 0x00000200, 0x00808200, 0x00808202, 0x00000200, 0x00800202, 0x00808002, 0x00800000, 0x00000002,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
611 0x00000202, 0x00800200, 0x00800200, 0x00008200, 0x00008200, 0x00808000, 0x00808000, 0x00800202,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
612 0x00008002, 0x00800002, 0x00800002, 0x00008002, 0x00000000, 0x00000202, 0x00008202, 0x00800000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
613 0x00008000, 0x00808202, 0x00000002, 0x00808000, 0x00808200, 0x00800000, 0x00800000, 0x00000200,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
614 0x00808002, 0x00008000, 0x00008200, 0x00800002, 0x00000200, 0x00000002, 0x00800202, 0x00008202,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
615 0x00808202, 0x00008002, 0x00808000, 0x00800202, 0x00800002, 0x00000202, 0x00008202, 0x00808200,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
616 0x00000202, 0x00800200, 0x00800200, 0x00000000, 0x00008002, 0x00008200, 0x00000000, 0x00808002
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
617 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
618
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
619 static guint32 sbox2[64] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
620 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
621 0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x00080000, 0x00000010, 0x40080010, 0x40004010,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
622 0x40000010, 0x40084010, 0x40084000, 0x40000000, 0x40004000, 0x00080000, 0x00000010, 0x40080010,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
623 0x00084000, 0x00080010, 0x40004010, 0x00000000, 0x40000000, 0x00004000, 0x00084010, 0x40080000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
624 0x00080010, 0x40000010, 0x00000000, 0x00084000, 0x00004010, 0x40084000, 0x40080000, 0x00004010,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
625 0x00000000, 0x00084010, 0x40080010, 0x00080000, 0x40004010, 0x40080000, 0x40084000, 0x00004000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
626 0x40080000, 0x40004000, 0x00000010, 0x40084010, 0x00084010, 0x00000010, 0x00004000, 0x40000000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
627 0x00004010, 0x40084000, 0x00080000, 0x40000010, 0x00080010, 0x40004010, 0x40000010, 0x00080010,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
628 0x00084000, 0x00000000, 0x40004000, 0x00004010, 0x40000000, 0x40080010, 0x40084010, 0x00084000
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
629 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
630
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
631 static guint32 sbox3[64] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
632 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
633 0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x04000100, 0x00000000, 0x00010104, 0x04000100,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
634 0x00010004, 0x04000004, 0x04000004, 0x00010000, 0x04010104, 0x00010004, 0x04010000, 0x00000104,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
635 0x04000000, 0x00000004, 0x04010100, 0x00000100, 0x00010100, 0x04010000, 0x04010004, 0x00010104,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
636 0x04000104, 0x00010100, 0x00010000, 0x04000104, 0x00000004, 0x04010104, 0x00000100, 0x04000000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
637 0x04010100, 0x04000000, 0x00010004, 0x00000104, 0x00010000, 0x04010100, 0x04000100, 0x00000000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
638 0x00000100, 0x00010004, 0x04010104, 0x04000100, 0x04000004, 0x00000100, 0x00000000, 0x04010004,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
639 0x04000104, 0x00010000, 0x04000000, 0x04010104, 0x00000004, 0x00010104, 0x00010100, 0x04000004,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
640 0x04010000, 0x04000104, 0x00000104, 0x04010000, 0x00010104, 0x00000004, 0x04010004, 0x00010100
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
641 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
642
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
643 static guint32 sbox4[64] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
644 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
645 0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x00401040, 0x80400040, 0x80400000, 0x80001000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
646 0x00000000, 0x00401000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00400040, 0x80400000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
647 0x80000000, 0x00001000, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x80001000, 0x00001040,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
648 0x80400040, 0x80000000, 0x00001040, 0x00400040, 0x00001000, 0x00401040, 0x80401040, 0x80000040,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
649 0x00400040, 0x80400000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00000000, 0x00401000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
650 0x00001040, 0x00400040, 0x80400040, 0x80000000, 0x80401000, 0x80001040, 0x80001040, 0x00000040,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
651 0x80401040, 0x80000040, 0x80000000, 0x00001000, 0x80400000, 0x80001000, 0x00401040, 0x80400040,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
652 0x80001000, 0x00001040, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x00001000, 0x00401040
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
653 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
654
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
655 static guint32 sbox5[64] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
656 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
657 0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00040000, 0x00000080, 0x20000000, 0x01040000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
658 0x20040080, 0x00040000, 0x01000080, 0x20040080, 0x21000080, 0x21040000, 0x00040080, 0x20000000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
659 0x01000000, 0x20040000, 0x20040000, 0x00000000, 0x20000080, 0x21040080, 0x21040080, 0x01000080,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
660 0x21040000, 0x20000080, 0x00000000, 0x21000000, 0x01040080, 0x01000000, 0x21000000, 0x00040080,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
661 0x00040000, 0x21000080, 0x00000080, 0x01000000, 0x20000000, 0x01040000, 0x21000080, 0x20040080,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
662 0x01000080, 0x20000000, 0x21040000, 0x01040080, 0x20040080, 0x00000080, 0x01000000, 0x21040000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
663 0x21040080, 0x00040080, 0x21000000, 0x21040080, 0x01040000, 0x00000000, 0x20040000, 0x21000000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
664 0x00040080, 0x01000080, 0x20000080, 0x00040000, 0x00000000, 0x20040000, 0x01040080, 0x20000080
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
665 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
666
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
667 static guint32 sbox6[64] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
668 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
669 0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10200000, 0x00000008, 0x10202008, 0x00200000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
670 0x10002000, 0x00202008, 0x00200000, 0x10000008, 0x00200008, 0x10002000, 0x10000000, 0x00002008,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
671 0x00000000, 0x00200008, 0x10002008, 0x00002000, 0x00202000, 0x10002008, 0x00000008, 0x10200008,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
672 0x10200008, 0x00000000, 0x00202008, 0x10202000, 0x00002008, 0x00202000, 0x10202000, 0x10000000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
673 0x10002000, 0x00000008, 0x10200008, 0x00202000, 0x10202008, 0x00200000, 0x00002008, 0x10000008,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
674 0x00200000, 0x10002000, 0x10000000, 0x00002008, 0x10000008, 0x10202008, 0x00202000, 0x10200000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
675 0x00202008, 0x10202000, 0x00000000, 0x10200008, 0x00000008, 0x00002000, 0x10200000, 0x00202008,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
676 0x00002000, 0x00200008, 0x10002008, 0x00000000, 0x10202000, 0x10000000, 0x00200008, 0x10002008
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
677 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
678
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
679 static guint32 sbox7[64] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
680 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
681 0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00000400, 0x02000401, 0x00100401, 0x02100400,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
682 0x02100401, 0x00100000, 0x00000000, 0x02000001, 0x00000001, 0x02000000, 0x02100001, 0x00000401,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
683 0x02000400, 0x00100401, 0x00100001, 0x02000400, 0x02000001, 0x02100000, 0x02100400, 0x00100001,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
684 0x02100000, 0x00000400, 0x00000401, 0x02100401, 0x00100400, 0x00000001, 0x02000000, 0x00100400,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
685 0x02000000, 0x00100400, 0x00100000, 0x02000401, 0x02000401, 0x02100001, 0x02100001, 0x00000001,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
686 0x00100001, 0x02000000, 0x02000400, 0x00100000, 0x02100400, 0x00000401, 0x00100401, 0x02100400,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
687 0x00000401, 0x02000001, 0x02100401, 0x02100000, 0x00100400, 0x00000000, 0x00000001, 0x02100401,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
688 0x00000000, 0x00100401, 0x02100000, 0x00000400, 0x02000001, 0x02000400, 0x00000400, 0x00100001
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
689 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
690
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
691 static guint32 sbox8[64] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
692 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
693 0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000000, 0x08000820, 0x00000020, 0x08000000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
694 0x00020020, 0x08020000, 0x08020820, 0x00020800, 0x08020800, 0x00020820, 0x00000800, 0x00000020,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
695 0x08020000, 0x08000020, 0x08000800, 0x00000820, 0x00020800, 0x00020020, 0x08020020, 0x08020800,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
696 0x00000820, 0x00000000, 0x00000000, 0x08020020, 0x08000020, 0x08000800, 0x00020820, 0x00020000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
697 0x00020820, 0x00020000, 0x08020800, 0x00000800, 0x00000020, 0x08020020, 0x00000800, 0x00020820,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
698 0x08000800, 0x00000020, 0x08000020, 0x08020000, 0x08020020, 0x08000000, 0x00020000, 0x08000820,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
699 0x00000000, 0x08020820, 0x00020020, 0x08000020, 0x08020000, 0x08000800, 0x08000820, 0x00000000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
700 0x08020820, 0x00020800, 0x00020800, 0x00000820, 0x00000820, 0x00020020, 0x08000000, 0x08020800
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
701 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
702
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
703
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
704
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
705 /*
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
706 * * These two tables are part of the 'permuted choice 1' function.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
707 * * In this implementation several speed improvements are done.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
708 * */
11677
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11597
diff changeset
709 static guint32 leftkey_swap[16] =
11335
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
710 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
711 0x00000000, 0x00000001, 0x00000100, 0x00000101,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
712 0x00010000, 0x00010001, 0x00010100, 0x00010101,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
713 0x01000000, 0x01000001, 0x01000100, 0x01000101,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
714 0x01010000, 0x01010001, 0x01010100, 0x01010101
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
715 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
716
11677
8004885fabbe [gaim-migrate @ 13963]
Mark Doliner <mark@kingant.net>
parents: 11597
diff changeset
717 static guint32 rightkey_swap[16] =
11335
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
718 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
719 0x00000000, 0x01000000, 0x00010000, 0x01010000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
720 0x00000100, 0x01000100, 0x00010100, 0x01010100,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
721 0x00000001, 0x01000001, 0x00010001, 0x01010001,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
722 0x00000101, 0x01000101, 0x00010101, 0x01010101,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
723 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
724
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
725
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
726
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
727 /*
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
728 * Numbers of left shifts per round for encryption subkey schedule
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
729 * To calculate the decryption key scheduling we just reverse the
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
730 * ordering of the subkeys so we can omit the table for decryption
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
731 * subkey schedule.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
732 */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
733 static guint8 encrypt_rotate_tab[16] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
734 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
735 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
736 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
737
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
738 /*
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
739 * Macro to swap bits across two words
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
740 **/
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
741 #define DO_PERMUTATION(a, temp, b, offset, mask) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
742 temp = ((a>>offset) ^ b) & mask; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
743 b ^= temp; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
744 a ^= temp<<offset;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
745
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
746
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
747 /*
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
748 * This performs the 'initial permutation' for the data to be encrypted or decrypted
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
749 **/
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
750 #define INITIAL_PERMUTATION(left, temp, right) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
751 DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
752 DO_PERMUTATION(left, temp, right, 16, 0x0000ffff) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
753 DO_PERMUTATION(right, temp, left, 2, 0x33333333) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
754 DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
755 DO_PERMUTATION(left, temp, right, 1, 0x55555555)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
756
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
757
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
758 /*
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
759 * The 'inverse initial permutation'
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
760 **/
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
761 #define FINAL_PERMUTATION(left, temp, right) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
762 DO_PERMUTATION(left, temp, right, 1, 0x55555555) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
763 DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
764 DO_PERMUTATION(right, temp, left, 2, 0x33333333) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
765 DO_PERMUTATION(left, temp, right, 16, 0x0000ffff) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
766 DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
767
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
768
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
769 /*
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
770 * A full DES round including 'expansion function', 'sbox substitution'
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
771 * and 'primitive function P' but without swapping the left and right word.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
772 **/
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
773 #define DES_ROUND(from, to, work, subkey) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
774 work = ((from<<1) | (from>>31)) ^ *subkey++; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
775 to ^= sbox8[ work & 0x3f ]; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
776 to ^= sbox6[ (work>>8) & 0x3f ]; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
777 to ^= sbox4[ (work>>16) & 0x3f ]; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
778 to ^= sbox2[ (work>>24) & 0x3f ]; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
779 work = ((from>>3) | (from<<29)) ^ *subkey++; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
780 to ^= sbox7[ work & 0x3f ]; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
781 to ^= sbox5[ (work>>8) & 0x3f ]; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
782 to ^= sbox3[ (work>>16) & 0x3f ]; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
783 to ^= sbox1[ (work>>24) & 0x3f ];
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
784
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
785
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
786 /*
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
787 * Macros to convert 8 bytes from/to 32bit words
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
788 **/
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
789 #define READ_64BIT_DATA(data, left, right) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
790 left = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
791 right = (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | data[7];
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
792
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
793 #define WRITE_64BIT_DATA(data, left, right) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
794 data[0] = (left >> 24) &0xff; data[1] = (left >> 16) &0xff; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
795 data[2] = (left >> 8) &0xff; data[3] = left &0xff; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
796 data[4] = (right >> 24) &0xff; data[5] = (right >> 16) &0xff; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
797 data[6] = (right >> 8) &0xff; data[7] = right &0xff;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
798
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
799
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
800
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
801
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
802
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
803
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
804 /*
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
805 * des_key_schedule(): Calculate 16 subkeys pairs (even/odd) for
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
806 * 16 encryption rounds.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
807 * To calculate subkeys for decryption the caller
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
808 * have to reorder the generated subkeys.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
809 *
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
810 * rawkey: 8 Bytes of key data
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
811 * subkey: Array of at least 32 guint32s. Will be filled
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
812 * with calculated subkeys.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
813 *
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
814 **/
11597
036bd21c5560 [gaim-migrate @ 13867]
Ethan Blanton <elb@pidgin.im>
parents: 11335
diff changeset
815 static void
11335
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
816 des_key_schedule (const guint8 * rawkey, guint32 * subkey)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
817 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
818 guint32 left, right, work;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
819 int round;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
820
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
821 READ_64BIT_DATA (rawkey, left, right)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
822
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
823 DO_PERMUTATION (right, work, left, 4, 0x0f0f0f0f)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
824 DO_PERMUTATION (right, work, left, 0, 0x10101010)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
825
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
826 left = (leftkey_swap[(left >> 0) & 0xf] << 3) | (leftkey_swap[(left >> 8) & 0xf] << 2)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
827 | (leftkey_swap[(left >> 16) & 0xf] << 1) | (leftkey_swap[(left >> 24) & 0xf])
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
828 | (leftkey_swap[(left >> 5) & 0xf] << 7) | (leftkey_swap[(left >> 13) & 0xf] << 6)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
829 | (leftkey_swap[(left >> 21) & 0xf] << 5) | (leftkey_swap[(left >> 29) & 0xf] << 4);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
830
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
831 left &= 0x0fffffff;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
832
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
833 right = (rightkey_swap[(right >> 1) & 0xf] << 3) | (rightkey_swap[(right >> 9) & 0xf] << 2)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
834 | (rightkey_swap[(right >> 17) & 0xf] << 1) | (rightkey_swap[(right >> 25) & 0xf])
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
835 | (rightkey_swap[(right >> 4) & 0xf] << 7) | (rightkey_swap[(right >> 12) & 0xf] << 6)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
836 | (rightkey_swap[(right >> 20) & 0xf] << 5) | (rightkey_swap[(right >> 28) & 0xf] << 4);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
837
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
838 right &= 0x0fffffff;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
839
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
840 for (round = 0; round < 16; ++round)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
841 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
842 left = ((left << encrypt_rotate_tab[round]) | (left >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
843 right = ((right << encrypt_rotate_tab[round]) | (right >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
844
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
845 *subkey++ = ((left << 4) & 0x24000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
846 | ((left << 28) & 0x10000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
847 | ((left << 14) & 0x08000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
848 | ((left << 18) & 0x02080000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
849 | ((left << 6) & 0x01000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
850 | ((left << 9) & 0x00200000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
851 | ((left >> 1) & 0x00100000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
852 | ((left << 10) & 0x00040000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
853 | ((left << 2) & 0x00020000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
854 | ((left >> 10) & 0x00010000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
855 | ((right >> 13) & 0x00002000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
856 | ((right >> 4) & 0x00001000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
857 | ((right << 6) & 0x00000800)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
858 | ((right >> 1) & 0x00000400)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
859 | ((right >> 14) & 0x00000200)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
860 | (right & 0x00000100)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
861 | ((right >> 5) & 0x00000020)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
862 | ((right >> 10) & 0x00000010)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
863 | ((right >> 3) & 0x00000008)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
864 | ((right >> 18) & 0x00000004)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
865 | ((right >> 26) & 0x00000002)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
866 | ((right >> 24) & 0x00000001);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
867
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
868 *subkey++ = ((left << 15) & 0x20000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
869 | ((left << 17) & 0x10000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
870 | ((left << 10) & 0x08000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
871 | ((left << 22) & 0x04000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
872 | ((left >> 2) & 0x02000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
873 | ((left << 1) & 0x01000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
874 | ((left << 16) & 0x00200000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
875 | ((left << 11) & 0x00100000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
876 | ((left << 3) & 0x00080000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
877 | ((left >> 6) & 0x00040000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
878 | ((left << 15) & 0x00020000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
879 | ((left >> 4) & 0x00010000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
880 | ((right >> 2) & 0x00002000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
881 | ((right << 8) & 0x00001000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
882 | ((right >> 14) & 0x00000808)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
883 | ((right >> 9) & 0x00000400)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
884 | ((right) & 0x00000200)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
885 | ((right << 7) & 0x00000100)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
886 | ((right >> 7) & 0x00000020)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
887 | ((right >> 3) & 0x00000011)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
888 | ((right << 2) & 0x00000004)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
889 | ((right >> 21) & 0x00000002);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
890 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
891 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
892
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
893
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
894
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
895 /*
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
896 * Fill a DES context with subkeys calculated from a 64bit key.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
897 * Does not check parity bits, but simply ignore them.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
898 * Does not check for weak keys.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
899 **/
11597
036bd21c5560 [gaim-migrate @ 13867]
Ethan Blanton <elb@pidgin.im>
parents: 11335
diff changeset
900 static void
13697
89ceef5203ac [gaim-migrate @ 16100]
Mark Doliner <mark@kingant.net>
parents: 13395
diff changeset
901 des_set_key (GaimCipherContext *context, const guchar * key)
11335
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
902 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
903 struct _des_ctx *ctx = gaim_cipher_context_get_data(context);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
904 int i;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
905
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
906 des_key_schedule (key, ctx->encrypt_subkeys);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
907
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
908 for(i=0; i<32; i+=2)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
909 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
910 ctx->decrypt_subkeys[i] = ctx->encrypt_subkeys[30-i];
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
911 ctx->decrypt_subkeys[i+1] = ctx->encrypt_subkeys[31-i];
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
912 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
913 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
914
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
915
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
916
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
917 /*
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
918 * Electronic Codebook Mode DES encryption/decryption of data according
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
919 * to 'mode'.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
920 **/
11597
036bd21c5560 [gaim-migrate @ 13867]
Ethan Blanton <elb@pidgin.im>
parents: 11335
diff changeset
921 static int
11335
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
922 des_ecb_crypt (struct _des_ctx *ctx, const guint8 * from, guint8 * to, int mode)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
923 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
924 guint32 left, right, work;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
925 guint32 *keys;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
926
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
927 keys = mode ? ctx->decrypt_subkeys : ctx->encrypt_subkeys;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
928
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
929 READ_64BIT_DATA (from, left, right)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
930 INITIAL_PERMUTATION (left, work, right)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
931
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
932 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
933 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
934 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
935 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
936 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
937 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
938 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
939 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
940
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
941 FINAL_PERMUTATION (right, work, left)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
942 WRITE_64BIT_DATA (to, right, left)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
943
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
944 return 0;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
945 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
946
11597
036bd21c5560 [gaim-migrate @ 13867]
Ethan Blanton <elb@pidgin.im>
parents: 11335
diff changeset
947 static gint
036bd21c5560 [gaim-migrate @ 13867]
Ethan Blanton <elb@pidgin.im>
parents: 11335
diff changeset
948 des_encrypt(GaimCipherContext *context, const guchar data[],
036bd21c5560 [gaim-migrate @ 13867]
Ethan Blanton <elb@pidgin.im>
parents: 11335
diff changeset
949 size_t len, guchar output[], size_t *outlen) {
11335
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
950 int offset = 0;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
951 int i = 0;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
952 int tmp;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
953 guint8 buf[8] = {0,0,0,0,0,0,0,0};
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
954 while(offset+8<=len) {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
955 des_ecb_crypt(gaim_cipher_context_get_data(context),
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
956 data+offset,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
957 output+offset,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
958 0);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
959 offset+=8;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
960 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
961 *outlen = len;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
962 if(offset<len) {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
963 *outlen += len - offset;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
964 tmp = offset;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
965 while(tmp<len) {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
966 buf[i++] = data[tmp];
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
967 tmp++;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
968 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
969 des_ecb_crypt(gaim_cipher_context_get_data(context),
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
970 buf,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
971 output+offset,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
972 0);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
973 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
974 return 0;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
975 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
976
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
977 static void
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
978 des_init(GaimCipherContext *context, gpointer extra) {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
979 struct _des_ctx *mctx;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
980 mctx = g_new0(struct _des_ctx, 1);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
981 gaim_cipher_context_set_data(context, mctx);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
982 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
983
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
984 static void
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
985 des_uninit(GaimCipherContext *context) {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
986 struct _des_ctx *des_context;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
987
13218
c01aa6ea4947 [gaim-migrate @ 15582]
Richard Laager <rlaager@wiktel.com>
parents: 12389
diff changeset
988 des_context = gaim_cipher_context_get_data(context);
11335
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
989 memset(des_context, 0, sizeof(des_context));
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
990
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
991 g_free(des_context);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
992 des_context = NULL;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
993 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
994
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
995 static GaimCipherOps DESOps = {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
996 NULL, /* Set option */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
997 NULL, /* Get option */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
998 des_init, /* init */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
999 NULL, /* reset */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1000 des_uninit, /* uninit */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1001 NULL, /* set iv */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1002 NULL, /* append */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1003 NULL, /* digest */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1004 des_encrypt, /* encrypt */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1005 NULL, /* decrypt */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1006 NULL, /* set salt */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1007 NULL, /* get salt size */
11597
036bd21c5560 [gaim-migrate @ 13867]
Ethan Blanton <elb@pidgin.im>
parents: 11335
diff changeset
1008 des_set_key, /* set key */
11335
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1009 NULL /* get key size */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1010 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1011
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1012
11329
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
1013 /*******************************************************************************
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1014 * SHA-1
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1015 ******************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1016 #define SHA1_ROTL(X,n) ((((X) << (n)) | ((X) >> (32-(n)))) & 0xFFFFFFFF)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1017
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1018 struct SHA1Context {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1019 guint32 H[5];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1020 guint32 W[80];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1021
13218
c01aa6ea4947 [gaim-migrate @ 15582]
Richard Laager <rlaager@wiktel.com>
parents: 12389
diff changeset
1022 gint lenW;
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1023
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1024 guint32 sizeHi;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1025 guint32 sizeLo;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1026 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1027
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1028 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1029 sha1_hash_block(struct SHA1Context *sha1_ctx) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1030 gint i;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1031 guint32 A, B, C, D, E, T;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1032
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1033 for(i = 16; i < 80; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1034 sha1_ctx->W[i] = SHA1_ROTL(sha1_ctx->W[i - 3] ^
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1035 sha1_ctx->W[i - 8] ^
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1036 sha1_ctx->W[i - 14] ^
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1037 sha1_ctx->W[i - 16], 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1038 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1039
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1040 A = sha1_ctx->H[0];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1041 B = sha1_ctx->H[1];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1042 C = sha1_ctx->H[2];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1043 D = sha1_ctx->H[3];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1044 E = sha1_ctx->H[4];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1045
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1046 for(i = 0; i < 20; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1047 T = (SHA1_ROTL(A, 5) + (((C ^ D) & B) ^ D) + E + sha1_ctx->W[i] + 0x5A827999) & 0xFFFFFFFF;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1048 E = D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1049 D = C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1050 C = SHA1_ROTL(B, 30);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1051 B = A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1052 A = T;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1053 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1054
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1055 for(i = 20; i < 40; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1056 T = (SHA1_ROTL(A, 5) + (B ^ C ^ D) + E + sha1_ctx->W[i] + 0x6ED9EBA1) & 0xFFFFFFFF;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1057 E = D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1058 D = C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1059 C = SHA1_ROTL(B, 30);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1060 B = A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1061 A = T;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1062 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1063
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1064 for(i = 40; i < 60; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1065 T = (SHA1_ROTL(A, 5) + ((B & C) | (D & (B | C))) + E + sha1_ctx->W[i] + 0x8F1BBCDC) & 0xFFFFFFFF;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1066 E = D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1067 D = C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1068 C = SHA1_ROTL(B, 30);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1069 B = A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1070 A = T;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1071 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1072
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1073 for(i = 60; i < 80; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1074 T = (SHA1_ROTL(A, 5) + (B ^ C ^ D) + E + sha1_ctx->W[i] + 0xCA62C1D6) & 0xFFFFFFFF;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1075 E = D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1076 D = C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1077 C = SHA1_ROTL(B, 30);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1078 B = A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1079 A = T;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1080 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1081
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1082 sha1_ctx->H[0] += A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1083 sha1_ctx->H[1] += B;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1084 sha1_ctx->H[2] += C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1085 sha1_ctx->H[3] += D;
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1086 sha1_ctx->H[4] += E;
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1087 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1088
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1089 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1090 sha1_set_opt(GaimCipherContext *context, const gchar *name, void *value) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1091 struct SHA1Context *ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1092
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1093 ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1094
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1095 if(!strcmp(name, "sizeHi")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1096 ctx->sizeHi = GPOINTER_TO_INT(value);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1097 } else if(!strcmp(name, "sizeLo")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1098 ctx->sizeLo = GPOINTER_TO_INT(value);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1099 } else if(!strcmp(name, "lenW")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1100 ctx->lenW = GPOINTER_TO_INT(value);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1101 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1102 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1103
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1104 static void *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1105 sha1_get_opt(GaimCipherContext *context, const gchar *name) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1106 struct SHA1Context *ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1107
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1108 ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1109
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1110 if(!strcmp(name, "sizeHi")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1111 return GINT_TO_POINTER(ctx->sizeHi);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1112 } else if(!strcmp(name, "sizeLo")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1113 return GINT_TO_POINTER(ctx->sizeLo);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1114 } else if(!strcmp(name, "lenW")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1115 return GINT_TO_POINTER(ctx->lenW);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1116 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1117
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1118 return NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1119 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1120
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1121 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1122 sha1_init(GaimCipherContext *context, void *extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1123 struct SHA1Context *sha1_ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1124
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1125 sha1_ctx = g_new0(struct SHA1Context, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1126
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1127 gaim_cipher_context_set_data(context, sha1_ctx);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1128
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1129 gaim_cipher_context_reset(context, extra);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1130 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1131
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1132 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1133 sha1_reset(GaimCipherContext *context, void *extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1134 struct SHA1Context *sha1_ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1135 gint i;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1136
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1137 sha1_ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1138
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1139 g_return_if_fail(sha1_ctx);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1140
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1141 sha1_ctx->lenW = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1142 sha1_ctx->sizeHi = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1143 sha1_ctx->sizeLo = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1144
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1145 sha1_ctx->H[0] = 0x67452301;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1146 sha1_ctx->H[1] = 0xEFCDAB89;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1147 sha1_ctx->H[2] = 0x98BADCFE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1148 sha1_ctx->H[3] = 0x10325476;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1149 sha1_ctx->H[4] = 0xC3D2E1F0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1150
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1151 for(i = 0; i < 80; i++)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1152 sha1_ctx->W[i] = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1153 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1154
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1155 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1156 sha1_uninit(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1157 struct SHA1Context *sha1_ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1158
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1159 gaim_cipher_context_reset(context, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1160
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1161 sha1_ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1162
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1163 memset(sha1_ctx, 0, sizeof(struct SHA1Context));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1164
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1165 g_free(sha1_ctx);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1166 sha1_ctx = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1167 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1168
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1169
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1170 static void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1171 sha1_append(GaimCipherContext *context, const guchar *data, size_t len) {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1172 struct SHA1Context *sha1_ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1173 gint i;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1174
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1175 sha1_ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1176
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1177 g_return_if_fail(sha1_ctx);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1178
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1179 for(i = 0; i < len; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1180 sha1_ctx->W[sha1_ctx->lenW / 4] <<= 8;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1181 sha1_ctx->W[sha1_ctx->lenW / 4] |= data[i];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1182
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1183 if((++sha1_ctx->lenW) % 64 == 0) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1184 sha1_hash_block(sha1_ctx);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1185 sha1_ctx->lenW = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1186 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1187
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1188 sha1_ctx->sizeLo += 8;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1189 sha1_ctx->sizeHi += (sha1_ctx->sizeLo < 8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1190 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1191 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1192
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1193 static gboolean
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1194 sha1_digest(GaimCipherContext *context, size_t in_len, guchar digest[20],
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1195 size_t *out_len)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1196 {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1197 struct SHA1Context *sha1_ctx;
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1198 guchar pad0x80 = 0x80, pad0x00 = 0x00;
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1199 guchar padlen[8];
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1200 gint i;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1201
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1202 g_return_val_if_fail(in_len >= 20, FALSE);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1203
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1204 sha1_ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1205
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1206 g_return_val_if_fail(sha1_ctx, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1207
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1208 padlen[0] = (guchar)((sha1_ctx->sizeHi >> 24) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1209 padlen[1] = (guchar)((sha1_ctx->sizeHi >> 16) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1210 padlen[2] = (guchar)((sha1_ctx->sizeHi >> 8) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1211 padlen[3] = (guchar)((sha1_ctx->sizeHi >> 0) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1212 padlen[4] = (guchar)((sha1_ctx->sizeLo >> 24) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1213 padlen[5] = (guchar)((sha1_ctx->sizeLo >> 16) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1214 padlen[6] = (guchar)((sha1_ctx->sizeLo >> 8) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1215 padlen[7] = (guchar)((sha1_ctx->sizeLo >> 0) & 255);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1216
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1217 /* pad with a 1, then zeroes, then length */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1218 gaim_cipher_context_append(context, &pad0x80, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1219 while(sha1_ctx->lenW != 56)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1220 gaim_cipher_context_append(context, &pad0x00, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1221 gaim_cipher_context_append(context, padlen, 8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1222
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1223 for(i = 0; i < 20; i++) {
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1224 digest[i] = (guchar)(sha1_ctx->H[i / 4] >> 24);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1225 sha1_ctx->H[i / 4] <<= 8;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1226 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1227
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1228 gaim_cipher_context_reset(context, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1229
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1230 if(out_len)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1231 *out_len = 20;
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1232
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1233 return TRUE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1234 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1235
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1236 static GaimCipherOps SHA1Ops = {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1237 sha1_set_opt, /* Set Option */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1238 sha1_get_opt, /* Get Option */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1239 sha1_init, /* init */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1240 sha1_reset, /* reset */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1241 sha1_uninit, /* uninit */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1242 NULL, /* set iv */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1243 sha1_append, /* append */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1244 sha1_digest, /* digest */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1245 NULL, /* encrypt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1246 NULL, /* decrypt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1247 NULL, /* set salt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1248 NULL, /* get salt size */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1249 NULL, /* set key */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1250 NULL /* get key size */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1251 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1252
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1253 /*******************************************************************************
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1254 * Structs
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1255 ******************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1256 struct _GaimCipher {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1257 gchar *name;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1258 GaimCipherOps *ops;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1259 guint ref;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1260 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1261
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1262 struct _GaimCipherContext {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1263 GaimCipher *cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1264 gpointer data;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1265 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1266
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1267 /******************************************************************************
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1268 * Globals
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1269 *****************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1270 static GList *ciphers = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1271
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1272 /******************************************************************************
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1273 * GaimCipher API
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1274 *****************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1275 const gchar *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1276 gaim_cipher_get_name(GaimCipher *cipher) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1277 g_return_val_if_fail(cipher, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1278
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1279 return cipher->name;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1280 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1281
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1282 guint
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1283 gaim_cipher_get_capabilities(GaimCipher *cipher) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1284 GaimCipherOps *ops = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1285 guint caps = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1286
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1287 g_return_val_if_fail(cipher, 0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1288
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1289 ops = cipher->ops;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1290 g_return_val_if_fail(ops, 0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1291
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1292 if(ops->set_option)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1293 caps |= GAIM_CIPHER_CAPS_SET_OPT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1294 if(ops->get_option)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1295 caps |= GAIM_CIPHER_CAPS_GET_OPT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1296 if(ops->init)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1297 caps |= GAIM_CIPHER_CAPS_INIT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1298 if(ops->reset)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1299 caps |= GAIM_CIPHER_CAPS_RESET;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1300 if(ops->uninit)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1301 caps |= GAIM_CIPHER_CAPS_UNINIT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1302 if(ops->set_iv)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1303 caps |= GAIM_CIPHER_CAPS_SET_IV;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1304 if(ops->append)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1305 caps |= GAIM_CIPHER_CAPS_APPEND;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1306 if(ops->digest)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1307 caps |= GAIM_CIPHER_CAPS_DIGEST;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1308 if(ops->encrypt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1309 caps |= GAIM_CIPHER_CAPS_ENCRYPT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1310 if(ops->decrypt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1311 caps |= GAIM_CIPHER_CAPS_DECRYPT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1312 if(ops->set_salt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1313 caps |= GAIM_CIPHER_CAPS_SET_SALT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1314 if(ops->get_salt_size)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1315 caps |= GAIM_CIPHER_CAPS_GET_SALT_SIZE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1316 if(ops->set_key)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1317 caps |= GAIM_CIPHER_CAPS_SET_KEY;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1318 if(ops->get_key_size)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1319 caps |= GAIM_CIPHER_CAPS_GET_KEY_SIZE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1320
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1321 return caps;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1322 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1323
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1324 gboolean
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1325 gaim_cipher_digest_region(const gchar *name, const guchar *data,
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1326 size_t data_len, size_t in_len,
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1327 guchar digest[], size_t *out_len)
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1328 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1329 GaimCipher *cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1330 GaimCipherContext *context;
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1331 gboolean ret = FALSE;
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1332
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1333 g_return_val_if_fail(name, FALSE);
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1334 g_return_val_if_fail(data, FALSE);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1335
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1336 cipher = gaim_ciphers_find_cipher(name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1337
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1338 g_return_val_if_fail(cipher, FALSE);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1339
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1340 if(!cipher->ops->append || !cipher->ops->digest) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1341 gaim_debug_info("cipher", "gaim_cipher_region failed: "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1342 "the %s cipher does not support appending and or "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1343 "digesting.", cipher->name);
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1344 return FALSE;
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1345 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1346
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1347 context = gaim_cipher_context_new(cipher, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1348 gaim_cipher_context_append(context, data, data_len);
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1349 ret = gaim_cipher_context_digest(context, in_len, digest, out_len);
11143
5c56223fa24f [gaim-migrate @ 13207]
Mark Doliner <mark@kingant.net>
parents: 10687
diff changeset
1350 gaim_cipher_context_destroy(context);
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1351
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1352 return ret;
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1353 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1354
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1355 /******************************************************************************
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1356 * GaimCiphers API
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1357 *****************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1358 GaimCipher *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1359 gaim_ciphers_find_cipher(const gchar *name) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1360 GaimCipher *cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1361 GList *l;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1362
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1363 g_return_val_if_fail(name, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1364
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1365 for(l = ciphers; l; l = l->next) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1366 cipher = GAIM_CIPHER(l->data);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1367
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1368 if(!g_ascii_strcasecmp(cipher->name, name))
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1369 return cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1370 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1371
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1372 return NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1373 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1374
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1375 GaimCipher *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1376 gaim_ciphers_register_cipher(const gchar *name, GaimCipherOps *ops) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1377 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1378
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1379 g_return_val_if_fail(name, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1380 g_return_val_if_fail(ops, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1381 g_return_val_if_fail(!gaim_ciphers_find_cipher(name), NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1382
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1383 cipher = g_new0(GaimCipher, 1);
13758
ff94569010f5 [gaim-migrate @ 16169]
Mark Doliner <mark@kingant.net>
parents: 13697
diff changeset
1384 GAIM_DBUS_REGISTER_POINTER(cipher, GaimCipher);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1385
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1386 cipher->name = g_strdup(name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1387 cipher->ops = ops;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1388
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1389 ciphers = g_list_append(ciphers, cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1390
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1391 gaim_signal_emit(gaim_ciphers_get_handle(), "cipher-added", cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1392
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1393 return cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1394 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1395
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1396 gboolean
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1397 gaim_ciphers_unregister_cipher(GaimCipher *cipher) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1398 g_return_val_if_fail(cipher, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1399 g_return_val_if_fail(cipher->ref == 0, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1400
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1401 gaim_signal_emit(gaim_ciphers_get_handle(), "cipher-removed", cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1402
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1403 ciphers = g_list_remove(ciphers, cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1404
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1405 g_free(cipher->name);
13758
ff94569010f5 [gaim-migrate @ 16169]
Mark Doliner <mark@kingant.net>
parents: 13697
diff changeset
1406
ff94569010f5 [gaim-migrate @ 16169]
Mark Doliner <mark@kingant.net>
parents: 13697
diff changeset
1407 GAIM_DBUS_UNREGISTER_POINTER(cipher);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1408 g_free(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1409
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1410 return TRUE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1411 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1412
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1413 GList *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1414 gaim_ciphers_get_ciphers() {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1415 return ciphers;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1416 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1417
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1418 /******************************************************************************
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1419 * GaimCipher Subsystem API
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1420 *****************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1421 gpointer
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1422 gaim_ciphers_get_handle() {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1423 static gint handle;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1424
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1425 return &handle;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1426 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1427
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1428 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1429 gaim_ciphers_init() {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1430 gpointer handle;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1431
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1432 handle = gaim_ciphers_get_handle();
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1433
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1434 gaim_signal_register(handle, "cipher-added",
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1435 gaim_marshal_VOID__POINTER, NULL, 1,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1436 gaim_value_new(GAIM_TYPE_SUBTYPE,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1437 GAIM_SUBTYPE_CIPHER));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1438 gaim_signal_register(handle, "cipher-removed",
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1439 gaim_marshal_VOID__POINTER, NULL, 1,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1440 gaim_value_new(GAIM_TYPE_SUBTYPE,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1441 GAIM_SUBTYPE_CIPHER));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1442
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1443 gaim_ciphers_register_cipher("md5", &MD5Ops);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1444 gaim_ciphers_register_cipher("sha1", &SHA1Ops);
11329
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
1445 gaim_ciphers_register_cipher("md4", &MD4Ops);
11335
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1446 gaim_ciphers_register_cipher("des", &DESOps);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1447 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1448
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1449 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1450 gaim_ciphers_uninit() {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1451 GaimCipher *cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1452 GList *l, *ll;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1453
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1454 for(l = ciphers; l; l = ll) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1455 ll = l->next;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1456
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1457 cipher = GAIM_CIPHER(l->data);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1458 gaim_ciphers_unregister_cipher(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1459
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1460 ciphers = g_list_remove(ciphers, cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1461 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1462
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1463 g_list_free(ciphers);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1464
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1465 gaim_signals_unregister_by_instance(gaim_ciphers_get_handle());
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1466 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1467 /******************************************************************************
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1468 * GaimCipherContext API
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1469 *****************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1470 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1471 gaim_cipher_context_set_option(GaimCipherContext *context, const gchar *name,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1472 gpointer value)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1473 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1474 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1475
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1476 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1477 g_return_if_fail(name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1478
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1479 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1480 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1481
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1482 if(cipher->ops && cipher->ops->set_option)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1483 cipher->ops->set_option(context, name, value);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1484 else
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1485 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1486 "set_option operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1487 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1488
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1489 gpointer
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1490 gaim_cipher_context_get_option(GaimCipherContext *context, const gchar *name) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1491 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1492
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1493 g_return_val_if_fail(context, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1494 g_return_val_if_fail(name, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1495
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1496 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1497 g_return_val_if_fail(cipher, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1498
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1499 if(cipher->ops && cipher->ops->get_option)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1500 return cipher->ops->get_option(context, name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1501 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1502 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1503 "get_option operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1504
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1505 return NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1506 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1507 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1508
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1509 GaimCipherContext *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1510 gaim_cipher_context_new(GaimCipher *cipher, void *extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1511 GaimCipherContext *context = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1512
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1513 g_return_val_if_fail(cipher, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1514
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1515 cipher->ref++;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1516
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1517 context = g_new0(GaimCipherContext, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1518 context->cipher = cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1519
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1520 if(cipher->ops->init)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1521 cipher->ops->init(context, extra);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1522
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1523 return context;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1524 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1525
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1526 GaimCipherContext *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1527 gaim_cipher_context_new_by_name(const gchar *name, void *extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1528 GaimCipher *cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1529
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1530 g_return_val_if_fail(name, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1531
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1532 cipher = gaim_ciphers_find_cipher(name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1533
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1534 g_return_val_if_fail(cipher, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1535
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1536 return gaim_cipher_context_new(cipher, extra);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1537 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1538
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1539 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1540 gaim_cipher_context_reset(GaimCipherContext *context, void *extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1541 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1542
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1543 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1544
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1545 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1546 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1547
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1548 if(cipher->ops && cipher->ops->reset)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1549 context->cipher->ops->reset(context, extra);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1550 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1551
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1552 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1553 gaim_cipher_context_destroy(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1554 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1555
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1556 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1557
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1558 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1559 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1560
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1561 cipher->ref--;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1562
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1563 if(cipher->ops && cipher->ops->uninit)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1564 cipher->ops->uninit(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1565
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1566 memset(context, 0, sizeof(context));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1567 g_free(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1568 context = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1569 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1570
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1571 void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1572 gaim_cipher_context_set_iv(GaimCipherContext *context, guchar *iv, size_t len)
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1573 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1574 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1575
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1576 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1577 g_return_if_fail(iv);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1578
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1579 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1580 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1581
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1582 if(cipher->ops && cipher->ops->set_iv)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1583 cipher->ops->set_iv(context, iv, len);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1584 else
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1585 gaim_debug_info("cipher", "the %s cipher does not support the set"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1586 "initialization vector operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1587 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1588
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1589 void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1590 gaim_cipher_context_append(GaimCipherContext *context, const guchar *data,
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1591 size_t len)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1592 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1593 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1594
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1595 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1596
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1597 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1598 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1599
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1600 if(cipher->ops && cipher->ops->append)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1601 cipher->ops->append(context, data, len);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1602 else
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1603 gaim_debug_info("cipher", "the %s cipher does not support the append "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1604 "operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1605 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1606
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1607 gboolean
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1608 gaim_cipher_context_digest(GaimCipherContext *context, size_t in_len,
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1609 guchar digest[], size_t *out_len)
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1610 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1611 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1612
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1613 g_return_val_if_fail(context, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1614
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1615 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1616 g_return_val_if_fail(context, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1617
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1618 if(cipher->ops && cipher->ops->digest)
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1619 return cipher->ops->digest(context, in_len, digest, out_len);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1620 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1621 gaim_debug_info("cipher", "the %s cipher does not support the digest "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1622 "operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1623 return FALSE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1624 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1625 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1626
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1627 gboolean
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1628 gaim_cipher_context_digest_to_str(GaimCipherContext *context, size_t in_len,
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1629 gchar digest_s[], size_t *out_len)
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1630 {
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1631 /* 8k is a bit excessive, will tweak later. */
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1632 guchar digest[BUF_LEN * 4];
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1633 gint n = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1634 size_t dlen = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1635
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1636 g_return_val_if_fail(context, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1637 g_return_val_if_fail(digest_s, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1638
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1639 if(!gaim_cipher_context_digest(context, sizeof(digest), digest, &dlen))
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1640 return FALSE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1641
12388
4e045668b9d0 [gaim-migrate @ 14694]
Richard Laager <rlaager@wiktel.com>
parents: 12382
diff changeset
1642 /* in_len must be greater than dlen * 2 so we have room for the NUL. */
4e045668b9d0 [gaim-migrate @ 14694]
Richard Laager <rlaager@wiktel.com>
parents: 12382
diff changeset
1643 if(in_len <= dlen * 2)
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1644 return FALSE;
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1645
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1646 for(n = 0; n < dlen; n++)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1647 sprintf(digest_s + (n * 2), "%02x", digest[n]);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1648
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1649 digest_s[n * 2] = '\0';
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1650
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1651 if(out_len)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1652 *out_len = dlen * 2;
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1653
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1654 return TRUE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1655 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1656
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1657 gint
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1658 gaim_cipher_context_encrypt(GaimCipherContext *context, const guchar data[],
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1659 size_t len, guchar output[], size_t *outlen)
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1660 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1661 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1662
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1663 g_return_val_if_fail(context, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1664
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1665 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1666 g_return_val_if_fail(cipher, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1667
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1668 if(cipher->ops && cipher->ops->encrypt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1669 return cipher->ops->encrypt(context, data, len, output, outlen);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1670 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1671 gaim_debug_info("cipher", "the %s cipher does not support the encrypt"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1672 "operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1673
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1674 if(outlen)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1675 *outlen = -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1676
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1677 return -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1678 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1679 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1680
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1681 gint
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1682 gaim_cipher_context_decrypt(GaimCipherContext *context, const guchar data[],
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1683 size_t len, guchar output[], size_t *outlen)
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1684 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1685 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1686
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1687 g_return_val_if_fail(context, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1688
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1689 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1690 g_return_val_if_fail(cipher, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1691
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1692 if(cipher->ops && cipher->ops->decrypt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1693 return cipher->ops->decrypt(context, data, len, output, outlen);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1694 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1695 gaim_debug_info("cipher", "the %s cipher does not support the decrypt"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1696 "operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1697
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1698 if(outlen)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1699 *outlen = -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1700
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1701 return -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1702 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1703 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1704
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1705 void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1706 gaim_cipher_context_set_salt(GaimCipherContext *context, guchar *salt) {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1707 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1708
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1709 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1710
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1711 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1712 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1713
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1714 if(cipher->ops && cipher->ops->set_salt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1715 cipher->ops->set_salt(context, salt);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1716 else
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1717 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1718 "set_salt operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1719 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1720
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1721 size_t
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1722 gaim_cipher_context_get_salt_size(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1723 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1724
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1725 g_return_val_if_fail(context, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1726
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1727 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1728 g_return_val_if_fail(cipher, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1729
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1730 if(cipher->ops && cipher->ops->get_salt_size)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1731 return cipher->ops->get_salt_size(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1732 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1733 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1734 "get_salt_size operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1735
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1736 return -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1737 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1738 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1739
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1740 void
13697
89ceef5203ac [gaim-migrate @ 16100]
Mark Doliner <mark@kingant.net>
parents: 13395
diff changeset
1741 gaim_cipher_context_set_key(GaimCipherContext *context, const guchar *key) {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1742 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1743
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1744 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1745
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1746 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1747 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1748
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1749 if(cipher->ops && cipher->ops->set_key)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1750 cipher->ops->set_key(context, key);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1751 else
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1752 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1753 "set_key operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1754 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1755
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1756 size_t
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1757 gaim_cipher_context_get_key_size(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1758 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1759
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1760 g_return_val_if_fail(context, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1761
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1762 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1763 g_return_val_if_fail(cipher, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1764
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1765 if(cipher->ops && cipher->ops->get_key_size)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1766 return cipher->ops->get_key_size(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1767 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1768 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1769 "get_key_size operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1770
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1771 return -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1772 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1773 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1774
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1775 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1776 gaim_cipher_context_set_data(GaimCipherContext *context, gpointer data) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1777 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1778
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1779 context->data = data;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1780 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1781
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1782 gpointer
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1783 gaim_cipher_context_get_data(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1784 g_return_val_if_fail(context, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1785
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1786 return context->data;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1787 }
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1788
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1789 gchar *gaim_cipher_http_digest_calculate_session_key(
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1790 const gchar *algorithm,
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1791 const gchar *username,
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1792 const gchar *realm,
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1793 const gchar *password,
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1794 const gchar *nonce,
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1795 const gchar *client_nonce)
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1796 {
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1797 GaimCipher *cipher;
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1798 GaimCipherContext *context;
12388
4e045668b9d0 [gaim-migrate @ 14694]
Richard Laager <rlaager@wiktel.com>
parents: 12382
diff changeset
1799 gchar hash[33]; /* We only support MD5. */
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1800
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1801 g_return_val_if_fail(username != NULL, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1802 g_return_val_if_fail(realm != NULL, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1803 g_return_val_if_fail(password != NULL, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1804 g_return_val_if_fail(nonce != NULL, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1805
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1806 /* Check for a supported algorithm. */
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1807 g_return_val_if_fail(algorithm == NULL ||
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1808 *algorithm == '\0' ||
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1809 strcasecmp(algorithm, "MD5") ||
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1810 strcasecmp(algorithm, "MD5-sess"), NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1811
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1812 cipher = gaim_ciphers_find_cipher("md5");
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1813 g_return_val_if_fail(cipher != NULL, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1814
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1815 context = gaim_cipher_context_new(cipher, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1816
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1817 gaim_cipher_context_append(context, (guchar *)username, strlen(username));
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1818 gaim_cipher_context_append(context, (guchar *)":", 1);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1819 gaim_cipher_context_append(context, (guchar *)realm, strlen(realm));
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1820 gaim_cipher_context_append(context, (guchar *)":", 1);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1821 gaim_cipher_context_append(context, (guchar *)password, strlen(password));
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1822
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1823 if (algorithm != NULL && !strcasecmp(algorithm, "MD5-sess"))
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1824 {
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1825 guchar digest[16];
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1826
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1827 if (client_nonce == NULL)
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1828 {
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1829 gaim_cipher_context_destroy(context);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1830 gaim_debug_error("cipher", "Required client_nonce missing for MD5-sess digest calculation.");
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1831 return NULL;
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1832 }
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1833
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1834 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1835 gaim_cipher_context_destroy(context);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1836
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1837 context = gaim_cipher_context_new(cipher, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1838 gaim_cipher_context_append(context, digest, sizeof(digest));
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1839 gaim_cipher_context_append(context, (guchar *)":", 1);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1840 gaim_cipher_context_append(context, (guchar *)nonce, strlen(nonce));
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1841 gaim_cipher_context_append(context, (guchar *)":", 1);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1842 gaim_cipher_context_append(context, (guchar *)client_nonce, strlen(client_nonce));
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1843 }
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1844
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1845 gaim_cipher_context_digest_to_str(context, sizeof(hash), hash, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1846 gaim_cipher_context_destroy(context);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1847
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1848 return g_strdup(hash);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1849 }
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1850
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1851 gchar *gaim_cipher_http_digest_calculate_response(
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1852 const gchar *algorithm,
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1853 const gchar *method,
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1854 const gchar *digest_uri,
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1855 const gchar *qop,
12389
e024601d45c7 [gaim-migrate @ 14695]
Richard Laager <rlaager@wiktel.com>
parents: 12388
diff changeset
1856 const gchar *entity,
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1857 const gchar *nonce,
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1858 const gchar *nonce_count,
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1859 const gchar *client_nonce,
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1860 const gchar *session_key)
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1861 {
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1862 GaimCipher *cipher;
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1863 GaimCipherContext *context;
12388
4e045668b9d0 [gaim-migrate @ 14694]
Richard Laager <rlaager@wiktel.com>
parents: 12382
diff changeset
1864 static gchar hash2[33]; /* We only support MD5. */
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1865
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1866 g_return_val_if_fail(method != NULL, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1867 g_return_val_if_fail(digest_uri != NULL, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1868 g_return_val_if_fail(nonce != NULL, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1869 g_return_val_if_fail(session_key != NULL, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1870
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1871 /* Check for a supported algorithm. */
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1872 g_return_val_if_fail(algorithm == NULL ||
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1873 *algorithm == '\0' ||
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1874 strcasecmp(algorithm, "MD5") ||
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1875 strcasecmp(algorithm, "MD5-sess"), NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1876
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1877 /* Check for a supported "quality of protection". */
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1878 g_return_val_if_fail(qop == NULL ||
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1879 *qop == '\0' ||
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1880 strcasecmp(qop, "auth") ||
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1881 strcasecmp(qop, "auth-int"), NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1882
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1883 cipher = gaim_ciphers_find_cipher("md5");
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1884 g_return_val_if_fail(cipher != NULL, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1885
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1886 context = gaim_cipher_context_new(cipher, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1887
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1888 gaim_cipher_context_append(context, (guchar *)method, strlen(method));
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1889 gaim_cipher_context_append(context, (guchar *)":", 1);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1890 gaim_cipher_context_append(context, (guchar *)digest_uri, strlen(digest_uri));
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1891
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1892 if (qop != NULL && !strcasecmp(qop, "auth-int"))
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1893 {
12389
e024601d45c7 [gaim-migrate @ 14695]
Richard Laager <rlaager@wiktel.com>
parents: 12388
diff changeset
1894 GaimCipherContext *context2;
e024601d45c7 [gaim-migrate @ 14695]
Richard Laager <rlaager@wiktel.com>
parents: 12388
diff changeset
1895 gchar entity_hash[33];
e024601d45c7 [gaim-migrate @ 14695]
Richard Laager <rlaager@wiktel.com>
parents: 12388
diff changeset
1896
e024601d45c7 [gaim-migrate @ 14695]
Richard Laager <rlaager@wiktel.com>
parents: 12388
diff changeset
1897 if (entity == NULL)
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1898 {
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1899 gaim_cipher_context_destroy(context);
12389
e024601d45c7 [gaim-migrate @ 14695]
Richard Laager <rlaager@wiktel.com>
parents: 12388
diff changeset
1900 gaim_debug_error("cipher", "Required entity missing for auth-int digest calculation.");
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1901 return NULL;
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1902 }
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1903
12389
e024601d45c7 [gaim-migrate @ 14695]
Richard Laager <rlaager@wiktel.com>
parents: 12388
diff changeset
1904 context2 = gaim_cipher_context_new(cipher, NULL);
e024601d45c7 [gaim-migrate @ 14695]
Richard Laager <rlaager@wiktel.com>
parents: 12388
diff changeset
1905 gaim_cipher_context_append(context2, (guchar *)entity, strlen(entity));
e024601d45c7 [gaim-migrate @ 14695]
Richard Laager <rlaager@wiktel.com>
parents: 12388
diff changeset
1906 gaim_cipher_context_digest_to_str(context2, sizeof(entity_hash), entity_hash, NULL);
e024601d45c7 [gaim-migrate @ 14695]
Richard Laager <rlaager@wiktel.com>
parents: 12388
diff changeset
1907 gaim_cipher_context_destroy(context2);
e024601d45c7 [gaim-migrate @ 14695]
Richard Laager <rlaager@wiktel.com>
parents: 12388
diff changeset
1908
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1909 gaim_cipher_context_append(context, (guchar *)":", 1);
12389
e024601d45c7 [gaim-migrate @ 14695]
Richard Laager <rlaager@wiktel.com>
parents: 12388
diff changeset
1910 gaim_cipher_context_append(context, (guchar *)entity_hash, strlen(entity_hash));
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1911 }
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1912
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1913 gaim_cipher_context_digest_to_str(context, sizeof(hash2), hash2, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1914 gaim_cipher_context_destroy(context);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1915
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1916 context = gaim_cipher_context_new(cipher, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1917 gaim_cipher_context_append(context, (guchar *)session_key, strlen(session_key));
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1918 gaim_cipher_context_append(context, (guchar *)":", 1);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1919 gaim_cipher_context_append(context, (guchar *)nonce, strlen(nonce));
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1920 gaim_cipher_context_append(context, (guchar *)":", 1);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1921
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1922 if (qop != NULL && *qop != '\0')
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1923 {
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1924 if (nonce_count == NULL)
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1925 {
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1926 gaim_cipher_context_destroy(context);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1927 gaim_debug_error("cipher", "Required nonce_count missing for digest calculation.");
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1928 return NULL;
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1929 }
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1930
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1931 if (client_nonce == NULL)
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1932 {
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1933 gaim_cipher_context_destroy(context);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1934 gaim_debug_error("cipher", "Required client_nonce missing for digest calculation.");
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1935 return NULL;
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1936 }
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1937
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1938 gaim_cipher_context_append(context, (guchar *)nonce_count, strlen(nonce_count));
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1939 gaim_cipher_context_append(context, (guchar *)":", 1);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1940 gaim_cipher_context_append(context, (guchar *)client_nonce, strlen(client_nonce));
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1941 gaim_cipher_context_append(context, (guchar *)":", 1);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1942
13395
ff4e85e04adf [gaim-migrate @ 15768]
Richard Laager <rlaager@wiktel.com>
parents: 13218
diff changeset
1943 gaim_cipher_context_append(context, (guchar *)qop, strlen(qop));
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1944
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1945 gaim_cipher_context_append(context, (guchar *)":", 1);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1946 }
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1947
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1948 gaim_cipher_context_append(context, (guchar *)hash2, strlen(hash2));
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1949 gaim_cipher_context_digest_to_str(context, sizeof(hash2), hash2, NULL);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1950 gaim_cipher_context_destroy(context);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1951
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1952 return g_strdup(hash2);
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 11677
diff changeset
1953 }