comparison src/ntlm.c @ 13698:6bee2e80e42c

[gaim-migrate @ 16101] Additional constification, add some comments, remove some superfluous whitespace, and changed gchar to guint8 in a few places. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 28 Apr 2006 03:52:09 +0000
parents 7f5b3313dd07
children c8043f9a4ce2
comparison
equal deleted inserted replaced
13697:89ceef5203ac 13698:6bee2e80e42c
138 memcpy(msg+sizeof(struct type1_message)+strlen(hostname),domain,strlen(domain)); 138 memcpy(msg+sizeof(struct type1_message)+strlen(hostname),domain,strlen(domain));
139 139
140 return gaim_base64_encode((guchar*)msg, sizeof(struct type1_message) + strlen(hostname) + strlen(domain)); 140 return gaim_base64_encode((guchar*)msg, sizeof(struct type1_message) + strlen(hostname) + strlen(domain));
141 } 141 }
142 142
143 gchar * 143 guint8 *
144 gaim_ntlm_parse_type2(const gchar *type2, guint32 *flags) 144 gaim_ntlm_parse_type2(const gchar *type2, guint32 *flags)
145 { 145 {
146 gsize retlen; 146 gsize retlen;
147 static gchar nonce[8]; 147 static guint8 nonce[8];
148 struct type2_message *tmsg = (struct type2_message*)gaim_base64_decode((char*)type2, &retlen); 148 struct type2_message *tmsg = (struct type2_message*)gaim_base64_decode((char*)type2, &retlen);
149 memcpy(nonce, tmsg->nonce, 8); 149 memcpy(nonce, tmsg->nonce, 8);
150 if(flags) *flags = tmsg->flags; 150 if(flags) *flags = tmsg->flags;
151 g_free(tmsg); 151 g_free(tmsg);
152 return nonce; 152 return nonce;
167 167
168 /* 168 /*
169 * helper function for gaim cipher.c 169 * helper function for gaim cipher.c
170 */ 170 */
171 static void 171 static void
172 des_ecb_encrypt(char *plaintext, char *result, char *key) 172 des_ecb_encrypt(const guint8 *plaintext, char *result, char *key)
173 { 173 {
174 GaimCipher *cipher; 174 GaimCipher *cipher;
175 GaimCipherContext *context; 175 GaimCipherContext *context;
176 gsize outlen; 176 gsize outlen;
177 177
186 * takes a 21 byte array and treats it as 3 56-bit DES keys. The 186 * takes a 21 byte array and treats it as 3 56-bit DES keys. The
187 * 8 byte plaintext is encrypted with each key and the resulting 24 187 * 8 byte plaintext is encrypted with each key and the resulting 24
188 * bytes are stored in the results array. 188 * bytes are stored in the results array.
189 */ 189 */
190 static void 190 static void
191 calc_resp(unsigned char *keys, unsigned char *plaintext, unsigned char *results) 191 calc_resp(unsigned char *keys, const guint8 *plaintext, unsigned char *results)
192 { 192 {
193 guchar key[8]; 193 guchar key[8];
194 setup_des_key(keys, (char*)key); 194 setup_des_key(keys, (char*)key);
195 des_ecb_encrypt((char*)plaintext, (char*)results, (char*)key); 195 des_ecb_encrypt(plaintext, (char*)results, (char*)key);
196 196
197 setup_des_key(keys+7, (char*)key); 197 setup_des_key(keys+7, (char*)key);
198 des_ecb_encrypt((char*)plaintext, (char*)(results+8), (char*)key); 198 des_ecb_encrypt(plaintext, (char*)(results+8), (char*)key);
199 199
200 setup_des_key(keys+14, (char*)key); 200 setup_des_key(keys+14, (char*)key);
201 des_ecb_encrypt((char*)plaintext, (char*)(results+16), (char*)key); 201 des_ecb_encrypt(plaintext, (char*)(results+16), (char*)key);
202 } 202 }
203 203
204 static void 204 static void
205 gensesskey(char *buffer, const char *oldkey) 205 gensesskey(char *buffer, const char *oldkey)
206 { 206 {
213 memcpy(buffer, oldkey, 16); 213 memcpy(buffer, oldkey, 16);
214 } 214 }
215 } 215 }
216 216
217 gchar * 217 gchar *
218 gaim_ntlm_gen_type3(const gchar *username, const gchar *passw, const gchar *hostname, const gchar *domain, gchar *nonce, guint32 *flags) 218 gaim_ntlm_gen_type3(const gchar *username, const gchar *passw, const gchar *hostname, const gchar *domain, const guint8 *nonce, guint32 *flags)
219 { 219 {
220 char lm_pw[14]; 220 char lm_pw[14];
221 unsigned char lm_hpw[21]; 221 unsigned char lm_hpw[21];
222 char sesskey[16]; 222 char sesskey[16];
223 gchar *sessionnonce = nonce;
224 gchar key[8]; 223 gchar key[8];
225 int msglen = sizeof(struct type3_message)+ 224 int msglen = sizeof(struct type3_message)+
226 strlen(domain) + strlen(username)+ 225 strlen(domain) + strlen(username)+
227 strlen(hostname) + 24 +24 + ((flags) ? 16 : 0); 226 strlen(hostname) + 24 +24 + ((flags) ? 16 : 0);
228 struct type3_message *tmsg = g_malloc0(msglen); 227 struct type3_message *tmsg = g_malloc0(msglen);
282 lm_pw[idx] = g_ascii_toupper(passw[idx]); 281 lm_pw[idx] = g_ascii_toupper(passw[idx]);
283 for (; idx<14; idx++) 282 for (; idx<14; idx++)
284 lm_pw[idx] = 0; 283 lm_pw[idx] = 0;
285 284
286 setup_des_key((unsigned char*)lm_pw, (char*)key); 285 setup_des_key((unsigned char*)lm_pw, (char*)key);
287 des_ecb_encrypt((char*)magic, (char*)lm_hpw, (char*)key); 286 des_ecb_encrypt(magic, (char*)lm_hpw, (char*)key);
288 287
289 setup_des_key((unsigned char*)(lm_pw+7), (char*)key); 288 setup_des_key((unsigned char*)(lm_pw+7), (char*)key);
290 des_ecb_encrypt((char*)magic, (char*)lm_hpw+8, (char*)key); 289 des_ecb_encrypt(magic, (char*)lm_hpw+8, (char*)key);
291 290
292 memset(lm_hpw+16, 0, 5); 291 memset(lm_hpw+16, 0, 5);
293 calc_resp(lm_hpw, (guchar*)sessionnonce, lm_resp); 292 calc_resp(lm_hpw, nonce, lm_resp);
294 293
295 /* NTLM */ 294 /* NTLM */
296 lennt = strlen(passw); 295 lennt = strlen(passw);
297 for (idx=0; idx<lennt; idx++) 296 for (idx=0; idx<lennt; idx++)
298 { 297 {
307 gaim_cipher_context_destroy(context); 306 gaim_cipher_context_destroy(context);
308 307
309 memset(nt_hpw+16, 0, 5); 308 memset(nt_hpw+16, 0, 5);
310 309
311 310
312 calc_resp(nt_hpw, (guchar*)sessionnonce, nt_resp); 311 calc_resp(nt_hpw, nonce, nt_resp);
313 memcpy(tmp, lm_resp, 0x18); 312 memcpy(tmp, lm_resp, 0x18);
314 tmp += 0x18; 313 tmp += 0x18;
315 memcpy(tmp, nt_resp, 0x18); 314 memcpy(tmp, nt_resp, 0x18);
316 tmp += 0x18; 315 tmp += 0x18;
317 316