[tor-commits] [tor/master] Optimize legacy intro point digest calculation.

dgoulet at torproject.org dgoulet at torproject.org
Thu May 3 13:39:19 UTC 2018


commit af70d3c459d3b11b04e49c1b659183fe2e96e252
Author: Neel Chauhan <neel at neelc.org>
Date:   Fri Apr 27 17:45:16 2018 -0400

    Optimize legacy intro point digest calculation.
---
 changes/bug23107    |  6 ++++++
 src/or/hs_circuit.c | 19 ++++---------------
 src/or/hs_service.c |  4 ++++
 src/or/hs_service.h |  3 +++
 4 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/changes/bug23107 b/changes/bug23107
new file mode 100644
index 000000000..70d1856bb
--- /dev/null
+++ b/changes/bug23107
@@ -0,0 +1,6 @@
+  o Code simplification and refactoring:
+    - Put a SHA1 public key digest in hs_service_intro_point_t, and use it in
+      register_intro_circ() and service_intro_point_new(). This prevents the
+      digest from being re-calculated each time. Fixes bug 23107. Patch by 
+      Neel Chauhan.
+
diff --git a/src/or/hs_circuit.c b/src/or/hs_circuit.c
index 3a674f622..417447063 100644
--- a/src/or/hs_circuit.c
+++ b/src/or/hs_circuit.c
@@ -193,11 +193,8 @@ register_intro_circ(const hs_service_intro_point_t *ip,
   tor_assert(circ);
 
   if (ip->base.is_only_legacy) {
-    uint8_t digest[DIGEST_LEN];
-    if (BUG(crypto_pk_get_digest(ip->legacy_key, (char *) digest) < 0)) {
-      return;
-    }
-    hs_circuitmap_register_intro_circ_v2_service_side(circ, digest);
+    hs_circuitmap_register_intro_circ_v2_service_side(circ,
+                                                      ip->legacy_key_digest);
   } else {
     hs_circuitmap_register_intro_circ_v3_service_side(circ,
                                          &ip->auth_key_kp.pubkey);
@@ -675,22 +672,14 @@ setup_introduce1_data(const hs_desc_intro_point_t *ip,
 origin_circuit_t *
 hs_circ_service_get_intro_circ(const hs_service_intro_point_t *ip)
 {
-  origin_circuit_t *circ = NULL;
-
   tor_assert(ip);
 
   if (ip->base.is_only_legacy) {
-    uint8_t digest[DIGEST_LEN];
-    if (BUG(crypto_pk_get_digest(ip->legacy_key, (char *) digest) < 0)) {
-      goto end;
-    }
-    circ = hs_circuitmap_get_intro_circ_v2_service_side(digest);
+    return hs_circuitmap_get_intro_circ_v2_service_side(ip->legacy_key_digest);
   } else {
-    circ = hs_circuitmap_get_intro_circ_v3_service_side(
+    return hs_circuitmap_get_intro_circ_v3_service_side(
                                         &ip->auth_key_kp.pubkey);
   }
- end:
-  return circ;
 }
 
 /* Called when we fail building a rendezvous circuit at some point other than
diff --git a/src/or/hs_service.c b/src/or/hs_service.c
index e40e9203e..cf2760760 100644
--- a/src/or/hs_service.c
+++ b/src/or/hs_service.c
@@ -441,6 +441,10 @@ service_intro_point_new(const extend_info_t *ei, unsigned int is_legacy)
     if (crypto_pk_generate_key(ip->legacy_key) < 0) {
       goto err;
     }
+    if (crypto_pk_get_digest(ip->legacy_key,
+                             (char *) ip->legacy_key_digest) < 0) {
+      goto err;
+    }
   }
 
   if (ei == NULL) {
diff --git a/src/or/hs_service.h b/src/or/hs_service.h
index 2e27d8a89..ea7ee9ecf 100644
--- a/src/or/hs_service.h
+++ b/src/or/hs_service.h
@@ -51,6 +51,9 @@ typedef struct hs_service_intro_point_t {
    * the base object legacy flag is set. */
   crypto_pk_t *legacy_key;
 
+  /* Legacy key SHA1 public key digest. */
+   uint8_t legacy_key_digest[DIGEST_LEN];
+
   /* Amount of INTRODUCE2 cell accepted from this intro point. */
   uint64_t introduce2_count;
 





More information about the tor-commits mailing list