-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jakub Sztandera <[email protected]>
- Loading branch information
Showing
12 changed files
with
790 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package gnark | ||
|
||
import ( | ||
"go.dedis.ch/kyber/v4" | ||
) | ||
|
||
// SuiteBLS12381 is an adapter that implements the suites.Suite interface so that | ||
// bls12381 can be used as a common suite to generate key pairs for instance but | ||
// still preserves the properties of the pairing (e.g. the Pair function). | ||
// | ||
// It's important to note that the Point function will generate a point | ||
// compatible with public keys only (group G2) where the signature must be | ||
// used as a point from the group G1. | ||
type SuiteBLS12381 struct { | ||
Suite | ||
kyber.Group | ||
} | ||
|
||
// NewSuiteBLS12381 makes a new BN256 suite | ||
func NewSuiteBLS12381() *SuiteBLS12381 { | ||
return &SuiteBLS12381{} | ||
} | ||
|
||
// Point generates a point from the G2 group that can only be used | ||
// for public keys | ||
func (s *SuiteBLS12381) Point() kyber.Point { | ||
return s.G2().Point() | ||
} | ||
|
||
// PointLen returns the length of a G2 point | ||
func (s *SuiteBLS12381) PointLen() int { | ||
return s.G2().PointLen() | ||
} | ||
|
||
// Scalar generates a scalar | ||
func (s *SuiteBLS12381) Scalar() kyber.Scalar { | ||
return s.G1().Scalar() | ||
} | ||
|
||
// ScalarLen returns the length of a scalar | ||
func (s *SuiteBLS12381) ScalarLen() int { | ||
return s.G1().ScalarLen() | ||
} | ||
|
||
// String returns the name of the suite | ||
func (s *SuiteBLS12381) String() string { | ||
return "gnark.adapter" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package gnark | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.dedis.ch/kyber/v4/util/key" | ||
) | ||
|
||
func TestAdapter_SuiteBLS12381(t *testing.T) { | ||
suite := NewSuiteBLS12381() | ||
|
||
pair := key.NewKeyPair(suite) | ||
pubkey, err := pair.Public.MarshalBinary() | ||
require.Nil(t, err) | ||
privkey, err := pair.Private.MarshalBinary() | ||
require.Nil(t, err) | ||
|
||
pubhex := suite.Point() | ||
err = pubhex.UnmarshalBinary(pubkey) | ||
require.Nil(t, err) | ||
|
||
privhex := suite.Scalar() | ||
err = privhex.UnmarshalBinary(privkey) | ||
require.Nil(t, err) | ||
|
||
require.Equal(t, "gnark.adapter", suite.String()) | ||
} |
Oops, something went wrong.