Exemple #1
0
    def decrypt(self, master_public_key, sk, cipher_matrix, vertices):
        '''
        Decryption requires master_public_key, user secret key, and cipher
        '''
        group = PairingGroup('SS512')
        cpabe = CPabe_BSW07(group)
        hyb_abe = HybridABEnc(cpabe, group)

        N = len(vertices)

        resMat = [None] * N
        for i in range(0, N):
            resMat[i] = [None] * N
            for j in range(0, N):
                #convert to lower case
                s = vertices[i].lower()
                s2 = vertices[j].lower()

                cipher = cipher_matrix.get_cell_by_symbol(s, s2)
                resMat[i][j] = hyb_abe.decrypt(master_public_key, sk, cipher)
                if resMat[i][j] == False:
                    return False

        result = AdjMatrixDiGraph(mat=resMat)
        return SymbolDiGraphMat(vertices, G=result)
Exemple #2
0
def testKPABE_dk(nodes, E, P):
    sg = SymbolDiGraphMat(nodes, rand_E=E)
    #print nodes
    abe_graph = KPABESymbolDiGraph(sg)
    abe_graph.setup()
    dk = abe_graph.key_generation(P)
    return len(str(dk))
Exemple #3
0
def testCPABE_subgraph_size(nodes, E, vertices):
    sg = SymbolDiGraphMat(nodes, rand_E=E)
    abe_graph = CPABESymbolDiGraph(sg)
    abe_graph.setup()
    encMat = abe_graph.encrypt()
    
    return len(str(abe_graph.subgraph(encMat, vertices)))
Exemple #4
0
def testKPABE_keygen(nodes, E, policy):
    sg = SymbolDiGraphMat(nodes, rand_E=E)
    abe_graph = KPABESymbolDiGraph(sg)
    abe_graph.setup()
    t0 = time.clock()
    abe_graph.key_generation(policy)
    t1 = time.clock()
    return t1-t0
Exemple #5
0
def testCPABE_keygen(nodes, E, attributes):
    sg = SymbolDiGraphMat(nodes, rand_E=E)
    abe_graph = CPABESymbolDiGraph(sg)
    abe_graph.setup()
    t0 = time.clock()
    abe_graph.key_generation(attributes)
    t1 = time.clock()
    return t1-t0
Exemple #6
0
def testKPABE_enc(nodes, E):
    sg = SymbolDiGraphMat(nodes, rand_E=E)
    abe_graph = KPABESymbolDiGraph(sg)
    abe_graph.setup()
    t0 = time.clock()
    abe_graph.encrypt()
    t1 = time.clock()
    return t1-t0
Exemple #7
0
def testKPABE_subgraph(nodes, E, vertices):
    sg = SymbolDiGraphMat(nodes, rand_E=E)
    abe_graph = KPABESymbolDiGraph(sg)
    abe_graph.setup()
    encMat = abe_graph.encrypt()
    t0 = time.clock()
    abe_graph.subgraph(encMat, vertices)
    t1 = time.clock()
    return t1-t0
Exemple #8
0
        return enc_symbol_matix

    def out_to_file(self, filename):
        pass

    def read_from_file(self, filename):

        pass


if __name__ == '__main__':
    '''Owner side'''
    nodes = []
    for i in xrange(0, 4):
        nodes.append('v%d' % (i + 1))
    sg = SymbolDiGraphMat(nodes, rand_E=10)
    print sg

    #encrypt graph
    abe_graph = CPABESymbolDiGraph(sg)

    t0 = time.clock()
    abe_graph.setup()

    t1 = time.clock()

    encMat = abe_graph.encrypt()
    t2 = time.clock()
    print encMat

    #bob needs to query graph
Exemple #9
0
def testCPABE_dk(nodes, E, A):
    sg = SymbolDiGraphMat(nodes, rand_E=E)
    abe_graph = CPABESymbolDiGraph(sg)
    abe_graph.setup()
    dk = abe_graph.key_generation(A)
    return len(str(dk))
Exemple #10
0
def testKPABE_pp(nodes, E):
    sg = SymbolDiGraphMat(nodes, rand_E=E)
    abe_graph = KPABESymbolDiGraph(sg)
    pk_t, mk_t = abe_graph.setup()
    return len(str(pk_t))
Exemple #11
0
def compare_dec_rt(N, E, K):
    nodes = []
    for i in xrange(0,N):
        nodes.append('v%d'%(i+1))
        
    attributes = []
    vertices = []
    policy = "("
    for i in xrange(0, K):
        if i!=0:
            policy+=" OR "
        policy+="v%dr"%(i+1)
        attributes.append('V%dR'%(i+1))  
        attributes.append('V%dC'%(i+1))  
        vertices.append('v%d'%(i+1))
    
    policy+=") AND ("
    
    for i in xrange(0, K):
        if i!=0:
            policy+=" OR "
        policy+="v%dc"%(i+1)
    
    policy+=")"
    
    sg = SymbolDiGraphMat(nodes, rand_E=E)
    
    cpabe_graph = CPABESymbolDiGraph(sg)
    cpabe_graph.setup()
    cpabeEncMat = cpabe_graph.encrypt()
    
    kpabe_graph = KPABESymbolDiGraph(sg)
    kpabe_graph.setup()
    kpabeEncMat = kpabe_graph.encrypt()
    
    sg = SymbolDiGraphLst(nodes,rand_E=E)
    list_graph = PairEncSymbolDiGraph(sg)
    list_graph.setup()
    pairEncList = list_graph.encrypt()
    
    
    cpabe_dk = cpabe_graph.key_generation(attributes)
    kpabe_dk = kpabe_graph.key_generation(policy)
    plist_dk = list_graph.key_generation(vertices)
    
    Q = 2
    subnodes = []
    for i in xrange(0, Q):
        subnodes.append('v%d'%(i+1)) 
    
    print "CPABE with %d vertices and %d edges and %d queried subnodes %s s"%(N, E, Q, testCPABE_dec(cpabe_graph._master_public_key, cpabe_dk, cpabeEncMat, subnodes))
    print "KPABE with %d vertices and %d edges and %d queried subnodes %s s"%(N, E, Q, testKPABE_dec(kpabe_dk, kpabeEncMat, subnodes))
    print "PAIRE with %d vertices and %d edges and %d queried subnodes %s s"%(N, E, Q, testPairEnc_dec( plist_dk, pairEncList, subnodes ))
    print ""
    
    Q = 4
    subnodes = []
    for i in xrange(0, Q):
        subnodes.append('v%d'%(i+1)) 
    
    print "CPABE with %d vertices and %d edges and %d queried subnodes %s s"%(N, E, Q, testCPABE_dec(cpabe_graph._master_public_key, cpabe_dk, cpabeEncMat, subnodes))
    print "KPABE with %d vertices and %d edges and %d queried subnodes %s s"%(N, E, Q, testKPABE_dec(kpabe_dk, kpabeEncMat, subnodes))
    print "PAIRE with %d vertices and %d edges and %d queried subnodes %s s"%(N, E, Q, testPairEnc_dec( plist_dk, pairEncList, subnodes ))
    print ""
    
    
    Q = 6
    subnodes = []
    for i in xrange(0, Q):
        subnodes.append('v%d'%(i+1)) 
    
    print "CPABE with %d vertices and %d edges and %d queried subnodes %s s"%(N, E, Q, testCPABE_dec(cpabe_graph._master_public_key,cpabe_dk, cpabeEncMat, subnodes))
    print "KPABE with %d vertices and %d edges and %d queried subnodes %s s"%(N, E, Q, testKPABE_dec(kpabe_dk, kpabeEncMat, subnodes))
    print "PAIRE with %d vertices and %d edges and %d queried subnodes %s s"%(N, E, Q, testPairEnc_dec( plist_dk, pairEncList, subnodes ))
    print ""
    
    
    Q = 8
    subnodes = []
    for i in xrange(0, Q):
        subnodes.append('v%d'%(i+1)) 
    
    print "CPABE with %d vertices and %d edges and %d queried subnodes %s s"%(N, E, Q, testCPABE_dec(cpabe_graph._master_public_key,cpabe_dk, cpabeEncMat, subnodes))
    print "KPABE with %d vertices and %d edges and %d queried subnodes %s s"%(N, E, Q, testKPABE_dec(kpabe_dk, kpabeEncMat, subnodes))
    print "PAIRE with %d vertices and %d edges and %d queried subnodes %s s"%(N, E, Q, testPairEnc_dec( plist_dk, pairEncList, subnodes ))
    print ""
    
    
    Q = 10
    subnodes = []
    for i in xrange(0, Q):
        subnodes.append('v%d'%(i+1)) 
    
    print "CPABE with %d vertices and %d edges and %d queried subnodes %s s"%(N, E, Q, testCPABE_dec(cpabe_graph._master_public_key,cpabe_dk, cpabeEncMat, subnodes))
    print "KPABE with %d vertices and %d edges and %d queried subnodes %s s"%(N, E, Q, testKPABE_dec(kpabe_dk, kpabeEncMat, subnodes))
    print "PAIRE with %d vertices and %d edges and %d queried subnodes %s s"%(N, E, Q, testPairEnc_dec( plist_dk, pairEncList, subnodes ))
    print ""
Exemple #12
0
def testKPABE_ct(nodes, E):
    sg = SymbolDiGraphMat(nodes, rand_E=E)
    abe_graph = KPABESymbolDiGraph(sg)
    abe_graph.setup()
    encMat = abe_graph.encrypt()
    return len(str(encMat))