示例#1
0
def encrypt_time_space(list_n):
    iterations = 1

    private = public = 0
    encrypt_timings = []
    aggregate_time = []
    aggregate_size = []
    private_space = []
    public_space = []
    for n in list_n:
        start = time.clock()
        for i in xrange(iterations):
            storage = generate_ciphertext_keys(n)
        end = time.clock()
        no_of_bits = len(list(bin(n)[2:])) + 1
        kpabe = KPabe(group)

        encrypt_timings.append((n, (end - start) / iterations))
        policy = policy_less_than(
            'A', n + 1, no_of_bits) + " and " + policy_more_than_equal(
                'A', 1, no_of_bits)
        start = time.clock()
        for i in xrange(iterations):
            secret_key = kpabe.keygen(storage['master_public_key'],
                                      storage['master_key'], policy)
        end = time.clock()
        aggregate_size.append(
            (n, getsizeof(pickle.dumps(objectToBytes(secret_key, group)))))
        aggregate_time.append((end - start) / iterations)
        public, private = getStorageSize(storage)
        private_space.append((n, private))
        public_space.append((n, public))

    return encrypt_timings, aggregate_time, public_space, private_space, aggregate_size
示例#2
0
def calculate_aggregate_size(list_q, n):
	kpabe = KPabe(group)
	more_than = 1
	iterations = 1
	aggregate_size = []
	aggregate_time = []
	storage = {}
	storage['n'] = n
	no_of_bits = len(list(bin(n)[2:]))+1
	storage['master_public_key'], storage['master_key'] = kpabe.setup()


	for q in list_q:
		gen_timing = 0.0

		for i in xrange(iterations):
			more_than_equal, less_than = generate_range(storage, q)	 
			policy = policy_less_than('A', less_than, no_of_bits) + " and " + policy_more_than_equal('A', more_than_equal, no_of_bits)
			start = time.clock()
			secret_key = kpabe.keygen(storage['master_public_key'], storage['master_key'], policy)
			end = time.clock()
			gen_timing += end-start
		
		aggregate_size.append((q, getsizeof(pickle.dumps(objectToBytes(secret_key, group)))))
		aggregate_time.append((q, (gen_timing)/iterations))
	return aggregate_time, aggregate_size
示例#3
0
def calculate_aggregate_size(list_q, n):
    kpabe = KPabe(group)
    more_than = 1
    iterations = 10
    aggregate_size = []
    aggregate_time = []
    storage = {}
    storage['n'] = n
    no_of_bits = len(list(bin(n)[2:])) + 1
    storage['master_public_key'], storage['master_key'] = kpabe.setup()

    for q in list_q:
        gen_timing = 0.0

        for i in xrange(iterations):
            more_than_equal, less_than = generate_range(storage, q)
            policy = policy_less_than(
                'A', less_than, no_of_bits) + " and " + policy_more_than_equal(
                    'A', more_than_equal, no_of_bits)
            start = time.clock()
            secret_key = kpabe.keygen(storage['master_public_key'],
                                      storage['master_key'], policy)
            end = time.clock()
            gen_timing += end - start

        aggregate_size.append(
            (q, getsizeof(pickle.dumps(objectToBytes(secret_key, group)))))
        aggregate_time.append((q, (gen_timing) / iterations))
    return aggregate_time, aggregate_size
示例#4
0
文件: ABE.py 项目: dkhungme/FastKAC
def decryption_time(storage, q_list):
	iterations = 1
	timings = []
	aggregate_time = []
	aggregate_size = []
	no_of_bits = len(list(bin(storage['n'])[2:]))+1  
	kpabe = KPabe(group)
	for q in q_list:
		check = True
		timing = 0.0
		gen_timing = 0.0
		for i in xrange(iterations):
			more_than_equal, less_than = generate_range(storage, q)	 
			start = time.clock()
			policy = policy_less_than('A', less_than, no_of_bits) + " and " + policy_more_than_equal('A', more_than_equal, no_of_bits)
			secret_key = kpabe.keygen(storage['master_public_key'], storage['master_key'], policy)
			end = time.clock()
			gen_timing += end-start

			cipher_text = storage['cipher'][more_than_equal:less_than]
			plain_text = storage['plain'][more_than_equal:less_than]
			start = time.clock()
			result = [kpabe.decrypt(ct, secret_key) for ct in cipher_text]
			end = time.clock()
			timing+=end-start
			if (plain_text!=result):
				check = False
		aggregate_time.append((q, gen_timing/iterations))
		aggregate_size.append((q, getsizeof(pickle.dumps(objectToBytes(secret_key, group)))))
		if (check==True):
			timings.append((q, timing/iterations))
		else:
			timings.append((q, 'error'))
	return timings
示例#5
0
文件: ABE.py 项目: dkhungme/FastKAC
def encrypt_time_space(list_n):
	iterations = 1

	private = public = 0
	encrypt_timings = []
	aggregate_time = []
	aggregate_size = []
	private_space = []
	public_space = []
	for n in list_n:
		start = time.clock()
		for i in xrange(iterations):	
			storage = generate_ciphertext_keys(n)
		end = time.clock()
		no_of_bits = len(list(bin(n)[2:]))+1
		kpabe = KPabe(group)

		encrypt_timings.append((n, (end-start)/iterations))
		policy = policy_less_than('A', n+1, no_of_bits) + " and " + policy_more_than_equal('A', 1, no_of_bits)
		start = time.clock()
		for i in xrange(iterations):
			secret_key = kpabe.keygen(storage['master_public_key'], storage['master_key'], policy)
		end = time.clock()	
		aggregate_size.append((n, getsizeof(pickle.dumps(objectToBytes(secret_key, group)))))
		aggregate_time.append((end-start)/iterations)
		public, private = getStorageSize(storage)
		private_space.append((n, private))
		public_space.append((n, public))

	return encrypt_timings, aggregate_time, public_space, private_space, aggregate_size
示例#6
0
def decryption_time(storage, q_list):
	iterations = 5
	timings = []
	aggregate_time = []
	aggregate_size = []
	no_of_bits = len(list(bin(storage['n'])[2:]))+1  
	kpabe = KPabe(group)
	for q in q_list:
		print "q"
		print q

		check = True
		timing = 0.0
		gen_timing = 0.0
		for i in xrange(iterations):
			# print "iterations"
			# print i

			more_than_equal, less_than = generate_range(storage, q)	 
			print "more_than_equal"
			print more_than_equal
			print "less_than"
			print less_than

			start = time.clock()
			policy = policy_less_than('A', less_than, no_of_bits) + " and " + policy_more_than_equal('A', more_than_equal, no_of_bits)
			print "policy"
			print policy

			secret_key = kpabe.keygen(storage['master_public_key'], storage['master_key'], policy)
			end = time.clock()
			gen_timing += end-start

			cipher_text = storage['cipher'][more_than_equal:less_than]
			plain_text = storage['plain'][more_than_equal:less_than]
			start = time.clock()

			assert group.InitBenchmark(), "failed to initialize benchmark"
			group.StartBenchmark(["Mul", "Exp", "Pair", "Div", "Granular"])

			result = [kpabe.decrypt(ct, secret_key) for ct in cipher_text]
			
			group.EndBenchmark()

			end = time.clock()
			msmtDict = group.GetGeneralBenchmarks()
			print("<=== General Benchmarks ===>")
			print("Results  := ", msmtDict)

			timing+=end-start
			if (plain_text!=result):
				check = False
		aggregate_time.append((q, gen_timing/iterations))
		aggregate_size.append((q, getsizeof(pickle.dumps(objectToBytes(secret_key, group)))))
		if (check==True):
			timings.append((q, timing/iterations))
		else:
			timings.append((q, 'error'))
	return timings
示例#7
0
def benchmark():
    groupObj1 = PairingGroup('MNT224')
    groupObj2 = PairingGroup('MNT224')
    ekpabe = EKPabe(groupObj1)
    kpabe = KPabe(groupObj2)

    t1_s = 0
    t1_k = 0
    t1_e = 0
    t1_d = 0
    t2_s = 0
    t2_k = 0
    t2_e = 0
    t2_d = 0

    attributes = ['ONE', 'TWO', 'THREE', 'FOUR']
    policy = 'THREE and (ONE or TWO)'
    msg1 = b"Some Random Message"
    msg2 = groupObj2.random(GT)

    for b in range(4):
        start = clock()
        (epk, emk) = ekpabe.setup(attributes)
        t1_s += clock() - start

        start = clock()
        (pk, mk) = kpabe.setup()
        t2_s += clock() - start

        start = clock()
        emykey = ekpabe.keygen(epk, emk, policy)
        t1_k += clock() - start

        start = clock()
        mykey = kpabe.keygen(pk, mk, policy)
        t2_k += clock() - start

        for i in range(50):
            start = clock()
            eciphertext = ekpabe.encrypt(epk, msg1, attributes)
            t1_e += clock() - start

            start = clock()
            ciphertext = kpabe.encrypt(pk, msg2, attributes)
            t2_e += clock() - start

            start = clock()
            erec_msg = ekpabe.decrypt(eciphertext, emykey)
            t1_d += clock() - start

            start = clock()
            rec_msg = kpabe.decrypt(ciphertext, mykey)
            t2_d += clock() - start

            assert msg1 == erec_msg
            assert msg2 == rec_msg

    print("yct14 s=%s k=%s e=%s d=%s" % (t1_s, t1_k, t1_e, t1_d))
    print("lsw08 s=%s k=%s e=%s d=%s" % (t2_s, t2_k, t2_e, t2_d))
示例#8
0
def encrypt_time_space(list_n):
	iterations = 1

	private = public = 0
	encrypt_timings = []
	aggregate_time = []
	aggregate_size = []
	private_space = []
	public_space = []
	for n in list_n:
		print "list_n"
		print n

		start = time.clock()
		for i in xrange(iterations):	
			storage = generate_ciphertext_keys(n)
		end = time.clock()
		no_of_bits = len(list(bin(n)[2:]))+1


		kpabe = KPabe(group)

		encrypt_timings.append((n, (end-start)/iterations))
		policy = policy_less_than('A', n+1, no_of_bits) + " and " + policy_more_than_equal('A', 1, no_of_bits)
		start = time.clock()


		for i in xrange(iterations):
			print "iterations"
			print i

			assert group.InitBenchmark(), "failed to initialize benchmark"
			group.StartBenchmark(["Mul", "Exp", "Pair", "Div", "Granular"])

			secret_key = kpabe.keygen(storage['master_public_key'], storage['master_key'], policy)

			group.EndBenchmark()

		end = time.clock()	

		msmtDict = group.GetGeneralBenchmarks()
		# granDict = group.GetGranularBenchmarks()
		print("<=== General Benchmarks ===>")
		print("Results  := ", msmtDict)
		# print("<=== Granular Benchmarks ===>")
		# print("G1 mul   := ", granDict)

		aggregate_size.append((n, getsizeof(pickle.dumps(objectToBytes(secret_key, group)))))
		aggregate_time.append((end-start)/iterations)
		public, private = getStorageSize(storage)
		private_space.append((n, private))
		public_space.append((n, public))

	return encrypt_timings, aggregate_time, public_space, private_space, aggregate_size
示例#9
0
 def testKPabe(self):    
     groupObj = PairingGroup('MNT224')
     kpabe = KPabe(groupObj)
     
     (pk, mk) = kpabe.setup()
     
     policy = '(ONE or THREE) and (THREE or TWO)'
     attributes = [ 'ONE', 'TWO', 'THREE', 'FOUR' ]
     msg = groupObj.random(GT) 
  
     mykey = kpabe.keygen(pk, mk, policy)
     
     if debug: print("Encrypt under these attributes: ", attributes)
     ciphertext = kpabe.encrypt(pk, msg, attributes)
     if debug: print(ciphertext)
     
     rec_msg = kpabe.decrypt(ciphertext, mykey)
    
     assert msg == rec_msg 
     if debug: print("Successful Decryption!")
示例#10
0
    def testKPabe(self):
        groupObj = PairingGroup('MNT224')
        kpabe = KPabe(groupObj)

        (pk, mk) = kpabe.setup()

        policy = '(ONE or THREE) and (THREE or TWO)'
        attributes = ['ONE', 'TWO', 'THREE', 'FOUR']
        msg = groupObj.random(GT)

        mykey = kpabe.keygen(pk, mk, policy)

        if debug: print("Encrypt under these attributes: ", attributes)
        ciphertext = kpabe.encrypt(pk, msg, attributes)
        if debug: print(ciphertext)

        rec_msg = kpabe.decrypt(ciphertext, mykey)

        assert msg == rec_msg
        if debug: print("Successful Decryption!")
示例#11
0
def decryption_time(storage, q_list):
    iterations = 1
    timings = []
    aggregate_time = []
    aggregate_size = []
    no_of_bits = len(list(bin(storage['n'])[2:])) + 1
    kpabe = KPabe(group)
    for q in q_list:
        check = True
        timing = 0.0
        gen_timing = 0.0
        for i in xrange(iterations):
            more_than_equal, less_than = generate_range(storage, q)
            start = time.clock()
            policy = policy_less_than(
                'A', less_than, no_of_bits) + " and " + policy_more_than_equal(
                    'A', more_than_equal, no_of_bits)
            secret_key = kpabe.keygen(storage['master_public_key'],
                                      storage['master_key'], policy)
            end = time.clock()
            gen_timing += end - start

            cipher_text = storage['cipher'][more_than_equal:less_than]
            plain_text = storage['plain'][more_than_equal:less_than]
            start = time.clock()
            result = [kpabe.decrypt(ct, secret_key) for ct in cipher_text]
            end = time.clock()
            timing += end - start
            if (plain_text != result):
                check = False
        aggregate_time.append((q, gen_timing / iterations))
        aggregate_size.append(
            (q, getsizeof(pickle.dumps(objectToBytes(secret_key, group)))))
        if (check == True):
            timings.append((q, timing / iterations))
        else:
            timings.append((q, 'error'))
    return timings