[tor-commits] [tor/master] Add an ed25519_copy; use it in a couple of places dgoulet suggested.

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


commit 937aef48eeae4b81528de3e04b39047d0f826d9b
Author: Nick Mathewson <nickm at torproject.org>
Date:   Mon Dec 5 12:55:52 2016 -0500

    Add an ed25519_copy; use it in a couple of places dgoulet suggested.
---
 src/common/crypto_ed25519.c | 12 ++++++++++++
 src/common/crypto_ed25519.h |  3 +++
 src/or/circuitbuild.c       |  5 ++---
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/common/crypto_ed25519.c b/src/common/crypto_ed25519.c
index 809ad12..b7c8311 100644
--- a/src/common/crypto_ed25519.c
+++ b/src/common/crypto_ed25519.c
@@ -628,6 +628,18 @@ ed25519_pubkey_eq(const ed25519_public_key_t *key1,
   return tor_memeq(key1->pubkey, key2->pubkey, ED25519_PUBKEY_LEN);
 }
 
+/**
+ * Set <b>dest</b> to contain the same key as <b>src</b>.
+ */
+void
+ed25519_pubkey_copy(ed25519_public_key_t *dest,
+                    const ed25519_public_key_t *src)
+{
+  tor_assert(dest);
+  tor_assert(src);
+  memcpy(dest, src, sizeof(ed25519_public_key_t));
+}
+
 /** Check whether the given Ed25519 implementation seems to be working.
  * If so, return 0; otherwise return -1. */
 static int
diff --git a/src/common/crypto_ed25519.h b/src/common/crypto_ed25519.h
index 5d63d90..929b2b5 100644
--- a/src/common/crypto_ed25519.h
+++ b/src/common/crypto_ed25519.h
@@ -121,6 +121,9 @@ void ed25519_keypair_free(ed25519_keypair_t *kp);
 
 int ed25519_pubkey_eq(const ed25519_public_key_t *key1,
                       const ed25519_public_key_t *key2);
+void ed25519_pubkey_copy(ed25519_public_key_t *dest,
+                         const ed25519_public_key_t *src);
+
 
 void ed25519_set_impl_params(int use_donna);
 void ed25519_init(void);
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index bac68bb..96bd472 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -1045,8 +1045,7 @@ circuit_send_next_onion_skin(origin_circuit_t *circ)
     memcpy(ec.node_id, hop->extend_info->identity_digest, DIGEST_LEN);
     /* Set the ED25519 identity too -- it will only get included
      * in the extend2 cell if we're configured to use it, though. */
-    memcpy(&ec.ed_pubkey, &hop->extend_info->ed_identity,
-           sizeof(ed25519_public_key_t));
+    ed25519_pubkey_copy(&ec.ed_pubkey, &hop->extend_info->ed_identity);
 
     len = onion_skin_create(ec.create_cell.handshake_type,
                             hop->extend_info,
@@ -1183,7 +1182,7 @@ circuit_extend(cell_t *cell, circuit_t *circ)
     if (node &&
         node_supports_ed25519_link_authentication(node) &&
         (node_ed_id = node_get_ed25519_id(node))) {
-      memcpy(ec.ed_pubkey.pubkey, node_ed_id->pubkey, ED25519_PUBKEY_LEN);
+      ed25519_pubkey_copy(&ec.ed_pubkey, node_ed_id);
     }
   }
 





More information about the tor-commits mailing list