From 0380a6c281646e73f28976290dbf0da767cfd97c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Thu, 5 Feb 2004 16:08:20 +0100
Subject: [PATCH] =?UTF-8?q?(arcfour=5Fcrypt):=20Optimization=20suggested?=
 =?UTF-8?q?=20by=20Jonas=20Walld=C3=A9n.=20Makes=20arcfour=20up=20to=2050%?=
 =?UTF-8?q?=20faster=20on=20x86=20and=20ppc,=20and=20probably=20on=20other?=
 =?UTF-8?q?=20architectures=20as=20well.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Rev: src/nettle/arcfour.c:1.4
---
 arcfour.c | 16 ++++++++++------
 1 file 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;
 }
-- 
GitLab