#define n 500
#define N 1024
#define N2 (N/2+1)
#define K2 6
#define BS_base 23
#define BS_exp 2
typedef double complex_double[2];
typedef complex_double Ring_FFT[N2];
typedef Ring_FFT ct_FFT[K2][2]; // Ciphertext in FFT form ct_FFT[K2][2] => Ring_FFT[6][2] => complex_double[6][2][513] => double[6][2][513][2]
typedef ct_FFT BootstrappingKey[n][BS_base][BS_exp];
//BootstrappingKey[500][23][2] => ct_FFT[500][23][2] => ct_FFT[500][23][2][6][2] => complex_double[500][23][2][6][2][513] => double[500][23][2][6][2][513][2]
typedef struct {
BootstrappingKey *BSkey;
SwitchingKey *KSkey;
} EvalKey;
EvalKey EK;
EK.BSkey = (BootstrappingKey*) malloc(sizeof(BootstrappingKey));
printf("sizeof BootstrappingKey: %lu\n",sizeof(BootstrappingKey));
printf("EK.BSkey: %p\n",EK.BSkey);
if(EK.BSkey == NULL) {
fprintf(stderr, "BAD BAD BAD!\n");
return -1;
}
EK.KSkey = (SwitchingKey*) malloc(sizeof(SwitchingKey));
if(EK.KSkey == NULL) {
fprintf(stderr, "EVEN WORSE!\n");
return -1;
}
printf("\nPointer value of EK.BSkey = %p\n",(EK.BSkey));
printf("\nPointer value of EK.KSkey = %p\n",(EK.KSkey));
printf("Starting another huge loop\n");
for(int i =0; i< n; ++i)
for(int j=0;j < BS_base;++j)
for(int k=0;k < BS_exp; ++k)
for(int l=0; l < K2; ++l)
for(int a =0; a <2; ++a)
for(int b =0; b < N2; ++b)
for(int c =0; c < 2; ++c){
printf("Arrrrgh: i=%d, j=%d, k=%d, l=%d, a=%d, b=%d, c=%d\n",i,j,k,l,a,b,c);
*(EK.BSkey)[i][j][k][l][a][b][c] = 1.0;
}
This is a really large array for a Homomorphic encryption project. However I kept getting segmentation faults. I wrote this forloop just for debugging purposes. As soon as the loop reaches:
Arrrrgh: i=0, j=22, k=1, l=5, a=1, b=512, c=1<br>
Arrrrgh: i=1, j=0, k=0, l=0, a=0, b=0, c=0
I got a segmentation fault (output of Valgrind):
==8127== Invalid write of size 8 ==8127== at 0x401CFB: FHEWKeyGen (FHEW.c:100) ==8127== by 0x400D94: main (gen.c:46)
I would really appreciate some help.