This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 125
/
round1.go
78 lines (63 loc) · 1.73 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
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
package frost
import (
"bytes"
crand "crypto/rand"
"encoding/gob"
"github.com/pkg/errors"
"github.com/coinbase/kryptology/internal"
"github.com/coinbase/kryptology/pkg/core/curves"
)
// Round1Bcast contains values to be broadcast to all players after the completion of signing round 1.
type Round1Bcast struct {
Di, Ei curves.Point
}
func (result *Round1Bcast) Encode() ([]byte, error) {
gob.Register(result.Di) // just the point for now
gob.Register(result.Ei)
buf := &bytes.Buffer{}
enc := gob.NewEncoder(buf)
if err := enc.Encode(result); err != nil {
return nil, errors.Wrap(err, "couldn't encode round 1 broadcast")
}
return buf.Bytes(), nil
}
func (result *Round1Bcast) Decode(input []byte) error {
buf := bytes.NewBuffer(input)
dec := gob.NewDecoder(buf)
if err := dec.Decode(result); err != nil {
return errors.Wrap(err, "couldn't encode round 1 broadcast")
}
return nil
}
func (signer *Signer) SignRound1() (*Round1Bcast, error) {
// Make sure signer is not empty
if signer == nil || signer.curve == nil {
return nil, internal.ErrNilArguments
}
// Make sure round number is correct
if signer.round != 1 {
return nil, internal.ErrInvalidRound
}
// Step 1 - Sample di, ei
di := signer.curve.Scalar.Random(crand.Reader)
ei := signer.curve.Scalar.Random(crand.Reader)
// Step 2 - Compute Di, Ei
Di := signer.curve.ScalarBaseMult(di)
Ei := signer.curve.ScalarBaseMult(ei)
// Update round number
signer.round = 2
// Store di, ei, Di, Ei locally and broadcast Di, Ei
signer.state.capD = Di
signer.state.capE = Ei
signer.state.smallD = di
signer.state.smallE = ei
return &Round1Bcast{
Di,
Ei,
}, nil
}