Browse Source

created branch for dags_64

Gustavo Banegas 2 years ago
parent
commit
dec5d7f012
8 changed files with 49 additions and 35 deletions
  1. 2 0
      .gitignore
  2. 2 1
      src/Makefile
  3. 1 1
      src/decapsulation.c
  4. 3 3
      src/decoding.c
  5. 10 10
      src/gf.c
  6. 17 16
      src/gf.h
  7. 2 2
      src/key_gen.c
  8. 12 2
      src/param.h

+ 2 - 0
.gitignore

@@ -32,3 +32,5 @@
 # Debug files
 *.dSYM/
 
+/Debug/
+/Release/

+ 2 - 1
src/Makefile

@@ -8,8 +8,9 @@ INCS     =
 CXXINCS  = 
 BIN      = PQCgenKAT_kem
 LFLAGS=
-CFLAGS= -c -Wall -I. -O3
+#CFLAGS= -c -Wall -I. 
 RM       = rm -f
+CFLAGS= -c -Wall -I. -O3 -funroll-loops -I/usr/local/include/keccak
 
 .PHONY: all all-before all-after clean clean-custom
 

+ 1 - 1
src/decapsulation.c

@@ -17,7 +17,7 @@ int decapsulation(unsigned char *ss, const unsigned char *ct,
 {
 
     int i, test, decode_value;
-    gf_init(6);                                            // Initialize of Log Antilog table
+    gf_init(5);                                            // Initialize of Log Antilog table
     const unsigned char *custom = (unsigned char *)"DAGs"; // customization = "DAGs";
     unsigned char *mot;
     unsigned char *m1, *rho1;

+ 3 - 3
src/decoding.c

@@ -35,7 +35,7 @@ void polynome_syndrome_1(binmat_t H, const unsigned char *mot, poly_t S)
  */
 binmat_t alternant_matrix(binmat_t H, gf *u)
 {
-    gf_init(6);
+    gf_init(5);
     int i, j, k;
     int st = order * pol_deg;
     poly_t Srivastava;
@@ -125,7 +125,7 @@ binmat_t alternant_matrix(binmat_t H, gf *u)
 int decoding_H(binmat_t H_alt, const unsigned char *c, unsigned char *error,
                unsigned char *code_word)
 {
-    gf_init(6);
+    gf_init(5);
     int i, k, j, dr;
     int *LOG_12;
     int st = order * pol_deg;
@@ -291,7 +291,7 @@ int decoding_from_vy(gf* v,gf* y, const unsigned char *c, unsigned char *error,
                unsigned char *code_word)
 {
     
-    gf_init(6);
+    gf_init(5);
     int i, k, j, dr;
     int *LOG_12;
     int st = order * pol_deg;

+ 10 - 10
src/gf.c

@@ -135,18 +135,18 @@ gf gf_mult(gf x, gf y)
 {
     gf a1, b1, a2, b2, a3, b3, tmp1;
 
-    a1 = x >> 6;
-    b1 = x & 63;
-    a2 = y >> 6;
-    b2 = y & 63;
+    a1 = x >> 5;
+    b1 = x & 31;
+    a2 = y >> 5;
+    b2 = y & 31;
 	
     tmp1 = gf_Mult_subfield(a1, a2);
 
-    a3 = gf_Mult_subfield_ctrly(tmp1, 36) ^ gf_Mult_subfield(a1, b2) ^ gf_Mult_subfield(b1, a2);
+    a3 = gf_Mult_subfield_ctrly(tmp1, gf_antilog_sf[4]) ^ gf_Mult_subfield(a1, b2) ^ gf_Mult_subfield(b1, a2);
 
     b3 = gf_Mult_subfield_ctrly(tmp1, 2) ^ gf_Mult_subfield(b1, b2);
 
-    return (a3 << 6) ^ b3;
+    return (a3 << 5) ^ b3;
 }
 
 // Correct gf_sq
@@ -154,15 +154,15 @@ gf gf_sq(gf x)
 {
     gf a1, b1, a3, b3, tmp1;
 
-    a1 = x >> 6;
-    b1 = x & 63;
+    a1 = x >> 5;
+    b1 = x & 31;
     tmp1 = gf_Mult_subfield(a1, a1); 
 
-    a3 = gf_Mult_subfield_ctrly(tmp1, 36); 
+    a3 = gf_Mult_subfield_ctrly(tmp1, gf_antilog_sf[4]);
 
     b3 = gf_Mult_subfield_ctrly(tmp1, 2) ^ gf_Mult_subfield(b1, b1);
 
-    return (a3 << 6) ^ b3;
+    return (a3 << 5) ^ b3;
 }
 
 // Correct gf_Inv

+ 17 - 16
src/gf.h

@@ -6,28 +6,29 @@
 typedef uint16_t gf;
 typedef uint16_t gf_t;
 
-// Extension degree 12
-#define gf_extd 12
-// Field size 2^12
-#define gf_card (1 << gf_extd)
-// Field Group order 2^12 - 1
-#define gf_ord ((gf_card)-1)
+
+#define gf_extd 10 // extension degree
+#define gf_card (1<<gf_extd) // Field size
+#define gf_ord ((gf_card) - 1) // Group order
+#define m_val 2
+#define gf_extd_sf gf_extd/m_val // subfield extension degree
+#define gf_card_sf (1<<gf_extd_sf) // Field sizeml
+#define gf_ord_sf ((gf_card_sf) - 1) // Group order
+
+
+#define poly_primitif (1<<10)^(gf_antilog_sf[4]<<5)^2
+
+#define primitif_elt_field    gf_antilog_sf[4]
+
+#define poly_primitive_subfield 37
+
 
 // Subfield delaration
 
-// Define subfield degree
 #define m_val 2
-// Subfield degree is 6
-#define gf_extd_sf gf_extd / m_val
-// Subfield size 2^6
-#define gf_card_sf (1 << gf_extd_sf)
-// Subfield Group order 2^6 -1
-#define gf_ord_sf ((gf_card_sf)-1)
 
 // Define Field value
-#define u_val 64
-// Define Poly primitive subfield: X^6 + x + 1
-#define poly_primitive_subfield 67
+#define u_val 32
 
 //int gf_extension_degree, gf_cardinality, gf_multiplicative_order;
 gf_t *gf_log_sf;

+ 2 - 2
src/key_gen.c

@@ -81,7 +81,7 @@ void init_random_element(gf *U)
         U[v + 1] = tmp;
     }
 
-    free(random_bytes);
+//    free(random_bytes);
 }
 
 void Remove_From_U(gf elt, gf *U)
@@ -247,7 +247,7 @@ int key_pair(unsigned char *pk, unsigned char *sk)
     gf *u, *v, *w, *z;
     int return_value = 1;
     binmat_t H, H_syst;//, H_alt;
-    gf_init(6);
+    gf_init(5);
     
     gf* y = (gf *)calloc(code_length, sizeof(gf));
     while(return_value != 0)

+ 12 - 2
src/param.h

@@ -16,7 +16,7 @@
 #define ss_length 64*/
 
 
-
+/*
 // DAG 128
 #define pol_deg 11 //block number 11
 #define code_length 2112
@@ -27,10 +27,11 @@
 #define k_sec 661
 #define n0_w 352
 #define ss_length 64
+*/
 
 
-/*
 // DAG 64
+/*
 #define pol_deg 8 //block number 11
 #define code_length 80
 #define code_dimension 48
@@ -38,6 +39,15 @@
 #define n0_val 40 // number of constant block
 */
 
+#define pol_deg 13 //block number 11
+#define code_length 832
+#define code_dimension 416
+#define order  1<<4  // number of line of each block matrix
+#define n0_val 52 // number of constant block
+#define k_prime 32
+#define k_sec 384
+#define n0_w 104
+#define ss_length 16