def test_cipher_hash(): cipher = Test_Cipher([0 for byte in range(16)], "ecb") cipher.blocksize = 16 print cipher.hash("\x00", [0xff] * 16) from crypto.analysis.metrics import test_hash_function test_hash_function(cipher.hash)
def test_prf(): def test_hash(data): output = bytearray(16) key = xor_sum(bytearray(data[:16])) for block in slide(bytearray(data), 16): prf(block, xor_sum(block)) xor_subroutine(output, block) return bytes(output) from crypto.analysis.metrics import test_hash_function test_hash_function(test_hash)
def keccak_hash(data): if len(data) in (0, 1): data = ord(data[0] or "\x00") print data return keccak_1600.Keccak((8, hex(data)[2:])) else: data = ''.join(hex( return keccak_1600(Keccak((len(data) * 8, hex(data)))) def test_keccak_metrics(): from crypto.analysis.metrics import test_hash_function test_hash_function(keccak_hash) if __name__ == "__main__": test_keccak_metrics()
def test_bit_byte_transposition_diffusion(): def test_hash(data): output = bytearray(16) for block in slide(bytearray(data), 16): block.extend("\x00" * (16 - len(block))) assert len(block) == 16 for round in range(4): bit_transposition(block) byte_transposition(block) for index in range(16): block[index] = (block[index] + block[(index + 2) % 16] + index) % 256 xor_subroutine(output, block) return bytes(output) from crypto.analysis.metrics import test_hash_function test_hash_function(test_hash)
def test_hash_function_metrics(): print "Testing metrics of hash function" from crypto.analysis.metrics import test_hash_function, PERFORMANCE_TEST #key = [] #index = 0 #bit = 1 #for byte in range(256): # entry = bytearray(STATE_SIZE) # entry[index] = bit # bit <<= 1 # bit &= 255 # if not bit: # index += 1 # bit = 1 # key.append(entry) test_hash_function(lambda data: hash_function(data))#, avalanche_test=False, randomness_test=False, period_test=False)#, bias_test=False)#, compression_test=False, performance_test=False)
def test_prp_metrics(): from crypto.utilities import slide, xor_subroutine def test_hash(data): size = len(data) data = data + ("\x00" * (16 - size)) if size == 16: output = bytearray(data) for round in range(1): prp(output, xor_sum(output)) else: output = bytearray(16) for block in slide(bytearray(data), 16): prp(block, xor_sum(block)) xor_subroutine(output, block) return bytes(output) from crypto.analysis.metrics import test_hash_function test_hash_function(test_hash)
def test_hash_function_metrics(): print "Testing metrics of hash function" from crypto.analysis.metrics import test_hash_function, PERFORMANCE_TEST #key = [] #index = 0 #bit = 1 #for byte in range(256): # entry = bytearray(STATE_SIZE) # entry[index] = bit # bit <<= 1 # bit &= 255 # if not bit: # index += 1 # bit = 1 # key.append(entry) test_hash_function( lambda data: hash_function(data) ) #, avalanche_test=False, randomness_test=False, period_test=False)#, bias_test=False)#, compression_test=False, performance_test=False)
def test_permute3_sponge(): test_hash_function(permute3_sponge, avalanche_test=False)
def test_cube_prf(): from crypto.designs.hash.sponge import crypto.designs.hash.sponge_factory cube_hash = sponge_factory(cube_prf, rate=32, capacity=0, output_size=32) from crypto.analysis.metrics import test_hash_function test_hash_function(cube_hash)
def test_hash_function(): print hash_function("\x01") print hash_function("\x02") from crypto.analysis.metrics import test_hash_function test_hash_function(hash_function, avalanche_test=False)
def compression_function(data, rounds=ROUNDS): data = bytes_to_words(data, 8) # convert 8-bit words to 64-bit words a, b, c, d = (0, 0, 0, 0) counter = 1 for in0, in1, in2, in3 in slide(data, 4): # work on 4 64-bit words at a time (256 bit state) # print "Digesting: ", in0, in1, in2, in3 a, b, c, d = add_block(a, b, c, d, in0, in1, in2, in3, counter) assert counter <= INTEGER64_OVERFLOW for round in range(rounds): a, b, c, d = round_function(a, b, c, d) a, b, c, d = add_block(a, b, c, d, in0, in1, in2, in3, counter) counter += 1 a, b, c, d = round_function(a, b, c, d) return bytes(words_to_bytes((a, b, c, d), 8)) def hash_function(data): data = pad_input(bytearray(data), 32) return compression_function(data) def test_hash_function(): print hash_function("\x01") print hash_function("\x02") from crypto.analysis.metrics import test_hash_function test_hash_function(hash_function, avalanche_test=False) if __name__ == "__main__": test_hash_function()
def test_hash_function(): print hash_function("\x01") print hash_function("\x02") from crypto.analysis.metrics import test_hash_function test_hash_function(hash_function)
def test_prf_sponge(): import crypto.designs.hash.sponge from crypto.analysis.metrics import test_hash_function hasher = sponge.sponge_factory(prf, rate=8, capacity=8, output_size=8) test_hash_function(hasher)
def test_permute4_sponge(): test_hash_function(permute4_sponge, avalanche_test=False)
def test_example_mixer_stats(): hash_function = sponge_factory(example_mixing_subroutine) from crypto.analysis.metrics import test_hash_function test_hash_function(hash_function, avalanche_test=False, randomness_test=False)
def compression_function(data, words_per_block=16): state = [0] * 16 for counter in range(len(data) / words_per_block): data_block = data[counter * words_per_block:(counter + 1) * words_per_block] diffused_counter = generate_constant(counter + 1) xor_subroutine(data_block, diffused_counter) xor_subroutine(data_block, state) data_block = permutation(*[counter] + data_block) xor_subroutine(state, data_block) return state def hash_function(data): data = bytes_to_words(pad_input(bytearray(data), 64), 4) return bytes(words_to_bytes(compression_function(data), 4)) def test_hash_function(): from crypto.analysis.metrics import test_hash_function test_hash_function(hash_function) if __name__ == "__main__": test_hash_function() #state = G(F(input), state)
def test_hash_function(): from crypto.analysis.metrics import test_hash_function test_hash_function(hash_function)
def test_hash_metrics(): from crypto.analysis.metrics import test_hash_function test_hash_function(lambda data: memory_hard_hash(data, 1), avalanche_test=False, randomness_test=False)
def test_permute_hash(): data = "\x01" print permute_hash(data, blocksize=8) from crypto.analysis.metrics import test_hash_function test_hash_function(permute_hash)