--- truecrypt/common/crypto.c 2018/04/24 16:44:45 1.1.1.9 +++ truecrypt/common/crypto.c 2018/04/24 16:46:33 1.1.1.11 @@ -1,20 +1,23 @@ -/* Legal Notice: The source code contained in this file has been derived from - the source code of Encryption for the Masses 2.02a, which is Copyright (c) - 1998-99 Paul Le Roux and which is covered by the 'License Agreement for - Encryption for the Masses'. Modifications and additions to that source code - contained in this file are Copyright (c) 2004-2006 TrueCrypt Foundation and - Copyright (c) 2004 TrueCrypt Team, and are covered by TrueCrypt License 2.0 - the full text of which is contained in the file License.txt included in - TrueCrypt binary and source code distribution archives. */ +/* + Legal Notice: The source code contained in this file has been derived from + the source code of Encryption for the Masses 2.02a, which is Copyright (c) + Paul Le Roux and which is covered by the 'License Agreement for Encryption + for the Masses'. Modifications and additions to that source code contained + in this file are Copyright (c) TrueCrypt Foundation and are covered by the + TrueCrypt License 2.2 the full text of which is contained in the file + License.txt included in TrueCrypt binary and source code distribution + packages. */ #include "Tcdefs.h" #include "Crypto.h" #include "Crc.h" -#include "Endian.h" +#include "Common/Endian.h" #ifdef LINUX_DRIVER #include #include +#else +#include #endif /* Update the following when adding a new cipher or EA: @@ -52,21 +55,21 @@ static Cipher Ciphers[] = static EncryptionAlgorithm EncryptionAlgorithms[] = { // Cipher(s) Modes - { { 0, 0 } , { 0, 0, 0 } }, // Must be all-zero - { { AES, 0 } , { LRW, CBC, 0 } }, - { { BLOWFISH, 0 } , { LRW, CBC, 0 } }, - { { CAST, 0 } , { LRW, CBC, 0 } }, - { { SERPENT, 0 } , { LRW, CBC, 0 } }, - { { TRIPLEDES, 0 } , { LRW, CBC, 0 } }, - { { TWOFISH, 0 } , { LRW, CBC, 0 } }, - { { TWOFISH, AES, 0 } , { LRW, OUTER_CBC, 0 } }, - { { SERPENT, TWOFISH, AES, 0 } , { LRW, OUTER_CBC, 0 } }, - { { AES, SERPENT, 0 } , { LRW, OUTER_CBC, 0 } }, - { { AES, TWOFISH, SERPENT, 0 } , { LRW, OUTER_CBC, 0 } }, - { { SERPENT, TWOFISH, 0 } , { LRW, OUTER_CBC, 0 } }, - { { BLOWFISH, AES, 0 } , { INNER_CBC, 0, 0 } }, - { { SERPENT, BLOWFISH, AES, 0 } , { INNER_CBC, 0, 0 } }, - { { 0, 0 } , { 0, 0, 0 } } // Must be all-zero + { { 0, 0 }, { 0, 0, 0 }, 0 }, // Must be all-zero + { { AES, 0 }, { LRW, CBC, 0 }, 1 }, + { { BLOWFISH, 0 }, { LRW, CBC, 0 }, 0 }, + { { CAST, 0 }, { LRW, CBC, 0 }, 0 }, + { { SERPENT, 0 }, { LRW, CBC, 0 }, 1 }, + { { TRIPLEDES, 0 }, { LRW, CBC, 0 }, 0 }, + { { TWOFISH, 0 }, { LRW, CBC, 0 }, 1 }, + { { TWOFISH, AES, 0 }, { LRW, OUTER_CBC, 0 }, 1 }, + { { SERPENT, TWOFISH, AES, 0 }, { LRW, OUTER_CBC, 0 }, 1 }, + { { AES, SERPENT, 0 }, { LRW, OUTER_CBC, 0 }, 1 }, + { { AES, TWOFISH, SERPENT, 0 }, { LRW, OUTER_CBC, 0 }, 1 }, + { { SERPENT, TWOFISH, 0 }, { LRW, OUTER_CBC, 0 }, 1 }, + { { BLOWFISH, AES, 0 }, { INNER_CBC, 0, 0 }, 0 }, + { { SERPENT, BLOWFISH, AES, 0 }, { INNER_CBC, 0, 0 }, 0 }, + { { 0, 0 }, { 0, 0, 0 }, 0 } // Must be all-zero }; // Hash algorithms @@ -81,7 +84,7 @@ static Hash Hashes[] = /* Return values: 0 = success, ERR_CIPHER_INIT_FAILURE (fatal), ERR_CIPHER_INIT_WEAK_KEY (non-fatal) */ int CipherInit (int cipher, unsigned char *key, unsigned __int8 *ks) { - int retVal = 0; + int retVal = ERR_SUCCESS; switch (cipher) { @@ -145,9 +148,9 @@ int CipherInit (int cipher, unsigned cha } // Verify whether all three DES keys are mutually different - if (((*((__int64 *) key) ^ *((__int64 *) key+1)) & 0xFEFEFEFEFEFEFEFE) == 0 - || ((*((__int64 *) key+1) ^ *((__int64 *) key+2)) & 0xFEFEFEFEFEFEFEFE) == 0 - || ((*((__int64 *) key) ^ *((__int64 *) key+2)) & 0xFEFEFEFEFEFEFEFE) == 0) + if (((*((__int64 *) key) ^ *((__int64 *) key+1)) & 0xFEFEFEFEFEFEFEFEULL) == 0 + || ((*((__int64 *) key+1) ^ *((__int64 *) key+2)) & 0xFEFEFEFEFEFEFEFEULL) == 0 + || ((*((__int64 *) key) ^ *((__int64 *) key+2)) & 0xFEFEFEFEFEFEFEFEULL) == 0) retVal = ERR_CIPHER_INIT_WEAK_KEY; // Non-fatal error break; @@ -254,7 +257,10 @@ int EAGetNext (int previousEA) // Return values: 0 = success, ERR_CIPHER_INIT_FAILURE (fatal), ERR_CIPHER_INIT_WEAK_KEY (non-fatal) int EAInit (int ea, unsigned char *key, unsigned __int8 *ks) { - int c, retVal = 0; + int c, retVal = ERR_SUCCESS; + + if (ea == 0) + return ERR_CIPHER_INIT_FAILURE; for (c = EAGetFirstCipher (ea); c != 0; c = EAGetNextCipher (ea, c)) { @@ -301,7 +307,7 @@ int EAInitMode (PCRYPTO_INFO ci) char *EAGetName (char *buf, int ea) { int i = EAGetLastCipher(ea); - strcpy (buf, CipherGetName (i)); + strcpy (buf, (i != 0) ? CipherGetName (i) : "?"); while (i = EAGetPreviousCipher(ea, i)) { @@ -488,6 +494,12 @@ int EAGetPreviousCipher (int ea, int pre } +int EAIsFormatEnabled (int ea) +{ + return EncryptionAlgorithms[ea].FormatEnabled; +} + + Hash *HashGet (int id) { int i; @@ -1105,7 +1117,7 @@ unsigned __int64 LRWSector2Index (unsign // iv: IV // ea: encryption algorithm -void _cdecl +void EncryptSectors (unsigned __int32 *buf, unsigned __int64 secNo, unsigned __int64 noSectors, @@ -1267,7 +1279,7 @@ DecryptBuffer (unsigned __int32 *buf, // iv: IV // ea: encryption algorithm -void _cdecl +void DecryptSectors (unsigned __int32 *buf, unsigned __int64 secNo, unsigned __int64 noSectors,