![]() | ![]() |
|
Cryptoloop HOWTORalf Hölzer2004-01-15
1. About this documentThis HOWTO describes how to use the Cryptoloop loop device encryption in the 2.6 Linux kernel series. Cryptoloop makes it possible to create encrypted file systems within a partition or another file in the file system. These encrypted files can the be moved to a CD, DVD, USB memory stick, etc. Cryptoloop makes use of the loop device. This device is a pseudo-device which serves as a "loop" through which each call to a the file system has to pass. This way, data can be processed in order to encrypt and decrypt it. Since kernel 2.6, the Crypto API has been integrated into the main kernel, and setting up an encrypted file system has become much easier. No additional kernel patches are required. An update of some userspace utilities is necessary. Unfortunately, the use of Cryptoloop is not very well-documented so far. This HOWTO is an attempt to make it easy everyone to create an encrypted file system using the standard Cryptoloop functionality. Cryptoloop is based on the Crypto API in the 2.6 Linux kernel. It should not be confused with Loop-AES, which is a completely separate project. Cryptoloop is similar to the Crypto API that was available as a separate patch for the 2.4 kernel series. The new version is not compatible with the older one. 1.1. Copyright and LicenseThis document, Cryptoloop HOWTO, is copyrighted © 2004 by Ralf Hölzer. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is available at http://www.gnu.org/copyleft/fdl.html. Linux is a registered trademark of Linus Torvalds. 1.2. DisclaimerNo liability for the contents of this document can be accepted. Use the concepts, examples and information at your own risk. There may be errors and inaccuracies, that could be damaging to your system. Proceed with caution, and although this is highly unlikely, the author(s) do not take any responsibility. All copyrights are held by their by their respective owners, unless specifically noted otherwise. Use of a term in this document should not be regarded as affecting the validity of any trademark or service mark. Naming of particular products or brands should not be seen as endorsements. 1.3. Credits / ContributorsI'd like to thank the following people who helped me improve this HOWTO:
1.4. FeedbackFeedback is most certainly welcome for this document. Send your additions, comments and criticisms to the following email address : <cryptoloop@ralfhoelzer.com>. 2. IntroductionThere are currently a few alternatives to using Cryptoloop. Loop-AES (http://loop-aes.sourceforge.net) is probably the most well-known. It provides very similar functionality to Cryptoloop. Aes-loop is currently more mature than Cryptoloop and it is also faster (about twice as fast, according to the author of loop-AES), because it uses a highly optimized assembler implementation for AES. This doesn't mean that Cryptoloop is slow. I have not noticed any significant speed differences between a Cryptoloop-encrypted partition and a non-encrypted partition during everyday work with normal amounts of I/O. Unless I/O performance is extremely important to you, Cryptoloop should do just fine. Loop-AES offers some additional features that are not yet present in the kernel implementation of Cryptoloop. Loop-AES requires modified userspace tools (mount, losetup) and these modifications are incompatible with Cryptoloop. You will not be able to use Cryptoloop and Loop-AES at the same time. In terms of security, Cryptoloop is doing ok. The key is usually generated from a password and its hash is used as the key to AES. This leads to the possibility of a known-plaintext attack. Loop-AES is superior in this regard, because it generates a random key and encrypts this key separately, making a known-plaintext attack more difficult. Loop-AES also supports a multi-key mode, where sectors are encrypted with 64 separate AES keys. In general, a brute-force attack on your password can be very effective, if you choose a weak password. To be on the safe side, your password should be at least 20 characters long. Otherwise a brute-force attack on the password will be much easier than trying to brute-force the AES encryption directly. The Cryptoloop functionality in the standard kernel provides a stable and clean implementation without the need for extra patches. Since it is still fairly new, it may not have gotten the necessary amount of review in terms of security. You have to decide for yourself what is suitable for you. IMPORTANT: Cryptoloop has been marked deprecated in the latest 2.6 kernel. This means that it will no longer be maintained actively. The successor to Cryptoloop will be dm-crypt. Dm-crypt is available in the main kernel since 2.6.4. Cryptoloop will still be available in the main kernel for a long time, but dm-crypt will be the method of choice for disk encryption in the future. Dm-crypt is based on the device mapper and offers pretty much the same functionality as Cryptoloop. It is still very new and there are no easy-to-use userspace tools available yet. Dm-crypt is considered to be much cleaner code than Cryptoloop, but there are some important differences. For example, creating an ecrypted filesystem within a file will still require to go through a loop device, but this support is still in development. There are other tools which allow you to create an encrypted file system. BestCrypt is a commercial product from Jetico. It allows you to create encrypted containers and has a large choice of ciphers. It also offers some nifty features such as hidden containers. It is available for Windows and Linux, which makes it suitable for interchanging encrypted containers between Windows and Linux. BestCrypt now compiles on 2.6 kernels as well. Cryptoloop can also create containers that can be moved around, by creating the encrypted file system within a file as described below. I don't know of a way to access the Cryptoloop-encrypted files from other operating systems such as Windows. In this case, BestCrypt may be your only choice. There are other commercial disk encryption tools such as PGP disk, but to my knowledge there is no Linux support for them. 3. Configuring the kernelIn order to use Cryptoloop, you need to activate a few kernel options. You have the option to either compile these requirements as modules or compile them directly into the kernel. The following steps enable them as modules. If you are not familiar with building a 2.6 kernel, you should refer to the Linux Kernel HOWTO. The following instructions just give the minimal steps.
4. Getting the user space toolsThe Cryptoloop driver requires updated userspace tools to actually create and mount the encrypted file system. An updated util-linux package is needed and can be obtained from http://ftp.cwi.nl/aeb/util-linux/util-linux-2.12.tar.gz. The most current version is 2.12. There will be new versions out soon that will probably introduce major changes, so make sure you check this HOWTO for updates before upgrading to a newer version. Unfortunately there are many patches for util-linux out there. There are differences in the way how encrypted partitions are created and mounted. In order to use util-linux 2.12 with a 2.6 kernel at least the following two patches need to be applied: Download the util-linux package and the two patches above. First extract the util-linux package and then apply the two patches:
After applying the patches, compile and install util-linux according to the instructions in the INSTALL file. I recommend to use Gentoo Linux, which automatically applies these patches when emerging the util-linux patches. Other distributions may have versions of util-linux available, that have these patches aleady applied as well. 5. Setting up the loop deviceCryptoloop can be used either on a file or an entire file system. The following describes how to set it up on a particular partition. This partition can be any partition you like; the following example uses /dev/sda1. I have chosen to use AES as a cipher, but you can substitute any cipher you like that has been enabled in the kernel. You can get a list of the algorithms supported by your currently running kernel by looking into /proc/crypto. An excellent resource, discussing the different cryptographic algorithms, are Bruce Schneier's books, Applied Cryptography and Practical Cryptography. Both AES and Serpent are probably a reasonable choice. AES has been cryptanalyzed a lot and no serious weaknesses have been discovered so far. Serpent has not been analyzed as much, but is considered to be even a little bit stronger than AES. However, Serpent is also slower than AES. Stay away from DES, it is both slow and weak. Triple-DES may be an option, but AES is probably more secure and faster, so there is really no reason to use Triple-DES anymore.
6. Mounting the encrypted file systemFor all operations on the Cryptoloop device, it is important that the necessary modules are loaded. You need to load at least the Cryptoloop module and the modules for each cipher with modprobe. If the features are compiled directly into the kernel, this is not necessary. In order to mount the encrypted file system created above, you can use the standard mount command from util-linux:
You will be prompted for the password and the file system will be mounted just as any other. Since the encryption option implies that this is a Cryptoloop filesystem, it will automatically pick an available loopback device. When you are done, unmount it with:
You can add the following line to /etc/fstab:
Now you can simply mount the device with:
That's it. Have fun. 7. Using a file instead of a partitionIt is just as easy to create an encrypted file system within a file on another file system. This is especially useful if you want to back up this file by burning it to a DVD, etc. You can then easily move the file around to other machines as well. To initially create a 100MB file containing random data use the following command:
If you want to change the size of the file, change the count value accordingly. The above command creates 100000 blocks of 1k in size, but you can change this to whatever you like. Just make sure it is not too small to hold the file system you chose. You can choose any file name and path you want instead of /mystuff.aes as long as there's enough space on the partition. You can then create the encrypted file system within this file, similar to the way it is done above:
Now you can create the file system:
and mount it:
Finally, unmount and detach the loop device:
You can then mount the file system later on as follows:
If you want to move the file or burn it to a CD or DVD, make sure you unmount it first. |