Skip to content

Commit

Permalink
TrueCrypt Source Version 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Truecrypt Foundation authored and FreeApophis committed May 29, 2014
1 parent f15ecbe commit b364b38
Show file tree
Hide file tree
Showing 79 changed files with 3,056 additions and 862 deletions.
6 changes: 5 additions & 1 deletion Common/APIDRVR.H
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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-2005 TrueCrypt Foundation and
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. */
Expand Down Expand Up @@ -89,6 +89,8 @@ typedef struct
Password VolumePassword; /* User password */
BOOL bCache; /* Cache passwords in driver */
int nDosDriveNo; /* Drive number to mount */
BOOL bSystemVolume; /* Volume is used by system and hidden from user */
BOOL bPersistentVolume; /* Volume is hidden from user */
BOOL bMountReadOnly; /* Mount volume in read-only mode */
BOOL bMountRemovable; /* Mount volume as removable media */
BOOL bExclusiveAccess; /* Open host file/device in exclusive access mode */
Expand Down Expand Up @@ -128,6 +130,8 @@ typedef struct
int pkcs5Iterations;
BOOL hiddenVolume;
BOOL readOnly;
BOOL systemVolume;
BOOL persistentVolume;
unsigned __int64 volumeCreationTime;
unsigned __int64 headerCreationTime;
unsigned __int64 totalBytesRead;
Expand Down
2 changes: 1 addition & 1 deletion Common/CACHE.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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-2005 TrueCrypt Foundation and
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. */
Expand Down
2 changes: 1 addition & 1 deletion Common/CACHE.H
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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-2005 TrueCrypt Foundation and
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. */
Expand Down
2 changes: 1 addition & 1 deletion Common/CMDLINE.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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-2005 TrueCrypt Foundation and
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. */
Expand Down
2 changes: 1 addition & 1 deletion Common/CMDLINE.H
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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-2005 TrueCrypt Foundation and
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. */
Expand Down
2 changes: 1 addition & 1 deletion Common/COMBO.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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-2005 TrueCrypt Foundation and
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. */
Expand Down
2 changes: 1 addition & 1 deletion Common/COMBO.H
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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-2005 TrueCrypt Foundation and
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. */
Expand Down
2 changes: 1 addition & 1 deletion Common/CRC.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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-2005 TrueCrypt Foundation and
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. */
Expand Down
2 changes: 1 addition & 1 deletion Common/CRC.H
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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-2005 TrueCrypt Foundation and
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. */
Expand Down
101 changes: 88 additions & 13 deletions Common/CRYPTO.C
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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-2005 TrueCrypt Foundation and
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. */
Expand Down Expand Up @@ -59,16 +59,24 @@ static EncryptionAlgorithm EncryptionAlgorithms[] =
{ { SERPENT, 0 } , { LRW, CBC, 0 } },
{ { TRIPLEDES, 0 } , { LRW, CBC, 0 } },
{ { TWOFISH, 0 } , { LRW, CBC, 0 } },
{ { BLOWFISH, AES, 0 } , { INNER_CBC, 0, 0 } },
{ { SERPENT, BLOWFISH, AES, 0 } , { INNER_CBC, 0, 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
};

// Hash algorithms
static Hash Hashes[] =
{
{ RIPEMD160, "RIPEMD-160" },
{ SHA1, "SHA-1" },
{ WHIRLPOOL, "Whirlpool" },
{ 0, 0 }
};

/* 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)
Expand Down Expand Up @@ -135,6 +143,13 @@ int CipherInit (int cipher, unsigned char *key, unsigned __int8 *ks)
retVal = ERR_CIPHER_INIT_WEAK_KEY; // Non-fatal error
break;
}

// 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)
retVal = ERR_CIPHER_INIT_WEAK_KEY; // Non-fatal error

break;

case TWOFISH:
Expand Down Expand Up @@ -473,23 +488,41 @@ int EAGetPreviousCipher (int ea, int previousCipherId)
}


char *get_hash_algo_name (int hash_algo_id)
Hash *HashGet (int id)
{
switch (hash_algo_id)
{
case SHA1: return "SHA-1";
case RIPEMD160: return "RIPEMD-160";
case WHIRLPOOL: return "Whirlpool";
default: return "Unknown";
}
int i;
for (i = 0; Hashes[i].Id != 0; i++)
if (Hashes[i].Id == id)
return &Hashes[i];

return 0;
}


int HashGetIdByName (char *name)
{
int i;
for (i = 0; Hashes[i].Id != 0; i++)
if (strcmp (Hashes[i].Name, name) == 0)
return Hashes[i].Id;

return 0;
}


char *HashGetName (int hashId)
{
return HashGet (hashId) -> Name;
}


PCRYPTO_INFO
crypto_open ()
{
/* Do the crt allocation */
PCRYPTO_INFO cryptoInfo = TCalloc (sizeof (CRYPTO_INFO));
PCRYPTO_INFO cryptoInfo = (PCRYPTO_INFO) TCalloc (sizeof (CRYPTO_INFO));
memset (cryptoInfo, 0, sizeof (CRYPTO_INFO));

#ifndef DEVICE_DRIVER
#ifdef _WIN32
VirtualLock (cryptoInfo, sizeof (CRYPTO_INFO));
Expand Down Expand Up @@ -525,7 +558,49 @@ crypto_close (PCRYPTO_INFO cryptoInfo)
TCfree (cryptoInfo);
}
}



// Detect weak and potentially weak secondary LRW keys.
// Remark: These tests reduce the key search space by approximately 0.001%
BOOL DetectWeakSecondaryKey (unsigned char *key, int len)
{
#define LRW_MAX_SUCCESSIVE_IDENTICAL_BITS 24
#define LRW_MIN_HAMMING_WEIGHT_16 39
#define LRW_MIN_HAMMING_WEIGHT_8 15

int minWeight = (len == 16 ? LRW_MIN_HAMMING_WEIGHT_16 : LRW_MIN_HAMMING_WEIGHT_8);
int i, b, zero = 0, one = 0, zeroTotal = 0, oneTotal = 0;

for (i = 0; i < len; i++)
{
for (b = 7; b >= 0; b--)
{
if ((key[i] & (1 << b)) == 0)
{
zeroTotal++;
zero++;
one = 0;
}
else
{
oneTotal++;
one++;
zero = 0;
}

// Maximum number of consecutive identical bit values
if (one >= LRW_MAX_SUCCESSIVE_IDENTICAL_BITS || zero >= LRW_MAX_SUCCESSIVE_IDENTICAL_BITS)
return TRUE;
}
}

// Minimum and maximum Hamming weight
if (zeroTotal < minWeight || oneTotal < minWeight)
return TRUE;

return FALSE;
}


// Initializes IV and whitening values for sector encryption/decryption in CBC mode.
// IMPORTANT: This function has been deprecated (legacy).
Expand Down
18 changes: 16 additions & 2 deletions Common/CRYPTO.H
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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-2005 TrueCrypt Foundation and
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. */
Expand Down Expand Up @@ -105,13 +105,25 @@ typedef struct
int Modes[3]; // Null terminated array of modes of operation
} EncryptionAlgorithm;

typedef struct
{
int Id; // Hash ID
char *Name; // Name
} Hash;

// Maxium length of scheduled key
#define AES_KS (sizeof(aes_encrypt_ctx) + sizeof(aes_decrypt_ctx))
#define SERPENT_KS (140 * 4)
#define MAX_EXPANDED_KEY (AES_KS + SERPENT_KS + TWOFISH_KS)

#define DISK_WIPE_PASSES 36 // (Gutmann)

/* If a 64-bit block cipher is selected and the volume size is greater than WARN_VOL_SIZE_BLOCK64,
warn and require a confirmation from the user. For n-bit blocks, this constant shall be << 8*2^(n/2);
i.e. for 64-bit ciphers this constant shall be much less than the number of bytes in 2^32 blocks
(birthday bound for 64-bit PRP). */
#define WARN_VOL_SIZE_BLOCK64 1 * BYTES_PER_GB

#include "Aes.h"
#include "Blowfish.h"
#include "Cast.h"
Expand Down Expand Up @@ -205,6 +217,8 @@ void _cdecl DecryptSectors (unsigned __int32 *buf, unsigned __int64 secNo, unsig

unsigned __int64 LRWSector2Index (unsigned __int64 sector, int blockSize, PCRYPTO_INFO ci);

char *get_hash_algo_name (int hash_algo_id);
char *HashGetName (int hash_algo_id);

BOOL DetectWeakSecondaryKey (unsigned char *key, int len);

#endif /* CRYPTO_H */
2 changes: 2 additions & 0 deletions Common/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ typedef struct
BOOL Removable;
BOOL ProtectHiddenVolume;
BOOL PreserveTimestamp;
BOOL SystemVolume;
BOOL PersistentVolume;
Password ProtectedHidVolPassword; /* Password of hidden volume to protect against overwriting */
} MountOptions;

Expand Down
18 changes: 10 additions & 8 deletions Common/Common.rc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ BEGIN
NOT WS_TABSTOP
DEFPUSHBUTTON "OK",IDOK,121,178,50,14
LTEXT "",IDC_HOMEPAGE,18,87,147,12,SS_NOTIFY
LTEXT "Copyright � 2004-2005 TrueCrypt Foundation",IDC_STATIC,
LTEXT "Copyright � 2004-2006 TrueCrypt Foundation",IDC_STATIC,
18,71,207,8
LTEXT "",IDC_FORUMS,192,87,62,8,SS_NOTIFY | NOT WS_VISIBLE
CONTROL 50,IDC_ABOUT_IMG,"Static",SS_BITMAP,0,0,293,49,
Expand Down Expand Up @@ -92,9 +92,9 @@ BEGIN
IDT_HIDDEN_PROT_PASSWD,15,76,91,17
EDITTEXT IDC_PASSWORD_PROT_HIDVOL,112,77,151,14,ES_PASSWORD |
ES_AUTOHSCROLL
CONTROL "Display password",IDC_SHOW_PASSWORD_MO,"Button",
CONTROL "&Display password",IDC_SHOW_PASSWORD_MO,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,112,96,90,10
CONTROL "Use keyfiles",IDC_KEYFILES_ENABLE_HIDVOL_PROT,"Button",
CONTROL "U&se keyfiles",IDC_KEYFILES_ENABLE_HIDVOL_PROT,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,112,109,90,10
PUSHBUTTON "&Keyfiles...",IDC_KEYFILES_HIDVOL_PROT,203,98,60,14
DEFPUSHBUTTON "OK",IDOK,211,7,60,14
Expand All @@ -119,15 +119,15 @@ BEGIN
PUSHBUTTON "Remove",IDC_KEYREMOVE,139,132,62,14
PUSHBUTTON "Remove All",IDC_KEYREMOVEALL,205,132,62,14
CONTROL "Use keyfiles",IDC_KEYFILES_ENABLE,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,7,201,63,10
BS_AUTOCHECKBOX | WS_TABSTOP,7,201,195,10
PUSHBUTTON "Generate Random Keyfile...",IDC_GENERATE_KEYFILE,210,
198,123,14
LTEXT "",IDT_KEYFILES_NOTE,10,160,318,29,0,WS_EX_TRANSPARENT
LTEXT "WARNING: If you lose a keyfile or if its first 1024 kilobytes are corrupted, it will be impossible to mount volumes that use the keyfile!",
IDT_KEYFILE_WARNING,275,44,58,85,0,WS_EX_TRANSPARENT
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,2,152,335,1,
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,2,152,339,1,
WS_EX_STATICEDGE
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,2,190,335,1,
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,2,190,339,1,
WS_EX_STATICEDGE
END

Expand Down Expand Up @@ -190,7 +190,7 @@ BEGIN
EDITTEXT IDC_LRW_KEY,8,93,159,14,ES_AUTOHSCROLL
EDITTEXT IDC_LRW_BLOCK_INDEX,8,118,159,14,ES_AUTOHSCROLL
CONTROL "LRW mode",IDC_LRW_MODE_ENABLED,"Button",BS_AUTOCHECKBOX |
WS_TABSTOP,197,94,118,10
WS_TABSTOP,221,13,95,10
EDITTEXT IDC_PLAINTEXT,8,151,159,14,ES_AUTOHSCROLL
COMBOBOX IDC_PLAINTEXT_SIZE,245,151,36,30,CBS_DROPDOWNLIST |
WS_DISABLED | WS_VSCROLL | WS_TABSTOP
Expand All @@ -214,12 +214,14 @@ BEGIN
CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,1,257,324,1,
WS_EX_STATICEDGE
LTEXT "bits",IDT_PLAINTEXT_SIZE_UNIT,285,153,22,8
LTEXT "Note: When testing Triple DES, the key must be a 192-bit value consisting of three concatenated 64-bit DES keys, where the last 8 bits of each of these keys are parity bits. For more information, see FIPS PUB 46-3.",
LTEXT "Note: When testing Triple DES, the key must be a 192-bit value consisting of three concatenated 64-bit DES keys, where the least significant bit in each byte is a parity bit. For more information, see FIPS PUB 46-3.",
IDT_TEST_VECTORS_NOTE,15,214,293,25,0,WS_EX_TRANSPARENT
GROUPBOX "LRW mode",IDT_LRW_MODE,1,75,323,65
LTEXT "Secondary key (hexadecimal)",IDT_LRW_KEY,8,84,159,8
LTEXT "Block index (hexadecimal)",IDT_LRW_BLOCK_INDEX,8,109,
159,8
CONTROL "Least significant bit first",IDC_LRW_INDEX_LSB,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,175,121,143,10
END

IDD_LEGAL_NOTICES_DLG DIALOGEX 0, 0, 372, 221
Expand Down
Loading

0 comments on commit b364b38

Please sign in to comment.