annotate src/cipher.c @ 11519:0dfda214df89

[gaim-migrate @ 13764] A few fixes for transitioning to the new status stuff committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 11 Sep 2005 17:46:01 +0000
parents 59aa7080eb2d
children 036bd21c5560
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"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
59 #include "debug.h"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
60 #include "signals.h"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
61 #include "value.h"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
62
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 * MD5
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
65 ******************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
66 struct MD5Context {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
67 guint32 total[2];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
68 guint32 state[4];
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
69 guchar buffer[64];
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
70 };
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 #define MD5_GET_GUINT32(n,b,i) { \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
73 (n) = ((guint32)(b) [(i) ] ) \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
74 | ((guint32)(b) [(i) + 1] << 8) \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
75 | ((guint32)(b) [(i) + 2] << 16) \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
76 | ((guint32)(b) [(i) + 3] << 24); \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
77 }
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
78 #define MD5_PUT_GUINT32(n,b,i) { \
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
79 (b)[(i) ] = (guchar)((n) ); \
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
80 (b)[(i) + 1] = (guchar)((n) >> 8); \
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
81 (b)[(i) + 2] = (guchar)((n) >> 16); \
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
82 (b)[(i) + 3] = (guchar)((n) >> 24); \
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
83 }
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 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
86 md5_init(GaimCipherContext *context, gpointer extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
87 struct MD5Context *md5_context;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
88
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
89 md5_context = g_new0(struct MD5Context, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
90
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
91 gaim_cipher_context_set_data(context, md5_context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
92
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
93 gaim_cipher_context_reset(context, extra);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
94 }
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 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
97 md5_reset(GaimCipherContext *context, gpointer extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
98 struct MD5Context *md5_context;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
99
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
100 md5_context = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
101
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
102 md5_context->total[0] = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
103 md5_context->total[1] = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
104
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
105 md5_context->state[0] = 0x67452301;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
106 md5_context->state[1] = 0xEFCDAB89;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
107 md5_context->state[2] = 0x98BADCFE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
108 md5_context->state[3] = 0x10325476;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
109
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
110 memset(md5_context->buffer, 0, sizeof(md5_context->buffer));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
111 }
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 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
114 md5_uninit(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
115 struct MD5Context *md5_context;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
116
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
117 gaim_cipher_context_reset(context, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
118
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
119 md5_context = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
120 memset(md5_context, 0, sizeof(md5_context));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
121
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
122 g_free(md5_context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
123 md5_context = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
124 }
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 static void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
127 md5_process(struct MD5Context *md5_context, const guchar data[64]) {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
128 guint32 X[16], A, B, C, D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
129
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
130 A = md5_context->state[0];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
131 B = md5_context->state[1];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
132 C = md5_context->state[2];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
133 D = md5_context->state[3];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
134
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
135 MD5_GET_GUINT32(X[ 0], data, 0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
136 MD5_GET_GUINT32(X[ 1], data, 4);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
137 MD5_GET_GUINT32(X[ 2], data, 8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
138 MD5_GET_GUINT32(X[ 3], data, 12);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
139 MD5_GET_GUINT32(X[ 4], data, 16);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
140 MD5_GET_GUINT32(X[ 5], data, 20);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
141 MD5_GET_GUINT32(X[ 6], data, 24);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
142 MD5_GET_GUINT32(X[ 7], data, 28);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
143 MD5_GET_GUINT32(X[ 8], data, 32);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
144 MD5_GET_GUINT32(X[ 9], data, 36);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
145 MD5_GET_GUINT32(X[10], data, 40);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
146 MD5_GET_GUINT32(X[11], data, 44);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
147 MD5_GET_GUINT32(X[12], data, 48);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
148 MD5_GET_GUINT32(X[13], data, 52);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
149 MD5_GET_GUINT32(X[14], data, 56);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
150 MD5_GET_GUINT32(X[15], data, 60);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
151
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
152 #define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
153 #define P(a,b,c,d,k,s,t) { \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
154 a += F(b,c,d) + X[k] + t; \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
155 a = S(a,s) + b; \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
156 }
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 /* first pass */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
159 #define F(x,y,z) (z ^ (x & (y ^ z)))
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
160 P(A, B, C, D, 0, 7, 0xD76AA478);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
161 P(D, A, B, C, 1, 12, 0xE8C7B756);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
162 P(C, D, A, B, 2, 17, 0x242070DB);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
163 P(B, C, D, A, 3, 22, 0xC1BDCEEE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
164 P(A, B, C, D, 4, 7, 0xF57C0FAF);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
165 P(D, A, B, C, 5, 12, 0x4787C62A);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
166 P(C, D, A, B, 6, 17, 0xA8304613);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
167 P(B, C, D, A, 7, 22, 0xFD469501);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
168 P(A, B, C, D, 8, 7, 0x698098D8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
169 P(D, A, B, C, 9, 12, 0x8B44F7AF);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
170 P(C, D, A, B, 10, 17, 0xFFFF5BB1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
171 P(B, C, D, A, 11, 22, 0x895CD7BE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
172 P(A, B, C, D, 12, 7, 0x6B901122);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
173 P(D, A, B, C, 13, 12, 0xFD987193);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
174 P(C, D, A, B, 14, 17, 0xA679438E);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
175 P(B, C, D, A, 15, 22, 0x49B40821);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
176 #undef F
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
177
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
178 /* second pass */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
179 #define F(x,y,z) (y ^ (z & (x ^ y)))
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
180 P(A, B, C, D, 1, 5, 0xF61E2562);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
181 P(D, A, B, C, 6, 9, 0xC040B340);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
182 P(C, D, A, B, 11, 14, 0x265E5A51);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
183 P(B, C, D, A, 0, 20, 0xE9B6C7AA);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
184 P(A, B, C, D, 5, 5, 0xD62F105D);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
185 P(D, A, B, C, 10, 9, 0x02441453);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
186 P(C, D, A, B, 15, 14, 0xD8A1E681);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
187 P(B, C, D, A, 4, 20, 0xE7D3FBC8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
188 P(A, B, C, D, 9, 5, 0x21E1CDE6);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
189 P(D, A, B, C, 14, 9, 0xC33707D6);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
190 P(C, D, A, B, 3, 14, 0xF4D50D87);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
191 P(B, C, D, A, 8, 20, 0x455A14ED);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
192 P(A, B, C, D, 13, 5, 0xA9E3E905);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
193 P(D, A, B, C, 2, 9, 0xFCEFA3F8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
194 P(C, D, A, B, 7, 14, 0x676F02D9);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
195 P(B, C, D, A, 12, 20, 0x8D2A4C8A);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
196 #undef F
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
197
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
198 /* third pass */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
199 #define F(x,y,z) (x ^ y ^ z)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
200 P(A, B, C, D, 5, 4, 0xFFFA3942);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
201 P(D, A, B, C, 8, 11, 0x8771F681);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
202 P(C, D, A, B, 11, 16, 0x6D9D6122);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
203 P(B, C, D, A, 14, 23, 0xFDE5380C);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
204 P(A, B, C, D, 1, 4, 0xA4BEEA44);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
205 P(D, A, B, C, 4, 11, 0x4BDECFA9);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
206 P(C, D, A, B, 7, 16, 0xF6BB4B60);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
207 P(B, C, D, A, 10, 23, 0xBEBFBC70);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
208 P(A, B, C, D, 13, 4, 0x289B7EC6);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
209 P(D, A, B, C, 0, 11, 0xEAA127FA);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
210 P(C, D, A, B, 3, 16, 0xD4EF3085);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
211 P(B, C, D, A, 6, 23, 0x04881D05);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
212 P(A, B, C, D, 9, 4, 0xD9D4D039);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
213 P(D, A, B, C, 12, 11, 0xE6DB99E5);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
214 P(C, D, A, B, 15, 16, 0x1FA27CF8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
215 P(B, C, D, A, 2, 23, 0xC4AC5665);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
216 #undef F
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
217
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
218 /* forth pass */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
219 #define F(x,y,z) (y ^ (x | ~z))
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
220 P(A, B, C, D, 0, 6, 0xF4292244);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
221 P(D, A, B, C, 7, 10, 0x432AFF97);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
222 P(C, D, A, B, 14, 15, 0xAB9423A7);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
223 P(B, C, D, A, 5, 21, 0xFC93A039);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
224 P(A, B, C, D, 12, 6, 0x655B59C3);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
225 P(D, A, B, C, 3, 10, 0x8F0CCC92);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
226 P(C, D, A, B, 10, 15, 0xFFEFF47D);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
227 P(B, C, D, A, 1, 21, 0x85845DD1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
228 P(A, B, C, D, 8, 6, 0x6FA87E4F);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
229 P(D, A, B, C, 15, 10, 0xFE2CE6E0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
230 P(C, D, A, B, 6, 15, 0xA3014314);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
231 P(B, C, D, A, 13, 21, 0x4E0811A1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
232 P(A, B, C, D, 4, 6, 0xF7537E82);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
233 P(D, A, B, C, 11, 10, 0xBD3AF235);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
234 P(C, D, A, B, 2, 15, 0x2AD7D2BB);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
235 P(B, C, D, A, 9, 21, 0xEB86D391);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
236 #undef F
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
237 #undef P
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
238 #undef S
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
239
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
240 md5_context->state[0] += A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
241 md5_context->state[1] += B;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
242 md5_context->state[2] += C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
243 md5_context->state[3] += D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
244 }
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 static void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
247 md5_append(GaimCipherContext *context, const guchar *data, size_t len) {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
248 struct MD5Context *md5_context = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
249 guint32 left = 0, fill = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
250
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
251 g_return_if_fail(context != NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
252
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
253 md5_context = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
254 g_return_if_fail(md5_context != NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
255
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
256 left = md5_context->total[0] & 0x3F;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
257 fill = 64 - left;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
258
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
259 md5_context->total[0] += len;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
260 md5_context->total[0] &= 0xFFFFFFFF;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
261
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
262 if(md5_context->total[0] < len)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
263 md5_context->total[1]++;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
264
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
265 if(left && len >= fill) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
266 memcpy((md5_context->buffer + left), data, fill);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
267 md5_process(md5_context, md5_context->buffer);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
268 len -= fill;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
269 data += fill;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
270 left = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
271 }
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 while(len >= 64) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
274 md5_process(md5_context, data);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
275 len -= 64;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
276 data += 64;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
277 }
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 if(len) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
280 memcpy((md5_context->buffer + left), data, len);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
281 }
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 static gboolean
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
285 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
286 size_t *out_len)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
287 {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
288 struct MD5Context *md5_context = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
289 guint32 last, pad;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
290 guint32 high, low;
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
291 guchar message[8];
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
292 guchar padding[64] = {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
293 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
294 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
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 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
298
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
299 g_return_val_if_fail(in_len >= 16, FALSE);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
300
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
301 md5_context = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
302
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
303 high = (md5_context->total[0] >> 29)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
304 | (md5_context->total[1] << 3);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
305 low = (md5_context->total[0] << 3);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
306
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
307 MD5_PUT_GUINT32(low, message, 0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
308 MD5_PUT_GUINT32(high, message, 4);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
309
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
310 last = md5_context->total[0] & 0x3F;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
311 pad = (last < 56) ? (56 - last) : (120 - last);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
312
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
313 md5_append(context, padding, pad);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
314 md5_append(context, message, 8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
315
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
316 MD5_PUT_GUINT32(md5_context->state[0], digest, 0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
317 MD5_PUT_GUINT32(md5_context->state[1], digest, 4);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
318 MD5_PUT_GUINT32(md5_context->state[2], digest, 8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
319 MD5_PUT_GUINT32(md5_context->state[3], digest, 12);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
320
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
321 if(out_len)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
322 *out_len = 16;
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
323
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
324 return TRUE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
325 }
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 static GaimCipherOps MD5Ops = {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
328 NULL, /* Set option */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
329 NULL, /* Get option */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
330 md5_init, /* init */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
331 md5_reset, /* reset */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
332 md5_uninit, /* uninit */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
333 NULL, /* set iv */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
334 md5_append, /* append */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
335 md5_digest, /* digest */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
336 NULL, /* encrypt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
337 NULL, /* decrypt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
338 NULL, /* set salt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
339 NULL, /* get salt size */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
340 NULL, /* set key */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
341 NULL /* get key size */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
342 };
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 /*******************************************************************************
11329
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
345 * MD4
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
346 ******************************************************************************/
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
347 #define MD4_DIGEST_SIZE 16
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
348 #define MD4_HMAC_BLOCK_SIZE 64
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
349 #define MD4_BLOCK_WORDS 16
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
350 #define MD4_HASH_WORDS 4
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
351
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 struct MD4_Context {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
355 guint32 hash[MD4_HASH_WORDS];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
356 guint32 block[MD4_BLOCK_WORDS];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
357 guint64 byte_count;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
358 };
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
359
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
360 static inline guint32 lshift(guint32 x, unsigned int s)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
361 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
362 x &= 0xFFFFFFFF;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
363 return ((x << s) & 0xFFFFFFFF) | (x >> (32 - s));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
364 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
365
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
366 static inline guint32 F(guint32 x, guint32 y, guint32 z)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
367 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
368 return (x & y) | ((~x) & z);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
369 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
370
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
371 static inline guint32 G(guint32 x, guint32 y, guint32 z)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
372 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
373 return (x & y) | (x & z) | (y & z);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
374 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
375
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
376 static inline guint32 H(guint32 x, guint32 y, guint32 z)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
377 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
378 return x ^ y ^ z;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
379 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
380
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
381 #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
382 #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
383 #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
384
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
385 static inline void le32_to_cpu_array(guint32 *buf, unsigned int words)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
386 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
387 while (words--) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
388 *buf=GUINT_FROM_LE(*buf);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
389 buf++;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
390 }
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 static inline void cpu_to_le32_array(guint32 *buf, unsigned int words)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
394 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
395 while (words--) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
396 *buf=GUINT_TO_LE(*buf);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
397 buf++;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
398 }
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 static void md4_transform(guint32 *hash, guint32 const *in)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
402 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
403 guint32 a, b, c, d;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
404
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
405 a = hash[0];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
406 b = hash[1];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
407 c = hash[2];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
408 d = hash[3];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
409
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
410 ROUND1(a, b, c, d, in[0], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
411 ROUND1(d, a, b, c, in[1], 7);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
412 ROUND1(c, d, a, b, in[2], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
413 ROUND1(b, c, d, a, in[3], 19);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
414 ROUND1(a, b, c, d, in[4], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
415 ROUND1(d, a, b, c, in[5], 7);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
416 ROUND1(c, d, a, b, in[6], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
417 ROUND1(b, c, d, a, in[7], 19);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
418 ROUND1(a, b, c, d, in[8], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
419 ROUND1(d, a, b, c, in[9], 7);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
420 ROUND1(c, d, a, b, in[10], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
421 ROUND1(b, c, d, a, in[11], 19);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
422 ROUND1(a, b, c, d, in[12], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
423 ROUND1(d, a, b, c, in[13], 7);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
424 ROUND1(c, d, a, b, in[14], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
425 ROUND1(b, c, d, a, in[15], 19);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
426
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
427 ROUND2(a, b, c, d,in[ 0], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
428 ROUND2(d, a, b, c, in[4], 5);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
429 ROUND2(c, d, a, b, in[8], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
430 ROUND2(b, c, d, a, in[12], 13);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
431 ROUND2(a, b, c, d, in[1], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
432 ROUND2(d, a, b, c, in[5], 5);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
433 ROUND2(c, d, a, b, in[9], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
434 ROUND2(b, c, d, a, in[13], 13);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
435 ROUND2(a, b, c, d, in[2], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
436 ROUND2(d, a, b, c, in[6], 5);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
437 ROUND2(c, d, a, b, in[10], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
438 ROUND2(b, c, d, a, in[14], 13);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
439 ROUND2(a, b, c, d, in[3], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
440 ROUND2(d, a, b, c, in[7], 5);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
441 ROUND2(c, d, a, b, in[11], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
442 ROUND2(b, c, d, a, in[15], 13);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
443
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
444 ROUND3(a, b, c, d,in[ 0], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
445 ROUND3(d, a, b, c, in[8], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
446 ROUND3(c, d, a, b, in[4], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
447 ROUND3(b, c, d, a, in[12], 15);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
448 ROUND3(a, b, c, d, in[2], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
449 ROUND3(d, a, b, c, in[10], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
450 ROUND3(c, d, a, b, in[6], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
451 ROUND3(b, c, d, a, in[14], 15);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
452 ROUND3(a, b, c, d, in[1], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
453 ROUND3(d, a, b, c, in[9], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
454 ROUND3(c, d, a, b, in[5], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
455 ROUND3(b, c, d, a, in[13], 15);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
456 ROUND3(a, b, c, d, in[3], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
457 ROUND3(d, a, b, c, in[11], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
458 ROUND3(c, d, a, b, in[7], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
459 ROUND3(b, c, d, a, in[15], 15);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
460
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
461 hash[0] += a;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
462 hash[1] += b;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
463 hash[2] += c;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
464 hash[3] += d;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
465 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
466
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
467 static inline void md4_transform_helper(struct MD4_Context *ctx)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
468 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
469 le32_to_cpu_array(ctx->block, sizeof(ctx->block) / sizeof(guint32));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
470 md4_transform(ctx->hash, ctx->block);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
471 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
472
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
473 static void
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
474 md4_init(GaimCipherContext *context, gpointer extra) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
475 struct MD4_Context *mctx;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
476 mctx = g_new0(struct MD4_Context, 1);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
477 gaim_cipher_context_set_data(context, mctx);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
478 gaim_cipher_context_reset(context, extra);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
479
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
480 mctx->hash[0] = 0x67452301;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
481 mctx->hash[1] = 0xefcdab89;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
482 mctx->hash[2] = 0x98badcfe;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
483 mctx->hash[3] = 0x10325476;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
484 mctx->byte_count = 0;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
485 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
486
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
487 static void
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
488 md4_reset(GaimCipherContext *context, gpointer extra) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
489 struct MD4_Context *mctx;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
490
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
491 mctx = gaim_cipher_context_get_data(context);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
492
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
493 mctx->hash[0] = 0x67452301;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
494 mctx->hash[1] = 0xefcdab89;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
495 mctx->hash[2] = 0x98badcfe;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
496 mctx->hash[3] = 0x10325476;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
497 mctx->byte_count = 0;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
498 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
499
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
500 static void
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
501 md4_append(GaimCipherContext *context, const guchar *data, size_t len)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
502 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
503 struct MD4_Context *mctx = gaim_cipher_context_get_data(context);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
504 const guint32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
505
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
506 mctx->byte_count += len;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
507
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
508 if (avail > len) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
509 memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
510 data, len);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
511 return;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
512 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
513
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
514 memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
515 data, avail);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
516
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
517 md4_transform_helper(mctx);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
518 data += avail;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
519 len -= avail;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
520
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
521 while (len >= sizeof(mctx->block)) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
522 memcpy(mctx->block, data, sizeof(mctx->block));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
523 md4_transform_helper(mctx);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
524 data += sizeof(mctx->block);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
525 len -= sizeof(mctx->block);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
526 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
527
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
528 memcpy(mctx->block, data, len);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
529 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
530
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
531 static gboolean
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
532 md4_digest(GaimCipherContext *context, size_t in_len, guchar *out,
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
533 size_t *out_len)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
534 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
535 struct MD4_Context *mctx = gaim_cipher_context_get_data(context);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
536 const unsigned int offset = mctx->byte_count & 0x3f;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
537 char *p = (char *)mctx->block + offset;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
538 int padding = 56 - (offset + 1);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
539
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
540
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
541 if(in_len<16) return FALSE;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
542 if(out_len) *out_len = 16;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
543 *p++ = 0x80;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
544 if (padding < 0) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
545 memset(p, 0x00, padding + sizeof (guint64));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
546 md4_transform_helper(mctx);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
547 p = (char *)mctx->block;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
548 padding = 56;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
549 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
550
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
551 memset(p, 0, padding);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
552 mctx->block[14] = mctx->byte_count << 3;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
553 mctx->block[15] = mctx->byte_count >> 29;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
554 le32_to_cpu_array(mctx->block, (sizeof(mctx->block) -
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
555 sizeof(guint64)) / sizeof(guint32));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
556 md4_transform(mctx->hash, mctx->block);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
557 cpu_to_le32_array(mctx->hash, sizeof(mctx->hash) / sizeof(guint32));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
558 memcpy(out, mctx->hash, sizeof(mctx->hash));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
559 memset(mctx, 0, sizeof(*mctx));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
560 return TRUE;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
561 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
562
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
563 static void
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
564 md4_uninit(GaimCipherContext *context) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
565 struct MD4_Context *md4_context;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
566
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
567 gaim_cipher_context_reset(context, NULL);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
568
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
569 md4_context = gaim_cipher_context_get_data(context);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
570 memset(md4_context, 0, sizeof(md4_context));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
571
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
572 g_free(md4_context);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
573 md4_context = NULL;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
574 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
575
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
576 static GaimCipherOps MD4Ops = {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
577 NULL, /* Set option */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
578 NULL, /* Get option */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
579 md4_init, /* init */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
580 md4_reset, /* reset */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
581 md4_uninit, /* uninit */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
582 NULL, /* set iv */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
583 md4_append, /* append */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
584 md4_digest, /* digest */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
585 NULL, /* encrypt */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
586 NULL, /* decrypt */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
587 NULL, /* set salt */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
588 NULL, /* get salt size */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
589 NULL, /* set key */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
590 NULL /* get key size */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
591 };
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
592
11335
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
593 /******************************************************************************
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
594 * DES
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
595 *****************************************************************************/
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
596
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
597 typedef struct _des_ctx
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
598 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
599 guint32 encrypt_subkeys[32];
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
600 guint32 decrypt_subkeys[32];
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
601 } des_ctx[1];
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
602
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
603 /*
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
604 * The s-box values are permuted according to the 'primitive function P'
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
605 */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
606 static guint32 sbox1[64] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
607 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
608 0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
609 0x00000200, 0x00808200, 0x00808202, 0x00000200, 0x00800202, 0x00808002, 0x00800000, 0x00000002,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
610 0x00000202, 0x00800200, 0x00800200, 0x00008200, 0x00008200, 0x00808000, 0x00808000, 0x00800202,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
611 0x00008002, 0x00800002, 0x00800002, 0x00008002, 0x00000000, 0x00000202, 0x00008202, 0x00800000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
612 0x00008000, 0x00808202, 0x00000002, 0x00808000, 0x00808200, 0x00800000, 0x00800000, 0x00000200,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
613 0x00808002, 0x00008000, 0x00008200, 0x00800002, 0x00000200, 0x00000002, 0x00800202, 0x00008202,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
614 0x00808202, 0x00008002, 0x00808000, 0x00800202, 0x00800002, 0x00000202, 0x00008202, 0x00808200,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
615 0x00000202, 0x00800200, 0x00800200, 0x00000000, 0x00008002, 0x00008200, 0x00000000, 0x00808002
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
616 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
617
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
618 static guint32 sbox2[64] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
619 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
620 0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x00080000, 0x00000010, 0x40080010, 0x40004010,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
621 0x40000010, 0x40084010, 0x40084000, 0x40000000, 0x40004000, 0x00080000, 0x00000010, 0x40080010,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
622 0x00084000, 0x00080010, 0x40004010, 0x00000000, 0x40000000, 0x00004000, 0x00084010, 0x40080000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
623 0x00080010, 0x40000010, 0x00000000, 0x00084000, 0x00004010, 0x40084000, 0x40080000, 0x00004010,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
624 0x00000000, 0x00084010, 0x40080010, 0x00080000, 0x40004010, 0x40080000, 0x40084000, 0x00004000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
625 0x40080000, 0x40004000, 0x00000010, 0x40084010, 0x00084010, 0x00000010, 0x00004000, 0x40000000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
626 0x00004010, 0x40084000, 0x00080000, 0x40000010, 0x00080010, 0x40004010, 0x40000010, 0x00080010,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
627 0x00084000, 0x00000000, 0x40004000, 0x00004010, 0x40000000, 0x40080010, 0x40084010, 0x00084000
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
628 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
629
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
630 static guint32 sbox3[64] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
631 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
632 0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x04000100, 0x00000000, 0x00010104, 0x04000100,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
633 0x00010004, 0x04000004, 0x04000004, 0x00010000, 0x04010104, 0x00010004, 0x04010000, 0x00000104,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
634 0x04000000, 0x00000004, 0x04010100, 0x00000100, 0x00010100, 0x04010000, 0x04010004, 0x00010104,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
635 0x04000104, 0x00010100, 0x00010000, 0x04000104, 0x00000004, 0x04010104, 0x00000100, 0x04000000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
636 0x04010100, 0x04000000, 0x00010004, 0x00000104, 0x00010000, 0x04010100, 0x04000100, 0x00000000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
637 0x00000100, 0x00010004, 0x04010104, 0x04000100, 0x04000004, 0x00000100, 0x00000000, 0x04010004,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
638 0x04000104, 0x00010000, 0x04000000, 0x04010104, 0x00000004, 0x00010104, 0x00010100, 0x04000004,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
639 0x04010000, 0x04000104, 0x00000104, 0x04010000, 0x00010104, 0x00000004, 0x04010004, 0x00010100
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
640 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
641
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
642 static guint32 sbox4[64] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
643 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
644 0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x00401040, 0x80400040, 0x80400000, 0x80001000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
645 0x00000000, 0x00401000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00400040, 0x80400000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
646 0x80000000, 0x00001000, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x80001000, 0x00001040,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
647 0x80400040, 0x80000000, 0x00001040, 0x00400040, 0x00001000, 0x00401040, 0x80401040, 0x80000040,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
648 0x00400040, 0x80400000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00000000, 0x00401000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
649 0x00001040, 0x00400040, 0x80400040, 0x80000000, 0x80401000, 0x80001040, 0x80001040, 0x00000040,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
650 0x80401040, 0x80000040, 0x80000000, 0x00001000, 0x80400000, 0x80001000, 0x00401040, 0x80400040,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
651 0x80001000, 0x00001040, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x00001000, 0x00401040
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
652 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
653
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
654 static guint32 sbox5[64] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
655 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
656 0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00040000, 0x00000080, 0x20000000, 0x01040000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
657 0x20040080, 0x00040000, 0x01000080, 0x20040080, 0x21000080, 0x21040000, 0x00040080, 0x20000000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
658 0x01000000, 0x20040000, 0x20040000, 0x00000000, 0x20000080, 0x21040080, 0x21040080, 0x01000080,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
659 0x21040000, 0x20000080, 0x00000000, 0x21000000, 0x01040080, 0x01000000, 0x21000000, 0x00040080,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
660 0x00040000, 0x21000080, 0x00000080, 0x01000000, 0x20000000, 0x01040000, 0x21000080, 0x20040080,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
661 0x01000080, 0x20000000, 0x21040000, 0x01040080, 0x20040080, 0x00000080, 0x01000000, 0x21040000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
662 0x21040080, 0x00040080, 0x21000000, 0x21040080, 0x01040000, 0x00000000, 0x20040000, 0x21000000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
663 0x00040080, 0x01000080, 0x20000080, 0x00040000, 0x00000000, 0x20040000, 0x01040080, 0x20000080
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
664 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
665
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
666 static guint32 sbox6[64] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
667 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
668 0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10200000, 0x00000008, 0x10202008, 0x00200000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
669 0x10002000, 0x00202008, 0x00200000, 0x10000008, 0x00200008, 0x10002000, 0x10000000, 0x00002008,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
670 0x00000000, 0x00200008, 0x10002008, 0x00002000, 0x00202000, 0x10002008, 0x00000008, 0x10200008,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
671 0x10200008, 0x00000000, 0x00202008, 0x10202000, 0x00002008, 0x00202000, 0x10202000, 0x10000000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
672 0x10002000, 0x00000008, 0x10200008, 0x00202000, 0x10202008, 0x00200000, 0x00002008, 0x10000008,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
673 0x00200000, 0x10002000, 0x10000000, 0x00002008, 0x10000008, 0x10202008, 0x00202000, 0x10200000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
674 0x00202008, 0x10202000, 0x00000000, 0x10200008, 0x00000008, 0x00002000, 0x10200000, 0x00202008,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
675 0x00002000, 0x00200008, 0x10002008, 0x00000000, 0x10202000, 0x10000000, 0x00200008, 0x10002008
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
676 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
677
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
678 static guint32 sbox7[64] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
679 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
680 0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00000400, 0x02000401, 0x00100401, 0x02100400,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
681 0x02100401, 0x00100000, 0x00000000, 0x02000001, 0x00000001, 0x02000000, 0x02100001, 0x00000401,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
682 0x02000400, 0x00100401, 0x00100001, 0x02000400, 0x02000001, 0x02100000, 0x02100400, 0x00100001,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
683 0x02100000, 0x00000400, 0x00000401, 0x02100401, 0x00100400, 0x00000001, 0x02000000, 0x00100400,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
684 0x02000000, 0x00100400, 0x00100000, 0x02000401, 0x02000401, 0x02100001, 0x02100001, 0x00000001,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
685 0x00100001, 0x02000000, 0x02000400, 0x00100000, 0x02100400, 0x00000401, 0x00100401, 0x02100400,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
686 0x00000401, 0x02000001, 0x02100401, 0x02100000, 0x00100400, 0x00000000, 0x00000001, 0x02100401,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
687 0x00000000, 0x00100401, 0x02100000, 0x00000400, 0x02000001, 0x02000400, 0x00000400, 0x00100001
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
688 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
689
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
690 static guint32 sbox8[64] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
691 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
692 0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000000, 0x08000820, 0x00000020, 0x08000000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
693 0x00020020, 0x08020000, 0x08020820, 0x00020800, 0x08020800, 0x00020820, 0x00000800, 0x00000020,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
694 0x08020000, 0x08000020, 0x08000800, 0x00000820, 0x00020800, 0x00020020, 0x08020020, 0x08020800,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
695 0x00000820, 0x00000000, 0x00000000, 0x08020020, 0x08000020, 0x08000800, 0x00020820, 0x00020000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
696 0x00020820, 0x00020000, 0x08020800, 0x00000800, 0x00000020, 0x08020020, 0x00000800, 0x00020820,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
697 0x08000800, 0x00000020, 0x08000020, 0x08020000, 0x08020020, 0x08000000, 0x00020000, 0x08000820,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
698 0x00000000, 0x08020820, 0x00020020, 0x08000020, 0x08020000, 0x08000800, 0x08000820, 0x00000000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
699 0x08020820, 0x00020800, 0x00020800, 0x00000820, 0x00000820, 0x00020020, 0x08000000, 0x08020800
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
700 };
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 * * These two tables are part of the 'permuted choice 1' function.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
706 * * In this implementation several speed improvements are done.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
707 * */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
708 guint32 leftkey_swap[16] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
709 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
710 0x00000000, 0x00000001, 0x00000100, 0x00000101,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
711 0x00010000, 0x00010001, 0x00010100, 0x00010101,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
712 0x01000000, 0x01000001, 0x01000100, 0x01000101,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
713 0x01010000, 0x01010001, 0x01010100, 0x01010101
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
714 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
715
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
716 guint32 rightkey_swap[16] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
717 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
718 0x00000000, 0x01000000, 0x00010000, 0x01010000,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
719 0x00000100, 0x01000100, 0x00010100, 0x01010100,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
720 0x00000001, 0x01000001, 0x00010001, 0x01010001,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
721 0x00000101, 0x01000101, 0x00010101, 0x01010101,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
722 };
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 * Numbers of left shifts per round for encryption subkey schedule
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
728 * To calculate the decryption key scheduling we just reverse the
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
729 * ordering of the subkeys so we can omit the table for decryption
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
730 * subkey schedule.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
731 */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
732 static guint8 encrypt_rotate_tab[16] =
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
733 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
734 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
735 };
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 * Macro to swap bits across two words
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
739 **/
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
740 #define DO_PERMUTATION(a, temp, b, offset, mask) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
741 temp = ((a>>offset) ^ b) & mask; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
742 b ^= temp; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
743 a ^= temp<<offset;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
744
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 * This performs the 'initial permutation' for the data to be encrypted or decrypted
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
748 **/
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
749 #define INITIAL_PERMUTATION(left, temp, right) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
750 DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
751 DO_PERMUTATION(left, temp, right, 16, 0x0000ffff) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
752 DO_PERMUTATION(right, temp, left, 2, 0x33333333) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
753 DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
754 DO_PERMUTATION(left, temp, right, 1, 0x55555555)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
755
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 * The 'inverse initial permutation'
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
759 **/
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
760 #define FINAL_PERMUTATION(left, temp, right) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
761 DO_PERMUTATION(left, temp, right, 1, 0x55555555) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
762 DO_PERMUTATION(right, temp, left, 8, 0x00ff00ff) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
763 DO_PERMUTATION(right, temp, left, 2, 0x33333333) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
764 DO_PERMUTATION(left, temp, right, 16, 0x0000ffff) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
765 DO_PERMUTATION(left, temp, right, 4, 0x0f0f0f0f)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
766
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 * A full DES round including 'expansion function', 'sbox substitution'
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
770 * and 'primitive function P' but without swapping the left and right word.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
771 **/
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
772 #define DES_ROUND(from, to, work, subkey) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
773 work = ((from<<1) | (from>>31)) ^ *subkey++; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
774 to ^= sbox8[ work & 0x3f ]; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
775 to ^= sbox6[ (work>>8) & 0x3f ]; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
776 to ^= sbox4[ (work>>16) & 0x3f ]; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
777 to ^= sbox2[ (work>>24) & 0x3f ]; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
778 work = ((from>>3) | (from<<29)) ^ *subkey++; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
779 to ^= sbox7[ work & 0x3f ]; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
780 to ^= sbox5[ (work>>8) & 0x3f ]; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
781 to ^= sbox3[ (work>>16) & 0x3f ]; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
782 to ^= sbox1[ (work>>24) & 0x3f ];
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
783
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 * Macros to convert 8 bytes from/to 32bit words
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
787 **/
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
788 #define READ_64BIT_DATA(data, left, right) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
789 left = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
790 right = (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | data[7];
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
791
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
792 #define WRITE_64BIT_DATA(data, left, right) \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
793 data[0] = (left >> 24) &0xff; data[1] = (left >> 16) &0xff; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
794 data[2] = (left >> 8) &0xff; data[3] = left &0xff; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
795 data[4] = (right >> 24) &0xff; data[5] = (right >> 16) &0xff; \
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
796 data[6] = (right >> 8) &0xff; data[7] = right &0xff;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
797
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 * des_key_schedule(): Calculate 16 subkeys pairs (even/odd) for
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
805 * 16 encryption rounds.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
806 * To calculate subkeys for decryption the caller
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
807 * have to reorder the generated subkeys.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
808 *
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
809 * rawkey: 8 Bytes of key data
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
810 * subkey: Array of at least 32 guint32s. Will be filled
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
811 * with calculated subkeys.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
812 *
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
813 **/
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
814 static void
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
815 des_key_schedule (const guint8 * rawkey, guint32 * subkey)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
816 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
817 guint32 left, right, work;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
818 int round;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
819
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
820 READ_64BIT_DATA (rawkey, left, right)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
821
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
822 DO_PERMUTATION (right, work, left, 4, 0x0f0f0f0f)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
823 DO_PERMUTATION (right, work, left, 0, 0x10101010)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
824
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
825 left = (leftkey_swap[(left >> 0) & 0xf] << 3) | (leftkey_swap[(left >> 8) & 0xf] << 2)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
826 | (leftkey_swap[(left >> 16) & 0xf] << 1) | (leftkey_swap[(left >> 24) & 0xf])
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
827 | (leftkey_swap[(left >> 5) & 0xf] << 7) | (leftkey_swap[(left >> 13) & 0xf] << 6)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
828 | (leftkey_swap[(left >> 21) & 0xf] << 5) | (leftkey_swap[(left >> 29) & 0xf] << 4);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
829
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
830 left &= 0x0fffffff;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
831
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
832 right = (rightkey_swap[(right >> 1) & 0xf] << 3) | (rightkey_swap[(right >> 9) & 0xf] << 2)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
833 | (rightkey_swap[(right >> 17) & 0xf] << 1) | (rightkey_swap[(right >> 25) & 0xf])
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
834 | (rightkey_swap[(right >> 4) & 0xf] << 7) | (rightkey_swap[(right >> 12) & 0xf] << 6)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
835 | (rightkey_swap[(right >> 20) & 0xf] << 5) | (rightkey_swap[(right >> 28) & 0xf] << 4);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
836
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
837 right &= 0x0fffffff;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
838
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
839 for (round = 0; round < 16; ++round)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
840 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
841 left = ((left << encrypt_rotate_tab[round]) | (left >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
842 right = ((right << encrypt_rotate_tab[round]) | (right >> (28 - encrypt_rotate_tab[round]))) & 0x0fffffff;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
843
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
844 *subkey++ = ((left << 4) & 0x24000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
845 | ((left << 28) & 0x10000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
846 | ((left << 14) & 0x08000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
847 | ((left << 18) & 0x02080000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
848 | ((left << 6) & 0x01000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
849 | ((left << 9) & 0x00200000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
850 | ((left >> 1) & 0x00100000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
851 | ((left << 10) & 0x00040000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
852 | ((left << 2) & 0x00020000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
853 | ((left >> 10) & 0x00010000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
854 | ((right >> 13) & 0x00002000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
855 | ((right >> 4) & 0x00001000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
856 | ((right << 6) & 0x00000800)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
857 | ((right >> 1) & 0x00000400)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
858 | ((right >> 14) & 0x00000200)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
859 | (right & 0x00000100)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
860 | ((right >> 5) & 0x00000020)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
861 | ((right >> 10) & 0x00000010)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
862 | ((right >> 3) & 0x00000008)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
863 | ((right >> 18) & 0x00000004)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
864 | ((right >> 26) & 0x00000002)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
865 | ((right >> 24) & 0x00000001);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
866
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
867 *subkey++ = ((left << 15) & 0x20000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
868 | ((left << 17) & 0x10000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
869 | ((left << 10) & 0x08000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
870 | ((left << 22) & 0x04000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
871 | ((left >> 2) & 0x02000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
872 | ((left << 1) & 0x01000000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
873 | ((left << 16) & 0x00200000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
874 | ((left << 11) & 0x00100000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
875 | ((left << 3) & 0x00080000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
876 | ((left >> 6) & 0x00040000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
877 | ((left << 15) & 0x00020000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
878 | ((left >> 4) & 0x00010000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
879 | ((right >> 2) & 0x00002000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
880 | ((right << 8) & 0x00001000)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
881 | ((right >> 14) & 0x00000808)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
882 | ((right >> 9) & 0x00000400)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
883 | ((right) & 0x00000200)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
884 | ((right << 7) & 0x00000100)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
885 | ((right >> 7) & 0x00000020)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
886 | ((right >> 3) & 0x00000011)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
887 | ((right << 2) & 0x00000004)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
888 | ((right >> 21) & 0x00000002);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
889 }
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 * Fill a DES context with subkeys calculated from a 64bit key.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
896 * Does not check parity bits, but simply ignore them.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
897 * Does not check for weak keys.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
898 **/
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
899 void
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
900 des_setkey (GaimCipherContext *context, guchar * key)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
901 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
902 struct _des_ctx *ctx = gaim_cipher_context_get_data(context);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
903 int i;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
904
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
905 des_key_schedule (key, ctx->encrypt_subkeys);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
906
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
907 for(i=0; i<32; i+=2)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
908 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
909 ctx->decrypt_subkeys[i] = ctx->encrypt_subkeys[30-i];
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
910 ctx->decrypt_subkeys[i+1] = ctx->encrypt_subkeys[31-i];
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
911 }
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 * Electronic Codebook Mode DES encryption/decryption of data according
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
918 * to 'mode'.
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
919 **/
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
920 int
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
921 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
922 {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
923 guint32 left, right, work;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
924 guint32 *keys;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
925
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
926 keys = mode ? ctx->decrypt_subkeys : ctx->encrypt_subkeys;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
927
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
928 READ_64BIT_DATA (from, left, right)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
929 INITIAL_PERMUTATION (left, work, right)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
930
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
931 DES_ROUND (right, left, work, keys) DES_ROUND (left, right, work, keys)
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
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
940 FINAL_PERMUTATION (right, work, left)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
941 WRITE_64BIT_DATA (to, right, left)
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
942
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
943 return 0;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
944 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
945
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
946 gint des_encrypt(GaimCipherContext *context, const guchar data[], size_t len, guchar output[], size_t *outlen) {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
947 int offset = 0;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
948 int i = 0;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
949 int tmp;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
950 guint8 buf[8] = {0,0,0,0,0,0,0,0};
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
951 while(offset+8<=len) {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
952 des_ecb_crypt(gaim_cipher_context_get_data(context),
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
953 data+offset,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
954 output+offset,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
955 0);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
956 offset+=8;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
957 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
958 *outlen = len;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
959 if(offset<len) {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
960 *outlen += len - offset;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
961 tmp = offset;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
962 while(tmp<len) {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
963 buf[i++] = data[tmp];
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
964 tmp++;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
965 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
966 des_ecb_crypt(gaim_cipher_context_get_data(context),
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
967 buf,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
968 output+offset,
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
969 0);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
970 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
971 return 0;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
972 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
973
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
974 static void
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
975 des_init(GaimCipherContext *context, gpointer extra) {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
976 struct _des_ctx *mctx;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
977 mctx = g_new0(struct _des_ctx, 1);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
978 gaim_cipher_context_set_data(context, mctx);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
979 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
980
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
981 static void
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
982 des_uninit(GaimCipherContext *context) {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
983 struct _des_ctx *des_context;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
984
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
985 des_context = gaim_cipher_context_get_data(context);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
986 memset(des_context, 0, sizeof(des_context));
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
987
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
988 g_free(des_context);
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
989 des_context = NULL;
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
990 }
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
991
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
992 static GaimCipherOps DESOps = {
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
993 NULL, /* Set option */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
994 NULL, /* Get option */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
995 des_init, /* init */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
996 NULL, /* reset */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
997 des_uninit, /* uninit */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
998 NULL, /* set iv */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
999 NULL, /* append */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1000 NULL, /* digest */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1001 des_encrypt, /* encrypt */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1002 NULL, /* decrypt */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1003 NULL, /* set salt */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1004 NULL, /* get salt size */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1005 des_setkey, /* set key */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1006 NULL /* get key size */
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1007 };
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1008
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1009
11329
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
1010 /*******************************************************************************
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1011 * SHA-1
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1012 ******************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1013 #define SHA1_ROTL(X,n) ((((X) << (n)) | ((X) >> (32-(n)))) & 0xFFFFFFFF)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1014
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1015 struct SHA1Context {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1016 guint32 H[5];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1017 guint32 W[80];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1018
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1019 gint lenW;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1020
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1021 guint32 sizeHi;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1022 guint32 sizeLo;
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
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1025 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1026 sha1_hash_block(struct SHA1Context *sha1_ctx) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1027 gint i;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1028 guint32 A, B, C, D, E, T;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1029
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1030 for(i = 16; i < 80; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1031 sha1_ctx->W[i] = SHA1_ROTL(sha1_ctx->W[i - 3] ^
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1032 sha1_ctx->W[i - 8] ^
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1033 sha1_ctx->W[i - 14] ^
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1034 sha1_ctx->W[i - 16], 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1035 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1036
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1037 A = sha1_ctx->H[0];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1038 B = sha1_ctx->H[1];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1039 C = sha1_ctx->H[2];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1040 D = sha1_ctx->H[3];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1041 E = sha1_ctx->H[4];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1042
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1043 for(i = 0; i < 20; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1044 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
1045 E = D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1046 D = C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1047 C = SHA1_ROTL(B, 30);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1048 B = A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1049 A = T;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1050 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1051
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1052 for(i = 20; i < 40; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1053 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
1054 E = D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1055 D = C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1056 C = SHA1_ROTL(B, 30);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1057 B = A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1058 A = T;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1059 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1060
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1061 for(i = 40; i < 60; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1062 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
1063 E = D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1064 D = C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1065 C = SHA1_ROTL(B, 30);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1066 B = A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1067 A = T;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1068 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1069
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1070 for(i = 60; i < 80; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1071 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
1072 E = D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1073 D = C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1074 C = SHA1_ROTL(B, 30);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1075 B = A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1076 A = T;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1077 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1078
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1079 sha1_ctx->H[0] += A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1080 sha1_ctx->H[1] += B;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1081 sha1_ctx->H[2] += C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1082 sha1_ctx->H[3] += D;
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1083 sha1_ctx->H[4] += E;
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1084 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1085
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1086 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1087 sha1_set_opt(GaimCipherContext *context, const gchar *name, void *value) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1088 struct SHA1Context *ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1089
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1090 ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1091
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1092 if(!strcmp(name, "sizeHi")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1093 ctx->sizeHi = GPOINTER_TO_INT(value);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1094 } else if(!strcmp(name, "sizeLo")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1095 ctx->sizeLo = GPOINTER_TO_INT(value);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1096 } else if(!strcmp(name, "lenW")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1097 ctx->lenW = GPOINTER_TO_INT(value);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1098 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1099 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1100
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1101 static void *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1102 sha1_get_opt(GaimCipherContext *context, const gchar *name) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1103 struct SHA1Context *ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1104
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1105 ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1106
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1107 if(!strcmp(name, "sizeHi")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1108 return GINT_TO_POINTER(ctx->sizeHi);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1109 } else if(!strcmp(name, "sizeLo")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1110 return GINT_TO_POINTER(ctx->sizeLo);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1111 } else if(!strcmp(name, "lenW")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1112 return GINT_TO_POINTER(ctx->lenW);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1113 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1114
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1115 return NULL;
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 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1119 sha1_init(GaimCipherContext *context, void *extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1120 struct SHA1Context *sha1_ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1121
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1122 sha1_ctx = g_new0(struct SHA1Context, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1123
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1124 gaim_cipher_context_set_data(context, sha1_ctx);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1125
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1126 gaim_cipher_context_reset(context, extra);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1127 }
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 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1130 sha1_reset(GaimCipherContext *context, void *extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1131 struct SHA1Context *sha1_ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1132 gint i;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1133
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1134 sha1_ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1135
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1136 g_return_if_fail(sha1_ctx);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1137
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1138 sha1_ctx->lenW = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1139 sha1_ctx->sizeHi = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1140 sha1_ctx->sizeLo = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1141
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1142 sha1_ctx->H[0] = 0x67452301;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1143 sha1_ctx->H[1] = 0xEFCDAB89;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1144 sha1_ctx->H[2] = 0x98BADCFE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1145 sha1_ctx->H[3] = 0x10325476;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1146 sha1_ctx->H[4] = 0xC3D2E1F0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1147
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1148 for(i = 0; i < 80; i++)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1149 sha1_ctx->W[i] = 0;
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
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1152 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1153 sha1_uninit(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1154 struct SHA1Context *sha1_ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1155
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1156 gaim_cipher_context_reset(context, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1157
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1158 sha1_ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1159
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1160 memset(sha1_ctx, 0, sizeof(struct SHA1Context));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1161
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1162 g_free(sha1_ctx);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1163 sha1_ctx = NULL;
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
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1166
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1167 static void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1168 sha1_append(GaimCipherContext *context, const guchar *data, size_t len) {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1169 struct SHA1Context *sha1_ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1170 gint i;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1171
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1172 sha1_ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1173
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1174 g_return_if_fail(sha1_ctx);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1175
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1176 for(i = 0; i < len; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1177 sha1_ctx->W[sha1_ctx->lenW / 4] <<= 8;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1178 sha1_ctx->W[sha1_ctx->lenW / 4] |= data[i];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1179
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1180 if((++sha1_ctx->lenW) % 64 == 0) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1181 sha1_hash_block(sha1_ctx);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1182 sha1_ctx->lenW = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1183 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1184
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1185 sha1_ctx->sizeLo += 8;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1186 sha1_ctx->sizeHi += (sha1_ctx->sizeLo < 8);
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 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1189
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1190 static gboolean
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1191 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
1192 size_t *out_len)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1193 {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1194 struct SHA1Context *sha1_ctx;
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1195 guchar pad0x80 = 0x80, pad0x00 = 0x00;
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1196 guchar padlen[8];
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1197 gint i;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1198
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1199 g_return_val_if_fail(in_len >= 20, FALSE);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1200
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1201 sha1_ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1202
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1203 g_return_val_if_fail(sha1_ctx, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1204
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1205 padlen[0] = (guchar)((sha1_ctx->sizeHi >> 24) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1206 padlen[1] = (guchar)((sha1_ctx->sizeHi >> 16) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1207 padlen[2] = (guchar)((sha1_ctx->sizeHi >> 8) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1208 padlen[3] = (guchar)((sha1_ctx->sizeHi >> 0) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1209 padlen[4] = (guchar)((sha1_ctx->sizeLo >> 24) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1210 padlen[5] = (guchar)((sha1_ctx->sizeLo >> 16) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1211 padlen[6] = (guchar)((sha1_ctx->sizeLo >> 8) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1212 padlen[7] = (guchar)((sha1_ctx->sizeLo >> 0) & 255);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1213
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1214 /* pad with a 1, then zeroes, then length */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1215 gaim_cipher_context_append(context, &pad0x80, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1216 while(sha1_ctx->lenW != 56)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1217 gaim_cipher_context_append(context, &pad0x00, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1218 gaim_cipher_context_append(context, padlen, 8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1219
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1220 for(i = 0; i < 20; i++) {
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1221 digest[i] = (guchar)(sha1_ctx->H[i / 4] >> 24);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1222 sha1_ctx->H[i / 4] <<= 8;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1223 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1224
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1225 gaim_cipher_context_reset(context, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1226
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1227 if(out_len)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1228 *out_len = 20;
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1229
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1230 return TRUE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1231 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1232
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1233 static GaimCipherOps SHA1Ops = {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1234 sha1_set_opt, /* Set Option */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1235 sha1_get_opt, /* Get Option */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1236 sha1_init, /* init */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1237 sha1_reset, /* reset */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1238 sha1_uninit, /* uninit */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1239 NULL, /* set iv */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1240 sha1_append, /* append */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1241 sha1_digest, /* digest */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1242 NULL, /* encrypt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1243 NULL, /* decrypt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1244 NULL, /* set salt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1245 NULL, /* get salt size */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1246 NULL, /* set key */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1247 NULL /* get key size */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1248 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1249
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1250 /*******************************************************************************
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1251 * Structs
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 struct _GaimCipher {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1254 gchar *name;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1255 GaimCipherOps *ops;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1256 guint ref;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1257 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1258
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1259 struct _GaimCipherContext {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1260 GaimCipher *cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1261 gpointer data;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1262 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1263
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1264 /******************************************************************************
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1265 * Globals
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 static GList *ciphers = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1268
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 * GaimCipher API
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 const gchar *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1273 gaim_cipher_get_name(GaimCipher *cipher) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1274 g_return_val_if_fail(cipher, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1275
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1276 return cipher->name;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1277 }
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 guint
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1280 gaim_cipher_get_capabilities(GaimCipher *cipher) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1281 GaimCipherOps *ops = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1282 guint caps = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1283
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1284 g_return_val_if_fail(cipher, 0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1285
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1286 ops = cipher->ops;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1287 g_return_val_if_fail(ops, 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 if(ops->set_option)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1290 caps |= GAIM_CIPHER_CAPS_SET_OPT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1291 if(ops->get_option)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1292 caps |= GAIM_CIPHER_CAPS_GET_OPT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1293 if(ops->init)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1294 caps |= GAIM_CIPHER_CAPS_INIT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1295 if(ops->reset)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1296 caps |= GAIM_CIPHER_CAPS_RESET;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1297 if(ops->uninit)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1298 caps |= GAIM_CIPHER_CAPS_UNINIT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1299 if(ops->set_iv)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1300 caps |= GAIM_CIPHER_CAPS_SET_IV;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1301 if(ops->append)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1302 caps |= GAIM_CIPHER_CAPS_APPEND;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1303 if(ops->digest)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1304 caps |= GAIM_CIPHER_CAPS_DIGEST;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1305 if(ops->encrypt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1306 caps |= GAIM_CIPHER_CAPS_ENCRYPT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1307 if(ops->decrypt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1308 caps |= GAIM_CIPHER_CAPS_DECRYPT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1309 if(ops->set_salt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1310 caps |= GAIM_CIPHER_CAPS_SET_SALT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1311 if(ops->get_salt_size)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1312 caps |= GAIM_CIPHER_CAPS_GET_SALT_SIZE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1313 if(ops->set_key)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1314 caps |= GAIM_CIPHER_CAPS_SET_KEY;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1315 if(ops->get_key_size)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1316 caps |= GAIM_CIPHER_CAPS_GET_KEY_SIZE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1317
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1318 return caps;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1319 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1320
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1321 gboolean
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1322 gaim_cipher_digest_region(const gchar *name, const guchar *data,
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1323 size_t data_len, size_t in_len,
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1324 guchar digest[], size_t *out_len)
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1325 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1326 GaimCipher *cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1327 GaimCipherContext *context;
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1328 gboolean ret = FALSE;
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1329
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1330 g_return_val_if_fail(name, FALSE);
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1331 g_return_val_if_fail(data, FALSE);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1332
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1333 cipher = gaim_ciphers_find_cipher(name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1334
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1335 g_return_val_if_fail(cipher, FALSE);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1336
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1337 if(!cipher->ops->append || !cipher->ops->digest) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1338 gaim_debug_info("cipher", "gaim_cipher_region failed: "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1339 "the %s cipher does not support appending and or "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1340 "digesting.", cipher->name);
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1341 return FALSE;
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1342 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1343
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1344 context = gaim_cipher_context_new(cipher, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1345 gaim_cipher_context_append(context, data, data_len);
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1346 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
1347 gaim_cipher_context_destroy(context);
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1348
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1349 return ret;
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1350 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1351
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1352 /******************************************************************************
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1353 * GaimCiphers API
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 GaimCipher *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1356 gaim_ciphers_find_cipher(const gchar *name) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1357 GaimCipher *cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1358 GList *l;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1359
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1360 g_return_val_if_fail(name, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1361
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1362 for(l = ciphers; l; l = l->next) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1363 cipher = GAIM_CIPHER(l->data);
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 if(!g_ascii_strcasecmp(cipher->name, name))
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1366 return cipher;
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
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1369 return NULL;
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 GaimCipher *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1373 gaim_ciphers_register_cipher(const gchar *name, GaimCipherOps *ops) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1374 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1375
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1376 g_return_val_if_fail(name, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1377 g_return_val_if_fail(ops, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1378 g_return_val_if_fail(!gaim_ciphers_find_cipher(name), NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1379
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1380 cipher = g_new0(GaimCipher, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1381
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1382 cipher->name = g_strdup(name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1383 cipher->ops = ops;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1384
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1385 ciphers = g_list_append(ciphers, cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1386
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1387 gaim_signal_emit(gaim_ciphers_get_handle(), "cipher-added", cipher);
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 return 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
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1392 gboolean
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1393 gaim_ciphers_unregister_cipher(GaimCipher *cipher) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1394 g_return_val_if_fail(cipher, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1395 g_return_val_if_fail(cipher->ref == 0, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1396
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1397 gaim_signal_emit(gaim_ciphers_get_handle(), "cipher-removed", cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1398
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1399 ciphers = g_list_remove(ciphers, cipher);
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 g_free(cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1402 g_free(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1403
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1404 return TRUE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1405 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1406
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1407 GList *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1408 gaim_ciphers_get_ciphers() {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1409 return ciphers;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1410 }
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 * GaimCipher Subsystem API
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1414 *****************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1415 gpointer
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1416 gaim_ciphers_get_handle() {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1417 static gint handle;
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 return &handle;
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
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1422 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1423 gaim_ciphers_init() {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1424 gpointer handle;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1425
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1426 handle = gaim_ciphers_get_handle();
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 gaim_signal_register(handle, "cipher-added",
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1429 gaim_marshal_VOID__POINTER, NULL, 1,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1430 gaim_value_new(GAIM_TYPE_SUBTYPE,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1431 GAIM_SUBTYPE_CIPHER));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1432 gaim_signal_register(handle, "cipher-removed",
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1433 gaim_marshal_VOID__POINTER, NULL, 1,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1434 gaim_value_new(GAIM_TYPE_SUBTYPE,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1435 GAIM_SUBTYPE_CIPHER));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1436
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1437 gaim_ciphers_register_cipher("md5", &MD5Ops);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1438 gaim_ciphers_register_cipher("sha1", &SHA1Ops);
11329
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
1439 gaim_ciphers_register_cipher("md4", &MD4Ops);
11335
59aa7080eb2d [gaim-migrate @ 13548]
Thomas Butter <tbutter>
parents: 11333
diff changeset
1440 gaim_ciphers_register_cipher("des", &DESOps);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1441 }
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 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1444 gaim_ciphers_uninit() {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1445 GaimCipher *cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1446 GList *l, *ll;
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 for(l = ciphers; l; l = ll) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1449 ll = l->next;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1450
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1451 cipher = GAIM_CIPHER(l->data);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1452 gaim_ciphers_unregister_cipher(cipher);
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 ciphers = g_list_remove(ciphers, cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1455 }
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 g_list_free(ciphers);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1458
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1459 gaim_signals_unregister_by_instance(gaim_ciphers_get_handle());
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1460 }
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 * GaimCipherContext API
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1463 *****************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1464 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1465 gaim_cipher_context_set_option(GaimCipherContext *context, const gchar *name,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1466 gpointer value)
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 GaimCipher *cipher = NULL;
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 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1471 g_return_if_fail(name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1472
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1473 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1474 g_return_if_fail(cipher);
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 if(cipher->ops && cipher->ops->set_option)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1477 cipher->ops->set_option(context, name, value);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1478 else
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1479 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1480 "set_option operation\n", cipher->name);
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
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1483 gpointer
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1484 gaim_cipher_context_get_option(GaimCipherContext *context, const gchar *name) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1485 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1486
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1487 g_return_val_if_fail(context, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1488 g_return_val_if_fail(name, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1489
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1490 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1491 g_return_val_if_fail(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 if(cipher->ops && cipher->ops->get_option)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1494 return cipher->ops->get_option(context, name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1495 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1496 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1497 "get_option operation\n", cipher->name);
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 return NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1500 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1501 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1502
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1503 GaimCipherContext *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1504 gaim_cipher_context_new(GaimCipher *cipher, void *extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1505 GaimCipherContext *context = 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 g_return_val_if_fail(cipher, NULL);
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 cipher->ref++;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1510
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1511 context = g_new0(GaimCipherContext, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1512 context->cipher = cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1513
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1514 if(cipher->ops->init)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1515 cipher->ops->init(context, extra);
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 return context;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1518 }
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 GaimCipherContext *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1521 gaim_cipher_context_new_by_name(const gchar *name, void *extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1522 GaimCipher *cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1523
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1524 g_return_val_if_fail(name, NULL);
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 cipher = gaim_ciphers_find_cipher(name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1527
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1528 g_return_val_if_fail(cipher, NULL);
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 return gaim_cipher_context_new(cipher, extra);
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
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1533 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1534 gaim_cipher_context_reset(GaimCipherContext *context, void *extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1535 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1536
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1537 g_return_if_fail(context);
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 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1540 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1541
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1542 if(cipher->ops && cipher->ops->reset)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1543 context->cipher->ops->reset(context, extra);
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
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1546 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1547 gaim_cipher_context_destroy(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1548 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1549
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1550 g_return_if_fail(context);
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 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1553 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1554
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1555 cipher->ref--;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1556
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1557 if(cipher->ops && cipher->ops->uninit)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1558 cipher->ops->uninit(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1559
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1560 memset(context, 0, sizeof(context));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1561 g_free(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1562 context = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1563 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1564
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1565 void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1566 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
1567 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1568 GaimCipher *cipher = 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 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1571 g_return_if_fail(iv);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1572
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1573 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1574 g_return_if_fail(cipher);
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 if(cipher->ops && cipher->ops->set_iv)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1577 cipher->ops->set_iv(context, iv, len);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1578 else
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1579 gaim_debug_info("cipher", "the %s cipher does not support the set"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1580 "initialization vector operation\n", cipher->name);
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
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1583 void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1584 gaim_cipher_context_append(GaimCipherContext *context, const guchar *data,
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1585 size_t len)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1586 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1587 GaimCipher *cipher = NULL;
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 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1590
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1591 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1592 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1593
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1594 if(cipher->ops && cipher->ops->append)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1595 cipher->ops->append(context, data, len);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1596 else
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1597 gaim_debug_info("cipher", "the %s cipher does not support the append "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1598 "operation\n", cipher->name);
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
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1601 gboolean
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1602 gaim_cipher_context_digest(GaimCipherContext *context, size_t in_len,
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1603 guchar digest[], size_t *out_len)
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1604 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1605 GaimCipher *cipher = NULL;
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 g_return_val_if_fail(context, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1608
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1609 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1610 g_return_val_if_fail(context, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1611
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1612 if(cipher->ops && cipher->ops->digest)
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1613 return cipher->ops->digest(context, in_len, digest, out_len);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1614 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1615 gaim_debug_info("cipher", "the %s cipher does not support the digest "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1616 "operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1617 return FALSE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1618 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1619 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1620
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1621 gboolean
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1622 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
1623 gchar digest_s[], size_t *out_len)
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1624 {
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1625 /* 8k is a bit excessive, will tweak later. */
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1626 guchar digest[BUF_LEN * 4];
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1627 gint n = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1628 size_t dlen = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1629
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1630 g_return_val_if_fail(context, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1631 g_return_val_if_fail(digest_s, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1632
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1633 if(!gaim_cipher_context_digest(context, sizeof(digest), digest, &dlen))
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1634 return FALSE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1635
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1636 if(in_len < dlen * 2)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1637 return FALSE;
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1638
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1639 for(n = 0; n < dlen; n++)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1640 sprintf(digest_s + (n * 2), "%02x", digest[n]);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1641
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1642 digest_s[n * 2] = '\0';
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1643
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1644 if(out_len)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1645 *out_len = dlen * 2;
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1646
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1647 return TRUE;
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
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1650 gint
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1651 gaim_cipher_context_encrypt(GaimCipherContext *context, const guchar data[],
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1652 size_t len, guchar output[], size_t *outlen)
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1653 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1654 GaimCipher *cipher = NULL;
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 g_return_val_if_fail(context, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1657
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1658 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1659 g_return_val_if_fail(cipher, -1);
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 if(cipher->ops && cipher->ops->encrypt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1662 return cipher->ops->encrypt(context, data, len, output, outlen);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1663 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1664 gaim_debug_info("cipher", "the %s cipher does not support the encrypt"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1665 "operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1666
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1667 if(outlen)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1668 *outlen = -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1669
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1670 return -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1671 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1672 }
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 gint
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1675 gaim_cipher_context_decrypt(GaimCipherContext *context, const guchar data[],
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1676 size_t len, guchar output[], size_t *outlen)
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1677 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1678 GaimCipher *cipher = NULL;
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 g_return_val_if_fail(context, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1681
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1682 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1683 g_return_val_if_fail(cipher, -1);
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 if(cipher->ops && cipher->ops->decrypt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1686 return cipher->ops->decrypt(context, data, len, output, outlen);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1687 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1688 gaim_debug_info("cipher", "the %s cipher does not support the decrypt"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1689 "operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1690
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1691 if(outlen)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1692 *outlen = -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1693
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1694 return -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1695 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1696 }
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 void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1699 gaim_cipher_context_set_salt(GaimCipherContext *context, guchar *salt) {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1700 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1701
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1702 g_return_if_fail(context);
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 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1705 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1706
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1707 if(cipher->ops && cipher->ops->set_salt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1708 cipher->ops->set_salt(context, salt);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1709 else
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1710 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1711 "set_salt operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1712 }
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 size_t
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1715 gaim_cipher_context_get_salt_size(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1716 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1717
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1718 g_return_val_if_fail(context, -1);
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 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1721 g_return_val_if_fail(cipher, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1722
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1723 if(cipher->ops && cipher->ops->get_salt_size)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1724 return cipher->ops->get_salt_size(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1725 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1726 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1727 "get_salt_size operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1728
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1729 return -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1730 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1731 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1732
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1733 void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1734 gaim_cipher_context_set_key(GaimCipherContext *context, guchar *key) {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1735 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1736
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1737 g_return_if_fail(context);
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 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1740 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1741
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1742 if(cipher->ops && cipher->ops->set_key)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1743 cipher->ops->set_key(context, key);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1744 else
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1745 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1746 "set_key operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1747 }
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 size_t
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1750 gaim_cipher_context_get_key_size(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1751 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1752
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1753 g_return_val_if_fail(context, -1);
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 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1756 g_return_val_if_fail(cipher, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1757
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1758 if(cipher->ops && cipher->ops->get_key_size)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1759 return cipher->ops->get_key_size(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1760 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1761 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1762 "get_key_size operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1763
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1764 return -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1765 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1766 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1767
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1768 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1769 gaim_cipher_context_set_data(GaimCipherContext *context, gpointer data) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1770 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1771
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1772 context->data = data;
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 gpointer
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1776 gaim_cipher_context_get_data(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1777 g_return_val_if_fail(context, NULL);
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 return context->data;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1780 }