[tor-commits] [tor/master] helper to test a node for matching an ed25519 ID.

nickm at torproject.org nickm at torproject.org
Thu Dec 8 21:53:43 UTC 2016


commit 424ae9e18bc902e6c96a0e49b609f40868174af8
Author: Nick Mathewson <nickm at torproject.org>
Date:   Fri Nov 11 12:37:58 2016 -0500

    helper to test a node for matching an ed25519 ID.
---
 src/or/nodelist.c | 12 ++++++++++++
 src/or/nodelist.h |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/src/or/nodelist.c b/src/or/nodelist.c
index 1f993e4..d8d2dbb 100644
--- a/src/or/nodelist.c
+++ b/src/or/nodelist.c
@@ -671,6 +671,18 @@ node_get_ed25519_id(const node_t *node)
   return NULL;
 }
 
+/** Return true iff this node's Ed25519 identity matches <b>id</b>.
+ * (An absent Ed25519 identity matches NULL or zero.) */
+int
+node_ed25519_id_matches(const node_t *node, const ed25519_public_key_t *id)
+{
+  const ed25519_public_key_t *node_id = node_get_ed25519_id(node);
+  if (node_id == NULL || ed25519_public_key_is_zero(node_id)) {
+    return id == NULL || ed25519_public_key_is_zero(id);
+  } else {
+    return id && ed25519_pubkey_eq(node_id, id);
+  }
+}
 
 /** Return true iff <b>node</b> supports authenticating itself
  * by ed25519 ID during the link handshake in a way that we can understand
diff --git a/src/or/nodelist.h b/src/or/nodelist.h
index 57c3b43..31fdc64 100644
--- a/src/or/nodelist.h
+++ b/src/or/nodelist.h
@@ -56,6 +56,8 @@ long node_get_declared_uptime(const node_t *node);
 time_t node_get_published_on(const node_t *node);
 const smartlist_t *node_get_declared_family(const node_t *node);
 const ed25519_public_key_t *node_get_ed25519_id(const node_t *node);
+int node_ed25519_id_matches(const node_t *node,
+                            const ed25519_public_key_t *id);
 int node_supports_ed25519_link_authentication(const node_t *node);
 const uint8_t *node_get_rsa_id_digest(const node_t *node);
 





More information about the tor-commits mailing list