mirror of
https://github.com/cheat/cheat.git
synced 2024-11-18 01:40:39 +01:00
80c91cbdee
Integrate `go-git` into the application, and use it to `git clone` cheatsheets when the installer runs. Previously, the installer required that `git` be installed on the system `PATH`, so this change has to big advantages: 1. It removes that system dependency on `git` 2. It paves the way for implementing the `--update` command Additionally, `cheat` now performs a `--depth=1` clone when installing cheatsheets, which should at least somewhat improve installation times (especially on slow network connections).
52 lines
1.7 KiB
Go
52 lines
1.7 KiB
Go
package goldilocks
|
|
|
|
import fp "github.com/cloudflare/circl/math/fp448"
|
|
|
|
func (Curve) pull(P *twistPoint) *Point { return twistCurve{}.push(P) }
|
|
func (twistCurve) pull(P *Point) *twistPoint { return Curve{}.push(P) }
|
|
|
|
// push sends a point on the Goldilocks curve to a point on the twist curve.
|
|
func (Curve) push(P *Point) *twistPoint {
|
|
Q := &twistPoint{}
|
|
Px, Py, Pz := &P.x, &P.y, &P.z
|
|
a, b, c, d, e, f, g, h := &Q.x, &Q.y, &Q.z, &fp.Elt{}, &Q.ta, &Q.x, &Q.y, &Q.tb
|
|
fp.Add(e, Px, Py) // x+y
|
|
fp.Sqr(a, Px) // A = x^2
|
|
fp.Sqr(b, Py) // B = y^2
|
|
fp.Sqr(c, Pz) // z^2
|
|
fp.Add(c, c, c) // C = 2*z^2
|
|
*d = *a // D = A
|
|
fp.Sqr(e, e) // (x+y)^2
|
|
fp.Sub(e, e, a) // (x+y)^2-A
|
|
fp.Sub(e, e, b) // E = (x+y)^2-A-B
|
|
fp.Add(h, b, d) // H = B+D
|
|
fp.Sub(g, b, d) // G = B-D
|
|
fp.Sub(f, c, h) // F = C-H
|
|
fp.Mul(&Q.z, f, g) // Z = F * G
|
|
fp.Mul(&Q.x, e, f) // X = E * F
|
|
fp.Mul(&Q.y, g, h) // Y = G * H, // T = E * H
|
|
return Q
|
|
}
|
|
|
|
// push sends a point on the twist curve to a point on the Goldilocks curve.
|
|
func (twistCurve) push(P *twistPoint) *Point {
|
|
Q := &Point{}
|
|
Px, Py, Pz := &P.x, &P.y, &P.z
|
|
a, b, c, d, e, f, g, h := &Q.x, &Q.y, &Q.z, &fp.Elt{}, &Q.ta, &Q.x, &Q.y, &Q.tb
|
|
fp.Add(e, Px, Py) // x+y
|
|
fp.Sqr(a, Px) // A = x^2
|
|
fp.Sqr(b, Py) // B = y^2
|
|
fp.Sqr(c, Pz) // z^2
|
|
fp.Add(c, c, c) // C = 2*z^2
|
|
fp.Neg(d, a) // D = -A
|
|
fp.Sqr(e, e) // (x+y)^2
|
|
fp.Sub(e, e, a) // (x+y)^2-A
|
|
fp.Sub(e, e, b) // E = (x+y)^2-A-B
|
|
fp.Add(h, b, d) // H = B+D
|
|
fp.Sub(g, b, d) // G = B-D
|
|
fp.Sub(f, c, h) // F = C-H
|
|
fp.Mul(&Q.z, f, g) // Z = F * G
|
|
fp.Mul(&Q.x, e, f) // X = E * F
|
|
fp.Mul(&Q.y, g, h) // Y = G * H, // T = E * H
|
|
return Q
|
|
}
|