From c284ea4aeae3fdf4c935b0f61e3bac2fa777f3bc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Thu, 5 Feb 2004 19:40:06 +0100
Subject: [PATCH] * x86/arcfour-crypt.asm (nettle_arcfour_crypt): Bug fix, half
 of the S array swap was forgotten. * arcfour.c (arcfour_stream): Likewise. *
 arcfour-crypt.c (arcfour_crypt): Likewise.

Rev: src/nettle/ChangeLog:1.233
Rev: src/nettle/arcfour-crypt.c:1.2
Rev: src/nettle/arcfour.c:1.6
Rev: src/nettle/x86/arcfour-crypt.asm:1.5
---
 ChangeLog             | 13 +++++++++++++
 arcfour-crypt.c       |  1 +
 arcfour.c             |  1 +
 x86/arcfour-crypt.asm |  3 ++-
 4 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index ad65f733..30f84e2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2004-02-05  Niels Möller  <nisse@lysator.liu.se>
+
+	* testsuite/arcfour-test.c (test_main): Use test_cipher_stream.
+
+	* testsuite/testutils.c (test_cipher_stream): New function, that
+	tries dividing the input into varying size blocks before
+	processing. 
+
+	* x86/arcfour-crypt.asm (nettle_arcfour_crypt): Bug fix, half of
+	the S array swap was forgotten.
+	* arcfour.c (arcfour_stream): Likewise.
+	* arcfour-crypt.c (arcfour_crypt): Likewise.
+
 2004-02-05  Niels Möller  <niels@s3.kth.se>
 
 	* x86/arcfour-crypt.asm (nettle_arcfour_crypt): Must store the new
diff --git a/arcfour-crypt.c b/arcfour-crypt.c
index e3d678ff..78f68311 100644
--- a/arcfour-crypt.c
+++ b/arcfour-crypt.c
@@ -46,6 +46,7 @@ arcfour_crypt(struct arcfour_ctx *ctx,
       si = ctx->S[i];
       j += si; j &= 0xff;
       sj = ctx->S[i] = ctx->S[j];
+      ctx->S[j] = si;
       *dst++ = *src++ ^ ctx->S[ (si + sj) & 0xff ];
     }
   ctx->i = i; ctx->j = j;
diff --git a/arcfour.c b/arcfour.c
index da039428..d8334222 100644
--- a/arcfour.c
+++ b/arcfour.c
@@ -70,6 +70,7 @@ arcfour_stream(struct arcfour_ctx *ctx,
       si = ctx->S[i];
       j += si; j &= 0xff;
       sj = ctx->S[i] = ctx->S[j];
+      ctx->S[j] = si;
       *dst++ = ctx->S[ (si + sj) & 0xff ];
     }
   ctx->i = i; ctx->j = j;
diff --git a/x86/arcfour-crypt.asm b/x86/arcfour-crypt.asm
index 007315ae..b997abaf 100644
--- a/x86/arcfour-crypt.asm
+++ b/x86/arcfour-crypt.asm
@@ -54,7 +54,8 @@ nettle_arcfour_crypt:
 	movzbl  (%ebp, %eax), %ecx	C  si. Clears high bytes
 	addb    %cl, %bl
 	movb    (%ebp, %ebx), %ch	C  sj
-	movb    %ch, (%ebp, %eax)
+	movb    %ch, (%ebp, %eax)	C  S[i] = sj
+	movb	%cl, (%ebp, %ebx)	C  C[j] = si
 	addb    %ch, %cl
 	xorb    %ch, %ch		C  Clear, so it can be used
 					C  for indexing.
-- 
GitLab