Skip to content

Commit

Permalink
Fix lint issues sign
Browse files Browse the repository at this point in the history
  • Loading branch information
K1li4nL committed Feb 24, 2024
1 parent fc031d7 commit 434c405
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 35 deletions.
13 changes: 8 additions & 5 deletions sign/bdn/bdn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestBDN_HashPointToR_BN256(t *testing.T) {
require.Equal(t, "933f6013eb3f654f9489d6d45ad04eaf", coefs[2].String())
require.Equal(t, 16, coefs[0].MarshalSize())

mask, _ := sign.NewMask(suite, []kyber.Point{p1, p2, p3}, nil)
mask, _ := sign.NewMask([]kyber.Point{p1, p2, p3}, nil)
mask.SetBit(0, true)
mask.SetBit(1, true)
mask.SetBit(2, true)
Expand All @@ -55,7 +55,7 @@ func TestBDN_AggregateSignatures(t *testing.T) {
sig2, err := Sign(suite, private2, msg)
require.NoError(t, err)

mask, _ := sign.NewMask(suite, []kyber.Point{public1, public2}, nil)
mask, _ := sign.NewMask([]kyber.Point{public1, public2}, nil)
mask.SetBit(0, true)
mask.SetBit(1, true)

Expand All @@ -66,6 +66,7 @@ func TestBDN_AggregateSignatures(t *testing.T) {
require.NoError(t, err)

aggregatedKey, err := AggregatePublicKeys(suite, mask)
require.NoError(t, err)

sig, err := aggregatedSig.MarshalBinary()
require.NoError(t, err)
Expand All @@ -75,6 +76,7 @@ func TestBDN_AggregateSignatures(t *testing.T) {

mask.SetBit(1, false)
aggregatedKey, err = AggregatePublicKeys(suite, mask)
require.NoError(t, err)

err = Verify(suite, aggregatedKey, msg, sig)
require.Error(t, err)
Expand All @@ -91,14 +93,15 @@ func TestBDN_SubsetSignature(t *testing.T) {
sig2, err := Sign(suite, private2, msg)
require.NoError(t, err)

mask, _ := sign.NewMask(suite, []kyber.Point{public1, public3, public2}, nil)
mask, _ := sign.NewMask([]kyber.Point{public1, public3, public2}, nil)
mask.SetBit(0, true)
mask.SetBit(2, true)

aggregatedSig, err := AggregateSignatures(suite, [][]byte{sig1, sig2}, mask)
require.NoError(t, err)

aggregatedKey, err := AggregatePublicKeys(suite, mask)
require.NoError(t, err)

sig, err := aggregatedSig.MarshalBinary()
require.NoError(t, err)
Expand Down Expand Up @@ -128,7 +131,7 @@ func TestBDN_RogueAttack(t *testing.T) {
require.NoError(t, bls.Verify(suite, agg, msg, sig))

// New scheme that should detect
mask, _ := sign.NewMask(suite, pubs, nil)
mask, _ := sign.NewMask(pubs, nil)
mask.SetBit(0, true)
mask.SetBit(1, true)
agg, err = AggregatePublicKeys(suite, mask)
Expand All @@ -146,7 +149,7 @@ func Benchmark_BDN_AggregateSigs(b *testing.B) {
sig2, err := Sign(suite, private2, msg)
require.Nil(b, err)

mask, _ := sign.NewMask(suite, []kyber.Point{public1, public2}, nil)
mask, _ := sign.NewMask([]kyber.Point{public1, public2}, nil)
mask.SetBit(0, true)
mask.SetBit(1, false)

Expand Down
4 changes: 1 addition & 3 deletions sign/dss/dss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ var partSec []kyber.Scalar
var longterms []*dkg.DistKeyShare
var randoms []*dkg.DistKeyShare

var dss []*DSS

func init() {
partPubs = make([]kyber.Point, nbParticipants)
partSec = make([]kyber.Scalar, nbParticipants)
Expand Down Expand Up @@ -220,6 +218,6 @@ func genPair() (kyber.Scalar, kyber.Point) {

func randomBytes(n int) []byte {
var buff = make([]byte, n)
_, _ = rand.Read(buff[:])
_, _ = rand.Read(buff)
return buff
}
2 changes: 1 addition & 1 deletion sign/eddsa/eddsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func VerifyWithChecks(pub, msg, sig []byte) error {
func Verify(public kyber.Point, msg, sig []byte) error {
PBuf, err := public.MarshalBinary()
if err != nil {
return fmt.Errorf("error unmarshalling public key: %s", err)
return fmt.Errorf("error unmarshalling public key: %w", err)
}
return VerifyWithChecks(PBuf, msg, sig)
}
9 changes: 4 additions & 5 deletions sign/mask.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"

"go.dedis.ch/kyber/v3"
"go.dedis.ch/kyber/v3/pairing"
)

// Mask is a bitmask of the participation to a collective signature.
Expand All @@ -17,7 +16,7 @@ type Mask struct {

// NewMask creates a new mask from a list of public keys. If a key is provided, it
// will set the bit of the key to 1 or return an error if it is not found.
func NewMask(suite pairing.Suite, publics []kyber.Point, myKey kyber.Point) (*Mask, error) {
func NewMask(publics []kyber.Point, myKey kyber.Point) (*Mask, error) {
m := &Mask{
publics: publics,
}
Expand All @@ -26,8 +25,8 @@ func NewMask(suite pairing.Suite, publics []kyber.Point, myKey kyber.Point) (*Ma
if myKey != nil {
for i, key := range publics {
if key.Equal(myKey) {
m.SetBit(i, true)
return m, nil
err := m.SetBit(i, true)
return m, err
}
}

Expand All @@ -40,7 +39,7 @@ func NewMask(suite pairing.Suite, publics []kyber.Point, myKey kyber.Point) (*Ma
// Mask returns the bitmask as a byte array.
func (m *Mask) Mask() []byte {
clone := make([]byte, len(m.mask))
copy(clone[:], m.mask)
copy(clone, m.mask)
return clone
}

Expand Down
12 changes: 6 additions & 6 deletions sign/mask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func init() {
}

func TestMask_CreateMask(t *testing.T) {
mask, err := NewMask(suite, publics, nil)
mask, err := NewMask(publics, nil)
require.NoError(t, err)

require.Equal(t, len(publics), len(mask.Publics()))
Expand All @@ -34,19 +34,19 @@ func TestMask_CreateMask(t *testing.T) {
require.Equal(t, n/8+1, mask.Len())
require.Equal(t, uint8(0), mask.Mask()[0])

mask, err = NewMask(suite, publics, publics[2])
mask, err = NewMask(publics, publics[2])
require.NoError(t, err)

require.Equal(t, len(publics), len(mask.Publics()))
require.Equal(t, 1, mask.CountEnabled())
require.Equal(t, uint8(0x4), mask.Mask()[0])

mask, err = NewMask(suite, publics, suite.G1().Point())
_, err = NewMask(publics, suite.G1().Point())
require.Error(t, err)
}

func TestMask_SetBit(t *testing.T) {
mask, err := NewMask(suite, publics, publics[2])
mask, err := NewMask(publics, publics[2])
require.NoError(t, err)

err = mask.SetBit(1, true)
Expand All @@ -72,7 +72,7 @@ func TestMask_SetBit(t *testing.T) {
}

func TestMask_SetAndMerge(t *testing.T) {
mask, err := NewMask(suite, publics, publics[2])
mask, err := NewMask(publics, publics[2])
require.NoError(t, err)

err = mask.SetMask([]byte{})
Expand All @@ -90,7 +90,7 @@ func TestMask_SetAndMerge(t *testing.T) {
}

func TestMask_PositionalQueries(t *testing.T) {
mask, err := NewMask(suite, publics, publics[2])
mask, err := NewMask(publics, publics[2])
require.NoError(t, err)

for i := 0; i < 10000; i++ {
Expand Down
22 changes: 11 additions & 11 deletions sign/schnorr/schnorr.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,23 @@ func VerifyWithChecks(g kyber.Group, pub, msg, sig []byte) error {
IsCanonical(b []byte) bool
}

R := g.Point()
r := g.Point()
s := g.Scalar()
pointSize := R.MarshalSize()
pointSize := r.MarshalSize()
scalarSize := s.MarshalSize()
sigSize := scalarSize + pointSize
if len(sig) != sigSize {
return fmt.Errorf("schnorr: signature of invalid length %d instead of %d", len(sig), sigSize)
}
if err := R.UnmarshalBinary(sig[:pointSize]); err != nil {
if err := r.UnmarshalBinary(sig[:pointSize]); err != nil {
return err
}
if p, ok := R.(pointCanCheckCanonicalAndSmallOrder); ok {
if p, ok := r.(pointCanCheckCanonicalAndSmallOrder); ok {
if !p.IsCanonical(sig[:pointSize]) {
return fmt.Errorf("R is not canonical")
return fmt.Errorf("r is not canonical")
}
if p.HasSmallOrder() {
return fmt.Errorf("R has small order")
return fmt.Errorf("r has small order")
}
}
if s, ok := g.Scalar().(scalarCanCheckCanonical); ok && !s.IsCanonical(sig[pointSize:]) {
Expand All @@ -111,17 +111,17 @@ func VerifyWithChecks(g kyber.Group, pub, msg, sig []byte) error {
return fmt.Errorf("public key has small order")
}
}
// recompute hash(public || R || msg)
h, err := hash(g, public, R, msg)
// recompute hash(public || r || msg)
h, err := hash(g, public, r, msg)
if err != nil {
return err
}

// compute S = g^s
S := g.Point().Mul(s, nil)
// compute RAh = R + A^h
// compute RAh = r + A^h
Ah := g.Point().Mul(h, public)
RAs := g.Point().Add(R, Ah)
RAs := g.Point().Add(r, Ah)

if !S.Equal(RAs) {
return errors.New("schnorr: invalid signature")
Expand All @@ -136,7 +136,7 @@ func VerifyWithChecks(g kyber.Group, pub, msg, sig []byte) error {
func Verify(g kyber.Group, public kyber.Point, msg, sig []byte) error {
PBuf, err := public.MarshalBinary()
if err != nil {
return fmt.Errorf("error unmarshalling public key: %s", err)
return fmt.Errorf("error unmarshalling public key: %w", err)
}
return VerifyWithChecks(g, PBuf, msg, sig)
}
Expand Down
8 changes: 4 additions & 4 deletions sign/schnorr/schnorr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ type quickstream struct {
rand *rand.Rand
}

func (s *quickstream) XORKeyStream(dst, src []byte) {
func (s *quickstream) XORKeyStream(dst, _ []byte) {
s.rand.Read(dst)
}

func (s *quickstream) Generate(rand *rand.Rand, size int) reflect.Value {
func (s *quickstream) Generate(rand *rand.Rand, _ int) reflect.Value {
return reflect.ValueOf(&quickstream{rand: rand})
}

Expand All @@ -99,10 +99,10 @@ func TestQuickSchnorrSignature(t *testing.T) {

func TestSchnorrMalleability(t *testing.T) {
/* l = 2^252+27742317777372353535851937790883648493, prime order of the base point */
var L []uint16 = []uint16{0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7,
L := []uint16{0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7,
0xa2, 0xde, 0xf9, 0xde, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}
var c uint16 = 0
var c uint16

msg := []byte("Hello Schnorr")
suite := edwards25519.NewBlakeSHA256Ed25519()
Expand Down

0 comments on commit 434c405

Please sign in to comment.