From: Niels Möller Date: Thu, 5 Feb 2004 15:08:20 +0000 (+0100) Subject: (arcfour_crypt): Optimization suggested by Jonas X-Git-Tag: nettle_1.9_release_20040207~49 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0380a6c281646e73f28976290dbf0da767cfd97c;p=thirdparty%2Fnettle.git (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 --- diff --git a/arcfour.c b/arcfour.c index 03c9cd88..d5424348 100644 --- a/arcfour.c +++ b/arcfour.c @@ -63,14 +63,16 @@ arcfour_crypt(struct arcfour_ctx *ctx, const uint8_t *src) { register uint8_t i, j; + register int si, sj; i = ctx->i; j = ctx->j; while(length--) { i++; i &= 0xff; - j += ctx->S[i]; j &= 0xff; - SWAP(ctx->S[i], ctx->S[j]); - *dst++ = *src++ ^ ctx->S[ (ctx->S[i] + ctx->S[j]) & 0xff ]; + si = ctx->S[i]; + j += si; j &= 0xff; + sj = ctx->S[i] = ctx->S[j]; + *dst++ = *src++ ^ ctx->S[ (si + sj) & 0xff ]; } ctx->i = i; ctx->j = j; } @@ -80,14 +82,16 @@ arcfour_stream(struct arcfour_ctx *ctx, unsigned length, uint8_t *dst) { register uint8_t i, j; + register int si, sj; i = ctx->i; j = ctx->j; while(length--) { i++; i &= 0xff; - j += ctx->S[i]; j &= 0xff; - SWAP(ctx->S[i], ctx->S[j]); - *dst++ = ctx->S[ (ctx->S[i] + ctx->S[j]) & 0xff ]; + si = ctx->S[i]; + j += si; j &= 0xff; + sj = ctx->S[i] = ctx->S[j]; + *dst++ = ctx->S[ (si + sj) & 0xff ]; } ctx->i = i; ctx->j = j; }