summaryrefslogtreecommitdiff
path: root/arcfour.c
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2004-02-05 16:08:20 +0100
committerNiels Möller <nisse@lysator.liu.se>2004-02-05 16:08:20 +0100
commit0380a6c281646e73f28976290dbf0da767cfd97c (patch)
treea364fb1929caada5d3a49320bfb72f635ed177a3 /arcfour.c
parent27f2a7805caa1d8529661f71881cbcd22330fd91 (diff)
downloadnettle-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
Diffstat (limited to 'arcfour.c')
-rw-r--r--arcfour.c16
1 files changed, 10 insertions, 6 deletions
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;
}