Principles and system development of truecrypt (1): Create an encrypted volume using truecrypt format

Source: Internet
Author: User
Tags pkcs5

 

 

I. Overview
Truecrypt is the only virtual encrypted disk software that supports Windows Vista/XP/2000/Linux open source. It can create and set encrypted virtual disk images, and the virtual disk can be accessed as normal as other disks, all internal files are automatically encrypted and accessed using passwords. encryption and decryption are both real-time.
Truecrypt consists of two parts: truecrypt format, which is used to create an encrypted volume and truecrypt mount, which is used to load and detach a virtual disk to a partition.

Part 1: Create an encrypted volume using truecrypt format
The wizard for creating an encrypted volume according to the truecrypt format shows the location, algorithm, size, password, and format of the encrypted volume, then the encrypted volume is created. The created encrypted volume is the file at which the encrypted volume is located.

Therefore, we know that the core of truecrypt is to create an encrypted volume function. This function is used to accept the preceding parameters such as the location of the encrypted volume to complete the creation process, the prototype in truecrypt is

 

Int formatvolume (char * volumepath, <br/> bool bdevice, <br/> unsigned _ int64 size, <br/> unsigned _ int64 hiddenvolhostsize, <br/> password * password, <br/> int cipher, <br/> int pkcs5, <br/> bool quickformat, <br/> bool sparsefileswitch, <br/> int filesystem, <br/> int clustersize, <br/> hwnd hwnddlg, <br/> bool hiddenvol, <br/> int * realclustersize, <br/> bool UAC ); 

Next, let's take a look at the specific meaning of each parameter.

 

Parameters Type Description Example
Volumepath Char * Encrypted volume file selected C: // 1.txt
Bdevice Bool Whether it is a partition volume False
Size Unsigned _ int64 Size of the encrypted volume (in bytes) 10*1024*1024
Hiddenvolhostsize Unsigned _ int64 Hide the size of the encrypted volume (in bytes) 0
Password Password Password entered by the user 123456
Cipher Int Default encryption algorithm 1
Pkcs5 Int Hash Algorithm Default_hash_algorithm
Quickformat Bool Is it quick format? False
Sparsefileswitch Bool True
Filesystem Int File System Filesys_fat
Clustersize Int 0
Hwnddlg Hwnd Input window handle Null
Hiddenvol Bool Whether the volume is hidden False
Realclustersize Int 512
UAC Bool False

 

Next let's look at the specific example

 

Int format (char * szfile, unsigned _ int64 nsize, char * szpassword, hwnd hwnddlg) <br/>{< br/> char szfilename [tc_max_path + 1]; /* the file selected by the user */<br/> char szdiskfile [tc_max_path + 1]; /* fully qualified name derived from szfilename */<br/> bool bdevice = false;/* Is this a partition volume? */<Br/> unsigned _ int64 nvolumesize = 0;/* The volume size, in bytes. */<br/> unsigned _ int64 nhiddenvolhostsize = 0;/* size of the hidden volume host, in bytes */<br/> password volumepassword; /* users password */<br/> int nvolumeea = 1;/* default encryption algorithm */<br/> int hash_algo = default_hash_algorithm; /* which PRF to use in Header key derivation (PKCS #5) and in the RNG. */<br/> volatile bool bsparsefileswitch = false; <br/> volatile bool quickformat = false;/* warning: meaning of this variable depends on bsparsefileswitch. */<br/>/* If bsparsefileswitch is true, this variable represents the sparse file flag. */<br/> volatile int filesystem = 0; <br/> volatile int clustersize = 0; <br/> bool bhidden; <br/> int realclustersize; /* parameter used when determining the maximum possible size of a hidden volume. */<br/> int nstatus; <br/> char sztmp [16]; <br/> int nmultiplier = 1024*1024;/* Size Selection multiplier. */<br/> // strcpy (szdiskfile, "C: // 1.txt"); <br/> // szdiskfile [8] = 0; <br/> strcpy (szdiskfile, szfile); <br/> szdiskfile [strlen (szfile)] = 0; <br/> strcpy (sztmp, "10 "); <br/> // nvolumesize = _ atoi64 (sztmp); <br/> nvolumesize = nsize; <br/> nvolumesize = nvolumesize * nmultiplier; <br/> nhiddenvolhostsize = 0; <br/> // strcpy (volumepassword. text, "123456"); <br/> strcpy (volumepassword. text, szpassword); <br/> volumepassword. length = strlen (volumepassword. text); <br/> quickformat = false; <br/> bsparsefileswitch = true; <br/> filesystem = filesys_fat; <br/> clustersize = 0; <br/> bhidden = false; <br/> realclustersize = 512; </P> <p> nstatus = formatvolume (szdiskfile, // <br/> bdevice, // <br/> nvolumesize, // 1024*1024*10 <br/> nhiddenvolhostsize, // 0 <br/> & volumepassword, // <br/> nvolumeea, // <br/> hash_algo, // <br/> quickformat, // false <br/> bsparsefileswitch, // true <br/> filesystem, // 1 <br/> clustersize, // 0 <br/> hwnddlg, // <br/> bhidden, // false <br/> & realclustersize, /// 512 <br/> false); <br/> return 1; <br/>} 

 

After setting a series of parameters, you can complete the setting of the encrypted volume. Now you can create an encrypted volume. You can use the preceding method to create the encrypted volume. Truecrypt has no limit on the size of the encrypted volume file. The size of the virtual disk is limited only by the file system of the disk where the encrypted volume is located. For example, the encrypted volume file that can be created in a disk that is FAT32 formatted cannot exceed 4 GB.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.