Skip to content

Commit 99e6d31

Browse files
committed
Merge branch 'develop' of github.com:ConsenSys/gnark-crypto into develop
2 parents 35d0c90 + 3ca2549 commit 99e6d31

File tree

11 files changed

+92
-13
lines changed

11 files changed

+92
-13
lines changed

ecc/bls12-377/fp/element_utils.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2020 ConsenSys Software Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package fp
16+
17+
// MulByNonResidueInv ...
18+
func (z *Element) MulByNonResidueInv(x *Element) *Element {
19+
qnrInv := Element{
20+
9255502405446297221,
21+
10229180150694123945,
22+
9215585410771530959,
23+
13357015519562362907,
24+
5437107869987383107,
25+
16259554076827459,
26+
}
27+
z.Mul(x, &qnrInv)
28+
return z
29+
}

ecc/bls12-377/internal/fptower/e2_bls377.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,14 @@ func (z *E2) norm(x *fp.Element) {
104104
fp.MulBy5(&tmp)
105105
x.Square(&z.A0).Add(x, &tmp)
106106
}
107+
108+
// MulBybTwistCurveCoeff multiplies by 1/(0,1)
109+
func (z *E2) MulBybTwistCurveCoeff(x *E2) *E2 {
110+
111+
var res E2
112+
res.A0.Set(&x.A1)
113+
res.A1.MulByNonResidueInv(&x.A0)
114+
z.Set(&res)
115+
116+
return z
117+
}

ecc/bls12-377/pairing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func (p *g2Proj) DoubleStep(evaluations *lineEvaluation) {
176176
C.Square(&p.z)
177177
D.Double(&C).
178178
Add(&D, &C)
179-
E.Mul(&D, &bTwistCurveCoeff)
179+
E.MulBybTwistCurveCoeff(&D)
180180
F.Double(&E).
181181
Add(&F, &E)
182182
G.Add(&B, &F)

ecc/bls12-381/internal/fptower/e2_bls381.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,15 @@ func (z *E2) norm(x *fp.Element) {
8989
tmp.Square(&z.A1)
9090
x.Add(x, &tmp)
9191
}
92+
93+
// MulBybTwistCurveCoeff multiplies by 4(1,1)
94+
func (z *E2) MulBybTwistCurveCoeff(x *E2) *E2 {
95+
96+
var res E2
97+
res.A0.Sub(&x.A0, &x.A1)
98+
res.A1.Add(&x.A0, &x.A1)
99+
z.Double(&res).
100+
Double(z)
101+
102+
return z
103+
}

ecc/bls12-381/pairing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (p *g2Proj) DoubleStep(l *lineEvaluation) {
180180
C.Square(&p.z)
181181
D.Double(&C).
182182
Add(&D, &C)
183-
E.Mul(&D, &bTwistCurveCoeff)
183+
E.MulBybTwistCurveCoeff(&D)
184184
F.Double(&E).
185185
Add(&F, &E)
186186
G.Add(&B, &F)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2020 ConsenSys AG
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package fptower
16+
17+
// MulBybTwistCurveCoeff multiplies by 1/(0,1)
18+
func (z *E4) MulBybTwistCurveCoeff(x *E4) *E4 {
19+
20+
var res E4
21+
res.B0.Set(&x.B1)
22+
res.B1.MulByNonResidueInv(&x.B0)
23+
z.Set(&res)
24+
25+
return z
26+
}

ecc/bls24-315/pairing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (p *g2Proj) DoubleStep(evaluations *lineEvaluation) {
190190
C.Square(&p.z)
191191
D.Double(&C).
192192
Add(&D, &C)
193-
E.Mul(&D, &bTwistCurveCoeff)
193+
E.MulBybTwistCurveCoeff(&D)
194194
F.Double(&E).
195195
Add(&F, &E)
196196
G.Add(&B, &F)

ecc/bn254/g2.go

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ecc/bw6-633/pairing.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,11 @@ func (p *g1Proj) DoubleStep(evaluations *lineEvaluation) {
322322
C.Square(&p.z)
323323
D.Double(&C).
324324
Add(&D, &C)
325-
E.Mul(&D, &bCurveCoeff)
325+
326+
// E.Mul(&D, &bCurveCoeff)
327+
E.Double(&D).
328+
Double(&E)
329+
326330
F.Double(&E).
327331
Add(&F, &E)
328332
G.Add(&B, &F)

ecc/bw6-761/pairing.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ func (p *g1Proj) DoubleStep(evaluations *lineEvaluation) {
297297
C.Square(&p.z)
298298
D.Double(&C).
299299
Add(&D, &C)
300-
E.Mul(&D, &bCurveCoeff)
300+
301+
// E.Mul(&D, &bCurveCoeff)
302+
E.Neg(&D)
303+
301304
F.Double(&E).
302305
Add(&F, &E)
303306
G.Add(&B, &F)

0 commit comments

Comments
 (0)