From fabad4ec561c343bbeba87450a6aedbc07ab1750 Mon Sep 17 00:00:00 2001 From: bg Date: Thu, 11 Dec 2008 17:46:12 +0000 Subject: [PATCH] even more ASM-fun now only decryption needs C-Stub --- seed-asm.S | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++- seed-stub.c | 5 +- 2 files changed, 164 insertions(+), 5 deletions(-) diff --git a/seed-asm.S b/seed-asm.S index 62d8420..9abad3f 100644 --- a/seed-asm.S +++ b/seed-asm.S @@ -477,7 +477,7 @@ seed_getnextkeys: push_range 10, 17 push r28 push r29 - andi r22, 0x0F +; andi r22, 0x0F bst r22,0 rcall compute_keys brtc even_round @@ -586,7 +586,7 @@ seed_getprevkeys: push r28 push r29 movw r28, r24 - andi r22, 0x0F +; andi r22, 0x0F bst r22, 0 brts r_odd_round r_even_round: @@ -676,3 +676,163 @@ seed_kc: .long 0x8d676ede .long 0x1bcfdcbc +/******************************************************************************/ +/* +#define L (((uint64_t*)buffer)[0]) +#define R (((uint64_t*)buffer)[1]) + +void seed_enc(void * buffer, seed_ctx_t * ctx){ + uint8_t r; + keypair_t k; + for(r=0; r<8; ++r){ + k = seed_getnextkeys(ctx->k, 2*r); +/ * + DEBUG_S("\r\n\tDBG ka,0: "); uart_hexdump(&k.k0, 4); + DEBUG_S("\r\n\tDBG ka,1: "); uart_hexdump(&k.k1, 4); + DEBUG_S("\r\n\t DBG L: "); uart_hexdump((uint8_t*)buffer+0, 8); + DEBUG_S("\r\n\t DBG R: "); uart_hexdump((uint8_t*)buffer+8, 8); +* / + L ^= seed_f_function(&R,k.k0,k.k1); + + k = seed_getnextkeys(ctx->k, 2*r+1); +/ * + DEBUG_S("\r\n\tDBG kb,0: "); uart_hexdump(&k.k0, 4); + DEBUG_S("\r\n\tDBG kb,1: "); uart_hexdump(&k.k1, 4); + DEBUG_S("\r\n\t DBG L: "); uart_hexdump((uint8_t*)buffer+8, 8); + DEBUG_S("\r\n\t DBG R: "); uart_hexdump((uint8_t*)buffer+0, 8); +* / + R ^= seed_f_function(&L,k.k0,k.k1); + } + / * just an exchange without temp. variable * / + L ^= R; + R ^= L; + L ^= R; +} +*/ +/* + * param buffer: r24:r25 + * param ctx: r22:r23 + */ +CTR = 9 +xLPTR = 10 +xRPTR = 12 +CPTR = 14 + +.global seed_enc +seed_enc: + push_range 9, 17 + push r28 + push r29 + clr CTR + movw xLPTR, r24 + adiw r24, 8 + movw xRPTR, r24 + movw CPTR, r22 +1: + movw r28, xLPTR + movw r24, CPTR + mov r22, CTR + lsl r22 + rcall seed_getnextkeys + + /* use pen & paper to understand the following permutation */ + movw r16, r22 + movw r22, r18 + movw r18, r24 + movw r24, r20 + movw r20, r22 + movw r22, r24 + movw r24, xRPTR + + rcall seed_f_function + + ld r0, Y + eor r0, r18 + st Y+, r0 + ld r0, Y + eor r0, r19 + st Y+, r0 + ld r0, Y + eor r0, r20 + st Y+, r0 + ld r0, Y + eor r0, r21 + st Y+, r0 + ld r0, Y + eor r0, r22 + st Y+, r0 + ld r0, Y + eor r0, r23 + st Y+, r0 + ld r0, Y + eor r0, r24 + st Y+, r0 + ld r0, Y + eor r0, r25 + st Y+, r0 + /* secound half */ + movw r24, CPTR + mov r22, CTR + lsl r22 + inc r22 + rcall seed_getnextkeys + + movw r16, r22 + movw r22, r18 + movw r18, r24 + movw r24, r20 + movw r20, r22 + movw r22, r24 + movw r24, xLPTR + + rcall seed_f_function + + ld r0, Y + eor r0, r18 + st Y+, r0 + ld r0, Y + eor r0, r19 + st Y+, r0 + ld r0, Y + eor r0, r20 + st Y+, r0 + ld r0, Y + eor r0, r21 + st Y+, r0 + ld r0, Y + eor r0, r22 + st Y+, r0 + ld r0, Y + eor r0, r23 + st Y+, r0 + ld r0, Y + eor r0, r24 + st Y+, r0 + ld r0, Y + eor r0, r25 + st Y+, r0 + + inc CTR + bst CTR, 3 + brts 3f + rjmp 1b +3: + movw r28, xLPTR + movw r30, xRPTR + ldi r17, 8 +4: + ld r10, Y + ld r11, Z + st Z+, r10 + st Y+, r11 + dec r17 + brne 4b +5: + pop r29 + pop r28 + pop_range 9, 17 + ret + + + + diff --git a/seed-stub.c b/seed-stub.c index d31665c..d9c2289 100644 --- a/seed-stub.c +++ b/seed-stub.c @@ -44,7 +44,7 @@ keypair_t seed_getnextkeys(uint32_t *keystate, uint8_t curround); keypair_t seed_getprevkeys(uint32_t *keystate, uint8_t curround); /******************************************************************************/ - +#if 0 #define L (((uint64_t*)buffer)[0]) #define R (((uint64_t*)buffer)[1]) @@ -75,6 +75,7 @@ void seed_enc(void * buffer, seed_ctx_t * ctx){ R ^= L; L ^= R; } +#endif /******************************************************************************/ @@ -117,5 +118,3 @@ void seed_dec(void * buffer, seed_ctx_t * ctx){ - - -- 2.39.5