annotate src/cipher.c @ 11333:b0185f9214d3

[gaim-migrate @ 13546] Remove // comments committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Wed, 24 Aug 2005 17:10:20 +0000
parents f93d434ee222
children 59aa7080eb2d
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 *
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
25 * This program is free software; you can redistribute it and/or modify
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
26 * 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
27 * the Free Software Foundation; either version 2 of the License, or
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
28 * (at your option) any later version.
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
29 *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
30 * This program is distributed in the hope that it will be useful,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
33 * GNU General Public License for more details.
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
34 *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
35 * You should have received a copy of the GNU General Public License
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
36 * along with this program; if not, write to the Free Software
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
37 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
38 */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
39 #include <glib.h>
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
40 #include <string.h>
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
41 #include <stdio.h>
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
42
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
43 #include "internal.h"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
44 #include "cipher.h"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
45 #include "debug.h"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
46 #include "signals.h"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
47 #include "value.h"
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 /*******************************************************************************
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
50 * MD5
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
51 ******************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
52 struct MD5Context {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
53 guint32 total[2];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
54 guint32 state[4];
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
55 guchar buffer[64];
10684
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
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
58 #define MD5_GET_GUINT32(n,b,i) { \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
59 (n) = ((guint32)(b) [(i) ] ) \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
60 | ((guint32)(b) [(i) + 1] << 8) \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
61 | ((guint32)(b) [(i) + 2] << 16) \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
62 | ((guint32)(b) [(i) + 3] << 24); \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
63 }
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
64 #define MD5_PUT_GUINT32(n,b,i) { \
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
65 (b)[(i) ] = (guchar)((n) ); \
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
66 (b)[(i) + 1] = (guchar)((n) >> 8); \
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
67 (b)[(i) + 2] = (guchar)((n) >> 16); \
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
68 (b)[(i) + 3] = (guchar)((n) >> 24); \
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
69 }
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 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
72 md5_init(GaimCipherContext *context, gpointer extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
73 struct MD5Context *md5_context;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
74
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
75 md5_context = g_new0(struct MD5Context, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
76
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
77 gaim_cipher_context_set_data(context, md5_context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
78
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
79 gaim_cipher_context_reset(context, extra);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
80 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
81
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
82 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
83 md5_reset(GaimCipherContext *context, gpointer extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
84 struct MD5Context *md5_context;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
85
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
86 md5_context = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
87
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
88 md5_context->total[0] = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
89 md5_context->total[1] = 0;
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 md5_context->state[0] = 0x67452301;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
92 md5_context->state[1] = 0xEFCDAB89;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
93 md5_context->state[2] = 0x98BADCFE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
94 md5_context->state[3] = 0x10325476;
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 memset(md5_context->buffer, 0, sizeof(md5_context->buffer));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
97 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
98
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
99 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
100 md5_uninit(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
101 struct MD5Context *md5_context;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
102
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
103 gaim_cipher_context_reset(context, NULL);
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 = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
106 memset(md5_context, 0, sizeof(md5_context));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
107
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
108 g_free(md5_context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
109 md5_context = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
110 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
111
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
112 static void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
113 md5_process(struct MD5Context *md5_context, const guchar data[64]) {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
114 guint32 X[16], A, B, C, D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
115
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
116 A = md5_context->state[0];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
117 B = md5_context->state[1];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
118 C = md5_context->state[2];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
119 D = md5_context->state[3];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
120
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
121 MD5_GET_GUINT32(X[ 0], data, 0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
122 MD5_GET_GUINT32(X[ 1], data, 4);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
123 MD5_GET_GUINT32(X[ 2], data, 8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
124 MD5_GET_GUINT32(X[ 3], data, 12);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
125 MD5_GET_GUINT32(X[ 4], data, 16);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
126 MD5_GET_GUINT32(X[ 5], data, 20);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
127 MD5_GET_GUINT32(X[ 6], data, 24);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
128 MD5_GET_GUINT32(X[ 7], data, 28);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
129 MD5_GET_GUINT32(X[ 8], data, 32);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
130 MD5_GET_GUINT32(X[ 9], data, 36);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
131 MD5_GET_GUINT32(X[10], data, 40);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
132 MD5_GET_GUINT32(X[11], data, 44);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
133 MD5_GET_GUINT32(X[12], data, 48);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
134 MD5_GET_GUINT32(X[13], data, 52);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
135 MD5_GET_GUINT32(X[14], data, 56);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
136 MD5_GET_GUINT32(X[15], data, 60);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
137
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
138 #define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
139 #define P(a,b,c,d,k,s,t) { \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
140 a += F(b,c,d) + X[k] + t; \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
141 a = S(a,s) + b; \
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
142 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
143
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
144 /* first pass */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
145 #define F(x,y,z) (z ^ (x & (y ^ z)))
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
146 P(A, B, C, D, 0, 7, 0xD76AA478);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
147 P(D, A, B, C, 1, 12, 0xE8C7B756);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
148 P(C, D, A, B, 2, 17, 0x242070DB);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
149 P(B, C, D, A, 3, 22, 0xC1BDCEEE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
150 P(A, B, C, D, 4, 7, 0xF57C0FAF);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
151 P(D, A, B, C, 5, 12, 0x4787C62A);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
152 P(C, D, A, B, 6, 17, 0xA8304613);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
153 P(B, C, D, A, 7, 22, 0xFD469501);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
154 P(A, B, C, D, 8, 7, 0x698098D8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
155 P(D, A, B, C, 9, 12, 0x8B44F7AF);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
156 P(C, D, A, B, 10, 17, 0xFFFF5BB1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
157 P(B, C, D, A, 11, 22, 0x895CD7BE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
158 P(A, B, C, D, 12, 7, 0x6B901122);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
159 P(D, A, B, C, 13, 12, 0xFD987193);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
160 P(C, D, A, B, 14, 17, 0xA679438E);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
161 P(B, C, D, A, 15, 22, 0x49B40821);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
162 #undef F
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
163
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
164 /* second pass */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
165 #define F(x,y,z) (y ^ (z & (x ^ y)))
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
166 P(A, B, C, D, 1, 5, 0xF61E2562);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
167 P(D, A, B, C, 6, 9, 0xC040B340);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
168 P(C, D, A, B, 11, 14, 0x265E5A51);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
169 P(B, C, D, A, 0, 20, 0xE9B6C7AA);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
170 P(A, B, C, D, 5, 5, 0xD62F105D);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
171 P(D, A, B, C, 10, 9, 0x02441453);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
172 P(C, D, A, B, 15, 14, 0xD8A1E681);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
173 P(B, C, D, A, 4, 20, 0xE7D3FBC8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
174 P(A, B, C, D, 9, 5, 0x21E1CDE6);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
175 P(D, A, B, C, 14, 9, 0xC33707D6);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
176 P(C, D, A, B, 3, 14, 0xF4D50D87);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
177 P(B, C, D, A, 8, 20, 0x455A14ED);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
178 P(A, B, C, D, 13, 5, 0xA9E3E905);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
179 P(D, A, B, C, 2, 9, 0xFCEFA3F8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
180 P(C, D, A, B, 7, 14, 0x676F02D9);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
181 P(B, C, D, A, 12, 20, 0x8D2A4C8A);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
182 #undef F
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
183
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
184 /* third pass */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
185 #define F(x,y,z) (x ^ y ^ z)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
186 P(A, B, C, D, 5, 4, 0xFFFA3942);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
187 P(D, A, B, C, 8, 11, 0x8771F681);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
188 P(C, D, A, B, 11, 16, 0x6D9D6122);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
189 P(B, C, D, A, 14, 23, 0xFDE5380C);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
190 P(A, B, C, D, 1, 4, 0xA4BEEA44);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
191 P(D, A, B, C, 4, 11, 0x4BDECFA9);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
192 P(C, D, A, B, 7, 16, 0xF6BB4B60);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
193 P(B, C, D, A, 10, 23, 0xBEBFBC70);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
194 P(A, B, C, D, 13, 4, 0x289B7EC6);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
195 P(D, A, B, C, 0, 11, 0xEAA127FA);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
196 P(C, D, A, B, 3, 16, 0xD4EF3085);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
197 P(B, C, D, A, 6, 23, 0x04881D05);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
198 P(A, B, C, D, 9, 4, 0xD9D4D039);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
199 P(D, A, B, C, 12, 11, 0xE6DB99E5);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
200 P(C, D, A, B, 15, 16, 0x1FA27CF8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
201 P(B, C, D, A, 2, 23, 0xC4AC5665);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
202 #undef F
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
203
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
204 /* forth pass */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
205 #define F(x,y,z) (y ^ (x | ~z))
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
206 P(A, B, C, D, 0, 6, 0xF4292244);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
207 P(D, A, B, C, 7, 10, 0x432AFF97);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
208 P(C, D, A, B, 14, 15, 0xAB9423A7);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
209 P(B, C, D, A, 5, 21, 0xFC93A039);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
210 P(A, B, C, D, 12, 6, 0x655B59C3);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
211 P(D, A, B, C, 3, 10, 0x8F0CCC92);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
212 P(C, D, A, B, 10, 15, 0xFFEFF47D);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
213 P(B, C, D, A, 1, 21, 0x85845DD1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
214 P(A, B, C, D, 8, 6, 0x6FA87E4F);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
215 P(D, A, B, C, 15, 10, 0xFE2CE6E0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
216 P(C, D, A, B, 6, 15, 0xA3014314);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
217 P(B, C, D, A, 13, 21, 0x4E0811A1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
218 P(A, B, C, D, 4, 6, 0xF7537E82);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
219 P(D, A, B, C, 11, 10, 0xBD3AF235);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
220 P(C, D, A, B, 2, 15, 0x2AD7D2BB);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
221 P(B, C, D, A, 9, 21, 0xEB86D391);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
222 #undef F
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
223 #undef P
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
224 #undef S
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
225
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
226 md5_context->state[0] += A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
227 md5_context->state[1] += B;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
228 md5_context->state[2] += C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
229 md5_context->state[3] += D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
230 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
231
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
232 static void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
233 md5_append(GaimCipherContext *context, const guchar *data, size_t len) {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
234 struct MD5Context *md5_context = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
235 guint32 left = 0, fill = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
236
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
237 g_return_if_fail(context != NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
238
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
239 md5_context = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
240 g_return_if_fail(md5_context != NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
241
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
242 left = md5_context->total[0] & 0x3F;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
243 fill = 64 - left;
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 md5_context->total[0] += len;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
246 md5_context->total[0] &= 0xFFFFFFFF;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
247
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
248 if(md5_context->total[0] < len)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
249 md5_context->total[1]++;
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 if(left && len >= fill) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
252 memcpy((md5_context->buffer + left), data, fill);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
253 md5_process(md5_context, md5_context->buffer);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
254 len -= fill;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
255 data += fill;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
256 left = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
257 }
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 while(len >= 64) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
260 md5_process(md5_context, data);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
261 len -= 64;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
262 data += 64;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
263 }
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(len) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
266 memcpy((md5_context->buffer + left), data, len);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
267 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
268 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
269
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
270 static gboolean
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
271 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
272 size_t *out_len)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
273 {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
274 struct MD5Context *md5_context = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
275 guint32 last, pad;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
276 guint32 high, low;
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
277 guchar message[8];
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
278 guchar padding[64] = {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
279 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
280 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
281 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
282 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
283 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
284
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
285 g_return_val_if_fail(in_len >= 16, FALSE);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
286
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
287 md5_context = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
288
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
289 high = (md5_context->total[0] >> 29)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
290 | (md5_context->total[1] << 3);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
291 low = (md5_context->total[0] << 3);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
292
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
293 MD5_PUT_GUINT32(low, message, 0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
294 MD5_PUT_GUINT32(high, message, 4);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
295
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
296 last = md5_context->total[0] & 0x3F;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
297 pad = (last < 56) ? (56 - last) : (120 - last);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
298
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
299 md5_append(context, padding, pad);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
300 md5_append(context, message, 8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
301
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
302 MD5_PUT_GUINT32(md5_context->state[0], digest, 0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
303 MD5_PUT_GUINT32(md5_context->state[1], digest, 4);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
304 MD5_PUT_GUINT32(md5_context->state[2], digest, 8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
305 MD5_PUT_GUINT32(md5_context->state[3], digest, 12);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
306
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
307 if(out_len)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
308 *out_len = 16;
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
309
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
310 return TRUE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
311 }
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 static GaimCipherOps MD5Ops = {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
314 NULL, /* Set option */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
315 NULL, /* Get option */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
316 md5_init, /* init */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
317 md5_reset, /* reset */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
318 md5_uninit, /* uninit */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
319 NULL, /* set iv */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
320 md5_append, /* append */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
321 md5_digest, /* digest */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
322 NULL, /* encrypt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
323 NULL, /* decrypt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
324 NULL, /* set salt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
325 NULL, /* get salt size */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
326 NULL, /* set key */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
327 NULL /* get key size */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
328 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
329
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
330 /*******************************************************************************
11329
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
331 * MD4
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
332 ******************************************************************************/
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
333 #define MD4_DIGEST_SIZE 16
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
334 #define MD4_HMAC_BLOCK_SIZE 64
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
335 #define MD4_BLOCK_WORDS 16
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
336 #define MD4_HASH_WORDS 4
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
337
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
338
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
339
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
340 struct MD4_Context {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
341 guint32 hash[MD4_HASH_WORDS];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
342 guint32 block[MD4_BLOCK_WORDS];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
343 guint64 byte_count;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
344 };
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
345
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
346 static inline guint32 lshift(guint32 x, unsigned int s)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
347 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
348 x &= 0xFFFFFFFF;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
349 return ((x << s) & 0xFFFFFFFF) | (x >> (32 - s));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
350 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
351
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
352 static inline guint32 F(guint32 x, guint32 y, guint32 z)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
353 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
354 return (x & y) | ((~x) & z);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
355 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
356
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
357 static inline guint32 G(guint32 x, guint32 y, guint32 z)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
358 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
359 return (x & y) | (x & z) | (y & z);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
360 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
361
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
362 static inline guint32 H(guint32 x, guint32 y, guint32 z)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
363 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
364 return x ^ y ^ z;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
365 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
366
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
367 #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
368 #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
369 #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
370
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
371 static inline void le32_to_cpu_array(guint32 *buf, unsigned int words)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
372 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
373 while (words--) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
374 *buf=GUINT_FROM_LE(*buf);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
375 buf++;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
376 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
377 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
378
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
379 static inline void cpu_to_le32_array(guint32 *buf, unsigned int words)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
380 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
381 while (words--) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
382 *buf=GUINT_TO_LE(*buf);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
383 buf++;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
384 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
385 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
386
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
387 static void md4_transform(guint32 *hash, guint32 const *in)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
388 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
389 guint32 a, b, c, d;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
390
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
391 a = hash[0];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
392 b = hash[1];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
393 c = hash[2];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
394 d = hash[3];
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
395
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
396 ROUND1(a, b, c, d, in[0], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
397 ROUND1(d, a, b, c, in[1], 7);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
398 ROUND1(c, d, a, b, in[2], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
399 ROUND1(b, c, d, a, in[3], 19);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
400 ROUND1(a, b, c, d, in[4], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
401 ROUND1(d, a, b, c, in[5], 7);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
402 ROUND1(c, d, a, b, in[6], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
403 ROUND1(b, c, d, a, in[7], 19);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
404 ROUND1(a, b, c, d, in[8], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
405 ROUND1(d, a, b, c, in[9], 7);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
406 ROUND1(c, d, a, b, in[10], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
407 ROUND1(b, c, d, a, in[11], 19);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
408 ROUND1(a, b, c, d, in[12], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
409 ROUND1(d, a, b, c, in[13], 7);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
410 ROUND1(c, d, a, b, in[14], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
411 ROUND1(b, c, d, a, in[15], 19);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
412
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
413 ROUND2(a, b, c, d,in[ 0], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
414 ROUND2(d, a, b, c, in[4], 5);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
415 ROUND2(c, d, a, b, in[8], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
416 ROUND2(b, c, d, a, in[12], 13);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
417 ROUND2(a, b, c, d, in[1], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
418 ROUND2(d, a, b, c, in[5], 5);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
419 ROUND2(c, d, a, b, in[9], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
420 ROUND2(b, c, d, a, in[13], 13);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
421 ROUND2(a, b, c, d, in[2], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
422 ROUND2(d, a, b, c, in[6], 5);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
423 ROUND2(c, d, a, b, in[10], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
424 ROUND2(b, c, d, a, in[14], 13);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
425 ROUND2(a, b, c, d, in[3], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
426 ROUND2(d, a, b, c, in[7], 5);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
427 ROUND2(c, d, a, b, in[11], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
428 ROUND2(b, c, d, a, in[15], 13);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
429
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
430 ROUND3(a, b, c, d,in[ 0], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
431 ROUND3(d, a, b, c, in[8], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
432 ROUND3(c, d, a, b, in[4], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
433 ROUND3(b, c, d, a, in[12], 15);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
434 ROUND3(a, b, c, d, in[2], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
435 ROUND3(d, a, b, c, in[10], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
436 ROUND3(c, d, a, b, in[6], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
437 ROUND3(b, c, d, a, in[14], 15);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
438 ROUND3(a, b, c, d, in[1], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
439 ROUND3(d, a, b, c, in[9], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
440 ROUND3(c, d, a, b, in[5], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
441 ROUND3(b, c, d, a, in[13], 15);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
442 ROUND3(a, b, c, d, in[3], 3);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
443 ROUND3(d, a, b, c, in[11], 9);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
444 ROUND3(c, d, a, b, in[7], 11);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
445 ROUND3(b, c, d, a, in[15], 15);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
446
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
447 hash[0] += a;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
448 hash[1] += b;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
449 hash[2] += c;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
450 hash[3] += d;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
451 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
452
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
453 static inline void md4_transform_helper(struct MD4_Context *ctx)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
454 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
455 le32_to_cpu_array(ctx->block, sizeof(ctx->block) / sizeof(guint32));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
456 md4_transform(ctx->hash, ctx->block);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
457 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
458
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
459 static void
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
460 md4_init(GaimCipherContext *context, gpointer extra) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
461 struct MD4_Context *mctx;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
462 mctx = g_new0(struct MD4_Context, 1);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
463 gaim_cipher_context_set_data(context, mctx);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
464 gaim_cipher_context_reset(context, extra);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
465
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
466 mctx->hash[0] = 0x67452301;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
467 mctx->hash[1] = 0xefcdab89;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
468 mctx->hash[2] = 0x98badcfe;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
469 mctx->hash[3] = 0x10325476;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
470 mctx->byte_count = 0;
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_reset(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
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
477 mctx = gaim_cipher_context_get_data(context);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
478
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
479 mctx->hash[0] = 0x67452301;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
480 mctx->hash[1] = 0xefcdab89;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
481 mctx->hash[2] = 0x98badcfe;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
482 mctx->hash[3] = 0x10325476;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
483 mctx->byte_count = 0;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
484 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
485
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
486 static void
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
487 md4_append(GaimCipherContext *context, const guchar *data, size_t len)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
488 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
489 struct MD4_Context *mctx = gaim_cipher_context_get_data(context);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
490 const guint32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
491
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
492 mctx->byte_count += len;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
493
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
494 if (avail > len) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
495 memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
496 data, len);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
497 return;
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 memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
501 data, avail);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
502
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
503 md4_transform_helper(mctx);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
504 data += avail;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
505 len -= avail;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
506
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
507 while (len >= sizeof(mctx->block)) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
508 memcpy(mctx->block, data, sizeof(mctx->block));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
509 md4_transform_helper(mctx);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
510 data += sizeof(mctx->block);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
511 len -= sizeof(mctx->block);
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(mctx->block, data, len);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
515 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
516
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
517 static gboolean
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
518 md4_digest(GaimCipherContext *context, size_t in_len, guchar *out,
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
519 size_t *out_len)
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
520 {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
521 struct MD4_Context *mctx = gaim_cipher_context_get_data(context);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
522 const unsigned int offset = mctx->byte_count & 0x3f;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
523 char *p = (char *)mctx->block + offset;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
524 int padding = 56 - (offset + 1);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
525
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
526
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
527 if(in_len<16) return FALSE;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
528 if(out_len) *out_len = 16;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
529 *p++ = 0x80;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
530 if (padding < 0) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
531 memset(p, 0x00, padding + sizeof (guint64));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
532 md4_transform_helper(mctx);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
533 p = (char *)mctx->block;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
534 padding = 56;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
535 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
536
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
537 memset(p, 0, padding);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
538 mctx->block[14] = mctx->byte_count << 3;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
539 mctx->block[15] = mctx->byte_count >> 29;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
540 le32_to_cpu_array(mctx->block, (sizeof(mctx->block) -
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
541 sizeof(guint64)) / sizeof(guint32));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
542 md4_transform(mctx->hash, mctx->block);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
543 cpu_to_le32_array(mctx->hash, sizeof(mctx->hash) / sizeof(guint32));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
544 memcpy(out, mctx->hash, sizeof(mctx->hash));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
545 memset(mctx, 0, sizeof(*mctx));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
546 return TRUE;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
547 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
548
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
549 static void
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
550 md4_uninit(GaimCipherContext *context) {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
551 struct MD4_Context *md4_context;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
552
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
553 gaim_cipher_context_reset(context, NULL);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
554
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
555 md4_context = gaim_cipher_context_get_data(context);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
556 memset(md4_context, 0, sizeof(md4_context));
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
557
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
558 g_free(md4_context);
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
559 md4_context = NULL;
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
560 }
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
561
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
562 static GaimCipherOps MD4Ops = {
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
563 NULL, /* Set option */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
564 NULL, /* Get option */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
565 md4_init, /* init */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
566 md4_reset, /* reset */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
567 md4_uninit, /* uninit */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
568 NULL, /* set iv */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
569 md4_append, /* append */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
570 md4_digest, /* digest */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
571 NULL, /* encrypt */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
572 NULL, /* decrypt */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
573 NULL, /* set salt */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
574 NULL, /* get salt size */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
575 NULL, /* set key */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
576 NULL /* get key size */
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
577 };
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
578
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
579 /*******************************************************************************
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
580 * SHA-1
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
581 ******************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
582 #define SHA1_ROTL(X,n) ((((X) << (n)) | ((X) >> (32-(n)))) & 0xFFFFFFFF)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
583
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
584 struct SHA1Context {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
585 guint32 H[5];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
586 guint32 W[80];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
587
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
588 gint lenW;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
589
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
590 guint32 sizeHi;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
591 guint32 sizeLo;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
592 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
593
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
594 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
595 sha1_hash_block(struct SHA1Context *sha1_ctx) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
596 gint i;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
597 guint32 A, B, C, D, E, T;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
598
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
599 for(i = 16; i < 80; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
600 sha1_ctx->W[i] = SHA1_ROTL(sha1_ctx->W[i - 3] ^
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
601 sha1_ctx->W[i - 8] ^
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
602 sha1_ctx->W[i - 14] ^
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
603 sha1_ctx->W[i - 16], 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
604 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
605
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
606 A = sha1_ctx->H[0];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
607 B = sha1_ctx->H[1];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
608 C = sha1_ctx->H[2];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
609 D = sha1_ctx->H[3];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
610 E = sha1_ctx->H[4];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
611
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
612 for(i = 0; i < 20; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
613 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
614 E = D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
615 D = C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
616 C = SHA1_ROTL(B, 30);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
617 B = A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
618 A = T;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
619 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
620
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
621 for(i = 20; i < 40; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
622 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
623 E = D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
624 D = C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
625 C = SHA1_ROTL(B, 30);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
626 B = A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
627 A = T;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
628 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
629
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
630 for(i = 40; i < 60; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
631 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
632 E = D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
633 D = C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
634 C = SHA1_ROTL(B, 30);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
635 B = A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
636 A = T;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
637 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
638
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
639 for(i = 60; i < 80; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
640 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
641 E = D;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
642 D = C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
643 C = SHA1_ROTL(B, 30);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
644 B = A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
645 A = T;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
646 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
647
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
648 sha1_ctx->H[0] += A;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
649 sha1_ctx->H[1] += B;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
650 sha1_ctx->H[2] += C;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
651 sha1_ctx->H[3] += D;
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
652 sha1_ctx->H[4] += E;
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
653 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
654
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
655 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
656 sha1_set_opt(GaimCipherContext *context, const gchar *name, void *value) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
657 struct SHA1Context *ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
658
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
659 ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
660
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
661 if(!strcmp(name, "sizeHi")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
662 ctx->sizeHi = GPOINTER_TO_INT(value);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
663 } else if(!strcmp(name, "sizeLo")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
664 ctx->sizeLo = GPOINTER_TO_INT(value);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
665 } else if(!strcmp(name, "lenW")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
666 ctx->lenW = GPOINTER_TO_INT(value);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
667 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
668 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
669
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
670 static void *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
671 sha1_get_opt(GaimCipherContext *context, const gchar *name) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
672 struct SHA1Context *ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
673
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
674 ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
675
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
676 if(!strcmp(name, "sizeHi")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
677 return GINT_TO_POINTER(ctx->sizeHi);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
678 } else if(!strcmp(name, "sizeLo")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
679 return GINT_TO_POINTER(ctx->sizeLo);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
680 } else if(!strcmp(name, "lenW")) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
681 return GINT_TO_POINTER(ctx->lenW);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
682 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
683
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
684 return NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
685 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
686
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
687 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
688 sha1_init(GaimCipherContext *context, void *extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
689 struct SHA1Context *sha1_ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
690
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
691 sha1_ctx = g_new0(struct SHA1Context, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
692
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
693 gaim_cipher_context_set_data(context, sha1_ctx);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
694
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
695 gaim_cipher_context_reset(context, extra);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
696 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
697
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
698 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
699 sha1_reset(GaimCipherContext *context, void *extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
700 struct SHA1Context *sha1_ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
701 gint i;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
702
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
703 sha1_ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
704
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
705 g_return_if_fail(sha1_ctx);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
706
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
707 sha1_ctx->lenW = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
708 sha1_ctx->sizeHi = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
709 sha1_ctx->sizeLo = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
710
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
711 sha1_ctx->H[0] = 0x67452301;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
712 sha1_ctx->H[1] = 0xEFCDAB89;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
713 sha1_ctx->H[2] = 0x98BADCFE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
714 sha1_ctx->H[3] = 0x10325476;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
715 sha1_ctx->H[4] = 0xC3D2E1F0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
716
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
717 for(i = 0; i < 80; i++)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
718 sha1_ctx->W[i] = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
719 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
720
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
721 static void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
722 sha1_uninit(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
723 struct SHA1Context *sha1_ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
724
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
725 gaim_cipher_context_reset(context, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
726
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
727 sha1_ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
728
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
729 memset(sha1_ctx, 0, sizeof(struct SHA1Context));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
730
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
731 g_free(sha1_ctx);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
732 sha1_ctx = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
733 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
734
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
735
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
736 static void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
737 sha1_append(GaimCipherContext *context, const guchar *data, size_t len) {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
738 struct SHA1Context *sha1_ctx;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
739 gint i;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
740
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
741 sha1_ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
742
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
743 g_return_if_fail(sha1_ctx);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
744
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
745 for(i = 0; i < len; i++) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
746 sha1_ctx->W[sha1_ctx->lenW / 4] <<= 8;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
747 sha1_ctx->W[sha1_ctx->lenW / 4] |= data[i];
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
748
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
749 if((++sha1_ctx->lenW) % 64 == 0) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
750 sha1_hash_block(sha1_ctx);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
751 sha1_ctx->lenW = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
752 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
753
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
754 sha1_ctx->sizeLo += 8;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
755 sha1_ctx->sizeHi += (sha1_ctx->sizeLo < 8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
756 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
757 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
758
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
759 static gboolean
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
760 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
761 size_t *out_len)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
762 {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
763 struct SHA1Context *sha1_ctx;
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
764 guchar pad0x80 = 0x80, pad0x00 = 0x00;
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
765 guchar padlen[8];
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
766 gint i;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
767
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
768 g_return_val_if_fail(in_len >= 20, FALSE);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
769
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
770 sha1_ctx = gaim_cipher_context_get_data(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
771
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
772 g_return_val_if_fail(sha1_ctx, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
773
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
774 padlen[0] = (guchar)((sha1_ctx->sizeHi >> 24) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
775 padlen[1] = (guchar)((sha1_ctx->sizeHi >> 16) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
776 padlen[2] = (guchar)((sha1_ctx->sizeHi >> 8) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
777 padlen[3] = (guchar)((sha1_ctx->sizeHi >> 0) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
778 padlen[4] = (guchar)((sha1_ctx->sizeLo >> 24) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
779 padlen[5] = (guchar)((sha1_ctx->sizeLo >> 16) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
780 padlen[6] = (guchar)((sha1_ctx->sizeLo >> 8) & 255);
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
781 padlen[7] = (guchar)((sha1_ctx->sizeLo >> 0) & 255);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
782
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
783 /* pad with a 1, then zeroes, then length */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
784 gaim_cipher_context_append(context, &pad0x80, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
785 while(sha1_ctx->lenW != 56)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
786 gaim_cipher_context_append(context, &pad0x00, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
787 gaim_cipher_context_append(context, padlen, 8);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
788
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
789 for(i = 0; i < 20; i++) {
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
790 digest[i] = (guchar)(sha1_ctx->H[i / 4] >> 24);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
791 sha1_ctx->H[i / 4] <<= 8;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
792 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
793
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
794 gaim_cipher_context_reset(context, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
795
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
796 if(out_len)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
797 *out_len = 20;
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
798
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
799 return TRUE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
800 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
801
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
802 static GaimCipherOps SHA1Ops = {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
803 sha1_set_opt, /* Set Option */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
804 sha1_get_opt, /* Get Option */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
805 sha1_init, /* init */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
806 sha1_reset, /* reset */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
807 sha1_uninit, /* uninit */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
808 NULL, /* set iv */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
809 sha1_append, /* append */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
810 sha1_digest, /* digest */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
811 NULL, /* encrypt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
812 NULL, /* decrypt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
813 NULL, /* set salt */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
814 NULL, /* get salt size */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
815 NULL, /* set key */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
816 NULL /* get key size */
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
817 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
818
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
819 /*******************************************************************************
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
820 * Structs
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
821 ******************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
822 struct _GaimCipher {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
823 gchar *name;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
824 GaimCipherOps *ops;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
825 guint ref;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
826 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
827
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
828 struct _GaimCipherContext {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
829 GaimCipher *cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
830 gpointer data;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
831 };
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
832
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
833 /******************************************************************************
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
834 * Globals
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
835 *****************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
836 static GList *ciphers = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
837
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
838 /******************************************************************************
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
839 * GaimCipher API
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
840 *****************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
841 const gchar *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
842 gaim_cipher_get_name(GaimCipher *cipher) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
843 g_return_val_if_fail(cipher, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
844
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
845 return cipher->name;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
846 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
847
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
848 guint
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
849 gaim_cipher_get_capabilities(GaimCipher *cipher) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
850 GaimCipherOps *ops = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
851 guint caps = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
852
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
853 g_return_val_if_fail(cipher, 0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
854
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
855 ops = cipher->ops;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
856 g_return_val_if_fail(ops, 0);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
857
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
858 if(ops->set_option)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
859 caps |= GAIM_CIPHER_CAPS_SET_OPT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
860 if(ops->get_option)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
861 caps |= GAIM_CIPHER_CAPS_GET_OPT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
862 if(ops->init)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
863 caps |= GAIM_CIPHER_CAPS_INIT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
864 if(ops->reset)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
865 caps |= GAIM_CIPHER_CAPS_RESET;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
866 if(ops->uninit)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
867 caps |= GAIM_CIPHER_CAPS_UNINIT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
868 if(ops->set_iv)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
869 caps |= GAIM_CIPHER_CAPS_SET_IV;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
870 if(ops->append)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
871 caps |= GAIM_CIPHER_CAPS_APPEND;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
872 if(ops->digest)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
873 caps |= GAIM_CIPHER_CAPS_DIGEST;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
874 if(ops->encrypt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
875 caps |= GAIM_CIPHER_CAPS_ENCRYPT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
876 if(ops->decrypt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
877 caps |= GAIM_CIPHER_CAPS_DECRYPT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
878 if(ops->set_salt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
879 caps |= GAIM_CIPHER_CAPS_SET_SALT;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
880 if(ops->get_salt_size)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
881 caps |= GAIM_CIPHER_CAPS_GET_SALT_SIZE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
882 if(ops->set_key)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
883 caps |= GAIM_CIPHER_CAPS_SET_KEY;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
884 if(ops->get_key_size)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
885 caps |= GAIM_CIPHER_CAPS_GET_KEY_SIZE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
886
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
887 return caps;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
888 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
889
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
890 gboolean
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
891 gaim_cipher_digest_region(const gchar *name, const guchar *data,
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
892 size_t data_len, size_t in_len,
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
893 guchar digest[], size_t *out_len)
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
894 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
895 GaimCipher *cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
896 GaimCipherContext *context;
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
897 gboolean ret = FALSE;
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
898
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
899 g_return_val_if_fail(name, FALSE);
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
900 g_return_val_if_fail(data, FALSE);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
901
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
902 cipher = gaim_ciphers_find_cipher(name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
903
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
904 g_return_val_if_fail(cipher, FALSE);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
905
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
906 if(!cipher->ops->append || !cipher->ops->digest) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
907 gaim_debug_info("cipher", "gaim_cipher_region failed: "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
908 "the %s cipher does not support appending and or "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
909 "digesting.", cipher->name);
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
910 return FALSE;
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
911 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
912
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
913 context = gaim_cipher_context_new(cipher, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
914 gaim_cipher_context_append(context, data, data_len);
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
915 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
916 gaim_cipher_context_destroy(context);
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
917
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
918 return ret;
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
919 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
920
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
921 /******************************************************************************
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
922 * GaimCiphers API
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
923 *****************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
924 GaimCipher *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
925 gaim_ciphers_find_cipher(const gchar *name) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
926 GaimCipher *cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
927 GList *l;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
928
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
929 g_return_val_if_fail(name, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
930
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
931 for(l = ciphers; l; l = l->next) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
932 cipher = GAIM_CIPHER(l->data);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
933
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
934 if(!g_ascii_strcasecmp(cipher->name, name))
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
935 return cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
936 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
937
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
938 return NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
939 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
940
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
941 GaimCipher *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
942 gaim_ciphers_register_cipher(const gchar *name, GaimCipherOps *ops) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
943 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
944
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
945 g_return_val_if_fail(name, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
946 g_return_val_if_fail(ops, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
947 g_return_val_if_fail(!gaim_ciphers_find_cipher(name), NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
948
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
949 cipher = g_new0(GaimCipher, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
950
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
951 cipher->name = g_strdup(name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
952 cipher->ops = ops;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
953
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
954 ciphers = g_list_append(ciphers, cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
955
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
956 gaim_signal_emit(gaim_ciphers_get_handle(), "cipher-added", cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
957
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
958 return cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
959 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
960
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
961 gboolean
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
962 gaim_ciphers_unregister_cipher(GaimCipher *cipher) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
963 g_return_val_if_fail(cipher, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
964 g_return_val_if_fail(cipher->ref == 0, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
965
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
966 gaim_signal_emit(gaim_ciphers_get_handle(), "cipher-removed", cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
967
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
968 ciphers = g_list_remove(ciphers, cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
969
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
970 g_free(cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
971 g_free(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
972
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
973 return TRUE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
974 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
975
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
976 GList *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
977 gaim_ciphers_get_ciphers() {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
978 return ciphers;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
979 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
980
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
981 /******************************************************************************
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
982 * GaimCipher Subsystem API
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
983 *****************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
984 gpointer
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
985 gaim_ciphers_get_handle() {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
986 static gint handle;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
987
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
988 return &handle;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
989 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
990
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
991 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
992 gaim_ciphers_init() {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
993 gpointer handle;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
994
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
995 handle = gaim_ciphers_get_handle();
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
996
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
997 gaim_signal_register(handle, "cipher-added",
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
998 gaim_marshal_VOID__POINTER, NULL, 1,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
999 gaim_value_new(GAIM_TYPE_SUBTYPE,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1000 GAIM_SUBTYPE_CIPHER));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1001 gaim_signal_register(handle, "cipher-removed",
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1002 gaim_marshal_VOID__POINTER, NULL, 1,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1003 gaim_value_new(GAIM_TYPE_SUBTYPE,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1004 GAIM_SUBTYPE_CIPHER));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1005
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1006 gaim_ciphers_register_cipher("md5", &MD5Ops);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1007 gaim_ciphers_register_cipher("sha1", &SHA1Ops);
11329
f93d434ee222 [gaim-migrate @ 13541]
Thomas Butter <tbutter>
parents: 11183
diff changeset
1008 gaim_ciphers_register_cipher("md4", &MD4Ops);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1009 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1010
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1011 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1012 gaim_ciphers_uninit() {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1013 GaimCipher *cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1014 GList *l, *ll;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1015
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1016 for(l = ciphers; l; l = ll) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1017 ll = l->next;
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 cipher = GAIM_CIPHER(l->data);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1020 gaim_ciphers_unregister_cipher(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1021
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1022 ciphers = g_list_remove(ciphers, cipher);
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 g_list_free(ciphers);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1026
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1027 gaim_signals_unregister_by_instance(gaim_ciphers_get_handle());
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1028 }
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 * GaimCipherContext API
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1031 *****************************************************************************/
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1032 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1033 gaim_cipher_context_set_option(GaimCipherContext *context, const gchar *name,
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1034 gpointer value)
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 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1037
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1038 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1039 g_return_if_fail(name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1040
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1041 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1042 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1043
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1044 if(cipher->ops && cipher->ops->set_option)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1045 cipher->ops->set_option(context, name, value);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1046 else
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1047 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1048 "set_option operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1049 }
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 gpointer
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1052 gaim_cipher_context_get_option(GaimCipherContext *context, const gchar *name) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1053 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1054
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1055 g_return_val_if_fail(context, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1056 g_return_val_if_fail(name, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1057
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1058 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1059 g_return_val_if_fail(cipher, NULL);
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 if(cipher->ops && cipher->ops->get_option)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1062 return cipher->ops->get_option(context, name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1063 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1064 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1065 "get_option operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1066
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1067 return NULL;
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
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1071 GaimCipherContext *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1072 gaim_cipher_context_new(GaimCipher *cipher, void *extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1073 GaimCipherContext *context = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1074
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1075 g_return_val_if_fail(cipher, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1076
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1077 cipher->ref++;
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 context = g_new0(GaimCipherContext, 1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1080 context->cipher = cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1081
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1082 if(cipher->ops->init)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1083 cipher->ops->init(context, extra);
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 return context;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1086 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1087
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1088 GaimCipherContext *
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1089 gaim_cipher_context_new_by_name(const gchar *name, void *extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1090 GaimCipher *cipher;
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 g_return_val_if_fail(name, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1093
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1094 cipher = gaim_ciphers_find_cipher(name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1095
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1096 g_return_val_if_fail(cipher, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1097
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1098 return gaim_cipher_context_new(cipher, extra);
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 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1102 gaim_cipher_context_reset(GaimCipherContext *context, void *extra) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1103 GaimCipher *cipher = NULL;
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 g_return_if_fail(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 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1108 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1109
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1110 if(cipher->ops && cipher->ops->reset)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1111 context->cipher->ops->reset(context, extra);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1112 }
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 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1115 gaim_cipher_context_destroy(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1116 GaimCipher *cipher = NULL;
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 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1119
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1120 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1121 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1122
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1123 cipher->ref--;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1124
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1125 if(cipher->ops && cipher->ops->uninit)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1126 cipher->ops->uninit(context);
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 memset(context, 0, sizeof(context));
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1129 g_free(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1130 context = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1131 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1132
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1133 void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1134 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
1135 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1136 GaimCipher *cipher = NULL;
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 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1139 g_return_if_fail(iv);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1140
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1141 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1142 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1143
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1144 if(cipher->ops && cipher->ops->set_iv)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1145 cipher->ops->set_iv(context, iv, len);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1146 else
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1147 gaim_debug_info("cipher", "the %s cipher does not support the set"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1148 "initialization vector operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1149 }
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 void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1152 gaim_cipher_context_append(GaimCipherContext *context, const guchar *data,
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1153 size_t len)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1154 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1155 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1156
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1157 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1158
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1159 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1160 g_return_if_fail(cipher);
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 if(cipher->ops && cipher->ops->append)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1163 cipher->ops->append(context, data, len);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1164 else
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1165 gaim_debug_info("cipher", "the %s cipher does not support the append "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1166 "operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1167 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1168
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1169 gboolean
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1170 gaim_cipher_context_digest(GaimCipherContext *context, size_t in_len,
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1171 guchar digest[], size_t *out_len)
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1172 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1173 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1174
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1175 g_return_val_if_fail(context, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1176
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1177 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1178 g_return_val_if_fail(context, FALSE);
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(cipher->ops && cipher->ops->digest)
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1181 return cipher->ops->digest(context, in_len, digest, out_len);
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1182 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1183 gaim_debug_info("cipher", "the %s cipher does not support the digest "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1184 "operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1185 return FALSE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1186 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1187 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1188
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1189 gboolean
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1190 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
1191 gchar digest_s[], size_t *out_len)
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1192 {
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1193 /* 8k is a bit excessive, will tweak later. */
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1194 guchar digest[BUF_LEN * 4];
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1195 gint n = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1196 size_t dlen = 0;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1197
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1198 g_return_val_if_fail(context, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1199 g_return_val_if_fail(digest_s, FALSE);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1200
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1201 if(!gaim_cipher_context_digest(context, sizeof(digest), digest, &dlen))
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1202 return FALSE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1203
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1204 if(in_len < dlen * 2)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1205 return FALSE;
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1206
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1207 for(n = 0; n < dlen; n++)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1208 sprintf(digest_s + (n * 2), "%02x", digest[n]);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1209
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1210 digest_s[n * 2] = '\0';
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1211
10687
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1212 if(out_len)
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1213 *out_len = dlen * 2;
b256ce6b85b8 [gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10684
diff changeset
1214
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1215 return TRUE;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1216 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1217
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1218 gint
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1219 gaim_cipher_context_encrypt(GaimCipherContext *context, const guchar data[],
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1220 size_t len, guchar output[], size_t *outlen)
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1221 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1222 GaimCipher *cipher = NULL;
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 g_return_val_if_fail(context, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1225
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1226 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1227 g_return_val_if_fail(cipher, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1228
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1229 if(cipher->ops && cipher->ops->encrypt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1230 return cipher->ops->encrypt(context, data, len, output, outlen);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1231 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1232 gaim_debug_info("cipher", "the %s cipher does not support the encrypt"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1233 "operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1234
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1235 if(outlen)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1236 *outlen = -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1237
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1238 return -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1239 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1240 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1241
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1242 gint
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1243 gaim_cipher_context_decrypt(GaimCipherContext *context, const guchar data[],
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1244 size_t len, guchar output[], size_t *outlen)
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1245 {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1246 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1247
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1248 g_return_val_if_fail(context, -1);
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 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1251 g_return_val_if_fail(cipher, -1);
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 if(cipher->ops && cipher->ops->decrypt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1254 return cipher->ops->decrypt(context, data, len, output, outlen);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1255 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1256 gaim_debug_info("cipher", "the %s cipher does not support the decrypt"
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1257 "operation\n", cipher->name);
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 if(outlen)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1260 *outlen = -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1261
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1262 return -1;
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
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1266 void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1267 gaim_cipher_context_set_salt(GaimCipherContext *context, guchar *salt) {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1268 GaimCipher *cipher = NULL;
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 g_return_if_fail(context);
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 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1273 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1274
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1275 if(cipher->ops && cipher->ops->set_salt)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1276 cipher->ops->set_salt(context, salt);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1277 else
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1278 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1279 "set_salt operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1280 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1281
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1282 size_t
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1283 gaim_cipher_context_get_salt_size(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1284 GaimCipher *cipher = NULL;
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 g_return_val_if_fail(context, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1287
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1288 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1289 g_return_val_if_fail(cipher, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1290
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1291 if(cipher->ops && cipher->ops->get_salt_size)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1292 return cipher->ops->get_salt_size(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1293 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1294 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1295 "get_salt_size operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1296
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1297 return -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1298 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1299 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1300
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1301 void
11183
8dca96cbcd64 [gaim-migrate @ 13295]
Mark Doliner <mark@kingant.net>
parents: 11143
diff changeset
1302 gaim_cipher_context_set_key(GaimCipherContext *context, guchar *key) {
10684
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1303 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1304
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1305 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1306
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1307 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1308 g_return_if_fail(cipher);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1309
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1310 if(cipher->ops && cipher->ops->set_key)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1311 cipher->ops->set_key(context, key);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1312 else
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1313 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1314 "set_key operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1315 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1316
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1317 size_t
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1318 gaim_cipher_context_get_key_size(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1319 GaimCipher *cipher = NULL;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1320
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1321 g_return_val_if_fail(context, -1);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1322
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1323 cipher = context->cipher;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1324 g_return_val_if_fail(cipher, -1);
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 if(cipher->ops && cipher->ops->get_key_size)
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1327 return cipher->ops->get_key_size(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1328 else {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1329 gaim_debug_info("cipher", "the %s cipher does not support the "
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1330 "get_key_size operation\n", cipher->name);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1331
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1332 return -1;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1333 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1334 }
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1335
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1336 void
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1337 gaim_cipher_context_set_data(GaimCipherContext *context, gpointer data) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1338 g_return_if_fail(context);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1339
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1340 context->data = data;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1341 }
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 gpointer
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1344 gaim_cipher_context_get_data(GaimCipherContext *context) {
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1345 g_return_val_if_fail(context, NULL);
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1346
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1347 return context->data;
72a5babfa8b4 [gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
diff changeset
1348 }