-
Notifications
You must be signed in to change notification settings - Fork 0
/
system.go
57 lines (45 loc) · 1.68 KB
/
system.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
package main
import (
"math/rand"
"time"
"go.dedis.ch/kyber/v3"
"go.dedis.ch/kyber/v3/pairing"
"go.dedis.ch/kyber/v3/share"
"go.dedis.ch/kyber/v3/util/random"
)
// PublicParameters contains all the required public parameters
type publicParameters struct {
Threshold int
TotalServers int
Suite pairing.Suite
PublicPolynomials [2]*share.PubPoly
}
type keysInTransport struct {
Left []byte
Right []byte
Error error
}
func setupThresholdServers(parameters publicParameters, secret kyber.Scalar) ([]*server, *share.PubPoly, *share.PubPoly) {
serverList := make([]*server, parameters.TotalServers)
if secret == nil {
secret = parameters.Suite.GT().Scalar().Pick(random.New())
}
priPoly1 := share.NewPriPoly(parameters.Suite.G2(), parameters.Threshold, secret, random.New())
pubPoly1 := priPoly1.Commit(parameters.Suite.G2().Point().Base())
serverPrivateKeys1 := priPoly1.Shares(parameters.TotalServers)
priPoly2 := share.NewPriPoly(parameters.Suite.G1(), parameters.Threshold, secret, random.New())
pubPoly2 := priPoly2.Commit(parameters.Suite.G1().Point().Base())
serverPrivateKeys2 := priPoly2.Shares(parameters.TotalServers)
for i := 0; i < parameters.TotalServers; i++ {
comms := make(chan keysInTransport)
serverList[i] = newServer(i, serverPrivateKeys1[i], serverPrivateKeys2[i], comms)
}
return serverList, pubPoly1, pubPoly2
}
func chooseTofNservers(parameters publicParameters, servers []*server) []*server {
rand.Seed(time.Now().Unix())
shuffled := make([]*server, len(servers))
copy(shuffled, servers)
rand.Shuffle(len(shuffled), func(i, j int) { shuffled[i], shuffled[j] = shuffled[j], shuffled[i] })
return shuffled[:parameters.Threshold]
}