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