def generate_ciphertext_keys(n): storage = {} storage['n'] = n kpabe = KPabe(group) more_than = 1 storage['plain'] = [group.random(GT)] storage['cipher'] = [group.random(GT)] no_of_bits = len(list(bin(n)[2:])) + 1 storage['master_public_key'], storage['master_key'] = kpabe.setup() frames_attribute = (num_to_attribute('A', i, no_of_bits) for i in xrange(1, n + 1)) for i in xrange(n): plain = group.random(GT) storage['plain'].append(plain) storage['cipher'].append( kpabe.encrypt(storage['master_public_key'], plain, frames_attribute.next())) # ct = storage['cipher'][1:n+1] # result = [kpabe.decrypt(cipher_text, secret_key) for cipher_text in ct] # print 'lol', result # print storage['plain'][1:n+1] return storage
def generate_ciphertext_keys(n): storage = {} storage['n'] = n kpabe = KPabe(group) more_than = 1 storage['plain'] = [group.random(GT)] storage['cipher'] = [group.random(GT)] no_of_bits = len(list(bin(n)[2:]))+1 print "no_of_bits" print no_of_bits storage['master_public_key'], storage['master_key'] = kpabe.setup() frames_attribute = (num_to_attribute('A', i, no_of_bits) for i in xrange(1, n+1)) print "frames_attribute" print frames_attribute for i in xrange(n): plain = group.random(GT) storage['plain'].append(plain) storage['cipher'].append(kpabe.encrypt(storage['master_public_key'], plain, frames_attribute.next())) # ct = storage['cipher'][1:n+1] # result = [kpabe.decrypt(cipher_text, secret_key) for cipher_text in ct] # print 'lol', result # print storage['plain'][1:n+1] return storage
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
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
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))
def callSetup(groupObj, schemeName): #calling a new groupObj somehow destroys the benchmark module #groupObj = PairingGroup(curve) if schemeName == 'bsw07': scheme = CPabe_BSW07(groupObj) elif schemeName == 'lw08': scheme = KPabe(groupObj) elif schemeName == 'waters09': scheme = CPabe09(groupObj) elif schemeName == 'rw12': scheme = CPABE_RW12(groupObj) elif schemeName == 'ot12': scheme = CPABE_OT12(groupObj) elif schemeName == 'AESCBC': return getAESCBC(groupObj) print("Setup(",curve,",", schemeName, ") ", end="") if schemeName == 'waters09':#great implementation! :) (mk, pp) = scheme.setup() else: (pp, mk) = scheme.setup() return (scheme, pp, mk)
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!")
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!")