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