X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=arcfour.c;h=93b2e26bd2e1cd61c34bf8d5bc761c22486b5675;hb=0f66a12e93ed43904c30810ac33c79c87befafe7;hp=13fb159e7aff4e559e69e91327935e2feb93aca9;hpb=4d76909e4282baf1420ee309e270384246b241b8;p=avr-crypto-lib.git diff --git a/arcfour.c b/arcfour.c index 13fb159..93b2e26 100644 --- a/arcfour.c +++ b/arcfour.c @@ -33,15 +33,16 @@ * length is length of key in bytes! */ -void arcfour_init(arcfour_ctx_t *ctx, void *key, uint8_t length_B){ +void arcfour_init(const void *key, uint8_t length_B, arcfour_ctx_t *ctx){ uint8_t t; - unsigned x,y=0; + uint16_t x,y=0; for(x=0; x<= 255; ++x) ctx->s[x]=x; for(x=0; x<= 255; ++x){ y += ctx->s[x] + ((uint8_t*)key)[x % length_B]; y &= 0xff; + /* ctx->s[y] <--> ctx->s[x] */ t = ctx->s[y]; ctx->s[y] = ctx->s[x]; ctx->s[x] = t; @@ -53,6 +54,7 @@ uint8_t arcfour_gen(arcfour_ctx_t *ctx){ uint8_t t; ctx->i++; ctx->j += ctx->s[ctx->i]; + /* ctx->s[i] <--> ctx->s[j] */ t = ctx->s[ctx->j]; ctx->s[ctx->j] = ctx->s[ctx->i]; ctx->s[ctx->i] = t;