def remote_agreement_debug(self, fingerprint_debug, hash, delta): """THIS IS A DEBUG FUNCTION using the fingerprint from the client Using this means NO security! 8. Key Agreement on Server generates fingerprint and decommits using received ``hash`` and ``delta`` :param hash: SHA-512 Hash of codeword c :type hash: str :param delta: difference :type delta: list """ log.info('8. Key Agreement on Server') #=============================================================================== # Fingerprinting and Fuzzy Cryptography #=============================================================================== # generate fingerprint, not used see possible fingerprints self.fingerprint = fingerprint_energy_diff.get_fingerprint(self.recording_data, self.recording_samplerate) # save fingerprint for debugging scipy.savetxt("server_fingerprint.txt", self.fingerprint) log.debug('Bob fingerprint:\n'+str(self.fingerprint)) # get possible fingerprints possible_fingerprints = get_possible_fingerprints(self.recording_data, self.recording_samplerate) # DEBUG length = len(fingerprint_debug) distances = [] for fingerprint in possible_fingerprints: # calculate hamming distance between fingerprints distance = hamming_distance(fingerprint, fingerprint_debug) print('Distance: '+str(distance)+' of '+str(length)) print('Correlation percentage: '+str(1-float(distance)/float(length))) distances += [distance] min_distance = min(distances) min_correlation = 1-float(min(distances))/float(length) print('Minimal distance: '+str(min_distance)+' of '+str(length)) print('Minimal correlation percentage: '+str(min_correlation)) try: minimals = scipy.genfromtxt(self.debug_file) except Exception, err: log.error('%s' % str(err)) print('first time, so creating minimals') minimals = scipy.array([])
def remote_agreement(self, hash, delta): """8. Key Agreement on Server generates fingerprint and decommits using received ``hash`` and ``delta`` :param hash: SHA-512 Hash of codeword c :type hash: str :param delta: difference :type delta: list """ log.info('8. Key Agreement on Server') #=============================================================================== # Fingerprinting and Fuzzy Cryptography #=============================================================================== # generate fingerprint, not used see possible fingerprints self.fingerprint = fingerprint_energy_diff.get_fingerprint(self.recording_data, self.recording_samplerate) # save fingerprint for debugging scipy.savetxt("server_fingerprint.txt", self.fingerprint) log.debug('Bob fingerprint:\n'+str(self.fingerprint)) # get possible fingerprints possible_fingerprints = get_possible_fingerprints(self.recording_data, self.recording_samplerate) for fingerprint in possible_fingerprints: try: # trying to decommit self.private_key, corr = crypto_fuzzy_jw.JW_decommit(hash, delta, fingerprint, m=self.rs_code_m, n=self.rs_code_n, symsize=self.rs_code_symsize) except Exception, err: log.error('%s' % str(err)) else: # if hash is the same accept key agreement, # test is in JW_decommit, try fails when not! # return True for accepted connection return True