-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestHelibJNI.java
More file actions
65 lines (51 loc) · 1.99 KB
/
TestHelibJNI.java
File metadata and controls
65 lines (51 loc) · 1.99 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
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
import java.util.ArrayList;
public class TestHelibJNI {
// Test Driver
public static void main(String[] args) {
HelibJNIApi obj = new HelibJNIApi();
//TODO: p,m,r,bits,c should be unsigned
// Plaintext prime modulus
long p = 4999;
// Cyclotomic polynomial - defines phi(m)
long m = 32109;
// Hensel lifting (default = 1)
long r = 1;
// Number of bits of the modulus chain
long bits = 300;
// Number of columns of Key-Switching matix (default = 2 or 3)
long c = 2;
System.out.println("##Init context...");
long cptr = obj.initContext(m, p, r); // Create an instance and invoke the native method
System.out.println("##cptr:"+cptr);
obj.printContext(cptr);
System.out.println("##building modulus chain...");
obj.buildModChain(cptr,bits,c);
obj.printContext(cptr);
System.out.println("##security level:"+obj.securityLevel(cptr));
System.out.println("##creating secret key...");
long seckeyptr = obj.initSecKey(cptr);
obj.genSecKey(seckeyptr);
obj.printSecKey(seckeyptr);
System.out.println("##generating keyswitching matrices");
obj.addSome1DMatrices(seckeyptr);
obj.printSecKey(seckeyptr);
System.out.println("##number of slots");
long nslots = obj.eaSize(cptr);
System.out.println("##nslots:"+nslots);
ArrayList<Long> ptxt = new ArrayList<Long>((int)nslots);
for (long i = 0; i < nslots; i++) {
ptxt.add(i);
}
long pubkeyptr = seckeyptr;
long ctxtptr = obj.initCtxt(pubkeyptr);
obj.eaEncrypt(cptr, ctxtptr, pubkeyptr, ptxt);
obj.mul(ctxtptr,ctxtptr);
obj.add(ctxtptr,ctxtptr);
System.out.println("##decrypt");
ArrayList<Long> decrypted = new ArrayList<Long>((int)nslots);
obj.eaDecrypt(cptr, ctxtptr, seckeyptr, decrypted);
for(int i = 0; i < decrypted.size(); i++) {
System.out.println("##jdecrypted:"+i+":"+decrypted.get(i));
}
}
}