示例#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 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
示例#3
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