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

[tor-commits] [tor/master] Another automated rename.



commit 9746aed2baffeb3788552f8cdedc5611ab2f91b7
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Wed Feb 10 15:31:43 2016 -0500

    Another automated rename.
    
    Also simplify crypto_common_digests() to have no loop.
---
 src/common/crypto.c    | 23 ++++-------------------
 src/common/crypto.h    |  2 +-
 src/common/tortls.c    |  2 +-
 src/test/test_crypto.c |  2 +-
 4 files changed, 7 insertions(+), 22 deletions(-)

diff --git a/src/common/crypto.c b/src/common/crypto.c
index 2ebf203..6c40c6e 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -1323,7 +1323,7 @@ crypto_pk_get_digest(const crypto_pk_t *pk, char *digest_out)
 /** Compute all digests of the DER encoding of <b>pk</b>, and store them
  * in <b>digests_out</b>.  Return 0 on success, -1 on failure. */
 int
-crypto_pk_get_all_digests(crypto_pk_t *pk, common_digests_t *digests_out)
+crypto_pk_get_common_digests(crypto_pk_t *pk, common_digests_t *digests_out)
 {
   unsigned char *buf = NULL;
   int len;
@@ -1650,28 +1650,13 @@ crypto_digest512(char *digest, const char *m, size_t len,
 int
 crypto_common_digests(common_digests_t *ds_out, const char *m, size_t len)
 {
-  int i;
   tor_assert(ds_out);
   memset(ds_out, 0, sizeof(*ds_out));
   if (crypto_digest(ds_out->d[DIGEST_SHA1], m, len) < 0)
     return -1;
-  for (i = DIGEST_SHA256; i < N_COMMON_DIGEST_ALGORITHMS; ++i) {
-      switch (i) {
-        case DIGEST_SHA256: /* FALLSTHROUGH */
-        case DIGEST_SHA3_256:
-          if (crypto_digest256(ds_out->d[i], m, len, i) < 0)
-            return -1;
-          break;
-        case DIGEST_SHA512:
-        case DIGEST_SHA3_512: /* FALLSTHROUGH */
-          tor_assert(0); /* These won't fit. */
-          if (crypto_digest512(ds_out->d[i], m, len, i) < 0)
-            return -1;
-          break;
-        default:
-          return -1;
-      }
-  }
+  if (crypto_digest256(ds_out->d[DIGEST_SHA256], m, len, DIGEST_SHA256) < 0)
+    return -1;
+
   return 0;
 }
 
diff --git a/src/common/crypto.h b/src/common/crypto.h
index 2aa49d3..f1e4981 100644
--- a/src/common/crypto.h
+++ b/src/common/crypto.h
@@ -193,7 +193,7 @@ int crypto_pk_private_hybrid_decrypt(crypto_pk_t *env, char *to,
 int crypto_pk_asn1_encode(crypto_pk_t *pk, char *dest, size_t dest_len);
 crypto_pk_t *crypto_pk_asn1_decode(const char *str, size_t len);
 int crypto_pk_get_digest(const crypto_pk_t *pk, char *digest_out);
-int crypto_pk_get_all_digests(crypto_pk_t *pk, common_digests_t *digests_out);
+int crypto_pk_get_common_digests(crypto_pk_t *pk, common_digests_t *digests_out);
 int crypto_pk_get_fingerprint(crypto_pk_t *pk, char *fp_out,int add_space);
 int crypto_pk_get_hashed_fingerprint(crypto_pk_t *pk, char *fp_out);
 
diff --git a/src/common/tortls.c b/src/common/tortls.c
index 688a755..3077943 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -691,7 +691,7 @@ MOCK_IMPL(STATIC tor_x509_cert_t *,
   if ((pkey = X509_get_pubkey(x509_cert)) &&
       (rsa = EVP_PKEY_get1_RSA(pkey))) {
     crypto_pk_t *pk = crypto_new_pk_from_rsa_(rsa);
-    crypto_pk_get_all_digests(pk, &cert->pkey_digests);
+    crypto_pk_get_common_digests(pk, &cert->pkey_digests);
     cert->pkey_digests_set = 1;
     crypto_pk_free(pk);
     EVP_PKEY_free(pkey);
diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c
index 5ac20b9..14f1ecc 100644
--- a/src/test/test_crypto.c
+++ b/src/test/test_crypto.c
@@ -1098,7 +1098,7 @@ test_crypto_digests(void *arg)
   tt_mem_op(hex_str(digest, DIGEST_LEN),OP_EQ,
              AUTHORITY_SIGNKEY_A_DIGEST, HEX_DIGEST_LEN);
 
-  r = crypto_pk_get_all_digests(k, &pkey_digests);
+  r = crypto_pk_get_common_digests(k, &pkey_digests);
 
   tt_mem_op(hex_str(pkey_digests.d[DIGEST_SHA1], DIGEST_LEN),OP_EQ,
              AUTHORITY_SIGNKEY_A_DIGEST, HEX_DIGEST_LEN);



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