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

[tor-commits] [tor/master] sr: add the base16 RSA identity digest to commit



commit 267e16ea616b3466652bfee81fec507ea45d96a6
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Mon Jul 4 12:05:48 2016 -0400

    sr: add the base16 RSA identity digest to commit
    
    Keep the base16 representation of the RSA identity digest in the commit object
    so we can use it without using hex_str() or dynamically encoding it everytime
    we need it. It's used extensively in the logs for instance.
    
    Fixes #19561
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 src/or/shared_random.c        |  2 ++
 src/or/shared_random.h        |  7 ++++---
 src/test/test_shared_random.c | 12 ++++++++++++
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/or/shared_random.c b/src/or/shared_random.c
index e9e6cbc..612e1c6 100644
--- a/src/or/shared_random.c
+++ b/src/or/shared_random.c
@@ -140,6 +140,8 @@ commit_new(const char *rsa_identity)
   commit = tor_malloc_zero(sizeof(*commit));
   commit->alg = SR_DIGEST_ALG;
   memcpy(commit->rsa_identity, rsa_identity, sizeof(commit->rsa_identity));
+  base16_encode(commit->rsa_identity_hex, sizeof(commit->rsa_identity_hex),
+                commit->rsa_identity, sizeof(commit->rsa_identity));
   return commit;
 }
 
diff --git a/src/or/shared_random.h b/src/or/shared_random.h
index 51f3b55..7c0a3e7 100644
--- a/src/or/shared_random.h
+++ b/src/or/shared_random.h
@@ -76,8 +76,10 @@ typedef struct sr_commit_t {
 
   /* Commit owner info */
 
-  /* The RSA identity key of the authority. */
+  /* The RSA identity key of the authority and it's base16 representation
+   * which includes the NUL terminated byte. */
   char rsa_identity[DIGEST_LEN];
+  char rsa_identity_hex[HEX_DIGEST_LEN + 1];
 
   /* Commitment information */
 
@@ -121,8 +123,7 @@ void sr_srv_encode(char *dst, size_t dst_len, const sr_srv_t *srv);
 static inline
 const char *sr_commit_get_rsa_fpr(const sr_commit_t *commit)
 {
-  return hex_str((const char *) commit->rsa_identity,
-                 sizeof(commit->rsa_identity));
+  return commit->rsa_identity_hex;
 }
 
 void sr_compute_srv(void);
diff --git a/src/test/test_shared_random.c b/src/test/test_shared_random.c
index d001785..270cd81 100644
--- a/src/test/test_shared_random.c
+++ b/src/test/test_shared_random.c
@@ -702,6 +702,9 @@ test_sr_setup_commits(void)
 
     /* Do some surgery on the commit */
     memset(commit_a->rsa_identity, 'A', sizeof(commit_a->rsa_identity));
+    base16_encode(commit_a->rsa_identity_hex,
+                  sizeof(commit_a->rsa_identity_hex), commit_a->rsa_identity,
+                  sizeof(commit_a->rsa_identity));
     strlcpy(commit_a->encoded_reveal,
             "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
             sizeof(commit_a->encoded_reveal));
@@ -716,6 +719,9 @@ test_sr_setup_commits(void)
 
     /* Do some surgery on the commit */
     memset(commit_b->rsa_identity, 'B', sizeof(commit_b->rsa_identity));
+    base16_encode(commit_b->rsa_identity_hex,
+                  sizeof(commit_b->rsa_identity_hex), commit_b->rsa_identity,
+                  sizeof(commit_b->rsa_identity));
     strlcpy(commit_b->encoded_reveal,
             "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
           sizeof(commit_b->encoded_reveal));
@@ -730,6 +736,9 @@ test_sr_setup_commits(void)
 
     /* Do some surgery on the commit */
     memset(commit_c->rsa_identity, 'C', sizeof(commit_c->rsa_identity));
+    base16_encode(commit_c->rsa_identity_hex,
+                  sizeof(commit_c->rsa_identity_hex), commit_c->rsa_identity,
+                  sizeof(commit_c->rsa_identity));
     strlcpy(commit_c->encoded_reveal,
             "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
             sizeof(commit_c->encoded_reveal));
@@ -744,6 +753,9 @@ test_sr_setup_commits(void)
 
     /* Do some surgery on the commit */
     memset(commit_d->rsa_identity, 'D', sizeof(commit_d->rsa_identity));
+    base16_encode(commit_d->rsa_identity_hex,
+                  sizeof(commit_d->rsa_identity_hex), commit_d->rsa_identity,
+                  sizeof(commit_d->rsa_identity));
     strlcpy(commit_d->encoded_reveal,
             "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD",
             sizeof(commit_d->encoded_reveal));



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