X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=arcfour-asm.S;h=1ef8218ce971a608ffaf096959dc40fb63141804;hb=8f855d283a31a468ea014774c4723a8b77b81644;hp=ec0eeebc879aa7b6706f45031f40a0b257fbea41;hpb=6bca96e560e6097aa5b225fad67f2e2a27f4182f;p=avr-crypto-lib.git diff --git a/arcfour-asm.S b/arcfour-asm.S index ec0eeeb..1ef8218 100644 --- a/arcfour-asm.S +++ b/arcfour-asm.S @@ -1,6 +1,6 @@ /* arcfour-asm.S */ /* - This file is part of the Crypto-avr-lib/microcrypt-lib. + This file is part of the AVR-Crypto-Lib. Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) This program is free software: you can redistribute it and/or modify @@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ + /* * File: arcfour-asm.S * Author: Daniel Otte @@ -25,68 +26,60 @@ * */ +#include +#include "avr-asm-macros.S" + /* +---+---+---------------------+ * | i | j | ......<256>........ | * +---+---+---------------------+ */ .global arcfour_init - -;== arcfour_init == -; this function initialises the context -; param1: 16-bit pointer to a ctx struct -; given in r25,r24 -; param2: 16-bit pointer to a key -; given in r23,r22 -; param1: 8-bit integer indicating keylength in byte -; given in r20 - +/* + *== arcfour_init == + * this function initialises the context + * param1: 16-bit pointer to the key + * given in r24:r25 + * param2: 8-bit integer indicating keylength in byte + * given in r22 + * param3: 16-bit pointer to a ctx struct + * given in r20:r21 + */ arcfour_init: - push r29 - push r28 - push r2 - - movw r26, r24 /* X points to ctx */ - movw r30, r22 /* Z points to key */ + push_ r28, r29 + movw r26, r20 /* X points to ctx */ + movw r30, r24 /* Z points to key */ st X+, r1 - st X+, r1 /* X points to S */ + st X+, r1 /* X points to S */ + movw r20, r26 /* store pointer to S in r21:r20 */ 1: st X+, r1 inc r1 brne 1b - adiw r24, 2 /* r24:r25 points to S */ - clr r21 /* r21 is j */ - mov r18, r20 /* r18 is keyindex counter */ + movw r26, r20 + add r22, r30 /* r18 is keyindex counter */ clr r0 + clr r19 2: - movw r26, r24 - ld r19, Z+ - add r21, r19 /* j+= key[i%length] */ - - add r26, r1 - adc r27, r0 - ld r19, X - add r21, r19 /* j += S[i] */ - - dec r18 /* check the key-index counter */ + ld r23, X + ld r18, Z+ + add r19, r18 + add r19, r23 + movw r28, r20 /* load pointer to S in Y */ + add r28, r19 + adc r29, r1 + ld r18, Y + st Y, r23 + st X+, r18 + cp r30, r22 brne 3f - movw r30, r22 - mov r18, r20 -3: /* now swap(S[i], S[j]) */ /* r19 is still S[i] */ - movw r28, r24 - add r28, r21 - adc r29, r0 /* Y points to S[j]*/ - ld r2, Y - st Y, r19 - st X, r2 - inc r1 + movw r30, r24 +3: + inc r0 brne 2b - - pop r2 - pop r28 - pop r29 + pop_ r29, r28 ret /*