|
|
@@ -247,7 +247,7 @@ type OpsCtx struct { |
|
|
|
var op OpsCtx |
|
|
|
type Ops1 struct{}; |
|
|
|
|
|
|
|
func (ctx *Ops1) MulFp2(res, lhs, rhs *ExtensionFieldElement) { |
|
|
|
func (ctx Ops1) MulFp2(res, lhs, rhs *ExtensionFieldElement) { |
|
|
|
// Let (a,b,c,d) = (lhs.a,lhs.b,rhs.a,rhs.b). |
|
|
|
a := &lhs.A |
|
|
|
b := &lhs.B |
|
|
@@ -283,7 +283,7 @@ func (ctx *Ops1) MulFp2(res, lhs, rhs *ExtensionFieldElement) { |
|
|
|
fp751X2SubLazy(&ac_minus_bd, &ac, &bd) // = (a*c - b*d)*R*R |
|
|
|
fp751MontgomeryReduce(&res.A, &ac_minus_bd) // = (a*c - b*d)*R mod p |
|
|
|
} |
|
|
|
func (ctx *Ops1) SquareFp2(res, x *ExtensionFieldElement) { |
|
|
|
func (ctx Ops1) SquareFp2(res, x *ExtensionFieldElement) { |
|
|
|
a := &x.A |
|
|
|
b := &x.B |
|
|
|
|
|
|
@@ -303,11 +303,11 @@ func (ctx *Ops1) SquareFp2(res, x *ExtensionFieldElement) { |
|
|
|
fp751MontgomeryReduce(&res.A, &asq_minus_bsq) // = (a^2 - b^2)*R mod p |
|
|
|
fp751MontgomeryReduce(&res.B, &ab2) // = 2*a*b*R mod p |
|
|
|
} |
|
|
|
func (ctx *Ops1) AddFp2(res, lhs, rhs *ExtensionFieldElement) { |
|
|
|
func (ctx Ops1) AddFp2(res, lhs, rhs *ExtensionFieldElement) { |
|
|
|
fp751AddReduced(&res.A, &lhs.A, &rhs.A) |
|
|
|
fp751AddReduced(&res.B, &lhs.B, &rhs.B) |
|
|
|
} |
|
|
|
func (ctx *Ops1) SubFp2(res, lhs, rhs *ExtensionFieldElement) { |
|
|
|
func (ctx Ops1) SubFp2(res, lhs, rhs *ExtensionFieldElement) { |
|
|
|
fp751SubReduced(&res.A, &lhs.A, &rhs.A) |
|
|
|
fp751SubReduced(&res.B, &lhs.B, &rhs.B) |
|
|
|
} |
|
|
@@ -324,31 +324,29 @@ func (x3P *ProjectivePoint) Pow3k(params *CurveCoefficientsEquiv, xP *Projective |
|
|
|
|
|
|
|
pp := op.op[0] |
|
|
|
|
|
|
|
sub, add, sqr, mul := pp.SubFp2, pp.AddFp2, pp.SquareFp2, pp.MulFp2 |
|
|
|
|
|
|
|
for i := uint32(0); i < k; i++ { |
|
|
|
sub(&t0, x, z) // t0 = Xp - Zp |
|
|
|
sqr(&t2, &t0) // t2 = t0^2 |
|
|
|
add(&t1,x, z) // t1 = Xp + Zp |
|
|
|
sqr(&t3, &t1) // t3 = t1^2 |
|
|
|
add(&t4,&t1, &t0) // t4 = t1 + t0 |
|
|
|
sub(&t0, &t1, &t0) // t0 = t1 - t0 |
|
|
|
sqr(&t1, &t4) // t1 = t4^2 |
|
|
|
sub(&t1, &t1, &t3) // t1 = t1 - t3 |
|
|
|
sub(&t1, &t1, &t2) // t1 = t1 - t2 |
|
|
|
mul(&t5,&t3, ¶ms.A) // t5 = t3 * A24+ |
|
|
|
mul(&t3,&t3, &t5) // t3 = t5 * t3 |
|
|
|
mul(&t6,&t2, ¶ms.C) // t6 = t2 * A24- |
|
|
|
mul(&t2,&t2, &t6) // t2 = t2 * t6 |
|
|
|
sub(&t3, &t2, &t3) // t3 = t2 - t3 |
|
|
|
sub(&t2, &t5, &t6) // t2 = t5 - t6 |
|
|
|
mul(&t1,&t2, &t1) // t1 = t2 * t1 |
|
|
|
add(&t2,&t3, &t1) // t2 = t3 + t1 |
|
|
|
sqr(&t2, &t2) // t2 = t2^2 |
|
|
|
mul(x,&t2, &t4) // X3p = t2 * t4 |
|
|
|
sub(&t1, &t3, &t1) // t1 = t3 - t1 |
|
|
|
sqr(&t1, &t1) // t1 = t1^2 |
|
|
|
mul(z,&t1, &t0) // Z3p = t1 * t0 |
|
|
|
pp.SubFp2(&t0, x, z) // t0 = Xp - Zp |
|
|
|
pp.SquareFp2(&t2, &t0) // t2 = t0^2 |
|
|
|
pp.AddFp2(&t1,x, z) // t1 = Xp + Zp |
|
|
|
pp.SquareFp2(&t3, &t1) // t3 = t1^2 |
|
|
|
pp.AddFp2(&t4,&t1, &t0) // t4 = t1 + t0 |
|
|
|
pp.SubFp2(&t0, &t1, &t0) // t0 = t1 - t0 |
|
|
|
pp.SquareFp2(&t1, &t4) // t1 = t4^2 |
|
|
|
pp.SubFp2(&t1, &t1, &t3) // t1 = t1 - t3 |
|
|
|
pp.SubFp2(&t1, &t1, &t2) // t1 = t1 - t2 |
|
|
|
pp.MulFp2(&t5,&t3, ¶ms.A) // t5 = t3 * A24+ |
|
|
|
pp.MulFp2(&t3,&t3, &t5) // t3 = t5 * t3 |
|
|
|
pp.MulFp2(&t6,&t2, ¶ms.C) // t6 = t2 * A24- |
|
|
|
pp.MulFp2(&t2,&t2, &t6) // t2 = t2 * t6 |
|
|
|
pp.SubFp2(&t3, &t2, &t3) // t3 = t2 - t3 |
|
|
|
pp.SubFp2(&t2, &t5, &t6) // t2 = t5 - t6 |
|
|
|
pp.MulFp2(&t1,&t2, &t1) // t1 = t2 * t1 |
|
|
|
pp.AddFp2(&t2,&t3, &t1) // t2 = t3 + t1 |
|
|
|
pp.SquareFp2(&t2, &t2) // t2 = t2^2 |
|
|
|
pp.MulFp2(x,&t2, &t4) // X3p = t2 * t4 |
|
|
|
pp.SubFp2(&t1, &t3, &t1) // t1 = t3 - t1 |
|
|
|
pp.SquareFp2(&t1, &t1) // t1 = t1^2 |
|
|
|
pp.MulFp2(z,&t1, &t0) // Z3p = t1 * t0 |
|
|
|
} |
|
|
|
return x3P |
|
|
|
} |
|
|
|