Browse Source

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

svn:r1489
Nick Mathewson 21 years ago
parent
commit
b1a8b208ca
1 changed files with 16 additions and 2 deletions
  1. 16 2
      src/or/circuit.c

+ 16 - 2
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;
   }