forked from winderica/kryptology
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dkg_round4.go
91 lines (82 loc) · 2.38 KB
/
dkg_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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
package participant
import (
"fmt"
"math/big"
"github.com/coinbase/kryptology/internal"
"github.com/coinbase/kryptology/pkg/core/curves"
"github.com/coinbase/kryptology/pkg/paillier"
"github.com/coinbase/kryptology/pkg/tecdsa/gg20/dealer"
)
// DkgResult is all the data generated from the DKG
type DkgResult struct {
PublicShares []*curves.EcPoint
VerificationKey *curves.EcPoint
SigningKeyShare *big.Int
EncryptionKey *paillier.SecretKey
ParticipantData map[uint32]*DkgParticipantData
}
type DkgParticipantData struct {
PublicKey *paillier.PublicKey
ProofParams *dealer.ProofParams
}
// DkgRound4 computes dkg round 4 as shown in
// [spec] fig. 5: DistKeyGenRound4
func (dp *DkgParticipant) DkgRound4(psfProof map[uint32]paillier.PsfProof) (*DkgResult, error) {
if len(psfProof) == 0 {
return nil, internal.ErrIncorrectCount
}
if dp.Round != 4 {
return nil, internal.ErrInvalidRound
}
// Make sure all participants sent a proof
for id := range dp.state.otherParticipantData {
if id == dp.id {
continue
}
if _, ok := psfProof[id]; !ok {
return nil, fmt.Errorf("missing proof for participant %d", id)
}
}
verifyPsfParams := paillier.PsfVerifyParams{
Curve: dp.Curve,
Y: dp.state.Y,
}
// 1. for j = [1,...,n]
for id, p := range psfProof {
// 2. if i == j, continue
if dp.id == id {
continue
}
verifyPsfParams.PublicKey = dp.state.otherParticipantData[id].PublicKey
verifyPsfParams.Pi = id
// 3. if VerifyPSF(\pi_j, pk_j.N, y, g, q, pj) = false, abort
if err := p.Verify(&verifyPsfParams); err != nil {
return nil, err
}
}
// Return paillier public keys and proof params
// from all participants
participantData := make(map[uint32]*DkgParticipantData)
for id, data := range dp.state.otherParticipantData {
participantData[id] = &DkgParticipantData{
PublicKey: data.PublicKey,
ProofParams: data.ProofParams,
}
}
// Return all necessary information to complete signing
// the proof params, paillier public keys, and public commitments
// from other participants, the secret signing key share, and
// the public verification key
return &DkgResult{
VerificationKey: dp.state.Y,
SigningKeyShare: dp.state.Xi,
PublicShares: dp.state.PublicShares,
EncryptionKey: dp.state.Sk,
ParticipantData: participantData,
}, nil
}