@@ -6,7 +6,6 @@ package vss
6
6
7
7
import (
8
8
"bytes"
9
- "crypto/cipher"
10
9
"encoding/binary"
11
10
"errors"
12
11
"fmt"
@@ -29,8 +28,7 @@ type Suite interface {
29
28
// Dealer encapsulates for creating and distributing the shares and for
30
29
// replying to any Responses.
31
30
type Dealer struct {
32
- suite Suite
33
- reader cipher.Stream
31
+ suite Suite
34
32
// long is the longterm key of the Dealer
35
33
long kyber.Scalar
36
34
pub kyber.Point
@@ -83,7 +81,7 @@ type Response struct {
83
81
// Index of the verifier issuing this Response from the new set of nodes
84
82
Index uint32
85
83
// false = NO APPROVAL == Complaint , true = APPROVAL
86
- Status bool
84
+ StatusApproved bool
87
85
// Signature over the whole packet
88
86
Signature []byte
89
87
}
@@ -115,7 +113,7 @@ type Justification struct {
115
113
// does not have to be trusted by other Verifiers. The security parameter t is
116
114
// the number of shares required to reconstruct the secret. MinimumT() provides
117
115
// a middle ground between robustness and secrecy. Increasing t will increase
118
- // the secrecy at the cost of the decreased robustness and vice versa. It
116
+ // the secrecy at the cost of the decreased robustness and vice versa. It
119
117
// returns an error if the t is inferior or equal to 2.
120
118
func NewDealer (suite Suite , longterm , secret kyber.Scalar , verifiers []kyber.Point , t int ) (* Dealer , error ) {
121
119
d := & Dealer {
@@ -227,14 +225,15 @@ func (d *Dealer) EncryptedDeals() ([]*EncryptedDeal, error) {
227
225
}
228
226
229
227
// ProcessResponse analyzes the given Response. If it's a valid complaint, then
230
- // it returns a Justification. This Justification must be broadcasted to every
231
- // participants . If it's an invalid complaint, it returns an error about the
228
+ // it returns a Justification. This Justification must be broadcast to every
229
+ // participant . If it's an invalid complaint, it returns an error about the
232
230
// complaint. The verifiers will also ignore an invalid Complaint.
233
231
func (d * Dealer ) ProcessResponse (r * Response ) (* Justification , error ) {
234
232
if err := d .verifyResponse (r ); err != nil {
235
233
return nil , err
236
234
}
237
- if r .Status == StatusApproval {
235
+ if r .StatusApproved {
236
+ //nolint:nilnil // Expected behavior
238
237
return nil , nil
239
238
}
240
239
@@ -370,12 +369,12 @@ func (v *Verifier) ProcessEncryptedDeal(e *EncryptedDeal) (*Response, error) {
370
369
}
371
370
372
371
r := & Response {
373
- SessionID : sid ,
374
- Index : uint32 (v .index ),
375
- Status : StatusApproval ,
372
+ SessionID : sid ,
373
+ Index : uint32 (v .index ),
374
+ StatusApproved : StatusApproval ,
376
375
}
377
376
if err = v .VerifyDeal (d , true ); err != nil {
378
- r .Status = StatusComplaint
377
+ r .StatusApproved = StatusComplaint
379
378
}
380
379
381
380
if errors .Is (err , errDealAlreadyProcessed ) {
@@ -503,11 +502,12 @@ func (v *Verifier) SetTimeout() {
503
502
// that works on basis of approval only.
504
503
func (v * Verifier ) UnsafeSetResponseDKG (idx uint32 , approval bool ) {
505
504
r := & Response {
506
- SessionID : v .Aggregator .sid ,
507
- Index : uint32 (idx ),
508
- Status : approval ,
505
+ SessionID : v .Aggregator .sid ,
506
+ Index : uint32 (idx ),
507
+ StatusApproved : approval ,
509
508
}
510
509
510
+ //nolint:errcheck // Unsafe function
511
511
v .Aggregator .addResponse (r )
512
512
}
513
513
@@ -527,7 +527,14 @@ type Aggregator struct {
527
527
timeout bool
528
528
}
529
529
530
- func newAggregator (suite Suite , dealer kyber.Point , verifiers , commitments []kyber.Point , t int , sid []byte ) * Aggregator {
530
+ func newAggregator (
531
+ suite Suite ,
532
+ dealer kyber.Point ,
533
+ verifiers ,
534
+ commitments []kyber.Point ,
535
+ t int ,
536
+ sid []byte ,
537
+ ) * Aggregator {
531
538
agg := & Aggregator {
532
539
suite : suite ,
533
540
dealer : dealer ,
@@ -636,7 +643,7 @@ func (a *Aggregator) verifyJustification(j *Justification) error {
636
643
if ! ok {
637
644
return errors .New ("vss: no complaints received for this justification" )
638
645
}
639
- if r .Status != StatusComplaint {
646
+ if r .StatusApproved {
640
647
return errors .New ("vss: justification received for an approval" )
641
648
}
642
649
@@ -645,7 +652,7 @@ func (a *Aggregator) verifyJustification(j *Justification) error {
645
652
a .badDealer = true
646
653
return err
647
654
}
648
- r .Status = StatusApproval
655
+ r .StatusApproved = StatusApproval
649
656
return nil
650
657
}
651
658
@@ -688,10 +695,10 @@ func (a *Aggregator) DealCertified() bool {
688
695
for i := range a .verifiers {
689
696
if r , ok := a .responses [uint32 (i )]; ! ok {
690
697
absentVerifiers ++
691
- } else if r .Status == StatusComplaint {
692
- isComplaint = true
693
- } else if r .Status == StatusApproval {
698
+ } else if r .StatusApproved {
694
699
approvals ++
700
+ } else {
701
+ isComplaint = true
695
702
}
696
703
}
697
704
enoughApprovals := approvals >= a .t
@@ -727,15 +734,6 @@ func validT(t int, verifiers []kyber.Point) bool {
727
734
return t >= 2 && t <= len (verifiers ) && int (uint32 (t )) == t
728
735
}
729
736
730
- func deriveH (suite Suite , verifiers []kyber.Point ) kyber.Point {
731
- var b bytes.Buffer
732
- for _ , v := range verifiers {
733
- _ , _ = v .MarshalTo (& b )
734
- }
735
- base := suite .Point ().Pick (suite .XOF (b .Bytes ()))
736
- return base
737
- }
738
-
739
737
func findPub (verifiers []kyber.Point , idx uint32 ) (kyber.Point , bool ) {
740
738
iidx := int (idx )
741
739
if iidx >= len (verifiers ) {
@@ -746,18 +744,27 @@ func findPub(verifiers []kyber.Point, idx uint32) (kyber.Point, bool) {
746
744
747
745
func sessionID (suite Suite , dealer kyber.Point , verifiers , commitments []kyber.Point , t int ) ([]byte , error ) {
748
746
h := suite .Hash ()
749
- _ , _ = dealer .MarshalTo (h )
747
+ _ , err := dealer .MarshalTo (h )
748
+ if err != nil {
749
+ return nil , err
750
+ }
750
751
751
752
for _ , v := range verifiers {
752
- _ , _ = v .MarshalTo (h )
753
+ _ , err = v .MarshalTo (h )
754
+ if err != nil {
755
+ return nil , err
756
+ }
753
757
}
754
758
755
759
for _ , c := range commitments {
756
- _ , _ = c .MarshalTo (h )
760
+ _ , err = c .MarshalTo (h )
761
+ if err != nil {
762
+ return nil , err
763
+ }
757
764
}
758
- _ = binary .Write (h , binary .LittleEndian , uint32 (t ))
759
765
760
- return h .Sum (nil ), nil
766
+ err = binary .Write (h , binary .LittleEndian , uint32 (t ))
767
+ return h .Sum (nil ), err
761
768
}
762
769
763
770
// Hash returns the Hash representation of the Response
@@ -766,7 +773,7 @@ func (r *Response) Hash(s Suite) []byte {
766
773
_ , _ = h .Write ([]byte ("response" ))
767
774
_ , _ = h .Write (r .SessionID )
768
775
_ = binary .Write (h , binary .LittleEndian , r .Index )
769
- _ = binary .Write (h , binary .LittleEndian , r .Status )
776
+ _ = binary .Write (h , binary .LittleEndian , r .StatusApproved )
770
777
return h .Sum (nil )
771
778
}
772
779
0 commit comments