コード例 #1
0
def first_3SPboxes(reg, round_value):
    # we need an additional register because we can't work on r28 r29 r30 r31
    wk_reg, wk_reg2 = init_working(
    )  # additional registers used for computation : r24 - r31
    reg = spbox(0, reg, wk_reg, wk_reg2)

    wk_reg, wk_reg2 = init_working(
    )  # additional registers used for computation : r24 - r31
    reg = spbox(3, reg, wk_reg, wk_reg2)

    reg = small_swap(reg)

    if round_value != 0:
        AVR.LDI32(wk_reg, round_value)  # load into the third register
        AVR.EOR32(reg[0], wk_reg)  # xor only the third register

    wk_reg, wk_reg2 = init_working(
    )  # additional registers used for computation : r24 - r31
    reg = spbox(3, reg, wk_reg, wk_reg2)

    wk_reg, wk_reg2 = init_working(
    )  # additional registers used for computation : r24 - r31
    reg = spbox(3, reg, wk_reg, wk_reg2)

    wk_reg, wk_reg2 = init_working(
    )  # additional registers used for computation : r24 - r31
    reg = spbox(0, reg, wk_reg, wk_reg2)

    wk_reg, wk_reg2 = init_working(
    )  # additional registers used for computation : r24 - r31
    reg = spbox(0, reg, wk_reg, wk_reg2)

    return reg
コード例 #2
0
def store(reg):
    AVR.POPZ()
    AVR.STZ32(reg[5])  # store z
    AVR.STZ32(reg[2])  # store y
    AVR.SBIW(30, 8)
    AVR.STZ32(reg[4])  # store x
    AVR.STZ32(reg[1])  # store z
    AVR.SBIW(30, 8)
    AVR.STZ32(reg[3])  # store y
    AVR.STZ32(reg[0])  # store x
    return reg
コード例 #3
0
ファイル: gen_gimli.py プロジェクト: jedisct1/gimli
def store():
	reg = init_state()
	AVR.STZ32(reg[5])		# store z
	AVR.STZ32(reg[2])		# store y
	AVR.SBIW(30,8)
	AVR.STZ32(reg[4])		# store x
	AVR.STZ32(reg[1])		# store z
	AVR.SBIW(30,8)
	AVR.STZ32(reg[3])		# store y
	AVR.STZ32(reg[0])		# store x
コード例 #4
0
ファイル: gen_gimli.py プロジェクト: jedisct1/gimli
def big_swap():
	reg = init_state()
	AVR.LDZ32(reg[0])
	AVR.LDZ32(reg[1])
	AVR.LDZ32(reg[2])
	AVR.LDZ32(reg[3])
	AVR.STZ32(reg[1])
	AVR.STZ32(reg[0])
	AVR.STZ32(reg[3])
	AVR.STZ32(reg[2])
コード例 #5
0
def load(reg):
    # load the first column
    # load x then y then z
    reg = init_state()
    AVR.LDZ32(reg[0])
    AVR.LDZ32(reg[3])
    AVR.ADIW(30, 8)
    AVR.LDZ32(reg[1])
    AVR.LDZ32(reg[4])
    AVR.ADIW(30, 8)
    AVR.LDZ32(reg[2])
    AVR.LDZ32(reg[5])
    AVR.PUSHZ()  # save current pointer (point to the first half of the state)
    return reg
コード例 #6
0
ファイル: gen_gimli.py プロジェクト: jedisct1/gimli
def load():
	# load the first column
	# load x then y then z
	reg = init_state()
	AVR.LDZ32(reg[0])
	AVR.LDZ32(reg[3])
	AVR.ADIW(30,8)
	AVR.LDZ32(reg[1])
	AVR.LDZ32(reg[4])
	AVR.ADIW(30,8)
	AVR.LDZ32(reg[2])
	AVR.LDZ32(reg[5])
コード例 #7
0
def stack_load_left_to_right(reg):
    AVR.POPZ()  # idx + 48
    AVR.PUSH32(reg[3])
    AVR.PUSH32(reg[0])
    # DO WE DO ONLY  A SIMPLE REINIT OR A FULL ???
    reg[0].sort()  # we only re init the values in r[0] and r[3]
    reg[3].sort()  # we only re init the values in r[0] and r[3]
    AVR.SBIW(30, 48)  # go the begining of the state
    AVR.LDZ32(reg[0])  # load r[0]
    AVR.LDZ32(reg[3])  # load r[3]
    AVR.ADIW(30, 40)  # go back to idx+48 : 4 + 4 + 16 + 16
    AVR.PUSHZ()  # push to the stack : idx + 48
    return reg
コード例 #8
0
def stack_load_right_to_left(reg):
    AVR.POPZ()  # idx + 40
    AVR.PUSH32(reg[3])
    AVR.PUSH32(reg[0])
    reg[3].sort()
    reg[0].sort()
    # reg = reinit_state(reg)			# we only re init the values in r[0] and r[3]
    AVR.SBIW(30, 32)  # skip the next two words
    AVR.LDZ32(reg[0])  # load r[0]
    AVR.LDZ32(reg[3])  # load r[3]
    AVR.ADIW(30, 24)  # skip back 8 + 16
    # current value of idx is +40
    AVR.PUSHZ()
    return reg
コード例 #9
0
def store_load_left_to_right(reg):
    AVR.POPZ()  # idx + 40
    AVR.STZ32(reg[5])  # store z
    AVR.STZ32(reg[2])  # store y
    AVR.SBIW(30, 8)
    AVR.STZ32(reg[4])  # store x
    AVR.STZ32(reg[1])  # store z
    AVR.SBIW(30, 8)
    AVR.STZ32(reg[3])  # store y
    AVR.STZ32(reg[0])  # store x
    reg = init_state()  # reinit the state.
    # current idx is 0
    AVR.ADIW(30, 24)  # go to idx + 12 + 8
    AVR.LDZ32(reg[1])  # load r[1]
    AVR.LDZ32(reg[4])  # load r[2]
    AVR.ADIW(30, 8)  # skip the next 8 words
    AVR.LDZ32(reg[2])  # load r[4]
    AVR.LDZ32(reg[5])  # load r[5]
    # pop the initial values of the other half from the stack ! :p
    AVR.POP32(reg[0])  # load r[0]
    AVR.POP32(reg[3])  # load r[1]
    # current value of idx is +48
    AVR.PUSHZ()
    return reg
コード例 #10
0
def spbox(idx, reg, t0, t1):
    x = reg[idx]
    y = reg[idx + 1]
    z = reg[idx + 2]
    AVR.comment('START SPBOX')
    AVR.comment('rotate x by 16: register renaming')
    # AVR.CLR0(t0)
    # AVR.ROL32(x,t0)
    # AVR.ROL32(x,t0)
    AVR.rotate8(x)  # rotate by 8
    AVR.rotate8(x)  # rotate by 8
    AVR.rotate8(x)  # rotate by 8
    # 24 + 2 = 26
    AVR.comment('rotate y by 9 : 1 + register renaming')
    AVR.CLR0(t0)
    AVR.ROL32(y, t0)
    AVR.rotate8(y)  # rotate by 8
    # 8 + 1 = 9
    AVR.comment('compute x')
    AVR.MOVW32(t1, x)
    AVR.MOVW32(t0, z)
    AVR.LSL32(t0)
    AVR.MOVW32(x, y)
    AVR.AND32(x, z)
    AVR.LSL32(x)
    AVR.LSL32(x)
    AVR.EOR32(x, t0)
    AVR.EOR32(x, t1)
    AVR.comment('compute y')
    AVR.MOVW32(t0, y)
    AVR.MOVW32(y, t1)
    AVR.OR32(y, z)
    AVR.LSL32(y)
    AVR.EOR32(y, t1)
    AVR.EOR32(y, t0)
    AVR.comment('compute z')
    AVR.AND32(t1, t0)
    AVR.LSL32(t1)
    AVR.LSL32(t1)
    AVR.LSL32(t1)
    AVR.EOR32(t0, t1)
    AVR.EOR32(z, t0)
    reg[idx], reg[idx + 2] = reg[idx + 2], reg[idx]
    AVR.comment('END SPBOX')
    return reg
コード例 #11
0
    AVR.POPZ()
    AVR.STZ32(reg[5])  # store z
    AVR.STZ32(reg[2])  # store y
    AVR.SBIW(30, 8)
    AVR.STZ32(reg[4])  # store x
    AVR.STZ32(reg[1])  # store z
    AVR.SBIW(30, 8)
    AVR.STZ32(reg[3])  # store y
    AVR.STZ32(reg[0])  # store x
    return reg


print('.global avr_gimli')
print('.type avr_gimli, @function')
print('')
AVR.comment('*********************************************************')
AVR.comment(' avr_gimli')
AVR.comment(' apply the SPbox on 3 32 bit integers')
AVR.comment('')
AVR.comment(' Inputs:')
AVR.comment(' x      in register R25:R24')
AVR.comment('')
print('avr_gimli:')
print('')
AVR.comment('  state has the following form :')
AVR.comment('')
AVR.comment('  First row:')
AVR.comment('  00 01 02 03')
AVR.comment('  04 05 06 07')
AVR.comment('  08 09 10 11')
AVR.comment('  12 13 14 15')
コード例 #12
0
ファイル: gen_gimli.py プロジェクト: jedisct1/gimli
def spbox(idx,reg, t0, t1):
	x = reg[idx]
	y = reg[idx+1]
	z = reg[idx+2]
	AVR.comment('START SPBOX')
	AVR.comment('rotate x by 16: no register renaming')
	AVR.PUSH(x[0])
	AVR.MOV(x[0],x[3])
	AVR.MOV(x[3],x[2])
	AVR.MOV(x[2],x[1])
	AVR.POP(x[1])

	# 24 + 2 = 26
	AVR.comment('rotate y by 9 : 1 + register renaming')

	AVR.CLR0(t0)
	AVR.ROL32(y,t0)
	AVR.PUSH(y[0])
	AVR.MOV(y[0],y[1])
	AVR.MOV(y[1],y[2])
	AVR.MOV(y[2],y[3])
	AVR.POP(y[3])

	AVR.comment('compute x')
	AVR.MOVW32(t1,x)
	AVR.MOVW32(t0,z)
	AVR.LSL32(t0)
	AVR.MOVW32(x,y)
	AVR.AND32(x,z)
	AVR.LSL32(x)
	AVR.LSL32(x)
	AVR.EOR32(x,t0)
	AVR.EOR32(x,t1)
	AVR.comment('compute y')
	AVR.MOVW32(t0,y)
	AVR.MOVW32(y,t1)
	AVR.OR32(y,z)
	AVR.LSL32(y)
	AVR.EOR32(y,t1)
	AVR.EOR32(y,t0)
	AVR.comment('compute z')
	AVR.AND32(t1,t0)
	AVR.LSL32(t1)
	AVR.LSL32(t1)
	AVR.LSL32(t1)
	AVR.EOR32(t0,t1)
	AVR.EOR32(z,t0)

	AVR.comment('swap x and z')
	AVR.PUSH32(z)
	AVR.MOV(z[0],x[0])
	AVR.MOV(z[1],x[1])
	AVR.MOV(z[2],x[2])
	AVR.MOV(z[3],x[3])
	AVR.POP32(x)
	return reg
コード例 #13
0
ファイル: gen_gimli.py プロジェクト: jedisct1/gimli
def store():
	reg = init_state()
	AVR.STZ32(reg[5])		# store z
	AVR.STZ32(reg[2])		# store y
	AVR.SBIW(30,8)
	AVR.STZ32(reg[4])		# store x
	AVR.STZ32(reg[1])		# store z
	AVR.SBIW(30,8)
	AVR.STZ32(reg[3])		# store y
	AVR.STZ32(reg[0])		# store x


print('.global avr_gimli')
print('.type avr_gimli, @function')
print('')
AVR.comment('*********************************************************')
AVR.comment(' avr_gimli')
AVR.comment(' apply the SPbox on 3 32 bit integers')
AVR.comment('')
AVR.comment(' Inputs:')
AVR.comment(' x      in register R25:R24')
AVR.comment('')
print('avr_gimli:')
print('')
AVR.comment('  state has the following form :')
AVR.comment('')
AVR.comment('  First row:')
AVR.comment('  00 01 02 03')
AVR.comment('  04 05 06 07')
AVR.comment('  08 09 10 11')
AVR.comment('  12 13 14 15')