[PATCH 4/5] Enable AMD64 Whirlpool implementation for WIN64

Jussi Kivilinna jussi.kivilinna at iki.fi
Sat May 2 15:11:58 CEST 2015


* cipher/whirlpool-sse2-amd64.S: Enable when
HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS defined.
(ELF): New macro to mask lines with ELF specific commands.
* cipher/whirlpool.c (USE_AMD64_ASM): Enable when
HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS defined.
[USE_AMD64_ASM] (ASM_FUNC_ABI, ASM_EXTRA_STACK): New.
[USE_AMD64_ASM] (_gcry_whirlpool_transform_amd64): Add ASM_FUNC_ABI to
prototype.
[USE_AMD64_ASM] (whirlpool_transform): Add ASM_EXTRA_STACK to stack
burn value.
--

Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
 cipher/whirlpool-sse2-amd64.S |   13 ++++++++++---
 cipher/whirlpool.c            |   15 ++++++++++++---
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/cipher/whirlpool-sse2-amd64.S b/cipher/whirlpool-sse2-amd64.S
index d0bcf2d..e98b831 100644
--- a/cipher/whirlpool-sse2-amd64.S
+++ b/cipher/whirlpool-sse2-amd64.S
@@ -20,7 +20,8 @@
 
 #ifdef __x86_64
 #include <config.h>
-#if defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) && defined(USE_WHIRLPOOL)
+#if (defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \
+     defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS)) && defined(USE_WHIRLPOOL)
 
 #ifdef __PIC__
 #  define RIP %rip
@@ -28,6 +29,12 @@
 #  define RIP
 #endif
 
+#ifdef HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS
+# define ELF(...) __VA_ARGS__
+#else
+# define ELF(...) /*_*/
+#endif
+
 .text
 
 /* look-up table offsets on RTAB */
@@ -157,7 +164,7 @@
 
 .align 8
 .globl _gcry_whirlpool_transform_amd64
-.type  _gcry_whirlpool_transform_amd64, at function;
+ELF(.type  _gcry_whirlpool_transform_amd64, at function;)
 
 _gcry_whirlpool_transform_amd64:
 	/* input:
@@ -329,7 +336,7 @@ _gcry_whirlpool_transform_amd64:
 .Lskip:
 	movl $(STACK_MAX + 8), %eax;
 	ret;
-.size _gcry_whirlpool_transform_amd64,.-_gcry_whirlpool_transform_amd64;
+ELF(.size _gcry_whirlpool_transform_amd64,.-_gcry_whirlpool_transform_amd64;)
 
 #endif
 #endif
diff --git a/cipher/whirlpool.c b/cipher/whirlpool.c
index 2732f63..5f224a1 100644
--- a/cipher/whirlpool.c
+++ b/cipher/whirlpool.c
@@ -42,7 +42,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
 
@@ -1192,9 +1193,17 @@ whirlpool_init (void *ctx, unsigned int flags)
 
 #ifdef USE_AMD64_ASM
 
+#ifdef HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS
+# define ASM_FUNC_ABI __attribute__((sysv_abi))
+# define ASM_EXTRA_STACK (10 * 16)
+#else
+# define ASM_FUNC_ABI
+# define ASM_EXTRA_STACK 0
+#endif
+
 extern unsigned int
 _gcry_whirlpool_transform_amd64(u64 *state, const unsigned char *data,
-	size_t nblks, const struct whirlpool_tables_s *tables);
+    size_t nblks, const struct whirlpool_tables_s *tables) ASM_FUNC_ABI;
 
 static unsigned int
 whirlpool_transform (void *ctx, const unsigned char *data, size_t nblks)
@@ -1202,7 +1211,7 @@ whirlpool_transform (void *ctx, const unsigned char *data, size_t nblks)
   whirlpool_context_t *context = ctx;
 
   return _gcry_whirlpool_transform_amd64(
-		context->hash_state, data, nblks, &tab);
+		context->hash_state, data, nblks, &tab) + ASM_EXTRA_STACK;
 }
 
 #else /* USE_AMD64_ASM */




More information about the Gcrypt-devel mailing list