Skip to content

Commit

Permalink
crypto: arc4 - improve performance by using u32 for ctx and variables
Browse files Browse the repository at this point in the history
This patch changes u8 in struct arc4_ctx and variables to u32 (as AMD seems
to have problem with u8 array). Below are tcrypt results of old 1-byte block
cipher versus ecb(arc4) with u8 and ecb(arc4) with u32.

tcrypt results, x86-64 (speed ratios: new-u32/old, new-u8/old):

                  u32    u8
AMD Phenom II   : x3.6   x2.7
Intel Core 2    : x2.0   x1.9

tcrypt results, i386 (speed ratios: new-u32/old, new-u8/old):

                  u32    u8
Intel Atom N260 : x1.5   x1.4

Cc: Jon Oberheide <[email protected]>
Signed-off-by: Jussi Kivilinna <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
jkivilin authored and herbertx committed Jun 14, 2012
1 parent ce6dd36 commit d366db6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crypto/arc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#define ARC4_BLOCK_SIZE 1

struct arc4_ctx {
u8 S[256];
u8 x, y;
u32 S[256];
u32 x, y;
};

static int arc4_set_key(struct crypto_tfm *tfm, const u8 *in_key,
Expand All @@ -39,7 +39,7 @@ static int arc4_set_key(struct crypto_tfm *tfm, const u8 *in_key,
ctx->S[i] = i;

for (i = 0; i < 256; i++) {
u8 a = ctx->S[i];
u32 a = ctx->S[i];
j = (j + in_key[k] + a) & 0xff;
ctx->S[i] = ctx->S[j];
ctx->S[j] = a;
Expand All @@ -53,9 +53,9 @@ static int arc4_set_key(struct crypto_tfm *tfm, const u8 *in_key,
static void arc4_crypt(struct arc4_ctx *ctx, u8 *out, const u8 *in,
unsigned int len)
{
u8 *const S = ctx->S;
u8 x, y, a, b;
u8 ty, ta, tb;
u32 *const S = ctx->S;
u32 x, y, a, b;
u32 ty, ta, tb;

if (len == 0)
return;
Expand Down

0 comments on commit d366db6

Please sign in to comment.