Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

garaga-rs / wasm - Implement Twisted Edwards to Weirstrass bijection for point representation #190

Open
feltroidprime opened this issue Sep 10, 2024 · 0 comments
Assignees

Comments

@feltroidprime
Copy link
Collaborator

feltroidprime commented Sep 10, 2024

Using the reference formulas in

def to_weierstrass(self, x_twisted, y_twisted):
a = self.a_twisted
d = self.d_twisted
return (
(5 * a + a * y_twisted - 5 * d * y_twisted - d)
* pow(12 - 12 * y_twisted, -1, self.p)
% self.p,
(a + a * y_twisted - d * y_twisted - d)
* pow(4 * x_twisted - 4 * x_twisted * y_twisted, -1, self.p)
% self.p,
)
def to_twistededwards(self, x_weirstrass: int, y_weirstrass: int):
a = self.a_twisted
d = self.d_twisted
y = (
(5 * a - 12 * x_weirstrass - d)
* pow(-12 * x_weirstrass - a + 5 * d, -1, self.p)
% self.p
)
x = (
(a + a * y - d * y - d)
* pow(4 * y_weirstrass - 4 * y_weirstrass * y, -1, self.p)
% self.p
)
return (x, y)

implement in tools/garaga-rs/definitions.rs the two conversion function

  • to_weirstrass(x:X25519PrimeField, y: X25519PrimeField)- > (X25519PrimeField, X25519PrimeField)
  • to_twisted(x:X25519PrimeField, y:X25519PrimeField) -> (X25519PrimeField, X25519PrimeField)

Test them simply similarly to

def test_weierstrass_to_twistededwards_and_back(curve_id):
curve: TwistedEdwardsCurve = CURVES[curve_id.value]
# Define a point in Weierstrass form
x_weierstrass = curve.Gx
y_weierstrass = curve.Gy
x_twisted, y_twisted = curve.to_twistededwards(x_weierstrass, y_weierstrass)
x_weierstrass_back, y_weierstrass_back = curve.to_weierstrass(x_twisted, y_twisted)
assert x_weierstrass == x_weierstrass_back
assert y_weierstrass == y_weierstrass_back
using the generator point Gx, Gy.

Then, create a wasm binding for it and add it to the npm package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants