summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@iki.fi>2015-05-03 17:06:56 +0300
committerJussi Kivilinna <jussi.kivilinna@iki.fi>2015-05-14 10:18:06 +0300
commitc46b015bedba7ce0db68929bd33a86a54ab3d919 (patch)
tree412ff5dd1f1a421331684d5f9b6bf51f3c38d99c
parentee8fc4edcb3466b03246c8720b90731bf274ff1d (diff)
downloadlibgcrypt-c46b015bedba7ce0db68929bd33a86a54ab3d919.tar.gz
Enable AMD64 arcfour implementation on WIN64
* cipher/arcfour-amd64.S: Enable when HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS defined. (ELF): New macro to mask lines with ELF specific commands. * cipher/arcfour.c (USE_AMD64_ASM): Enable when HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS defined. (do_encrypt, do_decrypt) [HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS]: Use assembly block to call AMD64 assembly function. -- Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
-rw-r--r--cipher/arcfour-amd64.S13
-rw-r--r--cipher/arcfour.c17
2 files changed, 26 insertions, 4 deletions
diff --git a/cipher/arcfour-amd64.S b/cipher/arcfour-amd64.S
index 8b8031a1..2e52ea00 100644
--- a/cipher/arcfour-amd64.S
+++ b/cipher/arcfour-amd64.S
@@ -15,12 +15,19 @@
#ifdef __x86_64__
#include <config.h>
-#if defined(USE_ARCFOUR) && defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS)
+#if defined(USE_ARCFOUR) && (defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \
+ defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS))
+
+#ifdef HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS
+# define ELF(...) __VA_ARGS__
+#else
+# define ELF(...) /*_*/
+#endif
.text
.align 16
.globl _gcry_arcfour_amd64
-.type _gcry_arcfour_amd64,@function
+ELF(.type _gcry_arcfour_amd64,@function)
_gcry_arcfour_amd64:
push %rbp
push %rbx
@@ -91,7 +98,7 @@ _gcry_arcfour_amd64:
pop %rbp
ret
.L__gcry_arcfour_amd64_end:
-.size _gcry_arcfour_amd64,.L__gcry_arcfour_amd64_end-_gcry_arcfour_amd64
+ELF(.size _gcry_arcfour_amd64,.L__gcry_arcfour_amd64_end-_gcry_arcfour_amd64)
#endif
#endif
diff --git a/cipher/arcfour.c b/cipher/arcfour.c
index 27537bfd..44e8ef46 100644
--- a/cipher/arcfour.c
+++ b/cipher/arcfour.c
@@ -33,7 +33,8 @@
/* 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)
+#if defined(__x86_64__) && (defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \
+ defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS))
# define USE_AMD64_ASM 1
#endif
@@ -53,7 +54,21 @@ static void
encrypt_stream (void *context,
byte *outbuf, const byte *inbuf, size_t length)
{
+#ifdef HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS
+ const void *fn = _gcry_arcfour_amd64;
+ /* Call SystemV ABI function without storing non-volatile XMM registers,
+ * as target function does not use vector instruction sets. */
+ asm volatile ("callq *%0\n\t"
+ : "+a" (fn),
+ "+D" (context),
+ "+S" (length),
+ "+d" (inbuf),
+ "+c" (outbuf)
+ :
+ : "cc", "memory", "r8", "r9", "r10", "r11");
+#else
_gcry_arcfour_amd64 (context, length, inbuf, outbuf );
+#endif
}
#else /*!USE_AMD64_ASM*/