aboutsummaryrefslogtreecommitdiff
path: root/src/common/crypto.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-04-18 11:13:36 -0400
committerNick Mathewson <nickm@torproject.org>2013-04-18 11:13:36 -0400
commit8362f8854aa3e36b766724226a3baec4d325c1c0 (patch)
treed309eb1c3b9502b4323405f1a312f04dd868077c /src/common/crypto.c
parentcd1cdae0fac33bca359b34dae4062fe87a351661 (diff)
parent4b15606fa2848f5112599865eb7b15ef2178e66a (diff)
downloadtor-8362f8854aa3e36b766724226a3baec4d325c1c0.tar
tor-8362f8854aa3e36b766724226a3baec4d325c1c0.tar.gz
Merge branch 'less_charbuf_rebased' into maint-0.2.4
Conflicts: src/or/dirserv.c src/or/dirserv.h src/test/test_dir.c
Diffstat (limited to 'src/common/crypto.c')
-rw-r--r--src/common/crypto.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 949fd52eb..93a60d8c6 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -1614,6 +1614,30 @@ crypto_digest_assign(crypto_digest_t *into,
memcpy(into,from,sizeof(crypto_digest_t));
}
+
+/** Given a list of strings in <b>lst</b>, set the <b>len_out</b>-byte digest
+ * at <b>digest_out</b> to the hash of the concatenation of those strings,
+ * plus the optional string <b>append</b>, computed with the algorithm
+ * <b>alg</b>.
+ * <b>out_len</b> must be \<= DIGEST256_LEN. */
+void
+crypto_digest_smartlist(char *digest_out, size_t len_out,
+ const smartlist_t *lst, const char *append,
+ digest_algorithm_t alg)
+{
+ crypto_digest_t *d;
+ if (alg == DIGEST_SHA1)
+ d = crypto_digest_new();
+ else
+ d = crypto_digest256_new(alg);
+ SMARTLIST_FOREACH(lst, const char *, cp,
+ crypto_digest_add_bytes(d, cp, strlen(cp)));
+ if (append)
+ crypto_digest_add_bytes(d, append, strlen(append));
+ crypto_digest_get_digest(d, digest_out, len_out);
+ crypto_digest_free(d);
+}
+
/** Compute the HMAC-SHA-1 of the <b>msg_len</b> bytes in <b>msg</b>, using
* the <b>key</b> of length <b>key_len</b>. Store the DIGEST_LEN-byte result
* in <b>hmac_out</b>.