VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/doc/html/Wear-Leveling.html
blob: e35ab4d91f542034e9dd0497e1c449191f29cbd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>VeraCrypt - Free Open source disk encryption with strong security for the Paranoid</title>
<meta name="description" content="VeraCrypt is free open-source disk encryption software for Windows, Mac OS X and Linux. In case an attacker forces you to reveal the password, VeraCrypt provides plausible deniability. In contrast to file encryption, data encryption performed by VeraCrypt is real-time (on-the-fly), automatic, transparent, needs very little memory, and does not involve temporary unencrypted files."/>
<meta name="keywords" content="encryption, security"/>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>

<div>
<a href="Documentation.html"><img src="VeraCrypt128x128.png" alt="VeraCrypt"/></a>
</div>

<div id="menu">
	<ul>
	  <li><a href="Home.html">Home</a></li>
	  <li><a href="/code/">Source Code</a></li>
	  <li><a href="Downloads.html">Downloads</a></li>
	  <li><a class="active" href="Documentation.html">Documentation</a></li>
	  <li><a href="Donation.html">Donate</a></li>
	  <li><a href="https://sourceforge.net/p/veracrypt/discussion/" target="_blank">Forums</a></li>
	</ul>
</div>

<div>
<p>
<a href="Documentation.html">Documentation</a>
<img src="arrow_right.gif" alt=">>" style="margin-top: 5px">
<a href="Security%20Requirements%20and%20Precautions.html">Security Requirements and Precautions</a>
<img src="arrow_right.gif" alt=">>" style="margin-top: 5px">
<a href="Wear-Leveling.html">Wear-Leveling</a>
</p></div>

<div class="wikidoc">
<h1>Wear-Leveling</h1>
<div style="text-align:left; margin-top:19px; margin-bottom:19px; padding-top:0px; padding-bottom:0px">
Some storage devices (e.g., some solid-state drives, including USB flash drives) and some file systems utilize so-called wear-leveling mechanisms to extend the lifetime of the storage device or medium. These mechanisms ensure that even if an application repeatedly
 writes data to the same logical sector, the data is distributed evenly across the medium (logical sectors are remapped to different physical sectors). Therefore, multiple &quot;versions&quot; of a single sector may be available to an attacker. This may have various
 security implications. For instance, when you change a volume password/keyfile(s), the volume header is, under normal conditions, overwritten with a re-encrypted version of the header. However, when the volume resides on a device that utilizes a wear-leveling
 mechanism, VeraCrypt cannot ensure that the older header is really overwritten. If an adversary found the old volume header (which was to be overwritten) on the device, he could use it to mount the volume using an old compromised password (and/or using compromised
 keyfiles that were necessary to mount the volume before the volume header was re-encrypted). Due to security reasons, we recommend that
<a href="VeraCrypt%20Volume.html" style="text-align:left; color:#0080c0; text-decoration:none.html">
VeraCrypt volumes</a> are not created/stored on devices (or in file systems) that utilize a wear-leveling mechanism (and that VeraCrypt is not used to encrypt any portions of such devices or filesystems).</div>
<div style="text-align:left; margin-top:19px; margin-bottom:19px; padding-top:0px; padding-bottom:0px">
If you decide not to follow this recommendation and you intend to use in-place encryption on a drive that utilizes wear-leveling mechanisms, make sure the partition/drive does not contain any sensitive data before you fully encrypt it (VeraCrypt cannot reliably
 perform secure in-place encryption of existing data on such a drive; however, after the partition/drive has been fully encrypted, any new data that will be saved to it will be reliably encrypted on the fly). That includes the following precautions: Before
 you run VeraCrypt to set up pre-boot authentication, disable the paging files and restart the operating system (you can enable the
<a href="Paging%20File.html" style="text-align:left; color:#0080c0; text-decoration:none.html">
paging files</a> after the system partition/drive has been fully encrypted). <a href="Hibernation%20File.html" style="text-align:left; color:#0080c0; text-decoration:none.html">
Hibernation</a> must be prevented during the period between the moment when you start VeraCrypt to set up pre-boot authentication and the moment when the system partition/drive has been fully encrypted. However, note that even if you follow those steps, it
 is <em style="text-align:left">not</em> guaranteed that you will prevent data leaks and that sensitive data on the device will be securely encrypted. For more information, see the sections
<a href="Data%20Leaks.html" style="text-align:left; color:#0080c0; text-decoration:none.html">
Data Leaks</a>, <a href="Paging%20File.html" style="text-align:left; color:#0080c0; text-decoration:none.html">
Paging File</a>, <a href="Hibernation%20File.html" style="text-align:left; color:#0080c0; text-decoration:none.html">
Hibernation File</a>, and <a href="Memory%20Dump%20Files.html" style="text-align:left; color:#0080c0; text-decoration:none.html">
Memory Dump Files</a>.</div>
<div style="text-align:left; margin-top:19px; margin-bottom:19px; padding-top:0px; padding-bottom:0px">
If you need <a href="Plausible%20Deniability.html" style="text-align:left; color:#0080c0; text-decoration:none.html">
plausible deniability</a>, you must not use VeraCrypt to encrypt any part of (or create encrypted containers on) a device (or file system) that utilizes a wear-leveling mechanism.</div>
<p>To find out whether a device utilizes a wear-leveling mechanism, please refer to documentation supplied with the device or contact the vendor/manufacturer.</p>
</div><div class="ClearBoth"></div></body></html>
class="p">} Hash; // Maxium length of scheduled key #if !defined (TC_WINDOWS_BOOT) || defined (TC_WINDOWS_BOOT_AES) # define AES_KS (sizeof(aes_encrypt_ctx) + sizeof(aes_decrypt_ctx)) #else # define AES_KS (sizeof(aes_context)) #endif #define SERPENT_KS (140 * 4) #ifdef TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE # ifdef TC_WINDOWS_BOOT_AES # define MAX_EXPANDED_KEY AES_KS # elif defined (TC_WINDOWS_BOOT_SERPENT) # define MAX_EXPANDED_KEY SERPENT_KS # elif defined (TC_WINDOWS_BOOT_TWOFISH) # define MAX_EXPANDED_KEY TWOFISH_KS # endif #else #define MAX_EXPANDED_KEY (AES_KS + SERPENT_KS + TWOFISH_KS) #endif #ifdef DEBUG # define PRAND_DISK_WIPE_PASSES 3 #else # define PRAND_DISK_WIPE_PASSES 256 #endif /* specific value for volume header wipe used only when drive is fully wiped. */ #define PRAND_HEADER_WIPE_PASSES 3 #if !defined (TC_WINDOWS_BOOT) || defined (TC_WINDOWS_BOOT_AES) # include "Aes.h" #else # include "AesSmall.h" #endif #include "Aes_hw_cpu.h" #include "Serpent.h" #include "Twofish.h" #include "Rmd160.h" #ifndef TC_WINDOWS_BOOT # include "Sha2.h" # include "Whirlpool.h" #endif #include "GfMul.h" #include "Password.h" typedef struct keyInfo_t { int noIterations; /* Number of times to iterate (PKCS-5) */ int keyLength; /* Length of the key */ __int8 userKey[MAX_PASSWORD]; /* Password (to which keyfiles may have been applied). WITHOUT +1 for the null terminator. */ __int8 salt[PKCS5_SALT_SIZE]; /* PKCS-5 salt */ __int8 master_keydata[MASTER_KEYDATA_SIZE]; /* Concatenated master primary and secondary key(s) (XTS mode). For LRW (deprecated/legacy), it contains the tweak key before the master key(s). For CBC (deprecated/legacy), it contains the IV seed before the master key(s). */ } KEY_INFO, *PKEY_INFO; typedef struct CRYPTO_INFO_t { int ea; /* Encryption algorithm ID */ int mode; /* Mode of operation (e.g., XTS) */ int pkcs5; /* PRF algorithm */ unsigned __int8 ks[MAX_EXPANDED_KEY]; /* Primary key schedule (if it is a cascade, it conatins multiple concatenated keys) */ unsigned __int8 ks2[MAX_EXPANDED_KEY]; /* Secondary key schedule (if cascade, multiple concatenated) for XTS mode. */ BOOL hiddenVolume; // Indicates whether the volume is mounted/mountable as hidden volume #ifndef TC_WINDOWS_BOOT uint16 HeaderVersion; GfCtx gf_ctx; unsigned __int8 master_keydata[MASTER_KEYDATA_SIZE]; /* This holds the volume header area containing concatenated master key(s) and secondary key(s) (XTS mode). For LRW (deprecated/legacy), it contains the tweak key before the master key(s). For CBC (deprecated/legacy), it contains the IV seed before the master key(s). */ unsigned __int8 k2[MASTER_KEYDATA_SIZE]; /* For XTS, this contains the secondary key (if cascade, multiple concatenated). For LRW (deprecated/legacy), it contains the tweak key. For CBC (deprecated/legacy), it contains the IV seed. */ unsigned __int8 salt[PKCS5_SALT_SIZE]; int noIterations; BOOL bTrueCryptMode; int volumePim; uint64 volume_creation_time; // Legacy uint64 header_creation_time; // Legacy BOOL bProtectHiddenVolume; // Indicates whether the volume contains a hidden volume to be protected against overwriting BOOL bHiddenVolProtectionAction; // TRUE if a write operation has been denied by the driver in order to prevent the hidden volume from being overwritten (set to FALSE upon volume mount). uint64 volDataAreaOffset; // Absolute position, in bytes, of the first data sector of the volume. uint64 hiddenVolumeSize; // Size of the hidden volume excluding the header (in bytes). Set to 0 for standard volumes. uint64 hiddenVolumeOffset; // Absolute position, in bytes, of the first hidden volume data sector within the host volume (provided that there is a hidden volume within). This must be set for all hidden volumes; in case of a normal volume, this variable is only used when protecting a hidden volume within it. uint64 hiddenVolumeProtectedSize; BOOL bPartitionInInactiveSysEncScope; // If TRUE, the volume is a partition located on an encrypted system drive and mounted without pre-boot authentication. UINT64_STRUCT FirstDataUnitNo; // First data unit number of the volume. This is 0 for file-hosted and non-system partition-hosted volumes. For partitions within key scope of system encryption this reflects real physical offset within the device (this is used e.g. when such a partition is mounted as a regular volume without pre-boot authentication). uint16 RequiredProgramVersion; BOOL LegacyVolume; uint32 SectorSize; #endif // !TC_WINDOWS_BOOT UINT64_STRUCT VolumeSize; UINT64_STRUCT EncryptedAreaStart; UINT64_STRUCT EncryptedAreaLength; uint32 HeaderFlags; } CRYPTO_INFO, *PCRYPTO_INFO; #ifdef _WIN32 #pragma pack (push) #pragma pack(1) typedef struct BOOT_CRYPTO_HEADER_t { __int16 ea; /* Encryption algorithm ID */ __int16 mode; /* Mode of operation (e.g., XTS) */ __int16 pkcs5; /* PRF algorithm */ } BOOT_CRYPTO_HEADER, *PBOOT_CRYPTO_HEADER; #pragma pack (pop) #endif PCRYPTO_INFO crypto_open (void); void crypto_loadkey (PKEY_INFO keyInfo, char *lpszUserKey, int nUserKeyLen); void crypto_close (PCRYPTO_INFO cryptoInfo); int CipherGetBlockSize (int cipher); int CipherGetKeySize (int cipher); int CipherGetKeyScheduleSize (int cipher); BOOL CipherSupportsIntraDataUnitParallelization (int cipher); #ifndef TC_WINDOWS_BOOT const #endif char * CipherGetName (int cipher); int CipherInit (int cipher, unsigned char *key, unsigned char *ks); #ifndef TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE int EAInit (int ea, unsigned char *key, unsigned char *ks); #else int EAInit (unsigned char *key, unsigned char *ks); #endif BOOL EAInitMode (PCRYPTO_INFO ci); void EncipherBlock(int cipher, void *data, void *ks); void DecipherBlock(int cipher, void *data, void *ks); #ifndef TC_WINDOWS_BOOT void EncipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount); void DecipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount); #endif int EAGetFirst (); int EAGetCount (void); int EAGetNext (int previousEA); char * EAGetName (char *buf, int ea, int guiDisplay); int EAGetByName (char *name); int EAGetKeySize (int ea); int EAGetFirstMode (int ea); int EAGetNextMode (int ea, int previousModeId); char * EAGetModeName (int ea, int mode, BOOL capitalLetters); int EAGetKeyScheduleSize (int ea); int EAGetLargestKey (); int EAGetLargestKeyForMode (int mode); 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); BOOL EAIsModeSupported (int ea, int testedMode); #ifndef TC_WINDOWS_BOOT const #endif char *HashGetName (int hash_algo_id); #ifndef TC_WINDOWS_BOOT Hash *HashGet (int id); void HashGetName2 (char *buf, int hashId); BOOL HashIsDeprecated (int hashId); BOOL HashForSystemEncryption (int hashId); int GetMaxPkcs5OutSize (void); #endif void EncryptDataUnits (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, uint32 nbrUnits, PCRYPTO_INFO ci); void EncryptDataUnitsCurrentThread (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, TC_LARGEST_COMPILER_UINT nbrUnits, PCRYPTO_INFO ci); void DecryptDataUnits (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, uint32 nbrUnits, PCRYPTO_INFO ci); void DecryptDataUnitsCurrentThread (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, TC_LARGEST_COMPILER_UINT nbrUnits, PCRYPTO_INFO ci); void EncryptBuffer (unsigned __int8 *buf, TC_LARGEST_COMPILER_UINT len, PCRYPTO_INFO cryptoInfo); void DecryptBuffer (unsigned __int8 *buf, TC_LARGEST_COMPILER_UINT len, PCRYPTO_INFO cryptoInfo); BOOL IsAesHwCpuSupported (); void EnableHwEncryption (BOOL enable); BOOL IsHwEncryptionEnabled (); #ifdef __cplusplus } #endif #endif /* CRYPTO_H */