[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Expose crypto_digest_algorithm_get_length from crypto.c
commit b53a2059c4495946d1bb27f8be1f6fadb7af69f1
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Mon May 23 10:58:27 2016 -0400
Expose crypto_digest_algorithm_get_length from crypto.c
Also, use it in routerparse.c
---
src/common/crypto.c | 2 +-
src/common/crypto.h | 1 +
src/or/routerparse.c | 6 ++----
3 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/src/common/crypto.c b/src/common/crypto.c
index fb5dd06..4ed8bfa 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -1727,7 +1727,7 @@ crypto_digest_algorithm_parse_name(const char *name)
}
/** Given an algorithm, return the digest length in bytes. */
-static inline size_t
+size_t
crypto_digest_algorithm_get_length(digest_algorithm_t alg)
{
switch (alg) {
diff --git a/src/common/crypto.h b/src/common/crypto.h
index 017c849..ff38cca 100644
--- a/src/common/crypto.h
+++ b/src/common/crypto.h
@@ -233,6 +233,7 @@ void crypto_digest_smartlist(char *digest_out, size_t len_out,
const struct smartlist_t *lst, const char *append,
digest_algorithm_t alg);
const char *crypto_digest_algorithm_get_name(digest_algorithm_t alg);
+size_t crypto_digest_algorithm_get_length(digest_algorithm_t alg);
int crypto_digest_algorithm_parse_name(const char *name);
crypto_digest_t *crypto_digest_new(void);
crypto_digest_t *crypto_digest256_new(digest_algorithm_t algorithm);
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index 42b0583..6ab042e 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -3531,10 +3531,8 @@ networkstatus_parse_detached_signatures(const char *s, const char *eos)
continue;
}
- expected_length =
- (alg == DIGEST_SHA1) ? HEX_DIGEST_LEN : HEX_DIGEST256_LEN;
- digest_length =
- (alg == DIGEST_SHA1) ? DIGEST_LEN : DIGEST256_LEN;
+ digest_length = crypto_digest_algorithm_get_length(alg);
+ expected_length = digest_length * 2; /* hex encoding */
if (strlen(hexdigest) != expected_length) {
log_warn(LD_DIR, "Wrong length on consensus-digest in detached "
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits