Mercurial > pidgin.yaz
comparison src/ntlm.c @ 13699:c8043f9a4ce2
[gaim-migrate @ 16102]
Some more constification. I try to use guint8 for arbitrary data.
I'm not sure why. Meh.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 28 Apr 2006 04:25:58 +0000 |
parents | 6bee2e80e42c |
children | 1a1248de26ed |
comparison
equal
deleted
inserted
replaced
13698:6bee2e80e42c | 13699:c8043f9a4ce2 |
---|---|
113 guint8 lm_resp[*]; /* LanManager response */ | 113 guint8 lm_resp[*]; /* LanManager response */ |
114 guint8 nt_resp[*]; /* NT response */ | 114 guint8 nt_resp[*]; /* NT response */ |
115 #endif | 115 #endif |
116 }; | 116 }; |
117 | 117 |
118 /* TODO: Will this work on both little-endian and big-endian machines? */ | |
118 gchar * | 119 gchar * |
119 gaim_ntlm_gen_type1(const gchar *hostname, const gchar *domain) | 120 gaim_ntlm_gen_type1(const gchar *hostname, const gchar *domain) |
120 { | 121 { |
121 char *msg = g_malloc0(sizeof(struct type1_message) + strlen(hostname) + strlen(domain)); | 122 char *msg = g_malloc0(sizeof(struct type1_message) + strlen(hostname) + strlen(domain)); |
122 struct type1_message *tmsg = (struct type1_message*)msg; | 123 struct type1_message *tmsg = (struct type1_message*)msg; |
150 if(flags) *flags = tmsg->flags; | 151 if(flags) *flags = tmsg->flags; |
151 g_free(tmsg); | 152 g_free(tmsg); |
152 return nonce; | 153 return nonce; |
153 } | 154 } |
154 | 155 |
156 /** | |
157 * Create a 64bit DES key by taking a 56bit key and adding | |
158 * a parity bit after every 7th bit. | |
159 */ | |
155 static void | 160 static void |
156 setup_des_key(const unsigned char key_56[], char *key) | 161 setup_des_key(const guint8 key_56[], guint8 *key) |
157 { | 162 { |
158 key[0] = key_56[0]; | 163 key[0] = key_56[0]; |
159 key[1] = ((key_56[0] << 7) & 0xFF) | (key_56[1] >> 1); | 164 key[1] = ((key_56[0] << 7) & 0xFF) | (key_56[1] >> 1); |
160 key[2] = ((key_56[1] << 6) & 0xFF) | (key_56[2] >> 2); | 165 key[2] = ((key_56[1] << 6) & 0xFF) | (key_56[2] >> 2); |
161 key[3] = ((key_56[2] << 5) & 0xFF) | (key_56[3] >> 3); | 166 key[3] = ((key_56[2] << 5) & 0xFF) | (key_56[3] >> 3); |
167 | 172 |
168 /* | 173 /* |
169 * helper function for gaim cipher.c | 174 * helper function for gaim cipher.c |
170 */ | 175 */ |
171 static void | 176 static void |
172 des_ecb_encrypt(const guint8 *plaintext, char *result, char *key) | 177 des_ecb_encrypt(const guint8 *plaintext, char *result, const guint8 *key) |
173 { | 178 { |
174 GaimCipher *cipher; | 179 GaimCipher *cipher; |
175 GaimCipherContext *context; | 180 GaimCipherContext *context; |
176 gsize outlen; | 181 gsize outlen; |
177 | 182 |
178 cipher = gaim_ciphers_find_cipher("des"); | 183 cipher = gaim_ciphers_find_cipher("des"); |
179 context = gaim_cipher_context_new(cipher, NULL); | 184 context = gaim_cipher_context_new(cipher, NULL); |
180 gaim_cipher_context_set_key(context, (guchar*)key); | 185 gaim_cipher_context_set_key(context, key); |
181 gaim_cipher_context_encrypt(context, (guchar*)plaintext, 8, (guchar*)result, &outlen); | 186 gaim_cipher_context_encrypt(context, (guchar*)plaintext, 8, (guchar*)result, &outlen); |
182 gaim_cipher_context_destroy(context); | 187 gaim_cipher_context_destroy(context); |
183 } | 188 } |
184 | 189 |
185 /* | 190 /* |
186 * takes a 21 byte array and treats it as 3 56-bit DES keys. The | 191 * 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 | 192 * 8 byte plaintext is encrypted with each key and the resulting 24 |
188 * bytes are stored in the results array. | 193 * bytes are stored in the results array. |
189 */ | 194 */ |
190 static void | 195 static void |
191 calc_resp(unsigned char *keys, const guint8 *plaintext, unsigned char *results) | 196 calc_resp(guint8 *keys, const guint8 *plaintext, unsigned char *results) |
192 { | 197 { |
193 guchar key[8]; | 198 guint8 key[8]; |
194 setup_des_key(keys, (char*)key); | 199 setup_des_key(keys, key); |
195 des_ecb_encrypt(plaintext, (char*)results, (char*)key); | 200 des_ecb_encrypt(plaintext, (char*)results, key); |
196 | 201 |
197 setup_des_key(keys+7, (char*)key); | 202 setup_des_key(keys+7, key); |
198 des_ecb_encrypt(plaintext, (char*)(results+8), (char*)key); | 203 des_ecb_encrypt(plaintext, (char*)(results+8), key); |
199 | 204 |
200 setup_des_key(keys+14, (char*)key); | 205 setup_des_key(keys+14, key); |
201 des_ecb_encrypt(plaintext, (char*)(results+16), (char*)key); | 206 des_ecb_encrypt(plaintext, (char*)(results+16), key); |
202 } | 207 } |
203 | 208 |
204 static void | 209 static void |
205 gensesskey(char *buffer, const char *oldkey) | 210 gensesskey(char *buffer, const char *oldkey) |
206 { | 211 { |
218 gaim_ntlm_gen_type3(const gchar *username, const gchar *passw, const gchar *hostname, const gchar *domain, const guint8 *nonce, guint32 *flags) | 223 gaim_ntlm_gen_type3(const gchar *username, const gchar *passw, const gchar *hostname, const gchar *domain, const guint8 *nonce, guint32 *flags) |
219 { | 224 { |
220 char lm_pw[14]; | 225 char lm_pw[14]; |
221 unsigned char lm_hpw[21]; | 226 unsigned char lm_hpw[21]; |
222 char sesskey[16]; | 227 char sesskey[16]; |
223 gchar key[8]; | 228 guint8 key[8]; |
224 int msglen = sizeof(struct type3_message)+ | 229 int msglen = sizeof(struct type3_message)+ |
225 strlen(domain) + strlen(username)+ | 230 strlen(domain) + strlen(username)+ |
226 strlen(hostname) + 24 +24 + ((flags) ? 16 : 0); | 231 strlen(hostname) + 24 +24 + ((flags) ? 16 : 0); |
227 struct type3_message *tmsg = g_malloc0(msglen); | 232 struct type3_message *tmsg = g_malloc0(msglen); |
228 int len = strlen(passw); | 233 int len = strlen(passw); |
280 for (idx=0; idx<len; idx++) | 285 for (idx=0; idx<len; idx++) |
281 lm_pw[idx] = g_ascii_toupper(passw[idx]); | 286 lm_pw[idx] = g_ascii_toupper(passw[idx]); |
282 for (; idx<14; idx++) | 287 for (; idx<14; idx++) |
283 lm_pw[idx] = 0; | 288 lm_pw[idx] = 0; |
284 | 289 |
285 setup_des_key((unsigned char*)lm_pw, (char*)key); | 290 setup_des_key((unsigned char*)lm_pw, key); |
286 des_ecb_encrypt(magic, (char*)lm_hpw, (char*)key); | 291 des_ecb_encrypt(magic, (char*)lm_hpw, key); |
287 | 292 |
288 setup_des_key((unsigned char*)(lm_pw+7), (char*)key); | 293 setup_des_key((unsigned char*)(lm_pw+7), key); |
289 des_ecb_encrypt(magic, (char*)lm_hpw+8, (char*)key); | 294 des_ecb_encrypt(magic, (char*)lm_hpw+8, key); |
290 | 295 |
291 memset(lm_hpw+16, 0, 5); | 296 memset(lm_hpw+16, 0, 5); |
292 calc_resp(lm_hpw, nonce, lm_resp); | 297 calc_resp(lm_hpw, nonce, lm_resp); |
293 | 298 |
294 /* NTLM */ | 299 /* NTLM */ |