Skip to content

Commit

Permalink
create new DST buffers instead of passing refs
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincharm committed Mar 11, 2024
1 parent 5732f15 commit 413ccb9
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions pairing/bn254/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,24 @@ type Suite struct {
gt *groupGT
}

var DEFAULT_DOMAIN_G1 = []byte("BN254G1_XMD:KECCAK-256_SSWU_RO_")
var DEFAULT_DOMAIN_G2 = []byte("BN254G2_XMD:KECCAK-256_SSWU_RO_")
func newDefaultDomainG1() []byte {
return []byte("BN254G1_XMD:KECCAK-256_SSWU_RO_")
}

func newDefaultDomainG2() []byte {
return []byte("BN254G2_XMD:KECCAK-256_SSWU_RO_")
}

// NewSuite generates and returns a new BN254 pairing suite.
func NewSuite() *Suite {
s := &Suite{commonSuite: &commonSuite{}}
s.g1 = &groupG1{
commonSuite: s.commonSuite,
dst: DEFAULT_DOMAIN_G1,
dst: newDefaultDomainG1(),
}
s.g2 = &groupG2{
commonSuite: s.commonSuite,
dst: DEFAULT_DOMAIN_G2,
dst: newDefaultDomainG2(),
}
s.gt = &groupGT{commonSuite: s.commonSuite}
return s
Expand Down Expand Up @@ -82,24 +87,28 @@ func NewSuiteRand(rand cipher.Stream) *Suite {
s := &Suite{commonSuite: &commonSuite{s: rand}}
s.g1 = &groupG1{
commonSuite: s.commonSuite,
dst: DEFAULT_DOMAIN_G1,
dst: newDefaultDomainG1(),
}
s.g2 = &groupG2{
commonSuite: s.commonSuite,
dst: DEFAULT_DOMAIN_G2,
dst: newDefaultDomainG2(),
}
s.gt = &groupGT{commonSuite: s.commonSuite}
return s
}

// Set G1 DST
func (s *Suite) SetDomainG1(dst []byte) {
s.g1.dst = dst
newDST := make([]byte, len(dst))
copy(newDST, dst)
s.g1.dst = newDST
}

// Set G2 DST
func (s *Suite) SetDomainG2(dst []byte) {
s.g2.dst = dst
newDST := make([]byte, len(dst))
copy(newDST, dst)
s.g2.dst = newDST
}

// G1 returns the group G1 of the BN254 pairing.
Expand Down

0 comments on commit 413ccb9

Please sign in to comment.