diff options
author | Karsten Loesing <karsten.loesing@gmx.net> | 2014-02-26 10:44:55 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-02-28 08:53:13 -0500 |
commit | 3ca5fe81e33ab7848c848b683bffe12e743398f3 (patch) | |
tree | fe83b2027c4595bc64677f64f4b2fa54f5d0f3ff /src/common | |
parent | bf1678603ffa66ed47c038faf309984839a98363 (diff) | |
download | tor-3ca5fe81e33ab7848c848b683bffe12e743398f3.tar.gz tor-3ca5fe81e33ab7848c848b683bffe12e743398f3.zip |
Write hashed bridge fingerprint to logs and to disk.
Implements #10884.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/crypto.c | 22 | ||||
-rw-r--r-- | src/common/crypto.h | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 49dc55a3e3..80d835131b 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 3666d5f9a3..4f0f1c10c3 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); |