gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r31984 - in gnunet/src: include util
Date: Tue, 21 Jan 2014 12:37:50 +0100

Author: cfuchs
Date: 2014-01-21 12:37:50 +0100 (Tue, 21 Jan 2014)
New Revision: 31984

Modified:
   gnunet/src/include/gnunet_crypto_lib.h
   gnunet/src/util/crypto_paillier.c
Log:
- added logics for homomorphic operation in paillier
- adjusted headers

Modified: gnunet/src/include/gnunet_crypto_lib.h
===================================================================
--- gnunet/src/include/gnunet_crypto_lib.h      2014-01-21 10:54:47 UTC (rev 
31983)
+++ gnunet/src/include/gnunet_crypto_lib.h      2014-01-21 11:37:50 UTC (rev 
31984)
@@ -1372,16 +1372,18 @@
  * Note that this operation can only be done a finite number of times
  * before an overflow occurs.
  *
- * @param x1 Paillier cipher text.
- * @param x2 Paillier cipher text.
+ * @param public_key Public key to use for encryption.
+ * @param c1 Paillier cipher text.
+ * @param c2 Paillier cipher text.
  * @param[out] result Result of the homomorphic operation.
  * @return #GNUNET_OK if the result could be computed,
  *         #GNUNET_SYSERR if no more homomorphic operations are remaining.
  */
 int
-GNUNET_CRYPTO_paillier_hom_add (const struct GNUNET_CRYPTO_PaillierCiphertext 
*x1,
-                                const struct GNUNET_CRYPTO_PaillierCiphertext 
*x2,
-                                const struct GNUNET_CRYPTO_PaillierCiphertext 
*result);
+GNUNET_CRYPTO_paillier_hom_add (const struct GNUNET_CRYPTO_PaillierPublicKey 
*public_key,
+                                const struct GNUNET_CRYPTO_PaillierCiphertext 
*c1,
+                                const struct GNUNET_CRYPTO_PaillierCiphertext 
*c2,
+                                struct GNUNET_CRYPTO_PaillierCiphertext 
*result);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */

Modified: gnunet/src/util/crypto_paillier.c
===================================================================
--- gnunet/src/util/crypto_paillier.c   2014-01-21 10:54:47 UTC (rev 31983)
+++ gnunet/src/util/crypto_paillier.c   2014-01-21 11:37:50 UTC (rev 31984)
@@ -139,7 +139,7 @@
   gcry_mpi_mulm (c, r, c, n_square);
 
   GNUNET_CRYPTO_mpi_print_unsigned (ciphertext->bits, 
-                                    sizeof(*ciphertext) - 
sizeof(ciphertext->remaining_ops), 
+                                    sizeof ciphertext->bits, 
                                     c);
 
   gcry_mpi_release (n_square);
@@ -154,7 +154,7 @@
  * Decrypt a paillier ciphertext with a private key.
  *
  * @param private_key Private key to use for decryption.
- * @param public_key Public key to use for decryption.
+ * @param public_key Public key to use for encryption.
  * @param ciphertext Ciphertext to decrypt.
  * @param[out] m Decryption of @a ciphertext with @private_key.
  */
@@ -172,7 +172,6 @@
 
   GNUNET_assert (0 != (n_square = gcry_mpi_new (0)));
 
-
   GNUNET_CRYPTO_mpi_scan_unsigned (&lambda, private_key->lambda, sizeof 
private_key->lambda);
   GNUNET_CRYPTO_mpi_scan_unsigned (&mu, private_key->mu, sizeof 
private_key->mu);
   GNUNET_CRYPTO_mpi_scan_unsigned (&n, public_key, sizeof *public_key);
@@ -201,20 +200,44 @@
  * Note that this operation can only be done a finite number of times
  * before an overflow occurs.
  *
- * @param x1 Paillier cipher text.
- * @param x2 Paillier cipher text.
+ * @param public_key Public key to use for encryption.
+ * @param c1 Paillier cipher text.
+ * @param c2 Paillier cipher text.
  * @param[out] result Result of the homomorphic operation.
  * @return #GNUNET_OK if the result could be computed,
  *         #GNUNET_SYSERR if no more homomorphic operations are remaining.
  */
 int
-GNUNET_CRYPTO_paillier_hom_add (const struct GNUNET_CRYPTO_PaillierCiphertext 
*x1,
-                                const struct GNUNET_CRYPTO_PaillierCiphertext 
*x2,
-                                const struct GNUNET_CRYPTO_PaillierCiphertext 
*result)
+GNUNET_CRYPTO_paillier_hom_add (const struct GNUNET_CRYPTO_PaillierPublicKey 
*public_key,
+                                const struct GNUNET_CRYPTO_PaillierCiphertext 
*c1,
+                                const struct GNUNET_CRYPTO_PaillierCiphertext 
*c2,
+                                struct GNUNET_CRYPTO_PaillierCiphertext 
*result)
 {
-  // not implemented yet
-  GNUNET_assert (0);
-  return GNUNET_SYSERR;
+  gcry_mpi_t a;
+  gcry_mpi_t b;
+  gcry_mpi_t c;
+  gcry_mpi_t n_square;
+  
+  if (0 == c1->remaining_ops || 0 == c2->remaining_ops)
+    return GNUNET_SYSERR;
+  
+  GNUNET_assert (0 != (c = gcry_mpi_new (0)));
+  
+  GNUNET_CRYPTO_mpi_scan_unsigned (&a, c1->bits, sizeof c1->bits);
+  GNUNET_CRYPTO_mpi_scan_unsigned (&b, c1->bits, sizeof c2->bits);
+  GNUNET_CRYPTO_mpi_scan_unsigned (&n_square, public_key, sizeof *public_key);
+  gcry_mpi_mul(n_square, n_square,n_square);
+  gcry_mpi_mulm(c,a,b,n_square);
+  
+  result->remaining_ops = (c1->remaining_ops > c2->remaining_ops) ? 
c2->remaining_ops : c1->remaining_ops;
+  GNUNET_CRYPTO_mpi_print_unsigned (result->bits, 
+                                    sizeof result->bits, 
+                                    c);
+  gcry_mpi_release (a);
+  gcry_mpi_release (b);
+  gcry_mpi_release (c);
+  gcry_mpi_release (n_square);
+  return GNUNET_OK;
 }
 
 




reply via email to

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