[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Store the sha3 of a networkstatus as part of the networkstatus_t



commit 112286338b61ed747572cfa67ac38e2052e7c807
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Wed May 3 10:17:37 2017 -0400

    Store the sha3 of a networkstatus as part of the networkstatus_t
    
    Also store it in the cached_dir_t.
---
 src/or/dirserv.c               | 4 ++++
 src/or/dirserv.h               | 1 +
 src/or/networkstatus.c         | 1 +
 src/or/or.h                    | 4 ++++
 src/or/routerparse.c           | 7 ++++++-
 src/test/test_dir_handle_get.c | 4 ++++
 6 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index bdf40b6..af7ec97 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -1212,6 +1212,8 @@ void
 dirserv_set_cached_consensus_networkstatus(const char *networkstatus,
                                            const char *flavor_name,
                                            const common_digests_t *digests,
+                                           // XXXX rename after 22143
+                                           const uint8_t *sha3_full_digest,
                                            time_t published)
 {
   cached_dir_t *new_networkstatus;
@@ -1221,6 +1223,8 @@ dirserv_set_cached_consensus_networkstatus(const char *networkstatus,
 
   new_networkstatus = new_cached_dir(tor_strdup(networkstatus), published);
   memcpy(&new_networkstatus->digests, digests, sizeof(common_digests_t));
+  memcpy(&new_networkstatus->digest_sha3_full, sha3_full_digest,
+         DIGEST256_LEN);
   old_networkstatus = strmap_set(cached_consensuses, flavor_name,
                                  new_networkstatus);
   if (old_networkstatus)
diff --git a/src/or/dirserv.h b/src/or/dirserv.h
index 4b09f87..480174d 100644
--- a/src/or/dirserv.h
+++ b/src/or/dirserv.h
@@ -118,6 +118,7 @@ cached_dir_t *dirserv_get_consensus(const char *flavor_name);
 void dirserv_set_cached_consensus_networkstatus(const char *consensus,
                                               const char *flavor_name,
                                               const common_digests_t *digests,
+                                              const uint8_t *sha3_as_signed,
                                               time_t published);
 void dirserv_clear_old_networkstatuses(time_t cutoff);
 int dirserv_get_routerdesc_spool(smartlist_t *spools_out, const char *key,
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index 188e753..8a5cdaf 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -1981,6 +1981,7 @@ networkstatus_set_current_consensus(const char *consensus,
     dirserv_set_cached_consensus_networkstatus(consensus,
                                                flavor,
                                                &c->digests,
+                                               c->digest_full_sha3,
                                                c->valid_after);
     if (server_mode(get_options())) {
       consdiffmgr_add_consensus(consensus, c);
diff --git a/src/or/or.h b/src/or/or.h
index e30a1d2..b69fcf1 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1938,6 +1938,7 @@ typedef struct cached_dir_t {
   size_t dir_z_len; /**< Length of <b>dir_z</b>. */
   time_t published; /**< When was this object published. */
   common_digests_t digests; /**< Digests of this object (networkstatus only) */
+  uint8_t digest_sha3_full[DIGEST256_LEN]; /**< sha3 digest (also ns only) */
   int refcnt; /**< Reference count for this cached_dir_t. */
 } cached_dir_t;
 
@@ -2638,6 +2639,9 @@ typedef struct networkstatus_t {
 
   /** Digests of this document, as signed. */
   common_digests_t digests;
+  /** A SHA3-256 digest of the document, including signatures: used for
+   * consensus diffs */
+  uint8_t digest_full_sha3[DIGEST256_LEN];
 
   /** List of router statuses, sorted by identity digest.  For a vote,
    * the elements are vote_routerstatus_t; for a consensus, the elements
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index f39c332..4def75a 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -3384,6 +3384,7 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out,
   networkstatus_voter_info_t *voter = NULL;
   networkstatus_t *ns = NULL;
   common_digests_t ns_digests;
+  uint8_t sha3_full[DIGEST256_LEN];
   const char *cert, *end_of_header, *end_of_footer, *s_dup = s;
   directory_token_t *tok;
   struct in_addr in;
@@ -3397,7 +3398,10 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out,
   if (eos_out)
     *eos_out = NULL;
 
-  if (router_get_networkstatus_v3_hashes(s, &ns_digests)) {
+  // XXXX replace SHA3_full with as_signed digest once #22143 is merged.
+  // XXXX Merge #22143 before this!
+  if (router_get_networkstatus_v3_hashes(s, &ns_digests) ||
+      crypto_digest256((char *)sha3_full, s, strlen(s), DIGEST_SHA3_256)<0) {
     log_warn(LD_DIR, "Unable to compute digest of network-status");
     goto err;
   }
@@ -3414,6 +3418,7 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out,
 
   ns = tor_malloc_zero(sizeof(networkstatus_t));
   memcpy(&ns->digests, &ns_digests, sizeof(ns_digests));
+  memcpy(&ns->digest_full_sha3, sha3_full, sizeof(sha3_full));
 
   tok = find_by_keyword(tokens, K_NETWORK_STATUS_VERSION);
   tor_assert(tok);
diff --git a/src/test/test_dir_handle_get.c b/src/test/test_dir_handle_get.c
index 6e96391..c98938b 100644
--- a/src/test/test_dir_handle_get.c
+++ b/src/test/test_dir_handle_get.c
@@ -1773,10 +1773,14 @@ status_vote_current_consensus_ns_test(char **header, char **body,
                                       size_t *body_len)
 {
   common_digests_t digests;
+  uint8_t sha3[DIGEST256_LEN];
   dir_connection_t *conn = NULL;
 
   #define NETWORK_STATUS "some network status string"
+  memset(&digests, 0x60, sizeof(digests));
+  memset(sha3, 0x06, sizeof(sha3));
   dirserv_set_cached_consensus_networkstatus(NETWORK_STATUS, "ns", &digests,
+                                             sha3,
                                              time(NULL));
 
   MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits