X-Git-Url: http://www.git.cypherpunks.ru/?p=gogost.git;a=blobdiff_plain;f=gost3410%2Fedwards.go;h=9cefec6e6fa013671b74d4905aeb3c8753af536c;hp=43484e061cdabd583ef2b296ae70f4dc521bbd0c;hb=7bed9561c7c09958ad1268b397058431fd3362bc;hpb=220aa87670f1b7ed258374c7ec84a9d9463c7a94 diff --git a/gost3410/edwards.go b/gost3410/edwards.go index 43484e0..9cefec6 100644 --- a/gost3410/edwards.go +++ b/gost3410/edwards.go @@ -31,62 +31,65 @@ func (c *Curve) EdwardsST() (*big.Int, *big.Int) { c.edS.Set(c.E) c.edS.Sub(c.edS, c.D) c.pos(c.edS) - c.t.SetUint64(4) - c.t.ModInverse(c.t, c.P) - c.edS.Mul(c.edS, c.t) + var t big.Int + t.SetUint64(4) + t.ModInverse(&t, c.P) + c.edS.Mul(c.edS, &t) c.edS.Mod(c.edS, c.P) c.edT = big.NewInt(0) c.edT.Set(c.E) c.edT.Add(c.edT, c.D) - c.t.SetUint64(6) - c.t.ModInverse(c.t, c.P) - c.edT.Mul(c.edT, c.t) + t.SetUint64(6) + t.ModInverse(&t, c.P) + c.edT.Mul(c.edT, &t) c.edT.Mod(c.edT, c.P) return c.edS, c.edT } // Convert Weierstrass X,Y coordinates to twisted Edwards U,V -func XY2UV(curve *Curve, x, y *big.Int) (*big.Int, *big.Int) { - if !curve.IsEdwards() { +func XY2UV(c *Curve, x, y *big.Int) (*big.Int, *big.Int) { + if !c.IsEdwards() { panic("non twisted Edwards curve") } - edS, edT := curve.EdwardsST() - curve.t.Sub(x, edT) - curve.pos(curve.t) + edS, edT := c.EdwardsST() + var t big.Int + t.Sub(x, edT) + c.pos(&t) u := big.NewInt(0) - u.ModInverse(y, curve.P) - u.Mul(u, curve.t) - u.Mod(u, curve.P) - v := big.NewInt(0).Set(curve.t) + u.ModInverse(y, c.P) + u.Mul(u, &t) + u.Mod(u, c.P) + v := big.NewInt(0).Set(&t) v.Sub(v, edS) - curve.pos(v) - curve.t.Add(curve.t, edS) - curve.t.ModInverse(curve.t, curve.P) - v.Mul(v, curve.t) - v.Mod(v, curve.P) + c.pos(v) + t.Add(&t, edS) + t.ModInverse(&t, c.P) + v.Mul(v, &t) + v.Mod(v, c.P) return u, v } // Convert twisted Edwards U,V coordinates to Weierstrass X,Y -func UV2XY(curve *Curve, u, v *big.Int) (*big.Int, *big.Int) { - if !curve.IsEdwards() { +func UV2XY(c *Curve, u, v *big.Int) (*big.Int, *big.Int) { + if !c.IsEdwards() { panic("non twisted Edwards curve") } - edS, edT := curve.EdwardsST() - curve.tx.Add(bigInt1, v) - curve.tx.Mul(curve.tx, edS) - curve.tx.Mod(curve.tx, curve.P) - curve.ty.Sub(bigInt1, v) - curve.pos(curve.ty) + edS, edT := c.EdwardsST() + var tx, ty big.Int + tx.Add(bigInt1, v) + tx.Mul(&tx, edS) + tx.Mod(&tx, c.P) + ty.Sub(bigInt1, v) + c.pos(&ty) x := big.NewInt(0) - x.ModInverse(curve.ty, curve.P) - x.Mul(x, curve.tx) + x.ModInverse(&ty, c.P) + x.Mul(x, &tx) x.Add(x, edT) - x.Mod(x, curve.P) + x.Mod(x, c.P) y := big.NewInt(0) - y.Mul(u, curve.ty) - y.ModInverse(y, curve.P) - y.Mul(y, curve.tx) - y.Mod(y, curve.P) + y.Mul(u, &ty) + y.ModInverse(y, c.P) + y.Mul(y, &tx) + y.Mod(y, c.P) return x, y }