예제 #1
0
	def create_cipher_string(self):
		self.cipher_prime = self.datum_string()
		""" Encrypt with all secondary keys from N ... 1 """
		self.debug("Orig len: %d" % len(self.cipher_prime))
		
		for i in xrange(self.n_nodes - 1, -1, -1):
			k1, k2 = self.pub_keys[i]
			self.cipher_prime = AnonCrypto.encrypt_with_rsa(k2, self.cipher_prime)
			self.debug("Cipher-prim len: %d" % len(self.cipher_prime))

		self.cipher = self.cipher_prime

		""" Encrypt with all primary keys from N ... 1 """
		for i in xrange(self.n_nodes-1, -1, -1):
			k1, k2 = self.pub_keys[i]
			self.cipher = AnonCrypto.encrypt_with_rsa(k1, self.cipher)
			self.debug("Cipher len: %d" % len(self.cipher))
예제 #2
0
    def create_cipher_string(self):
        self.cipher_prime = self.datum_string()
        """ Encrypt with all secondary keys from N ... 1 """
        self.debug("Orig len: %d" % len(self.cipher_prime))

        #for i in xrange(self.n_nodes - 1, -1, -1):
        #	k1, k2 = self.pub_keys[i]
        #	self.cipher_prime = AnonCrypto.encrypt_with_rsa(k1, self.cipher_prime)
        #	self.debug("Cipher-prim len: %d" % len(self.cipher_prime))

        self.cipher = self.cipher_prime
        """ Encrypt with all primary keys from N ... 1 """
        #for i in xrange(self.n_nodes-1, -1, -1):
        for i in xrange(self.n_nodes - 1, self.id - 1, -1):
            k1, k2 = self.pub_keys[i]
            self.cipher = AnonCrypto.encrypt_with_rsa(k2, self.cipher)
            self.debug("Cipher len: %d" % len(self.cipher))
예제 #3
0
    def run_phase1(self):
        self.seeds = []
        self.gens = []
        self.my_hashes = []
        for i in xrange(0, self.n_nodes):
            seed = AnonCrypto.random_seed()
            self.seeds.append(seed)
            self.gens.append(AnonRandom(seed))

        self.msg_len = os.path.getsize(self.msg_file)
        (handle, self.cip_file) = tempfile.mkstemp()

        blocksize = 8192

        """
		The hash h holds a hash of the XOR of all
		pseudo-random strings with the author's message.
		"""
        h = M2Crypto.EVP.MessageDigest("sha1")

        """ Hash of final message """
        h_msg = M2Crypto.EVP.MessageDigest("sha1")
        self.debug("Starting to write data file")

        with open(self.msg_file, "r") as f_msg:
            with open(self.cip_file, "w") as f_cip:
                """ Loop until we reach EOF """
                while True:
                    block = f_msg.read(blocksize)
                    h_msg.update(block)
                    n_bytes = len(block)
                    if n_bytes == 0:
                        break

                    """
					Get blocksize random bytes for each other node
					and XOR them together with blocksize bytes of
					my message, update the hash and write the XOR'd
					block out to disk.
					"""
                    for i in xrange(0, self.n_nodes):
                        """ Don't XOR bits for self """
                        if i == self.id:
                            continue

                        r_bytes = self.gens[i].rand_bytes(n_bytes)
                        # self.debug("l1: %d, l2: %d, n: %d" % (len(block), len(r_bytes), n_bytes))
                        block = Utilities.xor_bytes(block, r_bytes)
                    f_cip.write(block)
                    h.update(block)

        self.debug("Finished writing my data file")

        """ Encrypt each of the pseudo-random generator seeds. """
        self.enc_seeds = []
        for i in xrange(0, self.n_nodes):
            self.my_hashes.append(self.gens[i].hash_value())
            # Encrypt each seed with recipient's primary pub key
            self.enc_seeds.append(AnonCrypto.encrypt_with_rsa(self.pub_keys[i][0], self.seeds[i]))

        self.my_msg_hash = h_msg.final()

        """ Insert "cheating" hash for self. """
        self.my_hashes[self.id] = h.final()

        """ Remember the seed encrypted for self. """
        self.my_seed = self.enc_seeds[self.id]

        """ Write all the data to be sent out to disk. """
        (dhandle, self.dfilename) = tempfile.mkstemp()
        with open(self.dfilename, "w") as f:
            marshal.dump((self.id, self.round_id, self.msg_len, self.my_msg_hash, self.enc_seeds, self.my_hashes), f)
        return
예제 #4
0
	def run_phase1(self):
		self.seeds = []
		self.gens = []	
		self.my_hashes = []
		for i in xrange(0, self.n_nodes):
			seed = AnonCrypto.random_seed()
			self.seeds.append(seed)
			self.gens.append(AnonRandom(seed))

		self.msg_len = os.path.getsize(self.msg_file)
		(handle, self.cip_file) = tempfile.mkstemp()

		blocksize = 8192

		"""
		The hash h holds a hash of the XOR of all
		pseudo-random strings with the author's message.
		"""
		h = M2Crypto.EVP.MessageDigest('sha1')

		""" Hash of final message """
		h_msg = M2Crypto.EVP.MessageDigest('sha1')
		self.debug('Starting to write data file')

		with open(self.msg_file, 'r') as f_msg:
			with open(self.cip_file, 'w') as f_cip:
				""" Loop until we reach EOF """
				while True:
					block = f_msg.read(blocksize)
					h_msg.update(block)
					n_bytes = len(block)
					if n_bytes == 0: break

					"""
					Get blocksize random bytes for each other node
					and XOR them together with blocksize bytes of
					my message, update the hash and write the XOR'd
					block out to disk.
					"""
					for i in xrange(0, self.n_nodes):
						""" Don't XOR bits for self """
						if i == self.id: continue

						r_bytes = self.gens[i].rand_bytes(n_bytes)
						#self.debug("l1: %d, l2: %d, n: %d" % (len(block), len(r_bytes), n_bytes))
						block = Utilities.xor_bytes(block, r_bytes)
					f_cip.write(block)
					h.update(block)

		self.debug('Finished writing my data file')

		""" Encrypt each of the pseudo-random generator seeds. """ 
		self.enc_seeds = []
		for i in xrange(0, self.n_nodes):
			self.my_hashes.append(self.gens[i].hash_value())
			# Encrypt each seed with recipient's primary pub key
			self.enc_seeds.append(
					AnonCrypto.encrypt_with_rsa(
						self.pub_keys[i][0],
						self.seeds[i]))
	
		self.my_msg_hash = h_msg.final()

		""" Insert "cheating" hash for self. """
		self.my_hashes[self.id] = h.final()

		""" Remember the seed encrypted for self. """
		self.my_seed = self.enc_seeds[self.id]

		""" Write all the data to be sent out to disk. """
		(dhandle, self.dfilename) = tempfile.mkstemp()
		with open(self.dfilename, 'w') as f:
			marshal.dump((
				self.id,
				self.round_id,
				self.msg_len,
				self.my_msg_hash,
				self.enc_seeds,
				self.my_hashes), f)
		return