-
Notifications
You must be signed in to change notification settings - Fork 0
/
secret_share_test.go
85 lines (68 loc) · 1.37 KB
/
secret_share_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
85
package mpc_test
import (
"testing"
"github.com/CUIT-CBI/mpc"
)
func TestSplitSecret(t *testing.T) {
secret := make([]byte, 256)
for i := 0; i < 256; i++ {
secret[i] = byte(i)
}
n := 10
threshold := 3
parts := mpc.SplitSecret(secret, n, threshold)
if len(parts) != n {
t.FailNow()
}
for i := 0; i < n; i++ {
part := parts[i]
if part.Threshold != threshold {
t.FailNow()
}
if len(part.Value) != len(secret) {
t.FailNow()
}
}
}
func TestCombainSecret(t *testing.T) {
secrets := make([]byte, 256)
for i := 0; i < 256; i++ {
secrets[i] = byte(i)
}
n := 10
threshold := 3
parts := mpc.SplitSecret(secrets, n, threshold)
recovered_secrets := mpc.CombainSecret(parts[2:5])
if len(recovered_secrets) != len(secrets) {
t.FailNow()
}
for i := 0; i < len(secrets); i++ {
if secrets[i] != recovered_secrets[i] {
t.FailNow()
}
}
}
func BenchmarkTestSplitSecret(b *testing.B) {
secret := make([]byte, 256)
for i := 0; i < 256; i++ {
secret[i] = byte(i)
}
n := 10
threshold := 3
for i := 0; i < b.N; i++ {
mpc.SplitSecret(secret, n, threshold)
}
}
func BenchmarkTestCombainSecret(b *testing.B) {
secret := make([]byte, 256)
for i := 0; i < 256; i++ {
secret[i] = byte(i)
}
n := 10
threshold := 3
parts := mpc.SplitSecret(secret, n, threshold)
selected := parts[3:6]
for i := 0; i < b.N; i++ {
mpc.CombainSecret(selected)
}
}