Skip to content

Commit

Permalink
Disable X32 inline assembly (GH #686, PR #704)
Browse files Browse the repository at this point in the history
Also use CRYPTOPP_DISABLE_XXX_ASM consistently. The pattern is needed for Clang which still can't compile Intel assembly language. Also see http:https://llvm.org/bugs/show_bug.cgi?id=24232.
  • Loading branch information
noloader committed Aug 18, 2018
1 parent 06cf2ed commit 4282f94
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 112 deletions.
5 changes: 1 addition & 4 deletions gcm-simd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
#include "config.h"
#include "misc.h"

// Clang 3.3 integrated assembler crash on Linux. Other versions
// produce incorrect results. Clang has never handled Intel ASM
// very well. I wish LLVM would fix it.
#if defined(CRYPTOPP_DISABLE_INTEL_ASM)
#if defined(CRYPTOPP_DISABLE_GCM_ASM)
# undef CRYPTOPP_X86_ASM_AVAILABLE
# undef CRYPTOPP_X32_ASM_AVAILABLE
# undef CRYPTOPP_X64_ASM_AVAILABLE
Expand Down
4 changes: 1 addition & 3 deletions gcm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
#ifndef CRYPTOPP_IMPORTS
#ifndef CRYPTOPP_GENERATE_X64_MASM

// Clang 3.3 integrated assembler crash on Linux. Other versions produce incorrect results.
// Clang has never handled Intel ASM very well. I wish LLVM would fix it.
#if defined(CRYPTOPP_DISABLE_INTEL_ASM)
#if defined(CRYPTOPP_DISABLE_GCM_ASM)
# undef CRYPTOPP_X86_ASM_AVAILABLE
# undef CRYPTOPP_X32_ASM_AVAILABLE
# undef CRYPTOPP_X64_ASM_AVAILABLE
Expand Down
6 changes: 6 additions & 0 deletions gcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
#include "authenc.h"
#include "modes.h"

// Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler
// error with .intel_syntax, http:https://llvm.org/bugs/show_bug.cgi?id=24232
#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM)
# define CRYPTOPP_DISABLE_GCM_ASM 1
#endif

NAMESPACE_BEGIN(CryptoPP)

/// \enum GCM_TablesOption
Expand Down
17 changes: 6 additions & 11 deletions rijndael.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ being unloaded from L1 cache, until that round is finished.

NAMESPACE_BEGIN(CryptoPP)

// Clang 3.3 integrated assembler crash on Linux
#if CRYPTOPP_BOOL_X32 || (defined(CRYPTOPP_LLVM_CLANG_VERSION) && (CRYPTOPP_LLVM_CLANG_VERSION < 30400))
# define CRYPTOPP_DISABLE_RIJNDAEL_ASM
#endif

// Hack for http:https://github.com/weidai11/cryptopp/issues/42 and http:https://github.com/weidai11/cryptopp/issues/132
#if (CRYPTOPP_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE))
# define CRYPTOPP_ALLOW_RIJNDAEL_UNALIGNED_DATA_ACCESS 1
Expand Down Expand Up @@ -769,7 +764,7 @@ CRYPTOPP_NAKED void CRYPTOPP_FASTCALL Rijndael_Enc_AdvancedProcessBlocks(void *l
{
CRYPTOPP_UNUSED(locals); CRYPTOPP_UNUSED(k);

#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
#if CRYPTOPP_BOOL_X86

#define L_REG esp
#define L_INDEX(i) (L_REG+768+i)
Expand Down Expand Up @@ -869,7 +864,7 @@ CRYPTOPP_NAKED void CRYPTOPP_FASTCALL Rijndael_Enc_AdvancedProcessBlocks(void *l
AS2( mov edi, [g_cacheLineSize])
#endif

#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
#if CRYPTOPP_BOOL_X86
AS2( mov [ecx+16*12+16*4], esp) // save esp to L_SP
AS2( lea esp, [ecx-768])
#endif
Expand Down Expand Up @@ -929,7 +924,7 @@ CRYPTOPP_NAKED void CRYPTOPP_FASTCALL Rijndael_Enc_AdvancedProcessBlocks(void *l
AS2( movd eax, xmm1)
AS2( mov al, BYTE PTR [WORD_REG(si)+15])
AS2( MOVD MM(2), eax)
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
#if CRYPTOPP_BOOL_X86
AS2( mov eax, 1)
AS2( movd mm3, eax)
#endif
Expand Down Expand Up @@ -1057,7 +1052,7 @@ CRYPTOPP_NAKED void CRYPTOPP_FASTCALL Rijndael_Enc_AdvancedProcessBlocks(void *l
AS2( xor cl, ch)
AS2( and WORD_REG(cx), 255)
ASL(5)
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
#if CRYPTOPP_BOOL_X86
AS2( paddb MM(2), mm3)
#else
AS2( add MM(2), 1)
Expand Down Expand Up @@ -1158,7 +1153,7 @@ CRYPTOPP_NAKED void CRYPTOPP_FASTCALL Rijndael_Enc_AdvancedProcessBlocks(void *l
AS2( movdqu xmm2, [WORD_REG(ax)])
AS2( pxor xmm2, xmm4)

#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
#if CRYPTOPP_BOOL_X86
AS2( movdqa xmm0, [L_INCREMENTS])
AS2( paddd xmm0, [L_INBLOCKS])
AS2( movdqa [L_INBLOCKS], xmm0)
Expand Down Expand Up @@ -1206,7 +1201,7 @@ CRYPTOPP_NAKED void CRYPTOPP_FASTCALL Rijndael_Enc_AdvancedProcessBlocks(void *l
AS2( movaps [WORD_REG(ax)+4*16], xmm0)
AS2( movaps [WORD_REG(ax)+5*16], xmm0)
AS2( movaps [WORD_REG(ax)+6*16], xmm0)
#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32
#if CRYPTOPP_BOOL_X86
AS2( mov esp, [L_SP])
AS1( emms)
#endif
Expand Down
6 changes: 6 additions & 0 deletions rijndael.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
#include "seckey.h"
#include "secblock.h"

// Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler
// error with .intel_syntax, http:https://llvm.org/bugs/show_bug.cgi?id=24232
#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM)
# define CRYPTOPP_DISABLE_RIJNDAEL_ASM 1
#endif

#if CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_ARM32 || \
CRYPTOPP_BOOL_ARM64 || CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64
# define CRYPTOPP_RIJNDAEL_ADVANCED_PROCESS_BLOCKS 1
Expand Down
5 changes: 3 additions & 2 deletions salsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
#include "strciphr.h"
#include "secblock.h"

// "Inline assembly operands don't work with .intel_syntax", http:https://llvm.org/bugs/show_bug.cgi?id=24232
// Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler
// error with .intel_syntax, http:https://llvm.org/bugs/show_bug.cgi?id=24232
#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM)
# define CRYPTOPP_DISABLE_SALSA_ASM
# define CRYPTOPP_DISABLE_SALSA_ASM 1
#endif

NAMESPACE_BEGIN(CryptoPP)
Expand Down
7 changes: 7 additions & 0 deletions sha-simd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
#include "sha.h"
#include "misc.h"

#if defined(CRYPTOPP_DISABLE_SHA_ASM)
# undef CRYPTOPP_X86_ASM_AVAILABLE
# undef CRYPTOPP_X32_ASM_AVAILABLE
# undef CRYPTOPP_X64_ASM_AVAILABLE
# undef CRYPTOPP_SSE2_ASM_AVAILABLE
#endif

#if (CRYPTOPP_SHANI_AVAILABLE)
# include <nmmintrin.h>
# include <immintrin.h>
Expand Down
7 changes: 0 additions & 7 deletions sha.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@
#include "misc.h"
#include "cpu.h"

// Clang 3.3 integrated assembler crash on Linux
// http:https://github.com/weidai11/cryptopp/issues/264
// Clang 3.4.1 (x86) crash on FreeBSD 10.3. Clang 3.4.1 (x64) works fine.
#if (defined(CRYPTOPP_LLVM_CLANG_VERSION) && (CRYPTOPP_LLVM_CLANG_VERSION < 30500)) || CRYPTOPP_BOOL_X32
# define CRYPTOPP_DISABLE_SHA_ASM
#endif

#if defined(CRYPTOPP_DISABLE_SHA_ASM)
# undef CRYPTOPP_X86_ASM_AVAILABLE
# undef CRYPTOPP_X32_ASM_AVAILABLE
Expand Down
6 changes: 6 additions & 0 deletions sha.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
#include "config.h"
#include "iterhash.h"

// Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler
// error with .intel_syntax, http:https://llvm.org/bugs/show_bug.cgi?id=24232
#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM)
# define CRYPTOPP_DISABLE_SHA_ASM 1
#endif

NAMESPACE_BEGIN(CryptoPP)

/// \brief SHA-1 message digest
Expand Down
8 changes: 4 additions & 4 deletions sosemanuk.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
#include "strciphr.h"
#include "secblock.h"

// Clang due to "Inline assembly operands don't work with .intel_syntax"
// https:https://llvm.org/bugs/show_bug.cgi?id=24232
// Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler
// error with .intel_syntax, http:https://llvm.org/bugs/show_bug.cgi?id=24232
#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM)
# define CRYPTOPP_DISABLE_SOSEMANUK_ASM
# define CRYPTOPP_DISABLE_SOSEMANUK_ASM 1
#endif

NAMESPACE_BEGIN(CryptoPP)

/// \brief Sosemanuk stream cipher information
/// \since Crypto++ 5.5
/// \since Crypto++ 5.5
struct SosemanukInfo : public VariableKeyLength<16, 1, 32, 1, SimpleKeyingInterface::UNIQUE_IV, 16>
{
CRYPTOPP_STATIC_CONSTEXPR const char* StaticAlgorithmName() {return "Sosemanuk";}
Expand Down
6 changes: 3 additions & 3 deletions tiger.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include "config.h"
#include "iterhash.h"

// Clang 3.3 integrated assembler crash on Linux
// http:https://github.com/weidai11/cryptopp/issues/264
#if (defined(CRYPTOPP_LLVM_CLANG_VERSION) && (CRYPTOPP_LLVM_CLANG_VERSION < 30400)) || CRYPTOPP_BOOL_X32
// Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler
// error with .intel_syntax, http:https://llvm.org/bugs/show_bug.cgi?id=24232
#if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_INTEL_ASM)
# define CRYPTOPP_DISABLE_TIGER_ASM 1
#endif

Expand Down
Loading

0 comments on commit 4282f94

Please sign in to comment.