forked from taurushq-io/multi-party-sig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
round5.go
99 lines (76 loc) · 2.22 KB
/
round5.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
package sign
import (
"errors"
"github.com/taurusgroup/multi-party-sig/internal/round"
"github.com/taurusgroup/multi-party-sig/pkg/ecdsa"
"github.com/taurusgroup/multi-party-sig/pkg/math/curve"
"github.com/taurusgroup/multi-party-sig/pkg/party"
)
var _ round.Round = (*round5)(nil)
type round5 struct {
*round4
// SigmaShares[j] = σⱼ = m⋅kⱼ + χⱼ⋅R|ₓ
SigmaShares map[party.ID]curve.Scalar
// Delta = δ = ∑ⱼ δⱼ
// computed from received shares
Delta curve.Scalar
// BigDelta = Δ = ∑ⱼ Δⱼ
BigDelta curve.Point
// R = [δ⁻¹] Γ
BigR curve.Point
// R = R|ₓ
R curve.Scalar
}
type broadcast5 struct {
round.NormalBroadcastContent
SigmaShare curve.Scalar
}
// StoreBroadcastMessage implements round.BroadcastRound.
//
// - save σⱼ
func (r *round5) StoreBroadcastMessage(msg round.Message) error {
body, ok := msg.Content.(*broadcast5)
if !ok || body == nil {
return round.ErrInvalidContent
}
if body.SigmaShare.IsZero() {
return round.ErrNilFields
}
r.SigmaShares[msg.From] = body.SigmaShare
return nil
}
// VerifyMessage implements round.Round.
func (round5) VerifyMessage(round.Message) error { return nil }
// StoreMessage implements round.Round.
func (round5) StoreMessage(round.Message) error { return nil }
// Finalize implements round.Round
//
// - compute σ = ∑ⱼ σⱼ
// - verify signature.
func (r *round5) Finalize(chan<- *round.Message) (round.Session, error) {
// compute σ = ∑ⱼ σⱼ
Sigma := r.Group().NewScalar()
for _, j := range r.PartyIDs() {
Sigma.Add(r.SigmaShares[j])
}
signature := &ecdsa.Signature{
R: r.BigR,
S: Sigma,
}
if !signature.Verify(r.PublicKey, r.Message) {
return r.AbortRound(errors.New("failed to validate signature")), nil
}
return r.ResultRound(signature), nil
}
// MessageContent implements round.Round.
func (r *round5) MessageContent() round.Content { return nil }
// RoundNumber implements round.Content.
func (broadcast5) RoundNumber() round.Number { return 5 }
// BroadcastContent implements round.BroadcastRound.
func (r *round5) BroadcastContent() round.BroadcastContent {
return &broadcast5{
SigmaShare: r.Group().NewScalar(),
}
}
// Number implements round.Round.
func (round5) Number() round.Number { return 5 }