commit 0070016a317fecd96bd3dde6ff5670c9a8b81d00
parent 6a69a20d6847a6a359e3b8eb289bf351fed0651a
Author: Christian Grothoff <christian@grothoff.org>
Date: Mon, 9 Mar 2015 11:59:33 +0000
add GNUNET_CRYPTO_rsa_public_key_hash
Diffstat:
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
@@ -1539,6 +1539,17 @@ GNUNET_CRYPTO_rsa_private_key_get_public (const struct GNUNET_CRYPTO_rsa_Private
/**
+ * 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.
*
* @param key pointer to the memory to free
diff --git 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;
@@ -320,6 +320,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;