def Weil_2(P, Q, R, S, r): zz = P.ec.field pl = poly(zz) mil = millersF(P.ec, pl) f_QS = mil.mfunc(P, r, Q + S) * ((mil.line(P, R)[Q + S] * mil.vertical(P + R)[Q + S]) ** (-r)) f_S = mil.mfunc(P, r, S) * ((mil.line(P, R)[S] * mil.vertical(P + R)[S]) ** (-r)) g_R = mil.mfunc(Q, r, R) * ((mil.line(Q, S)[R] * mil.vertical(Q + S)[R]) ** (-r)) g_PR = mil.mfunc(Q, r, P + R) * ((mil.line(Q, S)[P + R] * mil.vertical(Q + S)[P + R]) ** (-r)) pairing = f_QS * g_R / (f_S * g_PR) return pairing
def Weil_1(P, Q, R, S, r): zz = P.ec.field pl = poly(zz) mil = millersF(P.ec, pl) fp = mil.mfunc_slow(P, r) fq = mil.mfunc_slow(Q, r) f = fp * (mil.line(P, R) * mil.vertical(P + R)) ** (-r) g = fq * (mil.line(Q, S) * mil.vertical(Q + S)) ** (-r) pairing = f[Q + S] * g[R] / (f[S] * g[P + R]) return pairing
def Weil(P, Q, R, S, r): zz = ec.field pl = poly(zz) mil = millersF(P.ec, pl) fp = mil.mfunc_slow(P, r) fq = mil.mfunc_slow(Q, r) f = fp * (mil.line(P, R) * mil.vertical(P + R))**(-r) g = fq * (mil.line(Q, S) * mil.vertical(Q + S))**(-r) pairing = f.apply(Q + S) * g.apply(R) / (f.apply(S) * g.apply(P + R)) return pairing
from ecs import * from finField import finField from millersF import millersF from pairings import Weil_1, Weil_2 from poly2 import poly from tortion import tortion ec = beginners5_3_1() zzz = ec.field p = poly(zzz) ff = finField(p.of([zzz.of(1), zzz.of(0), zzz.of(zzz.N - 4), zzz.of(0), zzz.of(5)])) P = ec.of(zzz.of(45), zzz.of(23)) qx = p.of([zzz.of(31), zzz.of(0), zzz.of(29)]) qy = p.of([zzz.of(35), zzz.of(0), zzz.of(11), zzz.of(0)]) # Q = tor_points[6] Q = ec.of(ff.of(qx), ff.of(qy)) it = ec.all() it.__next__() R = it.__next__() S = it.__next__() # R = ec.of(zzz.of(0), zzz.of(11)) # S = ec.of(zzz.of(0), zzz.of(12)) r = 17 print(tortion.k(r, zzz.N))
from matrix import matrix from zzn import zzn from finField import finField from poly2 import poly Bit = zzn(2) bitPoly = poly(Bit) GF256 = finField(bitPoly.irredusable(8).__next__()) p = poly(GF256) # convert int to field element def f(x): l = [] while (x != 0): (x, b) = divmod(x, 2) if b: l.append(Bit.one) else: l.append(Bit.zero) if not l: l.append(Bit.zero) l.reverse() return GF256.of(bitPoly.of(l)) k = 2 n = 6 e = (n - k) // 2 a = [f(1), f(2), f(3), f(4), f(5), f(6)]
def poly(self): p = poly(self.field) return p.of([self.field.one, self.field.zero, self.a, self.b])