aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorKarsten Loesing <karsten.loesing@gmx.net>2014-02-26 10:44:55 +0100
committerNick Mathewson <nickm@torproject.org>2014-02-28 08:53:13 -0500
commit3ca5fe81e33ab7848c848b683bffe12e743398f3 (patch)
treefe83b2027c4595bc64677f64f4b2fa54f5d0f3ff /src/common
parentbf1678603ffa66ed47c038faf309984839a98363 (diff)
downloadtor-3ca5fe81e33ab7848c848b683bffe12e743398f3.tar
tor-3ca5fe81e33ab7848c848b683bffe12e743398f3.tar.gz
Write hashed bridge fingerprint to logs and to disk.
Implements #10884.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/crypto.c22
-rw-r--r--src/common/crypto.h1
2 files changed, 23 insertions, 0 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 49dc55a3e..80d835131 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -1374,6 +1374,28 @@ crypto_pk_get_fingerprint(crypto_pk_t *pk, char *fp_out, int add_space)
return 0;
}
+/** Given a private or public key <b>pk</b>, put a hashed fingerprint of
+ * the public key into <b>fp_out</b> (must have at least FINGERPRINT_LEN+1
+ * bytes of space). Return 0 on success, -1 on failure.
+ *
+ * Hashed fingerprints are computed as the SHA1 digest of the SHA1 digest
+ * of the ASN.1 encoding of the public key, converted to hexadecimal, in
+ * upper case.
+ */
+int
+crypto_pk_get_hashed_fingerprint(crypto_pk_t *pk, char *fp_out)
+{
+ char digest[DIGEST_LEN], hashed_digest[DIGEST_LEN];
+ if (crypto_pk_get_digest(pk, digest)) {
+ return -1;
+ }
+ if (crypto_digest(hashed_digest, digest, DIGEST_LEN)) {
+ return -1;
+ }
+ base16_encode(fp_out, FINGERPRINT_LEN + 1, hashed_digest, DIGEST_LEN);
+ return 0;
+}
+
/* symmetric crypto */
/** Return a pointer to the key set for the cipher in <b>env</b>.
diff --git a/src/common/crypto.h b/src/common/crypto.h
index 3666d5f9a..4f0f1c10c 100644
--- a/src/common/crypto.h
+++ b/src/common/crypto.h
@@ -182,6 +182,7 @@ crypto_pk_t *crypto_pk_asn1_decode(const char *str, size_t len);
int crypto_pk_get_digest(crypto_pk_t *pk, char *digest_out);
int crypto_pk_get_all_digests(crypto_pk_t *pk, 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);
/* symmetric crypto */
const char *crypto_cipher_get_key(crypto_cipher_t *env);