Skip to content

Commit

Permalink
fix: add GT ExpGLV fix to BLS24 + BW6
Browse files Browse the repository at this point in the history
  • Loading branch information
yelhousni committed Sep 29, 2023
1 parent feaf161 commit aef1eef
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 7 deletions.
8 changes: 7 additions & 1 deletion ecc/bls24-315/internal/fptower/e24.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,14 @@ func (z *E24) ExpGLV(x E24, k *big.Int) *E24 {
s1 = s1.SetBigInt(&s[0]).Bits()
s2 = s2.SetBigInt(&s[1]).Bits()

maxBit := s1.BitLen()
if s2.BitLen() > maxBit {
maxBit = s2.BitLen()
}
hiWordIndex := (maxBit - 1) / 64

// loop starts from len(s1)/2 due to the bounds
for i := len(s1)/2 + 1; i >= 0; i-- {
for i := hiWordIndex; i >= 0; i-- {
mask := uint64(3) << 62
for j := 0; j < 32; j++ {
res.CyclotomicSquare(&res).CyclotomicSquare(&res)
Expand Down
8 changes: 7 additions & 1 deletion ecc/bls24-317/internal/fptower/e24.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,14 @@ func (z *E24) ExpGLV(x E24, k *big.Int) *E24 {
s1 = s1.SetBigInt(&s[0]).Bits()
s2 = s2.SetBigInt(&s[1]).Bits()

maxBit := s1.BitLen()
if s2.BitLen() > maxBit {
maxBit = s2.BitLen()
}
hiWordIndex := (maxBit - 1) / 64

// loop starts from len(s1)/2 due to the bounds
for i := len(s1)/2 + 1; i >= 0; i-- {
for i := hiWordIndex; i >= 0; i-- {
mask := uint64(3) << 62
for j := 0; j < 32; j++ {
res.CyclotomicSquare(&res).CyclotomicSquare(&res)
Expand Down
8 changes: 7 additions & 1 deletion ecc/bw6-633/internal/fptower/e6.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,14 @@ func (z *E6) ExpGLV(x E6, k *big.Int) *E6 {
s1 = s1.SetBigInt(&s[0]).Bits()
s2 = s2.SetBigInt(&s[1]).Bits()

maxBit := s1.BitLen()
if s2.BitLen() > maxBit {
maxBit = s2.BitLen()
}
hiWordIndex := (maxBit - 1) / 64

// loop starts from len(s1)/2 due to the bounds
for i := len(s1) / 2; i >= 0; i-- {
for i := hiWordIndex; i >= 0; i-- {
mask := uint64(3) << 62
for j := 0; j < 32; j++ {
res.CyclotomicSquare(&res).CyclotomicSquare(&res)
Expand Down
35 changes: 35 additions & 0 deletions ecc/bw6-633/pairing_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion ecc/bw6-756/internal/fptower/e6.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,14 @@ func (z *E6) ExpGLV(x E6, k *big.Int) *E6 {
s1 = s1.SetBigInt(&s[0]).Bits()
s2 = s2.SetBigInt(&s[1]).Bits()

maxBit := s1.BitLen()
if s2.BitLen() > maxBit {
maxBit = s2.BitLen()
}
hiWordIndex := (maxBit - 1) / 64

// loop starts from len(s1)/2 due to the bounds
for i := len(s1) / 2; i >= 0; i-- {
for i := hiWordIndex; i >= 0; i-- {
mask := uint64(3) << 62
for j := 0; j < 32; j++ {
res.CyclotomicSquare(&res).CyclotomicSquare(&res)
Expand Down
35 changes: 35 additions & 0 deletions ecc/bw6-756/pairing_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion ecc/bw6-761/internal/fptower/e6.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,14 @@ func (z *E6) ExpGLV(x E6, k *big.Int) *E6 {
s1 = s1.SetBigInt(&s[0]).Bits()
s2 = s2.SetBigInt(&s[1]).Bits()

maxBit := s1.BitLen()
if s2.BitLen() > maxBit {
maxBit = s2.BitLen()
}
hiWordIndex := (maxBit - 1) / 64

// loop starts from len(s1)/2 due to the bounds
for i := len(s1) / 2; i >= 0; i-- {
for i := hiWordIndex; i >= 0; i-- {
mask := uint64(3) << 62
for j := 0; j < 32; j++ {
res.CyclotomicSquare(&res).CyclotomicSquare(&res)
Expand Down
35 changes: 35 additions & 0 deletions ecc/bw6-761/pairing_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions internal/generator/pairing/template/tests/pairing.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func TestPairing(t *testing.T) {
genA,
))

{{if not (or ( or (eq .Name "bw6-761") (eq .Name "bw6-633")) (eq .Name "bw6-756") ) }}
properties.Property("[{{ toUpper .Name}}] Exp, CyclotomicExp and ExpGLV results must be the same in GT (small and big exponents)", prop.ForAll(
func(a GT, e fr.Element, ) bool {

Expand Down Expand Up @@ -86,7 +85,6 @@ func TestPairing(t *testing.T) {
genA,
genR1,
))
{{ end }}

properties.Property("[{{ toUpper .Name}}] Expt(Expt) and Exp(t^2) should output the same result in the cyclotomic subgroup", prop.ForAll(
func(a GT) bool {
Expand Down

0 comments on commit aef1eef

Please sign in to comment.