Skip to content

Commit

Permalink
Uncomment bls_test and internal folder (#517)
Browse files Browse the repository at this point in the history
* Moved scheme.go and threshold.go into internals and uncommented bls_test.go
* Removed nerr++ in favor of len(errors)
* Changed the path for test
* Sorting imports
  • Loading branch information
Robingoumaz authored May 15, 2024
1 parent 9cb3571 commit 2736907
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 15 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion pairing/bn254/bls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package bn254
import (
"testing"

"go.dedis.ch/kyber/v3/internal/test"
"go.dedis.ch/kyber/v3/sign/bls"
"go.dedis.ch/kyber/v3/sign/test"
)

func TestBLSSchemeBN254G1(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pairing/bn256/bls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

"github.com/stretchr/testify/require"
"go.dedis.ch/kyber/v3/internal/test"
"go.dedis.ch/kyber/v3/sign/bls"
"go.dedis.ch/kyber/v3/sign/test"
"go.dedis.ch/kyber/v3/util/random"
)

Expand Down
2 changes: 1 addition & 1 deletion pairing/circl_bls12381/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

"github.com/stretchr/testify/require"
"go.dedis.ch/kyber/v3"
"go.dedis.ch/kyber/v3/internal/test"
this "go.dedis.ch/kyber/v3/pairing/circl_bls12381"
"go.dedis.ch/kyber/v3/sign/bls"
"go.dedis.ch/kyber/v3/sign/tbls"
"go.dedis.ch/kyber/v3/sign/test"
"go.dedis.ch/kyber/v3/util/random"
)

Expand Down
19 changes: 12 additions & 7 deletions sign/bls/bls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func TestBLSFailAggregatedKey(t *testing.T) {
t.Fatal("bls: verification succeeded unexpectedly")
}
}

func TestBLSBatchVerify(t *testing.T) {
msg1 := []byte("Hello Boneh-Lynn-Shacham")
msg2 := []byte("Hello Dedis & Boneh-Lynn-Shacham")
Expand All @@ -136,6 +137,7 @@ func TestBLSBatchVerify(t *testing.T) {
err = BatchVerify(suite, []kyber.Point{public1, public2}, [][]byte{msg1, msg2}, aggregatedSig)
require.Nil(t, err)
}

func TestBLSFailBatchVerify(t *testing.T) {
msg1 := []byte("Hello Boneh-Lynn-Shacham")
msg2 := []byte("Hello Dedis & Boneh-Lynn-Shacham")
Expand Down Expand Up @@ -168,7 +170,6 @@ func TestBLSFailBatchVerify(t *testing.T) {
t.Fatal("bls: verification succeeded unexpectedly")
}
})

}

func BenchmarkBLSKeyCreation(b *testing.B) {
Expand All @@ -187,7 +188,8 @@ func BenchmarkBLSSign(b *testing.B) {
msg := []byte("Hello many times Boneh-Lynn-Shacham")
b.ResetTimer()
for i := 0; i < b.N; i++ {
scheme.Sign(private, msg)
_, err := scheme.Sign(private, msg)
require.Nil(b, err)
}
}

Expand All @@ -204,7 +206,8 @@ func BenchmarkBLSAggregateSigs(b *testing.B) {

b.ResetTimer()
for i := 0; i < b.N; i++ {
scheme.AggregateSignatures(sig1, sig2)
_, err := scheme.AggregateSignatures(sig1, sig2)
require.Nil(b, err)
}
}

Expand All @@ -222,14 +225,14 @@ func BenchmarkBLSVerifyAggregate(b *testing.B) {
key := scheme.AggregatePublicKeys(public1, public2)
b.ResetTimer()
for i := 0; i < b.N; i++ {
scheme.Verify(key, msg, sig)
err := scheme.Verify(key, msg, sig)
require.Nil(b, err)
}
}

func BenchmarkBLSVerifyBatchVerify(b *testing.B) {
suite := bn256.NewSuite()
scheme := NewSchemeOnG1(suite)

numSigs := 100
privates := make([]kyber.Scalar, numSigs)
publics := make([]kyber.Point, numSigs)
Expand All @@ -240,7 +243,8 @@ func BenchmarkBLSVerifyBatchVerify(b *testing.B) {
privates[i] = private
publics[i] = public
msg := make([]byte, 64, 64)
rand.Read(msg)
_, err := rand.Read(msg)
require.Nil(b, err)
msgs[i] = msg
sig, err := scheme.Sign(private, msg)
require.Nil(b, err)
Expand All @@ -250,7 +254,8 @@ func BenchmarkBLSVerifyBatchVerify(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
aggregateSig, _ := scheme.AggregateSignatures(sigs...)
BatchVerify(suite, publics, msgs, aggregateSig)
err := BatchVerify(suite, publics, msgs, aggregateSig)
require.Nil(b, err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion sign/tbls/tbls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"testing"

"github.com/stretchr/testify/require"
"go.dedis.ch/kyber/v3/internal/test"
"go.dedis.ch/kyber/v3/pairing/bn256"
"go.dedis.ch/kyber/v3/share"
"go.dedis.ch/kyber/v3/sign/test"
"go.dedis.ch/kyber/v3/xof/blake2xb"
)

Expand Down
3 changes: 2 additions & 1 deletion sign/test/bls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package test
import (
"testing"

"go.dedis.ch/kyber/v3/internal/test"
bls "go.dedis.ch/kyber/v3/pairing/circl_bls12381"
sign "go.dedis.ch/kyber/v3/sign/bls"
)

func TestBLS12381(t *testing.T) {
suite := bls.NewSuiteBLS12381()
scheme := sign.NewSchemeOnG1(suite)
SchemeTesting(t, scheme)
test.SchemeTesting(t, scheme)
}
4 changes: 1 addition & 3 deletions util/random/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,19 @@ func (r *randstream) XORKeyStream(dst, src []byte) {

// try to read readerBytes bytes from all readers and write them in a buffer
var b bytes.Buffer
var nerr int
var errors []string
buff := make([]byte, readerBytes)
for _, reader := range r.Readers {
n, err := io.ReadFull(reader, buff)
if err != nil {
nerr++
errors = append(errors, err.Error())
}
b.Write(buff[:n])
}

// we are ok with few sources being insecure (i.e., providing less than
// readerBytes bytes), but not all of them
if nerr == len(r.Readers) {
if len(errors) == len(r.Readers) {
panic(errors)
}

Expand Down

0 comments on commit 2736907

Please sign in to comment.