def unpack(T, Qx, Qy): aa, bb = T.get() aa = aa.muls(Qy) a = Fp4(aa, bb) t = Fp2(Qx) if curve.SexticTwist == D_TYPE: b = Fp4(t) c = Fp4() else: b = Fp4() c = Fp4(t).times_i() return Fp12(a, b, c)
def __init__(self, a=None, b=None, c=None): if b is None: if a is None: self.a = Fp4() self.b = Fp4() self.c = Fp4() else: self.a = a.copy() self.b = Fp4() self.c = Fp4() else: self.a = a.copy() self.b = b.copy() self.c = c.copy()
def fromBytes(self, E): FS = curve.EFS a = Fp4(Fp2(Fp(big.from_bytes(E[0:FS])), Fp(big.from_bytes(E[FS:2 * FS]))), Fp2(Fp(big.from_bytes(E[2 * FS:3 * FS])), Fp(big.from_bytes(E[3 * FS:4 * FS])))) b = Fp4(Fp2(Fp(big.from_bytes(E[4 * FS:5 * FS])), Fp(big.from_bytes(E[5 * FS:6 * FS]))), Fp2(Fp(big.from_bytes(E[6 * FS:7 * FS])), Fp(big.from_bytes(E[7 * FS:8 * FS])))) c = Fp4(Fp2(Fp(big.from_bytes(E[8 * FS:9 * FS])), Fp(big.from_bytes(E[9 * FS:10 * FS]))), Fp2(Fp(big.from_bytes(E[10 * FS:11 * FS])), Fp(big.from_bytes(E[11 * FS:12 * FS])))) self.set(a, b, c)
def rand(self): # mutable r = Fp4() r.rand() self.a = r.copy() r.rand() self.b = r.copy() r.rand() self.c = r.copy() return self
def g(A, B, Qx, Qy): if A == B: AA, BB, CC = dbl(A) else: AA, BB, CC = add(A, B) CC = CC.muls(Qx) AA = AA.muls(Qy) a = Fp4(AA, BB) if curve.SexticTwist == D_TYPE: b = Fp4(CC) c = Fp4() else: b = Fp4() c = Fp4(CC).times_i() return Fp12(a, b, c)
def smul(self,other) : if curve.SexticTwist == D_TYPE : w1=self.a.a*other.a.a w2=self.a.b*other.a.b w3=self.b.a*other.b.a ta=self.a.a+self.a.b tb=other.a.a+other.a.b tc=ta*tb tc-=(w1+w2) ta=self.a.a+self.b.a tb=other.a.a+other.b.a td=ta*tb td-=(w1+w3) ta=self.a.b+self.b.a tb=other.a.b+other.b.a te=ta*tb te-=(w2+w3) w1+=w2.mulQNR() self.a=Fp4(w1,tc) self.b=Fp4(td,te) self.c=Fp4(w3) else : w1=self.a.a*other.a.a w2=self.a.b*other.a.b w3=self.c.b*other.c.b ta=self.a.a+self.a.b tb=other.a.a+other.a.b tc=ta*tb tc-=(w1+w2) ta=self.a.a+self.c.b tb=other.a.a+other.c.b td=ta*tb td-=(w1+w3) ta=self.a.b+self.c.b tb=other.a.b+other.c.b te=ta*tb te-=(w2+w3) w1+=w2.mulQNR() self.a=Fp4(w1,tc) self.b=Fp4(w3.mulQNR()) self.b.times_i() self.c=Fp4(te.mulQNR(),td) return self
def zero(): return Fp12(Fp4(Fp2(Fp(0))))
def one(): return Fp12(Fp4(Fp2(Fp(1))))
def pack(AA, BB, CC): i = CC.inverse() return Fp4(AA * i, BB * i)