VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Tcdefs.h
AgeCommit message (Collapse)AuthorFilesLines
2018-09-03Increment version to 1.23-BETA8 and update release notes.Mounir IDRASSI1-2/+2
2018-09-03Increment version to 1.23-BETA7 and update release notes.Mounir IDRASSI1-3/+3
2018-08-24Increment version to 1.23-BETA6Mounir IDRASSI1-2/+2
2018-08-18Increment version to 1.23-BETA5 and update release notesMounir IDRASSI1-2/+2
2018-08-16Increment version to 1.23-BETA4 and update release notes.Mounir IDRASSI1-2/+2
2018-08-12Increment version to 1.23-BETA3 and update release notes.Mounir IDRASSI1-3/+3
2018-07-05Increment version to 1.23-BETA2Mounir IDRASSI1-3/+3
2018-05-03Increment version to 1.23-BETA1Mounir IDRASSI1-3/+3
2018-04-23Increment version to 1.23-BETA0 (1.23.0)Mounir IDRASSI1-4/+4
2018-03-30Increment version to 1.22 (1.22.9)Mounir IDRASSI1-2/+2
2018-03-28Increment version to 1.22-BETA8 (1.22.8)Mounir IDRASSI1-2/+2
2018-03-27Increment version to 1.22-BETA7 (1.22.7)Mounir IDRASSI1-2/+2
2018-03-25Increment version to 1.22-BETA6 (1.22.6)Mounir IDRASSI1-2/+2
2018-03-22Increment version to 1.22-BETA5 (1.22.5)Mounir IDRASSI1-4/+4
2017-12-09Increment version to 1.22-BETA4 (1.22.4)Mounir IDRASSI1-3/+3
2017-08-02Windows: Increment version to 1.22-BETA3Mounir IDRASSI1-3/+3
2017-07-29Windows: increment version to 1.22-BETA2-Build6Mounir IDRASSI1-2/+2
2017-07-27Windows: increment version to 1.22-BETA2-Build5Mounir IDRASSI1-2/+2
2017-07-23Windows: Increment version to 1.22-BETA2-Build1Mounir IDRASSI1-2/+2
2017-07-20Windows: Increment version to 1.22-BETA1-Build4Mounir IDRASSI1-2/+2
2017-07-19Windows: Increment version to 1.22-BETA0Mounir IDRASSI1-3/+3
2017-07-09Change 1.21 release date to July 9th 2017Mounir IDRASSI1-1/+1
2017-07-09Increment version to 1.21.5Mounir IDRASSI1-1/+1
2017-07-07Change 1.21 release date to July 7th 2017Mounir IDRASSI1-1/+1
2017-07-05Increment version to 1.21.4Mounir IDRASSI1-1/+1
2017-07-04Windows Driver: correctly save and restore extended processor state when ↵Mounir IDRASSI1-0/+20
performing AVX operations on Windows 7 and later. Enhance readability of code handling save/restore of floating point state.
2017-07-03Change 1.21 release date to July 3rd 2017Mounir IDRASSI1-1/+1
2017-07-02Increment version to 1.21 (1.21.1)Mounir IDRASSI1-4/+4
2017-06-29Set 1.20 release date to June 29th 2017Mounir IDRASSI1-1/+1
2017-06-29Update release date and increment version to 1.20.3.4Mounir IDRASSI1-1/+1
2017-06-23Update IDRIX copyright yearMounir IDRASSI1-1/+1
2017-06-23Increment version to 1.20 (1.20.3)Mounir IDRASSI1-3/+3
2017-06-10Windows Driver Security: Use enhanced protection of NX pool under Windows 8 ↵Mounir IDRASSI1-1/+9
and later.
2017-06-05Beta2 patch 1kavsrf1-4/+4
Edit DcsProp and PlatformInfo from System->Settings EFI loader updated
2017-05-15Replace Codeplex links by ones on veracrypt.frMounir IDRASSI1-3/+2
2016-12-30-1/+1
2016-08-17Linux: fix various compilation issues under Linux.Mounir IDRASSI1-0/+4
2016-08-16Increment version to 1.18. Update user guide PDF file.VeraCrypt_1.18_PreReleaseMounir IDRASSI1-4/+4
2016-08-15Windows EFI Bootloader: modifications to prepare EFI system encryption ↵Alex1-3/+88
support (common files with DcsBoot)
2016-08-15Windows Driver: Add extra traces and enable tracing in release build if ↵Mounir IDRASSI1-3/+3
DEBUG_TRACE defined.
2016-06-02Crypto: Add support for Japanese encryption standard Camellia, including for ↵Mounir IDRASSI1-4/+4
system encryption.
2016-05-10Remove trailing whitespaceDavid Foerster1-9/+9
2016-05-10Normalize all line terminatorsDavid Foerster1-323/+323
2016-02-21Linux & MacOSX: better implementation for TC_THROW_FATAL_EXCEPTION to use ↵Mounir IDRASSI1-0/+8
__builtin_trap when available.
2016-02-14Increment version to 1.17. Update user guide PDF file.Mounir IDRASSI1-5/+5
span>; unsigned int fatsecs; if(ft->cluster_size == 0) // 'Default' cluster size { uint32 clusterSize; // Determine optimal cluster size to minimize FAT size (mounting delay), maximize number of files, keep 4 KB alignment, etc. if (volumeSize >= 2 * BYTES_PER_TB) clusterSize = 256 * BYTES_PER_KB; else if (volumeSize >= 512 * BYTES_PER_GB) clusterSize = 128 * BYTES_PER_KB; else if (volumeSize >= 128 * BYTES_PER_GB) clusterSize = 64 * BYTES_PER_KB; else if (volumeSize >= 64 * BYTES_PER_GB) clusterSize = 32 * BYTES_PER_KB; else if (volumeSize >= 32 * BYTES_PER_GB) clusterSize = 16 * BYTES_PER_KB; else if (volumeSize >= 16 * BYTES_PER_GB) clusterSize = 8 * BYTES_PER_KB; else if (volumeSize >= 512 * BYTES_PER_MB) clusterSize = 4 * BYTES_PER_KB; else if (volumeSize >= 256 * BYTES_PER_MB) clusterSize = 2 * BYTES_PER_KB; else if (volumeSize >= 1 * BYTES_PER_MB) clusterSize = 1 * BYTES_PER_KB; else clusterSize = 512; ft->cluster_size = clusterSize / ft->sector_size; if (ft->cluster_size == 0) ft->cluster_size = 1; if (((unsigned __int64) ft->cluster_size * ft->sector_size) > TC_MAX_FAT_CLUSTER_SIZE) ft->cluster_size = TC_MAX_FAT_CLUSTER_SIZE / ft->sector_size; if (ft->cluster_size > 128) ft->cluster_size = 128; } if (volumeSize <= TC_MAX_FAT_CLUSTER_SIZE * 4) ft->cluster_size = 1; // Geometry always set to SECTORS/1/1 ft->secs_track = 1; ft->heads = 1; ft->dir_entries = 512; ft->fats = 2; ft->media = 0xf8; ft->hidden = 0; ft->size_root_dir = ft->dir_entries * 32; // FAT12 ft->size_fat = 12; ft->reserved = 2; fatsecs = ft->num_sectors - (ft->size_root_dir + ft->sector_size - 1) / ft->sector_size - ft->reserved; ft->cluster_count = (int) (((unsigned __int64) fatsecs * ft->sector_size) / ((unsigned __int64) ft->cluster_size * ft->sector_size)); ft->fat_length = (((ft->cluster_count * 3 + 1) >> 1) + ft->sector_size - 1) / ft->sector_size; if (ft->cluster_count >= 4085) // FAT16 { ft->size_fat = 16; ft->reserved = 2; fatsecs = ft->num_sectors - (ft->size_root_dir + ft->sector_size - 1) / ft->sector_size - ft->reserved; ft->cluster_count = (int) (((__int64) fatsecs * ft->sector_size) / (ft->cluster_size * ft->sector_size)); ft->fat_length = (ft->cluster_count * 2 + ft->sector_size - 1) / ft->sector_size; } if(ft->cluster_count >= 65525) // FAT32 { ft->size_fat = 32; ft->reserved = 32 - 1; do { ft->reserved++; fatsecs = ft->num_sectors - ft->reserved; ft->size_root_dir = ft->cluster_size * ft->sector_size; ft->cluster_count = (int) (((unsigned __int64) fatsecs * ft->sector_size) / (ft->cluster_size * ft->sector_size)); ft->fat_length = (ft->cluster_count * 4 + ft->sector_size - 1) / ft->sector_size; // Align data area on TC_MAX_VOLUME_SECTOR_SIZE } while (ft->sector_size == TC_SECTOR_SIZE_LEGACY && (ft->reserved * ft->sector_size + ft->fat_length * ft->fats * ft->sector_size) % TC_MAX_VOLUME_SECTOR_SIZE != 0); } ft->cluster_count -= ft->fat_length * ft->fats / ft->cluster_size; if (ft->num_sectors >= 65536 || ft->size_fat == 32) { ft->sectors = 0; ft->total_sect = ft->num_sectors; } else { ft->sectors = (uint16) ft->num_sectors; ft->total_sect = 0; } } void PutBoot (fatparams * ft, unsigned char *boot) { int cnt = 0; boot[cnt++] = 0xeb; /* boot jump */ boot[cnt++] = (ft->size_fat == 32)? 0x58: 0x3c; boot[cnt++] = 0x90; memcpy (boot + cnt, "MSDOS5.0", 8); /* system id */ cnt += 8; *(__int16 *)(boot + cnt) = LE16(ft->sector_size); /* bytes per sector */ cnt += 2; boot[cnt++] = (__int8) ft->cluster_size; /* sectors per cluster */ *(__int16 *)(boot + cnt) = LE16(ft->reserved); /* reserved sectors */ cnt += 2; boot[cnt++] = (__int8) ft->fats; /* 2 fats */ if(ft->size_fat == 32) { boot[cnt++] = 0x00; boot[cnt++] = 0x00; } else { *(__int16 *)(boot + cnt) = LE16(ft->dir_entries); /* 512 root entries */ cnt += 2; } *(__int16 *)(boot + cnt) = LE16(ft->sectors); /* # sectors */ cnt += 2; boot[cnt++] = (__int8) ft->media; /* media byte */ if(ft->size_fat == 32) { boot[cnt++] = 0x00; boot[cnt++] = 0x00; } else { *(__int16 *)(boot + cnt) = LE16((uint16) ft->fat_length); /* fat size */ cnt += 2; } *(__int16 *)(boot + cnt) = LE16(ft->secs_track); /* # sectors per track */ cnt += 2; *(__int16 *)(boot + cnt) = LE16(ft->heads); /* # heads */ cnt += 2; *(__int32 *)(boot + cnt) = LE32(ft->hidden); /* # hidden sectors */ cnt += 4; *(__int32 *)(boot + cnt) = LE32(ft->total_sect); /* # huge sectors */ cnt += 4; if(ft->size_fat == 32) { *(__int32 *)(boot + cnt) = LE32(ft->fat_length); cnt += 4; /* fat size 32 */ boot[cnt++] = 0x00; /* ExtFlags */ boot[cnt++] = 0x00; boot[cnt++] = 0x00; /* FSVer */ boot[cnt++] = 0x00; boot[cnt++] = 0x02; /* RootClus */ boot[cnt++] = 0x00; boot[cnt++] = 0x00; boot[cnt++] = 0x00; boot[cnt++] = 0x01; /* FSInfo */ boot[cnt++] = 0x00; boot[cnt++] = 0x06; /* BkBootSec */ boot[cnt++] = 0x00; memset(boot+cnt, 0, 12); cnt+=12; /* Reserved */ } boot[cnt++] = 0x00; /* drive number */ // FIXED 80 > 00 boot[cnt++] = 0x00; /* reserved */ boot[cnt++] = 0x29; /* boot sig */ memcpy (boot + cnt, ft->volume_id, 4); /* vol id */ cnt += 4; memcpy (boot + cnt, ft->volume_name, 11); /* vol title */ cnt += 11; switch(ft->size_fat) /* filesystem type */ { case 12: memcpy (boot + cnt, "FAT12 ", 8); break; case 16: memcpy (boot + cnt, "FAT16 ", 8); break; case 32: memcpy (boot + cnt, "FAT32 ", 8); break; } cnt += 8; memset (boot + cnt, 0, ft->size_fat==32 ? 420:448); /* boot code */ cnt += ft->size_fat==32 ? 420:448; boot[cnt++] = 0x55; boot[cnt++] = 0xaa; /* boot sig */ } /* FAT32 FSInfo */ static void PutFSInfo (unsigned char *sector, fatparams *ft) { memset (sector, 0, ft->sector_size); sector[3]=0x41; /* LeadSig */ sector[2]=0x61; sector[1]=0x52; sector[0]=0x52; sector[484+3]=0x61; /* StrucSig */ sector[484+2]=0x41; sector[484+1]=0x72; sector[484+0]=0x72; // Free cluster count *(uint32 *)(sector + 488) = LE32 (ft->cluster_count - ft->size_root_dir / ft->sector_size / ft->cluster_size); // Next free cluster *(uint32 *)(sector + 492) = LE32 (2); sector[508+3]=0xaa; /* TrailSig */ sector[508+2]=0x55; sector[508+1]=0x00; sector[508+0]=0x00; } int FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void * dev, PCRYPTO_INFO cryptoInfo, BOOL quickFormat, BOOL bDevice) { int write_buf_cnt = 0; char sector[TC_MAX_VOLUME_SECTOR_SIZE], *write_buf; unsigned __int64 nSecNo = startSector; unsigned __int64 nSkipSectors = 128 * (unsigned __int64) BYTES_PER_MB / ft->sector_size; unsigned __int64 num_sectors; DWORD bytesWritten; int x, n; int retVal; CRYPTOPP_ALIGN_DATA(16) char temporaryKey[MASTER_KEYDATA_SIZE]; HWND hwndDlg = (HWND) hwndDlgPtr; LARGE_INTEGER startOffset; LARGE_INTEGER newOffset; // Seek to start sector startOffset.QuadPart = startSector * ft->sector_size; if (!SetFilePointerEx ((HANDLE) dev, startOffset, &newOffset, FILE_BEGIN) || newOffset.QuadPart != startOffset.QuadPart) { return ERR_VOL_SEEKING; } /* Write the data area */ write_buf = (char *)TCalloc (FormatWriteBufferSize); if (!write_buf) return ERR_OUTOFMEMORY; memset (sector, 0, ft->sector_size); if (!RandgetBytes (hwndDlg, ft->volume_id, sizeof (ft->volume_id), FALSE)) goto fail; PutBoot (ft, (unsigned char *) sector); if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector, cryptoInfo) == FALSE) goto fail; /* fat32 boot area */ if (ft->size_fat == 32) { /* fsinfo */ PutFSInfo((unsigned char *) sector, ft); if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector, cryptoInfo) == FALSE) goto fail; /* reserved */ while (nSecNo - startSector < 6) { memset (sector, 0, ft->sector_size); sector[508+3]=0xaa; /* TrailSig */ sector[508+2]=0x55; if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector, cryptoInfo) == FALSE) goto fail; } /* bootsector backup */ memset (sector, 0, ft->sector_size); PutBoot (ft, (unsigned char *) sector); if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector, cryptoInfo) == FALSE) goto fail; PutFSInfo((unsigned char *) sector, ft); if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector, cryptoInfo) == FALSE) goto fail; } /* reserved */ while (nSecNo - startSector < (unsigned int)ft->reserved) { memset (sector, 0, ft->sector_size); if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector, cryptoInfo) == FALSE) goto fail; } /* write fat */ for (x = 1; x <= ft->fats; x++) { for (n = 0; n < ft->fat_length; n++) { memset (sector, 0, ft->sector_size); if (n == 0) { unsigned char fat_sig[12]; if (ft->size_fat == 32) { fat_sig[0] = (unsigned char) ft->media; fat_sig[1] = fat_sig[2] = 0xff; fat_sig[3] = 0x0f; fat_sig[4] = fat_sig[5] = fat_sig[6] = 0xff; fat_sig[7] = 0x0f; fat_sig[8] = fat_sig[9] = fat_sig[10] = 0xff; fat_sig[11] = 0x0f; memcpy (sector, fat_sig, 12); } else if (ft->size_fat == 16) { fat_sig[0] = (unsigned char) ft->media; fat_sig[1] = 0xff; fat_sig[2] = 0xff; fat_sig[3] = 0xff; memcpy (sector, fat_sig, 4); } else if (ft->size_fat == 12) { fat_sig[0] = (unsigned char) ft->media; fat_sig[1] = 0xff; fat_sig[2] = 0xff; fat_sig[3] = 0x00; memcpy (sector, fat_sig, 4); } } if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector, cryptoInfo) == FALSE) goto fail; } } /* write rootdir */ for (x = 0; x < ft->size_root_dir / ft->sector_size; x++) { memset (sector, 0, ft->sector_size); if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector, cryptoInfo) == FALSE) goto fail; } /* Fill the rest of the data area with random data */ if(!quickFormat) { CRYPTO_INFO tmpCI; if (!FlushFormatWriteBuffer (dev, write_buf, &write_buf_cnt, &nSecNo, cryptoInfo)) goto fail; /* Generate a random temporary key set to be used for "dummy" encryption that will fill the free disk space (data area) with random data. This is necessary for plausible deniability of hidden volumes (and also reduces the amount of predictable plaintext within the volume). */ VirtualLock (&tmpCI, sizeof (tmpCI)); memcpy (&tmpCI, cryptoInfo, sizeof (CRYPTO_INFO)); cryptoInfo = &tmpCI; // Temporary master key if (!RandgetBytes (hwndDlg, temporaryKey, EAGetKeySize (cryptoInfo->ea), FALSE)) { burn (&tmpCI, sizeof (tmpCI)); VirtualUnlock (&tmpCI, sizeof (tmpCI)); goto fail; } // Temporary secondary key (XTS mode) if (!RandgetBytes (hwndDlg, cryptoInfo->k2, sizeof cryptoInfo->k2, FALSE)) { burn (&tmpCI, sizeof (tmpCI)); VirtualUnlock (&tmpCI, sizeof (tmpCI)); goto fail; } retVal = EAInit (cryptoInfo->ea, temporaryKey, cryptoInfo->ks); if (retVal != ERR_SUCCESS) { TCfree (write_buf); burn (temporaryKey, sizeof(temporaryKey)); burn (&tmpCI, sizeof (tmpCI)); VirtualUnlock (&tmpCI, sizeof (tmpCI)); return retVal; } if (!EAInitMode (cryptoInfo, cryptoInfo->k2)) { TCfree (write_buf); burn (temporaryKey, sizeof(temporaryKey)); burn (&tmpCI, sizeof (tmpCI)); VirtualUnlock (&tmpCI, sizeof (tmpCI)); return ERR_MODE_INIT_FAILED; } #ifdef _WIN64 if (IsRamEncryptionEnabled ()) VcProtectKeys (cryptoInfo, VcGetEncryptionID (cryptoInfo)); #endif x = ft->num_sectors - ft->reserved - ft->size_root_dir / ft->sector_size - ft->fat_length * 2; while (x--) { if (WriteSector (dev, sector, write_buf, &write_buf_cnt, &nSecNo, startSector, cryptoInfo) == FALSE) goto fail; } UpdateProgressBar ((nSecNo - startSector) * ft->sector_size); if (!FlushFormatWriteBuffer (dev, write_buf, &write_buf_cnt, &nSecNo, cryptoInfo)) { burn (&tmpCI, sizeof (tmpCI)); VirtualUnlock (&tmpCI, sizeof (tmpCI)); goto fail; } burn (&tmpCI, sizeof (tmpCI)); VirtualUnlock (&tmpCI, sizeof (tmpCI)); } else if (!bDevice) { if (!FlushFormatWriteBuffer (dev, write_buf, &write_buf_cnt, &nSecNo, cryptoInfo)) goto fail; // Quick format: write a zeroed sector every 128 MiB, leaving other sectors untouched // This helps users visualize the progress of actual file creation while forcing Windows // to allocate the disk space of each 128 MiB chunk immediately, otherwise, Windows // would delay the allocation until we write the backup header at the end of the volume which // would make the user think that the format process has stalled after progress bar reaches 100%. num_sectors = ft->num_sectors - ft->reserved - ft->size_root_dir / ft->sector_size - ft->fat_length * 2; while (num_sectors >= nSkipSectors) { // seek to next sector to be written nSecNo += (nSkipSectors - 1); startOffset.QuadPart = nSecNo * ft->sector_size; if (!MoveFilePointer ((HANDLE) dev, startOffset)) { goto fail; } // sector array has been zeroed above if (!WriteFile ((HANDLE) dev, sector, ft->sector_size, &bytesWritten, NULL) || bytesWritten != ft->sector_size) { goto fail; } nSecNo++; num_sectors -= nSkipSectors; if (UpdateProgressBar ((nSecNo - startSector)* ft->sector_size)) goto fail; } nSecNo += num_sectors; UpdateProgressBar ((nSecNo - startSector)* ft->sector_size); } else { UpdateProgressBar ((uint64) ft->num_sectors * ft->sector_size); if (!FlushFormatWriteBuffer (dev, write_buf, &write_buf_cnt, &nSecNo, cryptoInfo)) goto fail; } TCfree (write_buf); burn (temporaryKey, sizeof(temporaryKey)); return 0; fail: TCfree (write_buf); burn (temporaryKey, sizeof(temporaryKey)); return ERR_OS_ERROR; }