From b1a8b208ca9a3fe4c1de1e5e53c32b147937b8f7 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 5 Apr 2004 20:53:04 +0000 Subject: [PATCH] Make init_cpath_crypto able to handle both sides of handshake, by adding a "reverse" flag svn:r1489 --- src/or/circuit.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/or/circuit.c b/src/or/circuit.c index abec47c0a9..82fb5aa74c 100644 --- a/src/or/circuit.c +++ b/src/or/circuit.c @@ -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; }