Mercurial > pidgin
comparison src/ntlm.c @ 13677:7f5b3313dd07
[gaim-migrate @ 16079]
Add "const" to some function parameters.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 22 Apr 2006 15:11:07 +0000 |
parents | a91a8a28f61f |
children | 6bee2e80e42c |
comparison
equal
deleted
inserted
replaced
13676:1f1dc7f4cd29 | 13677:7f5b3313dd07 |
---|---|
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 gchar *gaim_ntlm_gen_type1(gchar *hostname, gchar *domain) { | 118 gchar * |
119 gaim_ntlm_gen_type1(const gchar *hostname, const gchar *domain) | |
120 { | |
119 char *msg = g_malloc0(sizeof(struct type1_message) + strlen(hostname) + strlen(domain)); | 121 char *msg = g_malloc0(sizeof(struct type1_message) + strlen(hostname) + strlen(domain)); |
120 struct type1_message *tmsg = (struct type1_message*)msg; | 122 struct type1_message *tmsg = (struct type1_message*)msg; |
121 tmsg->protocol[0] = 'N'; | 123 tmsg->protocol[0] = 'N'; |
122 tmsg->protocol[1] = 'T'; | 124 tmsg->protocol[1] = 'T'; |
123 tmsg->protocol[2] = 'L'; | 125 tmsg->protocol[2] = 'L'; |
136 memcpy(msg+sizeof(struct type1_message)+strlen(hostname),domain,strlen(domain)); | 138 memcpy(msg+sizeof(struct type1_message)+strlen(hostname),domain,strlen(domain)); |
137 | 139 |
138 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)); |
139 } | 141 } |
140 | 142 |
141 gchar *gaim_ntlm_parse_type2(gchar *type2, guint32 *flags) { | 143 gchar * |
144 gaim_ntlm_parse_type2(const gchar *type2, guint32 *flags) | |
145 { | |
142 gsize retlen; | 146 gsize retlen; |
143 static gchar nonce[8]; | 147 static gchar nonce[8]; |
144 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); |
145 memcpy(nonce, tmsg->nonce, 8); | 149 memcpy(nonce, tmsg->nonce, 8); |
146 if(flags) *flags = tmsg->flags; | 150 if(flags) *flags = tmsg->flags; |
147 g_free(tmsg); | 151 g_free(tmsg); |
148 return nonce; | 152 return nonce; |
149 } | 153 } |
150 | 154 |
151 static void setup_des_key(unsigned char key_56[], char *key) | 155 static void |
156 setup_des_key(const unsigned char key_56[], char *key) | |
152 { | 157 { |
153 key[0] = key_56[0]; | 158 key[0] = key_56[0]; |
154 key[1] = ((key_56[0] << 7) & 0xFF) | (key_56[1] >> 1); | 159 key[1] = ((key_56[0] << 7) & 0xFF) | (key_56[1] >> 1); |
155 key[2] = ((key_56[1] << 6) & 0xFF) | (key_56[2] >> 2); | 160 key[2] = ((key_56[1] << 6) & 0xFF) | (key_56[2] >> 2); |
156 key[3] = ((key_56[2] << 5) & 0xFF) | (key_56[3] >> 3); | 161 key[3] = ((key_56[2] << 5) & 0xFF) | (key_56[3] >> 3); |
161 } | 166 } |
162 | 167 |
163 /* | 168 /* |
164 * helper function for gaim cipher.c | 169 * helper function for gaim cipher.c |
165 */ | 170 */ |
166 static void des_ecb_encrypt(char *plaintext, char *result, char *key) { | 171 static void |
172 des_ecb_encrypt(char *plaintext, char *result, char *key) | |
173 { | |
167 GaimCipher *cipher; | 174 GaimCipher *cipher; |
168 GaimCipherContext *context; | 175 GaimCipherContext *context; |
169 gsize outlen; | 176 gsize outlen; |
170 | 177 |
171 cipher = gaim_ciphers_find_cipher("des"); | 178 cipher = gaim_ciphers_find_cipher("des"); |
172 context = gaim_cipher_context_new(cipher, NULL); | 179 context = gaim_cipher_context_new(cipher, NULL); |
173 gaim_cipher_context_set_key(context, (guchar*)key); | 180 gaim_cipher_context_set_key(context, (guchar*)key); |
174 gaim_cipher_context_encrypt(context, (guchar*)plaintext, 8, (guchar*)result, &outlen); | 181 gaim_cipher_context_encrypt(context, (guchar*)plaintext, 8, (guchar*)result, &outlen); |
175 gaim_cipher_context_destroy(context); | 182 gaim_cipher_context_destroy(context); |
178 /* | 185 /* |
179 * 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 |
180 * 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 |
181 * bytes are stored in the results array. | 188 * bytes are stored in the results array. |
182 */ | 189 */ |
183 static void calc_resp(unsigned char *keys, unsigned char *plaintext, unsigned char *results) | 190 static void |
191 calc_resp(unsigned char *keys, unsigned char *plaintext, unsigned char *results) | |
184 { | 192 { |
185 guchar key[8]; | 193 guchar key[8]; |
186 setup_des_key(keys, (char*)key); | 194 setup_des_key(keys, (char*)key); |
187 des_ecb_encrypt((char*)plaintext, (char*)results, (char*)key); | 195 des_ecb_encrypt((char*)plaintext, (char*)results, (char*)key); |
188 | 196 |
191 | 199 |
192 setup_des_key(keys+14, (char*)key); | 200 setup_des_key(keys+14, (char*)key); |
193 des_ecb_encrypt((char*)plaintext, (char*)(results+16), (char*)key); | 201 des_ecb_encrypt((char*)plaintext, (char*)(results+16), (char*)key); |
194 } | 202 } |
195 | 203 |
196 static void gensesskey(char *buffer, char *oldkey) { | 204 static void |
205 gensesskey(char *buffer, const char *oldkey) | |
206 { | |
197 int i = 0; | 207 int i = 0; |
198 if(oldkey == NULL) { | 208 if(oldkey == NULL) { |
199 for(i=0; i<16; i++) { | 209 for(i=0; i<16; i++) { |
200 buffer[i] = (char)(rand() & 0xff); | 210 buffer[i] = (char)(rand() & 0xff); |
201 } | 211 } |