BLOCK_CIPHERS += $(ALGO_NAME)
-$(ALGO_NAME)_OBJ := serpent.o serpent-sboxes-bitslice.o memxor.o
+$(ALGO_NAME)_OBJ := serpent-asm.o serpent-sboxes-bitslice.o memxor.o
$(ALGO_NAME)_TEST_BIN := main-serpent-test.o debug.o uart.o serial-tools.o \
nessie_bc_test.o nessie_common.o cli.o performance_test.o
$(ALGO_NAME)_NESSIE_TEST := "nessie"
BLOCK_CIPHERS += $(ALGO_NAME)
-$(ALGO_NAME)_OBJ := serpent.o serpent-sboxes-fast.o memxor.o
+$(ALGO_NAME)_OBJ := serpent-asm.o serpent-sboxes-fast.o memxor.o
$(ALGO_NAME)_TEST_BIN := main-serpent-test.o debug.o uart.o serial-tools.o \
nessie_bc_test.o nessie_common.o cli.o performance_test.o
$(ALGO_NAME)_NESSIE_TEST := "nessie"
BLOCK_CIPHERS += $(ALGO_NAME)
-$(ALGO_NAME)_OBJ := serpent.o serpent-asm.o serpent-sboxes-small.o memxor.o
+$(ALGO_NAME)_OBJ := serpent-asm.o serpent-sboxes-small.o memxor.o
$(ALGO_NAME)_TEST_BIN := main-serpent-test.o debug.o uart.o serial-tools.o \
nessie_bc_test.o nessie_common.o cli.o performance_test.o
$(ALGO_NAME)_NESSIE_TEST := "nessie"
T2 = 22
T3 = 23
-.global serpent_lt
serpent_lt:
push_range 4, 17
movw r26, r24
pop_range 4, 17
ret
-
#endif
+
T0 = 22
T1 = 23
T2 = 24
brne 1b
ret
-.global serpent_lt
serpent_lt:
/* X0 := X0 <<< 13 */
movw r26, r24
rcall memrotr32
ret
-.global serpent_inv_lt
serpent_inv_lt:
/* X0 := X0 >>> 5 */
movw r26, r24
/* trashes:
* r20-r25, r30-r31
*/
-.global serpent_gen_w
serpent_gen_w:
movw r30, r24
/* ^i^b[0]*/
stack_free 32
ret
+/*
+ * void serpent_enc(void* buffer, const serpent_ctx_t* ctx){
+ */
+/*
+ * param buffer is passed in r24:r25
+ * param ctx is passed in r22:r23
+ */
+.global serpent_enc
+serpent_enc:
+
+ push_ r12, r13, r14, r15, r16
+ clr r16
+ movw r14, r24
+ movw r12, r22
+1:
+ movw r24, r14
+ movw r22, r12
+ ldi r20, 16
+ add r12, r20
+ adc r13, r1
+ clr r21
+ rcall memxor
+ movw r24, r14
+ mov r22, r16
+ rcall sbox128
+ movw r24, r14
+ rcall serpent_lt
+
+ inc r16
+ cpi r16, 31
+ brne 1b
+
+ movw r24, r14
+ movw r22, r12
+ ldi r20, 16
+ add r12, r20
+ adc r13, r1
+ clr r21
+ rcall memxor
+ movw r24, r14
+ mov r22, r16
+ rcall sbox128
+
+ inc r16
+ movw r24, r14
+ movw r22, r12
+ ldi r20, 16
+ clr r21
+ pop_ r16, r15, r14, r13, r12
+ rjmp memxor
+/*
+ * void serpent_dec(void* buffer, const serpent_ctx_t* ctx){
+ */
+/*
+ * param buffer is passed in r24:r25
+ * param ctx is passed in r22:r23
+ */
+.global serpent_dec
+serpent_dec:
+ push_ r12, r13, r14, r15, r16
+ movw r14, r24
+// ldi r16, lo8(32*16)
+// add r22, r16
+ ldi r16, hi8(32*16)
+ add r23, r16
+ movw r12, r22
+ ldi r20, 16
+ clr r21
+ rcall memxor
+
+ movw r24, r14
+ ldi r22, 31
+ rcall inv_sbox128
+
+ movw r24, r14
+ ldi r20, 16
+ sub r12, r20
+ sbc r13, r1
+ movw r22, r12
+ clr r21
+ rcall memxor
+ ldi r16, 31
+1:
+ dec r16
+ movw r24, r14
+ rcall serpent_inv_lt
+ movw r24, r14
+ mov r22, r16
+ rcall inv_sbox128
+ movw r24, r14
+ ldi r20, 16
+ sub r12, r20
+ sbc r13, r1
+ movw r22, r12
+ clr r21
+ rcall memxor
+
+ tst r16
+ brne 1b
+ pop_ r16, r15, r14, r13, r12
+ ret
+
+
+
#define X2 (((uint32_t*)b)[2])
#define X3 (((uint32_t*)b)[3])
-void serpent_lt(uint8_t *b);
-/*
static void serpent_lt(uint8_t *b){
X0 = rotl32(X0, 13);
X2 = rotl32(X2, 3);
X0 = rotl32(X0, 5);
X2 = rotr32(X2, 10);
}
-*/
-
-static void serpent_inv_lt(uint8_t *b);
-/*
static void serpent_inv_lt(uint8_t *b){
X2 = rotl32(X2, 10);
X0 = rotr32(X0, 5);
X2 = rotr32(X2, 3);
X0 = rotr32(X0, 13);
}
-*/
-uint32_t serpent_gen_w(uint32_t * b, uint8_t i);
-/*
#define GOLDEN_RATIO 0x9e3779b9l
static uint32_t serpent_gen_w(uint32_t * b, uint8_t i){
ret = rotl32(ret, 11);
return ret;
}
-*/
-#if 0
+
void serpent_init(const void* key, uint16_t keysize_b, serpent_ctx_t* ctx){
uint32_t buffer[8];
uint8_t i,j;
sbox128(ctx->k[i],3-i);
}
}
-#endif
void serpent_enc(void* buffer, const serpent_ctx_t* ctx){
uint8_t i;
-