github.com/cloudflare/circl@v1.5.0/ecc/goldilocks/isogeny.go (about)

     1  package goldilocks
     2  
     3  import fp "github.com/cloudflare/circl/math/fp448"
     4  
     5  func (Curve) pull(P *twistPoint) *Point      { return twistCurve{}.push(P) }
     6  func (twistCurve) pull(P *Point) *twistPoint { return Curve{}.push(P) }
     7  
     8  // push sends a point on the Goldilocks curve to a point on the twist curve.
     9  func (Curve) push(P *Point) *twistPoint {
    10  	Q := &twistPoint{}
    11  	Px, Py, Pz := &P.x, &P.y, &P.z
    12  	a, b, c, d, e, f, g, h := &Q.x, &Q.y, &Q.z, &fp.Elt{}, &Q.ta, &Q.x, &Q.y, &Q.tb
    13  	fp.Add(e, Px, Py)  // x+y
    14  	fp.Sqr(a, Px)      // A = x^2
    15  	fp.Sqr(b, Py)      // B = y^2
    16  	fp.Sqr(c, Pz)      // z^2
    17  	fp.Add(c, c, c)    // C = 2*z^2
    18  	*d = *a            // D = A
    19  	fp.Sqr(e, e)       // (x+y)^2
    20  	fp.Sub(e, e, a)    // (x+y)^2-A
    21  	fp.Sub(e, e, b)    // E = (x+y)^2-A-B
    22  	fp.Add(h, b, d)    // H = B+D
    23  	fp.Sub(g, b, d)    // G = B-D
    24  	fp.Sub(f, c, h)    // F = C-H
    25  	fp.Mul(&Q.z, f, g) // Z = F * G
    26  	fp.Mul(&Q.x, e, f) // X = E * F
    27  	fp.Mul(&Q.y, g, h) // Y = G * H, // T = E * H
    28  	return Q
    29  }
    30  
    31  // push sends a point on the twist curve to a point on the Goldilocks curve.
    32  func (twistCurve) push(P *twistPoint) *Point {
    33  	Q := &Point{}
    34  	Px, Py, Pz := &P.x, &P.y, &P.z
    35  	a, b, c, d, e, f, g, h := &Q.x, &Q.y, &Q.z, &fp.Elt{}, &Q.ta, &Q.x, &Q.y, &Q.tb
    36  	fp.Add(e, Px, Py)  // x+y
    37  	fp.Sqr(a, Px)      // A = x^2
    38  	fp.Sqr(b, Py)      // B = y^2
    39  	fp.Sqr(c, Pz)      // z^2
    40  	fp.Add(c, c, c)    // C = 2*z^2
    41  	fp.Neg(d, a)       // D = -A
    42  	fp.Sqr(e, e)       // (x+y)^2
    43  	fp.Sub(e, e, a)    // (x+y)^2-A
    44  	fp.Sub(e, e, b)    // E = (x+y)^2-A-B
    45  	fp.Add(h, b, d)    // H = B+D
    46  	fp.Sub(g, b, d)    // G = B-D
    47  	fp.Sub(f, c, h)    // F = C-H
    48  	fp.Mul(&Q.z, f, g) // Z = F * G
    49  	fp.Mul(&Q.x, e, f) // X = E * F
    50  	fp.Mul(&Q.y, g, h) // Y = G * H, // T = E * H
    51  	return Q
    52  }