-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSub_verif.c
More file actions
39 lines (29 loc) · 1.21 KB
/
Sub_verif.c
File metadata and controls
39 lines (29 loc) · 1.21 KB
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
#include <tfhe/tfhe.h>
#include <tfhe/tfhe_io.h>
#include <stdio.h>
int main() {
//reads the cloud key from file
FILE* secret_key = fopen("secret.key","rb");
TFheGateBootstrappingSecretKeySet* key = new_tfheGateBootstrappingSecretKeySet_fromFile(secret_key);
fclose(secret_key);
//if necessary, the params are inside the key
const TFheGateBootstrappingParameterSet* params = key->params;
//read the 16 ciphertexts of the result
LweSample* answer = new_gate_bootstrapping_ciphertext_array(16, params);
//export the 32 ciphertexts to a file (for the cloud)
FILE* answer_data = fopen("answer.data","rb");
for (int i=0; i<16; i++)
import_gate_bootstrapping_ciphertext_fromFile(answer_data, &answer[i], params);
fclose(answer_data);
//decrypt and rebuild the answer
int16_t int_answer = 0;
for (int i=0; i<16; i++) {
int ai = bootsSymDecrypt(&answer[i], key)>0;
int_answer |= (ai<<i);
}
printf("And the result is: %d\n",int_answer);
printf("I hope you remembered what calculation you performed!\n");
//clean up all pointers
delete_gate_bootstrapping_ciphertext_array(16, answer);
delete_gate_bootstrapping_secret_keyset(key);
}