summaryrefslogtreecommitdiff
path: root/extra/yassl/taocrypt
diff options
context:
space:
mode:
authorAnirudh Mangipudi <anirudh.mangipudi@oracle.com>2014-02-06 11:16:55 +0530
committerAnirudh Mangipudi <anirudh.mangipudi@oracle.com>2014-02-06 11:16:55 +0530
commit1747a4564700fa51902e948d98fc2034703cabc6 (patch)
tree0bd61dbb63324ef8bbc6aae424c02decdd803a12 /extra/yassl/taocrypt
parent288f1ce10977bc88ab2c81e9a45a9809d2ccfa65 (diff)
downloadmariadb-git-1747a4564700fa51902e948d98fc2034703cabc6.tar.gz
Bug#14211271 ISSUES WITH SSL ON DEBIAN WHEEZY I386 AND KFREEBSD-I386
Problem: It was reported that on Debian and KFreeBSD platforms, i386 architecture machines certain SSL tests are failing. main.ssl_connect rpl.rpl_heartbeat_ssl rpl.rpl_ssl1 rpl.rpl_ssl main.ssl_cipher, main.func_encrypt were the tests that were reportedly failing (crashing). The reason for the crashes are said to be due to the assembly code of yaSSL. Solution: There was initially a workaround suggested i.e., to enable -DTAOCRYPT_DISABLE_X86ASM flag which would prevent the crash, but at an expense of 4X reduction of speed. Since this was unacceptable, the fix was the functions using assembly, now input variables from the function call using extended inline assembly on GCC instead of relying on direct assembly code.
Diffstat (limited to 'extra/yassl/taocrypt')
-rw-r--r--extra/yassl/taocrypt/include/integer.hpp8
-rw-r--r--extra/yassl/taocrypt/include/misc.hpp9
-rw-r--r--extra/yassl/taocrypt/src/aes.cpp82
-rw-r--r--extra/yassl/taocrypt/src/arc4.cpp49
-rw-r--r--extra/yassl/taocrypt/src/blowfish.cpp43
-rw-r--r--extra/yassl/taocrypt/src/des.cpp52
-rw-r--r--extra/yassl/taocrypt/src/integer.cpp6
-rw-r--r--extra/yassl/taocrypt/src/md5.cpp50
-rw-r--r--extra/yassl/taocrypt/src/rabbit.cpp15
-rw-r--r--extra/yassl/taocrypt/src/ripemd.cpp47
-rw-r--r--extra/yassl/taocrypt/src/sha.cpp51
-rw-r--r--extra/yassl/taocrypt/src/twofish.cpp49
12 files changed, 282 insertions, 179 deletions
diff --git a/extra/yassl/taocrypt/include/integer.hpp b/extra/yassl/taocrypt/include/integer.hpp
index e1a2ed5f426..68f3c4bbf39 100644
--- a/extra/yassl/taocrypt/include/integer.hpp
+++ b/extra/yassl/taocrypt/include/integer.hpp
@@ -46,6 +46,14 @@
#ifdef TAOCRYPT_X86ASM_AVAILABLE
+ #if defined(__GNUC__) && (__GNUC__ >= 4)
+ // GCC 4 or greater optimizes too much inline on recursive for bigint,
+ // -O3 just as fast without asm here anyway
+ #undef TAOCRYPT_X86ASM_AVAILABLE
+ #endif
+#endif
+
+#ifdef TAOCRYPT_X86ASM_AVAILABLE
#ifdef _M_IX86
#if (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 500)) || \
diff --git a/extra/yassl/taocrypt/include/misc.hpp b/extra/yassl/taocrypt/include/misc.hpp
index 1382d3690fb..f68abbda8da 100644
--- a/extra/yassl/taocrypt/include/misc.hpp
+++ b/extra/yassl/taocrypt/include/misc.hpp
@@ -124,15 +124,22 @@ void CleanUp();
// no gas on these systems ?, disable for now
-#if defined(__sun__) || defined (__APPLE__)
+#if defined(__sun__)
+ #undef TAOCRYPT_DISABLE_X86ASM
#define TAOCRYPT_DISABLE_X86ASM
#endif
// icc problem with -03 and integer, disable for now
#if defined(__INTEL_COMPILER)
+ #undef TAOCRYPT_DISABLE_X86ASM
#define TAOCRYPT_DISABLE_X86ASM
#endif
+// indpedent of build system, unless ia32 asm is enabled disable it
+#if !defined(TAOCRYPT_ENABLE_X86ASM)
+ #undef TAOCRYPT_DISABLE_X86ASM
+ #define TAOCRYPT_DISABLE_X86ASM
+#endif
// Turn on ia32 ASM for Big Integer
// CodeWarrior defines _MSC_VER
diff --git a/extra/yassl/taocrypt/src/aes.cpp b/extra/yassl/taocrypt/src/aes.cpp
index 9b04e7b0dbc..d04ef69c19f 100644
--- a/extra/yassl/taocrypt/src/aes.cpp
+++ b/extra/yassl/taocrypt/src/aes.cpp
@@ -52,7 +52,7 @@ void AES::Process(byte* out, const byte* in, word32 sz)
in += BLOCK_SIZE;
}
else if (mode_ == CBC) {
- if (dir_ == ENCRYPTION)
+ if (dir_ == ENCRYPTION) {
while (blocks--) {
r_[0] ^= *(word32*)in;
r_[1] ^= *(word32*)(in + 4);
@@ -65,7 +65,8 @@ void AES::Process(byte* out, const byte* in, word32 sz)
out += BLOCK_SIZE;
in += BLOCK_SIZE;
}
- else
+ }
+ else {
while (blocks--) {
AsmDecrypt(in, out, (void*)Td0);
@@ -78,6 +79,7 @@ void AES::Process(byte* out, const byte* in, word32 sz)
out += BLOCK_SIZE;
in += BLOCK_SIZE;
}
+ }
}
}
@@ -452,27 +454,31 @@ void AES::decrypt(const byte* inBlock, const byte* xorBlock,
#if defined(DO_AES_ASM)
#ifdef __GNUC__
- #define AS1(x) asm(#x);
- #define AS2(x, y) asm(#x ", " #y);
+ #define AS1(x) #x ";"
+ #define AS2(x, y) #x ", " #y ";"
#define PROLOG() \
- asm(".intel_syntax noprefix"); \
- AS2( movd mm3, edi ) \
- AS2( movd mm4, ebx ) \
- AS2( sub esp, 4 ) \
- AS2( movd mm7, ebp ) \
- AS2( mov [ebp - 4], esi ) \
- AS2( mov ecx, DWORD PTR [ebp + 8] ) \
- AS2( mov esi, DWORD PTR [ebp + 12] ) \
- AS2( mov ebp, DWORD PTR [ebp + 20] )
+ __asm__ __volatile__ \
+ ( \
+ ".intel_syntax noprefix;" \
+ "push ebx;" \
+ "push ebp;" \
+ "movd mm7, ebp;" \
+ "movd mm4, eax;" \
+ "mov ebp, edx;" \
+ "sub esp, 4;"
#define EPILOG() \
- AS2( mov esi, [ebp - 4] ) \
- AS2( mov esp, ebp ) \
- AS2( movd ebx, mm4 ) \
- AS2( movd edi, mm3 ) \
- AS1( emms ) \
- asm(".att_syntax");
+ "add esp, 4;" \
+ "pop ebp;" \
+ "pop ebx;" \
+ "emms;" \
+ ".att_syntax;" \
+ : \
+ : "c" (this), "S" (inBlock), "d" (boxes), "a" (outBlock) \
+ : "%edi", "memory", "cc" \
+ );
+
#else
#define AS1(x) __asm x
#define AS2(x, y) __asm x, y
@@ -504,6 +510,8 @@ void AES::decrypt(const byte* inBlock, const byte* xorBlock,
#ifdef _MSC_VER
__declspec(naked)
+#else
+ __attribute__ ((noinline))
#endif
void AES::AsmEncrypt(const byte* inBlock, byte* outBlock, void* boxes) const
{
@@ -537,7 +545,11 @@ void AES::AsmEncrypt(const byte* inBlock, byte* outBlock, void* boxes) const
AS2( xor ecx, DWORD PTR [edi + 8] ) // s2
AS2( xor edx, DWORD PTR [edi + 12] ) // s3
- AS1(loop1: )
+#ifdef _MSC_VER
+ AS1( loop1: ) // loop1
+#else
+ AS1(1: ) // loop1
+#endif
/* Put0 (mm0) =
Te0[get0,rs 24] ^
Te1[get1,rs 16] ^
@@ -652,7 +664,11 @@ void AES::AsmEncrypt(const byte* inBlock, byte* outBlock, void* boxes) const
AS1( dec edi )
AS2( movd mm5, edi )
- AS1( jnz loop1 )
+#ifdef _MSC_VER
+ AS1( jnz loop1) // loop1
+#else
+ AS1( jnz 1b ) // loop1
+#endif
// last round
/*
@@ -799,9 +815,9 @@ void AES::AsmEncrypt(const byte* inBlock, byte* outBlock, void* boxes) const
// store
#ifdef __GNUC__
- AS2( mov esi, DWORD PTR [ebp + 16] ) // outBlock
+ AS2( movd esi, mm4 ) // outBlock
#else
- AS2( mov esi, DWORD PTR [ebp + 12] ) // outBlock
+ AS2( mov esi, DWORD PTR [ebp + 12] ) // outBlock
#endif
AS1( bswap ecx )
@@ -818,7 +834,9 @@ void AES::AsmEncrypt(const byte* inBlock, byte* outBlock, void* boxes) const
#ifdef _MSC_VER
- __declspec(naked)
+ __declspec(naked)
+#else
+ __attribute__ ((noinline))
#endif
void AES::AsmDecrypt(const byte* inBlock, byte* outBlock, void* boxes) const
{
@@ -853,7 +871,11 @@ void AES::AsmDecrypt(const byte* inBlock, byte* outBlock, void* boxes) const
AS2( xor edx, DWORD PTR [edi + 12] ) // s3
- AS1(loop2: )
+#ifdef _MSC_VER
+ AS1( loop2: ) // loop2
+#else
+ AS1(2: ) // loop2
+#endif
/* Put0 (mm0) =
Td0[GETBYTE(get0, rs24)] ^
Td1[GETBYTE(get3, rs16)] ^
@@ -964,7 +986,11 @@ void AES::AsmDecrypt(const byte* inBlock, byte* outBlock, void* boxes) const
AS1( dec edi )
AS2( movd mm5, edi )
- AS1( jnz loop2 )
+#ifdef _MSC_VER
+ AS1( jnz loop2) // loop2
+#else
+ AS1( jnz 2b ) // loop2
+#endif
// last round
/*
@@ -1114,9 +1140,9 @@ void AES::AsmDecrypt(const byte* inBlock, byte* outBlock, void* boxes) const
// store
#ifdef __GNUC__
- AS2( mov esi, DWORD PTR [ebp + 16] ) // outBlock
+ AS2( movd esi, mm4 ) // outBlock
#else
- AS2( mov esi, DWORD PTR [ebp + 12] ) // outBlock
+ AS2( mov esi, DWORD PTR [ebp + 12] ) // outBlock
#endif
AS2( mov DWORD PTR [esi], eax )
AS2( mov DWORD PTR [esi + 4], ebx )
diff --git a/extra/yassl/taocrypt/src/arc4.cpp b/extra/yassl/taocrypt/src/arc4.cpp
index a76a37904f9..f5794ec2566 100644
--- a/extra/yassl/taocrypt/src/arc4.cpp
+++ b/extra/yassl/taocrypt/src/arc4.cpp
@@ -111,28 +111,27 @@ void ARC4::Process(byte* out, const byte* in, word32 length)
void ARC4::AsmProcess(byte* out, const byte* in, word32 length)
{
#ifdef __GNUC__
- #define AS1(x) asm(#x);
- #define AS2(x, y) asm(#x ", " #y);
+ #define AS1(x) #x ";"
+ #define AS2(x, y) #x ", " #y ";"
#define PROLOG() \
- asm(".intel_syntax noprefix"); \
- AS2( movd mm3, edi ) \
- AS2( movd mm4, ebx ) \
- AS2( movd mm5, esi ) \
- AS2( movd mm6, ebp ) \
- AS2( mov ecx, DWORD PTR [ebp + 8] ) \
- AS2( mov edi, DWORD PTR [ebp + 12] ) \
- AS2( mov esi, DWORD PTR [ebp + 16] ) \
- AS2( mov ebp, DWORD PTR [ebp + 20] )
+ __asm__ __volatile__ \
+ ( \
+ ".intel_syntax noprefix;" \
+ "push ebx;" \
+ "push ebp;" \
+ "mov ebp, eax;"
#define EPILOG() \
- AS2( movd ebp, mm6 ) \
- AS2( movd esi, mm5 ) \
- AS2( movd ebx, mm4 ) \
- AS2( mov esp, ebp ) \
- AS2( movd edi, mm3 ) \
- AS1( emms ) \
- asm(".att_syntax");
+ "pop ebp;" \
+ "pop ebx;" \
+ "emms;" \
+ ".att_syntax;" \
+ : \
+ : "c" (this), "D" (out), "S" (in), "a" (length) \
+ : "%edx", "memory", "cc" \
+ );
+
#else
#define AS1(x) __asm x
#define AS2(x, y) __asm x, y
@@ -178,7 +177,11 @@ void ARC4::AsmProcess(byte* out, const byte* in, word32 length)
AS2( movzx eax, BYTE PTR [ebp + ecx] )
-AS1( begin: )
+#ifdef _MSC_VER
+ AS1( loopStart: ) // loopStart
+#else
+ AS1( 0: ) // loopStart for some gas (need numeric for jump back
+#endif
// y = (y+a) & 0xff;
AS2( add edx, eax )
@@ -215,7 +218,11 @@ AS1( begin: )
AS1( inc edi )
AS1( dec DWORD PTR [esp] )
- AS1( jnz begin )
+#ifdef _MSC_VER
+ AS1( jnz loopStart ) // loopStart
+#else
+ AS1( jnz 0b ) // loopStart
+#endif
// write back to x_ and y_
@@ -225,6 +232,8 @@ AS1( begin: )
AS1( nothing: )
+ // inline adjust
+ AS2( add esp, 4 ) // fix room on stack
EPILOG()
}
diff --git a/extra/yassl/taocrypt/src/blowfish.cpp b/extra/yassl/taocrypt/src/blowfish.cpp
index cedae6af281..5cfd81e369c 100644
--- a/extra/yassl/taocrypt/src/blowfish.cpp
+++ b/extra/yassl/taocrypt/src/blowfish.cpp
@@ -54,7 +54,7 @@ void Blowfish::Process(byte* out, const byte* in, word32 sz)
in += BLOCK_SIZE;
}
else if (mode_ == CBC) {
- if (dir_ == ENCRYPTION)
+ if (dir_ == ENCRYPTION) {
while (blocks--) {
r_[0] ^= *(word32*)in;
r_[1] ^= *(word32*)(in + 4);
@@ -66,7 +66,8 @@ void Blowfish::Process(byte* out, const byte* in, word32 sz)
out += BLOCK_SIZE;
in += BLOCK_SIZE;
}
- else
+ }
+ else {
while (blocks--) {
AsmProcess(in, out);
@@ -78,6 +79,7 @@ void Blowfish::Process(byte* out, const byte* in, word32 sz)
out += BLOCK_SIZE;
in += BLOCK_SIZE;
}
+ }
}
}
@@ -222,23 +224,26 @@ void Blowfish::ProcessAndXorBlock(const byte* in, const byte* xOr, byte* out)
#if defined(DO_BLOWFISH_ASM)
#ifdef __GNUC__
- #define AS1(x) asm(#x);
- #define AS2(x, y) asm(#x ", " #y);
+ #define AS1(x) #x ";"
+ #define AS2(x, y) #x ", " #y ";"
#define PROLOG() \
- asm(".intel_syntax noprefix"); \
- AS2( movd mm3, edi ) \
- AS2( movd mm4, ebx ) \
- AS2( movd mm5, esi ) \
- AS2( mov ecx, DWORD PTR [ebp + 8] ) \
- AS2( mov esi, DWORD PTR [ebp + 12] )
-
+ __asm__ __volatile__ \
+ ( \
+ ".intel_syntax noprefix;" \
+ "push ebx;" \
+ "push ebp;" \
+ "movd mm3, eax;"
#define EPILOG() \
- AS2( movd esi, mm5 ) \
- AS2( movd ebx, mm4 ) \
- AS2( movd edi, mm3 ) \
- AS1( emms ) \
- asm(".att_syntax");
+ "pop ebp;" \
+ "pop ebx;" \
+ "emms;" \
+ ".att_syntax;" \
+ : \
+ : "c" (this), "S" (inBlock), "a" (outBlock) \
+ : "%edi", "%edx", "memory", "cc" \
+ );
+
#else
#define AS1(x) __asm x
#define AS2(x, y) __asm x, y
@@ -286,7 +291,9 @@ void Blowfish::ProcessAndXorBlock(const byte* in, const byte* xOr, byte* out)
#ifdef _MSC_VER
- __declspec(naked)
+ __declspec(naked)
+#else
+ __attribute__ ((noinline))
#endif
void Blowfish::AsmProcess(const byte* inBlock, byte* outBlock) const
{
@@ -335,7 +342,7 @@ void Blowfish::AsmProcess(const byte* inBlock, byte* outBlock) const
#endif
#ifdef __GNUC__
- AS2( mov edi, [ebp + 16] ) // outBlock
+ AS2( movd edi, mm3 ) // outBlock
#else
AS2( mov edi, [ebp + 12] ) // outBlock
#endif
diff --git a/extra/yassl/taocrypt/src/des.cpp b/extra/yassl/taocrypt/src/des.cpp
index 5cffeaea9c9..2b9a9d9019e 100644
--- a/extra/yassl/taocrypt/src/des.cpp
+++ b/extra/yassl/taocrypt/src/des.cpp
@@ -473,7 +473,7 @@ void DES_EDE3::ProcessAndXorBlock(const byte* in, const byte* xOr,
uses ecx
*/
-#define AsmIPERM() {\
+#define AsmIPERM() \
AS2( rol ebx, 4 ) \
AS2( mov ecx, eax ) \
AS2( xor ecx, ebx ) \
@@ -504,7 +504,7 @@ void DES_EDE3::ProcessAndXorBlock(const byte* in, const byte* xOr,
AS2( and ecx, 0xaaaaaaaa ) \
AS2( xor eax, ecx ) \
AS2( rol eax, 1 ) \
- AS2( xor ebx, ecx ) }
+ AS2( xor ebx, ecx )
/* Uses FPERM algorithm from above
@@ -514,7 +514,7 @@ void DES_EDE3::ProcessAndXorBlock(const byte* in, const byte* xOr,
uses ecx
*/
-#define AsmFPERM() {\
+#define AsmFPERM() \
AS2( ror ebx, 1 ) \
AS2( mov ecx, eax ) \
AS2( xor ecx, ebx ) \
@@ -545,7 +545,7 @@ void DES_EDE3::ProcessAndXorBlock(const byte* in, const byte* xOr,
AS2( and ecx, 0xf0f0f0f0 ) \
AS2( xor eax, ecx ) \
AS2( xor ebx, ecx ) \
- AS2( ror eax, 4 ) }
+ AS2( ror eax, 4 )
@@ -641,32 +641,34 @@ void DES_EDE3::ProcessAndXorBlock(const byte* in, const byte* xOr,
#ifdef _MSC_VER
- __declspec(naked)
+ __declspec(naked)
+#else
+ __attribute__ ((noinline))
#endif
void DES_EDE3::AsmProcess(const byte* in, byte* out, void* box) const
{
#ifdef __GNUC__
- #define AS1(x) asm(#x);
- #define AS2(x, y) asm(#x ", " #y);
-
- asm(".intel_syntax noprefix");
+ #define AS1(x) #x ";"
+ #define AS2(x, y) #x ", " #y ";"
#define PROLOG() \
- AS2( movd mm3, edi ) \
- AS2( movd mm4, ebx ) \
- AS2( movd mm5, esi ) \
- AS2( movd mm6, ebp ) \
- AS2( mov edx, DWORD PTR [ebp + 8] ) \
- AS2( mov esi, DWORD PTR [ebp + 12] ) \
- AS2( mov ebp, DWORD PTR [ebp + 20] )
-
- // ebp restored at end
- #define EPILOG() \
- AS2( movd edi, mm3 ) \
- AS2( movd ebx, mm4 ) \
- AS2( movd esi, mm5 ) \
- AS1( emms ) \
- asm(".att_syntax");
+ __asm__ __volatile__ \
+ ( \
+ ".intel_syntax noprefix;" \
+ "push ebx;" \
+ "push ebp;" \
+ "movd mm6, ebp;" \
+ "movd mm7, ecx;" \
+ "mov ebp, eax;"
+ #define EPILOG() \
+ "pop ebp;" \
+ "pop ebx;" \
+ "emms;" \
+ ".att_syntax;" \
+ : \
+ : "d" (this), "S" (in), "a" (box), "c" (out) \
+ : "%edi", "memory", "cc" \
+ );
#else
#define AS1(x) __asm x
@@ -756,7 +758,7 @@ void DES_EDE3::AsmProcess(const byte* in, byte* out, void* box) const
AS1( bswap eax )
#ifdef __GNUC__
- AS2( mov esi, DWORD PTR [ebp + 16] ) // outBlock
+ AS2( movd esi, mm7 ) // outBlock
#else
AS2( mov esi, DWORD PTR [ebp + 12] ) // outBlock
#endif
diff --git a/extra/yassl/taocrypt/src/integer.cpp b/extra/yassl/taocrypt/src/integer.cpp
index bfced6d0c74..c981b1bf786 100644
--- a/extra/yassl/taocrypt/src/integer.cpp
+++ b/extra/yassl/taocrypt/src/integer.cpp
@@ -55,7 +55,9 @@
#include <emmintrin.h>
#endif
#elif defined(_MSC_VER) && defined(_M_IX86)
- #pragma message("You do not seem to have the Visual C++ Processor Pack ")
+/* #pragma message("You do not seem to have the Visual C++ Processor Pack ")
+ #pragma message("installed, so use of SSE2 intrinsics will be disabled.")
+*/
#pragma message("installed, so use of SSE2 intrinsics will be disabled.")
#elif defined(__GNUC__) && defined(__i386__)
/* #warning You do not have GCC 3.3 or later, or did not specify the -msse2 \
@@ -73,7 +75,7 @@ template <class T>
CPP_TYPENAME AlignedAllocator<T>::pointer AlignedAllocator<T>::allocate(
size_type n, const void *)
{
- if (n > max_size())
+ if (n > this->max_size())
return 0;
if (n == 0)
return 0;
diff --git a/extra/yassl/taocrypt/src/md5.cpp b/extra/yassl/taocrypt/src/md5.cpp
index ee0d64acc17..e9a9e8fe517 100644
--- a/extra/yassl/taocrypt/src/md5.cpp
+++ b/extra/yassl/taocrypt/src/md5.cpp
@@ -223,32 +223,32 @@ void MD5::Update(const byte* data, word32 len)
#ifdef _MSC_VER
- __declspec(naked)
+ __declspec(naked)
+#else
+ __attribute__ ((noinline))
#endif
void MD5::AsmTransform(const byte* data, word32 times)
{
#ifdef __GNUC__
- #define AS1(x) asm(#x);
- #define AS2(x, y) asm(#x ", " #y);
+ #define AS1(x) #x ";"
+ #define AS2(x, y) #x ", " #y ";"
#define PROLOG() \
- asm(".intel_syntax noprefix"); \
- AS2( movd mm3, edi ) \
- AS2( movd mm4, ebx ) \
- AS2( movd mm5, esi ) \
- AS2( movd mm6, ebp ) \
- AS2( mov ecx, DWORD PTR [ebp + 8] ) \
- AS2( mov edi, DWORD PTR [ebp + 12] ) \
- AS2( mov eax, DWORD PTR [ebp + 16] )
-
+ __asm__ __volatile__ \
+ ( \
+ ".intel_syntax noprefix;" \
+ "push ebx;" \
+ "push ebp;"
#define EPILOG() \
- AS2( movd ebp, mm6 ) \
- AS2( movd esi, mm5 ) \
- AS2( movd ebx, mm4 ) \
- AS2( mov esp, ebp ) \
- AS2( movd edi, mm3 ) \
- AS1( emms ) \
- asm(".att_syntax");
+ "pop ebp;" \
+ "pop ebx;" \
+ "emms;" \
+ ".att_syntax;" \
+ : \
+ : "c" (this), "D" (data), "a" (times) \
+ : "%esi", "%edx", "memory", "cc" \
+ );
+
#else
#define AS1(x) __asm x
#define AS2(x, y) __asm x, y
@@ -294,7 +294,11 @@ void MD5::AsmTransform(const byte* data, word32 times)
AS2( mov ecx, [esi + 8] ) // c
AS2( mov edx, [esi + 12] ) // d
-AS1(loopStart:)
+#ifdef _MSC_VER
+ AS1( loopStart: ) // loopStart
+#else
+ AS1( 0: ) // loopStart for some gas (need numeric for jump back
+#endif
// set up
AS2( mov esi, ecx )
@@ -389,7 +393,11 @@ AS1(loopStart:)
AS2( movd ebp, mm2 ) // times
AS1( dec ebp )
AS2( movd mm2, ebp )
- AS1( jnz loopStart )
+#ifdef _MSC_VER
+ AS1( jnz loopStart ) // loopStart
+#else
+ AS1( jnz 0b ) // loopStart
+#endif
EPILOG()
diff --git a/extra/yassl/taocrypt/src/rabbit.cpp b/extra/yassl/taocrypt/src/rabbit.cpp
index 071a25191f8..89e6a207a1b 100644
--- a/extra/yassl/taocrypt/src/rabbit.cpp
+++ b/extra/yassl/taocrypt/src/rabbit.cpp
@@ -198,7 +198,6 @@ void Rabbit::Process(byte* output, const byte* input, word32 msglen)
{
/* Temporary variables */
word32 i;
- byte buffer[16];
/* Encrypt/decrypt all full blocks */
while (msglen >= 16) {
@@ -227,17 +226,23 @@ void Rabbit::Process(byte* output, const byte* input, word32 msglen)
/* Encrypt/decrypt remaining data */
if (msglen) {
+
+ word32 tmp[4];
+ byte* buffer = (byte*)tmp;
+
+ memset(tmp, 0, sizeof(tmp)); /* help static analysis */
+
/* Iterate the system */
NextState(Work);
/* Generate 16 bytes of pseudo-random data */
- *(word32*)(buffer+ 0) = LITTLE32(workCtx_.x[0] ^
+ tmp[0] = LITTLE32(workCtx_.x[0] ^
(workCtx_.x[5]>>16) ^ U32V(workCtx_.x[3]<<16));
- *(word32*)(buffer+ 4) = LITTLE32(workCtx_.x[2] ^
+ tmp[1] = LITTLE32(workCtx_.x[2] ^
(workCtx_.x[7]>>16) ^ U32V(workCtx_.x[5]<<16));
- *(word32*)(buffer+ 8) = LITTLE32(workCtx_.x[4] ^
+ tmp[2] = LITTLE32(workCtx_.x[4] ^
(workCtx_.x[1]>>16) ^ U32V(workCtx_.x[7]<<16));
- *(word32*)(buffer+12) = LITTLE32(workCtx_.x[6] ^
+ tmp[3] = LITTLE32(workCtx_.x[6] ^
(workCtx_.x[3]>>16) ^ U32V(workCtx_.x[1]<<16));
/* Encrypt/decrypt the data */
diff --git a/extra/yassl/taocrypt/src/ripemd.cpp b/extra/yassl/taocrypt/src/ripemd.cpp
index f77010ca94d..b670a9eca86 100644
--- a/extra/yassl/taocrypt/src/ripemd.cpp
+++ b/extra/yassl/taocrypt/src/ripemd.cpp
@@ -511,27 +511,26 @@ void RIPEMD160::Transform()
void RIPEMD160::AsmTransform(const byte* data, word32 times)
{
#ifdef __GNUC__
- #define AS1(x) asm(#x);
- #define AS2(x, y) asm(#x ", " #y);
+ #define AS1(x) #x ";"
+ #define AS2(x, y) #x ", " #y ";"
#define PROLOG() \
- asm(".intel_syntax noprefix"); \
- AS2( movd mm3, edi ) \
- AS2( movd mm4, ebx ) \
- AS2( movd mm5, esi ) \
- AS2( movd mm6, ebp ) \
- AS2( mov ecx, DWORD PTR [ebp + 8] ) \
- AS2( mov edi, DWORD PTR [ebp + 12] ) \
- AS2( mov edx, DWORD PTR [ebp + 16] )
+ __asm__ __volatile__ \
+ ( \
+ ".intel_syntax noprefix;" \
+ "push ebx;" \
+ "push ebp;"
#define EPILOG() \
- AS2( movd ebp, mm6 ) \
- AS2( movd esi, mm5 ) \
- AS2( movd ebx, mm4 ) \
- AS2( mov esp, ebp ) \
- AS2( movd edi, mm3 ) \
- AS1( emms ) \
- asm(".att_syntax");
+ "pop ebp;" \
+ "pop ebx;" \
+ "emms;" \
+ ".att_syntax;" \
+ : \
+ : "c" (this), "D" (data), "d" (times) \
+ : "%esi", "%eax", "memory", "cc" \
+ );
+
#else
#define AS1(x) __asm x
#define AS2(x, y) __asm x, y
@@ -569,7 +568,11 @@ void RIPEMD160::AsmTransform(const byte* data, word32 times)
AS2( sub esp, 24 ) // make room for tmp a1 - e1
AS2( movd mm1, esi ) // store digest_
-AS1( loopStart: )
+#ifdef _MSC_VER
+ AS1( loopStart: ) // loopStart
+#else
+ AS1( 0: ) // loopStart for some gas (need numeric for jump back
+#endif
AS2( movd mm2, edx ) // store times_
@@ -821,8 +824,14 @@ AS1( loopStart: )
AS2( movd edx, mm2 ) // times
AS2( movd edi, mm0 ) // data, already advanced
AS1( dec edx )
- AS1( jnz loopStart )
+#ifdef _MSC_VER
+ AS1( jnz loopStart ) // loopStart
+#else
+ AS1( jnz 0b ) // loopStart
+#endif
+ // inline adjust
+ AS2( add esp, 24 ) // fix room on stack
EPILOG()
}
diff --git a/extra/yassl/taocrypt/src/sha.cpp b/extra/yassl/taocrypt/src/sha.cpp
index f67a4f55067..0d3491eb83d 100644
--- a/extra/yassl/taocrypt/src/sha.cpp
+++ b/extra/yassl/taocrypt/src/sha.cpp
@@ -760,32 +760,33 @@ void SHA384::Transform()
#ifdef _MSC_VER
- __declspec(naked)
+ __declspec(naked)
+#else
+ __attribute__ ((noinline))
#endif
void SHA::AsmTransform(const byte* data, word32 times)
{
#ifdef __GNUC__
- #define AS1(x) asm(#x);
- #define AS2(x, y) asm(#x ", " #y);
+ #define AS1(x) #x ";"
+ #define AS2(x, y) #x ", " #y ";"
#define PROLOG() \
- asm(".intel_syntax noprefix"); \
- AS2( movd mm3, edi ) \
- AS2( movd mm4, ebx ) \
- AS2( movd mm5, esi ) \
- AS2( movd mm6, ebp ) \
- AS2( mov ecx, DWORD PTR [ebp + 8] ) \
- AS2( mov edi, DWORD PTR [ebp + 12] ) \
- AS2( mov eax, DWORD PTR [ebp + 16] )
+ __asm__ __volatile__ \
+ ( \
+ ".intel_syntax noprefix;" \
+ "push ebx;" \
+ "push ebp;"
#define EPILOG() \
- AS2( movd ebp, mm6 ) \
- AS2( movd esi, mm5 ) \
- AS2( movd ebx, mm4 ) \
- AS2( mov esp, ebp ) \
- AS2( movd edi, mm3 ) \
- AS1( emms ) \
- asm(".att_syntax");
+ "pop ebp;" \
+ "pop ebx;" \
+ "emms;" \
+ ".att_syntax;" \
+ : \
+ : "c" (this), "D" (data), "a" (times) \
+ : "%esi", "%edx", "memory", "cc" \
+ );
+
#else
#define AS1(x) __asm x
#define AS2(x, y) __asm x, y
@@ -826,7 +827,11 @@ void SHA::AsmTransform(const byte* data, word32 times)
AS2( sub esp, 68 ) // make room on stack
-AS1( loopStart: )
+#ifdef _MSC_VER
+ AS1( loopStart: ) // loopStart
+#else
+ AS1( 0: ) // loopStart for some gas (need numeric for jump back
+#endif
// byte reverse 16 words of input, 4 at a time, put on stack for W[]
@@ -1011,8 +1016,14 @@ AS1( loopStart: )
AS1( dec ebp )
AS2( movd mm2, ebp )
- AS1( jnz loopStart )
+#ifdef _MSC_VER
+ AS1( jnz loopStart ) // loopStart
+#else
+ AS1( jnz 0b ) // loopStart
+#endif
+ // inline adjust
+ AS2( add esp, 68 ) // fix room on stack
EPILOG()
}
diff --git a/extra/yassl/taocrypt/src/twofish.cpp b/extra/yassl/taocrypt/src/twofish.cpp
index 235b712b7c5..3a93ac11476 100644
--- a/extra/yassl/taocrypt/src/twofish.cpp
+++ b/extra/yassl/taocrypt/src/twofish.cpp
@@ -55,7 +55,7 @@ void Twofish::Process(byte* out, const byte* in, word32 sz)
in += BLOCK_SIZE;
}
else if (mode_ == CBC) {
- if (dir_ == ENCRYPTION)
+ if (dir_ == ENCRYPTION) {
while (blocks--) {
r_[0] ^= *(word32*)in;
r_[1] ^= *(word32*)(in + 4);
@@ -68,7 +68,8 @@ void Twofish::Process(byte* out, const byte* in, word32 sz)
out += BLOCK_SIZE;
in += BLOCK_SIZE;
}
- else
+ }
+ else {
while (blocks--) {
AsmDecrypt(in, out);
@@ -82,6 +83,7 @@ void Twofish::Process(byte* out, const byte* in, word32 sz)
out += BLOCK_SIZE;
in += BLOCK_SIZE;
}
+ }
}
}
@@ -272,25 +274,28 @@ void Twofish::decrypt(const byte* inBlock, const byte* xorBlock,
#if defined(DO_TWOFISH_ASM)
#ifdef __GNUC__
- #define AS1(x) asm(#x);
- #define AS2(x, y) asm(#x ", " #y);
+ #define AS1(x) #x ";"
+ #define AS2(x, y) #x ", " #y ";"
#define PROLOG() \
- asm(".intel_syntax noprefix"); \
- AS2( movd mm3, edi ) \
- AS2( movd mm4, ebx ) \
- AS2( movd mm5, esi ) \
- AS2( movd mm6, ebp ) \
- AS2( mov edi, DWORD PTR [ebp + 8] ) \
- AS2( mov esi, DWORD PTR [ebp + 12] )
+ __asm__ __volatile__ \
+ ( \
+ ".intel_syntax noprefix;" \
+ "push ebx;" \
+ "push ebp;" \
+ "movd mm3, eax;" \
+ "movd mm6, ebp;"
#define EPILOG() \
- AS2( movd esp, mm6 ) \
- AS2( movd esi, mm5 ) \
- AS2( movd ebx, mm4 ) \
- AS2( movd edi, mm3 ) \
- AS1( emms ) \
- asm(".att_syntax");
+ "pop ebp;" \
+ "pop ebx;" \
+ "emms;" \
+ ".att_syntax;" \
+ : \
+ : "D" (this), "S" (inBlock), "a" (outBlock) \
+ : "%ecx", "%edx", "memory", "cc" \
+ );
+
#else
#define AS1(x) __asm x
#define AS2(x, y) __asm x, y
@@ -424,6 +429,8 @@ void Twofish::decrypt(const byte* inBlock, const byte* xorBlock,
#ifdef _MSC_VER
__declspec(naked)
+#else
+ __attribute__ ((noinline))
#endif
void Twofish::AsmEncrypt(const byte* inBlock, byte* outBlock) const
{
@@ -472,7 +479,7 @@ void Twofish::AsmEncrypt(const byte* inBlock, byte* outBlock) const
AS2( movd ebp, mm6 )
AS2( movd esi, mm0 ) // k_
#ifdef __GNUC__
- AS2( mov edi, [ebp + 16] ) // outBlock
+ AS2( movd edi, mm3 ) // outBlock
#else
AS2( mov edi, [ebp + 12] ) // outBlock
#endif
@@ -493,7 +500,9 @@ void Twofish::AsmEncrypt(const byte* inBlock, byte* outBlock) const
#ifdef _MSC_VER
- __declspec(naked)
+ __declspec(naked)
+#else
+ __attribute__ ((noinline))
#endif
void Twofish::AsmDecrypt(const byte* inBlock, byte* outBlock) const
{
@@ -542,7 +551,7 @@ void Twofish::AsmDecrypt(const byte* inBlock, byte* outBlock) const
AS2( movd ebp, mm6 )
AS2( movd esi, mm0 ) // k_
#ifdef __GNUC__
- AS2( mov edi, [ebp + 16] ) // outBlock
+ AS2( movd edi, mm3 ) // outBlock
#else
AS2( mov edi, [ebp + 12] ) // outBlock
#endif