def fingerprint(self): if self.Jcoord: return fingexp.fingerprint( (self.ECG, self.infty, self.x, self.y, self.z, self.Jcoord)) else: return fingexp.fingerprint( (self.ECG, self.infty, self.x, self.y, self.Jcoord))
def reshuffleBucket(self, bucket): ''' This method randomly shuffles the bucket and update the positionList, the positionMap and the clientStash accordingly. bucket is a list of tuples (is_real_block, position, blockID_or_dummyBlock) We assume all real blocks are stored in the client Stash ''' #positionL = [] first_pos = bucket[0][1] #print '\t --> reshuffling bucket', first_pos,'to',first_pos+self.SZ-1 #for i in range(len(bucket)): # positionL.append(bucket[i][1]) #print 'bucket',bucket perm_bucket = randomPermutation(bucket) #print 'perm_bucket',perm_bucket for i in range(len(bucket)): #position = positionL[i] position = first_pos + i if perm_bucket[i][0] == True: # a real block blockID = perm_bucket[i][2] block = self.clientStash.pop(blockID) assert block != None #print 're-inserting block',blockID,'from stash' old_pos, path = self.positionMap[blockID] assert not path == None self.positionList[position] = blockID, path, True #print '(3) modifying positionList at',position #self.check_insertion(position,blockID) self.positionMap[blockID] = position, path #print '(1) updtating position map of ',blockID, 'to ',position, path perm_bucket[i] = (position, blockID, block) else: # a dummy block self.positionList[position] = None, None, True #print '(4) modifying positionList at',position perm_bucket[i] = (position, 'dummy', perm_bucket[i][2]) #print 'permuted bucket', perm_bucket for i in range(len(perm_bucket)): perm_bucket[i] = (perm_bucket[i][0], perm_bucket[i][2]) subpath = positionToSubPath(perm_bucket[0][0], self.nbChildren, self.SZ, self.depth, self.sPD) B = [] for i in range(self.SZ): B.append(perm_bucket[i][1]) self.hashDic[subpath] = fingexp.fingerprint(B) return perm_bucket
def hashf(self,L): ''' Return a number in Zr computed from a list L of elements Assuming that all elements of the list has a fingerprint ''' order = self.pairing.r f = fingexp.fingerprint(L) z = utils.b64tompz(f)%order return z
def hashf(self,L): ''' Return a number in Zq computed from a list L of elements Assuming that all elements of the list has a fingerprint ''' q = self.PPATCpp.order f = fingexp.fingerprint(L) r = utils.b64tompz(f)%q return r
def hashNode(self, subpath): hashList = [] for i in range(self.nbChildren): hashList.append(self.hashDic[subpath + str(i)]) self.hashDic[subpath] = fingexp.fingerprint([self.hashDic[subpath]] + hashList)
def hashf(self, L): ''' Return a number in Zq computed from a list L of elements Assuming that all elements of the list has a fingerprint ''' q = self.PPATCpp.order f = fingexp.fingerprint(L) r = utils.b64tompz(f) % q return r
def fingerprint(self): return fingexp.fingerprint(self.val)
def fingerprint(self): L = [] for c in self.coef: L.append(c.fingerprint()) return fingexp.fingerprint(L)
def fillupTree(self, blockList): ''' This method assigns blocks to the tree nodes and pad with dummy blocks We assume here that the tree is empty ''' #print 'blockList',blockList t = self.tLoad t1 = time.time() #permuted_blockList, permutation = randomPermutation(blockList) permuted_blockList = randomPermutation(blockList) t2 = time.time() #print 'permuted_blockList',permuted_blockList new_blockList = [] while permuted_blockList != []: bucket = [] i = 0 while permuted_blockList != [] and i < self.Z: bucket.append((permuted_blockList.pop(), True)) i += 1 while len(bucket) < (self.SZ): bucket.append((self.createDummyBlock(), False)) #permuted_bucket, perm = randomPermutation(bucket) #TODO: time-consuming! permuted_bucket = randomPermutation(bucket) #TODO: time-consuming! new_blockList = permuted_bucket + new_blockList k = max(t - len(new_blockList), 0) #print 'new_blockList',new_blockList t3 = time.time() for i in range(k): new_blockList = [(self.createDummyBlock(), False)] + new_blockList assert len(new_blockList) == t #print 'new_blockList',new_blockList t4 = time.time() for i in range(0, t, self.SZ): bucket = [] subpath = positionToSubPath(i, self.nbChildren, self.SZ, self.depth, self.sPD) for j in range(self.SZ): bucket.append(new_blockList[i + j][0]) self.hashDic[subpath] = fingexp.fingerprint(bucket) self.treeHash = self.hashDic['0'] t4b = time.time() for i in range(t): if new_blockList[i][1] == True: blockID, block = new_blockList[i][0] subpath = positionToSubPath(i, self.nbChildren, self.SZ, self.depth, self.sPD) path = randomPath(subpath, self.nbChildren, self.depth + 1) self.positionList[i] = (blockID, path, True) self.positionMap[blockID] = (i, path) new_blockList[i] = new_blockList[i][0][1] else: # the block is a dummy one new_blockList[i] = new_blockList[i][0] t5 = time.time() L = enumerate(new_blockList) #print 'new_blockList',new_blockList self.POTree.writeBlocks(L) t6 = time.time() print 'permutation of blockList:', t2 - t1, '\n buckets creation:', t3 - t2, '\n dummy block creation:', t4 - t3, '\n hashing nodes of the tree:', t4b - t4, '\n filling up of the tree:', t5 - t4b, '\n block rerwriting in tree:', t6 - t5
def fingerprint(self): if self.Jcoord : return fingexp.fingerprint((self.ECG,self.infty,self.x,self.y,self.z,self.Jcoord)) else : return fingexp.fingerprint((self.ECG,self.infty,self.x,self.y,self.Jcoord))