def spbox(reg, idx, t0, t1): x = reg[idx] y = reg[idx + 2] z = reg[idx + 4] ARM_m0.comment('START SPBOX') ARM_m0.comment('rotate x <<< ' + str(R)) ARM_m0.LDI(t0, ror_r) ARM_m0.ROR(x, t0) ARM_m0.comment('rotate y <<< ' + str(S)) ARM_m0.LDI(t0, ror_s) ARM_m0.ROR(y, t0) ARM_m0.comment('compute x') ARM_m0.MOV(t1, x) ARM_m0.MOV(t0, z) ARM_m0.LSL(t0, 1) ARM_m0.MOV(x, y) ARM_m0.AND(x, z) ARM_m0.LSL(x, 2) ARM_m0.EOR(x, t0) ARM_m0.EOR(x, t1) ARM_m0.comment('compute y') ARM_m0.MOV(t0, y) ARM_m0.MOV(y, t1) ARM_m0.OR(y, z) ARM_m0.LSL(y, 1) ARM_m0.EOR(y, t1) ARM_m0.EOR(y, t0) ARM_m0.comment('compute z') ARM_m0.AND(t1, t0) ARM_m0.LSL(t1, 3) ARM_m0.EOR(t0, t1) ARM_m0.EOR(z, t0) reg[idx], reg[idx + 4] = reg[idx + 4], reg[idx] return reg
right = spbox(right, 0, 0, 7) right = spbox(right, 1, 0, 7) right = small_swap(right) right = spbox(right, 0, 0, 7) right = spbox(right, 1, 0, 7) right = spbox(right, 0, 0, 7) right = spbox(right, 1, 0, 7) right, left = permute(right, left) left = spbox(left, 0, 0, 7) left = spbox(left, 1, 0, 7) left = small_swap(left) load_cst(0, 24) ARM_m0.EOR(left[0], 0) # add constants left = spbox(left, 0, 0, 7) left = spbox(left, 1, 0, 7) left = spbox(left, 0, 0, 7) left = spbox(left, 1, 0, 7) # 3 rounds left, right = big_swap(left, right) left = spbox(left, 0, 0, 7) left = spbox(left, 1, 0, 7) left = spbox(left, 0, 0, 7) left = spbox(left, 1, 0, 7) left = small_swap(left) load_cst(0, 20)