From 2151b81a2ed1f48d1e805972659b6fe20fdc989e Mon Sep 17 00:00:00 2001
From: Neel Chauhan <neel@neelc.org>
Date: Fri, 27 Apr 2018 14:11:43 -0400
Subject: [PATCH] Add a cached SHA1 public key digest nii
hs_service_intro_point_t and use it in register_intro_circ() and
service_intro_point_new()
---
changes/bug23107 | 6 ++++++
src/or/hs_circuit.c | 18 ++++++++++--------
src/or/hs_service.c | 3 +++
src/or/hs_service.h | 3 +++
4 files changed, 22 insertions(+), 8 deletions(-)
create mode 100644 changes/bug23107
diff --git a/changes/bug23107 b/changes/bug23107
new file mode 100644
index 000000000..d47b12500
-
|
+
|
|
| 1 | o Code simplification and refactoring: |
| 2 | - Put a cached SHA1 public key digest in hs_service_intro_point_t, and use |
| 3 | it in register_intro_circ() and service_intro_point_new(). This prevents |
| 4 | the digest from being re-calculated each time. Fixes bug 23107. Patch by |
| 5 | Neel Chauhan. |
| 6 | |
diff --git a/src/or/hs_circuit.c b/src/or/hs_circuit.c
index 3a674f622..b34a78892 100644
a
|
b
|
register_intro_circ(const hs_service_intro_point_t *ip, |
193 | 193 | tor_assert(circ); |
194 | 194 | |
195 | 195 | if (ip->base.is_only_legacy) { |
196 | | uint8_t digest[DIGEST_LEN]; |
197 | | if (BUG(crypto_pk_get_digest(ip->legacy_key, (char *) digest) < 0)) { |
198 | | return; |
| 196 | if (tor_digest_is_zero((const char *) ip->digest)) { |
| 197 | if (BUG(crypto_pk_get_digest(ip->legacy_key, (char *) ip->digest) < 0)) { |
| 198 | return; |
| 199 | } |
199 | 200 | } |
200 | | hs_circuitmap_register_intro_circ_v2_service_side(circ, digest); |
| 201 | hs_circuitmap_register_intro_circ_v2_service_side(circ, ip->digest); |
201 | 202 | } else { |
202 | 203 | hs_circuitmap_register_intro_circ_v3_service_side(circ, |
203 | 204 | &ip->auth_key_kp.pubkey); |
… |
… |
hs_circ_service_get_intro_circ(const hs_service_intro_point_t *ip) |
680 | 681 | tor_assert(ip); |
681 | 682 | |
682 | 683 | if (ip->base.is_only_legacy) { |
683 | | uint8_t digest[DIGEST_LEN]; |
684 | | if (BUG(crypto_pk_get_digest(ip->legacy_key, (char *) digest) < 0)) { |
685 | | goto end; |
| 684 | if (tor_digest_is_zero((const char *) ip->digest)) { |
| 685 | if (BUG(crypto_pk_get_digest(ip->legacy_key, (char *) ip->digest) < 0)) { |
| 686 | goto end; |
| 687 | } |
686 | 688 | } |
687 | | circ = hs_circuitmap_get_intro_circ_v2_service_side(digest); |
| 689 | circ = hs_circuitmap_get_intro_circ_v2_service_side(ip->digest); |
688 | 690 | } else { |
689 | 691 | circ = hs_circuitmap_get_intro_circ_v3_service_side( |
690 | 692 | &ip->auth_key_kp.pubkey); |
diff --git a/src/or/hs_service.c b/src/or/hs_service.c
index f6c7e3cd8..2584aeefa 100644
a
|
b
|
service_intro_point_new(const extend_info_t *ei, unsigned int is_legacy) |
458 | 458 | smartlist_add(ip->base.link_specifiers, ls); |
459 | 459 | } |
460 | 460 | |
| 461 | /* Blank the cached SHA1 public key digest. */ |
| 462 | memset(ip->digest, 0, sizeof(ip->digest)); |
| 463 | |
461 | 464 | /* IPv6 is not supported in this release. */ |
462 | 465 | |
463 | 466 | /* Finally, copy onion key from the extend_info_t object. */ |
diff --git a/src/or/hs_service.h b/src/or/hs_service.h
index d163eeef2..ed61eea53 100644
a
|
b
|
typedef struct hs_service_intro_point_t { |
51 | 51 | * the base object legacy flag is set. */ |
52 | 52 | crypto_pk_t *legacy_key; |
53 | 53 | |
| 54 | /* Cached SHA1 public key digest. */ |
| 55 | uint8_t digest[DIGEST_LEN]; |
| 56 | |
54 | 57 | /* Amount of INTRODUCE2 cell accepted from this intro point. */ |
55 | 58 | uint64_t introduce2_count; |
56 | 59 | |