Ejemplo n.º 1
0
def test_linear_branch_number():
    from crypto.analysis.branch_number import branch_number

    def test_function(a, b):
        return linear_layer(a, b, 0, 0)

    print branch_number(test_function)
Ejemplo n.º 2
0
def test_round_function_branch_number():
    from crypto.analysis.branch_number import branch_number

    def test_function(a, b):
        return round_function(a, b, 0, 0)

    print branch_number(test_function)
Ejemplo n.º 3
0
def test_round_function_branch_number():
    from crypto.analysis.branch_number import branch_number
    def test_function(a, b):
        state = (a, b, 0, 0)
        state = round_function(*state)            
        #print_state(state)
        #raw_input()
        return state        
    print branch_number(test_function) # 96; instruction count: 39
Ejemplo n.º 4
0
def test_min_weights():
    from operator import itemgetter
    from crypto.analysis.branch_number import branch_number
    _weights = []
    for r1 in range(8):
        for r2 in range(8):
            def branch(word):
                word ^= rotate_left(word, r1, 8)
                word ^= rotate_left(word, r2, 8)
                return word
            weights = []
            for byte in range(32):
                weights.append(format(branch(byte), 'b').count('1'))
                if weights[-1] == 0:
                    weights.pop(-1)
            _weights.append((r1, r2, weights))
    good_rotations = []
    for r1, r2, weight in _weights:        
        if weight and min(weight) >= 3:
            good_rotations.append((r1, r2))
    
    outputs = []
    for r1, r2 in good_rotations:
        def branch(word):
            word ^= rotate_left(word, r1, 8)
            word ^= rotate_left(word, r2, 8)
            return word
        outputs.append((r1, r2, branch_number(lambda x, y: (branch(x), y))))
    print sorted(outputs, key=itemgetter(2))
Ejemplo n.º 5
0
def test_diffusion():
    from crypto.analysis.branch_number import branch_number
    rounds = 2
    def test_function(a, b):
        c = d = 0
        for round in range(1, 1 + rounds):
            a, b, c, d = round_function(a, b, c, d, round)        
        return b, 0, 0, 0#b, c, d#0, 0, 0# b, c, d
    print("Differences after {} rounds: {}".format(rounds, branch_number(test_function)))
Ejemplo n.º 6
0
def test_round_function_branch_number():
    from crypto.analysis.branch_number import branch_number
    def test_function(a, b):
        return round_function(a, b, 0, 0)
    print branch_number(test_function)
Ejemplo n.º 7
0
def test_linear_branch_number():
    from crypto.analysis.branch_number import branch_number
    def test_function(a, b):
        return linear_layer(a, b, 0, 0)
    print branch_number(test_function)
Ejemplo n.º 8
0
def test_branch64():   
    print PRINT_STRING.format(64, branch_number(linear64), 64 + 1)    
Ejemplo n.º 9
0
def test_branch16():
    print PRINT_STRING.format(16, branch_number(linear16), 16 + 1)            
Ejemplo n.º 10
0
def test_branch32():
    print PRINT_STRING.format(32, branch_number(linear32), 32 + 1)
Ejemplo n.º 11
0
def test_branch8():
    print PRINT_STRING.format(8, branch_number(lambda x, y: (branch8(x), y)), 8)            
Ejemplo n.º 12
0
def test_branch8():
    print PRINT_STRING.format(8, branch_number(lambda x, y: (branch8(x), y)),
                              8)
Ejemplo n.º 13
0
def test_branch64():
    print PRINT_STRING.format(64, branch_number(linear64), 64 + 1)
Ejemplo n.º 14
0
def test_branch32():
    print PRINT_STRING.format(32, branch_number(linear32), 32 + 1)
Ejemplo n.º 15
0
def test_branch16():
    print PRINT_STRING.format(16, branch_number(linear16), 16 + 1)