Commit 1747a456 authored by Anirudh Mangipudi's avatar Anirudh Mangipudi

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.
parent 288f1ce1
...@@ -12,7 +12,15 @@ before calling SSL_new(); ...@@ -12,7 +12,15 @@ before calling SSL_new();
*** end Note *** *** end Note ***
yaSSL Release notes, version 2.2.3b (4/23/2013) yaSSL Release notes, version 2.3.0 (12/5/2013)
This release of yaSSL updates asm for newer GCC versions.
See normal build instructions below under 1.0.6.
See libcurl build instructions below under 1.3.0 and note in 1.5.8.
*****************yaSSL Release notes, version 2.2.3b (4/23/2013)
This release of yaSSL updates the test certificates as they were expired This release of yaSSL updates the test certificates as they were expired
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include "rsa.h" #include "rsa.h"
#define YASSL_VERSION "2.2.3b" #define YASSL_VERSION "2.3.0"
#if defined(__cplusplus) #if defined(__cplusplus)
......
...@@ -953,9 +953,9 @@ x509* PemToDer(FILE* file, CertType type, EncryptedInfo* info) ...@@ -953,9 +953,9 @@ x509* PemToDer(FILE* file, CertType type, EncryptedInfo* info)
info->set = true; info->set = true;
} }
} }
// get blank line
if (fgets(line, sizeof(line), file))
begin = ftell(file); begin = ftell(file);
if (fgets(line,sizeof(line), file)) // get blank line
begin = ftell(file);
} }
} }
......
...@@ -45,6 +45,14 @@ ...@@ -45,6 +45,14 @@
#endif #endif
#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 TAOCRYPT_X86ASM_AVAILABLE
#ifdef _M_IX86 #ifdef _M_IX86
......
...@@ -124,15 +124,22 @@ void CleanUp(); ...@@ -124,15 +124,22 @@ void CleanUp();
// no gas on these systems ?, disable for now // no gas on these systems ?, disable for now
#if defined(__sun__) || defined (__APPLE__) #if defined(__sun__)
#undef TAOCRYPT_DISABLE_X86ASM
#define TAOCRYPT_DISABLE_X86ASM #define TAOCRYPT_DISABLE_X86ASM
#endif #endif
// icc problem with -03 and integer, disable for now // icc problem with -03 and integer, disable for now
#if defined(__INTEL_COMPILER) #if defined(__INTEL_COMPILER)
#undef TAOCRYPT_DISABLE_X86ASM
#define TAOCRYPT_DISABLE_X86ASM #define TAOCRYPT_DISABLE_X86ASM
#endif #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 // Turn on ia32 ASM for Big Integer
// CodeWarrior defines _MSC_VER // CodeWarrior defines _MSC_VER
......
...@@ -52,7 +52,7 @@ void AES::Process(byte* out, const byte* in, word32 sz) ...@@ -52,7 +52,7 @@ void AES::Process(byte* out, const byte* in, word32 sz)
in += BLOCK_SIZE; in += BLOCK_SIZE;
} }
else if (mode_ == CBC) { else if (mode_ == CBC) {
if (dir_ == ENCRYPTION) if (dir_ == ENCRYPTION) {
while (blocks--) { while (blocks--) {
r_[0] ^= *(word32*)in; r_[0] ^= *(word32*)in;
r_[1] ^= *(word32*)(in + 4); r_[1] ^= *(word32*)(in + 4);
...@@ -65,7 +65,8 @@ void AES::Process(byte* out, const byte* in, word32 sz) ...@@ -65,7 +65,8 @@ void AES::Process(byte* out, const byte* in, word32 sz)
out += BLOCK_SIZE; out += BLOCK_SIZE;
in += BLOCK_SIZE; in += BLOCK_SIZE;
} }
else }
else {
while (blocks--) { while (blocks--) {
AsmDecrypt(in, out, (void*)Td0); AsmDecrypt(in, out, (void*)Td0);
...@@ -78,6 +79,7 @@ void AES::Process(byte* out, const byte* in, word32 sz) ...@@ -78,6 +79,7 @@ void AES::Process(byte* out, const byte* in, word32 sz)
out += BLOCK_SIZE; out += BLOCK_SIZE;
in += BLOCK_SIZE; in += BLOCK_SIZE;
} }
}
} }
} }
...@@ -452,27 +454,31 @@ void AES::decrypt(const byte* inBlock, const byte* xorBlock, ...@@ -452,27 +454,31 @@ void AES::decrypt(const byte* inBlock, const byte* xorBlock,
#if defined(DO_AES_ASM) #if defined(DO_AES_ASM)
#ifdef __GNUC__ #ifdef __GNUC__
#define AS1(x) asm(#x); #define AS1(x) #x ";"
#define AS2(x, y) asm(#x ", " #y); #define AS2(x, y) #x ", " #y ";"
#define PROLOG() \ #define PROLOG() \
asm(".intel_syntax noprefix"); \ __asm__ __volatile__ \
AS2( movd mm3, edi ) \ ( \
AS2( movd mm4, ebx ) \ ".intel_syntax noprefix;" \
AS2( sub esp, 4 ) \ "push ebx;" \
AS2( movd mm7, ebp ) \ "push ebp;" \
AS2( mov [ebp - 4], esi ) \ "movd mm7, ebp;" \
AS2( mov ecx, DWORD PTR [ebp + 8] ) \ "movd mm4, eax;" \
AS2( mov esi, DWORD PTR [ebp + 12] ) \ "mov ebp, edx;" \
AS2( mov ebp, DWORD PTR [ebp + 20] ) "sub esp, 4;"
#define EPILOG() \ #define EPILOG() \
AS2( mov esi, [ebp - 4] ) \ "add esp, 4;" \
AS2( mov esp, ebp ) \ "pop ebp;" \
AS2( movd ebx, mm4 ) \ "pop ebx;" \
AS2( movd edi, mm3 ) \ "emms;" \
AS1( emms ) \ ".att_syntax;" \
asm(".att_syntax"); : \
: "c" (this), "S" (inBlock), "d" (boxes), "a" (outBlock) \
: "%edi", "memory", "cc" \
);
#else #else
#define AS1(x) __asm x #define AS1(x) __asm x
#define AS2(x, y) __asm x, y #define AS2(x, y) __asm x, y
...@@ -504,6 +510,8 @@ void AES::decrypt(const byte* inBlock, const byte* xorBlock, ...@@ -504,6 +510,8 @@ void AES::decrypt(const byte* inBlock, const byte* xorBlock,
#ifdef _MSC_VER #ifdef _MSC_VER
__declspec(naked) __declspec(naked)
#else
__attribute__ ((noinline))
#endif #endif
void AES::AsmEncrypt(const byte* inBlock, byte* outBlock, void* boxes) const 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 ...@@ -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 ecx, DWORD PTR [edi + 8] ) // s2
AS2( xor edx, DWORD PTR [edi + 12] ) // s3 AS2( xor edx, DWORD PTR [edi + 12] ) // s3
AS1(loop1: ) #ifdef _MSC_VER
AS1( loop1: ) // loop1
#else
AS1(1: ) // loop1
#endif
/* Put0 (mm0) = /* Put0 (mm0) =
Te0[get0,rs 24] ^ Te0[get0,rs 24] ^
Te1[get1,rs 16] ^ Te1[get1,rs 16] ^
...@@ -652,7 +664,11 @@ void AES::AsmEncrypt(const byte* inBlock, byte* outBlock, void* boxes) const ...@@ -652,7 +664,11 @@ void AES::AsmEncrypt(const byte* inBlock, byte* outBlock, void* boxes) const
AS1( dec edi ) AS1( dec edi )
AS2( movd mm5, edi ) AS2( movd mm5, edi )
AS1( jnz loop1 ) #ifdef _MSC_VER
AS1( jnz loop1) // loop1
#else
AS1( jnz 1b ) // loop1
#endif
// last round // last round
/* /*
...@@ -799,9 +815,9 @@ void AES::AsmEncrypt(const byte* inBlock, byte* outBlock, void* boxes) const ...@@ -799,9 +815,9 @@ void AES::AsmEncrypt(const byte* inBlock, byte* outBlock, void* boxes) const
// store // store
#ifdef __GNUC__ #ifdef __GNUC__
AS2( mov esi, DWORD PTR [ebp + 16] ) // outBlock AS2( movd esi, mm4 ) // outBlock
#else #else
AS2( mov esi, DWORD PTR [ebp + 12] ) // outBlock AS2( mov esi, DWORD PTR [ebp + 12] ) // outBlock
#endif #endif
AS1( bswap ecx ) AS1( bswap ecx )
...@@ -818,7 +834,9 @@ void AES::AsmEncrypt(const byte* inBlock, byte* outBlock, void* boxes) const ...@@ -818,7 +834,9 @@ void AES::AsmEncrypt(const byte* inBlock, byte* outBlock, void* boxes) const
#ifdef _MSC_VER #ifdef _MSC_VER
__declspec(naked) __declspec(naked)
#else
__attribute__ ((noinline))
#endif #endif
void AES::AsmDecrypt(const byte* inBlock, byte* outBlock, void* boxes) const 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 ...@@ -853,7 +871,11 @@ void AES::AsmDecrypt(const byte* inBlock, byte* outBlock, void* boxes) const
AS2( xor edx, DWORD PTR [edi + 12] ) // s3 AS2( xor edx, DWORD PTR [edi + 12] ) // s3
AS1(loop2: ) #ifdef _MSC_VER
AS1( loop2: ) // loop2
#else
AS1(2: ) // loop2
#endif
/* Put0 (mm0) = /* Put0 (mm0) =
Td0[GETBYTE(get0, rs24)] ^ Td0[GETBYTE(get0, rs24)] ^
Td1[GETBYTE(get3, rs16)] ^ Td1[GETBYTE(get3, rs16)] ^
...@@ -964,7 +986,11 @@ void AES::AsmDecrypt(const byte* inBlock, byte* outBlock, void* boxes) const ...@@ -964,7 +986,11 @@ void AES::AsmDecrypt(const byte* inBlock, byte* outBlock, void* boxes) const
AS1( dec edi ) AS1( dec edi )
AS2( movd mm5, edi ) AS2( movd mm5, edi )
AS1( jnz loop2 ) #ifdef _MSC_VER
AS1( jnz loop2) // loop2
#else
AS1( jnz 2b ) // loop2
#endif
// last round // last round
/* /*
...@@ -1114,9 +1140,9 @@ void AES::AsmDecrypt(const byte* inBlock, byte* outBlock, void* boxes) const ...@@ -1114,9 +1140,9 @@ void AES::AsmDecrypt(const byte* inBlock, byte* outBlock, void* boxes) const
// store // store
#ifdef __GNUC__ #ifdef __GNUC__
AS2( mov esi, DWORD PTR [ebp + 16] ) // outBlock AS2( movd esi, mm4 ) // outBlock
#else #else
AS2( mov esi, DWORD PTR [ebp + 12] ) // outBlock AS2( mov esi, DWORD PTR [ebp + 12] ) // outBlock
#endif #endif
AS2( mov DWORD PTR [esi], eax ) AS2( mov DWORD PTR [esi], eax )
AS2( mov DWORD PTR [esi + 4], ebx ) AS2( mov DWORD PTR [esi + 4], ebx )
......
...@@ -111,28 +111,27 @@ void ARC4::Process(byte* out, const byte* in, word32 length) ...@@ -111,28 +111,27 @@ void ARC4::Process(byte* out, const byte* in, word32 length)
void ARC4::AsmProcess(byte* out, const byte* in, word32 length) void ARC4::AsmProcess(byte* out, const byte* in, word32 length)
{ {
#ifdef __GNUC__ #ifdef __GNUC__
#define AS1(x) asm(#x); #define AS1(x) #x ";"
#define AS2(x, y) asm(#x ", " #y); #define AS2(x, y) #x ", " #y ";"
#define PROLOG() \ #define PROLOG() \
asm(".intel_syntax noprefix"); \ __asm__ __volatile__ \
AS2( movd mm3, edi ) \ ( \
AS2( movd mm4, ebx ) \ ".intel_syntax noprefix;" \
AS2( movd mm5, esi ) \ "push ebx;" \
AS2( movd mm6, ebp ) \ "push ebp;" \
AS2( mov ecx, DWORD PTR [ebp + 8] ) \ "mov ebp, eax;"
AS2( mov edi, DWORD PTR [ebp + 12] ) \
AS2( mov esi, DWORD PTR [ebp + 16] ) \
AS2( mov ebp, DWORD PTR [ebp + 20] )
#define EPILOG() \ #define EPILOG() \
AS2( movd ebp, mm6 ) \ "pop ebp;" \
AS2( movd esi, mm5 ) \ "pop ebx;" \
AS2( movd ebx, mm4 ) \ "emms;" \
AS2( mov esp, ebp ) \ ".att_syntax;" \
AS2( movd edi, mm3 ) \ : \
AS1( emms ) \ : "c" (this), "D" (out), "S" (in), "a" (length) \
asm(".att_syntax"); : "%edx", "memory", "cc" \
);
#else #else
#define AS1(x) __asm x #define AS1(x) __asm x
#define AS2(x, y) __asm x, y #define AS2(x, y) __asm x, y
...@@ -178,7 +177,11 @@ void ARC4::AsmProcess(byte* out, const byte* in, word32 length) ...@@ -178,7 +177,11 @@ void ARC4::AsmProcess(byte* out, const byte* in, word32 length)
AS2( movzx eax, BYTE PTR [ebp + ecx] ) 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; // y = (y+a) & 0xff;
AS2( add edx, eax ) AS2( add edx, eax )
...@@ -215,7 +218,11 @@ AS1( begin: ) ...@@ -215,7 +218,11 @@ AS1( begin: )
AS1( inc edi ) AS1( inc edi )
AS1( dec DWORD PTR [esp] ) 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_ // write back to x_ and y_
...@@ -225,6 +232,8 @@ AS1( begin: ) ...@@ -225,6 +232,8 @@ AS1( begin: )
AS1( nothing: ) AS1( nothing: )
// inline adjust
AS2( add esp, 4 ) // fix room on stack
EPILOG() EPILOG()
} }
......
...@@ -54,7 +54,7 @@ void Blowfish::Process(byte* out, const byte* in, word32 sz) ...@@ -54,7 +54,7 @@ void Blowfish::Process(byte* out, const byte* in, word32 sz)
in += BLOCK_SIZE; in += BLOCK_SIZE;
} }
else if (mode_ == CBC) { else if (mode_ == CBC) {
if (dir_ == ENCRYPTION) if (dir_ == ENCRYPTION) {
while (blocks--) { while (blocks--) {
r_[0] ^= *(word32*)in; r_[0] ^= *(word32*)in;
r_[1] ^= *(word32*)(in + 4); r_[1] ^= *(word32*)(in + 4);
...@@ -66,7 +66,8 @@ void Blowfish::Process(byte* out, const byte* in, word32 sz) ...@@ -66,7 +66,8 @@ void Blowfish::Process(byte* out, const byte* in, word32 sz)
out += BLOCK_SIZE; out += BLOCK_SIZE;
in += BLOCK_SIZE; in += BLOCK_SIZE;
} }
else }
else {
while (blocks--) { while (blocks--) {
AsmProcess(in, out); AsmProcess(in, out);
...@@ -78,6 +79,7 @@ void Blowfish::Process(byte* out, const byte* in, word32 sz) ...@@ -78,6 +79,7 @@ void Blowfish::Process(byte* out, const byte* in, word32 sz)
out += BLOCK_SIZE; out += BLOCK_SIZE;
in += BLOCK_SIZE; in += BLOCK_SIZE;
} }
}
} }
} }
...@@ -222,23 +224,26 @@ void Blowfish::ProcessAndXorBlock(const byte* in, const byte* xOr, byte* out) ...@@ -222,23 +224,26 @@ void Blowfish::ProcessAndXorBlock(const byte* in, const byte* xOr, byte* out)
#if defined(DO_BLOWFISH_ASM) #if defined(DO_BLOWFISH_ASM)
#ifdef __GNUC__ #ifdef __GNUC__
#define AS1(x) asm(#x); #define AS1(x) #x ";"
#define AS2(x, y) asm(#x ", " #y); #define AS2(x, y) #x ", " #y ";"
#define PROLOG() \ #define PROLOG() \
asm(".intel_syntax noprefix"); \ __asm__ __volatile__ \
AS2( movd mm3, edi ) \ ( \
AS2( movd mm4, ebx ) \ ".intel_syntax noprefix;" \
AS2( movd mm5, esi ) \ "push ebx;" \
AS2( mov ecx, DWORD PTR [ebp + 8] ) \ "push ebp;" \
AS2( mov esi, DWORD PTR [ebp + 12] ) "movd mm3, eax;"
#define EPILOG() \ #define EPILOG() \
AS2( movd esi, mm5 ) \ "pop ebp;" \
AS2( movd ebx, mm4 ) \ "pop ebx;" \
AS2( movd edi, mm3 ) \ "emms;" \
AS1( emms ) \ ".att_syntax;" \
asm(".att_syntax"); : \
: "c" (this), "S" (inBlock), "a" (outBlock) \
: "%edi", "%edx", "memory", "cc" \
);
#else #else
#define AS1(x) __asm x #define AS1(x) __asm x
#define AS2(x, y) __asm x, y #define AS2(x, y) __asm x, y
...@@ -286,7 +291,9 @@ void Blowfish::ProcessAndXorBlock(const byte* in, const byte* xOr, byte* out) ...@@ -286,7 +291,9 @@ void Blowfish::ProcessAndXorBlock(const byte* in, const byte* xOr, byte* out)
#ifdef _MSC_VER #ifdef _MSC_VER
__declspec(naked) __declspec(naked)
#else
__attribute__ ((noinline))
#endif #endif
void Blowfish::AsmProcess(const byte* inBlock, byte* outBlock) const void Blowfish::AsmProcess(const byte* inBlock, byte* outBlock) const
{ {
...@@ -335,7 +342,7 @@ void Blowfish::AsmProcess(const byte* inBlock, byte* outBlock) const ...@@ -335,7 +342,7 @@ void Blowfish::AsmProcess(const byte* inBlock, byte* outBlock) const
#endif #endif
#ifdef __GNUC__ #ifdef __GNUC__
AS2( mov edi, [ebp + 16] ) // outBlock AS2( movd edi, mm3 ) // outBlock
#else #else
AS2( mov edi, [ebp + 12] ) // outBlock AS2( mov edi, [ebp + 12] ) // outBlock
#endif #endif
......
...@@ -473,7 +473,7 @@ void DES_EDE3::ProcessAndXorBlock(const byte* in, const byte* xOr, ...@@ -473,7 +473,7 @@ void DES_EDE3::ProcessAndXorBlock(const byte* in, const byte* xOr,
uses ecx uses ecx
*/ */
#define AsmIPERM() {\ #define AsmIPERM() \
AS2( rol ebx, 4 ) \ AS2( rol ebx, 4 ) \
AS2( mov ecx, eax ) \ AS2( mov ecx, eax ) \
AS2( xor ecx, ebx ) \ AS2( xor ecx, ebx ) \
...@@ -504,7 +504,7 @@ void DES_EDE3::ProcessAndXorBlock(const byte* in, const byte* xOr, ...@@ -504,7 +504,7 @@ void DES_EDE3::ProcessAndXorBlock(const byte* in, const byte* xOr,
AS2( and ecx, 0xaaaaaaaa ) \ AS2( and ecx, 0xaaaaaaaa ) \
AS2( xor eax, ecx ) \ AS2( xor eax, ecx ) \
AS2( rol eax, 1 ) \ AS2( rol eax, 1 ) \
AS2( xor ebx, ecx ) } AS2( xor ebx, ecx )
/* Uses FPERM algorithm from above /* Uses FPERM algorithm from above
...@@ -514,7 +514,7 @@ void DES_EDE3::ProcessAndXorBlock(const byte* in, const byte* xOr, ...@@ -514,7 +514,7 @@ void DES_EDE3::ProcessAndXorBlock(const byte* in, const byte* xOr,
uses ecx uses ecx
*/ */
#define AsmFPERM() {\ #define AsmFPERM() \
AS2( ror ebx, 1 ) \ AS2( ror ebx, 1 ) \
AS2( mov ecx, eax ) \ AS2( mov ecx, eax ) \
AS2( xor ecx, ebx ) \ AS2( xor ecx, ebx ) \
...@@ -545,7 +545,7 @@ void DES_EDE3::ProcessAndXorBlock(const byte* in, const byte* xOr, ...@@ -545,7 +545,7 @@ void DES_EDE3::ProcessAndXorBlock(const byte* in, const byte* xOr,
AS2( and ecx, 0xf0f0f0f0 ) \ AS2( and ecx, 0xf0f0f0f0 ) \
AS2( xor eax, ecx ) \ AS2( xor eax, ecx ) \
AS2( xor ebx, 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, ...@@ -641,32 +641,34 @@ void DES_EDE3::ProcessAndXorBlock(const byte* in, const byte* xOr,
#ifdef _MSC_VER #ifdef _MSC_VER
__declspec(naked) __declspec(naked)
#else
__attribute__ ((noinline))
#endif #endif
void DES_EDE3::AsmProcess(const byte* in, byte* out, void* box) const void DES_EDE3::AsmProcess(const byte* in, byte* out, void* box) const
{ {
#ifdef __GNUC__ #ifdef __GNUC__
#define AS1(x) asm(#x); #define AS1(x) #x ";"
#define AS2(x, y) asm(#x ", " #y); #define AS2(x, y) #x ", " #y ";"
asm(".intel_syntax noprefix");
#define PROLOG() \ #define PROLOG() \
AS2( movd mm3, edi ) \ __asm__ __volatile__ \
AS2( movd mm4, ebx ) \ ( \
AS2( movd mm5, esi ) \ ".intel_syntax noprefix;" \
AS2( movd mm6, ebp ) \ "push ebx;" \
AS2( mov edx, DWORD PTR [ebp + 8] ) \ "push ebp;" \
AS2( mov esi, DWORD PTR [ebp + 12] ) \ "movd mm6, ebp;" \
AS2( mov ebp, DWORD PTR [ebp + 20] ) "movd mm7, ecx;" \
"mov ebp, eax;"
// ebp restored at end #define EPILOG() \
#define EPILOG() \ "pop ebp;" \
AS2( movd edi, mm3 ) \ "pop ebx;" \
AS2( movd ebx, mm4 ) \ "emms;" \
AS2( movd esi, mm5 ) \ ".att_syntax;" \
AS1( emms ) \ : \
asm(".att_syntax"); : "d" (this), "S" (in), "a" (box), "c" (out) \
: "%edi", "memory", "cc" \
);
#else #else
#define AS1(x) __asm x #define AS1(x) __asm x
...@@ -756,7 +758,7 @@ void DES_EDE3::AsmProcess(const byte* in, byte* out, void* box) const ...@@ -756,7 +758,7 @@ void DES_EDE3::AsmProcess(const byte* in, byte* out, void* box) const
AS1( bswap eax ) AS1( bswap eax )
#ifdef __GNUC__ #ifdef __GNUC__
AS2( mov esi, DWORD PTR [ebp + 16] ) // outBlock AS2( movd esi, mm7 ) // outBlock
#else #else
AS2( mov esi, DWORD PTR [ebp + 12] ) // outBlock AS2( mov esi, DWORD PTR [ebp + 12] ) // outBlock
#endif #endif
......
...@@ -55,7 +55,9 @@ ...@@ -55,7 +55,9 @@
#include <emmintrin.h> #include <emmintrin.h>
#endif #endif
#elif defined(_MSC_VER) && defined(_M_IX86) #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.") #pragma message("installed, so use of SSE2 intrinsics will be disabled.")
#elif defined(__GNUC__) && defined(__i386__) #elif defined(__GNUC__) && defined(__i386__)
/* #warning You do not have GCC 3.3 or later, or did not specify the -msse2 \ /* #warning You do not have GCC 3.3 or later, or did not specify the -msse2 \
...@@ -73,7 +75,7 @@ template <class T> ...@@ -73,7 +75,7 @@ template <class T>
CPP_TYPENAME AlignedAllocator<T>::pointer AlignedAllocator<T>::allocate( CPP_TYPENAME AlignedAllocator<T>::pointer AlignedAllocator<T>::allocate(
size_type n, const void *) size_type n, const void *)
{ {
if (n > max_size()) if (n > this->max_size())
return 0; return 0;
if (n == 0) if (n == 0)
return 0; return 0;
......
...@@ -223,32 +223,32 @@ void MD5::Update(const byte* data, word32 len) ...@@ -223,32 +223,32 @@ void MD5::Update(const byte* data, word32 len)
#ifdef _MSC_VER #ifdef _MSC_VER
__declspec(naked) __declspec(naked)
#else
__attribute__ ((noinline))
#endif #endif
void MD5::AsmTransform(const byte* data, word32 times) void MD5::AsmTransform(const byte* data, word32 times)
{ {
#ifdef __GNUC__ #ifdef __GNUC__
#define AS1(x) asm(#x); #define AS1(x) #x ";"
#define AS2(x, y) asm(#x ", " #y); #define AS2(x, y) #x ", " #y ";"
#define PROLOG() \ #define PROLOG() \
asm(".intel_syntax noprefix"); \ __asm__ __volatile__ \
AS2( movd mm3, edi ) \ ( \
AS2( movd mm4, ebx ) \ ".intel_syntax noprefix;" \
AS2( movd mm5, esi ) \ "push ebx;" \
AS2( movd mm6, ebp ) \ "push ebp;"
AS2( mov ecx, DWORD PTR [ebp + 8] ) \
AS2( mov edi, DWORD PTR [ebp + 12] ) \
AS2( mov eax, DWORD PTR [ebp + 16] )
#define EPILOG() \ #define EPILOG() \
AS2( movd ebp, mm6 ) \ "pop ebp;" \
AS2( movd esi, mm5 ) \ "pop ebx;" \
AS2( movd ebx, mm4 ) \ "emms;" \
AS2( mov esp, ebp ) \ ".att_syntax;" \
AS2( movd edi, mm3 ) \ : \
AS1( emms ) \ : "c" (this), "D" (data), "a" (times) \
asm(".att_syntax"); : "%esi", "%edx", "memory", "cc" \
);
#else #else
#define AS1(x) __asm x #define AS1(x) __asm x
#define AS2(x, y) __asm x, y #define AS2(x, y) __asm x, y
...@@ -294,7 +294,11 @@ void MD5::AsmTransform(const byte* data, word32 times) ...@@ -294,7 +294,11 @@ void MD5::AsmTransform(const byte* data, word32 times)
AS2( mov ecx, [esi + 8] ) // c AS2( mov ecx, [esi + 8] ) // c
AS2( mov edx, [esi + 12] ) // d 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 // set up
AS2( mov esi, ecx ) AS2( mov esi, ecx )
...@@ -389,7 +393,11 @@ AS1(loopStart:) ...@@ -389,7 +393,11 @@ AS1(loopStart:)
AS2( movd ebp, mm2 ) // times AS2( movd ebp, mm2 ) // times
AS1( dec ebp ) AS1( dec ebp )
AS2( movd mm2, ebp ) AS2( movd mm2, ebp )
AS1( jnz loopStart ) #ifdef _MSC_VER
AS1( jnz loopStart ) // loopStart
#else
AS1( jnz 0b ) // loopStart
#endif
EPILOG() EPILOG()
......
...@@ -198,7 +198,6 @@ void Rabbit::Process(byte* output, const byte* input, word32 msglen) ...@@ -198,7 +198,6 @@ void Rabbit::Process(byte* output, const byte* input, word32 msglen)
{ {
/* Temporary variables */ /* Temporary variables */
word32 i; word32 i;
byte buffer[16];
/* Encrypt/decrypt all full blocks */ /* Encrypt/decrypt all full blocks */
while (msglen >= 16) { while (msglen >= 16) {
...@@ -227,17 +226,23 @@ void Rabbit::Process(byte* output, const byte* input, word32 msglen) ...@@ -227,17 +226,23 @@ void Rabbit::Process(byte* output, const byte* input, word32 msglen)
/* Encrypt/decrypt remaining data */ /* Encrypt/decrypt remaining data */
if (msglen) { if (msglen) {
word32 tmp[4];
byte* buffer = (byte*)tmp;
memset(tmp, 0, sizeof(tmp)); /* help static analysis */
/* Iterate the system */ /* Iterate the system */
NextState(Work); NextState(Work);
/* Generate 16 bytes of pseudo-random data */ /* 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)); (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)); (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)); (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)); (workCtx_.x[3]>>16) ^ U32V(workCtx_.x[1]<<16));
/* Encrypt/decrypt the data */ /* Encrypt/decrypt the data */
......
...@@ -511,27 +511,26 @@ void RIPEMD160::Transform() ...@@ -511,27 +511,26 @@ void RIPEMD160::Transform()
void RIPEMD160::AsmTransform(const byte* data, word32 times) void RIPEMD160::AsmTransform(const byte* data, word32 times)
{ {
#ifdef __GNUC__ #ifdef __GNUC__
#define AS1(x) asm(#x); #define AS1(x) #x ";"
#define AS2(x, y) asm(#x ", " #y); #define AS2(x, y) #x ", " #y ";"
#define PROLOG() \ #define PROLOG() \
asm(".intel_syntax noprefix"); \ __asm__ __volatile__ \
AS2( movd mm3, edi ) \ ( \
AS2( movd mm4, ebx ) \ ".intel_syntax noprefix;" \
AS2( movd mm5, esi ) \ "push ebx;" \
AS2( movd mm6, ebp ) \ "push ebp;"
AS2( mov ecx, DWORD PTR [ebp + 8] ) \
AS2( mov edi, DWORD PTR [ebp + 12] ) \
AS2( mov edx, DWORD PTR [ebp + 16] )
#define EPILOG() \ #define EPILOG() \
AS2( movd ebp, mm6 ) \ "pop ebp;" \
AS2( movd esi, mm5 ) \ "pop ebx;" \
AS2( movd ebx, mm4 ) \ "emms;" \
AS2( mov esp, ebp ) \ ".att_syntax;" \
AS2( movd edi, mm3 ) \ : \
AS1( emms ) \ : "c" (this), "D" (data), "d" (times) \
asm(".att_syntax"); : "%esi", "%eax", "memory", "cc" \
);
#else #else
#define AS1(x) __asm x #define AS1(x) __asm x
#define AS2(x, y) __asm x, y #define AS2(x, y) __asm x, y
...@@ -569,7 +568,11 @@ void RIPEMD160::AsmTransform(const byte* data, word32 times) ...@@ -569,7 +568,11 @@ void RIPEMD160::AsmTransform(const byte* data, word32 times)
AS2( sub esp, 24 ) // make room for tmp a1 - e1 AS2( sub esp, 24 ) // make room for tmp a1 - e1
AS2( movd mm1, esi ) // store digest_ 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_ AS2( movd mm2, edx ) // store times_
...@@ -821,8 +824,14 @@ AS1( loopStart: ) ...@@ -821,8 +824,14 @@ AS1( loopStart: )
AS2( movd edx, mm2 ) // times AS2( movd edx, mm2 ) // times
AS2( movd edi, mm0 ) // data, already advanced AS2( movd edi, mm0 ) // data, already advanced
AS1( dec edx ) 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() EPILOG()
} }
......
...@@ -760,32 +760,33 @@ void SHA384::Transform() ...@@ -760,32 +760,33 @@ void SHA384::Transform()
#ifdef _MSC_VER #ifdef _MSC_VER
__declspec(naked) __declspec(naked)
#else
__attribute__ ((noinline))
#endif #endif
void SHA::AsmTransform(const byte* data, word32 times) void SHA::AsmTransform(const byte* data, word32 times)
{ {
#ifdef __GNUC__ #ifdef __GNUC__
#define AS1(x) asm(#x); #define AS1(x) #x ";"
#define AS2(x, y) asm(#x ", " #y); #define AS2(x, y) #x ", " #y ";"
#define PROLOG() \ #define PROLOG() \
asm(".intel_syntax noprefix"); \ __asm__ __volatile__ \
AS2( movd mm3, edi ) \ ( \
AS2( movd mm4, ebx ) \ ".intel_syntax noprefix;" \
AS2( movd mm5, esi ) \ "push ebx;" \
AS2( movd mm6, ebp ) \ "push ebp;"
AS2( mov ecx, DWORD PTR [ebp + 8] ) \
AS2( mov edi, DWORD PTR [ebp + 12] ) \
AS2( mov eax, DWORD PTR [ebp + 16] )
#define EPILOG() \ #define EPILOG() \
AS2( movd ebp, mm6 ) \ "pop ebp;" \
AS2( movd esi, mm5 ) \ "pop ebx;" \
AS2( movd ebx, mm4 ) \ "emms;" \
AS2( mov esp, ebp ) \ ".att_syntax;" \
AS2( movd edi, mm3 ) \ : \
AS1( emms ) \ : "c" (this), "D" (data), "a" (times) \
asm(".att_syntax"); : "%esi", "%edx", "memory", "cc" \
);
#else #else
#define AS1(x) __asm x #define AS1(x) __asm x
#define AS2(x, y) __asm x, y #define AS2(x, y) __asm x, y
...@@ -826,7 +827,11 @@ void SHA::AsmTransform(const byte* data, word32 times) ...@@ -826,7 +827,11 @@ void SHA::AsmTransform(const byte* data, word32 times)
AS2( sub esp, 68 ) // make room on stack 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[] // byte reverse 16 words of input, 4 at a time, put on stack for W[]
...@@ -1011,8 +1016,14 @@ AS1( loopStart: ) ...@@ -1011,8 +1016,14 @@ AS1( loopStart: )
AS1( dec ebp ) AS1( dec ebp )
AS2( movd mm2, 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() EPILOG()
} }
......
...@@ -55,7 +55,7 @@ void Twofish::Process(byte* out, const byte* in, word32 sz) ...@@ -55,7 +55,7 @@ void Twofish::Process(byte* out, const byte* in, word32 sz)
in += BLOCK_SIZE; in += BLOCK_SIZE;
} }
else if (mode_ == CBC) { else if (mode_ == CBC) {
if (dir_ == ENCRYPTION) if (dir_ == ENCRYPTION) {
while (blocks--) { while (blocks--) {
r_[0] ^= *(word32*)in; r_[0] ^= *(word32*)in;
r_[1] ^= *(word32*)(in + 4); r_[1] ^= *(word32*)(in + 4);
...@@ -68,7 +68,8 @@ void Twofish::Process(byte* out, const byte* in, word32 sz) ...@@ -68,7 +68,8 @@ void Twofish::Process(byte* out, const byte* in, word32 sz)
out += BLOCK_SIZE; out += BLOCK_SIZE;
in += BLOCK_SIZE; in += BLOCK_SIZE;
} }
else }
else {
while (blocks--) { while (blocks--) {
AsmDecrypt(in, out); AsmDecrypt(in, out);
...@@ -82,6 +83,7 @@ void Twofish::Process(byte* out, const byte* in, word32 sz) ...@@ -82,6 +83,7 @@ void Twofish::Process(byte* out, const byte* in, word32 sz)
out += BLOCK_SIZE; out += BLOCK_SIZE;
in += BLOCK_SIZE; in += BLOCK_SIZE;
} }
}
} }
} }
...@@ -272,25 +274,28 @@ void Twofish::decrypt(const byte* inBlock, const byte* xorBlock, ...@@ -272,25 +274,28 @@ void Twofish::decrypt(const byte* inBlock, const byte* xorBlock,
#if defined(DO_TWOFISH_ASM) #if defined(DO_TWOFISH_ASM)
#ifdef __GNUC__ #ifdef __GNUC__
#define AS1(x) asm(#x); #define AS1(x) #x ";"
#define AS2(x, y) asm(#x ", " #y); #define AS2(x, y) #x ", " #y ";"
#define PROLOG() \ #define PROLOG() \
asm(".intel_syntax noprefix"); \ __asm__ __volatile__ \
AS2( movd mm3, edi ) \ ( \
AS2( movd mm4, ebx ) \ ".intel_syntax noprefix;" \
AS2( movd mm5, esi ) \ "push ebx;" \
AS2( movd mm6, ebp ) \ "push ebp;" \
AS2( mov edi, DWORD PTR [ebp + 8] ) \ "movd mm3, eax;" \
AS2( mov esi, DWORD PTR [ebp + 12] ) "movd mm6, ebp;"
#define EPILOG() \ #define EPILOG() \
AS2( movd esp, mm6 ) \ "pop ebp;" \
AS2( movd esi, mm5 ) \ "pop ebx;" \
AS2( movd ebx, mm4 ) \ "emms;" \
AS2( movd edi, mm3 ) \ ".att_syntax;" \
AS1( emms ) \ : \
asm(".att_syntax"); : "D" (this), "S" (inBlock), "a" (outBlock) \
: "%ecx", "%edx", "memory", "cc" \
);
#else #else
#define AS1(x) __asm x #define AS1(x) __asm x
#define AS2(x, y) __asm x, y #define AS2(x, y) __asm x, y
...@@ -424,6 +429,8 @@ void Twofish::decrypt(const byte* inBlock, const byte* xorBlock, ...@@ -424,6 +429,8 @@ void Twofish::decrypt(const byte* inBlock, const byte* xorBlock,
#ifdef _MSC_VER #ifdef _MSC_VER
__declspec(naked) __declspec(naked)
#else
__attribute__ ((noinline))
#endif #endif
void Twofish::AsmEncrypt(const byte* inBlock, byte* outBlock) const void Twofish::AsmEncrypt(const byte* inBlock, byte* outBlock) const
{ {
...@@ -472,7 +479,7 @@ 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 ebp, mm6 )
AS2( movd esi, mm0 ) // k_ AS2( movd esi, mm0 ) // k_
#ifdef __GNUC__ #ifdef __GNUC__
AS2( mov edi, [ebp + 16] ) // outBlock AS2( movd edi, mm3 ) // outBlock
#else #else
AS2( mov edi, [ebp + 12] ) // outBlock AS2( mov edi, [ebp + 12] ) // outBlock
#endif #endif
...@@ -493,7 +500,9 @@ void Twofish::AsmEncrypt(const byte* inBlock, byte* outBlock) const ...@@ -493,7 +500,9 @@ void Twofish::AsmEncrypt(const byte* inBlock, byte* outBlock) const
#ifdef _MSC_VER #ifdef _MSC_VER
__declspec(naked) __declspec(naked)
#else
__attribute__ ((noinline))
#endif #endif
void Twofish::AsmDecrypt(const byte* inBlock, byte* outBlock) const void Twofish::AsmDecrypt(const byte* inBlock, byte* outBlock) const
{ {
...@@ -542,7 +551,7 @@ 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 ebp, mm6 )
AS2( movd esi, mm0 ) // k_ AS2( movd esi, mm0 ) // k_
#ifdef __GNUC__ #ifdef __GNUC__
AS2( mov edi, [ebp + 16] ) // outBlock AS2( movd edi, mm3 ) // outBlock
#else #else
AS2( mov edi, [ebp + 12] ) // outBlock AS2( mov edi, [ebp + 12] ) // outBlock
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment