diff options
author | Nick Mathewson <nickm@torproject.org> | 2011-09-13 14:32:51 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-10-10 23:14:02 -0400 |
commit | dcf69a9e12d013563575e50b7d6f547832f92f66 (patch) | |
tree | bec4a9f8a4cb793661af12cd481d4e2acb930c34 /src/common/crypto.c | |
parent | bc2d9357f523d87385229087cb13253874f070f0 (diff) | |
download | tor-dcf69a9e12d013563575e50b7d6f547832f92f66.tar.gz tor-dcf69a9e12d013563575e50b7d6f547832f92f66.zip |
New function to get all digests of a public key
Diffstat (limited to 'src/common/crypto.c')
-rw-r--r-- | src/common/crypto.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 9ad7575a7e..edb0d42ac2 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -1249,6 +1249,32 @@ crypto_pk_get_digest(crypto_pk_env_t *pk, char *digest_out) return 0; } +/** 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_env_t *pk, digests_t *digests_out) +{ + unsigned char *buf, *bufp; + int len; + + len = i2d_RSAPublicKey(pk->key, NULL); + if (len < 0) + return -1; + buf = bufp = tor_malloc(len+1); + len = i2d_RSAPublicKey(pk->key, &bufp); + if (len < 0) { + crypto_log_errors(LOG_WARN,"encoding public key"); + tor_free(buf); + return -1; + } + if (crypto_digest_all(digests_out, (char*)buf, len) < 0) { + tor_free(buf); + return -1; + } + tor_free(buf); + return 0; +} + /** Copy <b>in</b> to the <b>outlen</b>-byte buffer <b>out</b>, adding spaces * every four spaces. */ /* static */ void |