-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathaggregation.go
56 lines (46 loc) · 1.33 KB
/
aggregation.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
package distIBE
import (
"github.com/drand/kyber"
"github.com/drand/kyber/pairing"
)
func AggregateSK(s pairing.Suite, receivedShares []ExtractedKey, commitments []Commitment, id []byte) (kyber.Point, []uint32) {
SkShares := []kyber.Point{}
invalid := []uint32{}
valid := []uint32{}
validShare := []ExtractedKey{}
for i := range receivedShares {
receivedShare := receivedShares[i]
commitment := commitments[i]
hG2, ok := s.G2().Point().(kyber.HashablePoint)
if !ok {
panic("point needs to implement `kyber.HashablePoint`")
}
Qid := hG2.Hash(id)
if VerifyShare(s, commitment, receivedShare, Qid) {
valid = append(valid, receivedShare.Index)
validShare = append(validShare, receivedShare)
} else {
invalid = append(invalid, commitment.Index)
}
}
for _, r := range validShare {
processedShare := processSK(s, r, valid)
SkShares = append(SkShares, processedShare.SK)
}
SK := aggregate(SkShares...)
return SK, invalid
}
func processSK(suite pairing.Suite, share ExtractedKey, S []uint32) ExtractedKey {
lagrangeCoef := LagrangeCoefficient(suite, share.Index, S)
idenityKey := share.SK.Mul(lagrangeCoef, share.SK)
return ExtractedKey{idenityKey, share.Index}
}
func aggregate(keys ...kyber.Point) kyber.Point {
var sk = keys[0]
for _, key := range keys {
if key != sk {
sk.Add(sk, key)
}
}
return sk
}