-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparams.h
119 lines (88 loc) · 2.98 KB
/
params.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef LIBE_PARAMS_H
#define LIBE_PARAMS_H
#include <math.h>
#include <complex.h>
#include <NTL/ZZ.h>
#include <NTL/ZZX.h>
#include <NTL/mat_ZZ.h>
using namespace NTL;
using std::complex;
//=====================================================================================
// These are the parameters you need to change
// N0 is the degree of the polynomial ring used. N0 must be a power of 2!
// q0 is the modulus w.r.t. whom the integers are reduced. We suggest to take q0 prime
//=====================================================================================
#define N0 512
// #define N0 1024
#define q0 (1<<19)
// #define q0 (2<<20) // gives nice results
// #define q0 536870913 // 2^29+1
// #define q0 798086719 // 30-bit prime
// #define q0 1497879259 // 31-bit prime
//======================================================================================
const ZZ q1 = conv<ZZ>(q0);
const long double q2 = (long double) q0;
//#ifdef USE_FLOAT128
// typedef __float128 RR_t;
//#else
typedef long double RR_t;
typedef complex<RR_t> CC_t;
//#endif
//NTRU
typedef struct
{
ZZX PrK[4];
CC_t PrK_fft[4][N0];
RR_t GS_Norms[2*N0];
RR_t sigma;
RR_t B[2*N0][2*N0];
RR_t Bstar[2*N0][2*N0];
} MSK_Data;
typedef struct
{
ZZ_pX h;
CC_t h_FFT[N0];
} MPK_Data;
//GNTRU
typedef struct
{
ZZX PrK[9];
CC_t PrK_fft[9][N0];
RR_t GS_Norms[3 * N0];
RR_t sigma;
RR_t B[3 * N0][3 * N0];
RR_t Bstar[3 * N0][3 * N0];
} GNTRU_MSK_Data;
typedef struct
{
ZZ_pX h1;
ZZ_pX h2;
CC_t h1_FFT[N0];
CC_t h2_FFT[N0];
} GNTRU_MPK_Data;
//==============================================================================
// Seed for the RNG
//==============================================================================
#ifdef __i386
extern __inline__ uint64_t rdtsc(void) {
uint64_t x;
__asm__ volatile ("rdtsc" : "=A" (x));
return x;
}
#elif defined __amd64
extern __inline__ uint64_t rdtsc(void) {
uint64_t a, d;
__asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
return (d << 32) | a;
}
#endif
// Useful constants up to ~500 bits
const long double sigma_1= 0.84932180028801904272150283410288961971514109378435394286159953238339383120795466719298223538163406787061691601172910413284884326532697308797136114023L;//sqrt(1/(2*log(2)))
const long double log_2 = 0.6931471805599453094172321214581765680755001343602552541206800094933936219696947156058633269964186875420014810205706857336855202357581305570326707516L;
const RR_t Pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081L;
const RR_t PiPrime = 0.39894228040143267793994605993438186847585863116493465766592582967065792589930183850125233390730693643030255886263518268551099195455583724299621273062L; //1/sqrt(2*Pi)
const RR_t LDRMX = ((RR_t)RAND_MAX );
const CC_t ii(0, 1);
const CC_t omega = exp( ii*(Pi/N0));
const CC_t omega_1 = exp(-ii*(Pi/N0));
#endif