diff options
author | Alex <kavsrf@gmail.com> | 2016-08-09 22:08:47 +0200 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-08-15 01:09:12 +0200 |
commit | 246233c40262c5be2edfa916cf841dd4bce6598e (patch) | |
tree | 75f17aeeb2aca66ac1cda709311ae710ae3d10d3 /src/Crypto | |
parent | 58cff70724e9d90902a33b0718ccbe8ee4c7b329 (diff) | |
download | VeraCrypt-246233c40262c5be2edfa916cf841dd4bce6598e.tar.gz VeraCrypt-246233c40262c5be2edfa916cf841dd4bce6598e.zip |
Windows EFI Bootloader: modifications to prepare EFI system encryption support (common files with DcsBoot)
Diffstat (limited to 'src/Crypto')
-rw-r--r-- | src/Crypto/Rmd160.c | 12 | ||||
-rw-r--r-- | src/Crypto/Serpent.c | 2 | ||||
-rw-r--r-- | src/Crypto/Sha2.c | 6 | ||||
-rw-r--r-- | src/Crypto/Whirlpool.c | 24 | ||||
-rw-r--r-- | src/Crypto/cpu.c | 20 | ||||
-rw-r--r-- | src/Crypto/cpu.h | 8 | ||||
-rw-r--r-- | src/Crypto/misc.h | 14 |
7 files changed, 53 insertions, 33 deletions
diff --git a/src/Crypto/Rmd160.c b/src/Crypto/Rmd160.c index 9387f9ba..386a1a80 100644 --- a/src/Crypto/Rmd160.c +++ b/src/Crypto/Rmd160.c @@ -9,13 +9,15 @@ /* Adapted for TrueCrypt */ /* Adapted for VeraCrypt */ - +#if !defined(_UEFI) #include <memory.h> +#endif !defined(_UEFI) + #include "Common/Tcdefs.h" #include "Common/Endian.h" #include "Rmd160.h" -#define F(x, y, z) (x ^ y ^ z) +#define F(x, y, z) (x ^ y ^ z) #define G(x, y, z) (z ^ (x & (y^z))) #define H(x, y, z) (z ^ (x | ~y)) #define I(x, y, z) (y ^ (z & (x^y))) @@ -300,7 +302,7 @@ void RMD160Transform (unsigned __int32 *digest, const unsigned __int32 *data) Subround(J, b2, c2, d2, e2, a2, X[ 3], 12, k5); Subround(J, a2, b2, c2, d2, e2, X[12], 6, k5); - Subround(I, e2, a2, b2, c2, d2, X[ 6], 9, k6); + Subround(I, e2, a2, b2, c2, d2, X[ 6], 9, k6); Subround(I, d2, e2, a2, b2, c2, X[11], 13, k6); Subround(I, c2, d2, e2, a2, b2, X[ 3], 15, k6); Subround(I, b2, c2, d2, e2, a2, X[ 7], 7, k6); @@ -383,7 +385,7 @@ void RMD160Transform (unsigned __int32 *digest, const unsigned __int32 *data) Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed by the TrueCrypt License 3.0. - Modifications and additions to the original source code (contained in this file) + 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 @@ -454,7 +456,7 @@ void RMD160Transform (unsigned __int32 *state, const unsigned __int32 *data) for (pos = 0; pos < 160; ++pos) { tmp = a + data[OrderTab[pos]] + KTab[pos >> 4]; - + switch (pos >> 4) { case 0: case 9: tmp += F (b, c, d); break; diff --git a/src/Crypto/Serpent.c b/src/Crypto/Serpent.c index 23c1c504..25bcea96 100644 --- a/src/Crypto/Serpent.c +++ b/src/Crypto/Serpent.c @@ -19,7 +19,9 @@ #include "Crypto/misc.h" #endif +#if !defined(_UEFI) #include <memory.h> +#endif !defined(_UEFI) // linear transformation #define LT(i,a,b,c,d,e) {\ diff --git a/src/Crypto/Sha2.c b/src/Crypto/Sha2.c index 02680eb5..6bc0bd84 100644 --- a/src/Crypto/Sha2.c +++ b/src/Crypto/Sha2.c @@ -69,7 +69,9 @@ */ #include "Common/Endian.h" +#include "Common/Tcdefs.h" #include "Crypto/misc.h" + #define PLATFORM_BYTE_ORDER BYTE_ORDER #define IS_LITTLE_ENDIAN LITTLE_ENDIAN @@ -77,7 +79,9 @@ #define UNROLL_SHA2 /* for SHA2 loop unroll */ #endif +#if !defined(_UEFI) #include <string.h> /* for memcpy() etc. */ +#endif !defined(_UEFI) #include "Sha2.h" @@ -86,7 +90,7 @@ extern "C" { #endif -#if defined( _MSC_VER ) && ( _MSC_VER > 800 ) +#if defined( _MSC_VER ) && ( _MSC_VER > 800 ) && !defined(_UEFI) #pragma intrinsic(memcpy) #endif diff --git a/src/Crypto/Whirlpool.c b/src/Crypto/Whirlpool.c index 19cfad2a..86b3ebf6 100644 --- a/src/Crypto/Whirlpool.c +++ b/src/Crypto/Whirlpool.c @@ -26,7 +26,7 @@ * ``The Whirlpool hashing function,'' * NESSIE submission, 2000 (tweaked version, 2001), * <https://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/whirlpool.zip> - * + * * @author Paulo S.L.M. Barreto * @author Vincent Rijmen. * @@ -68,14 +68,16 @@ * */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> +#include "Common/Tcdefs.h" #include "Common/Endian.h" +#if !defined(_UEFI) +#include <memory.h> +#include <stdlib.h> +#endif + #include "cpu.h" -#include "misc.h" +#include "misc.h" #include "Whirlpool.h" /* @@ -656,7 +658,7 @@ void WhirlpoolTransform(uint64 *digest, const uint64 *block) AS2( and esp, -16) AS2( sub esp, 16*8) AS_PUSH_IF86( ax) - + #if CRYPTOPP_BOOL_X86 #define SSE2_workspace esp+WORD_SZ #elif CRYPTOPP_BOOL_X32 @@ -899,7 +901,7 @@ void WHIRLPOOL_init(WHIRLPOOL_CTX * const ctx) { */ void WHIRLPOOL_add(const unsigned char * input, unsigned __int32 sourceBytes, - WHIRLPOOL_CTX * const ctx) + WHIRLPOOL_CTX * const ctx) { uint64 num, oldCountLo = ctx->countLo, oldCountHi = ctx->countHi; uint64 len = sourceBytes; @@ -911,7 +913,7 @@ void WHIRLPOOL_add(const unsigned char * input, else { uint64* dataBuf = ctx->data; - byte* data = (byte *)dataBuf; + byte* data = (byte *)dataBuf; num = oldCountLo & 63; if (num != 0) // process left over data @@ -963,11 +965,11 @@ void WHIRLPOOL_add(const unsigned char * input, /** * Get the hash value from the hashing state. - * + * * This method uses the invariant: bufferBits < DIGESTBITS */ void WHIRLPOOL_finalize(WHIRLPOOL_CTX * const ctx, - unsigned char * result) + unsigned char * result) { unsigned int num = ctx->countLo & 63; uint64* dataBuf = ctx->data; diff --git a/src/Crypto/cpu.c b/src/Crypto/cpu.c index 21c6c194..c358088d 100644 --- a/src/Crypto/cpu.c +++ b/src/Crypto/cpu.c @@ -60,8 +60,10 @@ static void SigIllHandlerSSE2(int p) int CpuId(uint32 input, uint32 output[4]) { #ifdef CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY +#ifndef _UEFI __try { +#endif __asm { mov eax, input @@ -73,11 +75,13 @@ int CpuId(uint32 input, uint32 output[4]) mov [edi+8], ecx mov [edi+12], edx } - } - __except (EXCEPTION_EXECUTE_HANDLER) +#ifndef _UEFI + } + __except (EXCEPTION_EXECUTE_HANDLER) { return 0; } +#endif // function 0 returns the highest basic function understood in EAX if(input == 0) @@ -123,7 +127,7 @@ static int TrySSE2() { #if CRYPTOPP_BOOL_X64 return 1; -#elif defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY) +#elif defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY) && !defined(_UEFI) volatile int result = 1; #if defined (TC_WINDOWS_DRIVER) && !defined (_WIN64) KFLOATING_SAVE floatingPointState; @@ -150,7 +154,7 @@ static int TrySSE2() return 0; #endif return result; -#else +#elif !defined(_UEFI) // longjmp and clobber warnings. Volatile is required. // http://github.com/weidai11/cryptopp/issues/24 // http://stackoverflow.com/q/7721854 @@ -174,6 +178,8 @@ static int TrySSE2() signal(SIGILL, oldHandler); return result; +#else + return 1; #endif } @@ -198,7 +204,7 @@ VC_INLINE int IsAMD(const uint32 output[4]) (output[3] /*EDX*/ == 0x444D4163); } -#if (defined(__AES__) && defined(__PCLMUL__)) || defined(__INTEL_COMPILER) || CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE +#if !defined (_UEFI) && ((defined(__AES__) && defined(__PCLMUL__)) || defined(__INTEL_COMPILER) || CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE) static int TryAESNI () { @@ -289,7 +295,7 @@ void DetectX86Features() g_hasAESNI = g_hasSSE2 && (cpuid1[2] & (1<<25)); g_hasCLMUL = g_hasSSE2 && (cpuid1[2] & (1<<1)); -#if (defined(__AES__) && defined(__PCLMUL__)) || defined(__INTEL_COMPILER) || CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE +#if !defined (_UEFI) && ((defined(__AES__) && defined(__PCLMUL__)) || defined(__INTEL_COMPILER) || CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE) // Hypervisor = bit 31 of ECX of CPUID leaf 0x1 // reference: http://artemonsecurity.com/vmde.pdf if (!g_hasAESNI && (cpuid1[2] & (1<<31))) @@ -337,7 +343,7 @@ int is_aes_hw_cpu_supported () { if (cpuid[2] & (1<<25)) bHasAESNI = 1; -#if (defined(__AES__) && defined(__PCLMUL__)) || defined(__INTEL_COMPILER) || CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE +#if !defined (_UEFI) && ((defined(__AES__) && defined(__PCLMUL__)) || defined(__INTEL_COMPILER) || CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE) // Hypervisor = bit 31 of ECX of CPUID leaf 0x1 // reference: http://artemonsecurity.com/vmde.pdf if (!bHasAESNI && (cpuid[2] & (1<<31))) diff --git a/src/Crypto/cpu.h b/src/Crypto/cpu.h index df7ec18e..2d26e927 100644 --- a/src/Crypto/cpu.h +++ b/src/Crypto/cpu.h @@ -13,7 +13,7 @@ #else #if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE -#if defined(TC_WINDOWS_DRIVER) +#if defined(TC_WINDOWS_DRIVER) || defined (_UEFI) #if defined(__cplusplus) extern "C" { #endif @@ -82,7 +82,7 @@ extern __m128i _mm_setr_epi32(int _I0, int _I1, int _I2, int _I3); #if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE #if defined(__SSSE3__) || defined(__INTEL_COMPILER) -#if defined(TC_WINDOWS_DRIVER) +#if defined(TC_WINDOWS_DRIVER) || defined (_UEFI) #if defined(__cplusplus) extern "C" { #endif @@ -96,7 +96,7 @@ extern __m128i _mm_shuffle_epi8 (__m128i a, __m128i b); #endif #if defined(__SSE4_1__) || defined(__INTEL_COMPILER) || defined(_MSC_VER) -#if defined(TC_WINDOWS_DRIVER) +#if defined(TC_WINDOWS_DRIVER) || defined (_UEFI) #if defined(__cplusplus) extern "C" { #endif @@ -114,7 +114,7 @@ extern __m128i _mm_insert_epi64(__m128i dst, __int64 s, const int ndx); #endif #if (defined(__AES__) && defined(__PCLMUL__)) || defined(__INTEL_COMPILER) || CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE -#if defined(TC_WINDOWS_DRIVER) +#if defined(TC_WINDOWS_DRIVER) || defined (_UEFI) #if defined(__cplusplus) extern "C" { #endif diff --git a/src/Crypto/misc.h b/src/Crypto/misc.h index e4570664..e7391764 100644 --- a/src/Crypto/misc.h +++ b/src/Crypto/misc.h @@ -2,15 +2,19 @@ #define CRYPTOPP_MISC_H #include "config.h" +#if !defined(_UEFI) #include <string.h> // for memcpy and memmove #ifndef _WIN32 #include <strings.h> // for strcasecmp #define _stricmp strcasecmp #endif +#else +#include "Tcdefs.h" +#endif // !defined(_UEFI) -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(_UEFI) #if _MSC_VER >= 1400 - #ifndef TC_WINDOWS_DRIVER + #if !defined(TC_WINDOWS_DRIVER) && !defined(_UEFI) // VC2005 workaround: disable declarations that conflict with winnt.h #define _interlockedbittestandset CRYPTOPP_DISABLED_INTRINSIC_1 #define _interlockedbittestandreset CRYPTOPP_DISABLED_INTRINSIC_2 @@ -23,7 +27,7 @@ #undef _interlockedbittestandreset64 #endif #define CRYPTOPP_FAST_ROTATE(x) 1 - #elif _MSC_VER >= 1300 + #elif !defined(_UEFI) && _MSC_VER >= 1300 #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32 | (x) == 64) #else #define CRYPTOPP_FAST_ROTATE(x) ((x) == 32) @@ -37,7 +41,7 @@ #define CRYPTOPP_FAST_ROTATE(x) 0 #endif -#if defined( _MSC_VER ) && ( _MSC_VER > 800 ) +#if defined( _MSC_VER ) && ( _MSC_VER > 800 ) && !defined(_UEFI) #pragma intrinsic(memcpy,memset) #endif @@ -80,7 +84,7 @@ #if defined(__GNUC__) && defined(__linux__) #define CRYPTOPP_BYTESWAP_AVAILABLE #include <byteswap.h> -#elif defined(_MSC_VER) && _MSC_VER >= 1300 +#elif defined(_MSC_VER) && _MSC_VER >= 1300 && !defined(_UEFI) #define CRYPTOPP_BYTESWAP_AVAILABLE #define bswap_32(x) _byteswap_ulong(x) #define bswap_64(x) _byteswap_uint64(x) |