[tor-commits] [tor/master] sendme: Keep cell digest only if a SENDME is next

asn at torproject.org asn at torproject.org
Thu May 2 15:16:21 UTC 2019


commit c7385b5b14b30774c1768798c4495465da4d995d
Author: David Goulet <dgoulet at torproject.org>
Date:   Wed Apr 24 13:38:47 2019 -0400

    sendme: Keep cell digest only if a SENDME is next
    
    This way, we reduce the load by only hashing when we absolutely must.
    
    Part of #26288
    
    Signed-off-by: David Goulet <dgoulet at torproject.org>
---
 src/core/crypto/relay_crypto.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/core/crypto/relay_crypto.c b/src/core/crypto/relay_crypto.c
index 94e906065..eddc4298e 100644
--- a/src/core/crypto/relay_crypto.c
+++ b/src/core/crypto/relay_crypto.c
@@ -12,6 +12,7 @@
 #include "core/crypto/hs_ntor.h" // for HS_NTOR_KEY_EXPANSION_KDF_OUT_LEN
 #include "core/or/relay.h"
 #include "core/crypto/relay_crypto.h"
+#include "core/or/sendme.h"
 
 #include "core/or/cell_st.h"
 #include "core/or/or_circuit_st.h"
@@ -142,10 +143,11 @@ relay_decrypt_cell(circuit_t *circ, cell_t *cell,
           if (relay_digest_matches(thishop->crypto.b_digest, cell)) {
             *recognized = 1;
             *layer_hint = thishop;
-            /* Keep current digest of this cell for the possible SENDME. */
-            crypto_digest_get_digest(thishop->crypto.b_digest,
-                                     (char *) thishop->crypto.sendme_digest,
-                                     sizeof(thishop->crypto.sendme_digest));
+            /* This cell is for us. Keep a record of this cell because we will
+             * use it in the next SENDME cell. */
+            if (sendme_circuit_is_next_cell(thishop->deliver_window)) {
+              sendme_circuit_note_inbound_cell(thishop);
+            }
             return 0;
           }
         }
@@ -216,10 +218,13 @@ relay_encrypt_cell_inbound(cell_t *cell,
                            or_circuit_t *or_circ)
 {
   relay_set_digest(or_circ->crypto.b_digest, cell);
-  /* Keep a record of this cell, we might use it for validating the SENDME. */
-  crypto_digest_get_digest(or_circ->crypto.b_digest,
-                           (char *) or_circ->crypto.sendme_digest,
-                           sizeof(or_circ->crypto.sendme_digest));
+
+  /* We are about to send this cell outbound on the circuit. Keep a record of
+   * this cell if we are expecting that the next cell is a SENDME. */
+  if (sendme_circuit_is_next_cell(TO_CIRCUIT(or_circ)->package_window)) {
+    sendme_circuit_note_outbound_cell(or_circ);
+  }
+
   /* encrypt one layer */
   relay_crypt_one_payload(or_circ->crypto.b_crypto, cell->payload);
 }





More information about the tor-commits mailing list