📄 cryptoloop.txt
字号:
cryptoloop - a generic cryptographic loop device filter=======================================================To enable cryptoloop, you must fetch the cryptoloop-version.tar.gz source fromyour kernel.org mirror or directly from the non-US <http://www.kerneli.org>.Quickstart~~~~~~~~~~(if you have old encrypted volumes, please read the section aboutconversion below)you need a kernel compiled with *) loop device driver *) cryptographic support *) generic crypto loop filter *) one or more ciphers you want to use for encryption either as module or statically (if you build them as module, don't forget to insmod them!)Download the cryptoloop latest version tarball from the Internet and enterthe untarred directory. The following commands will patch your kernel andcopy the cryptoloop source in. $ make patch-kernel KDIR=/your/kernel/source LOOP=[iv or jari]Which will patch your kernel, and enable you to select cryptoloop in theCryptography section of the kernel configuration. Note, you have to manuallyenable both CryptoAPI and cryptoloop in your kernel configuration.If you would rather build modules you can use the following commands. $ make modules KDIR=/your/kernel/source CDIR=/cryptoapi/source \ LOOP=[iv or jari] $ make modules_install KDIR=/your/kernel/sourceYou also need a util-linux patched package (see<http://www.kernel.org/pub/linux/kernel/people/hvr/> for some recentpatches)Read on at <http://encryptionhowto.sourceforge.net/>How Loopback Encryption Works~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is a small overview of how the loopback filesystem encryption works.For all the of the data to be encrypted on a drive we need to interrupt thedisk write/read *after* the filesystem meta data is attached. Instead of hi-jacking the system call we pipe the the filesystem commands through a loopbackdevice. One advantage of this is that you can either encrypt a device(hard drive) ora file already on a drive and mount it as a file system. This allows you tohave encrypted folders on an unencrypted drive, useful if you don't want toencrypt everything. The loopback device fits in like this: device-->loop-->mountpoint The loop stage is actually divided into a couple stages, which is why thecryptoloop module is included. It splits the input and output from theloopback into pieces for the ciphers. Since they operate on a specific blocksize(i.e. 64-bits, 128-bits) the data must be chopped up for them. device-->cryptoloop-->loop-->mountpoint The cryptoloop module is also where the actual encryption and decryption ofthe data takes place.Some words about IV Calculation~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~There are some problems with the IV calculation up to recent 2.4.xlinux kernels. It's been calculated more or less by IV = rel_sector / (blocksize >> 9) + (lo_offset / blocksize)The first problem which arises, is that data transfers are not alwaysguaranteed to have a size of an integral multiple of the blocksize;This is a problem, because of CBC mode's property of needing thecomplete ciphertext block, i.e. you can't cipher or decipher only the2nd half of a block if you don't know the first half of it!Another problem which may be experienced is, when the soft blocksizechanges, i.e. due to different medias, as CDROM block devices andalike, or when the filesystem layer sets the blocksize to some othersize.But there's hope, as all transfer sizes are usually (except for thelast block on file backed loop devices sometimes...) an integralmultiple of 512 byte units (which is linux' atomic sector size);So the solution is to stick to a portable, uniform 512 byte based IVmetric! Alas this can't be accomplished without modifying the loopdriver, as the more granular IV metric can't be calculated from thecurrent dynamic IV metric.This change also renders most previously used encrypted volumesunreadable, which need to be converted to the new IV metric.Converting from Older IV Metrics~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~The recommended procedure is as follow, in case you don't want tobackup your old data in a conventional manner, and then restore it toa freshly created encrypted volume with the new IV-metric.The more valuable your data is, the more important it is, that you trythe following procedure with some dummy data, before risking your realdata! Cause if something goes wrong you'll have to keep both pieces...1) decrypt from within your old kernel version 1.1) setup your encrypted loop device, and mount it (this is also important for making sure, the filesystem layer sets the soft block size accordingly!) 1.2) unmount the filesystem (but leave the loop device setted up) 1.3) dd if=/dev/loop0 of=/dev/<underlying blockdev/file> make sure the process does not get interrupted, otherwise you will have a hard time, reconstructing your data, since you are decrypting the data back to the same area where the ciphertext was.3) make sure the block/file contains the properly deciphered content!!2) boot the new kernel featuring the 512byte based IV follow the instructions for 'encrypting unencrypted volumes' belowEncrypting Unencrypted Volumes~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~just as simple as that (please test this before trying on important data) 1) set up a new encrypted loop device over the still unencrypted data 2) dd if=/dev/<underlying blockdev/file> of=/dev/loop0Migrating from loop-AES to CryptoAPI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If you want to move from using the loop-AES filesystem encryption toCryptoAPI it only requires a small tweak. After loading cryptoapi and loadingthe cipher-aes module use the following line when setting up your loopbackdevice: $ losetup -e aes -k 256 -P sha512 /dev/loop0 /dev/<your drive>Then proceed to mount your loop device as you normall would. Here is thetable for mapping loop-AES to cryptoapi losetup flags:loop-AES cryptoapi============================================================-e aes128 -H rmd160 -e aes -k 128-e aes128 -H sha256 -e aes -k 128 -P sha256-e aes128 -H sha384 -e aes -k 128 -P sha384-e aes128 -H sha512 -e aes -k 128 -P sha512-e aes256 -H rmd160 -e aes -k 256-e aes256 -H sha256 -e aes -k 256 -P sha256-e aes256 -H sha384 -e aes -k 256 -P sha384-e aes256 -H sha512 -e aes -k 256 -P sha512-e aes128 -e aes -k 128 -P sha256-e aes192 -e aes -k 192 -P sha384-e aes256 -e aes -k 256 -P sha512--$Id: cryptoloop.txt,v 1.3 2002/08/03 19:29:58 kyle Exp $
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -