Make init_cpath_crypto able to handle both sides of handshake, by adding a "reverse" flag

svn:r1489
This commit is contained in:
Nick Mathewson 2004-04-05 20:53:04 +00:00
parent 34633c1122
commit b1a8b208ca

View File

@ -1398,10 +1398,15 @@ int circuit_extend(cell_t *cell, circuit_t *circ) {
* 20 to initialize b_digest
* 16 to key f_crypto
* 16 to key b_crypto
*
* (If 'reverse' is true, then f_XX and b_XX are swapped.)
*/
int circuit_init_cpath_crypto(crypt_path_t *cpath, char *key_data)
int circuit_init_cpath_crypto(crypt_path_t *cpath, char *key_data, int reverse)
{
unsigned char iv[CIPHER_IV_LEN];
crypto_digest_env_t *tmp_digest;
crypto_cipher_env_t *tmp_crypto;
assert(cpath && key_data);
assert(!(cpath->f_crypto || cpath->b_crypto ||
cpath->f_digest || cpath->b_digest));
@ -1426,6 +1431,15 @@ int circuit_init_cpath_crypto(crypt_path_t *cpath, char *key_data)
return -1;
}
if (reverse) {
tmp_digest = cpath->f_digest;
cpath->f_digest = cpath->b_digest;
cpath->b_digest = tmp_digest;
tmp_crypto = cpath->f_crypto;
cpath->f_crypto = cpath->b_crypto;
cpath->b_crypto = tmp_crypto;
}
return 0;
}
@ -1457,7 +1471,7 @@ int circuit_finish_handshake(circuit_t *circ, char *reply) {
/* Remember hash of g^xy */
memcpy(hop->handshake_digest, reply+DH_KEY_LEN, DIGEST_LEN);
if (circuit_init_cpath_crypto(hop, keys)<0) {
if (circuit_init_cpath_crypto(hop, keys, 0)<0) {
return -1;
}