43 |
static RC4_KEY rc4_decrypt_key; |
static RC4_KEY rc4_decrypt_key; |
44 |
static RC4_KEY rc4_encrypt_key; |
static RC4_KEY rc4_encrypt_key; |
45 |
|
|
46 |
static uint8 sec_sign_key[8]; |
static uint8 sec_sign_key[16]; |
47 |
static uint8 sec_decrypt_key[16]; |
static uint8 sec_decrypt_key[16]; |
48 |
static uint8 sec_encrypt_key[16]; |
static uint8 sec_encrypt_key[16]; |
49 |
static uint8 sec_decrypt_update_key[8]; |
static uint8 sec_decrypt_update_key[16]; |
50 |
static uint8 sec_encrypt_update_key[8]; |
static uint8 sec_encrypt_update_key[16]; |
51 |
static uint8 sec_crypted_random[64]; |
static uint8 sec_crypted_random[SEC_MODULUS_SIZE]; |
52 |
|
|
53 |
/* |
/* |
54 |
* General purpose 48-byte transformation, using two 32-byte salts (generally, |
* General purpose 48-byte transformation, using two 32-byte salts (generally, |
123 |
sec_hash_48(temp_hash, input, client_key, server_key, 65); |
sec_hash_48(temp_hash, input, client_key, server_key, 65); |
124 |
sec_hash_48(session_key, temp_hash, client_key, server_key, 88); |
sec_hash_48(session_key, temp_hash, client_key, server_key, 88); |
125 |
|
|
126 |
/* Store first 8 bytes of session key, for generating signatures */ |
/* Store first 16 bytes of session key, for generating signatures */ |
127 |
memcpy(sec_sign_key, session_key, 8); |
memcpy(sec_sign_key, session_key, 16); |
128 |
|
|
129 |
/* Generate RC4 keys */ |
/* Generate RC4 keys */ |
130 |
sec_hash_16(sec_decrypt_key, &session_key[16], client_key, |
sec_hash_16(sec_decrypt_key, &session_key[16], client_key, |
146 |
rc4_key_len = 16; |
rc4_key_len = 16; |
147 |
} |
} |
148 |
|
|
149 |
/* Store first 8 bytes of RC4 keys as update keys */ |
/* Save initial RC4 keys as update keys */ |
150 |
memcpy(sec_decrypt_update_key, sec_decrypt_key, 8); |
memcpy(sec_decrypt_update_key, sec_decrypt_key, 16); |
151 |
memcpy(sec_encrypt_update_key, sec_encrypt_key, 8); |
memcpy(sec_encrypt_update_key, sec_encrypt_key, 16); |
152 |
|
|
153 |
/* Initialise RC4 state arrays */ |
/* Initialise RC4 state arrays */ |
154 |
RC4_set_key(&rc4_decrypt_key, rc4_key_len, sec_decrypt_key); |
RC4_set_key(&rc4_decrypt_key, rc4_key_len, sec_decrypt_key); |
193 |
buf_out_uint32(lenhdr, datalen); |
buf_out_uint32(lenhdr, datalen); |
194 |
|
|
195 |
SHA1_Init(&sha); |
SHA1_Init(&sha); |
196 |
SHA1_Update(&sha, session_key, length); |
SHA1_Update(&sha, session_key, rc4_key_len); |
197 |
SHA1_Update(&sha, pad_54, 40); |
SHA1_Update(&sha, pad_54, 40); |
198 |
SHA1_Update(&sha, lenhdr, 4); |
SHA1_Update(&sha, lenhdr, 4); |
199 |
SHA1_Update(&sha, data, datalen); |
SHA1_Update(&sha, data, datalen); |
200 |
SHA1_Final(shasig, &sha); |
SHA1_Final(shasig, &sha); |
201 |
|
|
202 |
MD5_Init(&md5); |
MD5_Init(&md5); |
203 |
MD5_Update(&md5, session_key, length); |
MD5_Update(&md5, session_key, rc4_key_len); |
204 |
MD5_Update(&md5, pad_92, 48); |
MD5_Update(&md5, pad_92, 48); |
205 |
MD5_Update(&md5, shasig, 20); |
MD5_Update(&md5, shasig, 20); |
206 |
MD5_Final(md5sig, &md5); |
MD5_Final(md5sig, &md5); |
218 |
RC4_KEY update; |
RC4_KEY update; |
219 |
|
|
220 |
SHA1_Init(&sha); |
SHA1_Init(&sha); |
221 |
SHA1_Update(&sha, update_key, 8); |
SHA1_Update(&sha, update_key, rc4_key_len); |
222 |
SHA1_Update(&sha, pad_54, 40); |
SHA1_Update(&sha, pad_54, 40); |
223 |
SHA1_Update(&sha, key, 8); |
SHA1_Update(&sha, key, rc4_key_len); |
224 |
SHA1_Final(shasig, &sha); |
SHA1_Final(shasig, &sha); |
225 |
|
|
226 |
MD5_Init(&md5); |
MD5_Init(&md5); |
227 |
MD5_Update(&md5, update_key, 8); |
MD5_Update(&md5, update_key, rc4_key_len); |
228 |
MD5_Update(&md5, pad_92, 48); |
MD5_Update(&md5, pad_92, 48); |
229 |
MD5_Update(&md5, shasig, 20); |
MD5_Update(&md5, shasig, 20); |
230 |
MD5_Final(key, &md5); |
MD5_Final(key, &md5); |
432 |
/* Client encryption settings */ |
/* Client encryption settings */ |
433 |
out_uint16_le(s, SEC_TAG_CLI_CRYPT); |
out_uint16_le(s, SEC_TAG_CLI_CRYPT); |
434 |
out_uint16(s, 8); /* length */ |
out_uint16(s, 8); /* length */ |
435 |
out_uint32_le(s, encryption ? 1 : 0); /* encryption enabled */ |
out_uint32_le(s, encryption ? 0x3 : 0); /* encryption supported, 128-bit supported */ |
436 |
s_mark_end(s); |
s_mark_end(s); |
437 |
} |
} |
438 |
|
|