def run_test(dut,msg=0): msg = random.randint(0,(2**24)-1) print(hex(msg)) spongent_impl = spongent.Spongent(88,80,8,45) spongent_impl.initialization_phase(msg,64) expected_padded_msg = spongent_impl.padded_msg expected_state = spongent_impl.absorbing_phase() setup_function(dut,msg) yield rst_function_test(dut,expected_padded_msg) yield absorbing_test(dut,expected_state,spongent_impl)
def run_test(dut, msg=0): msg = random.randint(0, (2**24) - 1) print(hex(msg)) spongent_impl = spongent.Spongent(256, 256, 16, 140) spongent_impl.initialization_phase(msg, 64) expected_padded_msg = spongent_impl.padded_msg expected_state = spongent_impl.absorbing_phase() expected_result = spongent_impl.squeezing_phase(expected_state) setup_function(dut, msg) yield rst_function_test(dut, expected_padded_msg) yield absorbing_test(dut, expected_state, spongent_impl) yield squeezing_test(dut, spongent_impl, expected_result)
def create_microsd_vectors(micro_sd, VIOstorage_file, storage_file, num, e): storage_file.seek(0) #storage_file.write(int(N).to_bytes(4,byteorder='big')) zero = 0 counter_errors = 0 j = 0 for i in range(0, num): text = np.random.randint(0, 2**63 - 1, 1, dtype=np.int64) spongent_impl = spongent.Spongent(N, c, r, R) expected_value = spongent_impl.generate_hash(int(text[0]), DATA_WIDTH) print(hex(int(text[0]))) print(hex(expected_value)) percent = random.randint(1, 100) if (percent < e): expected_value = expected_value + 1 counter_errors = counter_errors + 1 text_string = '{0:0{1}x}'.format(int(text[0]), 16) expected_value_string = '{:022x}'.format(expected_value) if (N == 128): expected_value_string = '{:032x}'.format(expected_value) elif (N == 160): expected_value_string = '{:040x}'.format(expected_value) elif (N == 224): expected_value_string = '{:054x}'.format(expected_value) elif (N == 256): expected_value_string = '{:064x}'.format(expected_value) VIOstorage_file.write("""{0} {1}\n""".format(text_string, expected_value_string)) #clear block micro_sd.seek(BLOCK_SIZE * (NUM_BLOCK_TEST + j)) micro_sd.write(zero.to_bytes(512, byteorder='big')) micro_sd.seek(BLOCK_SIZE * (NUM_BLOCK_TEST + j)) j = j + 1 micro_sd.write(SIGNATURE.to_bytes(4, byteorder='big')) micro_sd.write(int(text[0]).to_bytes(8, byteorder='little')) micro_sd.write( int(expected_value).to_bytes(int(N / 8), byteorder='little')) #clear block micro_sd.seek(BLOCK_SIZE * (NUM_BLOCK_TEST + j)) micro_sd.write(zero.to_bytes(512, byteorder='big')) return counter_errors
def write_params(sheet1, params, i): msg = params[1] result = params[2] spongent_impl = spongent.Spongent(N, c, r, R) expected_hash = spongent_impl.generate_hash(msg, 64) print("*************************") print(hex(result)) print(hex(expected_hash)) print("*************************") error = 0 if (expected_hash != result): error = 1 sheet1.write(i, 1, hex(msg)) sheet1.write(i, 2, hex(result)) sheet1.write(i, 3, hex(expected_hash)) sheet1.write(i, 4, hex(error)) return i + 1
def __init__(self, count, salt, user_password, N=128, c=128, r=8, R=70, salt_len=64, user_password_len=32, count_len=32): #count_len + user_password_len + salt_len <= N self.count = count #valores de 32 bits self.salt = salt self.user_password = user_password self.N = N self.hash_function = spongent.Spongent(N, c, r, R) self.salt_len = salt_len self.count_len = count_len self.user_password_len = user_password_len self.data_in_len = salt_len + user_password_len + count_len
def __init__(self,key,n,c,r,R): self.key = key self.n = n self.hash_function = spongent.Spongent(n,c,r,R) self.ipad = self.generate_bit_pattern('00110110',n) self.opad = self.generate_bit_pattern('01011100',n)