forked from coinbase/kryptology
-
Notifications
You must be signed in to change notification settings - Fork 0
/
round4.go
76 lines (64 loc) · 1.86 KB
/
round4.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
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
package gennaro
import (
"math/big"
"github.com/coinbase/kryptology/internal"
"github.com/coinbase/kryptology/pkg/core"
"github.com/coinbase/kryptology/pkg/core/curves"
"github.com/coinbase/kryptology/pkg/sharing/v1"
)
// Round4 computes the public shares used by tECDSA during signing
// that are converted to additive shares once the signing participants
// are known. This function is idempotent
func (dp *Participant) Round4() (map[uint32]*curves.EcPoint, error) {
// Check participant is not empty
if dp == nil || dp.curve == nil {
return nil, internal.ErrNilArguments
}
// Check participant has the correct dkg round number
if dp.round != 4 {
return nil, internal.ErrInvalidRound
}
n := len(dp.otherParticipantShares) + 1 //+1 to include self
// Wj's
publicShares := make(map[uint32]*curves.EcPoint, n)
// 1. R = {{R1,...,Rt},{Rij,...,Rit}i!=j}
r := make(map[uint32][]*v1.ShareVerifier, n)
r[dp.id] = dp.pedersenResult.Verifiers
for j := range dp.otherParticipantShares {
r[j] = dp.otherParticipantShares[j].Verifiers
}
// 2. for j in 1,...,n
for j, v := range r {
// 3. Wj = Pk
publicShares[j] = &curves.EcPoint{
Curve: dp.verificationKey.Curve,
X: new(big.Int).Set(dp.verificationKey.X),
Y: new(big.Int).Set(dp.verificationKey.Y),
}
// 4. for k in 1,...,t
for k := 0; k < len(dp.pedersenResult.Verifiers); k++ {
// 5. ck = pj * k mod q
pj := big.NewInt(int64(j))
ck, err := core.Mul(pj, big.NewInt(int64(k+1)), dp.curve.Params().N)
if err != nil {
return nil, err
}
// 6a. t = ck * Rj
t, err := v[k].ScalarMult(ck)
if err != nil {
return nil, err
}
// 6b. Wj = Wj + t
publicShares[j], err = publicShares[j].Add(t)
if err != nil {
return nil, err
}
}
}
return publicShares, nil
}