Ejemplo n.º 1
0
// Given a y-coordinate, solve for the x-coordinate on the curve,
// using the characteristic equation rewritten as:
//
//	x^2 = (1 - y^2)/(a - d*y^2)
//
// Returns true on success,
// false if there is no x-coordinate corresponding to the chosen y-coordinate.
//
func (c *curve) solveForX(x, y *nist.Int) bool {
	var yy, t1, t2 nist.Int

	yy.Mul(y, y)                     // yy = y^2
	t1.Sub(&c.one, &yy)              // t1 = 1 - y^-2
	t2.Mul(&c.d, &yy).Sub(&c.a, &t2) // t2 = a - d*y^2
	t2.Div(&t1, &t2)                 // t2 = x^2
	return x.Sqrt(&t2)               // may fail if not a square
}