add GNUNET_CRYPTO_rsa_public_key_hash
authorChristian Grothoff <christian@grothoff.org>
Mon, 9 Mar 2015 11:59:33 +0000 (11:59 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 9 Mar 2015 11:59:33 +0000 (11:59 +0000)
src/include/gnunet_crypto_lib.h
src/util/crypto_rsa.c

index e87297e62d0907afce24dbc0c2c792b09a3c7c22..334dab156ea8c97f5ec47cf18c107d4f9c1a31f8 100644 (file)
@@ -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.
  *
index d7bcd1175c424d0e7e2cd77ff71a7051008ea920..66082fc9db869b24d48eb21542fdb6622f4e059f 100644 (file)
@@ -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;