diff options
author | Jussi Kivilinna <jussi.kivilinna@mbnet.fi> | 2012-06-09 11:25:46 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2012-06-13 22:07:23 -0400 |
commit | d366db605c8c4a9878589bc4a87e55f6063184ac (patch) | |
tree | a4984fee60973f52676ab9d9def30476ea0968bd /crypto/arc4.c | |
parent | ce6dd368984068c8938e8d3fba8e292ef63cee97 (diff) |
crypto: arc4 - improve performance by using u32 for ctx and variables
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 <jon@oberheide.org>
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/arc4.c')
-rw-r--r-- | crypto/arc4.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/crypto/arc4.c b/crypto/arc4.c index 07913fc52c4e..5a772c3657d5 100644 --- a/crypto/arc4.c +++ b/crypto/arc4.c | |||
@@ -22,8 +22,8 @@ | |||
22 | #define ARC4_BLOCK_SIZE 1 | 22 | #define ARC4_BLOCK_SIZE 1 |
23 | 23 | ||
24 | struct arc4_ctx { | 24 | struct arc4_ctx { |
25 | u8 S[256]; | 25 | u32 S[256]; |
26 | u8 x, y; | 26 | u32 x, y; |
27 | }; | 27 | }; |
28 | 28 | ||
29 | static int arc4_set_key(struct crypto_tfm *tfm, const u8 *in_key, | 29 | static int arc4_set_key(struct crypto_tfm *tfm, const u8 *in_key, |
@@ -39,7 +39,7 @@ static int arc4_set_key(struct crypto_tfm *tfm, const u8 *in_key, | |||
39 | ctx->S[i] = i; | 39 | ctx->S[i] = i; |
40 | 40 | ||
41 | for (i = 0; i < 256; i++) { | 41 | for (i = 0; i < 256; i++) { |
42 | u8 a = ctx->S[i]; | 42 | u32 a = ctx->S[i]; |
43 | j = (j + in_key[k] + a) & 0xff; | 43 | j = (j + in_key[k] + a) & 0xff; |
44 | ctx->S[i] = ctx->S[j]; | 44 | ctx->S[i] = ctx->S[j]; |
45 | ctx->S[j] = a; | 45 | ctx->S[j] = a; |
@@ -53,9 +53,9 @@ static int arc4_set_key(struct crypto_tfm *tfm, const u8 *in_key, | |||
53 | static void arc4_crypt(struct arc4_ctx *ctx, u8 *out, const u8 *in, | 53 | static void arc4_crypt(struct arc4_ctx *ctx, u8 *out, const u8 *in, |
54 | unsigned int len) | 54 | unsigned int len) |
55 | { | 55 | { |
56 | u8 *const S = ctx->S; | 56 | u32 *const S = ctx->S; |
57 | u8 x, y, a, b; | 57 | u32 x, y, a, b; |
58 | u8 ty, ta, tb; | 58 | u32 ty, ta, tb; |
59 | 59 | ||
60 | if (len == 0) | 60 | if (len == 0) |
61 | return; | 61 | return; |