comparison libgaim/protocols/qq/crypt.c @ 14610:473b225e7352

[gaim-migrate @ 17338] Eliminate a dependency in crypt.c by replacing ntohl() (etc) with g_ntohl() (etc). Also replace those calls in the rest of the QQ prpl, to be consistent. committer: Tailor Script <tailor@pidgin.im>
author Mark Huetsch <markhuetsch>
date Fri, 22 Sep 2006 16:05:09 +0000
parents ca943d7fb274
children c039c920e11c
comparison
equal deleted inserted replaced
14609:36ededd6e064 14610:473b225e7352
36 the golden ratio: Sqrt(5/4) - 1/2 ~ 0.618034 multiplied by 2^32. 36 the golden ratio: Sqrt(5/4) - 1/2 ~ 0.618034 multiplied by 2^32.
37 37
38 0x61C88647 is what we can track on the ASM codes.!! 38 0x61C88647 is what we can track on the ASM codes.!!
39 */ 39 */
40 40
41 #ifdef _WIN32
42 #include "win32dep.h"
43 #else
44 #include <arpa/inet.h>
45 #endif
46
47 #include <string.h> 41 #include <string.h>
48 42
49 #include "crypt.h" 43 #include "crypt.h"
50 #include "debug.h" 44 #include "debug.h"
51 45
54 *******************************************************************/ 48 *******************************************************************/
55 49
56 /* Tiny Encryption Algorithm (TEA) */ 50 /* Tiny Encryption Algorithm (TEA) */
57 static void qq_encipher(guint32 *const v, const guint32 *const k, guint32 *const w) 51 static void qq_encipher(guint32 *const v, const guint32 *const k, guint32 *const w)
58 { 52 {
59 register guint32 y = ntohl(v[0]), 53 register guint32 y = g_ntohl(v[0]),
60 z = ntohl(v[1]), 54 z = g_ntohl(v[1]),
61 a = ntohl(k[0]), 55 a = g_ntohl(k[0]),
62 b = ntohl(k[1]), 56 b = g_ntohl(k[1]),
63 c = ntohl(k[2]), 57 c = g_ntohl(k[2]),
64 d = ntohl(k[3]), 58 d = g_ntohl(k[3]),
65 n = 0x10, 59 n = 0x10,
66 sum = 0, 60 sum = 0,
67 delta = 0x9E3779B9; /* 0x9E3779B9 - 0x100000000 = -0x61C88647 */ 61 delta = 0x9E3779B9; /* 0x9E3779B9 - 0x100000000 = -0x61C88647 */
68 62
69 while (n-- > 0) { 63 while (n-- > 0) {
70 sum += delta; 64 sum += delta;
71 y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b); 65 y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
72 z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d); 66 z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
73 } 67 }
74 68
75 w[0] = htonl(y); 69 w[0] = g_htonl(y);
76 w[1] = htonl(z); 70 w[1] = g_htonl(z);
77 } 71 }
78 72
79 static gint rand(void) { /* it can be the real random seed function */ 73 static gint rand(void) { /* it can be the real random seed function */
80 return 0xdead; 74 return 0xdead;
81 } /* override with number, convenient for debug */ 75 } /* override with number, convenient for debug */
173 * decryption 167 * decryption
174 ********************************************************************/ 168 ********************************************************************/
175 169
176 static void qq_decipher(guint32 *const v, const guint32 *const k, guint32 *const w) 170 static void qq_decipher(guint32 *const v, const guint32 *const k, guint32 *const w)
177 { 171 {
178 register guint32 y = ntohl(v[0]), 172 register guint32 y = g_ntohl(v[0]),
179 z = ntohl(v[1]), 173 z = g_ntohl(v[1]),
180 a = ntohl(k[0]), 174 a = g_ntohl(k[0]),
181 b = ntohl(k[1]), 175 b = g_ntohl(k[1]),
182 c = ntohl(k[2]), 176 c = g_ntohl(k[2]),
183 d = ntohl(k[3]), 177 d = g_ntohl(k[3]),
184 n = 0x10, 178 n = 0x10,
185 sum = 0xE3779B90, /* why this ? must be related with n value */ 179 sum = 0xE3779B90, /* why this ? must be related with n value */
186 delta = 0x9E3779B9; 180 delta = 0x9E3779B9;
187 181
188 /* sum = delta<<5, in general sum = delta * n */ 182 /* sum = delta<<5, in general sum = delta * n */
190 z -= ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d); 184 z -= ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
191 y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b); 185 y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
192 sum -= delta; 186 sum -= delta;
193 } 187 }
194 188
195 w[0] = htonl(y); 189 w[0] = g_htonl(y);
196 w[1] = htonl(z); 190 w[1] = g_htonl(z);
197 } 191 }
198 192
199 static gint decrypt_block(const guint8 **crypt_buff, const gint instrlen, 193 static gint decrypt_block(const guint8 **crypt_buff, const gint instrlen,
200 const guint8 *const key, gint *context_start, 194 const guint8 *const key, gint *context_start,
201 guint8 *decrypted, gint *pos_in_block) 195 guint8 *decrypted, gint *pos_in_block)