From 0364a36f84b2a08c690ec008d4cbb160bdf27a67 Mon Sep 17 00:00:00 2001 From: alt3r 3go Date: Mon, 9 Dec 2019 17:43:33 +0100 Subject: Linux: fix NOASM compilation (#563) (#568) Signed-off-by: alt3r 3go --- src/Common/Crypto.c | 6 +++--- src/Crypto/Camellia.c | 2 +- src/Crypto/Camellia.h | 2 +- src/Crypto/Sha2.c | 2 +- src/Crypto/Sha2.h | 2 +- src/Crypto/Twofish.c | 8 ++++---- src/Crypto/Twofish.h | 4 ++-- src/Makefile | 1 + src/Volume/Cipher.cpp | 16 ++++++++-------- 9 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/Common/Crypto.c b/src/Common/Crypto.c index 89ce2508..913495f4 100644 --- a/src/Common/Crypto.c +++ b/src/Common/Crypto.c @@ -252,7 +252,7 @@ void EncipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount) #endif } #endif -#if CRYPTOPP_BOOL_X64 +#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM) else if (cipher == TWOFISH) { twofish_encrypt_blocks(ks, data, data, (uint32) blockCount); } @@ -369,7 +369,7 @@ void DecipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount) #endif } #endif -#if CRYPTOPP_BOOL_X64 +#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM) else if (cipher == TWOFISH) { twofish_decrypt_blocks(ks, data, data, (uint32) blockCount); } @@ -464,7 +464,7 @@ BOOL CipherSupportsIntraDataUnitParallelization (int cipher) || (cipher == SERPENT && HasSSE2()) || (cipher == KUZNYECHIK && HasSSE2()) #endif -#if CRYPTOPP_BOOL_X64 +#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM) || (cipher == TWOFISH) || (cipher == CAMELLIA) #endif diff --git a/src/Crypto/Camellia.c b/src/Crypto/Camellia.c index 49bc7670..b3a35784 100644 --- a/src/Crypto/Camellia.c +++ b/src/Crypto/Camellia.c @@ -3,7 +3,7 @@ #include "Crypto/cpu.h" #include "Crypto/misc.h" -#if CRYPTOPP_BOOL_X64 +#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM) /* camellia.c ver 1.2.0-x86_64_asm1.1 * diff --git a/src/Crypto/Camellia.h b/src/Crypto/Camellia.h index 988203d0..a1cb832e 100644 --- a/src/Crypto/Camellia.h +++ b/src/Crypto/Camellia.h @@ -17,7 +17,7 @@ void camellia_set_key(const unsigned __int8 userKey[], unsigned __int8 *ks); void camellia_encrypt(const unsigned __int8 *inBlock, unsigned __int8 *outBlock, unsigned __int8 *ks); void camellia_decrypt(const unsigned __int8 *inBlock, unsigned __int8 *outBlock, unsigned __int8 *ks); -#if CRYPTOPP_BOOL_X64 +#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM) void camellia_encrypt_blocks(unsigned __int8 *ks, const byte* in_blk, byte* out_blk, uint32 blockCount); void camellia_decrypt_blocks(unsigned __int8 *ks, const byte* in_blk, byte* out_blk, uint32 blockCount); #endif diff --git a/src/Crypto/Sha2.c b/src/Crypto/Sha2.c index f214f6dd..5949d85e 100644 --- a/src/Crypto/Sha2.c +++ b/src/Crypto/Sha2.c @@ -10,7 +10,7 @@ and released into public domain. #include "Crypto/cpu.h" #include "Crypto/misc.h" -#ifdef _UEFI +#if defined(_UEFI) || defined(CRYPTOPP_DISABLE_ASM) #define NO_OPTIMIZED_VERSIONS #endif diff --git a/src/Crypto/Sha2.h b/src/Crypto/Sha2.h index 37625ce8..7e90abff 100644 --- a/src/Crypto/Sha2.h +++ b/src/Crypto/Sha2.h @@ -22,7 +22,7 @@ extern "C" { #define SHA512_DIGEST_SIZE 64 #define SHA512_BLOCK_SIZE 128 -#if CRYPTOPP_BOOL_X64 +#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM) #define SHA2_ALIGN CRYPTOPP_ALIGN_DATA(32) #else #define SHA2_ALIGN CRYPTOPP_ALIGN_DATA(16) diff --git a/src/Crypto/Twofish.c b/src/Crypto/Twofish.c index 8ab59081..f0906f15 100644 --- a/src/Crypto/Twofish.c +++ b/src/Crypto/Twofish.c @@ -54,7 +54,7 @@ #define UNROLL_TWOFISH #endif -#if CRYPTOPP_BOOL_X64 +#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM) /* these are 64-bit assembly implementation taken from https://github.com/jkivilin/supercop-blockciphers Copyright © 2011-2013 Jussi Kivilinna @@ -630,7 +630,7 @@ void twofish_set_key(TwofishInstance *instance, const u4byte in_key[]) uint32 b = rotl32(MDSQ[0][Q[0][Q[0][Q[1][Q[1][i + 1] ^ key[28]] ^ key[20]] ^ key[12]] ^ key[4]] ^ MDSQ[1][Q[0][Q[1][Q[1][Q[0][i + 1] ^ key[29]] ^ key[21]] ^ key[13]] ^ key[5]] ^ MDSQ[2][Q[1][Q[0][Q[0][Q[0][i + 1] ^ key[30]] ^ key[22]] ^ key[14]] ^ key[6]] ^ MDSQ[3][Q[1][Q[1][Q[0][Q[1][i + 1] ^ key[31]] ^ key[23]] ^ key[15]] ^ key[7]], 8); a += b; -#if CRYPTOPP_BOOL_X64 +#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM) if (i < 8) { instance->w[i] = a; @@ -998,7 +998,7 @@ void twofish_set_key(TwofishInstance *instance, const u4byte in_key[]) #ifndef TC_MINIMIZE_CODE_SIZE -#if (CRYPTOPP_BOOL_X64 == 0) +#if (CRYPTOPP_BOOL_X64 == 0) || defined(CRYPTOPP_DISABLE_ASM) void twofish_encrypt(TwofishInstance *ks, const u4byte in_blk[4], u4byte out_blk[4]) { uint32* rk = ks->l_key; @@ -1071,7 +1071,7 @@ void twofish_encrypt(TwofishInstance *instance, const u4byte in_blk[4], u4byte o #ifndef TC_MINIMIZE_CODE_SIZE -#if (CRYPTOPP_BOOL_X64 == 0) +#if (CRYPTOPP_BOOL_X64 == 0) || defined(CRYPTOPP_DISABLE_ASM) void twofish_decrypt(TwofishInstance *ks, const u4byte in_blk[4], u4byte out_blk[4]) { uint32* rk = ks->l_key; diff --git a/src/Crypto/Twofish.h b/src/Crypto/Twofish.h index cec99c7c..e74826eb 100644 --- a/src/Crypto/Twofish.h +++ b/src/Crypto/Twofish.h @@ -35,7 +35,7 @@ extern "C" #endif typedef struct { -#if CRYPTOPP_BOOL_X64 +#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM) u4byte mk_tab[4][256], w[8], k[32]; #else u4byte l_key[40]; @@ -54,7 +54,7 @@ typedef struct /* in_key must be 32-bytes long */ void twofish_set_key(TwofishInstance *instance, const u4byte in_key[]); -#if CRYPTOPP_BOOL_X64 +#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM) void twofish_encrypt_blocks(TwofishInstance *instance, const byte* in_blk, byte* out_blk, uint32 blockCount); void twofish_decrypt_blocks(TwofishInstance *instance, const byte* in_blk, byte* out_blk, uint32 blockCount); #define twofish_encrypt(instance,in_blk,out_blk) twofish_encrypt_blocks(instance, (const byte*) in_blk, (byte*) out_blk, 1) diff --git a/src/Makefile b/src/Makefile index fe0c143b..f102a28c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -151,6 +151,7 @@ endif ifeq "$(origin NOASM)" "command line" CPU_ARCH = unknown + C_CXX_FLAGS += -DCRYPTOPP_DISABLE_X86ASM endif ifeq "$(CPU_ARCH)" "x86" diff --git a/src/Volume/Cipher.cpp b/src/Volume/Cipher.cpp index 32f61b76..40507a2d 100644 --- a/src/Volume/Cipher.cpp +++ b/src/Volume/Cipher.cpp @@ -247,7 +247,7 @@ namespace VeraCrypt if (!Initialized) throw NotInitialized (SRC_POS); -#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE +#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE && !defined(CRYPTOPP_DISABLE_ASM) if ((blockCount >= 4) && IsHwSupportAvailable()) { @@ -263,7 +263,7 @@ namespace VeraCrypt if (!Initialized) throw NotInitialized (SRC_POS); -#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE +#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE && !defined(CRYPTOPP_DISABLE_ASM) if ((blockCount >= 4) && IsHwSupportAvailable()) { @@ -318,7 +318,7 @@ namespace VeraCrypt if (!Initialized) throw NotInitialized (SRC_POS); -#if CRYPTOPP_BOOL_X64 +#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM) twofish_encrypt_blocks ( (TwofishInstance *) ScheduledKey.Ptr(), data, data, blockCount); #else Cipher::EncryptBlocks (data, blockCount); @@ -330,7 +330,7 @@ namespace VeraCrypt if (!Initialized) throw NotInitialized (SRC_POS); -#if CRYPTOPP_BOOL_X64 +#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM) twofish_decrypt_blocks ( (TwofishInstance *) ScheduledKey.Ptr(), data, data, blockCount); #else Cipher::DecryptBlocks (data, blockCount); @@ -339,7 +339,7 @@ namespace VeraCrypt bool CipherTwofish::IsHwSupportAvailable () const { -#if CRYPTOPP_BOOL_X64 +#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM) return true; #else return false; @@ -372,7 +372,7 @@ namespace VeraCrypt if (!Initialized) throw NotInitialized (SRC_POS); -#if CRYPTOPP_BOOL_X64 +#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM) camellia_encrypt_blocks ( ScheduledKey.Ptr(), data, data, blockCount); #else Cipher::EncryptBlocks (data, blockCount); @@ -384,7 +384,7 @@ namespace VeraCrypt if (!Initialized) throw NotInitialized (SRC_POS); -#if CRYPTOPP_BOOL_X64 +#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM) camellia_decrypt_blocks ( ScheduledKey.Ptr(), data, data, blockCount); #else Cipher::DecryptBlocks (data, blockCount); @@ -393,7 +393,7 @@ namespace VeraCrypt bool CipherCamellia::IsHwSupportAvailable () const { -#if CRYPTOPP_BOOL_X64 +#if CRYPTOPP_BOOL_X64 && !defined(CRYPTOPP_DISABLE_ASM) return true; #else return false; -- cgit v1.2.3