gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r32029 - in gnunet/src: include util
Date: Sun, 26 Jan 2014 14:51:21 +0100

Author: cfuchs
Date: 2014-01-26 14:51:21 +0100 (Sun, 26 Jan 2014)
New Revision: 32029

Modified:
   gnunet/src/include/gnunet_crypto_lib.h
   gnunet/src/util/crypto_paillier.c
Log:
- more work on crypto-paillier

Modified: gnunet/src/include/gnunet_crypto_lib.h
===================================================================
--- gnunet/src/include/gnunet_crypto_lib.h      2014-01-25 13:51:27 UTC (rev 
32028)
+++ gnunet/src/include/gnunet_crypto_lib.h      2014-01-26 13:51:21 UTC (rev 
32029)
@@ -385,7 +385,7 @@
   /**
    * guaranteed minimum number of homomorphic operations with this ciphertext
    */
-  uint32_t remaining_ops GNUNET_PACKED;
+  int32_t remaining_ops GNUNET_PACKED;
   
   /**
    * The bits of the ciphertext.
@@ -1386,6 +1386,15 @@
                                 struct GNUNET_CRYPTO_PaillierCiphertext 
*result);
 
 
+/**
+ * Get the number of remaining supported homomorphic operations. 
+ *
+ * @param c Paillier cipher text.
+ * @return the number of remaining homomorphic operations
+ */
+int
+GNUNET_CRYPTO_paillier_hom_get_remaining (const struct 
GNUNET_CRYPTO_PaillierCiphertext *c);
+
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
 #endif

Modified: gnunet/src/util/crypto_paillier.c
===================================================================
--- gnunet/src/util/crypto_paillier.c   2014-01-25 13:51:27 UTC (rev 32028)
+++ gnunet/src/util/crypto_paillier.c   2014-01-26 13:51:21 UTC (rev 32029)
@@ -99,7 +99,7 @@
                                 const gcry_mpi_t m,
                                 struct GNUNET_CRYPTO_PaillierCiphertext 
*ciphertext)
 {
-  unsigned int length;
+  int length;
   gcry_mpi_t n_square;
   gcry_mpi_t r;
   gcry_mpi_t g;
@@ -109,10 +109,11 @@
   // determine how many operations we could allow, if the other number
   // has the same length. 
   length = gcry_mpi_get_nbits(m);
-  if (length >= GNUNET_CRYPTO_PAILLIER_BITS)
+  if (GNUNET_CRYPTO_PAILLIER_BITS <= length) 
+    //paillier with 0 ops makes no sense, better use RSA and co.
     return -1;
   else
-    ciphertext->remaining_ops = 
ntohl(pow(2,(GNUNET_CRYPTO_PAILLIER_BITS-length-1)));
+    ciphertext->remaining_ops = htonl(GNUNET_CRYPTO_PAILLIER_BITS - length);
   
   GNUNET_assert (0 != (n_square = gcry_mpi_new (0)));
   GNUNET_assert (0 != (r = gcry_mpi_new (0)));
@@ -146,7 +147,7 @@
   gcry_mpi_release (r);
   gcry_mpi_release (c);
   
-  return pow(2,(GNUNET_CRYPTO_PAILLIER_BITS-length-1));
+  return GNUNET_CRYPTO_PAILLIER_BITS-length;
 }
 
 
@@ -229,7 +230,7 @@
   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;
+  result->remaining_ops = ((c1->remaining_ops > c2->remaining_ops) ? 
c2->remaining_ops : c1->remaining_ops) - 1;
   GNUNET_CRYPTO_mpi_print_unsigned (result->bits, 
                                     sizeof result->bits, 
                                     c);
@@ -241,4 +242,17 @@
 }
 
 
+/**
+ * Get the number of remaining supported homomorphic operations. 
+ *
+ * @param c Paillier cipher text.
+ * @return the number of remaining homomorphic operations
+ */
+int
+GNUNET_CRYPTO_paillier_hom_get_remaining (const struct 
GNUNET_CRYPTO_PaillierCiphertext *c)
+{
+  GNUNET_assert(NULL != c);
+  return ntohl(c->remaining_ops);
+}
+
 /* end of crypto_paillier.c */




reply via email to

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