gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r31983 - in gnunet/src: include scalarproduct util
Date: Tue, 21 Jan 2014 11:54:48 +0100

Author: cfuchs
Date: 2014-01-21 11:54:47 +0100 (Tue, 21 Jan 2014)
New Revision: 31983

Modified:
   gnunet/src/include/gnunet_crypto_lib.h
   gnunet/src/scalarproduct/scalarproduct.h
   gnunet/src/util/crypto_paillier.c
Log:
- scalarproduct element container was 1 byte too large
- added logics to compute the maximum supported number of paillier hom.ops for 
a ciphertext
- updated comments

Modified: gnunet/src/include/gnunet_crypto_lib.h
===================================================================
--- gnunet/src/include/gnunet_crypto_lib.h      2014-01-21 10:39:54 UTC (rev 
31982)
+++ gnunet/src/include/gnunet_crypto_lib.h      2014-01-21 10:54:47 UTC (rev 
31983)
@@ -1341,10 +1341,11 @@
  * Encrypt a plaintext with a paillier public key.
  *
  * @param public_key Public key to use.
- * @param plaintext Plaintext to encrypt.
+ * @param m Plaintext to encrypt.
  * @param[out] ciphertext Encrytion of @a plaintext with @a public_key.
+ * @return guaranteed number of supported homomorphic operations
  */
-void
+int
 GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey 
*public_key,
                                 const gcry_mpi_t m,
                                 struct GNUNET_CRYPTO_PaillierCiphertext 
*ciphertext);
@@ -1356,7 +1357,7 @@
  * @param private_key Private key to use for decryption.
  * @param public_key Public key to use for decryption.
  * @param ciphertext Ciphertext to decrypt.
- * @param[out] plaintext Decryption of @a ciphertext with @private_key.
+ * @param[out] m Decryption of @a ciphertext with @private_key.
  */
 void
 GNUNET_CRYPTO_paillier_decrypt (const struct GNUNET_CRYPTO_PaillierPrivateKey 
*private_key,

Modified: gnunet/src/scalarproduct/scalarproduct.h
===================================================================
--- gnunet/src/scalarproduct/scalarproduct.h    2014-01-21 10:39:54 UTC (rev 
31982)
+++ gnunet/src/scalarproduct/scalarproduct.h    2014-01-21 10:54:47 UTC (rev 
31983)
@@ -44,9 +44,8 @@
 /**
  * When performing our crypto, we may add two encrypted values with each
  * a maximal length of GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH.
- * thus we can receive a slightly longer element (+1 byte)
  */
-#define PAILLIER_ELEMENT_LENGTH (2*KEYBITS/8 +1)
+#define PAILLIER_ELEMENT_LENGTH (2*KEYBITS/sizeof(char))
 
 /**
  * Maximum count of elements we can put into a multipart message

Modified: gnunet/src/util/crypto_paillier.c
===================================================================
--- gnunet/src/util/crypto_paillier.c   2014-01-21 10:39:54 UTC (rev 31982)
+++ gnunet/src/util/crypto_paillier.c   2014-01-21 10:54:47 UTC (rev 31983)
@@ -92,18 +92,28 @@
  * @param public_key Public key to use.
  * @param m Plaintext to encrypt.
  * @param[out] ciphertext Encrytion of @a plaintext with @a public_key.
+ * @return guaranteed number of supported homomorphic operations >= 1, -1 for 
failure
  */
-void
+int
 GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey 
*public_key,
                                 const gcry_mpi_t m,
                                 struct GNUNET_CRYPTO_PaillierCiphertext 
*ciphertext)
 {
+  unsigned int length;
   gcry_mpi_t n_square;
   gcry_mpi_t r;
   gcry_mpi_t g;
   gcry_mpi_t c;
   gcry_mpi_t n;
-
+  
+  // 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)
+    return -1;
+  else
+    ciphertext->remaining_ops = 
ntohl(pow(2,(GNUNET_CRYPTO_PAILLIER_BITS-length-1)));
+  
   GNUNET_assert (0 != (n_square = gcry_mpi_new (0)));
   GNUNET_assert (0 != (r = gcry_mpi_new (0)));
   GNUNET_assert (0 != (g = gcry_mpi_new (0)));
@@ -135,6 +145,8 @@
   gcry_mpi_release (n_square);
   gcry_mpi_release (r);
   gcry_mpi_release (c);
+  
+  return pow(2,(GNUNET_CRYPTO_PAILLIER_BITS-length-1));
 }
 
 




reply via email to

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