Skip to content

Instantly share code, notes, and snippets.

@tarcieri
Last active December 12, 2015 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarcieri/40d2eb8e4e8f9ed28b3a to your computer and use it in GitHub Desktop.
Save tarcieri/40d2eb8e4e8f9ed28b3a to your computer and use it in GitHub Desktop.
Semiprivate keys in SAGE (via DCoder)
# curve25519 operats on F[2^255-19] so it's not actually a 2^256 value
import hashlib
p = 2^255 - 19;
E = EllipticCurve(GF(p), [0,486662,0,1,0]);
P = E.lift_x(9);
l = P.order();
x = ZZ.random_element(l);
S = x*P;
y = int(hashlib.sha512(str(S)).hexdigest(), 16) % l;
z = x*y % l;
R = y*S;
assert(R == z*P)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment