annotate libgaim/protocols/qq/crypt.c @ 15026:c039c920e11c

[gaim-migrate @ 17807] Thanks to everyone who worked on OpenQ! Please let me know if I left anything/anyone out. committer: Tailor Script <tailor@pidgin.im>
author Mark Huetsch <markhuetsch>
date Wed, 22 Nov 2006 15:29:57 +0000
parents 473b225e7352
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1 /**
15026
c039c920e11c [gaim-migrate @ 17807]
Mark Huetsch <markhuetsch>
parents: 14610
diff changeset
2 * @file crypt.c
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
3 *
15026
c039c920e11c [gaim-migrate @ 17807]
Mark Huetsch <markhuetsch>
parents: 14610
diff changeset
4 * gaim
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
5 *
15026
c039c920e11c [gaim-migrate @ 17807]
Mark Huetsch <markhuetsch>
parents: 14610
diff changeset
6 * Gaim is the legal property of its developers, whose names are too numerous
c039c920e11c [gaim-migrate @ 17807]
Mark Huetsch <markhuetsch>
parents: 14610
diff changeset
7 * to list here. Please refer to the COPYRIGHT file distributed with this
c039c920e11c [gaim-migrate @ 17807]
Mark Huetsch <markhuetsch>
parents: 14610
diff changeset
8 * source distribution.
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
9 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
13 * (at your option) any later version.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
14 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
18 * GNU General Public License for more details.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
19 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
23 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
24 *
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
25 * QQ encryption algorithm
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
26 * Convert from ASM code provided by PerlOICQ
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
27 *
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
28 * Puzzlebird, Nov-Dec 2002
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
29 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
30
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
31 /*Notes: (QQ uses 16 rounds, and modified something...)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
32
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
33 IN : 64 bits of data in v[0] - v[1].
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
34 OUT: 64 bits of data in w[0] - w[1].
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
35 KEY: 128 bits of key in k[0] - k[3].
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
36
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
37 delta is chosen to be the real part of
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
38 the golden ratio: Sqrt(5/4) - 1/2 ~ 0.618034 multiplied by 2^32.
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
39
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
40 0x61C88647 is what we can track on the ASM codes.!!
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
41 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
42
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
43 #include <string.h>
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
44
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
45 #include "crypt.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
46 #include "debug.h"
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
47
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
48 /********************************************************************
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
49 * encryption
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
50 *******************************************************************/
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
51
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
52 /* Tiny Encryption Algorithm (TEA) */
14236
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
53 static void qq_encipher(guint32 *const v, const guint32 *const k, guint32 *const w)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
54 {
14610
473b225e7352 [gaim-migrate @ 17338]
Mark Huetsch <markhuetsch>
parents: 14565
diff changeset
55 register guint32 y = g_ntohl(v[0]),
473b225e7352 [gaim-migrate @ 17338]
Mark Huetsch <markhuetsch>
parents: 14565
diff changeset
56 z = g_ntohl(v[1]),
473b225e7352 [gaim-migrate @ 17338]
Mark Huetsch <markhuetsch>
parents: 14565
diff changeset
57 a = g_ntohl(k[0]),
473b225e7352 [gaim-migrate @ 17338]
Mark Huetsch <markhuetsch>
parents: 14565
diff changeset
58 b = g_ntohl(k[1]),
473b225e7352 [gaim-migrate @ 17338]
Mark Huetsch <markhuetsch>
parents: 14565
diff changeset
59 c = g_ntohl(k[2]),
473b225e7352 [gaim-migrate @ 17338]
Mark Huetsch <markhuetsch>
parents: 14565
diff changeset
60 d = g_ntohl(k[3]),
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
61 n = 0x10,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
62 sum = 0,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
63 delta = 0x9E3779B9; /* 0x9E3779B9 - 0x100000000 = -0x61C88647 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
64
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
65 while (n-- > 0) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
66 sum += delta;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
67 y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
68 z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
69 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
70
14610
473b225e7352 [gaim-migrate @ 17338]
Mark Huetsch <markhuetsch>
parents: 14565
diff changeset
71 w[0] = g_htonl(y);
473b225e7352 [gaim-migrate @ 17338]
Mark Huetsch <markhuetsch>
parents: 14565
diff changeset
72 w[1] = g_htonl(z);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
73 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
74
14236
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
75 static gint rand(void) { /* it can be the real random seed function */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
76 return 0xdead;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
77 } /* override with number, convenient for debug */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
78
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
79 /* 64-bit blocks and some kind of feedback mode of operation */
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
80 static void encrypt_block(guint8 *plain, guint8 *plain_pre_8, guint8 **crypted,
14236
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
81 guint8 **crypted_pre_8, const guint8 *const key, gint *count,
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
82 gint *pos_in_block, gint *is_header)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
83 {
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
84 /* prepare input text */
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
85 if (!*is_header)
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
86 *(guint64 *) plain ^= **(guint64 **) crypted_pre_8;
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
87
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
88 /* encrypt it */
14236
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
89 qq_encipher((guint32 *) plain, (guint32 *) key, (guint32 *) *crypted);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
90
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
91 **(guint64 **) crypted ^= *(guint64 *) plain_pre_8;
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
92
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
93 memcpy(plain_pre_8, plain, 8); /* prepare next */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
94
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
95 *crypted_pre_8 = *crypted; /* store position of previous 8 byte */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
96 *crypted += 8; /* prepare next output */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
97 *count += 8; /* outstrlen increase by 8 */
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
98 *pos_in_block = 0; /* back to start */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
99 *is_header = 0; /* and exit header */
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
100 } /* encrypt_block */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
101
14236
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
102 static void qq_encrypt(const guint8 *const instr, gint instrlen,
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
103 const guint8 *const key,
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
104 guint8 *outstr, gint *outstrlen_ptr)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
105 {
14236
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
106 guint8 plain[8], /* plain text buffer */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
107 plain_pre_8[8], /* plain text buffer, previous 8 bytes */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
108 *crypted, /* crypted text */
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
109 *crypted_pre_8; /* crypted text, previous 8 bytes */
14236
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
110 const guint8 *inp; /* current position in instr */
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
111 gint pos_in_block = 1, /* loop in the byte */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
112 is_header = 1, /* header is one byte */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
113 count = 0, /* number of bytes being crypted */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
114 padding = 0; /* number of padding stuff */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
115
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
116 pos_in_block = (instrlen + 0x0a) % 8; /* header padding decided by instrlen */
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
117 if (pos_in_block)
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
118 pos_in_block = 8 - pos_in_block;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
119
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
120 /* initialization vector */
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
121 plain[0] = (rand() & 0xf8) | pos_in_block;
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
122 memset(plain + 1, rand() & 0xff, pos_in_block++);
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
123
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
124 memset(plain_pre_8, 0x00, sizeof(plain_pre_8));
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
125
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
126 crypted = crypted_pre_8 = outstr;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
127
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
128 padding = 1; /* pad some stuff in header */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
129 while (padding <= 2) { /* at most two bytes */
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
130 if (pos_in_block < 8) {
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
131 plain[pos_in_block++] = rand() & 0xff;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
132 padding++;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
133 }
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
134 if (pos_in_block == 8) {
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
135 encrypt_block(plain, plain_pre_8, &crypted, &crypted_pre_8,
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
136 key, &count, &pos_in_block, &is_header);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
137 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
138 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
139
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
140 inp = instr;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
141 while (instrlen > 0) {
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
142 if (pos_in_block < 8) {
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
143 plain[pos_in_block++] = *(inp++);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
144 instrlen--;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
145 }
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
146 if (pos_in_block == 8) {
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
147 encrypt_block(plain, plain_pre_8, &crypted, &crypted_pre_8,
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
148 key, &count, &pos_in_block, &is_header);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
149 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
150 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
151
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
152 padding = 1; /* pad some stuff in tail */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
153 while (padding <= 7) { /* at most seven bytes */
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
154 if (pos_in_block < 8) {
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
155 plain[pos_in_block++] = 0x00;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
156 padding++;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
157 }
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
158 if (pos_in_block == 8) {
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
159 encrypt_block(plain, plain_pre_8, &crypted, &crypted_pre_8,
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
160 key, &count, &pos_in_block, &is_header);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
161 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
162 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
163
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
164 *outstrlen_ptr = count;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
165 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
166
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
167
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
168 /********************************************************************
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
169 * decryption
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
170 ********************************************************************/
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
171
14236
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
172 static void qq_decipher(guint32 *const v, const guint32 *const k, guint32 *const w)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
173 {
14610
473b225e7352 [gaim-migrate @ 17338]
Mark Huetsch <markhuetsch>
parents: 14565
diff changeset
174 register guint32 y = g_ntohl(v[0]),
473b225e7352 [gaim-migrate @ 17338]
Mark Huetsch <markhuetsch>
parents: 14565
diff changeset
175 z = g_ntohl(v[1]),
473b225e7352 [gaim-migrate @ 17338]
Mark Huetsch <markhuetsch>
parents: 14565
diff changeset
176 a = g_ntohl(k[0]),
473b225e7352 [gaim-migrate @ 17338]
Mark Huetsch <markhuetsch>
parents: 14565
diff changeset
177 b = g_ntohl(k[1]),
473b225e7352 [gaim-migrate @ 17338]
Mark Huetsch <markhuetsch>
parents: 14565
diff changeset
178 c = g_ntohl(k[2]),
473b225e7352 [gaim-migrate @ 17338]
Mark Huetsch <markhuetsch>
parents: 14565
diff changeset
179 d = g_ntohl(k[3]),
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
180 n = 0x10,
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
181 sum = 0xE3779B90, /* why this ? must be related with n value */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
182 delta = 0x9E3779B9;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
183
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
184 /* sum = delta<<5, in general sum = delta * n */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
185 while (n-- > 0) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
186 z -= ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
187 y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
188 sum -= delta;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
189 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
190
14610
473b225e7352 [gaim-migrate @ 17338]
Mark Huetsch <markhuetsch>
parents: 14565
diff changeset
191 w[0] = g_htonl(y);
473b225e7352 [gaim-migrate @ 17338]
Mark Huetsch <markhuetsch>
parents: 14565
diff changeset
192 w[1] = g_htonl(z);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
193 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
194
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
195 static gint decrypt_block(const guint8 **crypt_buff, const gint instrlen,
14236
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
196 const guint8 *const key, gint *context_start,
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
197 guint8 *decrypted, gint *pos_in_block)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
198 {
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
199 if (*context_start == instrlen)
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
200 return 1;
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
201
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
202 *(guint64 *) decrypted ^= **(guint64 **) crypt_buff;
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
203
14236
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
204 qq_decipher((guint32 *) decrypted, (guint32 *) key, (guint32 *) decrypted);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
205
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
206 *context_start += 8;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
207 *crypt_buff += 8;
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
208 *pos_in_block = 0;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
209
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
210 return 1;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
211 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
212
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
213 /* return 0 if failed, 1 otherwise */
14236
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
214 static gint qq_decrypt(const guint8 *const instr, gint instrlen,
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
215 const guint8 *const key,
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
216 guint8 *outstr, gint *outstrlen_ptr)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
217 {
14236
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
218 guint8 decrypted[8], m[8], *outp;
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
219 const guint8 *crypt_buff, *crypt_buff_pre_8;
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
220 gint count, context_start, pos_in_block, padding;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
221
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
222 /* at least 16 bytes and %8 == 0 */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
223 if ((instrlen % 8) || (instrlen < 16)) {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
224 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
225 "Ciphertext len is either too short or not a multiple of 8 bytes, read %d bytes\n",
14236
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
226 instrlen);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
227 return 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
228 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
229 /* get information from header */
14236
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
230 qq_decipher((guint32 *) instr, (guint32 *) key, (guint32 *) decrypted);
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
231 pos_in_block = decrypted[0] & 0x7;
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
232 count = instrlen - pos_in_block - 10; /* this is the plaintext length */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
233 /* return if outstr buffer is not large enough or error plaintext length */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
234 if (*outstrlen_ptr < count || count < 0) {
14236
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
235 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Buffer len %d is less than real len %d",
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
236 *outstrlen_ptr, count);
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
237 return 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
238 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
239
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
240 memset(m, 0, 8);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
241 crypt_buff_pre_8 = m;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
242 *outstrlen_ptr = count; /* everything is ok! set return string length */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
243
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
244 crypt_buff = instr + 8; /* address of real data start */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
245 context_start = 8; /* context is at the second block of 8 bytes */
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
246 pos_in_block++; /* start of paddng stuff */
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
247
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
248 padding = 1; /* at least one in header */
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
249 while (padding <= 2) { /* there are 2 byte padding stuff in header */
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
250 if (pos_in_block < 8) { /* bypass the padding stuff, it's nonsense data */
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
251 pos_in_block++;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
252 padding++;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
253 }
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
254 if (pos_in_block == 8) {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
255 crypt_buff_pre_8 = instr;
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
256 if (!decrypt_block(&crypt_buff, instrlen, key,
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
257 &context_start, decrypted, &pos_in_block)) {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
258 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "decrypt every 8 bytes error A");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
259 return 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
260 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
261 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
262 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
263
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
264 outp = outstr;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
265 while (count != 0) {
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
266 if (pos_in_block < 8) {
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
267 *outp = crypt_buff_pre_8[pos_in_block] ^ decrypted[pos_in_block];
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
268 outp++;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
269 count--;
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
270 pos_in_block++;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
271 }
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
272 if (pos_in_block == 8) {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
273 crypt_buff_pre_8 = crypt_buff - 8;
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
274 if (!decrypt_block(&crypt_buff, instrlen, key,
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
275 &context_start, decrypted, &pos_in_block)) {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
276 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "decrypt every 8 bytes error B");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
277 return 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
278 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
279 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
280 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
281
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
282 for (padding = 1; padding < 8; padding++) {
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
283 if (pos_in_block < 8) {
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
284 if (crypt_buff_pre_8[pos_in_block] ^ decrypted[pos_in_block])
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
285 return 0;
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
286 pos_in_block++;
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
287 }
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
288 if (pos_in_block == 8) {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
289 crypt_buff_pre_8 = crypt_buff;
14565
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
290 if (!decrypt_block(&crypt_buff, instrlen, key,
ca943d7fb274 [gaim-migrate @ 17289]
Mark Huetsch <markhuetsch>
parents: 14554
diff changeset
291 &context_start, decrypted, &pos_in_block)) {
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
292 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "decrypt every 8 bytes error C");
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
293 return 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
294 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
295 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
296 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
297 return 1;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
298 }
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
299
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
300 /* return 1 is succeed, otherwise return 0 */
14236
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
301 gint qq_crypt(gint flag,
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
302 const guint8 *const instr, gint instrlen,
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
303 const guint8 *const key,
b7f17fdded6f [gaim-migrate @ 16918]
Mark Huetsch <markhuetsch>
parents: 14192
diff changeset
304 guint8 *outstr, gint *outstrlen_ptr)
14192
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
305 {
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
306 if (flag == DECRYPT)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
307 return qq_decrypt(instr, instrlen, key, outstr, outstrlen_ptr);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
308 else if (flag == ENCRYPT)
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
309 qq_encrypt(instr, instrlen, key, outstr, outstrlen_ptr);
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
310 else
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
311 return 0;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
312
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
313 return 1;
60b1bc8dbf37 [gaim-migrate @ 16863]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
314 }