Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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()
    
Ejemplo n.º 5
0
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)
    
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
def test_permute3_sponge():       
    test_hash_function(permute3_sponge, avalanche_test=False)
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
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)        
Ejemplo n.º 14
0
    
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()
    
    
Ejemplo n.º 15
0
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)
Ejemplo n.º 16
0
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)
Ejemplo n.º 17
0
def test_permute4_sponge():
    test_hash_function(permute4_sponge, avalanche_test=False)
Ejemplo n.º 18
0
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)
Ejemplo n.º 19
0
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)
Ejemplo n.º 20
0
def test_hash_function():
    from crypto.analysis.metrics import test_hash_function
    test_hash_function(hash_function)
Ejemplo n.º 21
0
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)
Ejemplo n.º 22
0
def test_hash_function():
    from crypto.analysis.metrics import test_hash_function
    test_hash_function(hash_function)
Ejemplo n.º 23
0
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)
Ejemplo n.º 24
0
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)
Ejemplo n.º 25
0
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)
Ejemplo n.º 26
0
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)
Ejemplo n.º 27
0
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)