X-Git-Url: https://git.cryptolib.org/?p=avr-crypto-lib.git;a=blobdiff_plain;f=arcfour%2Farcfour.c;h=6c068a8023ee0acb487b33a313c050f6afa8e9b4;hp=0d929efa899edfeba59634a76688970cabcdbdb1;hb=b246a2a0589f234db6247255555df98f4c281c41;hpb=35dc9566e40c9f68fa216c70eaa6d5b0597448fe diff --git a/arcfour/arcfour.c b/arcfour/arcfour.c index 0d929ef..6c068a8 100644 --- a/arcfour/arcfour.c +++ b/arcfour/arcfour.c @@ -36,18 +36,24 @@ void arcfour_init(const void *key, uint16_t length_b, arcfour_ctx_t *ctx){ uint8_t t; uint8_t length_B = length_b/8; - uint16_t x,y=0; - for(x=0; x<= 255; ++x) + uint8_t x=0,y=0; + uint8_t *kptr=key; + do{ ctx->s[x]=x; + }while(++x); - for(x=0; x<= 255; ++x){ - y += ctx->s[x] + ((uint8_t*)key)[x % length_B]; + do{ + y += ctx->s[x] + *kptr++; + if(x==length_B){ + kptr = key; + } y &= 0xff; /* ctx->s[y] <--> ctx->s[x] */ t = ctx->s[y]; ctx->s[y] = ctx->s[x]; ctx->s[x] = t; - } + }while(++x); + ctx->i = ctx->j = 0; }