Exemple #1
0
def generate_simon_version(n, rounds, a=8, b=1, c=2):
    simon = CipherDescription(2*n)
    for i in range(n):
        input_1 = "s{}".format((i-a)%n+n)
        input_2 = "s{}".format((i-b)%n+n)
        product =  "t{}".format(2*i)
        simon.apply_and(input_1, input_2, product)
        input_3 = "s{}".format((i-c)%n+n)
        xor = "t{}".format(2*i+1)
        simon.apply_xor(product, input_3, xor)
        right_side = "s{}".format(i)
        simon.apply_xor(xor, right_side, right_side)
    for i in range(n):
        right_side = "s{}".format(i)
        left_side = "s{}".format(i+n)
        simon.apply_permutation( (right_side, left_side) )
    simon.set_rounds(rounds)
    return simon
Exemple #2
0
def generate_Kreyvium_version(rounds):
    kreyvium = CipherDescription(416)

    for i in range(128):
        kreyvium.apply_mov("s{}".format(93+i), "s{}".format(288+i))

    for r in range(rounds):
        kreyvium.apply_xor("s65", "s92", "t1")
        kreyvium.apply_xor("s161", "s176", "t2")
        kreyvium.apply_xor("s242", "s287", "t3")

        kreyvium.apply_and("s90", "s91", "tand1")
        kreyvium.apply_and("s174", "s175", "tand2")
        kreyvium.apply_and("s285", "s286", "tand3")

        kreyvium.apply_xor("t1", "tand1", "t1")
        kreyvium.apply_xor("t1", "s415", "t1")
        kreyvium.apply_xor("t1", "s170", "s92")

        kreyvium.apply_xor("t2", "tand2", "t2")
        kreyvium.apply_xor("t2", "s263", "s176")

        kreyvium.apply_xor("t3", "tand3", "t3")
        kreyvium.apply_xor("t3", "s68", "s287")

        switch_last_bits = ("s92", "s176", "s287")
        kreyvium.apply_permutation(switch_last_bits)

        permutation_1 = tuple("s{}".format(i) for i in range(93))
        permutation_2 = tuple("s{}".format(i) for i in range(93, 177))
        permutation_3 = tuple("s{}".format(i) for i in range(177, 288))
        permutation_4 = tuple("s{}".format(i) for i in range(288, 416))
        kreyvium.apply_permutation(permutation_1)
        kreyvium.apply_permutation(permutation_2)
        kreyvium.apply_permutation(permutation_3)
        kreyvium.apply_permutation(permutation_4)

    return kreyvium
Exemple #3
0
from cipher_description import CipherDescription

trivium = CipherDescription(288)
trivium.apply_xor("s65", "s92", "t1")
trivium.apply_xor("s161", "s176", "t2")
trivium.apply_xor("s242", "s287", "t3")

trivium.apply_and("s90", "s91", "tand1")
trivium.apply_and("s174", "s175", "tand2")
trivium.apply_and("s285", "s286", "tand3")

trivium.apply_xor("t1", "tand1", "t1")
trivium.apply_xor("t1", "s170", "s92")

trivium.apply_xor("t2", "tand2", "t2")
trivium.apply_xor("t2", "s263", "s176")

trivium.apply_xor("t3", "tand3", "t3")
trivium.apply_xor("t3", "s68", "s287")

switch_last_bits = ("s92", "s176", "s287")
trivium.apply_permutation(switch_last_bits)

permutation_1 = tuple("s{}".format(i) for i in range(93))
permutation_2 = tuple("s{}".format(i) for i in range(93, 177))
permutation_3 = tuple("s{}".format(i) for i in range(177, 288))
trivium.apply_permutation(permutation_1)
trivium.apply_permutation(permutation_2)
trivium.apply_permutation(permutation_3)
trivium.set_rounds(1152)
Exemple #4
0
wordsize = 32

a = 2
b = 1
c = 3
d = 26
e = 9
f = 0

# newz = rotate(x ^ (z << 1) ^ ((y&z) << a),d);
# newy = rotate(y ^ x        ^ ((x|z) << b),e);
# newx = rotate(z ^ y        ^ ((x&y) << c),f);

# new z
for bit in range(32):
    gimli.apply_and("s{}".format(wordsize + bit),
                    "s{}".format(2 * wordsize + bit), "tand0{}".format(bit))

for bit in range(a, 32):
    gimli.apply_xor("s{}".format(0 + bit), "tand0{}".format(bit - a),
                    "txor{}".format(bit))
for bit in range(0, a):
    gimli.apply_and("s{}".format(0 + bit), "s{}".format(0 + bit),
                    "txor{}".format(bit))

for bit in range(0, 1):
    gimli.apply_and("txor{}".format(bit), "txor{}".format(bit),
                    "tnewz{}".format(bit))
for bit in range(1, 32):
    gimli.apply_xor("txor{}".format(bit), "s{}".format(2 * wordsize + bit - 1),
                    "tnewz{}".format(bit))
Exemple #5
0
from cipher_description import CipherDescription

bivium = CipherDescription(177)
bivium.apply_xor("s65", "s92", "t0")
bivium.apply_and("s90", "s91", "t1")
bivium.apply_xor("t0", "t1", "t2")
bivium.apply_xor("t2", "s170", "s92")
bivium.apply_xor("s161", "s176", "t3")
bivium.apply_and("s174", "s175", "t4")
bivium.apply_xor("t3", "t4", "t5")
bivium.apply_xor("t5", "s68", "s176")
switch_last_bits = ("s92", "s176")
bivium.apply_permutation(switch_last_bits)
permutation_1 = tuple("s{}".format(i) for i in range(93))
permutation_2 = tuple("s{}".format(i) for i in range(93, 177))
bivium.apply_permutation(permutation_1)
bivium.apply_permutation(permutation_2)
bivium.set_rounds(708)