Exemplo n.º 1
0
    def testWeilPairing(self):
        # this example was refered to Washington.
        e = elliptic.EC([0, 2], 7)
        P = [5, 1]
        Q = [0, 3]
        R = e.WeilPairing(3, P, Q)
        self.assertEqual(finitefield.FinitePrimeFieldElement(2, 7), R)

        # test case of extension field, characteristic 7
        p = 7
        r = 11
        F = finitefield.FinitePrimeField(p)
        PX = uniutil.polynomial({0:3,1:3,2:2,3:1,4:4,5:1,6:1,10:1},F)
        Fx = finitefield.FiniteExtendedField(p,PX)

        E = elliptic.EC([F.one,-F.one],F)
        Ex = elliptic.EC([Fx.one,-Fx.one],Fx)

        P = [3,6]
        assert E.whetherOn(P)
        assert Ex.whetherOn(P)
        assert E.mul(11,P) == E.infpoint
        Qxcoord = Fx.createElement(6*7**9+7**8+7**6+6*7**3+6*7**2+7+6)
        Qycoord = Fx.createElement(3*7**9+6*7**8+4*7**7+2*7**6+5*7**4+5*7**3+7**2+7+3)
        Q = [Qxcoord,Qycoord]
        assert Ex.whetherOn(Q)
        assert Ex.mul(11,Q) == Ex.infpoint

        w = Ex.WeilPairing(11, P, Q)
        Wp = Fx.createElement(7**9 + 5*7**8 + 4*7**7 + 2*7**5 + 7**4 + 6*7**2)
        assert w == Wp
Exemplo n.º 2
0
def u_FiniteField(char, modulus=None):
    """ Create FiniteField from modulus.
    modulus must be a form of PolynomialoverFp.
    """
    if type(modulus) is list:
        # FIXME: Undefined variable 'FpPolynomial'
        poly_Fp = FpPolynomial(char, modulus)
        return u_finitefield.FiniteExtendedField(char, poly_Fp)
    if type(modulus) is u_finitefield.FinitePrimeFieldPolynomial:
        return u_finitefield.FiniteExtendedField(char, modulus)
    elif not modulus:
        return u_finitefield.FinitePrimeField(char)
Exemplo n.º 3
0
def u_FpPolynomial(char, coeffs):
    """ Create FinitePrimeFieldPolynomial from coeffs with mapping
     FinitePrimeField(char).createElement.
    """
    field = u_finitefield.FinitePrimeField(char)
    if type(coeffs) is dict:
        return u_finitefield.FinitePrimeFieldPolynomial(coeffs, field)
    if isinstance(coeffs, list):
        coefficients = []
        for index in range(len(coeffs)):
            coefficients.append([index, coeffs[index]])
        return u_finitefield.FinitePrimeFieldPolynomial(coefficients, field)
Exemplo n.º 4
0
 def testWeilPairingIsFunction(self):
     # e2 is isomorphic to Z/256 x Z/256
     F_65537 = finitefield.FinitePrimeField(65537)
     e2 = elliptic.EC([-1, 0], F_65537)
     P1 = list(map(F_65537.createElement, [30840, 53250]))
     self.assertFalse(256 % e2.pointorder(P1))
     P2 = list(map(F_65537.createElement, [10657, 46245]))
     self.assertFalse(256 % e2.pointorder(P2))
     weil10 = set(e2.WeilPairing(256, P1, P2) for i in range(10))
     # since Weil pairing is a function, the result is always same
     self.assertEqual(1, len(weil10))
     # Weil pairing is a function E[m]xE[m] -> mu_m
     self.assertEqual(e2.basefield.one, weil10.pop()**256)