Forráskód Böngészése

Use uint32 !=, not tor_memneq, for relay cell integrity checking

tor_memeq has started to show up on profiles, and this is one of the
most frequent callers of that function, appearing as it does on every
cell handled for entry or exit.

59f9097d5c3dc010847c359888d31757d1c97904 introduced tor_memneq here;
it went into Tor 0.2.1.31.  Fixes part of 12169.
Nick Mathewson 10 éve
szülő
commit
d9564d5285
2 módosított fájl, 10 hozzáadás és 5 törlés
  1. 5 0
      changes/bug12169_simple
  2. 5 5
      src/or/relay.c

+ 5 - 0
changes/bug12169_simple

@@ -0,0 +1,5 @@
+  o Minor bugfixes (performance):
+    - Avoid using tor_memeq() for checking relay cell integrity.
+      This removes a possible performance bottleneck. Fixes part of bug
+      12169; bugfix on 0.2.1.31.
+

+ 5 - 5
src/or/relay.c

@@ -111,14 +111,14 @@ relay_set_digest(crypto_digest_t *digest, cell_t *cell)
 static int
 relay_digest_matches(crypto_digest_t *digest, cell_t *cell)
 {
-  char received_integrity[4], calculated_integrity[4];
+  uint32_t received_integrity, calculated_integrity;
   relay_header_t rh;
   crypto_digest_t *backup_digest=NULL;
 
   backup_digest = crypto_digest_dup(digest);
 
   relay_header_unpack(&rh, cell->payload);
-  memcpy(received_integrity, rh.integrity, 4);
+  memcpy(&received_integrity, rh.integrity, 4);
   memset(rh.integrity, 0, 4);
   relay_header_pack(cell->payload, &rh);
 
@@ -127,15 +127,15 @@ relay_digest_matches(crypto_digest_t *digest, cell_t *cell)
 //    received_integrity[2], received_integrity[3]);
 
   crypto_digest_add_bytes(digest, (char*) cell->payload, CELL_PAYLOAD_SIZE);
-  crypto_digest_get_digest(digest, calculated_integrity, 4);
+  crypto_digest_get_digest(digest, (char*) &calculated_integrity, 4);
 
-  if (tor_memneq(received_integrity, calculated_integrity, 4)) {
+  if (calculated_integrity != received_integrity) {
 //    log_fn(LOG_INFO,"Recognized=0 but bad digest. Not recognizing.");
 // (%d vs %d).", received_integrity, calculated_integrity);
     /* restore digest to its old form */
     crypto_digest_assign(digest, backup_digest);
     /* restore the relay header */
-    memcpy(rh.integrity, received_integrity, 4);
+    memcpy(rh.integrity, &received_integrity, 4);
     relay_header_pack(cell->payload, &rh);
     crypto_digest_free(backup_digest);
     return 0;