def run_tests(): import random from curve_ops import psi for _ in range(0, 128): t1 = Fq2(p, random.getrandbits(380), random.getrandbits(380)) t2 = Fq2(p, random.getrandbits(380), random.getrandbits(380)) # make sure each helper function actually returns a point on the curve for t in (t1, t2): P = osswu2_help(t) Pp = from_jacobian(P) assert Pp[0]**3 + Ell2p_a * Pp[0] + Ell2p_b == Pp[1]**2 P = iso3(P) Pp = from_jacobian(P) assert Pp[0]**3 + Fq2(p, 4, 4) == Pp[1]**2 P = psi(P) Pp = from_jacobian(P) assert Pp[0]**3 + Fq2(p, 4, 4) == Pp[1]**2 P = clear_h2(P) Pp = from_jacobian(P) assert Pp[0]**3 + Fq2(p, 4, 4) == Pp[1]**2 # now test end-to-end P = opt_swu2_map(t1, t2) Pp = from_jacobian(P) assert Pp[0]**3 + Fq2(p, 4, 4) == Pp[1]**2 sys.stdout.write('.') sys.stdout.flush() sys.stdout.write("\n")
def opt_swu2_map(t, t2=None): Pp = osswu2_help(t) if t2 is not None: Pp2 = osswu2_help(t2) Pp = point_add(Pp, Pp2) P = iso3(Pp) return clear_h2(P)