def decrypt(self, pk, sk_s, SK, CT, Delta):
        H = Hash(group)
        T1 = T2 = T3 = T4 = D = R = 1
        X = pair(SK["D"], SK["D_hat"])**sk_s
        X = H.hashToZr(X)
        X = SK["g_hat"]**X
        for name in Delta:
            tmp1 = SK[name]["T1"]
            tmp2 = SK[name]["T2"]
            tmp3 = SK[name]["T3"]
            tmp4 = SK[name]["T4"]

            T = Delta.copy()
            T.remove(name)
            for item in T:
                tmp1 *= SK[name]["Q"][item]["Q1"]
                tmp2 *= SK[name]["Q"][item]["Q2"]
                tmp3 *= SK[name]["Q"][item]["Q3"]
                tmp4 *= SK[name]["Q"][item]["Q4"]

            T1 *= tmp1
            T2 *= tmp2
            T3 *= tmp3
            T4 *= tmp4
            D *= SK[name]["D"]
            R *= (SK[name]["R"] / X)
            #R *= (SK[name]["R"])

        Y = pair(CT["C1"], D) * pair(CT["C2"], R) * pair(CT["E1"], T1) * pair(
            CT["E2"], T2) * pair(CT["E3"], T3) * pair(CT["E4"], T4)
        #return Y == (pk["Omega"] ** CT["mu"])
        return CT["C"] == Y
    def encrypt(self, pk, Keyword):
        H = Hash(group)
        mu, s, s1, s2 = group.random(), group.random(), group.random(
        ), group.random()

        C = pk["Omega"]**mu
        C1 = pk["g"]**mu
        C2 = (pk["h"])
        for name, value in Keyword.items():
            C2 *= (pk["u"]**H.hashToZr(name + value))
        C2 = C2**s
        C2 *= pk["delta"]**-mu
        E1 = pk["g1"]**(s - s1)
        E2 = pk["g2"]**s1
        E3 = pk["g3"]**(s - s2)
        E4 = pk["g4"]**s2

        return {
            "C": C,
            "C1": C1,
            "C2": C2,
            "E1": E1,
            "E2": E2,
            "E3": E3,
            "E4": E4,
            "mu": mu
        }
    def keygen(self, msk, pk_s, Pol, Pol_M):
        H = Hash(group)
        SK = dict()
        s, y2, y3 = msk["alpha"], group.random(), group.random()
        r, r_prime = group.random(), group.random()

        D = msk["g"]**r
        D_hat = msk["g_hat"]**r_prime
        SK["D"] = D
        SK["D_hat"] = D_hat

        X = pair(pk_s, D_hat)**r
        X = H.hashToZr(X)

        for name, row in Pol_M.items():
            lamb = row[0] * s + row[1] * y2 + row[2] * y3
            t1, t2 = group.random(), group.random()
            d1 = msk["d1"]
            d2 = msk["d2"]
            d3 = msk["d3"]
            d4 = msk["d4"]

            t = d1 * d2 * t1 + d3 * d4 * t2
            h = H.hashToZr(name + Pol[name])
            Y = (msk["u_hat"]**h) * msk["h_hat"]

            D = (msk["g_hat"]**lamb) * (msk["delta_hat"]**t)
            R = msk["g_hat"]**(t + X)
            #R = msk["g_hat"]** t
            T1 = Y**(-d2 * t1)
            T2 = Y**(-d1 * t1)
            T3 = Y**(-d4 * t2)
            T4 = Y**(-d3 * t2)

            Q = dict()
            tmp = Pol.copy()
            del tmp[name]
            for Q_name, Q_value in tmp.items():
                hQ = H.hashToZr(Q_name + Q_value)
                Q_tmp = msk["u_hat"]**(-hQ)
                Q[Q_name] = {
                    "Q1": Q_tmp**(d2 * t1),
                    "Q2": Q_tmp**(d1 * t1),
                    "Q3": Q_tmp**(d4 * t2),
                    "Q4": Q_tmp**(d3 * t2)
                }

            SK[name] = {
                "D": D,
                "R": R,
                "T1": T1,
                "T2": T2,
                "T3": T3,
                "T4": T4,
                "Q": Q
            }
            SK["g_hat"] = msk["g_hat"]

        return SK
    def keygen(self, msk, Pol):
        H = Hash(group)
        SK = dict()

        tau1 = msk["tau1"]
        tau2 = msk["tau2"]
        tau3 = msk["tau3"]
        tau4 = msk["tau4"]
        '''
        The access structure is fixed for "NSYSU" AND ( ("CSE" AND "Mas") OR "Teacher" ). This implementation is only for efficiency test.
        Label: Root -> 0, NSYSU -> 1, OR GATE -> 2, AND GATE -> 3, Teacher -> 4, CSE -> 5, Mas -> 6
        '''
        leaf = ["NSYSU", "Teacher", "CSE", "Mas"]
        #q0(x) = alpha + q0*x
        q0 = group.random()
        #q1 = q0(1)
        q1 = msk["alpha"] + q0
        #q2 = q0(2)
        q4 = q2 = msk["alpha"] + q0 * 2
        #q3(x) = q2(3) + q3*x = q2 + q3*x
        q3 = group.random()
        #q4 = q2(4) = q0(2)
        #q5 = q3(5)
        q5 = q2 + q3 * 5
        #q6 = q3(6)
        q6 = q2 + q3 * 6
        q = dict()
        q["NSYSU"] = q1
        q["CSE"] = q5
        q["Mas"] = q6
        q["Teacher"] = q4

        for name, value in Pol.items():
            t1, t2 = group.random(), group.random()

            t = tau1 * tau2 * t1 + tau3 * tau4 * t2
            h = H.hashToZr(name + value)
            Y = (msk["u_hat"]**h) * msk["h_hat"]

            D = (msk["g_hat"]**q[value]) * (msk["w_hat"]**t)
            D0 = msk["g_hat"]**t
            D1 = Y**(-tau2 * t1)
            D2 = Y**(-tau1 * t1)
            D3 = Y**(-tau4 * t2)
            D4 = Y**(-tau3 * t2)

            SK[name] = {
                "D": D,
                "D0": D0,
                "D1": D1,
                "D2": D2,
                "D3": D3,
                "D4": D4
            }
        #SK["q"] = q
        #SK["alpha"] = msk["alpha"]

        return SK
示例#5
0
    def encrypt(self, pk, M, Attribute):
        H = Hash(group)
        k = group.random()

        CT = dict()
        CT["C1"] = M * pk["V"]** k
        CT["C2"] = pk["U"] ** k
        CT["C3"] = pk["g1"] ** k

        for name, value in Attribute.items():
            r = H.hashToZr(name + value)
            CT[name] = (pk["h"] * pk["g1"] ** r)**k
        
        return CT
    def decrypt(self, pk, SK, CT, Delta):
        H = Hash(group)

        P_School = (pair(CT["E"], SK["School"]["D"]) *
                    pair(CT["School"]["E0"], SK["School"]["D0"]) *
                    pair(CT["School"]["E1"], SK["School"]["D1"]) *
                    pair(CT["School"]["E2"], SK["School"]["D2"]) *
                    pair(CT["School"]["E3"], SK["School"]["D3"]) *
                    pair(CT["School"]["E4"], SK["School"]["D4"]))
        P_Pos = (pair(CT["E"], SK["Pos"]["D"]) *
                 pair(CT["Pos"]["E0"], SK["Pos"]["D0"]) *
                 pair(CT["Pos"]["E1"], SK["Pos"]["D1"]) *
                 pair(CT["Pos"]["E2"], SK["Pos"]["D2"]) *
                 pair(CT["Pos"]["E3"], SK["Pos"]["D3"]) *
                 pair(CT["Pos"]["E4"], SK["Pos"]["D4"]))

        #s = CT["s"]
        #q = SK["q"]
        #alpha = SK["alpha"]
        #print(2* q["NSYSU"] - q["Teacher"] == alpha)
        #print( pk["omega"]**(q["NSYSU"]*s) == P_School)

        K = (P_School**2) * (P_Pos**(-1))

        M = CT["E_tilde"] / K

        return M
示例#7
0
    def keygen(self, msk, pk_s, Pol, Pol_M):
        H = Hash(group)
        SK = dict()
        s, y2, y3 = msk["alpha"], group.random(), group.random()
        r, r_prime = group.random(), group.random()
        d1 = msk["d1"]
        d2 = msk["d2"]
        d3 = msk["d3"]
        d4 = msk["d4"]

        T = msk["g"]**r
        T_hat = msk["g_hat"]**r_prime
        SK["T"] = T
        SK["T_hat"] = T_hat

        X = pair(pk_s, T_hat)**r
        X = H.hashToZr(X)

        for name, row in Pol_M.items():
            lamb = row[0] * s + row[1] * y2 + row[2] * y3
            t1, t2 = group.random(), group.random()

            t = d1 * d2 * t1 + d3 * d4 * t2
            h = H.hashToZr(name + Pol[name])
            Y = (msk["u_hat"]**h) * msk["h_hat"]

            T1 = (msk["g_hat"]**lamb) * (msk["w_hat"]**t)
            T2 = msk["g_hat"]**(t + X)
            #T2 = msk["g_hat"]** t
            T3 = Y**(-d2 * t1)
            T4 = Y**(-d1 * t1)
            T5 = Y**(-d4 * t2)
            T6 = Y**(-d3 * t2)

            SK[name] = {
                "T1": T1,
                "T2": T2,
                "T3": T3,
                "T4": T4,
                "T5": T5,
                "T6": T6
            }
            SK["g_hat"] = msk["g_hat"]

        return SK
示例#8
0
    def decrypt(self, pk, sk_s, SK, CT, Delta):
        H = Hash(group)
        Y = 1
        X = pair(SK["T"], SK["T_hat"])**sk_s
        X = H.hashToZr(X)
        X = SK["g_hat"]**X

        #print(Delta)

        for name in Delta:
            Y *= pair(CT["D"], SK[name]["T1"])
            T2 = SK[name]["T2"] / X
            #T2 = SK[name]["T2"]
            Y *= pair(CT[name]["D"], T2)
            Y *= pair(CT[name]["E1"], SK[name]["T3"])
            Y *= pair(CT[name]["E2"], SK[name]["T4"])
            Y *= pair(CT[name]["F1"], SK[name]["T5"])
            Y *= pair(CT[name]["F2"], SK[name]["T6"])

        #return CT['C'] == (pk["Omega"] ** CT["mu"])
        return CT["C"] == Y
示例#9
0
    def encrypt(self, pk, Keyword):
        H = Hash(group)
        mu = group.random()

        CT = dict()
        C = pk["Omega"]**mu
        D = pk["g"]**mu
        CT["C"] = C
        CT["D"] = D

        for name, value in Keyword.items():
            z, s1, s2 = group.random(), group.random(), group.random()
            htemp = H.hashToZr(name + value)

            D = (pk["w"]**-mu) * (((pk["u"]**htemp) * pk["h"])**z)
            E1 = pk["g1"]**(z - s1)
            E2 = pk["g2"]**s1
            F1 = pk["g3"]**(z - s2)
            F2 = pk["g4"]**s2
            CT[name] = {"D": D, "E1": E1, "E2": E2, "F1": F1, "F2": F2}
        CT["mu"] = mu
        return CT
示例#10
0
    def encrypt(self, pk, Keyword, M):
        H = Hash(group)
        s = group.random()

        CT = dict()
        E_tilde = pk["Omega"]**s
        E_tilde *= M
        E = pk["g"]**s
        CT["E_tilde"] = E_tilde
        CT["E"] = E

        for name, value in Keyword.items():
            z, s1, s2 = group.random(), group.random(), group.random()
            htemp = H.hashToZr(name + value)

            E0 = (pk["w"]**-s) * (((pk["u"]**htemp) * pk["h"])**z)
            E1 = pk["g1"]**(z - s1)
            E2 = pk["g2"]**s1
            E3 = pk["g3"]**(z - s2)
            E4 = pk["g4"]**s2
            CT[name] = {"E0": E0, "E1": E1, "E2": E2, "E3": E3, "E4": E4}
        #CT["s"] = s
        return CT
示例#11
0
    def keygen(self, pk, msk, Pol, Pol_M):
        H = Hash(group)
        SK = dict()
        s, y2, y3 = 1, group.random(), group.random()

        sigma = dict()
        for name, value in Pol.items():
            h = H.hashToZr(name + value)
            sigma[name] = msk["h_hat"] * msk["g2"]**h
        
        for name, row in Pol_M.items():
            lamb = row[0] + row[1]*y2 + row[2]*y3
            r = group.random()
            
            Q = dict()
            D0 = (msk["g_hat^alpha"]**lamb) * (sigma[name] ** r)
            D1 = msk["g2"]**r
            tmp = Pol.copy()
            del tmp[name]
            for j in tmp:
                Q[j] = sigma[j] ** r
            SK[name] = {"D0":D0, "D1":D1, "Q":Q}

        return SK
示例#12
0
 def __init__(self, groupObj):
     global group, h
     group = groupObj
     h = Hash(group)
示例#13
0
文件: PEKS.py 项目: arbuztw/PEKS
 def __init__(self, grpObj, pub):
    global group, h2
    group = grpObj
    h2 = Hash('sha1', group)
    self.pub = pub
示例#14
0
文件: PEKS.py 项目: arbuztw/PEKS
 def __init__(self, grpObj):
    global group, h2
    group = grpObj
    h2 = Hash('sha1', group)
示例#15
0
 def __init__(self, groupObj):
     IBEnc.__init__(self)
     global group,h
     group = groupObj
     h = Hash('sha1', group)
示例#16
0
 def __init__(self, groupObj, pkencObj=None):
     global group, h, pkenc
     group = groupObj
     h = Hash('sha1', group)
     if pkencObj != None:
         pkenc = HybridEnc(pkencObj)
示例#17
0
 def __init__(self, groupObj, pkencObj=None):
     global group, h, pkenc
     group = groupObj
     h = Hash(group)
     if pkencObj is not None:
         pkenc = HybridEnc(pkencObj, msg_len=20)