/* Legal Notice: Some portions of the source code contained in this file were derived from the source code of TrueCrypt 7.1a, which is Copyright (c) 2003-2012 TrueCrypt Developers Association and which is governed by the TrueCrypt License 3.0, also from the source code of Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux and which is governed by the 'License Agreement for Encryption for the Masses' Modifications and additions to the original source code (contained in this file) and all other portions of this file are Copyright (c) 2013-2016 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ #ifndef TCDEFS_H #define TCDEFS_H #if defined(_UEFI) #undef _WIN32 #undef _WIN64 #undef _DEBUG #include #include #include void* VeraCryptMemAlloc(IN UINTN size); void VeraCryptMemFree(IN VOID* ptr); #define BOOL int #ifndef FALSE #define FALSE 0 #define TRUE 1 #endif #define max(a,b) ((a)>(b))?(a):(b) #define min(a,b) ((a)<(b))?(a):(b) #ifdef __cplusplus extern "C" { #endif extern unsigned __int64 __cdecl _rotl64(unsigned __int64,int); extern unsigned __int64 __cdecl _rotr64(unsigned __int64,int); extern unsigned int __cdecl _rotl(unsigned int,int); extern unsigned int __cdecl _rotr(unsigned int,int); extern unsigned char _rotr8(unsigned char value, unsigned char shift); extern unsigned short _rotr16(unsigned short value, unsigned char shift); extern unsigned char _rotl8(unsigned char value, unsigned char shift); extern unsigned short _rotl16(unsigned short value, unsigned char shift); #ifdef __cplusplus } #endif #endif // defined(_UEFI) #define TC_APP_NAME "VeraCrypt" // Version displayed to user #define VERSION_STRING "1.20-BETA2" // Version number to compare against driver #define VERSION_NUM 0x0120 // Release date #define TC_STR_RELEASE_DATE L"December 30th, 2016" #define TC_RELEASE_DATE_YEAR 2016 #define TC_RELEASE_DATE_MONTH 12 #define BYTES_PER_KB 1024LL #define BYTES_PER_MB 1048576LL #define BYTES_PER_GB 1073741824LL #define BYTES_PER_TB 1099511627776LL #define BYTES_PER_PB 1125899906842624LL /* GUI/driver errors */ #define WIDE(x) (LPWSTR)L##x #define VC_MAX(a,b) ((a)>(b))?(a):(b) #define VC_MIN(a,b) ((a)<(b))?(a):(b) #ifdef _MSC_VER typedef __int8 int8; typedef __int16 int16; typedef __int32 int32; typedef unsigned __int8 byte; typedef unsigned __int16 uint16; typedef unsigned __int32 uint32; #ifdef TC_NO_COMPILER_INT64 typedef unsigned __int32 TC_LARGEST_COMPILER_UINT; #else typedef unsigned __int64 TC_LARGEST_COMPILER_UINT; typedef __int64 int64; typedef unsigned __int64 uint64; #define LL(x) x##ui64 #endif #pragma warning( disable : 4201 ) // disable: 4201 nonstandard extension used : nameless struct/union #pragma warning( disable : 4324 ) // disable: 4324 structure was padded due to __declspec(align()) #else // !_MSC_VER #include #include #include typedef int8_t int8; typedef int16_t int16; typedef int32_t int32; typedef int64_t int64; typedef uint8_t byte; typedef uint16_t uint16; typedef uint32_t uint32; typedef uint64_t uint64; #define LL(x) x##ULL #if UCHAR_MAX != 0xffU #error UCHAR_MAX != 0xff #endif #define __int8 char #if USHRT_MAX != 0xffffU #error USHRT_MAX != 0xffff #endif #define __int16 short #if UINT_MAX != 0xffffffffU #error UINT_MAX != 0xffffffff #endif #define __int32 int typedef uint64 TC_LARGEST_COMPILER_UINT; #define BOOL int #ifndef FALSE #define FALSE 0 #define TRUE 1 #endif #endif // !_MSC_VER #define TC_INT_TYPES_DEFINED // Integer types required by Cryptolib typedef unsigned __int8 uint_8t; typedef unsigned __int16 uint_16t; typedef unsigned __int32 uint_32t; #ifndef TC_NO_COMPILER_INT64 typedef uint64 uint_64t; #endif typedef union { struct { unsigned __int32 LowPart; unsigned __int32 HighPart; }; #ifndef TC_NO_COMPILER_INT64 uint64 Value; #endif } UINT64_STRUCT; #ifndef __has_builtin // Optional of course #define __has_builtin(x) 0 // Compatibility with non-clang compilers #endif #if defined(_UEFI) typedef UINTN size_t; typedef uint64 uint_64t; typedef CHAR16 wchar_t; typedef int LONG; #define wcscpy StrCpy #define wcslen StrLen #define wcscmp StrCmp #define wcscat StrCat #define memcpy(dest,source,count) CopyMem(dest,source,(UINTN)(count)) #define memset(dest,ch,count) SetMem(dest,(UINTN)(count),(UINT8)(ch)) #define memchr(buf,ch,count) ScanMem8(buf,(UINTN)(count),(UINT8)ch) #define memcmp(buf1,buf2,count) (int)(CompareMem(buf1,buf2,(UINTN)(count))) #define MAX_STRING_SIZE 0x1000 #define strcat(strDest,strSource) AsciiStrCatS(strDest,MAX_STRING_SIZE,strSource) #define strchr(str,ch) ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch) #define strcmp AsciiStrCmp #define strncmp(string1,string2,count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count))) #define strcpy(strDest,strSource) AsciiStrCpyS(strDest,MAX_STRING_SIZE,strSource) #define strncpy(strDest,strSource,count) AsciiStrnCpyS(strDest,MAX_STRING_SIZE,strSource,(UINTN)count) #define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE)) #define strstr AsciiStrStr // #define rotr32(x,n) (((x) >> n) | ((x) << (32 - n))) // #define rotl32(x,n) (((x) << n) | ((x) >> (32 - n))) // #define rotr64(x,n) (((x) >> n) | ((x) << (64 - n))) // #define rotl64(x,n) (((x) << n) | ((x) >> (64 - n))) // #define bswap_32(x) (rotl32((((x) & 0xFF00FF00) >> 8) | (((x) & 0x00FF00FF) << 8), 16U)) // #define bswap_64(x) rotl64(((((((x & LL(0xFF00FF00FF00FF00)) >> 8) | ((x & LL(0x00FF00FF00FF00FF)) << 8)) & LL(0xFFFF0000FFFF0000)) >> 16) | (((((x & LL(0xFF00FF00FF00FF00)) >> 8) | ((x & LL(0x00FF00FF00FF00FF)) << 8)) & LL(0x0000FFFF0000FFFF)) << 16)), 32U) #endif #ifdef TC_WINDOWS_BOOT # ifdef __cplusplus extern "C" # endif void ThrowFatalException (int line); # define TC_THROW_FATAL_EXCEPTION ThrowFatalException (__LINE__) #elif defined (TC_WINDOWS_DRIVER) # define TC_THROW_FATAL_EXCEPTION KeBugCheckEx (SECURITY_SYSTEM, __LINE__, 0, 0, 'VC') #elif defined(_UEFI) void ThrowFatalException(int line); # define TC_THROW_FATAL_EXCEPTION ThrowFatalException (__LINE__) #elif (defined(__clang__) && __has_builtin(__builtin_trap)) \ || (defined(__GNUC__ ) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))) \ || (__has_builtin(__builtin_trap)) # define TC_THROW_FATAL_EXCEPTION __builtin_trap() #else # define TC_THROW_FATAL_EXCEPTION *(char *) 0 = 0 #endif #ifdef __COVERITY__ #undef TC_THROW_FATAL_EXCEPTION #define TC_THROW_FATAL_EXCEPTION __coverity_panic__() #endif #ifdef TC_WINDOWS_DRIVER #include #include /* Standard header file for nt drivers */ #include /* Standard I/O control codes */ #define TCalloc(size) ((void *) ExAllocatePoolWithTag( NonPagedPool, size, 'MMCV' )) #define TCfree(memblock) ExFreePoolWithTag( memblock, 'MMCV' ) #define DEVICE_DRIVER #ifndef BOOL typedef int BOOL; #endif #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE !TRUE #endif #else /* !TC_WINDOWS_DRIVER */ #if !defined(_UEFI) #define TCalloc malloc #define TCfree free #else #define TCalloc VeraCryptMemAlloc #define TCfree VeraCryptMemFree #endif //!defined(_UEFI) #ifdef _WIN32 #ifndef TC_LOCAL_WIN32_WINNT_OVERRIDE # undef _WIN32_WINNT # define _WIN32_WINNT 0x0501 /* Does not apply to the driver */ #endif #include /* Windows header */ #include /* The common controls */ #include /* Process control */ #include #include /* For sprintf */ #include #endif /* _WIN32 */ #endif /* !TC_WINDOWS_DRIVER */ #ifndef TC_TO_STRING # define TC_TO_STRING2(n) #n # define TC_TO_STRING(n) TC_TO_STRING2(n) #endif #ifdef DEVICE_DRIVER # if defined (DEBUG) || defined (DEBUG_TRACE) # if 0 // DbgPrintEx is not available on Windows 2000 # define Dump DbgPrint # else # define Dump(...) DbgPrintEx (DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, __VA_ARGS__) # endif # define DumpMem(...) DumpMemory (__VA_ARGS__) # else # define Dump(...) # define DumpMem(...) # endif #endif #if !defined (trace_msg) && !defined (TC_WINDOWS_BOOT) # if defined(DEBUG) || defined (DEBUG_TRACE) # ifdef DEVICE_DRIVER # define trace_msg Dump # elif defined (_WIN32) # define trace_msg(...) do { char msg[2048]; StringCbPrintfA (msg, sizeof (msg), __VA_ARGS__); OutputDebugString (msg); } while (0) # else # define trace_msg(...) # endif # define trace_point trace_msg (__FUNCTION__ ":" TC_TO_STRING(__LINE__) "\n") # else # define trace_msg(...) # define trace_point # endif #endif #ifdef DEVICE_DRIVER # define TC_EVENT KEVENT # define TC_WAIT_EVENT(EVENT) KeWaitForSingleObject (&EVENT, Executive, KernelMode, FALSE, NULL) #elif defined (_WIN32) # define TC_EVENT HANDLE # define TC_WAIT_EVENT(EVENT) WaitForSingleObject (EVENT, INFINITE) #endif #if defined(_WIN32) && !defined(_UEFI) #define burn(mem,size) do { volatile char *burnm = (volatile char *)(mem); size_t burnc = size; RtlSecureZeroMemory (mem, size); while (burnc--) *burnm++ = 0; } while (0) #else #define burn(mem,size) do { volatile char *burnm = (volatile char *)(mem); int burnc = size; while (burnc--) *burnm++ = 0; } while (0) #endif // The size of the memory area to wipe is in bytes amd it must be a multiple of 8. #ifndef TC_NO_COMPILER_INT64 # define FAST_ERASE64(mem,size) do { volatile uint64 *burnm = (volatile uint64 *)(mem); int burnc = size >> 3; while (burnc--) *burnm++ = 0; } while (0) #else # define FAST_ERASE64(mem,size) do { volatile unsigned __int32 *burnm = (volatile unsigned __int32 *)(mem); int burnc = size >> 2; while (burnc--) *burnm++ = 0; } while (0) #endif #ifdef TC_WINDOWS_BOOT # ifndef max # define max(a,b) (((a) > (b)) ? (a) : (b)) # endif # if defined(__cplusplus) && !defined(_UEFI) extern "C" # endif void EraseMemory (void *memory, int size); # undef burn # define burn EraseMemory #endif #ifdef MAX_PATH #define TC_MAX_PATH MAX_PATH #else #define TC_MAX_PATH 260 /* Includes the null terminator */ #endif #define TC_STR_RELEASED_BY L"Released by IDRIX on " TC_STR_RELEASE_DATE #define MAX_URL_LENGTH 2084 /* Internet Explorer limit. Includes the terminating null character. */ #define TC_HOMEPAGE L"https://www.idrix.fr/" #define TC_APPLINK L"https://www.veracrypt.fr" enum { /* WARNING: ADD ANY NEW CODES AT THE END (DO NOT INSERT THEM BETWEEN EXISTING). DO *NOT* DELETE ANY EXISTING CODES! Changing these values or their meanings may cause incompatibility with other versions (for example, if a new version of the TrueCrypt installer receives an error code from an installed driver whose version is lower, it will report and interpret the error incorrectly). */ ERR_SUCCESS = 0, ERR_OS_ERROR = 1, ERR_OUTOFMEMORY = 2, ERR_PASSWORD_WRONG = 3, ERR_VOL_FORMAT_BAD = 4, ERR_DRIVE_NOT_FOUND = 5, ERR_FILES_OPEN = 6, ERR_VOL_SIZE_WRONG = 7, ERR_COMPRESSION_NOT_SUPPORTED = 8, ERR_PASSWORD_CHANGE_VOL_TYPE = 9, ERR_PASSWORD_CHANGE_VOL_VERSION = 10, ERR_VOL_SEEKING = 11, ERR_VOL_WRITING = 12, ERR_FILES_OPEN_LOCK = 13, ERR_VOL_READING = 14, ERR_DRIVER_VERSION = 15, ERR_NEW_VERSION_REQUIRED = 16, ERR_CIPHER_INIT_FAILURE = 17, ERR_CIPHER_INIT_WEAK_KEY = 18, ERR_SELF_TESTS_FAILED = 19, ERR_SECTOR_SIZE_INCOMPATIBLE = 20, ERR_VOL_ALREADY_MOUNTED = 21, ERR_NO_FREE_DRIVES = 22, ERR_FILE_OPEN_FAILED = 23, ERR_VOL_MOUNT_FAILED = 24, DEPRECATED_ERR_INVALID_DEVICE = 25, ERR_ACCESS_DENIED = 26, ERR_MODE_INIT_FAILED = 27, ERR_DONT_REPORT = 28, ERR_ENCRYPTION_NOT_COMPLETED = 29, ERR_PARAMETER_INCORRECT = 30, ERR_SYS_HIDVOL_HEAD_REENC_MODE_WRONG = 31, ERR_NONSYS_INPLACE_ENC_INCOMPLETE = 32, ERR_USER_ABORT = 33, ERR_UNSUPPORTED_TRUECRYPT_FORMAT = 34, ERR_RAND_INIT_FAILED = 35, ERR_CAPI_INIT_FAILED = 36 }; #endif // #ifndef TCDEFS_H Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#ifndef CRYPTOPP_CONFIG_H
#define CRYPTOPP_CONFIG_H

#ifdef __GNUC__
	#define VC_INLINE	static inline __attribute__((always_inline))
#elif defined (_MSC_VER)
	#define VC_INLINE	__forceinline
#else
	#define VC_INLINE	static inline
#endif

// Clang pretends to be VC++, too.
//   See http://github.com/weidai11/cryptopp/issues/147
#if defined(_MSC_VER) && defined(__clang__) && !defined(_DCSPKG_ANALYZE)
# error: "Unsupported configuration"
#endif

#ifdef __GNUC__
	#define CRYPTOPP_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif


// Apple and LLVM's Clang. Apple Clang version 7.0 roughly equals LLVM Clang version 3.7
#if defined(__clang__ ) && !defined(__apple_build_version__) && !defined(_DCSPKG_ANALYZE) 
	#define CRYPTOPP_LLVM_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
	#define CRYPTOPP_CLANG_INTEGRATED_ASSEMBLER 1
#elif defined(__clang__ ) && defined(__apple_build_version__) && !defined(_DCSPKG_ANALYZE)
	#define CRYPTOPP_APPLE_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
	#define CRYPTOPP_CLANG_INTEGRATED_ASSEMBLER 1
#endif

// Clang due to "Inline assembly operands don't work with .intel_syntax", http://llvm.org/bugs/show_bug.cgi?id=24232
//   TODO: supply the upper version when LLVM fixes it. We set it to 20.0 for compilation purposes.
#if (defined(CRYPTOPP_LLVM_CLANG_VERSION) && CRYPTOPP_LLVM_CLANG_VERSION <= 200000) || (defined(CRYPTOPP_APPLE_CLANG_VERSION) && CRYPTOPP_APPLE_CLANG_VERSION <= 200000) || defined(CRYPTOPP_CLANG_INTEGRATED_ASSEMBLER)
	#define CRYPTOPP_DISABLE_INTEL_ASM 1
#endif

#ifndef CRYPTOPP_L1_CACHE_LINE_SIZE
	// This should be a lower bound on the L1 cache line size. It's used for defense against timing attacks.
    // Also see http://stackoverflow.com/questions/794632/programmatically-get-the-cache-line-size.
    #if defined(_M_X64) || defined(__x86_64__) || (__ILP32__ >= 1)
		#define CRYPTOPP_L1_CACHE_LINE_SIZE 64
	#else
		// L1 cache line size is 32 on Pentium III and earlier
		#define CRYPTOPP_L1_CACHE_LINE_SIZE 32
	#endif
#endif

#if defined(_MSC_VER) && (_MSC_VER > 1200)
	#define CRYPTOPP_MSVC6PP_OR_LATER
#endif

#ifndef CRYPTOPP_ALIGN_DATA
	#if defined(_MSC_VER)
		#define CRYPTOPP_ALIGN_DATA(x) __declspec(align(x))
	#elif defined(__GNUC__)
		#define CRYPTOPP_ALIGN_DATA(x) __attribute__((aligned(x)))
	#else
		#define CRYPTOPP_ALIGN_DATA(x)
	#endif
#endif

#ifndef CRYPTOPP_SECTION_ALIGN16
	#if defined(__GNUC__) && !defined(__APPLE__)
		// the alignment attribute doesn't seem to work without this section attribute when -fdata-sections is turned on
		#define CRYPTOPP_SECTION_ALIGN16 __attribute__((section ("CryptoPP_Align16")))
	#else
		#define CRYPTOPP_SECTION_ALIGN16
	#endif
#endif

#if defined(_MSC_VER) || defined(__fastcall)
	#define CRYPTOPP_FASTCALL __fastcall
#else
	#define CRYPTOPP_FASTCALL
#endif

#ifdef CRYPTOPP_DISABLE_X86ASM		// for backwards compatibility: this macro had both meanings
#define CRYPTOPP_DISABLE_ASM
#define CRYPTOPP_DISABLE_SSE2
#endif

// Apple's Clang prior to 5.0 cannot handle SSE2 (and Apple does not use LLVM Clang numbering...)
#if defined(CRYPTOPP_APPLE_CLANG_VERSION) && (CRYPTOPP_APPLE_CLANG_VERSION < 50000)
# define CRYPTOPP_DISABLE_ASM
#endif

#if !defined(CRYPTOPP_DISABLE_ASM) && ((defined(_MSC_VER) && defined(_M_IX86)) || (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))))
    // C++Builder 2010 does not allow "call label" where label is defined within inline assembly
    #define CRYPTOPP_X86_ASM_AVAILABLE

    #if !defined(CRYPTOPP_DISABLE_SSE2) && (defined(CRYPTOPP_MSVC6PP_OR_LATER) || CRYPTOPP_GCC_VERSION >= 30300 || defined(__SSE2__))
        #define CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 1
    #else
        #define CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 0
    #endif

    // SSE3 was actually introduced in GNU as 2.17, which was released 6/23/2006, but we can't tell what version of binutils is installed.
    // GCC 4.1.2 was released on 2/13/2007, so we'll use that as a proxy for the binutils version. Also see the output of
    // `gcc -dM -E -march=native - < /dev/null | grep -i SSE` for preprocessor defines available.
    #if !defined(CRYPTOPP_DISABLE_SSSE3) && (_MSC_VER >= 1400 || CRYPTOPP_GCC_VERSION >= 40102 || defined(__SSSE3__) || defined(__SSE3__))
        #define CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE 1
    #else
        #define CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE 0
    #endif
#endif

#if !defined(CRYPTOPP_DISABLE_ASM) && defined(_MSC_VER) && defined(_M_X64)
    #define CRYPTOPP_X64_MASM_AVAILABLE
#endif

#if !defined(CRYPTOPP_DISABLE_ASM) && defined(__GNUC__) && defined(__x86_64__)
    #define CRYPTOPP_X64_ASM_AVAILABLE
#endif

#if !defined(CRYPTOPP_DISABLE_SSE2) && (defined(CRYPTOPP_MSVC6PP_OR_LATER) || defined(__SSE2__)) && !defined(_M_ARM)
    #define CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE 1
#else
    #define CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE 0
#endif

#if !defined(CRYPTOPP_DISABLE_ASM) && !defined(CRYPTOPP_DISABLE_SSSE3) && ( \
	defined(__SSSE3__) || (_MSC_VER >= 1500) || \
	(CRYPTOPP_GCC_VERSION >= 40300) || (__INTEL_COMPILER >= 1000) || (__SUNPRO_CC >= 0x5110) || \
	(CRYPTOPP_LLVM_CLANG_VERSION >= 20300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 40000))
	#define CRYPTOPP_SSSE3_AVAILABLE 1
#else
	#define CRYPTOPP_SSSE3_AVAILABLE 0
# endif

#if !defined(CRYPTOPP_DISABLE_SSSE3) && !defined(CRYPTOPP_DISABLE_AESNI) && CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE && (CRYPTOPP_GCC_VERSION >= 40400 || _MSC_FULL_VER >= 150030729 || __INTEL_COMPILER >= 1110 || defined(__AES__))
    #define CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE 1
#else
    #define CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE 0
#endif

#if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE || CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || defined(CRYPTOPP_X64_MASM_AVAILABLE)
    #define CRYPTOPP_BOOL_ALIGN16 1
#else
    #define CRYPTOPP_BOOL_ALIGN16 0
#endif

#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE && (defined(__SSE4_1__) || defined(__INTEL_COMPILER) || defined(_MSC_VER))
    #define CRYPTOPP_BOOL_SSE41_INTRINSICS_AVAILABLE 1
#else
    #define CRYPTOPP_BOOL_SSE41_INTRINSICS_AVAILABLE 0
#endif

// how to allocate 16-byte aligned memory (for SSE2)
#if defined(_MSC_VER)
	#define CRYPTOPP_MM_MALLOC_AVAILABLE
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
	#define CRYPTOPP_MALLOC_ALIGNMENT_IS_16
#elif defined(__linux__) || defined(__sun__) || defined(__CYGWIN__)
	#define CRYPTOPP_MEMALIGN_AVAILABLE
#else
	#define CRYPTOPP_NO_ALIGNED_ALLOC
#endif

// how to declare class constants
#if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__INTEL_COMPILER)
#	define CRYPTOPP_CONSTANT(x) enum {x};
#else
#	define CRYPTOPP_CONSTANT(x) static const int x;
#endif

// Linux provides X32, which is 32-bit integers, longs and pointers on x86_64 using the full x86_64 register set.
// Detect via __ILP32__ (http://wiki.debian.org/X32Port). However, __ILP32__ shows up in more places than
// the System V ABI specs calls out, like on just about any 32-bit system with Clang.
#if ((__ILP32__ >= 1) || (_ILP32 >= 1)) && defined(__x86_64__)
    #define CRYPTOPP_BOOL_X32 1
#else
    #define CRYPTOPP_BOOL_X32 0
#endif

// see http://predef.sourceforge.net/prearch.html
#if (defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(_X86_) || defined(__I86__) || defined(__INTEL__)) && !CRYPTOPP_BOOL_X32
    #define CRYPTOPP_BOOL_X86 1
#else
    #define CRYPTOPP_BOOL_X86 0
#endif

#if (defined(_M_X64) || defined(__x86_64__)) && !CRYPTOPP_BOOL_X32
    #define CRYPTOPP_BOOL_X64 1
#else
    #define CRYPTOPP_BOOL_X64 0
#endif

// Undo the ASM and Intrinsic related defines due to X32.
#if CRYPTOPP_BOOL_X32
# undef CRYPTOPP_BOOL_X64
# undef CRYPTOPP_X64_ASM_AVAILABLE
# undef CRYPTOPP_X64_MASM_AVAILABLE
#endif

#if !defined(CRYPTOPP_NO_UNALIGNED_DATA_ACCESS) && !defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS)
#if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || defined(__powerpc__) || (__ARM_FEATURE_UNALIGNED >= 1))
    #define CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS
#endif
#endif

// this version of the macro is fastest on Pentium 3 and Pentium 4 with MSVC 6 SP5 w/ Processor Pack
#define GETBYTE(x, y) (unsigned int)((unsigned char)((x)>>(8*(y))))
// these may be faster on other CPUs/compilers
// #define GETBYTE(x, y) (unsigned int)(((x)>>(8*(y)))&255)
// #define GETBYTE(x, y) (((byte *)&(x))[y])

#define CRYPTOPP_GET_BYTE_AS_BYTE(x, y) ((byte)((x)>>(8*(y))))

#endif