-
Notifications
You must be signed in to change notification settings - Fork 1
/
sss_test.go
104 lines (81 loc) · 2.29 KB
/
sss_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package sss
import (
"math/big"
"testing"
)
func TestShareGenerationAndRecovery(t *testing.T) {
min := 200
shares := 500
prime, _ := big.NewInt(1).SetString("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", 16)
secret, points, e1 := GenerateShares(min, shares, prime)
recoveredSecret, e2 := RecoverSecret(points[:min], prime)
if e1 != nil {
t.Error(e1)
t.Fail()
}
if e2 != nil {
t.Error(e2)
t.Fail()
}
t.Log("Expect ", secret, "to equal", recoveredSecret)
if secret.Cmp(recoveredSecret) != 0 {
t.Errorf("Expected secret %x to equal recovered secret %x", secret, recoveredSecret)
}
}
func benchmarkShareGeneration(i int, b *testing.B) {
prime, _ := big.NewInt(1).SetString("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", 16)
b.ResetTimer()
for n := 0; n < b.N; n++ {
GenerateShares(i/3, i, prime)
}
}
func BenchmarkShareGeneration10(b *testing.B) {
benchmarkShareGeneration(10, b)
}
func BenchmarkShareGeneration20(b *testing.B) {
benchmarkShareGeneration(20, b)
}
func BenchmarkShareGeneration50(b *testing.B) {
benchmarkShareGeneration(50, b)
}
func BenchmarkShareGeneration100(b *testing.B) {
benchmarkShareGeneration(100, b)
}
func BenchmarkShareGeneration200(b *testing.B) {
benchmarkShareGeneration(200, b)
}
func BenchmarkShareGeneration500(b *testing.B) {
benchmarkShareGeneration(500, b)
}
func BenchmarkShareGeneration1000(b *testing.B) {
benchmarkShareGeneration(1000, b)
}
func benchmarkSecretRecovery(i int, b *testing.B) {
prime, _ := big.NewInt(1).SetString("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", 16)
_, shares, _ := GenerateShares(i/3, i, prime)
b.ResetTimer()
for n := 0; n < b.N; n++ {
RecoverSecret(shares, prime)
}
}
func BenchmarkSecretRecovery10(b *testing.B) {
benchmarkSecretRecovery(10, b)
}
func BenchmarkSecretRecovery20(b *testing.B) {
benchmarkSecretRecovery(20, b)
}
func BenchmarkSecretRecovery50(b *testing.B) {
benchmarkSecretRecovery(50, b)
}
func BenchmarkSecretRecovery100(b *testing.B) {
benchmarkSecretRecovery(100, b)
}
func BenchmarkSecretRecovery200(b *testing.B) {
benchmarkSecretRecovery(100, b)
}
func BenchmarkSecretRecovery500(b *testing.B) {
benchmarkSecretRecovery(500, b)
}
func BenchmarkSecretRecovery1000(b *testing.B) {
benchmarkSecretRecovery(1000, b)
}