-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdhomo_test.go
84 lines (71 loc) · 3.59 KB
/
dhomo_test.go
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
72
73
74
75
76
77
78
79
80
81
82
83
84
package spdz2
import (
"fmt"
"testing"
)
func TestDhomo(t *testing.T) {
t.Run("2player", func(t *testing.T) {
publicparams, P := dkeyGen(2)
ciphertext0 := publicparams.bfvEnc([]uint64{2, 4, 6})
ciphertext1 := publicparams.bfvEnc([]uint64{2, 4, 6})
ciphertext2 := publicparams.bfvAdd(ciphertext0, ciphertext1)
ciphertext2 = publicparams.bfvSub(ciphertext2, ciphertext1)
ciphertext3 := publicparams.bfvMult(ciphertext0, ciphertext1)
ciphertext2New := publicparams.keyswitch(ciphertext2, P)
ciphertext3New := publicparams.keyswitch(ciphertext3, P)
plaintext2 := publicparams.bfvDDec(ciphertext2New)
plaintext3 := publicparams.bfvDDec(ciphertext3New)
fmt.Println(plaintext2)
fmt.Println(plaintext3)
})
t.Run("4player", func(t *testing.T) {
publicparams, P := dkeyGen(4)
ciphertext0 := publicparams.bfvEnc([]uint64{2, 4, 6})
ciphertext1 := publicparams.bfvEnc([]uint64{2, 4, 6})
ciphertext2 := publicparams.bfvEnc([]uint64{2, 4, 6})
ciphertext3 := publicparams.bfvEnc([]uint64{2, 4, 6})
ciphertext0123add := publicparams.bfvAdd(ciphertext0, ciphertext1)
ciphertext0123add = publicparams.bfvAdd(ciphertext0123add, ciphertext2)
ciphertext0123add = publicparams.bfvAdd(ciphertext0123add, ciphertext3)
ciphertext0123mult := publicparams.bfvMult(ciphertext0, ciphertext1)
ciphertext0123mult = publicparams.bfvMult(ciphertext0123mult, ciphertext2)
ciphertext0123mult = publicparams.bfvMult(ciphertext0123mult, ciphertext3)
ciphertext0123addNew := publicparams.keyswitch(ciphertext0123add, P)
ciphertext0123multNew := publicparams.keyswitch(ciphertext0123mult, P)
plaintext2 := publicparams.bfvDDec(ciphertext0123addNew)
plaintext3 := publicparams.bfvDDec(ciphertext0123multNew)
fmt.Println(plaintext2)
fmt.Println(plaintext3)
})
t.Run("8player", func(t *testing.T) {
publicparams, P := dkeyGen(8)
ciphertext0 := publicparams.bfvEnc([]uint64{2, 4, 6})
ciphertext1 := publicparams.bfvEnc([]uint64{2, 4, 6})
ciphertext2 := publicparams.bfvEnc([]uint64{2, 4, 6})
ciphertext3 := publicparams.bfvEnc([]uint64{2, 4, 6})
ciphertext4 := publicparams.bfvEnc([]uint64{2, 4, 6})
ciphertext5 := publicparams.bfvEnc([]uint64{2, 4, 6})
ciphertext6 := publicparams.bfvEnc([]uint64{2, 4, 6})
ciphertext7 := publicparams.bfvEnc([]uint64{2, 4, 6})
ciphertext0123add := publicparams.bfvAdd(ciphertext0, ciphertext1)
ciphertext0123add = publicparams.bfvAdd(ciphertext0123add, ciphertext2)
ciphertext0123add = publicparams.bfvAdd(ciphertext0123add, ciphertext3)
ciphertext0123add = publicparams.bfvAdd(ciphertext0123add, ciphertext4)
ciphertext0123add = publicparams.bfvAdd(ciphertext0123add, ciphertext5)
ciphertext0123add = publicparams.bfvAdd(ciphertext0123add, ciphertext6)
ciphertext0123add = publicparams.bfvAdd(ciphertext0123add, ciphertext7)
ciphertext0123mult := publicparams.bfvMult(ciphertext0, ciphertext1)
ciphertext0123mult = publicparams.bfvMult(ciphertext0123mult, ciphertext2)
ciphertext0123mult = publicparams.bfvMult(ciphertext0123mult, ciphertext3)
ciphertext0123mult = publicparams.bfvMult(ciphertext0123mult, ciphertext4)
ciphertext0123mult = publicparams.bfvMult(ciphertext0123mult, ciphertext5)
ciphertext0123mult = publicparams.bfvMult(ciphertext0123mult, ciphertext6)
ciphertext0123mult = publicparams.bfvMult(ciphertext0123mult, ciphertext7)
ciphertext0123addNew := publicparams.keyswitch(ciphertext0123add, P)
ciphertext0123multNew := publicparams.keyswitch(ciphertext0123mult, P)
plaintext2 := publicparams.bfvDDec(ciphertext0123addNew)
plaintext3 := publicparams.bfvDDec(ciphertext0123multNew)
fmt.Println(plaintext2)
fmt.Println(plaintext3)
})
}