forked from taurushq-io/multi-party-sig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
round1.go
106 lines (93 loc) · 3.69 KB
/
round1.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
100
101
102
103
104
105
106
package sign
import (
"crypto/rand"
"github.com/taurusgroup/multi-party-sig/internal/round"
"github.com/taurusgroup/multi-party-sig/pkg/math/curve"
"github.com/taurusgroup/multi-party-sig/pkg/math/sample"
"github.com/taurusgroup/multi-party-sig/pkg/party"
"github.com/zeebo/blake3"
)
// This round sort of corresponds with Figure 2 of the Frost paper:
// https://eprint.iacr.org/2020/852.pdf
//
// The main difference is that instead of having a separate pre-processing step,
// we instead have an additional round at the start of the signing step.
// The goal of this round is to generate two nonces, and corresponding commitments.
//
// There are also differences corresponding to the lack of a signing authority,
// namely that these commitments are broadcast, instead of stored with the authority.
type round1 struct {
*round.Helper
// taproot indicates whether or not we need to generate Taproot / BIP-340 signatures.
//
// If so, we have a few slight tweaks to make around the evenness of points,
// and we need to make sure to generate our challenge in the correct way. Naturally,
// we also return a taproot.Signature instead a generic signature.
taproot bool
// M is the hash of the message we're signing.
//
// This plays the same role as m in the Frost paper. One slight difference
// is that instead of including the message directly in various hashes,
// we include the *hash* of that message instead. This provides the same
// security.
M messageHash
// Y is the public key we're signing for.
Y curve.Point
// YShares are verification shares for each participant's fraction of the secret key
//
// YShares[i] corresponds with Yᵢ in the Frost paper.
YShares map[party.ID]curve.Point
// s_i = sᵢ is our private secret share
s_i curve.Scalar
}
// VerifyMessage implements round.Round.
func (r *round1) VerifyMessage(round.Message) error { return nil }
func (r *round1) StoreMessage(round.Message) error { return nil }
const deriveHashKeyContext = "github.com/taurusgroup/multi-party-sig/frost 2021-07-30T09:48+00:00 Derive hash Key"
// Finalize implements round.Round.
func (r *round1) Finalize(out chan<- *round.Message) (round.Session, error) {
// We can think of this as roughly implementing Figure 2. The idea is
// to generate two nonces (dᵢ, eᵢ) in Z/(q)ˣ, then two commitments
// Dᵢ = dᵢ * G, Eᵢ = eᵢ * G, and then broadcast them.
// We use a hedged deterministic process, instead of simply sampling (d_i, e_i):
//
// a = random()
// hk = KDF(s_i)
// (d_i, e_i) = H_hk(ctx, m, a)
//
// This protects against bad randomness, since a constant value for a is still unpredictable,
// and fault attacks against the hash function, because of the randomness.
s_iBytes, err := r.s_i.MarshalBinary()
if err != nil {
return r, err
}
hashKey := make([]byte, 32)
blake3.DeriveKey(deriveHashKeyContext, s_iBytes[:], hashKey)
nonceHasher, _ := blake3.NewKeyed(hashKey)
_, _ = nonceHasher.Write(r.Hash().Sum())
_, _ = nonceHasher.Write(r.M)
a := make([]byte, 32)
_, _ = rand.Read(a)
_, _ = nonceHasher.Write(a)
nonceDigest := nonceHasher.Digest()
d_i := sample.ScalarUnit(nonceDigest, r.Group())
e_i := sample.ScalarUnit(nonceDigest, r.Group())
D_i := d_i.ActOnBase()
E_i := e_i.ActOnBase()
// Broadcast the commitments
err = r.BroadcastMessage(out, &broadcast2{D_i: D_i, E_i: E_i})
if err != nil {
return r, err
}
return &round2{
round1: r,
d_i: d_i,
e_i: e_i,
D: map[party.ID]curve.Point{r.SelfID(): D_i},
E: map[party.ID]curve.Point{r.SelfID(): E_i},
}, nil
}
// MessageContent implements round.Round.
func (round1) MessageContent() round.Content { return nil }
// Number implements round.Round.
func (round1) Number() round.Number { return 1 }