File tree Expand file tree Collapse file tree 11 files changed +92
-13
lines changed
internal/generator/ecc/template Expand file tree Collapse file tree 11 files changed +92
-13
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments