From 0070016a317fecd96bd3dde6ff5670c9a8b81d00 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 9 Mar 2015 11:59:33 +0000 Subject: [PATCH] add GNUNET_CRYPTO_rsa_public_key_hash --- src/include/gnunet_crypto_lib.h | 11 +++++++++++ src/util/crypto_rsa.c | 26 ++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index e87297e62..334dab156 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -1538,6 +1538,17 @@ struct GNUNET_CRYPTO_rsa_PublicKey * GNUNET_CRYPTO_rsa_private_key_get_public (const struct GNUNET_CRYPTO_rsa_PrivateKey *priv); +/** + * Compute hash over the public key. + * + * @param key public key to hash + * @param hc where to store the hash code + */ +void +GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_rsa_PublicKey *key, + struct GNUNET_HashCode *hc); + + /** * Free memory occupied by the public key. * diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index d7bcd1175..66082fc9d 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c @@ -299,7 +299,7 @@ GNUNET_CRYPTO_rsa_public_key_free (struct GNUNET_CRYPTO_rsa_PublicKey *key) */ size_t GNUNET_CRYPTO_rsa_public_key_encode (const struct GNUNET_CRYPTO_rsa_PublicKey *key, - char **buffer) + char **buffer) { size_t n; char *b; @@ -319,6 +319,28 @@ GNUNET_CRYPTO_rsa_public_key_encode (const struct GNUNET_CRYPTO_rsa_PublicKey *k } +/** + * Compute hash over the public key. + * + * @param key public key to hash + * @param hc where to store the hash code + */ +void +GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_rsa_PublicKey *key, + struct GNUNET_HashCode *hc) +{ + char *buf; + size_t buf_size; + + buf_size = GNUNET_CRYPTO_rsa_public_key_encode (key, + &buf); + GNUNET_CRYPTO_hash (buf, + buf_size, + hc); + GNUNET_free (buf); +} + + /** * Decode the public key from the data-format back * to the "normal", internal format. @@ -329,7 +351,7 @@ GNUNET_CRYPTO_rsa_public_key_encode (const struct GNUNET_CRYPTO_rsa_PublicKey *k */ struct GNUNET_CRYPTO_rsa_PublicKey * GNUNET_CRYPTO_rsa_public_key_decode (const char *buf, - size_t len) + size_t len) { struct GNUNET_CRYPTO_rsa_PublicKey *key; gcry_mpi_t n; -- 2.25.1