comparison src/ntlm.c @ 11427:e2ebebcae270

[gaim-migrate @ 13664] warning fixes committer: Tailor Script <tailor@pidgin.im>
author Thomas Butter <tbutter>
date Fri, 02 Sep 2005 19:46:07 +0000
parents 7e98b3bf2fdf
children 03cd74ca2562
comparison
equal deleted inserted replaced
11426:d678a37c16d9 11427:e2ebebcae270
125 tmsg->host_len1 = tmsg->host_len2 = strlen(hostname); 125 tmsg->host_len1 = tmsg->host_len2 = strlen(hostname);
126 tmsg->host_off= 32; 126 tmsg->host_off= 32;
127 memcpy(msg+sizeof(struct type1_message),hostname,strlen(hostname)); 127 memcpy(msg+sizeof(struct type1_message),hostname,strlen(hostname));
128 memcpy(msg+sizeof(struct type1_message)+strlen(hostname),domain,strlen(domain)); 128 memcpy(msg+sizeof(struct type1_message)+strlen(hostname),domain,strlen(domain));
129 129
130 return gaim_base64_encode(msg, sizeof(struct type1_message) + strlen(hostname) + strlen(domain)); 130 return gaim_base64_encode((guchar*)msg, sizeof(struct type1_message) + strlen(hostname) + strlen(domain));
131 } 131 }
132 132
133 gchar *gaim_ntlm_parse_type2(gchar *type2) { 133 gchar *gaim_ntlm_parse_type2(gchar *type2) {
134 int retlen; 134 guint retlen;
135 static gchar nonce[8]; 135 static gchar nonce[8];
136 struct type2_message *tmsg = (struct type2_message*)gaim_base64_decode(type2, &retlen); 136 struct type2_message *tmsg = (struct type2_message*)gaim_base64_decode((char*)type2, &retlen);
137 memcpy(nonce, tmsg->nonce, 8); 137 memcpy(nonce, tmsg->nonce, 8);
138 g_free(tmsg); 138 g_free(tmsg);
139 return nonce; 139 return nonce;
140 } 140 }
141 141
155 * helper function for gaim cipher.c 155 * helper function for gaim cipher.c
156 */ 156 */
157 static void des_ecb_encrypt(char *plaintext, char *result, char *key) { 157 static void des_ecb_encrypt(char *plaintext, char *result, char *key) {
158 GaimCipher *cipher; 158 GaimCipher *cipher;
159 GaimCipherContext *context; 159 GaimCipherContext *context;
160 int outlen; 160 guint outlen;
161 161
162 cipher = gaim_ciphers_find_cipher("des"); 162 cipher = gaim_ciphers_find_cipher("des");
163 context = gaim_cipher_context_new(cipher, NULL); 163 context = gaim_cipher_context_new(cipher, NULL);
164 gaim_cipher_context_set_key(context, key); 164 gaim_cipher_context_set_key(context, (guchar*)key);
165 gaim_cipher_context_encrypt(context, plaintext, 8, result, &outlen); 165 gaim_cipher_context_encrypt(context, (guchar*)plaintext, 8, (guchar*)result, &outlen);
166 gaim_cipher_context_destroy(context); 166 gaim_cipher_context_destroy(context);
167 } 167 }
168 168
169 /* 169 /*
170 * takes a 21 byte array and treats it as 3 56-bit DES keys. The 170 * takes a 21 byte array and treats it as 3 56-bit DES keys. The
171 * 8 byte plaintext is encrypted with each key and the resulting 24 171 * 8 byte plaintext is encrypted with each key and the resulting 24
172 * bytes are stored in the results array. 172 * bytes are stored in the results array.
173 */ 173 */
174 static void calc_resp(unsigned char *keys, unsigned char *plaintext, unsigned char *results) 174 static void calc_resp(unsigned char *keys, unsigned char *plaintext, unsigned char *results)
175 { 175 {
176 gchar key[8]; 176 guchar key[8];
177 setup_des_key(keys, key); 177 setup_des_key(keys, (char*)key);
178 des_ecb_encrypt(plaintext, results, key); 178 des_ecb_encrypt((char*)plaintext, (char*)results, (char*)key);
179 179
180 setup_des_key(keys+7, key); 180 setup_des_key(keys+7, (char*)key);
181 des_ecb_encrypt(plaintext, (results+8), key); 181 des_ecb_encrypt((char*)plaintext, (char*)(results+8), (char*)key);
182 182
183 setup_des_key(keys+14, key); 183 setup_des_key(keys+14, (char*)key);
184 des_ecb_encrypt(plaintext, (results+16), key); 184 des_ecb_encrypt((char*)plaintext, (char*)(results+16), (char*)key);
185 } 185 }
186 186
187 gchar *gaim_ntlm_gen_type3(gchar *username, gchar *passw, gchar *hostname, gchar *domain, gchar *nonce) { 187 gchar *gaim_ntlm_gen_type3(gchar *username, gchar *passw, gchar *hostname, gchar *domain, gchar *nonce) {
188 char lm_pw[14]; 188 char lm_pw[14];
189 unsigned char lm_hpw[21]; 189 unsigned char lm_hpw[21];
240 for (idx=0; idx<len; idx++) 240 for (idx=0; idx<len; idx++)
241 lm_pw[idx] = g_ascii_toupper(passw[idx]); 241 lm_pw[idx] = g_ascii_toupper(passw[idx]);
242 for (; idx<14; idx++) 242 for (; idx<14; idx++)
243 lm_pw[idx] = 0; 243 lm_pw[idx] = 0;
244 244
245 setup_des_key(lm_pw, key); 245 setup_des_key((unsigned char*)lm_pw, (char*)key);
246 des_ecb_encrypt(magic, lm_hpw, key); 246 des_ecb_encrypt((char*)magic, (char*)lm_hpw, (char*)key);
247 247
248 setup_des_key(lm_pw+7, key); 248 setup_des_key((unsigned char*)(lm_pw+7), (char*)key);
249 des_ecb_encrypt(magic, lm_hpw+8, key); 249 des_ecb_encrypt((char*)magic, (char*)lm_hpw+8, (char*)key);
250 250
251 memset(lm_hpw+16, 0, 5); 251 memset(lm_hpw+16, 0, 5);
252 252
253 253
254 lennt = strlen(passw); 254 lennt = strlen(passw);
258 nt_pw[2*idx+1] = 0; 258 nt_pw[2*idx+1] = 0;
259 } 259 }
260 260
261 cipher = gaim_ciphers_find_cipher("md4"); 261 cipher = gaim_ciphers_find_cipher("md4");
262 context = gaim_cipher_context_new(cipher, NULL); 262 context = gaim_cipher_context_new(cipher, NULL);
263 gaim_cipher_context_append(context, nt_pw, 2*lennt); 263 gaim_cipher_context_append(context, (guchar*)nt_pw, 2*lennt);
264 gaim_cipher_context_digest(context, 21, nt_hpw, NULL); 264 gaim_cipher_context_digest(context, 21, (guchar*)nt_hpw, NULL);
265 gaim_cipher_context_destroy(context); 265 gaim_cipher_context_destroy(context);
266 266
267 memset(nt_hpw+16, 0, 5); 267 memset(nt_hpw+16, 0, 5);
268 268
269 269
270 calc_resp(lm_hpw, nonce, lm_resp); 270 calc_resp(lm_hpw, (guchar*)nonce, lm_resp);
271 calc_resp(nt_hpw, nonce, nt_resp); 271 calc_resp(nt_hpw, (guchar*)nonce, nt_resp);
272 memcpy(tmp, lm_resp, 0x18); 272 memcpy(tmp, lm_resp, 0x18);
273 memcpy(tmp+0x18, nt_resp, 0x18); 273 memcpy(tmp+0x18, nt_resp, 0x18);
274 tmp = gaim_base64_encode((guchar*) tmsg, tmsg->msg_len); 274 tmp = gaim_base64_encode((guchar*) tmsg, tmsg->msg_len);
275 g_free(tmsg); 275 g_free(tmsg);
276 return tmp; 276 return tmp;