doubleJacobian takes a point in Jacobian coordinates, (x, y, z), and returns its double, also in Jacobian form.
(x, y, z *big.Int)
| 208 | // doubleJacobian takes a point in Jacobian coordinates, (x, y, z), and |
| 209 | // returns its double, also in Jacobian form. |
| 210 | func (BitCurve *BitCurve) doubleJacobian(x, y, z *big.Int) (*big.Int, *big.Int, *big.Int) { |
| 211 | // See http://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#doubling-dbl-2009-l |
| 212 | |
| 213 | a := new(big.Int).Mul(x, x) //X1² |
| 214 | b := new(big.Int).Mul(y, y) //Y1² |
| 215 | c := new(big.Int).Mul(b, b) //B² |
| 216 | |
| 217 | d := new(big.Int).Add(x, b) //X1+B |
| 218 | d.Mul(d, d) //(X1+B)² |
| 219 | d.Sub(d, a) //(X1+B)²-A |
| 220 | d.Sub(d, c) //(X1+B)²-A-C |
| 221 | d.Mul(d, big.NewInt(2)) //2*((X1+B)²-A-C) |
| 222 | |
| 223 | e := new(big.Int).Mul(big.NewInt(3), a) //3*A |
| 224 | f := new(big.Int).Mul(e, e) //E² |
| 225 | |
| 226 | x3 := new(big.Int).Mul(big.NewInt(2), d) //2*D |
| 227 | x3.Sub(f, x3) //F-2*D |
| 228 | x3.Mod(x3, BitCurve.P) |
| 229 | |
| 230 | y3 := new(big.Int).Sub(d, x3) //D-X3 |
| 231 | y3.Mul(e, y3) //E*(D-X3) |
| 232 | y3.Sub(y3, new(big.Int).Mul(big.NewInt(8), c)) //E*(D-X3)-8*C |
| 233 | y3.Mod(y3, BitCurve.P) |
| 234 | |
| 235 | z3 := new(big.Int).Mul(y, z) //Y1*Z1 |
| 236 | z3.Mul(big.NewInt(2), z3) //3*Y1*Z1 |
| 237 | z3.Mod(z3, BitCurve.P) |
| 238 | |
| 239 | return x3, y3, z3 |
| 240 | } |
| 241 | |
| 242 | // ScalarMult does the private scalar. |
| 243 | func (BitCurve *BitCurve) ScalarMult(Bx, By *big.Int, scalar []byte) (*big.Int, *big.Int) { |