-
Notifications
You must be signed in to change notification settings - Fork 3
/
Recrypt_test.m
36 lines (27 loc) · 966 Bytes
/
Recrypt_test.m
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
// Load your favorite scheme
load "Crypto/BFV/BFV.m";
//load "Crypto/BGV/BGV.m";
// Load recryption functionality
load "Bootstrapping/Recrypt.m";
sk, pk := GenKeyPair();
// Message to recrypt
msq := RandPol(p ^ r);
csq := Encrypt(msq, p ^ r, pk);
if scheme eq "BFV" then
if enableModSwitch then
csq := ModSwitch(csq, 2 ^ 100); // BFV
end if;
else
csq := ModSwitch(csq, baseModulus ^ Round(Log(baseModulus, 2 ^ 100))); // BGV
end if;
// Bootstrapping info
recrypt_variables := GenerateRecryptVariables(sk, pk, r, e, B);
// Test recryption
t := Cputime();
res := Recrypt(csq, recrypt_variables);
"";
"Time for bootstrapping", Cputime(t);
"Test bootstrapping", Decrypt(res, sk) eq msq;
"Total noise in bootstrapped ciphertext", ErrorC(res, sk);
"Error after bootstrapping on canonical embedding", ErrorCanC(res, sk);
"Estimated error after bootstrapping on canonical embedding", EstimatedErrorCanC(res);