You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@milagro.apache.org by sa...@apache.org on 2019/12/06 15:07:41 UTC

[incubator-milagro-crypto-c] 02/10: rework paillier so ff_8192 is not needed

This is an automated email from the ASF dual-hosted git repository.

sandreoli pushed a commit to branch issue51
in repository https://gitbox.apache.org/repos/asf/incubator-milagro-crypto-c.git

commit 02699cc05380ded365a70b34fdc7932a040cdc8f
Author: samuele-andreoli <sa...@yahoo.it>
AuthorDate: Tue Nov 26 16:49:41 2019 +0000

    rework paillier so ff_8192 is not needed
---
 CMakeLists.txt                    |  2 +-
 benchmark/benchtest_paillier.c.in |  3 --
 cmake/AMCLParameters.cmake        |  1 -
 config.mk                         |  2 +-
 examples/example_paillier.c       |  3 --
 include/ff.h.in                   |  2 +-
 include/paillier.h                | 17 ----------
 src/paillier.c                    | 65 +++++++++++++--------------------------
 test/test_paillier_add.c          |  3 --
 test/test_paillier_consistency.c  |  3 --
 test/test_paillier_decrypt.c      |  3 --
 test/test_paillier_encrypt.c      |  3 --
 test/test_paillier_keygen.c       |  3 --
 test/test_paillier_mult.c         |  3 --
 14 files changed, 25 insertions(+), 88 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ace56aa..436c36e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -301,7 +301,7 @@ endif()
 ##################################################
 
 if(BUILD_PAILLIER)
-  foreach(level 2048 4096 8192)
+  foreach(level 2048 4096)
     amcl_rsa_field(BD "${level}")
     amcl_rsa_field(TFF "${level}")
 
diff --git a/benchmark/benchtest_paillier.c.in b/benchmark/benchtest_paillier.c.in
index 2cfb594..2e5a2ec 100644
--- a/benchmark/benchtest_paillier.c.in
+++ b/benchmark/benchtest_paillier.c.in
@@ -25,9 +25,6 @@ under the License.
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-#include "ff_8192.h"
-#include "ff_4096.h"
-#include "ff_2048.h"
 #include "randapi.h"
 #include "paillier.h"
 #include "amcl.h"
diff --git a/cmake/AMCLParameters.cmake b/cmake/AMCLParameters.cmake
index c4333f4..b9f8a93 100644
--- a/cmake/AMCLParameters.cmake
+++ b/cmake/AMCLParameters.cmake
@@ -101,7 +101,6 @@ set(AMCL_RSA_FIELDS          TB   TFF  NB  BASE ML)
 set(AMCL_RSA_64_2048         1024 2048 128 58   2 )
 set(AMCL_RSA_64_3072         384  3072 48  56   8 )
 set(AMCL_RSA_64_4096         512  4096 64  60   8 )
-set(AMCL_RSA_64_8192         512  8192 64  60   16)
 #  (                         TB   TFF  NB  BASE ML)
 set(AMCL_RSA_32_2048         1024 2048 128 28   2 )
 set(AMCL_RSA_32_3072         384  3072 48  28   8 )
diff --git a/config.mk b/config.mk
index 4a12ba5..bdbc4cd 100644
--- a/config.mk
+++ b/config.mk
@@ -7,7 +7,7 @@ WORD_SIZE:=64
 AMCL_CURVE:=ED25519,NIST256,GOLDILOCKS,BLS381
 
 # RSA security level: 2048 3072 4096 (8192 for Paillier)
-AMCL_RSA:=2048,4096,8192
+AMCL_RSA:=2048,4096
 
 # Build type Debug Release Coverage ASan Check CheckFull
 CMAKE_BUILD_TYPE:=Release
diff --git a/examples/example_paillier.c b/examples/example_paillier.c
index 884929f..b293724 100644
--- a/examples/example_paillier.c
+++ b/examples/example_paillier.c
@@ -28,9 +28,6 @@ under the License.
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-#include "ff_8192.h"
-#include "ff_4096.h"
-#include "ff_2048.h"
 #include "randapi.h"
 #include "paillier.h"
 
diff --git a/include/ff.h.in b/include/ff.h.in
index cb468b2..a3fc4c8 100644
--- a/include/ff.h.in
+++ b/include/ff.h.in
@@ -294,7 +294,7 @@ extern int FF_WWW_prime(BIG_XXX *x,csprng *R,int n);
 extern void FF_WWW_pow2(BIG_XXX *r,BIG_XXX *x,BIG_XXX e,BIG_XXX *y,BIG_XXX f,BIG_XXX *m,int n);
 /**	@brief Calculate r=x^e.y^f mod m for big e and f
  *
-	@param r FF instance, on exit = x^e.y^f mod p
+	@param r FF instance, on exit = x^e.y^f mod m
 	@param x FF instance
 	@param e FF exponent
 	@param y FF instance
diff --git a/include/paillier.h b/include/paillier.h
index 4f9fee8..8072370 100644
--- a/include/paillier.h
+++ b/include/paillier.h
@@ -27,34 +27,17 @@ under the License.
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-#include "ff_8192.h"
 #include "ff_4096.h"
 #include "ff_2048.h"
 
-#define HASH_TYPE SHA256  /**< Hash function used */
-
 // Field size
-#define FS_8192 MODBYTES_512_60*FFLEN_8192    /**< 8192 field size in bytes */
 #define FS_4096 MODBYTES_512_60*FFLEN_4096    /**< 4096 field size in bytes */
 #define FS_2048 MODBYTES_1024_58*FFLEN_2048   /**< 2048 field size in bytes */
 
 // Half field size
-#define HFS_8192 MODBYTES_512_60*HFLEN_8192   /**< Half 8192 field size in bytes */
 #define HFS_4096 MODBYTES_512_60*HFLEN_4096   /**< Half 4096 field size in bytes */
 #define HFS_2048 MODBYTES_1024_58*HFLEN_2048  /**< Half 2048 field size in bytes */
 
-/*! \brief quotient of y divided by x
- *
- *  <ol>
- *  <li> \f$ z = y / x \f$
- *  </ol>
- *
- *  @param  x       Demominator
- *  @param  y       Numerator
- *  @param  z       Quotient of y divided by x
- *  @return         Returns 0 or else error code
- */
-int FF_4096_divide(BIG_512_60 x[], BIG_512_60 y[], BIG_512_60 z[]);
 
 /*! \brief Generate the key pair
  *
diff --git a/src/paillier.c b/src/paillier.c
index d19776a..f2040c4 100644
--- a/src/paillier.c
+++ b/src/paillier.c
@@ -23,7 +23,6 @@ under the License.
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-#include "ff_8192.h"
 #include "ff_4096.h"
 #include "ff_2048.h"
 #include "paillier.h"
@@ -256,24 +255,9 @@ int PAILLIER_ENCRYPT(csprng *RNG, octet* N, octet* G, octet* PT, octet* CT, octe
     printf("pt ");
     FF_4096_output(pt,FFLEN_4096);
     printf("\n\n");
-    printf("gpt ");
-    FF_4096_output(gpt,FFLEN_4096);
-    printf("\n\n");
-    printf("rn ");
-    FF_4096_output(rn,FFLEN_4096);
-    printf("\n\n");
-    printf("gpt8 ");
-    FF_8192_output(gpt8,FFLEN_8192);
-    printf("\n\n");
-    printf("rn8 ");
-    FF_8192_output(rn8,FFLEN_8192);
-    printf("\n\n");
     printf("ct ");
-    FF_8192_output(ct,FFLEN_8192);
+    FF_4096_output(ct,FFLEN_4096);
     printf("\n\n");
-    printf("CT2: ");
-    OCT_output(&CT2);
-    printf("\n");
     printf("CT: ");
     OCT_output(CT);
     printf("\n");
@@ -384,60 +368,56 @@ int PAILLIER_DECRYPT(octet* N, octet* L, octet* M, octet* CT, octet* PT)
 int PAILLIER_ADD(octet* N, octet* CT1, octet* CT2, octet* CT)
 {
     // Public key
-    BIG_512_60 n[FFLEN_8192];
+    BIG_512_60 n[HFLEN_4096];
 
     // n2 = n^2
-    BIG_512_60 n2[FFLEN_8192];
+    BIG_512_60 n2[FFLEN_4096];
 
     // ciphertext
-    BIG_512_60 ct1[FFLEN_8192];
-    BIG_512_60 ct2[FFLEN_8192];
-    BIG_512_60 ct[FFLEN_8192];
-
-    FF_8192_zero(n,FFLEN_8192);
-    FF_8192_fromOctet(n,N,FFLEN_8192/4);
-
-    FF_8192_zero(ct1,FFLEN_8192);
-    FF_8192_fromOctet(ct1,CT1,HFLEN_8192);
+    BIG_512_60 ct1[FFLEN_4096];
+    BIG_512_60 ct2[FFLEN_4096];
+    BIG_512_60 ct[2 * FFLEN_4096];
 
-    FF_8192_zero(ct2,FFLEN_8192);
-    FF_8192_fromOctet(ct2,CT2,HFLEN_8192);
+    FF_4096_fromOctet(n,N,HFLEN_4096);
+    FF_4096_fromOctet(ct1,CT1,FFLEN_4096);
+    FF_4096_fromOctet(ct2,CT2,FFLEN_4096);
 
     // n2 = n^2
-    FF_8192_sqr(n2, n, HFLEN_8192);
+    FF_4096_sqr(n2, n, HFLEN_4096);
+    FF_4096_norm(n2, FFLEN_4096);
 
 #ifdef DEBUG
     printf("PAILLIER_ADD ct1 ");
-    FF_8192_output(ct1,FFLEN_8192);
+    FF_4096_output(ct1,FFLEN_4096);
     printf("\n\n");
     printf("PAILLIER_ADD ct2 ");
-    FF_8192_output(ct2,FFLEN_8192);
+    FF_4096_output(ct2,FFLEN_4096);
     printf("\n\n");
 #endif
 
     // ct = ct1 * ct2 mod n^2
-    FF_8192_mul(ct,ct1,ct2,HFLEN_8192);
+    FF_4096_mul(ct,ct1,ct2,FFLEN_4096);
 
 #ifdef DEBUG
     printf("PAILLIER_ADD ct1 * ct2 ");
-    FF_8192_output(ct,FFLEN_8192);
+    FF_4096_output(ct,2 * FFLEN_4096);
     printf("\n\n");
 #endif
 
-    FF_8192_mod(ct,n2,FFLEN_8192);
+    FF_4096_dmod(ct,ct,n2,FFLEN_4096);
 
     // Output
-    FF_8192_toOctet(CT, ct, HFLEN_8192);
+    FF_4096_toOctet(CT, ct, FFLEN_4096);
 
 #ifdef DEBUG
     printf("PAILLIER_ADD n ");
-    FF_8192_output(n,FFLEN_8192);
+    FF_4096_output(n,HFLEN_4096);
     printf("\n\n");
     printf("PAILLIER_ADD ct1 ");
-    FF_8192_output(ct1,FFLEN_8192);
+    FF_4096_output(ct1,FFLEN_4096);
     printf("\n\n");
     printf("PAILLIER_ADD ct2 ");
-    FF_8192_output(ct2,FFLEN_8192);
+    FF_4096_output(ct2,FFLEN_4096);
     printf("\n\n");
 #endif
 
@@ -452,7 +432,7 @@ int PAILLIER_ADD(octet* N, octet* CT1, octet* CT2, octet* CT)
 int PAILLIER_MULT(octet* N, octet* CT1, octet* PT, octet* CT)
 {
     // Public key
-    BIG_512_60 n[FFLEN_4096];
+    BIG_512_60 n[HFLEN_4096];
 
     // n^2
     BIG_512_60 n2[FFLEN_4096];
@@ -467,7 +447,6 @@ int PAILLIER_MULT(octet* N, octet* CT1, octet* PT, octet* CT)
     BIG_512_60 ct[FFLEN_4096];
 
     // Convert n from FF_2048 to FF_4096
-    FF_4096_zero(n, FFLEN_4096);
     FF_4096_fromOctet(n,N,HFLEN_4096);
 
     FF_4096_zero(pt, FFLEN_4096);
@@ -487,7 +466,7 @@ int PAILLIER_MULT(octet* N, octet* CT1, octet* PT, octet* CT)
 
 #ifdef DEBUG
     printf("PAILLIER_MULT n: ");
-    FF_4096_output(n,FFLEN_4096);
+    FF_4096_output(n,HFLEN_4096);
     printf("\n\n");
     printf("PAILLIER_MULT n2: ");
     FF_4096_output(n2,FFLEN_4096);
diff --git a/test/test_paillier_add.c b/test/test_paillier_add.c
index 63f2674..7408547 100644
--- a/test/test_paillier_add.c
+++ b/test/test_paillier_add.c
@@ -22,9 +22,6 @@
 #include <string.h>
 #include <time.h>
 #include "amcl.h"
-#include "ff_8192.h"
-#include "ff_4096.h"
-#include "ff_2048.h"
 #include "paillier.h"
 
 #define LINE_LEN 2000
diff --git a/test/test_paillier_consistency.c b/test/test_paillier_consistency.c
index 01ffa43..b21a1cb 100644
--- a/test/test_paillier_consistency.c
+++ b/test/test_paillier_consistency.c
@@ -26,9 +26,6 @@ under the License.
 #include <string.h>
 #include <time.h>
 #include "randapi.h"
-#include "ff_8192.h"
-#include "ff_4096.h"
-#include "ff_2048.h"
 #include "paillier.h"
 
 #define NTHREADS 2
diff --git a/test/test_paillier_decrypt.c b/test/test_paillier_decrypt.c
index 3d4c490..6f12989 100644
--- a/test/test_paillier_decrypt.c
+++ b/test/test_paillier_decrypt.c
@@ -22,9 +22,6 @@
 #include <string.h>
 #include <time.h>
 #include "amcl.h"
-#include "ff_8192.h"
-#include "ff_4096.h"
-#include "ff_2048.h"
 #include "paillier.h"
 
 #define LINE_LEN 2000
diff --git a/test/test_paillier_encrypt.c b/test/test_paillier_encrypt.c
index 3d4586d..62bb7e1 100644
--- a/test/test_paillier_encrypt.c
+++ b/test/test_paillier_encrypt.c
@@ -22,9 +22,6 @@
 #include <string.h>
 #include <time.h>
 #include "amcl.h"
-#include "ff_8192.h"
-#include "ff_4096.h"
-#include "ff_2048.h"
 #include "paillier.h"
 
 #define LINE_LEN 2000
diff --git a/test/test_paillier_keygen.c b/test/test_paillier_keygen.c
index 334cd10..74c8673 100644
--- a/test/test_paillier_keygen.c
+++ b/test/test_paillier_keygen.c
@@ -22,9 +22,6 @@
 #include <string.h>
 #include <time.h>
 #include "amcl.h"
-#include "ff_8192.h"
-#include "ff_4096.h"
-#include "ff_2048.h"
 #include "randapi.h"
 #include "paillier.h"
 
diff --git a/test/test_paillier_mult.c b/test/test_paillier_mult.c
index 4f832d3..b8b7aae 100644
--- a/test/test_paillier_mult.c
+++ b/test/test_paillier_mult.c
@@ -22,9 +22,6 @@
 #include <string.h>
 #include <time.h>
 #include "amcl.h"
-#include "ff_8192.h"
-#include "ff_4096.h"
-#include "ff_2048.h"
 #include "paillier.h"
 
 #define LINE_LEN 2000