diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2017-07-21 15:21:13 +0200 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2017-07-22 00:30:19 +0200 |
commit | ff871511af79fd8fb7a09d3ed42220830e6ddcd6 (patch) | |
tree | 100728bb821d4fe1b7622eedd1174920302459e8 /src | |
parent | 0fb2befe3ab57696d5b4c9de6fee344bfd520bf6 (diff) | |
download | VeraCrypt-ff871511af79fd8fb7a09d3ed42220830e6ddcd6.tar.gz VeraCrypt-ff871511af79fd8fb7a09d3ed42220830e6ddcd6.zip |
Windows: reduce size of MBR bootloader by removing unused functions in each build type.
Diffstat (limited to 'src')
-rw-r--r-- | src/Boot/Windows/BootConsoleIo.cpp | 6 | ||||
-rw-r--r-- | src/Boot/Windows/BootDiskIo.cpp | 6 | ||||
-rw-r--r-- | src/Common/Crc.c | 2 | ||||
-rw-r--r-- | src/Common/Crypto.c | 68 | ||||
-rw-r--r-- | src/Common/Crypto.h | 2 | ||||
-rw-r--r-- | src/Common/Endian.c | 14 | ||||
-rw-r--r-- | src/Common/Endian.h | 3 | ||||
-rw-r--r-- | src/Common/Pkcs5.c | 12 |
8 files changed, 36 insertions, 77 deletions
diff --git a/src/Boot/Windows/BootConsoleIo.cpp b/src/Boot/Windows/BootConsoleIo.cpp index 6a5a1595..b03098f0 100644 --- a/src/Boot/Windows/BootConsoleIo.cpp +++ b/src/Boot/Windows/BootConsoleIo.cpp @@ -18,19 +18,21 @@ static int ScreenOutputDisabled = 0; +#if defined(TC_TRACE_INT13) || !defined(TC_WINDOWS_BOOT_RESCUE_DISK_MODE) void DisableScreenOutput () { ++ScreenOutputDisabled; } +#endif - +#ifdef TC_TRACE_INT13 void EnableScreenOutput () { --ScreenOutputDisabled; } - +#endif void PrintChar (char c) { #ifdef TC_BOOT_TRACING_ENABLED diff --git a/src/Boot/Windows/BootDiskIo.cpp b/src/Boot/Windows/BootDiskIo.cpp index a36b2b7c..ea808dd4 100644 --- a/src/Boot/Windows/BootDiskIo.cpp +++ b/src/Boot/Windows/BootDiskIo.cpp @@ -156,28 +156,30 @@ BiosResult ReadWriteSectors (bool write, uint16 bufferSegment, uint16 bufferOffs return result; } +#ifdef TC_WINDOWS_BOOT_RESCUE_DISK_MODE BiosResult ReadWriteSectors (bool write, byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent) { uint16 codeSeg; __asm mov codeSeg, cs return ReadWriteSectors (write, codeSeg, (uint16) buffer, drive, chs, sectorCount, silent); } - BiosResult ReadSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent) { return ReadWriteSectors (false, buffer, drive, chs, sectorCount, silent); } - +#if 0 BiosResult WriteSectors (byte *buffer, byte drive, const ChsAddress &chs, byte sectorCount, bool silent) { return ReadWriteSectors (true, buffer, drive, chs, sectorCount, silent); } +#endif +#endif static BiosResult ReadWriteSectors (bool write, BiosLbaPacket &dapPacket, byte drive, const uint64 §or, uint16 sectorCount, bool silent) { CheckStack(); diff --git a/src/Common/Crc.c b/src/Common/Crc.c index 295bf8da..7e18cb4f 100644 --- a/src/Common/Crc.c +++ b/src/Common/Crc.c @@ -120,8 +120,9 @@ unsigned __int32 GetCrc32 (unsigned char *data, int length) return r ^ 0xFFFFFFFFUL; } +#if 0 BOOL crc32_selftests () { unsigned __int8 testData[32]; unsigned __int8 i; @@ -130,6 +131,7 @@ BOOL crc32_selftests () testData[i] = i; return GetCrc32 (testData, sizeof (testData)) == 0x91267E8AUL; } +#endif #endif // TC_MINIMIZE_CODE_SIZE diff --git a/src/Common/Crypto.c b/src/Common/Crypto.c index c0e77922..c7b0c73d 100644 --- a/src/Common/Crypto.c +++ b/src/Common/Crypto.c @@ -392,19 +392,15 @@ const wchar_t *CipherGetName (int cipherId) { Cipher* pCipher = CipherGet (cipherId); return pCipher? pCipher -> Name : L""; } -#endif int CipherGetBlockSize (int cipherId) { -#ifdef TC_WINDOWS_BOOT - return CipherGet (cipherId) -> BlockSize; -#else Cipher* pCipher = CipherGet (cipherId); return pCipher? pCipher -> BlockSize : 0; -#endif } +#endif int CipherGetKeySize (int cipherId) { #ifdef TC_WINDOWS_BOOT @@ -450,8 +446,9 @@ int EAGetFirst () { return 1; } +#ifndef TC_WINDOWS_BOOT // Returns number of EAs int EAGetCount (void) { int ea, count = 0; @@ -461,8 +458,9 @@ int EAGetCount (void) count++; } return count; } +#endif int EAGetNext (int previousEA) { int id = previousEA + 1; @@ -592,8 +590,10 @@ int EAGetKeySize (int ea) return size; } +#ifndef TC_WINDOWS_BOOT + // Returns the first mode of operation of EA int EAGetFirstMode (int ea) { return (EncryptionAlgorithms[ea].Modes[0]); @@ -611,11 +611,8 @@ int EAGetNextMode (int ea, int previousModeId) return 0; } - -#ifndef TC_WINDOWS_BOOT - // Returns the name of the mode of operation of the whole EA wchar_t *EAGetModeName (int ea, int mode, BOOL capitalLetters) { switch (mode) @@ -644,40 +641,9 @@ int EAGetKeyScheduleSize (int ea) return size; } - -// Returns the largest key size needed by an EA for the specified mode of operation -int EAGetLargestKeyForMode (int mode) -{ - int ea, key = 0; - - for (ea = EAGetFirst (); ea != 0; ea = EAGetNext (ea)) - { - if (!EAIsModeSupported (ea, mode)) - continue; - - if (EAGetKeySize (ea) >= key) - key = EAGetKeySize (ea); - } - return key; -} - - -// Returns the largest key needed by any EA for any mode -int EAGetLargestKey () -{ - int ea, key = 0; - - for (ea = EAGetFirst (); ea != 0; ea = EAGetNext (ea)) - { - if (EAGetKeySize (ea) >= key) - key = EAGetKeySize (ea); - } - - return key; -} - +#ifndef TC_WINDOWS_BOOT // Returns number of ciphers in EA int EAGetCipherCount (int ea) { @@ -686,8 +652,9 @@ int EAGetCipherCount (int ea) return i - 1; } +#endif int EAGetFirstCipher (int ea) { return EncryptionAlgorithms[ea].Ciphers[0]; @@ -731,20 +698,18 @@ int EAGetPreviousCipher (int ea, int previousCipherId) return 0; } - +#ifndef TC_WINDOWS_BOOT int EAIsFormatEnabled (int ea) { return EncryptionAlgorithms[ea].FormatEnabled; } -#ifndef TC_WINDOWS_BOOT int EAIsMbrSysEncEnabled (int ea) { return EncryptionAlgorithms[ea].MbrSysEncEnabled; } -#endif // Returns TRUE if the mode of operation is supported for the encryption algorithm BOOL EAIsModeSupported (int ea, int testedMode) { @@ -757,9 +722,8 @@ BOOL EAIsModeSupported (int ea, int testedMode) } return FALSE; } -#ifndef TC_WINDOWS_BOOT Hash *HashGet (int id) { int i; for (i = 0; Hashes[i].Id != 0; i++) @@ -809,8 +773,24 @@ BOOL HashForSystemEncryption (int hashId) return pHash? pHash -> SystemEncryption : FALSE; } +// Returns the largest key size needed by an EA for the specified mode of operation +int EAGetLargestKeyForMode (int mode) +{ + int ea, key = 0; + + for (ea = EAGetFirst (); ea != 0; ea = EAGetNext (ea)) + { + if (!EAIsModeSupported (ea, mode)) + continue; + + if (EAGetKeySize (ea) >= key) + key = EAGetKeySize (ea); + } + return key; +} + // Returns the maximum number of bytes necessary to be generated by the PBKDF2 (PKCS #5) int GetMaxPkcs5OutSize (void) { int size = 32; diff --git a/src/Common/Crypto.h b/src/Common/Crypto.h index 6f9d65ef..1d0c96e5 100644 --- a/src/Common/Crypto.h +++ b/src/Common/Crypto.h @@ -353,10 +353,10 @@ int EAGetCipherCount (int ea); int EAGetFirstCipher (int ea); int EAGetLastCipher (int ea); int EAGetNextCipher (int ea, int previousCipherId); int EAGetPreviousCipher (int ea, int previousCipherId); -int EAIsFormatEnabled (int ea); #ifndef TC_WINDOWS_BOOT +int EAIsFormatEnabled (int ea); int EAIsMbrSysEncEnabled (int ea); #endif BOOL EAIsModeSupported (int ea, int testedMode); diff --git a/src/Common/Endian.c b/src/Common/Endian.c index 46f6e1bd..cea24d09 100644 --- a/src/Common/Endian.c +++ b/src/Common/Endian.c @@ -42,18 +42,4 @@ uint64 MirrorBytes64 (uint64 x) return (n << 8) | (unsigned __int8) (x >> 56); } #endif -void -LongReverse (unsigned __int32 *buffer, unsigned byteCount) -{ - unsigned __int32 value; - - byteCount /= sizeof (unsigned __int32); - while (byteCount--) - { - value = *buffer; - value = ((value & 0xFF00FF00L) >> 8) | \ - ((value & 0x00FF00FFL) << 8); - *buffer++ = (value << 16) | (value >> 16); - } -} diff --git a/src/Common/Endian.h b/src/Common/Endian.h index ef242baa..000395f4 100644 --- a/src/Common/Endian.h +++ b/src/Common/Endian.h @@ -138,10 +138,9 @@ extern "C" unsigned __int16 MirrorBytes16 (unsigned __int16 x); unsigned __int32 MirrorBytes32 (unsigned __int32 x); #ifndef TC_NO_COMPILER_INT64 uint64 MirrorBytes64 (uint64 x); -#endif -void LongReverse ( unsigned __int32 *buffer , unsigned byteCount ); +#endif #if defined(__cplusplus) } #endif diff --git a/src/Common/Pkcs5.c b/src/Common/Pkcs5.c index 28df35d5..93e748a1 100644 --- a/src/Common/Pkcs5.c +++ b/src/Common/Pkcs5.c @@ -35,20 +35,8 @@ #endif #include "Pkcs5.h" #include "Crypto.h" -void hmac_truncate - ( - char *d1, /* data to be truncated */ - char *d2, /* truncated data */ - int len /* length in bytes to keep */ -) -{ - int i; - for (i = 0; i < len; i++) - d2[i] = d1[i]; -} - #if !defined(TC_WINDOWS_BOOT) || defined(TC_WINDOWS_BOOT_SHA2) typedef struct hmac_sha256_ctx_struct { |