gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r35837 - in gnunet/src: include util


From: gnunet
Subject: [GNUnet-SVN] r35837 - in gnunet/src: include util
Date: Thu, 28 May 2015 21:32:22 +0200

Author: harsha
Date: 2015-05-28 21:32:22 +0200 (Thu, 28 May 2015)
New Revision: 35837

Modified:
   gnunet/src/include/gnunet_crypto_lib.h
   gnunet/src/util/crypto_rsa.c
   gnunet/src/util/test_crypto_rsa.c
Log:
Introduce function to duplicate RSA public keys

Modified: gnunet/src/include/gnunet_crypto_lib.h
===================================================================
--- gnunet/src/include/gnunet_crypto_lib.h      2015-05-28 14:32:46 UTC (rev 
35836)
+++ gnunet/src/include/gnunet_crypto_lib.h      2015-05-28 19:32:22 UTC (rev 
35837)
@@ -1660,6 +1660,16 @@
 
 
 /**
+ * Duplicate the given public key
+ *
+ * @param key the public key to duplicate
+ * @return the duplicate key; NULL upon error
+ */
+struct GNUNET_CRYPTO_rsa_PublicKey *
+GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_rsa_PublicKey 
*key);
+
+
+/**
  * Create a blinding key
  *
  * @param len length of the key in bits (i.e. 2048)

Modified: gnunet/src/util/crypto_rsa.c
===================================================================
--- gnunet/src/util/crypto_rsa.c        2015-05-28 14:32:46 UTC (rev 35836)
+++ gnunet/src/util/crypto_rsa.c        2015-05-28 19:32:22 UTC (rev 35837)
@@ -801,6 +801,31 @@
 
 
 /**
+ * Duplicate the given public key
+ *
+ * @param key the public key to duplicate
+ * @return the duplicate key; NULL upon error
+ */
+struct GNUNET_CRYPTO_rsa_PublicKey *
+GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_rsa_PublicKey 
*key)
+{
+  struct GNUNET_CRYPTO_rsa_PublicKey *dup;
+  gcry_sexp_t dup_sexp;
+  size_t erroff;
+
+  /* check if we really are exporting a public key */
+  dup_sexp = gcry_sexp_find_token (key->sexp, "public-key", 0);
+  GNUNET_assert (NULL != dup_sexp);
+  gcry_sexp_release (dup_sexp);
+  /* copy the sexp */
+  GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", key->sexp));
+  dup = GNUNET_new (struct GNUNET_CRYPTO_rsa_PublicKey);
+  dup->sexp = dup_sexp;
+  return dup;
+}
+
+
+/**
  * Unblind a blind-signed signature.  The signature should have been generated
  * with #GNUNET_CRYPTO_rsa_sign() using a hash that was blinded with
  * #GNUNET_CRYPTO_rsa_blind().

Modified: gnunet/src/util/test_crypto_rsa.c
===================================================================
--- gnunet/src/util/test_crypto_rsa.c   2015-05-28 14:32:46 UTC (rev 35836)
+++ gnunet/src/util/test_crypto_rsa.c   2015-05-28 19:32:22 UTC (rev 35837)
@@ -33,6 +33,7 @@
   unsigned char rnd_blk[RND_BLK_SIZE];
   struct GNUNET_CRYPTO_rsa_PrivateKey *priv;
   struct GNUNET_CRYPTO_rsa_PublicKey *pub;
+  struct GNUNET_CRYPTO_rsa_PublicKey *pub_copy;
   struct GNUNET_CRYPTO_rsa_BlindingKey *bkey;
   struct GNUNET_CRYPTO_rsa_Signature *sig;
   struct GNUNET_CRYPTO_rsa_Signature *bsig;
@@ -69,8 +70,10 @@
   sig = GNUNET_CRYPTO_rsa_sign (priv,
                         &hash,
                         sizeof (hash));
+  pub_copy = GNUNET_CRYPTO_rsa_public_key_dup (pub);
+  GNUNET_assert (NULL != pub_copy);
   GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CRYPTO_rsa_verify (&hash, sig, pub));
+                 GNUNET_CRYPTO_rsa_verify (&hash, sig, pub_copy));
   /* corrupt our hash and see if the signature is still valid */
   GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &hash,
                               sizeof (struct GNUNET_HashCode));
@@ -101,6 +104,7 @@
   GNUNET_CRYPTO_rsa_signature_free (sig);
   GNUNET_CRYPTO_rsa_private_key_free (priv);
   GNUNET_CRYPTO_rsa_public_key_free (pub);
+  GNUNET_CRYPTO_rsa_public_key_free (pub_copy);
   GNUNET_CRYPTO_rsa_blinding_key_free (bkey);
   return 0;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]