Commit 0380a6c2 authored by Niels Möller's avatar Niels Möller

(arcfour_crypt): Optimization suggested by Jonas

Walldén. Makes arcfour up to 50% faster on x86 and ppc, and
probably on other architectures as well.

Rev: src/nettle/arcfour.c:1.4
parent 27f2a780
...@@ -63,14 +63,16 @@ arcfour_crypt(struct arcfour_ctx *ctx, ...@@ -63,14 +63,16 @@ arcfour_crypt(struct arcfour_ctx *ctx,
const uint8_t *src) const uint8_t *src)
{ {
register uint8_t i, j; register uint8_t i, j;
register int si, sj;
i = ctx->i; j = ctx->j; i = ctx->i; j = ctx->j;
while(length--) while(length--)
{ {
i++; i &= 0xff; i++; i &= 0xff;
j += ctx->S[i]; j &= 0xff; si = ctx->S[i];
SWAP(ctx->S[i], ctx->S[j]); j += si; j &= 0xff;
*dst++ = *src++ ^ ctx->S[ (ctx->S[i] + ctx->S[j]) & 0xff ]; sj = ctx->S[i] = ctx->S[j];
*dst++ = *src++ ^ ctx->S[ (si + sj) & 0xff ];
} }
ctx->i = i; ctx->j = j; ctx->i = i; ctx->j = j;
} }
...@@ -80,14 +82,16 @@ arcfour_stream(struct arcfour_ctx *ctx, ...@@ -80,14 +82,16 @@ arcfour_stream(struct arcfour_ctx *ctx,
unsigned length, uint8_t *dst) unsigned length, uint8_t *dst)
{ {
register uint8_t i, j; register uint8_t i, j;
register int si, sj;
i = ctx->i; j = ctx->j; i = ctx->i; j = ctx->j;
while(length--) while(length--)
{ {
i++; i &= 0xff; i++; i &= 0xff;
j += ctx->S[i]; j &= 0xff; si = ctx->S[i];
SWAP(ctx->S[i], ctx->S[j]); j += si; j &= 0xff;
*dst++ = ctx->S[ (ctx->S[i] + ctx->S[j]) & 0xff ]; sj = ctx->S[i] = ctx->S[j];
*dst++ = ctx->S[ (si + sj) & 0xff ];
} }
ctx->i = i; ctx->j = j; ctx->i = i; ctx->j = j;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment