gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r36028 - in gnunet/src: include util
Date: Tue, 30 Jun 2015 11:44:00 +0200

Author: grothoff
Date: 2015-06-30 11:43:59 +0200 (Tue, 30 Jun 2015)
New Revision: 36028

Modified:
   gnunet/src/include/gnunet_crypto_lib.h
   gnunet/src/util/crypto_rsa.c
   gnunet/src/util/test_crypto_rsa.c
Log:
patch from Nicolas Fournier to add some _dup and _cmp functions for RSA 
signatures and private keys

Modified: gnunet/src/include/gnunet_crypto_lib.h
===================================================================
--- gnunet/src/include/gnunet_crypto_lib.h      2015-06-30 09:43:08 UTC (rev 
36027)
+++ gnunet/src/include/gnunet_crypto_lib.h      2015-06-30 09:43:59 UTC (rev 
36028)
@@ -1603,6 +1603,16 @@
 
 
 /**
+ * Duplicate the given private key
+ *
+ * @param key the private key to duplicate
+ * @return the duplicate key; NULL upon error
+ */
+struct GNUNET_CRYPTO_rsa_PrivateKey *
+GNUNET_CRYPTO_rsa_private_key_dup (const struct GNUNET_CRYPTO_rsa_PrivateKey 
*key);
+
+
+/**
  * Extract the public key of the given private key.
  *
  * @param priv the private key
@@ -1701,7 +1711,18 @@
 GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_rsa_Signature *s1,
                                 struct GNUNET_CRYPTO_rsa_Signature *s2);
 
+/**
+ * Compare the values of two private keys.
+ *
+ * @param p1 one private key
+ * @param p2 the other private key
+ * @return 0 if the two are equal
+ */
+int
+GNUNET_CRYPTO_rsa_private_key_cmp (struct GNUNET_CRYPTO_rsa_PrivateKey *p1,
+                                 struct GNUNET_CRYPTO_rsa_PrivateKey *p2);
 
+
 /**
  * Compare the values of two public keys.
  *
@@ -1814,6 +1835,16 @@
 
 
 /**
+ * Duplicate the given rsa signature
+ *
+ * @param sig the signature to duplicate
+ * @return the duplicate key; NULL upon error
+ */
+struct GNUNET_CRYPTO_rsa_Signature *
+GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_rsa_Signature 
*sig);
+
+
+/**
  * 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/crypto_rsa.c
===================================================================
--- gnunet/src/util/crypto_rsa.c        2015-06-30 09:43:08 UTC (rev 36027)
+++ gnunet/src/util/crypto_rsa.c        2015-06-30 09:43:59 UTC (rev 36028)
@@ -494,6 +494,39 @@
 
 
 /**
+ * Compare the values of two private keys.
+ *
+ * @param p1 one private key
+ * @param p2 the other private key
+ * @return 0 if the two are equal
+ */
+int
+GNUNET_CRYPTO_rsa_private_key_cmp (struct GNUNET_CRYPTO_rsa_PrivateKey *p1,
+                                 struct GNUNET_CRYPTO_rsa_PrivateKey *p2)
+{
+  char *b1;
+  char *b2;
+  size_t z1;
+  size_t z2;
+  int ret;
+
+  z1 = GNUNET_CRYPTO_rsa_private_key_encode (p1,
+                                           &b1);
+  z2 = GNUNET_CRYPTO_rsa_private_key_encode (p2,
+                                           &b2);
+  if (z1 != z2)
+    ret = 1;
+  else
+    ret = memcmp (b1,
+                 b2,
+                 z1);
+  GNUNET_free (b1);
+  GNUNET_free (b2);
+  return ret;
+}
+
+
+/**
  * Destroy a blinding key
  *
  * @param bkey the blinding key to destroy
@@ -929,4 +962,57 @@
 }
 
 
+/**
+ * Duplicate the given private key
+ *
+ * @param key the private key to duplicate
+ * @return the duplicate key; NULL upon error
+ */
+struct GNUNET_CRYPTO_rsa_PrivateKey *
+GNUNET_CRYPTO_rsa_private_key_dup (const struct GNUNET_CRYPTO_rsa_PrivateKey 
*key)
+{
+  struct GNUNET_CRYPTO_rsa_PrivateKey *dup;
+  gcry_sexp_t dup_sexp;
+  size_t erroff;
+
+  /* check if we really are exporting a private key */
+  dup_sexp = gcry_sexp_find_token (key->sexp, "private-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_PrivateKey);
+  dup->sexp = dup_sexp;
+  return dup;
+}
+
+
+/**
+ * Duplicate the given private key
+ *
+ * @param key the private key to duplicate
+ * @return the duplicate key; NULL upon error
+ */
+struct GNUNET_CRYPTO_rsa_Signature *
+GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_rsa_Signature *sig)
+{
+  struct GNUNET_CRYPTO_rsa_Signature *dup;
+  gcry_sexp_t dup_sexp;
+  size_t erroff;
+  gcry_mpi_t s;
+  int ret;
+
+  /* verify that this is an RSA signature */
+  ret = key_from_sexp (&s, sig->sexp, "sig-val", "s");
+  GNUNET_assert (0 == ret);
+  ret = key_from_sexp (&s, sig->sexp, "rsa", "s");
+  GNUNET_assert (0==ret);
+  /* copy the sexp */
+  GNUNET_assert (0 == gcry_sexp_build (&dup_sexp, &erroff, "%S", sig->sexp));
+  dup = GNUNET_new (struct GNUNET_CRYPTO_rsa_Signature);
+  dup->sexp = dup_sexp;
+  return dup;
+}
+
+
 /* end of util/rsa.c */

Modified: gnunet/src/util/test_crypto_rsa.c
===================================================================
--- gnunet/src/util/test_crypto_rsa.c   2015-06-30 09:43:08 UTC (rev 36027)
+++ gnunet/src/util/test_crypto_rsa.c   2015-06-30 09:43:59 UTC (rev 36028)
@@ -32,10 +32,12 @@
 #define RND_BLK_SIZE 4096
   unsigned char rnd_blk[RND_BLK_SIZE];
   struct GNUNET_CRYPTO_rsa_PrivateKey *priv;
+  struct GNUNET_CRYPTO_rsa_PrivateKey *priv_copy;
   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 *sig_copy;
   struct GNUNET_CRYPTO_rsa_Signature *bsig;
   struct GNUNET_HashCode hash;
   char *blind_buf;
@@ -49,6 +51,9 @@
                       RND_BLK_SIZE,
                       &hash);
   priv = GNUNET_CRYPTO_rsa_private_key_create (KEY_SIZE);
+  priv_copy = GNUNET_CRYPTO_rsa_private_key_dup (priv);
+  GNUNET_assert (NULL != priv_copy);
+  GNUNET_assert (0 == GNUNET_CRYPTO_rsa_private_key_cmp (priv, priv_copy));
   pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv);
   /* Encoding */
   size_t size;
@@ -70,6 +75,9 @@
   sig = GNUNET_CRYPTO_rsa_sign (priv,
                         &hash,
                         sizeof (hash));
+  sig_copy = GNUNET_CRYPTO_rsa_signature_dup (sig);
+  GNUNET_assert (NULL != sig);
+  GNUNET_assert (0 == GNUNET_CRYPTO_rsa_signature_cmp (sig, sig_copy));
   pub_copy = GNUNET_CRYPTO_rsa_public_key_dup (pub);
   GNUNET_assert (NULL != pub_copy);
   GNUNET_assert (GNUNET_OK ==
@@ -102,7 +110,9 @@
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_CRYPTO_rsa_verify (&hash, sig, pub));
   GNUNET_CRYPTO_rsa_signature_free (sig);
+  GNUNET_CRYPTO_rsa_signature_free (sig_copy);
   GNUNET_CRYPTO_rsa_private_key_free (priv);
+  GNUNET_CRYPTO_rsa_private_key_free (priv_copy);
   GNUNET_CRYPTO_rsa_public_key_free (pub);
   GNUNET_CRYPTO_rsa_public_key_free (pub_copy);
   GNUNET_CRYPTO_rsa_blinding_key_free (bkey);




reply via email to

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