def server(ID, Y, SS, U, V): P = H(ID) y = big.from_bytes(Y) Q = ecp2.generator() P = y * P sQ = ECp2() if not sQ.fromBytes(SS): return (False, Fp12(), Fp12()) TU = ECp() if not TU.fromBytes(U): return (False, bytearray(0), bytearray(0)) TV = ECp() if not TV.fromBytes(V): return (False, bytearray(0), bytearray(0)) TU.add(P) # TU.affine() r = pair.double_ate(Q, TV, sQ, TU) r = pair.fexp(r) if r.isone(): return (True, bytearray(0), bytearray(0)) # failed - diagnose it E = r.toBytes() r = pair.e(Q, TU) F = r.toBytes() return (False, E, F)
def extract_pin(ID, PIN, SK): P = H(ID) P = -(PIN * P) S = ECp() if not S.fromBytes(SK): return bytearray(0) S.add(P) # S.affine() return S.toBytes(False)
def add_G1(A, B): """ Add two points in G1: C = A + B """ A1 = ECp() B1 = ECp() if not A1.fromBytes(A): return None if not B1.fromBytes(B): return None A1.add(B1) return A1.toBytes(False)
def client_2(X, Y, ID, PIN, TK): P = H(ID) S = ECp() if not S.fromBytes(TK): return bytearray(0) x = big.from_bytes(X) y = big.from_bytes(Y) x = (x + y) % curve.r x = curve.r - x S.add(PIN * P) S = x * S return S.toBytes(False)