diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2013-12-30 15:10:13 +0200 |
---|---|---|
committer | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2013-12-30 15:10:13 +0200 |
commit | 7547898109c72a97e3102b2a045ee4fdb2aa40bf (patch) | |
tree | 2f49ce05d804a1587435633a4b11cddc94fbf0c5 /cipher/arcfour.c | |
parent | a05be441d8cd89b90d8d58e3a343a436dae377d0 (diff) | |
download | libgcrypt-7547898109c72a97e3102b2a045ee4fdb2aa40bf.tar.gz |
Add AMD64 assembly implementation for arcfour
* cipher/Makefile.am: Add 'arcfour-amd64.S'.
* cipher/arcfour-amd64.S: New.
* cipher/arcfour.c (USE_AMD64_ASM): New.
[USE_AMD64_ASM] (ARCFOUR_context, _gcry_arcfour_amd64)
(encrypt_stream): New.
* configure.ac [host=x86_64]: Add 'arcfour-amd64.lo'.
--
Patch adds Marc Bevand's public-domain AMD64 assembly implementation of RC4 to
libgcrypt. Original implementation is at:
http://www.zorinaq.com/papers/rc4-amd64.html
Benchmarks on Intel i5-4570 (3200 Mhz):
New:
ARCFOUR | nanosecs/byte mebibytes/sec cycles/byte
STREAM enc | 1.29 ns/B 737.7 MiB/s 4.14 c/B
STREAM dec | 1.31 ns/B 730.6 MiB/s 4.18 c/B
Old (C-language):
ARCFOUR | nanosecs/byte mebibytes/sec cycles/byte
STREAM enc | 2.09 ns/B 457.4 MiB/s 6.67 c/B
STREAM dec | 2.09 ns/B 457.2 MiB/s 6.68 c/B
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'cipher/arcfour.c')
-rw-r--r-- | cipher/arcfour.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/cipher/arcfour.c b/cipher/arcfour.c index d692c84a..27537bfd 100644 --- a/cipher/arcfour.c +++ b/cipher/arcfour.c @@ -31,8 +31,33 @@ #include "g10lib.h" #include "cipher.h" +/* USE_AMD64_ASM indicates whether to use AMD64 assembly code. */ +#undef USE_AMD64_ASM +#if defined(__x86_64__) && defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) +# define USE_AMD64_ASM 1 +#endif + static const char *selftest(void); +#ifdef USE_AMD64_ASM + +typedef struct { + u32 sbox[256]; + u32 idx_i, idx_j; +} ARCFOUR_context; + +void _gcry_arcfour_amd64(void *key, size_t len, const byte *indata, + byte *outdata); + +static void +encrypt_stream (void *context, + byte *outbuf, const byte *inbuf, size_t length) +{ + _gcry_arcfour_amd64 (context, length, inbuf, outbuf ); +} + +#else /*!USE_AMD64_ASM*/ + typedef struct { byte sbox[256]; int idx_i, idx_j; @@ -96,6 +121,8 @@ encrypt_stream (void *context, _gcry_burn_stack (64); } +#endif /*!USE_AMD64_ASM*/ + static gcry_err_code_t do_arcfour_setkey (void *context, const byte *key, unsigned int keylen) |