-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateEvectors.c
71 lines (59 loc) · 2.11 KB
/
generateEvectors.c
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
/**
* \file generateEvectors.c
*
* \author H{\aa}vard Raddum, Prastudy Fauzi
*
* Code for sampling LGM secret keys.
* It requires the DGS library https://github.com/malb/dgs to generate discrete Gaussians over the integers
*/
#include <dgs/dgs_gauss.h>
int *randomE(int ne, double sigma, int B){
/* Samples a vector of integers from a Gaussian distribution with standard deviation sigma and cut-off bound B. */
dgs_disc_gauss_dp_t *DGS;
int *e, i;
e = (int *) malloc(ne * sizeof(int));
DGS = dgs_disc_gauss_dp_init(sigma, 0.0, (size_t) B, DGS_DISC_GAUSS_DEFAULT);
for(i = 0; i < ne; i++)
e[i] = (int) DGS->call(DGS);
dgs_disc_gauss_dp_clear(DGS);
return e;
}
int main(int argc, char *argv[]){
/**
* Program parameters:
* - number of secret key vectors t (e.g., 190)
* - length m of secret ley vectors (e.g., 525)
* - the standard deviation (sigma) for the discrete Gaussian sampler (e.g., 25)
*
* The result will be written to a file with the format "secretKey_%d_%d_%d.txt"
* For example, if t = 190, m = 525, sigma = 25 the file name will be "secretKey_190_525_25.txt"
*/
FILE *fp;
char filename[80];
int **Etab;
int t, m, sigma, i, j;
int B = 150;
if(argc<4){
printf("Usage: specify number of vectors produced (t) as first parameter, length of each vector (m) as second parameter, and standard deviation (sigma) for the Gaussian sampler as the last parameter.\n"); exit(0);
}
t = atoi(argv[1]);
m = atoi(argv[2]);
sigma = (double) atoi(argv[3]);
sprintf(filename, "secretKey_%d_%d_%d.txt", t, m, sigma);
fp = fopen(filename, "w");
fprintf(fp, "m=%d t=%d\n", m, t);
Etab=(int **) malloc(t * sizeof(int *));
for(i = 0; i < t; i++)
Etab[i] = randomE(m, (double) sigma, B);
/*
Vectors are stored as m vectors of length t in the file for easy parallelization.
The first vector contains [e_{1,0} e_{2,0} ... e_{t,0}], the second vector contains [e_{1,1} e_{2,1} ... e_{t,1}], etc.
*/
for(j = 0; j < m; j++){
fprintf(fp, "[");
for(i = 0; i < t; i++)
fprintf(fp, "%d ", Etab[i][j]);
fprintf(fp, "]\n");
}
fclose(fp);
}