diff options
author | Niels Möller <nisse@lysator.liu.se> | 2004-02-05 16:08:20 +0100 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2004-02-05 16:08:20 +0100 |
commit | 0380a6c281646e73f28976290dbf0da767cfd97c (patch) | |
tree | a364fb1929caada5d3a49320bfb72f635ed177a3 | |
parent | 27f2a7805caa1d8529661f71881cbcd22330fd91 (diff) | |
download | nettle-0380a6c281646e73f28976290dbf0da767cfd97c.tar.gz |
(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
-rw-r--r-- | arcfour.c | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -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; } |