]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Merge remote-tracking branch 'public/3122_memcmp_squashed' into bug3122_memcmp_022
authorNick Mathewson <nickm@torproject.org>
Wed, 11 May 2011 20:23:42 +0000 (16:23 -0400)
committerNick Mathewson <nickm@torproject.org>
Wed, 11 May 2011 20:24:29 +0000 (16:24 -0400)
Conflicts throughout.  All resolved in favor of taking HEAD and
adding tor_mem* or fast_mem* ops as appropriate.

src/common/Makefile.am
src/or/circuitbuild.c
src/or/directory.c
src/or/dirserv.c
src/or/dirvote.c
src/or/networkstatus.c
src/or/rendclient.c
src/or/rendservice.c
src/or/router.c
src/or/routerlist.c
src/or/routerparse.c
src/or/test.c

31 files changed:
1  2 
configure.in
src/common/Makefile.am
src/common/address.c
src/common/compat.c
src/common/container.c
src/common/container.h
src/common/crypto.c
src/common/torgzip.c
src/common/util.c
src/common/util.h
src/or/circuitbuild.c
src/or/circuitlist.c
src/or/circuituse.c
src/or/connection_edge.c
src/or/connection_or.c
src/or/control.c
src/or/directory.c
src/or/dirserv.c
src/or/dirvote.c
src/or/eventdns.c
src/or/networkstatus.c
src/or/onion.c
src/or/relay.c
src/or/rendclient.c
src/or/rendcommon.c
src/or/rendmid.c
src/or/rendservice.c
src/or/rephist.c
src/or/router.c
src/or/routerlist.c
src/or/routerparse.c

diff --cc configure.in
Simple merge
index b1e03cd7101336b3ed028931761d9f1997d6d836,db94a984ca323e36e360711d0bb33446d31f0fd5..2d009bd4fa50646164c1ee3793b9942f0aec94b4
@@@ -12,21 -10,7 +12,21 @@@ libor_extra_source
  endif
  
  libor_a_SOURCES = address.c log.c util.c compat.c container.c mempool.c \
-       memarea.c util_codedigest.c $(libor_extra_source)
 -      memarea.c di_ops.c $(libor_extra_source)
++      memarea.c di_ops.c util_codedigest.c $(libor_extra_source)
  libor_crypto_a_SOURCES = crypto.c aes.c tortls.c torgzip.c
- noinst_HEADERS = address.h torlog.h crypto.h util.h compat.h aes.h torint.h tortls.h strlcpy.c strlcat.c torgzip.h container.h ht.h mempool.h memarea.h ciphers.inc compat_libevent.h tortls_states.h
 +libor_event_a_SOURCES = compat_libevent.c
 +
++noinst_HEADERS = address.h torlog.h crypto.h util.h compat.h aes.h torint.h tortls.h strlcpy.c strlcat.c torgzip.h container.h ht.h mempool.h memarea.h ciphers.inc compat_libevent.h tortls_states.h di_ops.h
 +
 +common_sha1.i: $(libor_SOURCES) $(libor_crypto_a_SOURCES) $(noinst_HEADERS)
 +      if test "@SHA1SUM@" != none; then \
 +        @SHA1SUM@ $(libor_SOURCES) $(libor_crypto_a_SOURCES) $(noinst_HEADERS) | @SED@ -n 's/^\(.*\)$$/"\1\\n"/p' > common_sha1.i; \
 +      elif test "@OPENSSL@" != none; then \
 +        @OPENSSL@ sha1 $(libor_SOURCES) $(libor_crypto_a_SOURCES) $(noinst_HEADERS) | @SED@ -n 's/SHA1(\(.*\))= \(.*\)/"\2  \1\\n"/p' > common_sha1.i; \
 +      else \
 +        rm common_sha1.i; \
 +        touch common_sha1.i; \
 +      fi
  
 -noinst_HEADERS = address.h log.h crypto.h test.h util.h compat.h aes.h torint.h tortls.h strlcpy.c strlcat.c torgzip.h container.h ht.h mempool.h memarea.h di_ops.h ciphers.inc
 +util_codedigest.o: common_sha1.i
 +crypto.o: sha256.c
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 38c0ad05e60620460ab6ebe1583d491c47e10101,879a0e4bd3b27997a428cd5148257384ee6f8bd2..86f41416747aee6f4ade6ecff557c949dc43c012
@@@ -739,16 -662,12 +741,19 @@@ tor_mem_is_zero(const char *mem, size_
  int
  tor_digest_is_zero(const char *digest)
  {
-   return tor_mem_is_zero(digest, DIGEST_LEN);
+   static const uint8_t ZERO_DIGEST[] = {
+     0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0
+   };
+   return tor_memeq(digest, ZERO_DIGEST, DIGEST_LEN);
  }
  
 +/** Return true iff the DIGEST256_LEN bytes in digest are all zero. */
 +int
 +tor_digest256_is_zero(const char *digest)
 +{
 +  return tor_mem_is_zero(digest, DIGEST256_LEN);
 +}
 +
  /* Helper: common code to check whether the result of a strtol or strtoul or
   * strtoll is correct. */
  #define CHECK_STRTOX_RESULT()                           \
Simple merge
index 2189e0e55715387c04a4af76683d4873c4447c2d,208a9cb11baa9b2f9613cfa127fbbd8b8daf1c50..a9986d309cabc9fd243d48cb1faff2e8628255aa
@@@ -4504,10 -2997,11 +4504,10 @@@ get_configured_bridge_by_addr_port_dige
    SMARTLIST_FOREACH_BEGIN(bridge_list, bridge_info_t *, bridge)
      {
        if (tor_digest_is_zero(bridge->identity) &&
 -          tor_addr_eq_ipv4h(&bridge->addr, ri->addr) &&
 -          bridge->port == ri->or_port)
 +          !tor_addr_compare(&bridge->addr, addr, CMP_EXACT) &&
 +          bridge->port == port)
          return bridge;
-       if (!memcmp(bridge->identity, digest, DIGEST_LEN))
 -      if (tor_memeq(bridge->identity, ri->cache_info.identity_digest,
 -                  DIGEST_LEN))
++      if (tor_memeq(bridge->identity, digest, DIGEST_LEN))
          return bridge;
      }
    SMARTLIST_FOREACH_END(bridge);
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 68734e60426a7fc2cb155c2fe04f1a82c72b4d51,01f33752ff8393b836f471ebc49ed72533b3ca36..309d99745ff4e41b9107138314b98902c028f087
@@@ -2434,9 -2356,9 +2434,9 @@@ client_likes_consensus(networkstatus_t 
        continue;
      };
  
 -    SMARTLIST_FOREACH(v->voters, networkstatus_voter_info_t *, vi, {
 -      if (vi->signature &&
 -          fast_memeq(vi->identity_digest, want_digest, want_len)) {
 +    SMARTLIST_FOREACH_BEGIN(v->voters, networkstatus_voter_info_t *, vi) {
 +      if (smartlist_len(vi->sigs) &&
-           !memcmp(vi->identity_digest, want_digest, want_len)) {
++          tor_memeq(vi->identity_digest, want_digest, want_len)) {
          have++;
          break;
        };
index 860ac1f7001854a53510b0cb5416627653fd5e88,e367cb1c3abda31a4b9d65e8e05db9ce0e6b8410..1f4489a7e0f752d01844180dae8aac0d6d4b0440
@@@ -3152,23 -2841,15 +3152,23 @@@ dirserv_orconn_tls_done(const char *add
    tor_assert(address);
    tor_assert(digest_rcvd);
  
 -  SMARTLIST_FOREACH(rl->routers, routerinfo_t *, ri, {
 +  /* XXX023 Doing a loop like this is stupid.  We should just look up the
 +   * router by digest_rcvd, and see if address, orport, and as_advertised
 +   * match up. -NM */
 +  SMARTLIST_FOREACH_BEGIN(rl->routers, routerinfo_t *, ri) {
      if (!strcasecmp(address, ri->address) && or_port == ri->or_port &&
          as_advertised &&
-         !memcmp(ri->cache_info.identity_digest, digest_rcvd, DIGEST_LEN)) {
+         fast_memeq(ri->cache_info.identity_digest, digest_rcvd, DIGEST_LEN)) {
        /* correct digest. mark this router reachable! */
        if (!bridge_auth || ri->purpose == ROUTER_PURPOSE_BRIDGE) {
 -        log_info(LD_DIRSERV, "Found router %s to be reachable. Yay.",
 -                 ri->nickname);
 -        rep_hist_note_router_reachable(digest_rcvd, now);
 +        tor_addr_t addr, *addrp=NULL;
 +        log_info(LD_DIRSERV, "Found router %s to be reachable at %s:%d. Yay.",
 +                 ri->nickname, address, ri->or_port );
 +        if (tor_addr_from_str(&addr, ri->address) != -1)
 +          addrp = &addr;
 +        else
 +          log_warn(LD_BUG, "Couldn't parse IP address \"%s\"", ri->address);
 +        rep_hist_note_router_reachable(digest_rcvd, addrp, or_port, now);
          ri->last_reachable = now;
        }
      }
index 750c649f514bd0f60837032d95c58f8ace257188,9e763bdc91e60e5abb4aade714b954e0d2cc4993..a95cea4b7d28354f2bde72f62e6b443562352314
@@@ -1765,11 -879,9 +1765,11 @@@ networkstatus_compute_consensus(smartli
  
        /* Figure out the most popular opinion of what the most recent
         * routerinfo and its contents are. */
 -      rs = compute_routerstatus_consensus(matching_descs);
 +      memset(microdesc_digest, 0, sizeof(microdesc_digest));
 +      rs = compute_routerstatus_consensus(matching_descs, consensus_method,
 +                                          microdesc_digest);
        /* Copy bits of that into rs_out. */
-       tor_assert(!memcmp(lowest_id, rs->status.identity_digest, DIGEST_LEN));
+       tor_assert(fast_memeq(lowest_id, rs->status.identity_digest, DIGEST_LEN));
        memcpy(rs_out.identity_digest, lowest_id, DIGEST_LEN);
        memcpy(rs_out.descriptor_digest, rs->status.descriptor_digest,
               DIGEST_LEN);
@@@ -2970,19 -1797,15 +2970,19 @@@ dirvote_add_vote(const char *vote_body
      goto err;
    }
  
 +  /* Fetch any new router descriptors we just learned about */
 +  update_consensus_router_descriptor_downloads(time(NULL), 1, vote);
 +
    /* Now see whether we already have a vote from this authority. */
    SMARTLIST_FOREACH(pending_vote_list, pending_vote_t *, v, {
-       if (! memcmp(v->vote->cert->cache_info.identity_digest,
+       if (fast_memeq(v->vote->cert->cache_info.identity_digest,
                     vote->cert->cache_info.identity_digest,
                     DIGEST_LEN)) {
          networkstatus_voter_info_t *vi_old = get_voter(v->vote);
-         if (!memcmp(vi_old->vote_digest, vi->vote_digest, DIGEST_LEN)) {
+         if (fast_memeq(vi_old->vote_digest, vi->vote_digest, DIGEST_LEN)) {
            /* Ah, it's the same vote. Not a problem. */
 -          log_info(LD_DIR, "Discarding a vote we already have.");
 +          log_info(LD_DIR, "Discarding a vote we already have (from %s).",
 +                   vi->address);
            if (*status_out < 200)
              *status_out = 200;
            goto discard;
@@@ -3491,12 -2229,12 +3491,12 @@@ dirvote_get_vote(const char *fp, int fl
    } else {
      if (pending_vote_list && include_pending) {
        SMARTLIST_FOREACH(pending_vote_list, pending_vote_t *, pv,
-         if (!memcmp(pv->vote->digests.d[DIGEST_SHA1], fp, DIGEST_LEN))
 -        if (fast_memeq(pv->vote->networkstatus_digest, fp, DIGEST_LEN))
++        if (fast_memeq(pv->vote->digests.d[DIGEST_SHA1], fp, DIGEST_LEN))
            return pv->vote_body);
      }
      if (previous_vote_list && include_previous) {
        SMARTLIST_FOREACH(previous_vote_list, pending_vote_t *, pv,
-         if (!memcmp(pv->vote->digests.d[DIGEST_SHA1], fp, DIGEST_LEN))
 -        if (fast_memeq(pv->vote->networkstatus_digest, fp, DIGEST_LEN))
++        if (fast_memeq(pv->vote->digests.d[DIGEST_SHA1], fp, DIGEST_LEN))
            return pv->vote_body);
      }
    }
Simple merge
index a50d3ca070cfdda4648830c50e18e8ff6035140a,dcd8159aff44af003f281afece942d36b1119396..ff20566cd62f72d42efb6c905b5f89aed2891e3d
@@@ -414,39 -341,35 +414,39 @@@ networkstatus_get_voter_by_id(networkst
    return NULL;
  }
  
 -/** Check whether the signature on <b>voter</b> is correctly signed by
 - * the signing key of <b>cert</b>. Return -1 if <b>cert</b> doesn't match the
 +/** Check whether the signature <b>sig</b> is correctly signed with the
 + * signing key in <b>cert</b>.  Return -1 if <b>cert</b> doesn't match the
   * signing key; otherwise set the good_signature or bad_signature flag on
   * <b>voter</b>, and return 0. */
 -/* (private; exposed for testing.) */
  int
 -networkstatus_check_voter_signature(networkstatus_t *consensus,
 -                                    networkstatus_voter_info_t *voter,
 -                                    authority_cert_t *cert)
 +networkstatus_check_document_signature(const networkstatus_t *consensus,
 +                                       document_signature_t *sig,
 +                                       const authority_cert_t *cert)
  {
 -  char d[DIGEST_LEN];
 +  char key_digest[DIGEST_LEN];
 +  const int dlen = sig->alg == DIGEST_SHA1 ? DIGEST_LEN : DIGEST256_LEN;
    char *signed_digest;
    size_t signed_digest_len;
 -  if (crypto_pk_get_digest(cert->signing_key, d)<0)
 +
 +  if (crypto_pk_get_digest(cert->signing_key, key_digest)<0)
      return -1;
-   if (memcmp(sig->signing_key_digest, key_digest, DIGEST_LEN) ||
-       memcmp(sig->identity_digest, cert->cache_info.identity_digest,
-              DIGEST_LEN))
 -  if (tor_memneq(voter->signing_key_digest, d, DIGEST_LEN))
++  if (tor_memneq(sig->signing_key_digest, key_digest, DIGEST_LEN) ||
++      tor_memneq(sig->identity_digest, cert->cache_info.identity_digest,
++                 DIGEST_LEN))
      return -1;
 +
    signed_digest_len = crypto_pk_keysize(cert->signing_key);
    signed_digest = tor_malloc(signed_digest_len);
    if (crypto_pk_public_checksig(cert->signing_key,
                                  signed_digest,
                                  signed_digest_len,
 -                                voter->signature,
 -                                voter->signature_len) != DIGEST_LEN ||
 -      tor_memneq(signed_digest, consensus->networkstatus_digest, DIGEST_LEN)) {
 +                                sig->signature,
 +                                sig->signature_len) < dlen ||
-       memcmp(signed_digest, consensus->digests.d[sig->alg], dlen)) {
++      tor_memneq(signed_digest, consensus->digests.d[sig->alg], dlen)) {
      log_warn(LD_DIR, "Got a bad signature on a networkstatus vote");
 -    voter->bad_signature = 1;
 +    sig->bad_signature = 1;
    } else {
 -    voter->good_signature = 1;
 +    sig->good_signature = 1;
    }
    tor_free(signed_digest);
    return 0;
@@@ -1613,31 -1432,11 +1613,31 @@@ networkstatus_set_current_consensus(con
      goto done;
    }
  
 -  if (current_consensus &&
 -      tor_memeq(c->networkstatus_digest, current_consensus->networkstatus_digest,
 -              DIGEST_LEN)) {
 +  if (!strcmp(flavor, "ns")) {
 +    consensus_fname = get_datadir_fname("cached-consensus");
 +    unverified_fname = get_datadir_fname("unverified-consensus");
 +    if (current_consensus) {
 +      current_digests = &current_consensus->digests;
 +      current_valid_after = current_consensus->valid_after;
 +    }
 +  } else {
 +    cached_dir_t *cur;
 +    char buf[128];
 +    tor_snprintf(buf, sizeof(buf), "cached-%s-consensus", flavor);
 +    consensus_fname = get_datadir_fname(buf);
 +    tor_snprintf(buf, sizeof(buf), "unverified-%s-consensus", flavor);
 +    unverified_fname = get_datadir_fname(buf);
 +    cur = dirserv_get_consensus(flavor);
 +    if (cur) {
 +      current_digests = &cur->digests;
 +      current_valid_after = cur->published;
 +    }
 +  }
 +
 +  if (current_digests &&
-       !memcmp(&c->digests, current_digests, sizeof(c->digests))) {
++      tor_memeq(&c->digests, current_digests, sizeof(c->digests))) {
      /* We already have this one. That's a failure. */
 -    log_info(LD_DIR, "Got a consensus we already have");
 +    log_info(LD_DIR, "Got a %s consensus we already have", flavor);
      goto done;
    }
  
diff --cc src/or/onion.c
Simple merge
diff --cc src/or/relay.c
Simple merge
index e4a6d09f8faf503eea6df5293015d919b813b5ec,7bda70562b70d9e7058e3f9fb373da283d86558d..77e11c2a07925d987931cf37768df563c09108e2
@@@ -154,27 -98,42 +154,27 @@@ rend_client_send_introduction(origin_ci
    }
  
    /* first 20 bytes of payload are the hash of Bob's pk */
 -  if (entry->parsed->version == 0) { /* un-versioned descriptor */
 -    intro_key = entry->parsed->pk;
 -  } else { /* versioned descriptor */
 -    intro_key = NULL;
 -    SMARTLIST_FOREACH(entry->parsed->intro_nodes, rend_intro_point_t *,
 -                      intro, {
 -      if (tor_memeq(introcirc->build_state->chosen_exit->identity_digest,
 -                  intro->extend_info->identity_digest, DIGEST_LEN)) {
 -        intro_key = intro->intro_key;
 -        break;
 -      }
 -    });
 -    if (!intro_key) {
 -      /** XXX This case probably means that the intro point vanished while
 -       * we were building a circuit to it. In the future, we should find
 -       * out how that happened and whether we should kill the circuits to
 -       * removed intro points immediately. See task 1073. */
 -      int num_intro_points = smartlist_len(entry->parsed->intro_nodes);
 -      if (rend_cache_lookup_entry(introcirc->rend_data->onion_address,
 -          0, &entry) > 0) {
 -        log_info(LD_REND, "We have both a v0 and a v2 rend desc for this "
 -                 "service. The v2 desc doesn't contain the introduction "
 -                 "point (and key) to send an INTRODUCE1/2 cell to this "
 -                 "introduction point. Assuming the introduction point "
 -                 "is for v0 rend clients and using the service key "
 -                 "from the v0 desc instead. (This is probably a bug, "
 -                 "because we shouldn't even have both a v0 and a v2 "
 -                 "descriptor for the same service.)");
 -        /* See flyspray task 1024. */
 -        intro_key = entry->parsed->pk;
 -      } else {
 -        log_info(LD_REND, "Internal error: could not find intro key; we "
 -                 "only have a v2 rend desc with %d intro points.",
 -                 num_intro_points);
 -        goto perm_err;
 -      }
 +  intro_key = NULL;
 +  SMARTLIST_FOREACH(entry->parsed->intro_nodes, rend_intro_point_t *,
 +                    intro, {
-     if (!memcmp(introcirc->build_state->chosen_exit->identity_digest,
++    if (tor_memeq(introcirc->build_state->chosen_exit->identity_digest,
 +                intro->extend_info->identity_digest, DIGEST_LEN)) {
 +      intro_key = intro->intro_key;
 +      break;
 +    }
 +  });
 +  if (!intro_key) {
 +    log_info(LD_REND, "Could not find intro key for %s at %s; we "
 +             "have a v2 rend desc with %d intro points. "
 +             "Trying a different intro point...",
 +             safe_str_client(introcirc->rend_data->onion_address),
 +             introcirc->build_state->chosen_exit->nickname,
 +             smartlist_len(entry->parsed->intro_nodes));
 +
 +    if (rend_client_reextend_intro_circuit(introcirc)) {
 +      goto perm_err;
 +    } else {
 +      return -1;
      }
    }
    if (crypto_pk_get_digest(intro_key, payload)<0) {
index f8e7f9bbb0ea22637de89117dbf5f07289e7066a,c83573b208cd609003105d2f97bff5e7c40001cc..da33feccbc4f003beb8a260c5126c3fe0edd4fb1
@@@ -1067,9 -1101,9 +1067,9 @@@ rend_cache_store(const char *desc, size
      rend_service_descriptor_free(parsed);
      return 0;
    }
-   if (e && e->len == desc_len && !memcmp(desc,e->desc,desc_len)) {
+   if (e && e->len == desc_len && tor_memeq(desc,e->desc,desc_len)) {
      log_info(LD_REND,"We already have this service descriptor %s.",
 -             safe_str(query));
 +             safe_str_client(query));
      e->received = time(NULL);
      rend_service_descriptor_free(parsed);
      return 0;
Simple merge
index cd8f9eabeb411c1097d689267bf6e93df69cb55a,d1cc7f4f11ebc72be4dd67faa8d20e395d02690d..35e8b9057adf494f5a395e7669f6de37b6fb46e6
@@@ -465,8 -506,9 +465,8 @@@ rend_config_services(or_options_t *opti
          int keep_it = 0;
          tor_assert(oc->rend_data);
          SMARTLIST_FOREACH(surviving_services, rend_service_t *, ptr, {
-           if (!memcmp(ptr->pk_digest, oc->rend_data->rend_pk_digest,
+           if (tor_memeq(ptr->pk_digest, oc->rend_data->rend_pk_digest,
 -                      DIGEST_LEN) &&
 -              ptr->descriptor_version == oc->rend_data->rend_desc_version) {
 +                      DIGEST_LEN)) {
              keep_it = 1;
              break;
            }
@@@ -753,15 -797,17 +753,15 @@@ rend_service_load_keys(void
    return r;
  }
  
 -/** Return the service whose public key has a digest of <b>digest</b> and
 - * which publishes the given descriptor <b>version</b>.  Return NULL if no
 - * such service exists.
 +/** Return the service whose public key has a digest of <b>digest</b>, or
 + * NULL if no such service exists.
   */
  static rend_service_t *
 -rend_service_get_by_pk_digest_and_version(const char* digest,
 -                                          uint8_t version)
 +rend_service_get_by_pk_digest(const char* digest)
  {
    SMARTLIST_FOREACH(rend_service_list, rend_service_t*, s,
-                     if (!memcmp(s->pk_digest,digest,DIGEST_LEN))
 -                    if (tor_memeq(s->pk_digest,digest,DIGEST_LEN) &&
 -                        s->descriptor_version == version) return s);
++                    if (tor_memeq(s->pk_digest,digest,DIGEST_LEN))
 +                        return s);
    return NULL;
  }
  
@@@ -1555,9 -1593,10 +1555,9 @@@ find_intro_circuit(rend_intro_point_t *
    tor_assert(intro);
    while ((circ = circuit_get_next_by_pk_and_purpose(circ,pk_digest,
                                                    CIRCUIT_PURPOSE_S_INTRO))) {
-     if (!memcmp(circ->build_state->chosen_exit->identity_digest,
+     if (tor_memeq(circ->build_state->chosen_exit->identity_digest,
                  intro->extend_info->identity_digest, DIGEST_LEN) &&
 -        circ->rend_data &&
 -        circ->rend_data->rend_desc_version == desc_version) {
 +        circ->rend_data) {
        return circ;
      }
    }
    circ = NULL;
    while ((circ = circuit_get_next_by_pk_and_purpose(circ,pk_digest,
                                          CIRCUIT_PURPOSE_S_ESTABLISH_INTRO))) {
-     if (!memcmp(circ->build_state->chosen_exit->identity_digest,
+     if (tor_memeq(circ->build_state->chosen_exit->identity_digest,
                  intro->extend_info->identity_digest, DIGEST_LEN) &&
 -        circ->rend_data &&
 -        circ->rend_data->rend_desc_version == desc_version) {
 +        circ->rend_data) {
        return circ;
      }
    }
Simple merge
diff --cc src/or/router.c
index 65afd49f7f8d1537d11cf89c5e56641b5eb25d92,cc600415f08d5878bd1fa32c73695e7616bc81cf..a7148ea1f7110941bf9fea2046d285566897a0f9
@@@ -1260,8 -1119,7 +1260,8 @@@ router_my_exit_policy_is_reject_star(vo
  int
  router_digest_is_me(const char *digest)
  {
 -  return identitykey && tor_memeq(identitykey_digest, digest, DIGEST_LEN);
 +  return (server_identitykey &&
-           !memcmp(server_identitykey_digest, digest, DIGEST_LEN));
++          tor_memeq(server_identitykey_digest, digest, DIGEST_LEN));
  }
  
  /** Return true iff I'm a server and <b>digest</b> is equal to
index f567ccdf3cc335d978ecf457115ac7c1759a0b58,9f046209865734102608dcba50e637ea18731223..b0909eb730560016b91d8063b47c345fbbe2ff5b
@@@ -3328,15 -2999,16 +3328,15 @@@ router_add_to_routerlist(routerinfo_t *
    SMARTLIST_FOREACH(networkstatus_v2_list, networkstatus_v2_t *, ns,
    {
      routerstatus_t *rs =
 -      networkstatus_v2_find_entry(ns, router->cache_info.identity_digest);
 +      networkstatus_v2_find_entry(ns, id_digest);
-     if (rs && !memcmp(rs->descriptor_digest,
+     if (rs && tor_memeq(rs->descriptor_digest,
                        router->cache_info.signed_descriptor_digest,
                        DIGEST_LEN))
        rs->need_to_mirror = 0;
    });
    if (consensus) {
 -    routerstatus_t *rs = networkstatus_vote_find_entry(consensus,
 -                                        router->cache_info.identity_digest);
 +    routerstatus_t *rs = networkstatus_vote_find_entry(consensus, id_digest);
-     if (rs && !memcmp(rs->descriptor_digest,
+     if (rs && tor_memeq(rs->descriptor_digest,
                        router->cache_info.signed_descriptor_digest,
                        DIGEST_LEN)) {
        in_consensus = 1;
index d0138e638bc2f56ad7512f2aeaa9fa4b75495182,7ff0e2c3ce91443a816f0b0144a5f82dec1e35a1..3b669ad45997044dce8220851238a0fb7730d61c
@@@ -1095,7 -959,7 +1095,7 @@@ check_signature_token(const char *diges
    }
  //  log_debug(LD_DIR,"Signed %s hash starts %s", doctype,
  //            hex_str(signed_digest,4));
-   if (memcmp(digest, signed_digest, digest_len)) {
 -  if (tor_memneq(digest, signed_digest, DIGEST_LEN)) {
++  if (tor_memneq(digest, signed_digest, digest_len)) {
      log_warn(LD_DIR, "Error reading %s: signature does not match.", doctype);
      tor_free(signed_digest);
      return -1;
@@@ -2190,11 -2001,11 +2190,11 @@@ routerstatus_parse_entry_from_string(me
  }
  
  /** Helper to sort a smartlist of pointers to routerstatus_t */
 -static int
 -_compare_routerstatus_entries(const void **_a, const void **_b)
 +int
 +compare_routerstatus_entries(const void **_a, const void **_b)
  {
    const routerstatus_t *a = *_a, *b = *_b;
-   return memcmp(a->identity_digest, b->identity_digest, DIGEST_LEN);
+   return fast_memcmp(a->identity_digest, b->identity_digest, DIGEST_LEN);
  }
  
  /** Helper: used in call to _smartlist_uniq to clear out duplicate entries. */