Example #1
0
	def get_trace(self):
		"""
		Do not take any argument.
		Returns the next triplet (message, cipher, trace), where:
		 - message is an ascii string containing a 64 bits clear message in hexadecimal,
		 - cipher is an ascii string containing a 64 bits ciphered message in hexadecimal,
		 - trace is a float vector containing a trace during the cipher operation.
		"""
		if self.__i == len( self.__dbd ):
			return None, None, None; # Error, since we have reached the last file

		trace_name= self.__dbd[self.__i]
		self.__i+= 1;

		try:
			cmd= "SELECT message, cipher, data FROM "+self.__table+" WHERE name = '"+trace_name+"'"
			self.__curs.execute( cmd )
			one= self.__curs.fetchone()
			msg, crypt, raw_data= one
			#if db_name=='pgdb':
		 		#raw_data= db.unescape_bytea( raw_data )
			return msg, crypt, parse_binary( str(raw_data) )
		#except db.DatabaseError, e:
		except:
			#print e
			return 'err', 'err', 'err'
Example #2
0
def test():
	sb= sbox_breaker( 1 )
	tdb= traces_database(__TABLE__)
	for i in range(10):
		msg, crypt, trace= tdb.get_trace()
		sb.process(msg, parse_binary(trace))
		best_key= sb.get_keys()[0]
		print "processed trace:", i, "- best key is:", best_key
Example #3
0
def test():
	ke= key_estimator(0, 56) # 56 is the correct key for the sbox #0
	tdb= traces_database.traces_database( __TABLE__ )
	for i in range(10):
		msg, crypt, trace= tdb.get_trace()
		ke.process(msg, parse_binary(trace))
		print "processed trace:", i, "- mark is:", ke.get_mark()

	fd= open("output.csv", "w")
	for f in ke.get_differential():
		fd.write(str(f)+"\n")
	fd.close()
Example #4
0
	def get_file(self, filename):
		"""
		Returns the raw trace (header plus float vector) of <filename> 
		"""
		try:
			cmd= "SELECT encode(data, 'escape') FROM "+self.__table+" WHERE filename = '"+filename+"'"
			self.__curs.execute( cmd )
			raw_data= self.__curs.fetchone()
			if db_name=='pgdb':
		 		raw_data= db.unescape_bytea( raw_data )
			return parse_binary( str(raw_data) )
		except db.DatabaseError, e:
			print e
			sys.exit(1)
Example #5
0
	def get_trace(self):
		"""
		Do not take any argument.
		Returns the next triplet (message, cipher, trace), where:
		 - message is an ascii string containing a 64 bits clear message in hexadecimal,
		 - cipher is an ascii string containing a 64 bits ciphered message in hexadecimal,
		 - trace is a float vector containing a trace during the cipher operation.
		"""
		if self.__i == len( self.__dd ):
			return None, None, None # Error, since we have reached the last file

		trace_name= self.__dd[self.__i]
		self.__i+= 1

		self.__fd= open( self.__dn + '/' + trace_name, 'r' )
		raw_data= self.__fd.read()

		return get_msg( trace_name ), get_cph( trace_name ), parse_binary( raw_data )