Imported Upstream version 1.6.7
[platform/upstream/cryptsetup.git] / FAQ
1 Sections 
2
3 1. General Questions
4 2. Setup
5 3. Common Problems
6 4. Troubleshooting
7 5. Security Aspects
8 6. Backup and Data Recovery
9 7. Interoperability with other Disk Encryption Tools
10 8. Issues with Specific Versions of cryptsetup
11 9. References and Further Reading
12 A. Contributors
13
14
15 1. General Questions 
16
17
18  * 1.1 What is this?
19
20   This is the FAQ (Frequently Asked Questions) for cryptsetup. It
21   covers Linux disk encryption with plain dm-crypt (one passphrase,
22   no management, no metadata on disk) and LUKS (multiple user keys
23   with one master key, anti-forensic features, metadata block at
24   start of device, ...). The latest version of this FAQ should
25   usually be available at
26   https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions
27
28
29  * 1.2 WARNINGS
30
31   ATTENTION: If you are going to read just one thing, make it the
32   section on Backup and Data Recovery. By far the most questions on
33   the cryptsetup mailing list are from people that managed to damage
34   the start of their LUKS partitions, i.e. the LUKS header. In
35   most cases, there is nothing that can be done to help these poor
36   souls recover their data. Make sure you understand the problem and
37   limitations imposed by the LUKS security model BEFORE you face
38   such a disaster! In particular, make sure you have a current header
39   backup before doing any potentially dangerous operations.
40
41   SSDs/FLASH DRIVES: SSDs and Flash are different. Currently it is
42   unclear how to get LUKS or plain dm-crypt to run on them with the
43   full set of security features intact. This may or may not be a
44   problem, depending on the attacker model. See Section 5.19.
45
46   BACKUP: Yes, encrypted disks die, just as normal ones do. A full
47   backup is mandatory, see Section "6. Backup and Data Recovery" on
48   options for doing encrypted backup.
49
50   CLONING/IMAGING: If you clone or image a LUKS container, you make a
51   copy of the LUKS header and the master key will stay the same!
52   That means that if you distribute an image to several machines, the
53   same master key will be used on all of them, regardless of whether
54   you change the passphrases. Do NOT do this! If you do, a root-user
55   on any of the machines with a mapped (decrypted) container or a
56   passphrase on that machine can decrypt all other copies, breaking
57   security. See also Item 6.15.
58
59   DISTRIBUTION INSTALLERS: Some distribution installers offer to
60   create LUKS containers in a way that can be mistaken as activation
61   of an existing container. Creating a new LUKS container on top of
62   an existing one leads to permanent, complete and irreversible data
63   loss. It is strongly recommended to only use distribution
64   installers after a complete backup of all LUKS containers has been
65   made.
66
67   UBUNTU INSTALLER: In particular the Ubuntu installer seems to be
68   quite willing to kill LUKS containers in several different ways.
69   Those responsible at Ubuntu seem not to care very much (it is very
70   easy to recognize a LUKS container), so treat the process of
71   installing Ubuntu as a severe hazard to any LUKS container you may
72   have.
73
74   NO WARNING ON NON-INTERACTIVE FORMAT: If you feed cryptsetup from
75   STDIN (e.g. via GnuPG) on LUKS format, it does not give you the
76   warning that you are about to format (and e.g. will lose any
77   pre-existing LUKS container on the target), as it assumes it is
78   used from a script. In this scenario, the responsibility for
79   warning the user and possibly checking for an existing LUKS header
80   is shifted to the script. This is a more general form of the
81   previous item.
82
83   LUKS PASSPHRASE IS NOT THE MASTER KEY: The LUKS passphrase is not
84   used in deriving the master key. It is used in decrypting a master
85   key that is randomly selected on header creation. This means that
86   if you create a new LUKS header on top of an old one with
87   exactly the same parameters and exactly the same passphrase as the
88   old one, it will still have a different master key and your data
89   will be permanently lost.
90
91   PASSPHRASE CHARACTER SET: Some people have had difficulties with
92   this when upgrading distributions. It is highly advisable to only
93   use the 95 printable characters from the first 128 characters of
94   the ASCII table, as they will always have the same binary
95   representation. Other characters may have different encoding
96   depending on system configuration and your passphrase will not
97   work with a different encoding. A table of the standardized first
98   128 ASCII characters can, e.g. be found on
99   http://en.wikipedia.org/wiki/ASCII
100
101
102  * 1.3 System specific warnings
103
104   - Ubuntu as of 4/2011: It seems the installer offers to create
105   LUKS partitions in a way that several people mistook for an offer
106   to activate their existing LUKS partition. The installer gives no
107   or an inadequate warning and will destroy your old LUKS header,
108   causing permanent data loss. See also the section on Backup and
109   Data Recovery.
110
111   This issue has been acknowledged by the Ubuntu dev team, see here:
112   http://launchpad.net/bugs/420080
113
114   Update 4/2013: I am still unsure whether this has been fixed by
115   now, best be careful. They also seem to have added even more LUKS
116   killer functionality to the Ubuntu installer. I can only strongly
117   recommended to not install Ubuntu on a system with existing LUKS
118   containers without complete backups.
119
120
121  * 1.4 My LUKS-device is broken! Help!
122
123   First: Do not panic! In many cases the data is still recoverable.
124   Do not do anything hasty! Steps:
125
126   - Take some deep breaths. Maybe add some relaxing music. This may
127   sound funny, but I am completely serious. Often, critical damage is
128   done only after the initial problem.
129
130   - Do not reboot. The keys mays still be in the kernel if the device
131   is mapped.
132
133   - Make sure others do not reboot the system.
134
135   - Do not write to your disk without a clear understanding why this
136   will not make matters worse. Do a sector-level backup before any
137   writes. Often you do not need to write at all to get enough access
138   to make a backup of the data.
139
140   - Relax some more.
141
142   - Read section 6 of this FAQ.
143
144   - Ask on the mailing-list if you need more help.
145
146
147  * 1.5 Who wrote this?
148
149   Current FAQ maintainer is Arno Wagner <arno@wagner.name>. If you
150   want to send me encrypted email, my current PGP key is DSA key
151   CB5D9718, fingerprint 12D6 C03B 1B30 33BB 13CF B774 E35C 5FA1 CB5D
152   9718.
153
154   Other contributors are listed at the end. If you want to contribute,
155   send your article, including a descriptive headline, to the
156   maintainer, or the dm-crypt mailing list with something like "FAQ
157   ..." in the subject. You can also send more raw information and
158   have me write the section. Please note that by contributing to this
159   FAQ, you accept the license described below.
160
161   This work is under the "Attribution-Share Alike 3.0 Unported"
162   license, which means distribution is unlimited, you may create
163   derived works, but attributions to original authors and this
164   license statement must be retained and the derived work must be
165   under the same license. See
166   http://creativecommons.org/licenses/by-sa/3.0/ for more details of
167   the license.
168
169   Side note: I did text license research some time ago and I think
170   this license is best suited for the purpose at hand and creates the
171   least problems.
172
173
174  * 1.6 Where is the project website?
175
176   There is the project website at https://gitlab.com/cryptsetup/cryptsetup/
177   Please do not post questions there, nobody will read them. Use
178   the mailing-list instead.
179
180
181  * 1.7 Is there a mailing-list?
182
183   Instructions on how to subscribe to the mailing-list are at on the
184   project website. People are generally helpful and friendly on the
185   list.
186
187   The question of how to unsubscribe from the list does crop up
188   sometimes. For this you need your list management URL, which is
189   sent to you initially and once at the start of each month. Go to
190   the URL mentioned in the email and select "unsubscribe". This page
191   also allows you to request a password reminder.
192
193   Alternatively, you can send an Email to dm-crypt-request@saout.de
194   with just the word "help" in the subject or message body. Make sure
195   to send it from your list address.
196
197   The mailing list archive is here:
198   http://dir.gmane.org/gmane.linux.kernel.device-mapper.dm-crypt
199
200
201  * 1.8 Unsubscribe from the mailing-list
202
203   Send mail to dm-crypt-unsubscribe@saout.de from the subscribed
204   account. You will get an email with instructions.
205
206   Basically, you just have to respond to it unmodified to get
207   unsubscribed. The listserver admin functions are not very fast. It
208   can take 15 minutes or longer for a reply to arrive (I suspect
209   greylisting is in use), so be patient.
210
211   Also note that nobody on the list can unsubscribe you, sending
212   demands to be unsubscribed to the list just annoys people that are
213   entirely blameless for you being subscribed.
214
215   If you are subscribed, a subscription confirmation email was sent
216   to your email account and it had to be answered before the
217   subscription went active. The confirmation emails from the
218   listserver have subjects like these (with other numbers):
219
220   Subject: confirm 9964cf10.....
221   
222   and are sent from dm-crypt-request@saout.de. You should check
223   whether you have anything like it in your sent email folder. If
224   you find nothing and are sure you did not confirm, then you should
225   look into a possible compromise of your email account.
226
227
228 2. Setup 
229
230
231  * 2.1 LUKS Container Setup mini-HOWTO
232
233   This item tries to give you a very brief list of all the steps you
234   should go though when creating a new LUKS encrypted container, i.e.
235   encrypted disk, partition or loop-file.
236
237   01) All data will be lost, if there is data on the target, make a 
238   backup.
239
240   02) Make very sure you have the right target disk, partition or
241   loop-file.
242
243   03) If the target was in use previously, it is a good idea to
244   wipe it before creating the LUKS container in order to remove any
245   trace of old file systems and data. For example, some users have
246   managed to run e2fsck on a partition containing a LUKS container,
247   possibly because of residual ext2 superblocks from an earlier use.
248   This can do arbitrary damage up to complete and permanent loss of
249   all data in the LUKS container.
250
251   To just quickly wipe file systems (old data may remain), use
252
253      wipefs -a <target device>
254  
255   To wipe file system and data, use something like
256
257      cat /dev/zero > <target device>
258  
259   This can take a while. To get a progress indicator, you can use
260   the tool dd_rescue (->google) instead or use my stream meter "wcs"
261   (source here: http://www.tansi.org/tools/index.html) in the
262   following fashion:
263
264      cat /dev/zero | wcs > <target device>
265  
266   Be very sure you have the right target, all data will be lost!
267
268   Note that automatic wiping is on the TODO list for cryptsetup, so
269   at some time in the future this will become unnecessary.
270
271   Alternatively, plain cm-crypt can be used for a very fast wipe with
272   crypto-grade randomness, see Item 2.19
273
274   04) Create the LUKS container:
275      cryptsetup luksFormat <target device>
276  
277   Just follow the on-screen instructions.
278
279   Note: Passphrase iteration is determined by cryptsetup depending on
280   CPU power. On a slow device, this may be lower than you want. I
281   recently benchmarked this on a Raspberry Pi and it came out at
282   about 1/15 of the iteration count for a typical PC. If security is
283   paramount, you may want to increase the time spent in iteration, at
284   the cost of a slower unlock later. For the Raspberry Pi, using
285
286    cryptsetup luksFormat -i 15000 <target device>
287  
288   gives you an iteration count and security level equal to an average
289   PC for passphrase iteration and master-key iteration. If in doubt,
290   check the iteration counts with
291
292    cryptsetup luksDump <target device>
293  
294   and adjust the iteration count accordingly by creating the container
295   again with a different iteration time (the number after '-i' is the
296   iteration time in milicesonds) until your requirements are met.
297
298   05) Map the container. Here it will be mapped to /dev/mapper/c1:
299      cryptsetup luksOpen <target device> c1 
300  
301   06) (Optionally) wipe the container (make sure you have the right target!):
302      cat /dev/zero > /dev/mapper/c1
303       
304   Note that this creates a small information leak, as an attacker can
305   determine whether a 512 byte block is zero if the attacker has
306   access to the encrypted container multiple times. Typically a
307   competent attacker that has access multiple times can install a
308   passphrase sniffer anyways, so this leakage is not very
309   significant. For getting a progress indicator, see step 03.
310
311   Note that at some time in the future, cryptsetup will do this for
312   you, but currently it is a TODO list item.
313
314   07) Create a file system in the mapped container, for example an 
315   ext3 file system (any other file system is possible):
316
317      mke2fs -j /dev/mapper/c1
318  
319   08) Mount your encrypted file system, here on /mnt:
320      mount /dev/mapper/c1 /mnt 
321  
322   Done. You can now use the encrypted file system to store data. Be
323   sure to read though the rest of the FAQ, these are just the very
324   basics. In particular, there are a number of mistakes that are
325   easy to make, but will compromise your security.
326
327
328  * 2.2 LUKS on partitions or raw disks?
329
330   This is a complicated question, and made more so by the availability
331   of RAID and LVM. I will try to give some scenarios and discuss
332   advantages and disadvantages. Note that I say LUKS for simplicity,
333   but you can do all the things described with plain dm-crypt as well.
334   Also note that your specific scenario may be so special that most
335   or even all things I say below do not apply.
336
337   Be aware that if you add LVM into the mix, things can get very
338   complicated. Same with RAID but less so. In particular, data
339   recovery can get exceedingly difficult. Only do so if you have a
340   really good reason and always remember KISS is what separates an
341   engineer from an amateur. Of course, if you really need the added
342   complexity, KISS is satisfied. But be very sure as there is a price
343   to pay for it. In engineering, complexity is always the enemy and
344   needs to be fought without mercy when encountered.
345
346   Also consider using RAID instead of LVM, as at least with the old
347   superblock format 0.90, the RAID superblock is in the place (end
348   of disk) where the risk of it permanently damaging the LUKS header
349   is smallest and you can have your array assembled by the RAID
350   controller (i.e. the kernel), as it should be. Use partition type
351   0xfd for that. I recommend staying away from superblock formats
352   1.0, 1.1 and 1.2 unless you really need them. Be aware that you
353   lose autodetection with them and have to fall back to some
354   user-space script to do it.
355
356   Scenarios:
357
358   (1) Encrypted partition: Just make a partition to your liking,
359   and put LUKS on top of it and a filesystem into the LUKS container.
360   This gives you isolation of differently-tasked data areas, just as
361   ordinary partitioning does. You can have confidential data,
362   non-confidential data, data for some specific applications,
363   user-homes, root, etc. Advantages are simplicity as there is a 1:1
364   mapping between partitions and filesystems, clear security
365   functionality and the ability to separate data into different,
366   independent (!) containers.
367
368   Note that you cannot do this for encrypted root, that requires an
369   initrd. On the other hand, an initrd is about as vulnerable to a
370   competent attacker as a non-encrypted root, so there really is no
371   security advantage to doing it that way. An attacker that wants to
372   compromise your system will just compromise the initrd or the
373   kernel itself. The better way to deal with this is to make sure the
374   root partition does not store any critical data and move that to
375   additional encrypted partitions. If you really are concerned your
376   root partition may be sabotaged by somebody with physical access
377   (that would however strangely not, say, sabotage your BIOS,
378   keyboard, etc.), protect it in some other way. The PC is just not
379   set-up for a really secure boot-chain (whatever some people may
380   claim).
381
382   (2) Fully encrypted raw block device: For this, put LUKS on the
383   raw device (e.g. /dev/sdb) and put a filesystem into the LUKS
384   container, no partitioning whatsoever involved. This is very
385   suitable for things like external USB disks used for backups or
386   offline data-storage.
387
388   (3) Encrypted RAID: Create your RAID from partitions and/or full
389   devices. Put LUKS on top of the RAID device, just if it were an
390   ordinary block device. Applications are just the same as above, but
391   you get redundancy. (Side note as many people seem to be unaware of
392   it: You can do RAID1 with an arbitrary number of components in
393   Linux.) See also Item 2.8.
394
395   (4) Now, some people advocate doing the encryption below the RAID
396   layer. That has several serious problems. One is that suddenly
397   debugging RAID issues becomes much harder. You cannot do automatic
398   RAID assembly anymore. You need to keep the encryption keys for the
399   components in sync or manage them somehow. The only possible
400   advantage is that things may run a little faster as more CPUs do
401   the encryption, but if speed is a priority over security and
402   simplicity, you are doing this wrong anyways. A good way to
403   mitigate a speed issue is to get a CPU that does hardware AES.
404
405
406  * 2.3 How do I set up encrypted swap?
407
408   As things that are confidential can end up in swap (keys,
409   passphrases, etc. are usually protected against being swapped to
410   disk, but other things may not be), it may be advisable to do
411   something about the issue. One option is to run without swap, which
412   generally works well in a desktop-context. It may cause problems
413   in a server-setting or under special circumstances. The solution to
414   that is to encrypt swap with a random key at boot-time.
415
416   NOTE: This is for Debian, and should work for Debian-derived
417   distributions. For others you may have to write your own startup
418   script or use other mechanisms.
419
420   01) Add the swap partition to /etc/crypttab. A line like the following
421   should do it:
422
423       swap  /dev/<partition>  /dev/urandom   swap,noearly
424  
425   Warning: While Debian refuses to overwrite partitions with a
426   filesystem or RAID signature on it, if your disk IDs may change
427   (adding or removing disks, failure of disk during boot, etc.), you
428   may want to take additional precautions. Yes, this means that your
429   kernel device names like sda, sdb, ... can change between reboots!
430   This is not a concern if you have only one disk. One possibility is
431   to make sure the partition number is not present on additional
432   disks or also swap there. Another is to encapsulate the swap
433   partition (by making it a 1-disk RAID1 or by using LVM), so that it
434   gets a persistent identifier. Specifying it directly by UUID does
435   not work, unfortunately, as the UUID is part of the swap signature
436   and that is not visible from the outside due to the encryption and
437   in addition changes on each reboot with this setup.
438
439   Note: Use /dev/random if you are paranoid or in a potential
440   low-entropy situation (embedded system, etc.). This may cause the
441   operation to take a long time during boot. If you are in a "no
442   entropy" situation, you cannot encrypt swap securely. In this
443   situation you should find some entropy, also because nothing else
444   using crypto will be secure, like ssh, ssl or GnuPG.
445
446   Note: The "noearly" option makes sure things like LVM, RAID, etc.
447   are running. As swap is non-critical for boot, it is fine to start
448   it late.
449
450   02) Add the swap partition to /etc/fstab. A line like the following
451   should do it:
452
453       /dev/mapper/swap none swap sw 0 0
454  
455   That is it. Reboot or start it manually to activate encrypted swap.
456   Manual start would look like this:
457
458       /etc/init.d/crypdisks start
459       swapon /dev/mapper/swap
460  
461
462  * 2.4 What is the difference between "plain" and LUKS format?
463
464   First, unless you happen to understand the cryptographic background
465   well, you should use LUKS. It does protect the user from a lot of
466   common mistakes. Plain dm-crypt is for experts.
467
468   Plain format is just that: It has no metadata on disk, reads all
469   parameters from the commandline (or the defaults), derives a
470   master-key from the passphrase and then uses that to de-/encrypt
471   the sectors of the device, with a direct 1:1 mapping between
472   encrypted and decrypted sectors.
473
474   Primary advantage is high resilience to damage, as one damaged
475   encrypted sector results in exactly one damaged decrypted sector.
476   Also, it is not readily apparent that there even is encrypted data
477   on the device, as an overwrite with crypto-grade randomness (e.g.
478   from /dev/urandom) looks exactly the same on disk.
479
480   Side-note: That has limited value against the authorities. In
481   civilized countries, they cannot force you to give up a crypto-key
482   anyways. In quite a few countries around the world, they can force
483   you to give up the keys (using imprisonment or worse to pressure
484   you, sometimes without due process), and in the worst case, they
485   only need a nebulous "suspicion" about the presence of encrypted
486   data. Sometimes this applies to everybody, sometimes only when you
487   are suspected of having "illicit data" (definition subject to
488   change) and sometimes specifically when crossing a border. Note
489   that this is going on in countries like the US and the UK, to
490   different degrees and sometimes with courts restricting what the
491   authorities can actually demand.
492
493   My advice is to either be ready to give up the keys or to not have
494   encrypted data when traveling to those countries, especially when
495   crossing the borders. The latter also means not having any
496   high-entropy (random) data areas on your disk, unless you can
497   explain them and demonstrate that explanation. Hence doing a
498   zero-wipe of all free space, including unused space, may be a good
499   idea.
500
501   Disadvantages are that you do not have all the nice features that
502   the LUKS metadata offers, like multiple passphrases that can be
503   changed, the cipher being stored in the metadata, anti-forensic
504   properties like key-slot diffusion and salts, etc..
505
506   LUKS format uses a metadata header and 8 key-slot areas that are
507   being placed at the beginning of the disk, see below under "What
508   does the LUKS on-disk format looks like?". The passphrases are used
509   to decrypt a single master key that is stored in the anti-forensic
510   stripes.
511
512   Advantages are a higher usability, automatic configuration of
513   non-default crypto parameters, defenses against low-entropy
514   passphrases like salting and iterated PBKDF2 passphrase hashing,
515   the ability to change passphrases, and others.
516
517   Disadvantages are that it is readily obvious there is encrypted
518   data on disk (but see side note above) and that damage to the
519   header or key-slots usually results in permanent data-loss. See
520   below under "6. Backup and Data Recovery" on how to reduce that
521   risk. Also the sector numbers get shifted by the length of the
522   header and key-slots and there is a loss of that size in capacity
523   (1MB+4096B for defaults and 2MB for the most commonly used
524   non-default XTS mode).
525
526
527  * 2.5 Can I encrypt an already existing, non-empty partition to use
528    LUKS?
529
530   There is no converter, and it is not really needed. The way to do
531   this is to make a backup of the device in question, securely wipe
532   the device (as LUKS device initialization does not clear away old
533   data), do a luksFormat, optionally overwrite the encrypted device,
534   create a new filesystem and restore your backup on the now
535   encrypted device. Also refer to sections "Security Aspects" and
536   "Backup and Data Recovery".
537
538   For backup, plain GNU tar works well and backs up anything likely
539   to be in a filesystem.
540
541
542  * 2.6 How do I use LUKS with a loop-device?
543
544   This can be very handy for experiments. Setup is just the same as
545   with any block device. If you want, for example, to use a 100MiB
546   file as LUKS container, do something like this:
547
548       head -c 100M /dev/zero > luksfile  # create empty file
549       losetup /dev/loop0 luksfile        # map luksfile to /dev/loop0
550       cryptsetup luksFormat /dev/loop0   # create LUKS on loop device
551  
552   Afterwards just use /dev/loop0 as a you would use a LUKS partition.
553   To unmap the file when done, use "losetup -d /dev/loop0".
554
555
556  * 2.7 When I add a new key-slot to LUKS, it asks for a passphrase but
557    then complains about there not being a key-slot with that
558    passphrase?
559
560   That is as intended. You are asked a passphrase of an existing
561   key-slot first, before you can enter the passphrase for the new
562   key-slot. Otherwise you could break the encryption by just adding a
563   new key-slot. This way, you have to know the passphrase of one of
564   the already configured key-slots in order to be able to configure a
565   new key-slot.
566
567
568  * 2.8 Encryption on top of RAID or the other way round?
569
570   Unless you have special needs, place encryption between RAID and
571   filesystem, i.e. encryption on top of RAID. You can do it the other
572   way round, but you have to be aware that you then need to give the
573   passphrase for each individual disk and RAID autodetection will
574   not work anymore. Therefore it is better to encrypt the RAID
575   device, e.g. /dev/dm0 .
576
577   This means that the typical layering looks like this:
578
579   Filesystem     <- top
580   |
581   Encryption
582   |
583   RAID
584   |
585   Raw partitions
586   |
587   Raw disks      <- bottom
588  
589   The big advantage is that you can manage the RAID container just
590   like any RAID container, it does not care that what is in it is
591   encrypted.
592
593
594  * 2.9 How do I read a dm-crypt key from file?
595
596   Use the --key-file option, like this:
597
598       cryptsetup create --key-file keyfile e1 /dev/loop0
599  
600   This will read the binary key from file, i.e. no hashing or
601   transformation will be applied to the keyfile before its bits are
602   used as key. Extra bits (beyond the length of the key) at the end
603   are ignored. Note that if you read from STDIN, the data will still
604   be hashed, just as a key read interactively from the terminal. See
605   the man-page sections "NOTES ON PASSPHRASE PROCESSING..." for more
606   detail.
607
608
609  * 2.10 How do I read a LUKS slot key from file?
610
611   What you really do here is to read a passphrase from file, just as
612   you would with manual entry of a passphrase for a key-slot. You can
613   add a new passphrase to a free key-slot, set the passphrase of an
614   specific key-slot or put an already configured passphrase into a
615   file. In the last case make sure no trailing newline (0x0a) is
616   contained in the key file, or the passphrase will not work because
617   the whole file is used as input.
618
619   To add a new passphrase to a free key slot from file, use something
620   like this:
621
622       cryptsetup luksAddKey /dev/loop0 keyfile
623  
624   To add a new passphrase to a specific key-slot, use something like
625   this:
626
627       cryptsetup luksAddKey --key-slot 7 /dev/loop0 keyfile
628  
629   To supply a key from file to any LUKS command, use the --key-file
630   option, e.g. like this:
631
632       cryptsetup luksOpen --key-file keyfile /dev/loop0 e1
633  
634
635  * 2.11 How do I read the LUKS master key from file?
636
637   The question you should ask yourself first is why you would want to
638   do this. The only legitimate reason I can think of is if you want
639   to have two LUKS devices with the same master key. Even then, I
640   think it would be preferable to just use key-slots with the same
641   passphrase, or to use plain dm-crypt instead. If you really have a
642   good reason, please tell me. If I am convinced, I will add how to
643   do this here.
644
645
646  * 2.12 What are the security requirements for a key read from file?
647
648   A file-stored key or passphrase has the same security requirements
649   as one entered interactively, however you can use random bytes and
650   thereby use bytes you cannot type on the keyboard. You can use any
651   file you like as key file, for example a plain text file with a
652   human readable passphrase. To generate a file with random bytes,
653   use something like this:
654
655       head -c 256 /dev/random > keyfile
656  
657
658  * 2.13 If I map a journaled file system using dm-crypt/LUKS, does it
659    still provide its usual transactional guarantees?
660
661   Yes, it does, unless a very old kernel is used. The required flags
662   come from the filesystem layer and are processed and passed onwards
663   by dm-crypt. A bit more information on the process by which
664   transactional guarantees are implemented can be found here:
665
666   http://lwn.net/Articles/400541/
667
668   Please note that these "guarantees" are weaker than they appear to
669   be. One problem is that quite a few disks lie to the OS about
670   having flushed their buffers. Some other things can go wrong as
671   well. The filesystem developers are aware of these problems and
672   typically can make it work anyways. That said, dm-crypt/LUKS will
673   not make things worse.
674
675   One specific problem you can run into though is that you can get
676   short freezes and other slowdowns due to the encryption layer.
677   Encryption takes time and forced flushes will block for that time.
678   For example, I did run into frequent small freezes (1-2 sec) when
679   putting a vmware image on ext3 over dm-crypt. When I went back to
680   ext2, the problem went away. This seems to have gotten better with
681   kernel 2.6.36 and the reworking of filesystem flush locking
682   mechanism (less blocking of CPU activity during flushes). It
683   should improve further and eventually the problem should go away.
684
685
686  * 2.14 Can I use LUKS or cryptsetup with a more secure (external)
687    medium for key storage, e.g. TPM or a smartcard?
688
689   Yes, see the answers on using a file-supplied key. You do have to
690   write the glue-logic yourself though. Basically you can have
691   cryptsetup read the key from STDIN and write it there with your
692   own tool that in turn gets the key from the more secure key
693   storage.
694
695   For TPM support, you may want to have a look at tpm-luks at
696   https://github.com/shpedoikal/tpm-luks. Note that tpm-luks is not
697   related to the cryptsetup project.
698
699
700  * 2.15 Can I resize a dm-crypt or LUKS partition?
701
702   Yes, you can, as neither dm-crypt nor LUKS stores partition size.
703   Whether you should is a different question. Personally I recommend
704   backup, recreation of the encrypted partition with new size,
705   recreation of the filesystem and restore. This gets around the
706   tricky business of resizing the filesystem. Resizing a dm-crypt or
707   LUKS container does not resize the filesystem in it. The backup is
708   really non-optional here, as a lot can go wrong, resulting in
709   partial or complete data loss. Using something like gparted to
710   resize an encrypted partition is slow, but typically works. This
711   will not change the size of the filesystem hidden under the
712   encryption though.
713
714   You also need to be aware of size-based limitations. The one
715   currently relevant is that aes-xts-plain should not be used for
716   encrypted container sizes larger than 2TiB. Use aes-xts-plain64
717   for that.
718
719
720  * 2.16 How do I Benchmark the Ciphers, Hashes and Modes?
721
722   Since version 1.60 cryptsetup supports the "benchmark" command.
723   Simply run as root:
724
725    cryptsetup benchmark
726  
727   It will output first iterations/second for the key-derivation
728   function PBKDF2 parameterized with different hash-functions, and
729   then the raw encryption speed of ciphers with different modes and
730   key-sizes. You can get more than the default benchmarks, see the
731   man-page for the relevant parameters. Note that XTS mode takes two
732   keys, hence the listed key sizes are double that for other modes
733   and half of it is the cipher key, the other half is the XTS key.
734
735
736  * 2.17 How do I Verify I have an Authentic cryptsetup Source Package?
737
738   Current maintainer is Milan Broz and he signs the release packages
739   with his PGP key. The key he currently uses is the "RSA key ID
740   D93E98FC", fingerprint 2A29 1824 3FDE 4664 8D06 86F9 D9B0 577B
741   D93E 98FC. While I have every confidence this really is his key and
742   that he is who he claims to be, don't depend on it if your life is
743   at stake. For that matter, if your life is at stake, don't depend
744   on me being who I claim to be either.
745
746   That said, as cryptsetup is under good version control, a malicious
747   change should be noticed sooner or later, but it may take a while.
748   Also, the attacker model makes compromising the sources in a
749   non-obvious way pretty hard. Sure, you could put the master-key
750   somewhere on disk, but that is rather obvious as soon as somebody
751   looks as there would be data in an empty LUKS container in a place
752   it should not be. Doing this in a more nefarious way, for example
753   hiding the master-key in the salts, would need a look at the
754   sources to be discovered, but I think that somebody would find that
755   sooner or later as well.
756
757   That said, this discussion is really a lot more complicated and
758   longer as an FAQ can sustain. If in doubt, ask on the mailing list.
759
760
761  * 2.18 Is there a concern with 4k Sectors?
762
763   Not from dm-crypt itself. Encryption will be done in 512B blocks,
764   but if the partition and filesystem are aligned correctly and the
765   filesystem uses multiples of 4kiB as block size, the dm-crypt layer
766   will just process 8 x 512B = 4096B at a time with negligible
767   overhead. LUKS does place data at an offset, which is 2MiB per
768   default and will not break alignment. See also Item 6.12 of this
769   FAQ for more details. Note that if your partition or filesystem is
770   misaligned, dm-crypt can make the effect worse though.
771
772
773  * 2.19 How can I wipe a device with crypto-grade randomness?
774
775   The conventional recommendation if you want to not just do a
776   zero-wipe is to use something like
777
778   cat /dev/urandom >  <taget-device>
779  
780   That is very slow and painful at 10-20MB/s on a fast computer.
781   Using cryptsetup and a plain dm-crypt device with a random key, it
782   is much faster and gives you the same level of security. The
783   defaults are quite enough.
784
785   For device set-up, do the following:
786
787   cryptsetup open --type plain -d /dev/urandom /dev/<block-device>  to_be_wiped
788  
789   Then you have several options. Simple wipe without
790   progress-indicator:
791
792   cat /dev/zero > /dev/mapper/to_be_wiped
793  
794   Progress-indicator by dd_rescue:
795
796   dd_rescue -w /dev/zero /dev/mapper/to_be_wiped
797  
798   Progress-indicator by my "wcs" stream meter (available from
799   http://www.tansi.org/tools/index.html ):
800
801   cat /dev/zero | wcs > /dev/mapper/to_be_wiped
802  
803   Remove the mapping at the end and you are done.
804
805
806 3. Common Problems 
807
808
809  * 3.1 My dm-crypt/LUKS mapping does not work! What general steps are
810    there to investigate the problem?
811
812   If you get a specific error message, investigate what it claims
813   first. If not, you may want to check the following things.
814
815   - Check that "/dev", including "/dev/mapper/control" is there. If it
816   is missing, you may have a problem with the "/dev" tree itself or
817   you may have broken udev rules.
818
819   - Check that you have the device mapper and the crypt target in your
820   kernel. The output of "dmsetup targets" should list a "crypt"
821   target. If it is not there or the command fails, add device mapper
822   and crypt-target to the kernel.
823
824   - Check that the hash-functions and ciphers you want to use are in
825   the kernel. The output of "cat /proc/crypto" needs to list them.
826
827
828  * 3.2 My dm-crypt mapping suddenly stopped when upgrading cryptsetup.
829
830   The default cipher, hash or mode may have changed (the mode changed
831   from 1.0.x to 1.1.x). See under "Issues With Specific Versions of
832   cryptsetup".
833
834
835  * 3.3 When I call cryptsetup from cron/CGI, I get errors about
836    unknown features?
837
838   If you get errors about unknown parameters or the like that are not
839   present when cryptsetup is called from the shell, make sure you
840   have no older version of cryptsetup on your system that then gets
841   called by cron/CGI. For example some distributions install
842   cryptsetup into /usr/sbin, while a manual install could go to
843   /usr/local/sbin. As a debugging aid, call "cryptsetup --version"
844   from cron/CGI or the non-shell mechanism to be sure the right
845   version gets called.
846
847
848  * 3.4 Unlocking a LUKS device takes very long. Why?
849
850   The iteration time for a key-slot (see Section 5 for an explanation
851   what iteration does) is calculated when setting a passphrase. By
852   default it is 1 second on the machine where the passphrase is set.
853   If you set a passphrase on a fast machine and then unlock it on a
854   slow machine, the unlocking time can be much longer. Also take into
855   account that up to 8 key-slots have to be tried in order to find the
856   right one.
857
858   If this is problem, you can add another key-slot using the slow
859   machine with the same passphrase and then remove the old key-slot.
860   The new key-slot will have an iteration count adjusted to 1 second
861   on the slow machine. Use luksKeyAdd and then luksKillSlot or
862   luksRemoveKey.
863
864   However, this operation will not change volume key iteration count
865   (MK iterations in output of "cryptsetup luksDump"). In order to
866   change that, you will have to backup the data in the LUKS
867   container (i.e. your encrypted data), luksFormat on the slow
868   machine and restore the data. Note that in the original LUKS
869   specification this value was fixed to 10, but it is now derived
870   from the PBKDF2 benchmark as well and set to iterations in 0.125
871   sec or 1000, whichever is larger. Also note that MK iterations
872   are not very security relevant. But as each key-slot already takes
873   1 second, spending the additional 0.125 seconds really does not
874   matter.
875
876
877  * 3.5 "blkid" sees a LUKS UUID and an ext2/swap UUID on the same
878    device. What is wrong?
879
880   Some old versions of cryptsetup have a bug where the header does
881   not get completely wiped during LUKS format and an older ext2/swap
882   signature remains on the device. This confuses blkid.
883
884   Fix: Wipe the unused header areas by doing a backup and restore of
885   the header with cryptsetup 1.1.x:
886
887       cryptsetup luksHeaderBackup --header-backup-file <file> <device>
888       cryptsetup luksHeaderRestore --header-backup-file <file> <device>
889  
890
891  * 3.6 cryptsetup segfaults on Gentoo amd64 hardened ...
892
893   There seems to be some interference between the hardening and and
894   the way cryptsetup benchmarks PBKDF2. The solution to this is
895   currently not quite clear for an encrypted root filesystem.     For
896   other uses, you can apparently specify USE="dynamic" as compile
897   flag, see http://bugs.gentoo.org/show_bug.cgi?id=283470
898
899
900 4. Troubleshooting 
901
902
903  * 4.1 I get the error "LUKS keyslot x is invalid." What does that
904    mean?
905
906   This means that the given keyslot has an offset that points
907   outside the valid keyslot area. Typically, the reason is a
908   corrupted LUKS header because something was written to the start of
909   the device the LUKS container is on. Refer to Section "Backup and
910   Data Recovery" and ask on the mailing list if you have trouble
911   diagnosing and (if still possible) repairing this.
912
913
914  * 4.2 I cannot unlock my LUKS container! What could be the problem?
915
916   First, make sure you have a correct passphrase. Then make sure you
917   have the correct key-map and correct keyboard. And then make sure
918   you have the correct character set and encoding, see also
919   "PASSPHRASE CHARACTER SET" under Section 1.2.
920
921   If you are sure you are entering the passphrase right, there is the
922   possibility that the respective key-slot has been damaged. There
923   is no way to recover a damaged key-slot, except from a header
924   backup (see Section 6). For security reasons, there is also no
925   checksum in the key-slots that could tell you whether a key-slot has
926   been damaged. The only checksum present allows recognition of a
927   correct passphrase, but that only works if the passphrase is
928   correct and the respective key-slot is intact.
929
930   In order to find out whether a key-slot is damaged one has to look
931   for "non-random looking" data in it. There is a tool that
932   automatizes this in the cryptsetup distribution from version 1.6.0
933   onwards. It is located in misc/keyslot_checker/. Instructions how
934   to use and how to interpret results are in the README file. Note
935   that this tool requires a libcryptsetup from cryptsetup 1.6.0 or
936   later (which means libcryptsetup.so.4.5.0 or later). If the tool
937   complains about missing functions in libcryptsetup, you likely
938   have an earlier version from your distribution still installed. You
939   can either point the symbolic link(s) from libcryptsetup.so.4 to
940   the new version manually, or you can uninstall the distribution
941   version of cryptsetup and re-install that from cryptsetup >= 1.6.0
942   again to fix this.
943
944
945  * 4.3 Can a bad RAM module cause problems?
946
947   LUKS and dm-crypt can give the RAM quite a workout, especially when
948   combined with software RAID. In particular the combination RAID5 +
949   LUKS + XFS seems to uncover RAM problems that never caused obvious
950   problems before. Symptoms vary, but often the problem manifest
951   itself when copying large amounts of data, typically several times
952   larger than your main memory.
953
954   Side note: One thing you should always do on large data
955   copy/movements is to run a verify, for example with the "-d"
956   option of "tar" or by doing a set of MD5 checksums on the source
957   or target with
958
959       find . -type f -exec md5sum \{\} \; > checksum-file
960  
961   and then a "md5sum -c checksum-file" on the other side. If you get
962   mismatches here, RAM is the primary suspect. A lesser suspect is
963   an overclocked CPU. I have found countless hardware problems in
964   verify runs after copying or making backups. Bit errors are much
965   more common than most people think.
966
967   Some RAM issues are even worse and corrupt structures in one of the
968   layers. This typically results in lockups, CPU state dumps in the
969   system logs, kernel panic or other things. It is quite possible to
970   have the problem with an encrypted device, but not with an
971   otherwise the same unencrypted device. The reason for that is that
972   encryption has an error amplification property: You flip one bit
973   in an encrypted data block, and the decrypted version has half of
974   its bits flipped. This is an important security property for modern
975   ciphers. With the usual modes in cryptsetup (CBC, ESSIV, XTS), you
976   get up to a completely changed 512 byte block per bit error. A
977   corrupt block causes a lot more havoc than the occasionally
978   flipped single bit and can result in various obscure errors.
979
980   Note, that a verify run on copying between encrypted or
981   unencrypted devices will reliably detect corruption, even when the
982   copying itself did not report any problems. If you find defect
983   RAM, assume all backups and copied data to be suspect, unless you
984   did a verify.
985
986
987  * 4.4 How do I test RAM?
988
989   First you should know that overclocking often makes memory
990   problems worse. So if you overclock (which I strongly recommend
991   against in a system holding data that has some worth), run the
992   tests with the overclocking active.
993
994   There are two good options. One is Memtest86+ and the other is
995   "memtester" by Charles Cazabon. Memtest86+ requires a reboot and
996   then takes over the machine, while memtester runs from a
997   root-shell. Both use different testing methods and I have found
998   problems fast with each one that the other needed long to find. I
999   recommend running the following procedure until the first error is
1000   found:
1001
1002   - Run Memtest86+ for one cycle
1003
1004   - Run memtester for one cycle (shut down as many other applications
1005   as possible)
1006
1007   - Run Memtest86+ for 24h or more
1008
1009   - Run memtester for 24h or more
1010
1011   If all that does not produce error messages, your RAM may be sound,
1012   but I have had one weak bit that Memtest86+ needed around 60 hours
1013   to find. If you can reproduce the original problem reliably, a good
1014   additional test may be to remove half of the RAM (if you have more
1015   than one module) and try whether the problem is still there and if
1016   so, try with the other half. If you just have one module, get a
1017   different one and try with that. If you do overclocking, reduce
1018   the settings to the most conservative ones available and try with
1019   that.
1020
1021
1022 5. Security Aspects 
1023
1024
1025  * 5.1 How long is a secure passphrase ?
1026
1027   This is just the short answer. For more info and explanation of
1028   some of the terms used in this item, read the rest of Section 5.
1029   The actual recommendation is at the end of this item.
1030
1031   First, passphrase length is not really the right measure,
1032   passphrase entropy is. For example, a random lowercase letter (a-z)
1033   gives you 4.7 bit of entropy, one element of a-z0-9 gives you 5.2
1034   bits of entropy, an element of a-zA-Z0-9 gives you 5.9 bits and
1035   a-zA-Z0-9!@#$%^&:-+ gives you 6.2 bits. On the other hand, a random
1036   English word only gives you 0.6...1.3 bits of entropy per
1037   character. Using sentences that make sense gives lower entropy,
1038   series of random words gives higher entropy. Do not use sentences
1039   that can be tied to you or found on your computer. This type of
1040   attack is done routinely today.
1041
1042   That said, it does not matter too much what scheme you use, but it
1043   does matter how much entropy your passphrase contains, because an
1044   attacker has to try on average
1045
1046       1/2 * 2^(bits of entropy in passphrase)    
1047  
1048   different passphrases to guess correctly.
1049
1050   Historically, estimations tended to use computing time estimates,
1051   but more modern approaches try to estimate cost of guessing a
1052   passphrase.
1053
1054   As an example, I will try to get an estimate from the numbers in
1055   http://it.slashdot.org/story/12/12/05/0623215/new-25-gpu-monster-devours-strong-passwords-in-minutes
1056   More references can be found a the end of this document. Note that
1057   these are estimates from the defender side, so assuming something
1058   is easier than it actually is is fine. An attacker may still have
1059   vastly higher cost than estimated here.
1060
1061   LUKS uses SHA1 for hashing per default. The claim in the reference
1062   is 63 billion tries/second for SHA1. We will leave aside the check
1063   whether a try actually decrypts a key-slot. Now, the machine has 25
1064   GPUs, which I will estimate at an overall lifetime cost of USD/EUR
1065   1000 each, and an useful lifetime of 2 years. (This is on the low
1066   side.) Disregarding downtime, the machine can then break
1067
1068      N = 63*10^9 * 3600 * 24 * 365 * 2 ~ 4*10^18     
1069    
1070   passphrases for EUR/USD 25k. That is one 62 bit passphrase hashed
1071   once with SHA1 for EUR/USD 25k. Note that as this can be
1072   parallelized, it can be done faster than 2 years with several of
1073   these machines.
1074
1075   For plain dm-crypt (no hash iteration) this is it. This gives (with
1076   SHA1, plain dm-crypt default is ripemd160 which seems to be
1077   slightly slower than SHA1):
1078
1079     Passphrase entropy  Cost to break  
1080     60 bit              EUR/USD     6k  
1081     65 bit              EUR/USD   200K
1082     70 bit              EUR/USD     6M
1083     75 bit              EUR/USD   200M
1084     80 bit              EUR/USD     6B
1085     85 bit              EUR/USD   200B
1086     ...                      ...    
1087  
1088   For LUKS, you have to take into account hash iteration in PBKDF2.
1089   For a current CPU, there are about 100k iterations (as can be
1090   queried with ''cryptsetup luksDump''.
1091
1092   The table above then becomes:
1093
1094     Passphrase entropy  Cost to break 
1095     50 bit              EUR/USD   600k 
1096     55 bit              EUR/USD    20M
1097     60 bit              EUR/USD   600M  
1098     65 bit              EUR/USD    20B
1099     70 bit              EUR/USD   600B
1100     75 bit              EUR/USD    20T
1101     ...                      ...    
1102  
1103   Recommendation:
1104
1105   To get reasonable security for the next 10 years, it is a good idea
1106   to overestimate by a factor of at least 1000.
1107
1108   Then there is the question of how much the attacker is willing to
1109   spend. That is up to your own security evaluation. For general use,
1110   I will assume the attacker is willing to spend up to 1 million
1111   EUR/USD. Then we get the following recommendations:
1112
1113   Plain dm-crypt: Use > 80 bit. That is e.g. 17 random chars from a-z
1114   or a random English sentence of > 135 characters length.
1115
1116   LUKS: Use > 65 bit. That is e.g. 14 random chars from a-z or a
1117   random English sentence of > 108 characters length.
1118
1119   If paranoid, add at least 20 bit. That is roughly four additional
1120   characters for random passphrases and roughly 32 characters for a
1121   random English sentence.
1122
1123
1124  * 5.2 Is LUKS insecure? Everybody can see I have encrypted data!
1125
1126   In practice it does not really matter. In most civilized countries
1127   you can just refuse to hand over the keys, no harm done. In some
1128   countries they can force you to hand over the keys, if they suspect
1129   encryption. However the suspicion is enough, they do not have to
1130   prove anything. This is for practical reasons, as even the presence
1131   of a header (like the LUKS header) is not enough to prove that you
1132   have any keys. It might have been an experiment, for example. Or it
1133   was used as encrypted swap with a key from /dev/random. So they
1134   make you prove you do not have encrypted data. Of course that is
1135   just as impossible as the other way round.
1136
1137   This means that if you have a large set of random-looking data,
1138   they can already lock you up. Hidden containers (encryption hidden
1139   within encryption), as possible with Truecrypt, do not help
1140   either. They will just assume the hidden container is there and
1141   unless you hand over the key, you will stay locked up. Don't have
1142   a hidden container? Though luck. Anybody could claim that.
1143
1144   Still, if you are concerned about the LUKS header, use plain
1145   dm-crypt with a good passphrase. See also Section 2, "What is the
1146   difference between "plain" and LUKS format?"
1147
1148
1149  * 5.3 Should I initialize (overwrite) a new LUKS/dm-crypt partition?
1150
1151   If you just create a filesystem on it, most of the old data will
1152   still be there. If the old data is sensitive, you should overwrite
1153   it before encrypting. In any case, not initializing will leave the
1154   old data there until the specific sector gets written. That may
1155   enable an attacker to determine how much and where on the
1156   partition data was written. If you think this is a risk, you can
1157   prevent this by overwriting the encrypted device (here assumed to
1158   be named "e1") with zeros like this:
1159
1160       dd_rescue -w /dev/zero /dev/mapper/e1
1161  
1162   or alternatively with one of the following more standard commands:
1163
1164       cat /dev/zero > /dev/mapper/e1
1165       dd if=/dev/zero of=/dev/mapper/e1
1166        
1167
1168  * 5.4 How do I securely erase a LUKS (or other) partition?
1169
1170   For LUKS, if you are in a desperate hurry, overwrite the LUKS
1171   header and key-slot area. This means overwriting the first
1172   (keyslots x stripes x keysize) + offset bytes. For the default
1173   parameters, this is the 1'052'672 bytes, i.e. 1MiB + 4096 of the
1174   LUKS partition. For 512 bit key length (e.g. for aes-xts-plain with
1175   512 bit key) this is 2MiB. (The different offset stems from
1176   differences in the sector alignment of the key-slots.) If in doubt,
1177   just be generous and overwrite the first 10MB or so, it will likely
1178   still be fast enough. A single overwrite with zeros should be
1179   enough. If you anticipate being in a desperate hurry, prepare the
1180   command beforehand. Example with /dev/sde1 as the LUKS partition
1181   and default parameters:
1182
1183       head -c 1052672 /dev/zero > /dev/sde1; sync
1184  
1185   A LUKS header backup or full backup will still grant access to
1186   most or all data, so make sure that an attacker does not have
1187   access to backups or destroy them as well.
1188
1189   If you have time, overwrite the whole LUKS partition with a single
1190   pass of zeros. This is enough for current HDDs. For SSDs or FLASH
1191   (USB sticks) you may want to overwrite the whole drive several
1192   times to be sure data is not retained by wear leveling. This is
1193   possibly still insecure as SSD technology is not fully understood
1194   in this regard. Still, due to the anti-forensic properties of the
1195   LUKS key-slots, a single overwrite of an SSD or FLASH drive could
1196   be enough. If in doubt, use physical destruction in addition. Here
1197   is a link to some current research results on erasing SSDs and
1198   FLASH drives:
1199   http://www.usenix.org/events/fast11/tech/full_papers/Wei.pdf
1200
1201   Keep in mind to also erase all backups.
1202
1203   Example for a zero-overwrite erase of partition sde1 done with
1204   dd_rescue:
1205
1206       dd_rescue -w /dev/zero /dev/sde1   
1207  
1208
1209  * 5.5 How do I securely erase a backup of a LUKS partition or header?
1210
1211   That depends on the medium it is stored on. For HDD and SSD, use
1212   overwrite with zeros. For an SSD or FLASH drive (USB stick), you
1213   may want to overwrite the complete SSD several times and use
1214   physical destruction in addition, see last item. For re-writable
1215   CD/DVD, a single overwrite should also be enough, due to the
1216   anti-forensic properties of the LUKS keyslots. For write-once
1217   media, use physical destruction. For low security requirements,
1218   just cut the CD/DVD into several parts. For high security needs,
1219   shred or burn the medium. If your backup is on magnetic tape, I
1220   advise physical destruction by shredding or burning, after
1221   overwriting . The problem with magnetic tape is that it has a
1222   higher dynamic range than HDDs and older data may well be
1223   recoverable after overwrites. Also write-head alignment issues can
1224   lead to data not actually being deleted at all during overwrites.
1225
1226
1227  * 5.6 What about backup? Does it compromise security?
1228
1229   That depends. See item 6.7.
1230
1231
1232  * 5.7 Why is all my data permanently gone if I overwrite the LUKS
1233    header?
1234
1235   Overwriting the LUKS header in part or in full is the most common
1236   reason why access to LUKS containers is lost permanently.
1237   Overwriting can be done in a number of fashions, like creating a
1238   new filesystem on the raw LUKS partition, making the raw partition
1239   part of a raid array and just writing to the raw partition.
1240
1241   The LUKS header contains a 256 bit "salt" per key-slot and without
1242   that no decryption is possible. While the salts are not secret,
1243   they are key-grade material and cannot be reconstructed. This is a
1244   cryptographically strong "cannot". From observations on the
1245   cryptsetup mailing-list, people typically go though the usual
1246   stages of grief (Denial, Anger, Bargaining, Depression, Acceptance)
1247   when this happens to them. Observed times vary between 1 day and 2
1248   weeks to complete the cycle. Seeking help on the mailing-list is
1249   fine. Even if we usually cannot help with getting back your data,
1250   most people found the feedback comforting.
1251
1252   If your header does not contain an intact key-slot salt, best go
1253   directly to the last stage ("Acceptance") and think about what to
1254   do now. There is one exception that I know of: If your LUKS
1255   container is still open, then it may be possible to extract the
1256   master key from the running system. See Item "How do I recover the
1257   master key from a mapped LUKS container?" in Section "Backup and
1258   Data Recovery".
1259
1260
1261  * 5.8 What is a "salt"?
1262
1263   A salt is a random key-grade value added to the passphrase before
1264   it is processed. It is not kept secret. The reason for using salts
1265   is as follows: If an attacker wants to crack the password for a
1266   single LUKS container, then every possible passphrase has to be
1267   tried. Typically an attacker will not try every binary value, but
1268   will try words and sentences from a dictionary.
1269
1270   If an attacker wants to attack several LUKS containers with the
1271   same dictionary, then a different approach makes sense: Compute the
1272   resulting slot-key for each dictionary element and store it on
1273   disk. Then the test for each entry is just the slow unlocking with
1274   the slot key (say 0.00001 sec) instead of calculating the slot-key
1275   first (1 sec). For a single attack, this does not help. But if you
1276   have more than one container to attack, this helps tremendously,
1277   also because you can prepare your table before you even have the
1278   container to attack! The calculation is also very simple to
1279   parallelize. You could, for example, use the night-time unused CPU
1280   power of your desktop PCs for this.
1281
1282   This is where the salt comes in. If the salt is combined with the
1283   passphrase (in the simplest form, just appended to it), you
1284   suddenly need a separate table for each salt value. With a
1285   reasonably-sized salt value (256 bit, e.g.) this is quite
1286   infeasible.
1287
1288
1289  * 5.9 Is LUKS secure with a low-entropy (bad) passphrase?
1290
1291   Note: You should only use the 94 printable characters from 7 bit
1292   ASCII code to prevent your passphrase from failing when the
1293   character encoding changes, e.g. because of a system upgrade, see
1294   also the note at the very start of this FAQ under "WARNINGS".
1295
1296   This needs a bit of theory. The quality of your passphrase is
1297   directly related to its entropy (information theoretic, not
1298   thermodynamic). The entropy says how many bits of "uncertainty" or
1299   "randomness" are in you passphrase. In other words, that is how
1300   difficult guessing the passphrase is.
1301
1302   Example: A random English sentence has about 1 bit of entropy per
1303   character. A random lowercase (or uppercase) character has about
1304   4.7 bit of entropy.
1305
1306   Now, if n is the number of bits of entropy in your passphrase and t
1307   is the time it takes to process a passphrase in order to open the
1308   LUKS container, then an attacker has to spend at maximum
1309
1310       attack_time_max = 2^n * t 
1311  
1312   time for a successful attack and on average half that. There is no
1313   way getting around that relationship. However, there is one thing
1314   that does help, namely increasing t, the time it takes to use a
1315   passphrase, see next FAQ item.
1316
1317   Still, if you want good security, a high-entropy passphrase is the
1318   only option. For example, a low-entropy passphrase can never be
1319   considered secure against a TLA-level (Three Letter Agency level,
1320   i.e. government-level) attacker, no matter what tricks are used in
1321   the key-derivation function. Use at least 64 bits for secret stuff.
1322   That is 64 characters of English text (but only if randomly chosen)
1323   or a combination of 12 truly random letters and digits.
1324
1325   For passphrase generation, do not use lines from very well-known
1326   texts (religious texts, Harry potter, etc.) as they are to easy to
1327   guess. For example, the total Harry Potter has about 1'500'000
1328   words (my estimation). Trying every 64 character sequence starting
1329   and ending at a word boundary would take only something like 20
1330   days on a single CPU and is entirely feasible. To put that into
1331   perspective, using a number of Amazon EC2 High-CPU Extra Large
1332   instances (each gives about 8 real cores), this test costs
1333   currently about 50USD/EUR, but can be made to run arbitrarily fast.
1334
1335   On the other hand, choosing 1.5 lines from, say, the Wheel of Time
1336   is in itself not more secure, but the book selection adds quite a
1337   bit of entropy. (Now that I have mentioned it here, don't use tWoT
1338   either!) If you add 2 or 3 typos or switch some words around, then
1339   this is good passphrase material.
1340
1341
1342  * 5.10 What is "iteration count" and why is decreasing it a bad idea?
1343
1344   Iteration count is the number of PBKDF2 iterations a passphrase is
1345   put through before it is used to unlock a key-slot. Iterations are
1346   done with the explicit purpose to increase the time that it takes
1347   to unlock a key-slot. This provides some protection against use of
1348   low-entropy passphrases.
1349
1350   The idea is that an attacker has to try all possible passphrases.
1351   Even if the attacker knows the passphrase is low-entropy (see last
1352   item), it is possible to make each individual try take longer. The
1353   way to do this is to repeatedly hash the passphrase for a certain
1354   time. The attacker then has to spend the same time (given the same
1355   computing power) as the user per try. With LUKS, the default is 1
1356   second of PBKDF2 hashing.
1357
1358   Example 1: Lets assume we have a really bad passphrase (e.g. a
1359   girlfriends name) with 10 bits of entropy. With the same CPU, an
1360   attacker would need to spend around 500 seconds on average to
1361   break that passphrase. Without iteration, it would be more like
1362   0.0001 seconds on a modern CPU.
1363
1364   Example 2: The user did a bit better and has 32 chars of English
1365   text. That would be about 32 bits of entropy. With 1 second
1366   iteration, that means an attacker on the same CPU needs around 136
1367   years. That is pretty impressive for such a weak passphrase.
1368   Without the iterations, it would be more like 50 days on a modern
1369   CPU, and possibly far less.
1370
1371   In addition, the attacker can both parallelize and use special
1372   hardware like GPUs or FPGAs to speed up the attack. The attack can
1373   also happen quite some time after the luksFormat operation and CPUs
1374   can have become faster and cheaper. For that reason you want a
1375   bit of extra security. Anyways, in Example 1 your are screwed.
1376   In example 2, not necessarily. Even if the attack is faster, it
1377   still has a certain cost associated with it, say 10000 EUR/USD
1378   with iteration and 1 EUR/USD without iteration. The first can be
1379   prohibitively expensive, while the second is something you try
1380   even without solid proof that the decryption will yield something
1381   useful.
1382
1383   The numbers above are mostly made up, but show the idea. Of course
1384   the best thing is to have a high-entropy passphrase.
1385
1386   Would a 100 sec iteration time be even better? Yes and no.
1387   Cryptographically it would be a lot better, namely 100 times better.
1388   However, usability is a very important factor for security
1389   technology and one that gets overlooked surprisingly often. For
1390   LUKS, if you have to wait 2 minutes to unlock the LUKS container,
1391   most people will not bother and use less secure storage instead. It
1392   is better to have less protection against low-entropy passphrases
1393   and people actually use LUKS, than having them do without
1394   encryption altogether.
1395
1396   Now, what about decreasing the iteration time? This is generally a
1397   very bad idea, unless you know and can enforce that the users only
1398   use high-entropy passphrases. If you decrease the iteration time
1399   without ensuring that, then you put your users at increased risk,
1400   and considering how rarely LUKS containers are unlocked in a
1401   typical work-flow, you do so without a good reason. Don't do it.
1402   The iteration time is already low enough that users with entropy
1403   low passphrases are vulnerable. Lowering it even further increases
1404   this danger significantly.
1405
1406
1407  * 5.11 Some people say PBKDF2 is insecure?
1408
1409   There is some discussion that a hash-function should have a "large
1410   memory" property, i.e. that it should require a lot of memory to be
1411   computed. This serves to prevent attacks using special programmable
1412   circuits, like FPGAs, and attacks using graphics cards. PBKDF2
1413   does not need a lot of memory and is vulnerable to these attacks.
1414   However, the publication usually referred in these discussions is
1415   not very convincing in proving that the presented hash really is
1416   "large memory" (that may change, email the FAQ maintainer when it
1417   does) and it is of limited usefulness anyways. Attackers that use
1418   clusters of normal PCs will not be affected at all by a "large
1419   memory" property. For example the US Secret Service is known to
1420   use the off-hour time of all the office PCs of the Treasury for
1421   password breaking. The Treasury has about 110'000 employees.
1422   Assuming every one has an office PC, that is significant computing
1423   power, all of it with plenty of memory for computing "large
1424   memory" hashes. Bot-net operators also have all the memory they
1425   want. The only protection against a resourceful attacker is a
1426   high-entropy passphrase, see items 5.9 and 5.10.
1427
1428
1429  * 5.12 What about iteration count with plain dm-crypt?
1430
1431   Simple: There is none. There is also no salting. If you use plain
1432   dm-crypt, the only way to be secure is to use a high entropy
1433   passphrase. If in doubt, use LUKS instead.
1434
1435
1436  * 5.13 Is LUKS with default parameters less secure on a slow CPU?
1437
1438   Unfortunately, yes. However the only aspect affected is the
1439   protection for low-entropy passphrase or master-key. All other
1440   security aspects are independent of CPU speed.
1441
1442   The master key is less critical, as you really have to work at it
1443   to give it low entropy. One possibility is to supply the master key
1444   yourself. If that key is low-entropy, then you get what you
1445   deserve. The other known possibility is to use /dev/urandom for
1446   key generation in an entropy-starved situation (e.g. automatic
1447   installation on an embedded device without network and other entropy
1448   sources).
1449
1450   For the passphrase, don't use a low-entropy passphrase. If your
1451   passphrase is good, then a slow CPU will not matter. If you insist
1452   on a low-entropy passphrase on a slow CPU, use something like
1453   "--iter-time=10" or higher and wait a long time on each LUKS unlock
1454   and pray that the attacker does not find out in which way exactly
1455   your passphrase is low entropy. This also applies to low-entropy
1456   passphrases on fast CPUs. Technology can do only so much to
1457   compensate for problems in front of the keyboard.
1458
1459
1460  * 5.14 Why was the default aes-cbc-plain replaced with aes-cbc-essiv?
1461
1462   Note: This item applies both to plain dm-crypt and to LUKS
1463
1464   The problem is that cbc-plain has a fingerprint vulnerability, where
1465   a specially crafted file placed into the crypto-container can be
1466   recognized from the outside. The issue here is that for cbc-plain
1467   the initialization vector (IV) is the sector number. The IV gets
1468   XORed to the first data chunk of the sector to be encrypted. If you
1469   make sure that the first data block to be stored in a sector
1470   contains the sector number as well, the first data block to be
1471   encrypted is all zeros and always encrypted to the same ciphertext.
1472   This also works if the first data chunk just has a constant XOR
1473   with the sector number. By having several shifted patterns you can
1474   take care of the case of a non-power-of-two start sector number of
1475   the file.
1476
1477   This mechanism allows you to create a pattern of sectors that have
1478   the same first ciphertext block and signal one bit per sector to the
1479   outside, allowing you to e.g. mark media files that way for
1480   recognition without decryption. For large files this is a
1481   practical attack. For small ones, you do not have enough blocks to
1482   signal and take care of different file starting offsets.
1483
1484   In order to prevent this attack, the default was changed to
1485   cbc-essiv. ESSIV uses a keyed hash of the sector number, with the
1486   encryption key as key. This makes the IV unpredictable without
1487   knowing the encryption key and the watermarking attack fails.
1488
1489
1490  * 5.15 Are there any problems with "plain" IV? What is "plain64"?
1491
1492   First, "plain" and "plain64" are both not secure to use with CBC,
1493   see previous FAQ item.
1494
1495   However there are modes, like XTS, that are secure with "plain" IV.
1496   The next limit is that "plain" is 64 bit, with the upper 32 bit set
1497   to zero. This means that on volumes larger than 2TiB, the IV
1498   repeats, creating a vulnerability that potentially leaks some
1499   data. To avoid this, use "plain64", which uses the full sector
1500   number up to 64 bit. Note that "plain64" requires a kernel >=
1501   2.6.33. Also note that "plain64" is backwards compatible for
1502   volume sizes <= 2TiB, but not for those > 2TiB. Finally, "plain64"
1503   does not cause any performance penalty compared to "plain".
1504
1505
1506  * 5.16 What about XTS mode?
1507
1508   XTS mode is potentially even more secure than cbc-essiv (but only if
1509   cbc-essiv is insecure in your scenario). It is a NIST standard and
1510   used, e.g. in Truecrypt. From version 1.6.0 of cryptsetup onwards,
1511   aes-xts-plain64 is the default for LUKS. If you want to use it
1512   with a cryptsetup before version 1.6.0 or with plain dm-crypt, you
1513   have to specify it manually as "aes-xts-plain", i.e.
1514
1515       cryptsetup -c aes-xts-plain luksFormat <device>
1516  
1517   For volumes >2TiB and kernels >= 2.6.33 use "plain64" (see FAQ
1518   item on "plain" and "plain64"):
1519
1520       cryptsetup -c aes-xts-plain64 luksFormat <device>
1521  
1522   There is a potential security issue with XTS mode and large blocks.
1523   LUKS and dm-crypt always use 512B blocks and the issue does not
1524   apply.
1525
1526
1527  * 5.17 Is LUKS FIPS-140-2 certified?
1528
1529   No. But that is more a problem of FIPS-140-2 than of LUKS. From a
1530   technical point-of-view, LUKS with the right parameters would be
1531   FIPS-140-2 compliant, but in order to make it certified, somebody
1532   has to pay real money for that. And then, whenever cryptsetup is
1533   changed or extended, the certification lapses and has to be
1534   obtained again.
1535
1536   From the aspect of actual security, LUKS with default parameters
1537   should be as good as most things that are FIPS-140-2 certified,
1538   although you may want to make sure to use /dev/random (by
1539   specifying --use-random on luksFormat) as randomness source for
1540   the master key to avoid being potentially insecure in an
1541   entropy-starved situation.
1542
1543
1544  * 5.18 What about Plausible Deniability?
1545
1546   First let me attempt a definition for the case of encrypted
1547   filesystems: Plausible deniability is when you hide encrypted data
1548   inside an encrypted container and it is not possible to prove it is
1549   there. The idea is compelling and on first glance it seems
1550   possible to do it. And from a cryptographic point of view, it
1551   actually is possible.
1552
1553   So, does it work in practice? No, unfortunately. The reasoning used
1554   by its proponents is fundamentally flawed in several ways and the
1555   cryptographic properties fail fatally when colliding with the real
1556   world.
1557
1558   First, why should "I do not have a hidden partition" be any more
1559   plausible than "I forgot my crypto key" or "I wiped that partition
1560   with random data, nothing in there"? I do not see any reason.
1561
1562   Second, there are two types of situations: Either they cannot force
1563   you to give them the key (then you simply do not) or the can. In
1564   the second case, they can always do bad things to you, because they
1565   cannot prove that you have the key in the first place! This means
1566   they do not have to prove you have the key, or that this random
1567   looking data on your disk is actually encrypted data. So the
1568   situation will allow them to waterboard/lock-up/deport you
1569   anyways, regardless of how "plausible" your deniability is. Do not
1570   have a hidden partition you could show to them, but there are
1571   indications you may? Too bad for you. Unfortunately "plausible
1572   deniability" also means you cannot prove there is no hidden data.
1573
1574   Third, hidden partitions are not that hidden. There are basically
1575   just two possibilities: a) Make a large crypto container, but put a
1576   smaller filesystem in there and put the hidden partition into the
1577   free space. Unfortunately this is glaringly obvious and can be
1578   detected in an automated fashion. This means that the initial
1579   suspicion to put you under duress in order to make you reveal you
1580   hidden data is given. b) Make a filesystem that spans the whole
1581   encrypted partition, and put the hidden partition into space not
1582   currently used by that filesystem. Unfortunately that is also
1583   glaringly obvious, as you then cannot write to the filesystem
1584   without a high risk of destroying data in the hidden container.
1585   Have not written anything to the encrypted filesystem  in a while?
1586   Too bad, they have the suspicion they need to do unpleasant things
1587   to you.
1588
1589   To be fair, if you prepare option b) carefully and directly before
1590   going into danger, it may work. But then, the mere presence of
1591   encrypted data may already be enough to get you into trouble in
1592   those places were they can demand encryption keys.
1593
1594   Here is an additional reference for some problems with plausible
1595   deniability: http://www.schneier.com/paper-truecrypt-dfs.pdf I
1596   strongly suggest you read it.
1597
1598   So, no, I will not provide any instructions on how to do it with
1599   plain dm-crypt or LUKS. If you insist on shooting yourself in the
1600   foot, you can figure out how to do it yourself.
1601
1602
1603  * 5.19 What about SSDs, Flash and Hybrid Drives?
1604
1605   The problem is that you cannot reliably erase parts of these
1606   devices, mainly due to wear-leveling and possibly defect
1607   management.
1608
1609   Basically, when overwriting a sector (of 512B), what the device
1610   does is to move an internal sector (may be 128kB or even larger) to
1611   some pool of discarded, not-yet erased unused sectors, take a
1612   fresh empty sector from the empty-sector pool and copy the old
1613   sector over with the changes to the small part you wrote. This is
1614   done in some fashion so that larger writes do not cause a lot of
1615   small internal updates.
1616
1617   The thing is that the mappings between outside-addressable sectors
1618   and inside sectors is arbitrary (and the vendors are not talking).
1619   Also the discarded sectors are not necessarily erased immediately.
1620   They may linger a long time.
1621
1622   For plain dm-crypt, the consequences are that older encrypted data
1623   may be lying around in some internal pools of the device. Thus may
1624   or may not be a problem and depends on the application. Remember
1625   the same can happen with a filesystem if consecutive writes to the
1626   same area of a file can go to different sectors.
1627
1628   However, for LUKS, the worst case is that key-slots and LUKS
1629   header may end up in these internal pools. This means that password
1630   management functionality is compromised (the old passwords may
1631   still be around, potentially for a very long time) and that fast
1632   erase by overwriting the header and key-slot area is insecure.
1633
1634   Also keep in mind that the discarded/used pool may be large. For
1635   example, a 240GB SSD has about 16GB of spare area in the chips that
1636   it is free to do with as it likes. You would need to make each
1637   individual key-slot larger than that to allow reliable overwriting.
1638   And that assumes the disk thinks all other space is in use.
1639   Reading the internal pools using forensic tools is not that hard,
1640   but may involve some soldering.
1641
1642   What to do?
1643
1644   If you trust the device vendor (you probably should not...) you can
1645   try an ATA "secure erase" command for SSDs. That does not work for
1646   USB keys though and may or may not be secure for a hybrid drive. If
1647   it finishes on an SSD after a few seconds, it was possibly faked.
1648   Unfortunately, for hybrid drives that indicator does not work, as
1649   the drive may well take the time to truly erase the magnetic part,
1650   but only mark the SSD/Flash part as erased while data is still in
1651   there.
1652
1653   If you can do without password management and are fine with doing
1654   physical destruction for permanently deleting data (always after
1655   one or several full overwrites!), you can use plain dm-crypt or
1656   LUKS.
1657
1658   If you want or need all the original LUKS security features to work,
1659   you can use a detached LUKS header and put that on a conventional,
1660   magnetic disk. That leaves potentially old encrypted data in the
1661   pools on the disk, but otherwise you get LUKS with the same
1662   security as on a magnetic disk.
1663
1664   If you are concerned about your laptop being stolen, you are likely
1665   fine using LUKS on an SSD or hybrid drive. An attacker would need
1666   to have access to an old passphrase (and the key-slot for this old
1667   passphrase would actually need to still be somewhere in the SSD)
1668   for your data to be at risk. So unless you pasted your old
1669   passphrase all over the Internet or the attacker has knowledge of
1670   it from some other source and does a targeted laptop theft to get
1671   at your data, you should be fine.
1672
1673
1674  * 5.20 LUKS is broken! It uses SHA-1!
1675
1676   No, it is not. SHA-1 is (academically) broken for finding
1677   collisions, but not for using it in a key-derivation function. And
1678   that collision vulnerability is for non-iterated use only. And you
1679   need the hash-value in verbatim.
1680
1681   This basically means that if you already have a slot-key, and you
1682   have set the PBKDF2 iteration count to 1 (it is > 10'000 normally),
1683   you could (maybe) derive a different passphrase that gives you the
1684   the same slot-key. But if you have the slot-key, you can already
1685   unlock the key-slot and get the master key, breaking everything. So
1686   basically, this SHA-1 vulnerability allows you to open a LUKS
1687   container with high effort when you already have it open.
1688
1689   The real problem here is people that do not understand crypto and
1690   claim things are broken just because some mechanism is used that
1691   has been broken for a specific different use. The way the mechanism
1692   is used matters very much. A hash that is broken for one use can be
1693   completely secure for other uses and here it is.
1694
1695
1696  * 5.21 Why is there no "Nuke-Option"?
1697
1698   A "Nuke-Option" or "Kill-switch" is a password that when entered
1699   upon unlocking instead wipes the header and all passwords. So when
1700   somebody forces you to enter your password, you can destroy the
1701   data instead.
1702
1703   While this sounds attractive at first glance, it does not make sense
1704   once a real security analysis is done. One problem is that you have
1705   to have some kind of HSM (Hardware Security Module) in order to
1706   implement it securely. In the movies, a HSM starts to smoke and
1707   melt once the Nuke-Option has been activated. In reality, it just
1708   wipes some battery-backed RAM cells. A proper HSM costs something
1709   like 20'000...100'000 EUR/USD and there a Nuke-Option may make some
1710   sense. BTW, a chipcard or a TPM is not a HSM, although some
1711   vendors are promoting that myth.
1712
1713   Now, a proper HSMs will have a wipe option but not a Nuke-Option,
1714   i.e. you can explicitly wipe the HSM, but by a different process
1715   than unlocking it takes. Why is that? Simple: If somebody can force
1716   you to reveal passwords, then they can also do bad things to you if
1717   you do not or if you enter a nuke password instead. Think locking
1718   you up for a few years for "destroying evidence" or for far longer
1719   and without trial for being a "terrorist suspect". No HSM maker
1720   will want to expose its customers to that risk.
1721
1722   Now think of the typical LUKS application scenario, i.e. disk
1723   encryption. Usually the ones forcing you to hand over your password
1724   will have access to the disk as well, and, if they have any real
1725   suspicion, they will mirror your disk before entering anything
1726   supplied by you. This neatly negates any Nuke-Option. If they have
1727   no suspicion (just harassing people that cross some border for
1728   example), the Nuke-Option would work, but see above about likely
1729   negative consequences and remember that a Nuke-Option may not work
1730   reliably on SSD and hybrid drives anyways.
1731
1732   Hence my advice is to never take data that you do not want to reveal
1733   into any such situation in the first place. There is no need to
1734   transfer data on physical carriers today. The Internet makes it
1735   quite possible to transfer data between arbitrary places and modern
1736   encryption makes it secure. If you do it right, nobody will even be
1737   able to identify source or destination. (How to do that is out of
1738   scope of this document. It does require advanced skills in this age
1739   of pervasive surveillance.)
1740
1741   Hence, LUKS has not kill option because it would do much more harm
1742   than good.
1743
1744   Still, if you have a good use-case (i.e. non-abstract real-world
1745   situation) where a Nuke-Option would actually be beneficial, please
1746   let me know.
1747
1748
1749 6. Backup and Data Recovery 
1750
1751
1752  * 6.1 Why do I need Backup?
1753
1754   First, disks die. The rate for well-treated (!) disk is about 5%
1755   per year, which is high enough to worry about. There is some
1756   indication that this may be even worse for some SSDs. This applies
1757   both to LUKS and plain dm-crypt partitions.
1758
1759   Second, for LUKS, if anything damages the LUKS header or the
1760   key-stripe area then decrypting the LUKS device can become
1761   impossible. This is a frequent occurrence. For example an
1762   accidental format as FAT or some software overwriting the first
1763   sector where it suspects a partition boot sector typically makes a
1764   LUKS partition permanently inaccessible. See more below on LUKS
1765   header damage.
1766
1767   So, data-backup in some form is non-optional. For LUKS, you may
1768   also want to store a header backup in some secure location. This
1769   only needs an update if you change passphrases.
1770
1771
1772  * 6.2 How do I backup a LUKS header?
1773
1774   While you could just copy the appropriate number of bytes from the
1775   start of the LUKS partition, the best way is to use command option
1776   "luksHeaderBackup" of cryptsetup. This protects also against
1777   errors when non-standard parameters have been used in LUKS
1778   partition creation. Example:
1779
1780  
1781      cryptsetup luksHeaderBackup --header-backup-file <file> <device>
1782  
1783   To restore, use the inverse command, i.e.
1784
1785      cryptsetup luksHeaderRestore --header-backup-file <file> <device>
1786  
1787   If you are unsure about a header to be restored, make a backup of
1788   the current one first! You can also test the header-file without
1789   restoring it by using the --header option for a detached header
1790   like this:
1791
1792      cryptsetup --header <file> luksOpen <device> </dev/mapper/ -name>
1793  
1794   If that unlocks your keys-lot, you are good. Do not forget to close
1795   the device again.
1796
1797
1798  * 6.3 How do I test a LUKS header?
1799
1800   Use
1801
1802      cryptsetup -v isLuks <device>
1803  
1804   on the device. Without the "-v" it just signals its result via
1805   exit-status. You can also use the more general test
1806
1807       blkid -p <device>
1808  
1809   which will also detect other types and give some more info. Omit
1810   "-p" for old versions of blkid that do not support it.
1811
1812
1813  * 6.4 How do I backup a LUKS or dm-crypt partition?
1814
1815   There are two options, a sector-image and a plain file or
1816   filesystem backup of the contents of the partition. The sector
1817   image is already encrypted, but cannot be compressed and contains
1818   all empty space. The filesystem backup can be compressed, can
1819   contain only part of the encrypted device, but needs to be
1820   encrypted separately if so desired.
1821
1822   A sector-image will contain the whole partition in encrypted form,
1823   for LUKS the LUKS header, the keys-slots and the data area. It can
1824   be done under Linux e.g. with dd_rescue (for a direct image copy)
1825   and with "cat" or "dd". Example:
1826
1827       cat /dev/sda10 > sda10.img
1828       dd_rescue /dev/sda10 sda10.img 
1829  
1830   You can also use any other backup software that is capable of making
1831   a sector image of a partition. Note that compression is
1832   ineffective for encrypted data, hence it does not make sense to
1833   use it.
1834
1835   For a filesystem backup, you decrypt and mount the encrypted
1836   partition and back it up as you would a normal filesystem. In this
1837   case the backup is not encrypted, unless your encryption method
1838   does that. For example you can encrypt a backup with "tar" as
1839   follows with GnuPG:
1840
1841       tar cjf - <path> | gpg --cipher-algo AES -c - > backup.tbz2.gpg
1842  
1843   And verify the backup like this if you are at "path":
1844
1845       cat backup.tbz2.gpg | gpg - | tar djf - 
1846  
1847   Note: Always verify backups, especially encrypted ones!
1848
1849   There is one problem with verifying like this: The kernel may still
1850   have some files cached and in fact verify them against RAM or may
1851   even verify RAM against RAM, which defeats the purpose of the
1852   exercise. The following command empties the kernel caches:
1853
1854       echo 3 > /proc/sys/vm/drop_caches
1855  
1856   Run it after backup and before verify.
1857
1858   In both cases GnuPG will ask you interactively for your symmetric
1859   key. The verify will only output errors. Use "tar dvjf -" to get
1860   all comparison results. To make sure no data is written to disk
1861   unencrypted, turn off swap if it is not encrypted before doing the
1862   backup.
1863
1864   Restore works like certification with the 'd' ('difference')
1865   replaced by 'x' ('eXtract'). Refer to the man-page of tar for more
1866   explanations and instructions. Note that with default options tar
1867   will overwrite already existing files without warning. If you are
1868   unsure about how to use tar, experiment with it in a location
1869   where you cannot do damage.
1870
1871   You can of course use different or no compression and you can use
1872   an asymmetric key if you have one and have a backup of the secret
1873   key that belongs to it.
1874
1875   A second option for a filesystem-level backup that can be used when
1876   the backup is also on local disk (e.g. an external USB drive) is
1877   to use a LUKS container there and copy the files to be backed up
1878   between both mounted containers. Also see next item.
1879
1880
1881  * 6.5 Do I need a backup of the full partition? Would the header and
1882    key-slots not be enough?
1883
1884   Backup protects you against two things: Disk loss or corruption
1885   and user error. By far the most questions on the dm-crypt mailing
1886   list about how to recover a damaged LUKS partition are related
1887   to user error. For example, if you create a new filesystem on a
1888   LUKS partition, chances are good that all data is lost
1889   permanently.
1890
1891   For this case, a header+key-slot backup would often be enough. But
1892   keep in mind that a well-treated (!) HDD has roughly a failure
1893   risk of 5% per year. It is highly advisable to have a complete
1894   backup to protect against this case.
1895
1896
1897   * *6.6 What do I need to backup if I use "decrypt_derived"?
1898
1899   This is a script in Debian, intended for mounting /tmp or swap with
1900   a key derived from the master key of an already decrypted device.
1901   If you use this for an device with data that should be persistent,
1902   you need to make sure you either do not lose access to that master
1903   key or have a backup of the data. If you derive from a LUKS
1904   device, a header backup of that device would cover backing up the
1905   master key. Keep in mind that this does not protect against disk
1906   loss.
1907
1908   Note: If you recreate the LUKS header of the device you derive from
1909   (using luksFormat), the master key changes even if you use the same
1910   passphrase(s) and you will not be able to decrypt the derived
1911   device with the new LUKS header.
1912
1913
1914  * 6.7 Does a backup compromise security?
1915
1916   Depends on how you do it. However if you do not have one, you are
1917   going to eventually lose your encrypted data.
1918
1919   There are risks introduced by backups. For example if you
1920   change/disable a key-slot in LUKS, a binary backup of the partition
1921   will still have the old key-slot. To deal with this, you have to
1922   be able to change the key-slot on the backup as well, securely
1923   erase the backup or do a filesystem-level backup instead of a binary
1924   one.
1925
1926   If you use dm-crypt, backup is simpler: As there is no key
1927   management, the main risk is that you cannot wipe the backup when
1928   wiping the original. However wiping the original for dm-crypt
1929   should consist of forgetting the passphrase and that you can do
1930   without actual access to the backup.
1931
1932   In both cases, there is an additional (usually small) risk with
1933   binary backups: An attacker can see how many sectors and which
1934   ones have been changed since the backup. To prevent this, use a
1935   filesystem level backup method that encrypts the whole backup in
1936   one go, e.g. as described above with tar and GnuPG.
1937
1938   My personal advice is to use one USB disk (low value data) or
1939   three disks (high value data) in rotating order for backups, and
1940   either use independent LUKS partitions on them, or use encrypted
1941   backup with tar and GnuPG.
1942
1943   If you do network-backup or tape-backup, I strongly recommend to
1944   go the filesystem backup path with independent encryption, as you
1945   typically cannot reliably delete data in these scenarios,
1946   especially in a cloud setting. (Well, you can burn the tape if it
1947   is under your control...)
1948
1949
1950  * 6.8 What happens if I overwrite the start of a LUKS partition or
1951    damage the LUKS header or key-slots?
1952
1953   There are two critical components for decryption: The salt values
1954   in the key-slot descriptors of the header and the key-slots. If the
1955   salt values are overwritten or changed, nothing (in the
1956   cryptographically strong sense) can be done to access the data,
1957   unless there is a backup of the LUKS header. If a key-slot is
1958   damaged, the data can still be read with a different key-slot, if
1959   there is a remaining undamaged and used key-slot. Note that in
1960   order to make a key-slot unrecoverable in a cryptographically
1961   strong sense, changing about 4-6 bits in random locations of its
1962   128kiB size is quite enough.
1963
1964
1965  * 6.9 What happens if I (quick) format a LUKS partition?
1966
1967   I have not tried the different ways to do this, but very likely you
1968   will have written a new boot-sector, which in turn overwrites the
1969   LUKS header, including the salts, making your data permanently
1970   irretrievable, unless you have a LUKS header backup. You may also
1971   damage the key-slots in part or in full. See also last item.
1972
1973
1974  * 6.10 How do I recover the master key from a mapped LUKS container?
1975
1976   This is typically only needed if you managed to damage your LUKS
1977   header, but the container is still mapped, i.e. "luksOpen"ed. It
1978   also helps if you have a mapped container that you forgot or do not
1979   know a passphrase for (e.g. on a long running server.)
1980
1981   WARNING: Things go wrong, do a full backup before trying this!
1982
1983   WARNING: This exposes the master key of the LUKS container. Note
1984   that both ways to recreate a LUKS header with the old master key
1985   described below will write the master key to disk. Unless you are
1986   sure you have securely erased it afterwards, e.g. by writing it to
1987   an encrypted partition, RAM disk or by erasing the filesystem you
1988   wrote it to by a complete overwrite, you should change the master
1989   key afterwards.    Changing the master key requires a full data
1990   backup, luksFormat and then restore of the backup.
1991
1992   First, there is a script by Milan that automates    the whole
1993   process, except generating a new LUKS header with the old master
1994   key (it prints the command for that though):
1995
1996   https://gitlab.com/cryptsetup/cryptsetup/blob/master/misc/luks-header-from-active
1997
1998   You can also do this manually. Here is how:
1999
2000   - Get the master key from the device mapper. This is done by the
2001   following command. Substitute c5 for whatever you mapped to:
2002
2003       # dmsetup table --target crypt --showkey /dev/mapper/c5
2004       Result:
2005       0 200704 crypt aes-cbc-essiv:sha256 
2006       a1704d9715f73a1bb4db581dcacadaf405e700d591e93e2eaade13ba653d0d09 
2007       0 7:0 4096
2008  
2009   The result is actually one line, wrapped here for clarity. The long
2010   hex string is the master key.
2011
2012   - Convert the master key to a binary file representation. You can
2013   do this manually, e.g. with hexedit. You can also use the tool
2014   "xxd" from vim like this:
2015
2016       echo "a1704d9....53d0d09" | xxd -r -p > <master-key-file>
2017  
2018   - Do a luksFormat to create a new LUKS header.
2019
2020     NOTE: If your header is intact and you just forgot the
2021   passphrase, you can just set a new passphrase, see next
2022   sub-item.
2023
2024   Unmap the device before you do that (luksClose). Then do
2025
2026       cryptsetup luksFormat --master-key-file=<master-key-file> <luks device>
2027  
2028   Note that if the container was created with other than the default
2029   settings of the cryptsetup version you are using, you need to give
2030   additional parameters specifying the deviations. If in doubt, try
2031   the script by Milan. It does recover the other parameters as well.
2032
2033   Side note: This is the way the decrypt_derived script gets at the
2034   master key. It just omits the conversion and hashes the master key
2035   string.
2036
2037   - If the header is intact and you just forgot the passphrase, just
2038   set a new passphrase like this:
2039
2040       cryptsetup luksAddKey --master-key-file=<master-key-file> <luks device>
2041  
2042   You may want to disable the old one afterwards.
2043
2044
2045  * 6.11 What does the on-disk structure of dm-crypt look like?
2046
2047   There is none. dm-crypt takes a block device and gives encrypted
2048   access to each of its blocks with a key derived from the passphrase
2049   given. If you use a cipher different than the default, you have to
2050   specify that as a parameter to cryptsetup too. If you want to
2051   change the password, you basically have to create a second
2052   encrypted device with the new passphrase and copy your data over.
2053   On the plus side, if you accidentally overwrite any part of a
2054   dm-crypt device, the damage will be limited to the area you
2055   overwrote.
2056
2057
2058  * 6.12 What does the on-disk structure of LUKS look like?
2059
2060   A LUKS partition consists of a header, followed by 8 key-slot
2061   descriptors, followed by 8 key slots, followed by the encrypted
2062   data area.
2063
2064   Header and key-slot descriptors fill the first 592 bytes. The
2065   key-slot size depends on the creation parameters, namely on the
2066   number of anti-forensic stripes, key material offset and master
2067   key size.
2068
2069   With the default parameters, each key-slot is a bit less than
2070   128kiB in size. Due to sector alignment of the key-slot start,
2071   that means the key block 0 is at offset 0x1000-0x20400, key
2072   block 1 at offset 0x21000-0x40400, and key block 7 at offset
2073   0xc1000-0xe0400. The space to the next full sector address is
2074   padded with zeros. Never used key-slots are filled with what the
2075   disk originally contained there, a key-slot removed with
2076   "luksRemoveKey" or "luksKillSlot" gets filled with 0xff. Due to
2077   2MiB default alignment, start of the data area for cryptsetup 1.3
2078   and later is at 2MiB, i.e. at 0x200000. For older versions, it is
2079   at 0x101000, i.e. at 1'052'672 bytes, i.e. at 1MiB + 4096 bytes
2080   from the start of the partition. Incidentally, "luksHeaderBackup"
2081   for a LUKS container created with default parameters dumps exactly
2082   the first 2MiB (or 1'052'672 bytes for   headers created with
2083   cryptsetup versions < 1.3) to file and "luksHeaderRestore" restores
2084   them.
2085
2086   For non-default parameters, you have to figure out placement
2087   yourself. "luksDump" helps. See also next item. For the most common
2088   non-default settings, namely aes-xts-plain with 512 bit key, the
2089   offsets are: 1st keyslot 0x1000-0x3f800, 2nd keyslot
2090   0x40000-0x7e000, 3rd keyslot 0x7e000-0xbd800, ..., and start of
2091   bulk data at 0x200000.
2092
2093   The exact specification of the format is here:
2094   https://gitlab.com/cryptsetup/cryptsetup/wikis/Specification
2095
2096   For your convenience, here is the LUKS header with hex offsets.
2097   NOTE: The spec counts key-slots from 1 to 8, but the cryptsetup
2098   tool counts from 0 to 7. The numbers here refer to the cryptsetup
2099   numbers.
2100
2101 Refers to LUKS On-Disk Format Specification Version 1.2.1
2102 LUKS header:
2103 offset  length  name             data type  description
2104 -----------------------------------------------------------------------
2105 0x0000   0x06   magic            byte[]     'L','U','K','S', 0xba, 0xbe
2106      0      6
2107 0x0006   0x02   version          uint16_t   LUKS version
2108      6      3
2109 0x0008   0x20   cipher-name      char[]     cipher name spec.
2110      8     32
2111 0x0028   0x20   cipher-mode      char[]     cipher mode spec.
2112     40     32
2113 0x0048   0x20   hash-spec        char[]     hash spec.
2114     72     32
2115 0x0068   0x04   payload-offset   uint32_t   bulk data offset in sectors
2116    104      4                               (512 bytes per sector)
2117 0x006c   0x04   key-bytes        uint32_t   number of bytes in key
2118    108      4
2119 0x0070   0x14   mk-digest        byte[]     master key checksum
2120    112     20                               calculated with PBKDF2
2121 0x0084   0x20   mk-digest-salt   byte[]     salt for PBKDF2 when
2122    132     32                               calculating mk-digest
2123 0x00a4   0x04   mk-digest-iter   uint32_t   iteration count for PBKDF2
2124    164      4                               when calculating mk-digest
2125 0x00a8   0x28   uuid             char[]     partition UUID
2126    168     40
2127 0x00d0   0x30   key-slot-0       key slot   key slot 0
2128    208     48
2129 0x0100   0x30   key-slot-1       key slot   key slot 1
2130    256     48
2131 0x0130   0x30   key-slot-2       key slot   key slot 2
2132    304     48
2133 0x0160   0x30   key-slot-3       key slot   key slot 3
2134    352     48
2135 0x0190   0x30   key-slot-4       key slot   key slot 4
2136    400     48
2137 0x01c0   0x30   key-slot-5       key slot   key slot 5
2138    448     48
2139 0x01f0   0x30   key-slot-6       key slot   key slot 6
2140    496     48
2141 0x0220   0x30   key-slot-7       key slot   key slot 7
2142    544     48
2143 Key slot:
2144 offset  length  name                  data type  description
2145 -------------------------------------------------------------------------
2146 0x0000   0x04   active                uint32_t   key slot enabled/disabled
2147      0      4
2148 0x0004   0x04   iterations            uint32_t   PBKDF2 iteration count
2149      4      4
2150 0x0008   0x20   salt                  byte[]     PBKDF2 salt
2151      8     32
2152 0x0028   0x04   key-material-offset   uint32_t   key start sector
2153     40      4                                    (512 bytes/sector)
2154 0x002c   0x04   stripes               uint32_t   number of anti-forensic
2155     44      4                                    stripes
2156  
2157
2158  * 6.13 What is the smallest possible LUKS container?
2159
2160   Note: From cryptsetup 1.3 onwards, alignment is set to 1MB. With
2161   modern Linux partitioning tools that also align to 1MB, this will
2162   result in alignment to 2k sectors and typical Flash/SSD sectors,
2163   which is highly desirable for a number of reasons. Changing the
2164   alignment is not recommended.
2165
2166   That said, with default parameters, the data area starts at
2167   exactly 2MB offset (at 0x101000 for cryptsetup versions before
2168   1.3). The smallest data area you can have is one sector of 512
2169   bytes. Data areas of 0 bytes can be created, but fail on mapping.
2170
2171   While you cannot put a filesystem into something this small, it may
2172   still be used to contain, for example, key. Note that with current
2173   formatting tools, a partition for a container this size will be
2174   3MiB anyways. If you put the LUKS container into a file (via
2175   losetup and a loopback device), the file needs to be 2097664 bytes
2176   in size, i.e. 2MiB + 512B.
2177
2178   There two ways to influence the start of the data area are key-size
2179   and alignment.
2180
2181   For alignment, you can go down to 1 on the parameter. This will
2182   still leave you with a data-area starting at 0x101000, i.e.
2183   1MiB+4096B (default parameters) as alignment will be rounded up to
2184   the next multiple of 8 (i.e. 4096 bytes) If in doubt, do a dry-run
2185   on a larger file and dump the LUKS header to get actual
2186   information.
2187
2188   For key-size, you can use 128 bit (e.g. AES-128 with CBC), 256 bit
2189   (e.g. AES-256 with CBC) or 512 bit (e.g. AES-256 with XTS mode).
2190   You can do 64 bit (e.g. blowfish-64 with CBC), but anything below
2191   128 bit has to be considered insecure today.
2192
2193   Example 1 - AES 128 bit with CBC:
2194
2195       cryptsetup luksFormat -s 128 --align-payload=8 <device>
2196  
2197   This results in a data offset of 0x81000, i.e. 516KiB or 528384
2198   bytes. Add one 512 byte sector and the smallest LUKS container size
2199   with these parameters is 516KiB + 512B or 528896 bytes.
2200
2201   Example 2 - Blowfish 64 bit with CBC (WARNING: insecure):
2202
2203       cryptsetup luksFormat -c blowfish -s 64 --align-payload=8 /dev/loop0
2204  
2205   This results in a data offset of 0x41000, i.e. 260kiB or 266240
2206   bytes, with a minimal LUKS container size of 260kiB + 512B or
2207   266752 bytes.
2208
2209
2210  * 6.14 I think this is overly complicated. Is there an alternative?
2211
2212   Not really. Encryption comes at a price. You can use plain
2213   dm-crypt to simplify things a bit. It does not allow multiple
2214   passphrases, but on the plus side, it has zero on disk description
2215   and if you overwrite some part of a plain dm-crypt partition,
2216   exactly the overwritten parts are lost (rounded up to sector
2217   borders).
2218
2219
2220  * 6.15 Can I clone a LUKS container?
2221
2222   You can, but it breaks security, because the cloned container has
2223   the same header and hence the same master key. You cannot change
2224   the master key on a LUKS container, even if you change the
2225   passphrase(s), the master key stays the same. That means whoever
2226   has access to one of the clones can decrypt them all, completely
2227   bypassing the passphrases.
2228
2229   The right way to do this is to first luksFormat the target
2230   container, then to clone the contents of the source container, with
2231   both containers mapped, i.e. decrypted. You can clone the decrypted
2232   contents of a LUKS container in binary mode, although you may run
2233   into secondary issues with GUIDs in filesystems, partition tables,
2234   RAID-components and the like. These are just the normal problems
2235   binary cloning causes.
2236
2237   Note that if you need to ship (e.g.) cloned LUKS containers with a
2238   default passphrase, that is fine as long as each container was
2239   individually created (and hence has its own master key). In this
2240   case, changing the default passphrase will make it secure again.
2241
2242
2243 7. Interoperability with other Disk Encryption Tools  
2244
2245
2246  * 7.1 What is this section about?
2247
2248   Cryptsetup for plain dm-crypt can be used to access a number of
2249   on-disk formats created by tools like loop-aes patched into
2250   losetup. This sometimes works and sometimes does not.    This
2251   section collects insights into what works, what does not and where
2252   more information is required.
2253
2254   Additional information may be found in the mailing-list archives,
2255   mentioned at the start of this FAQ document. If you have a
2256   solution working that is not yet documented here and think a wider
2257   audience may be interested, please email the FAQ maintainer.
2258
2259
2260  * 7.2 loop-aes: General observations.
2261
2262   One problem is that there are different versions of losetup around.
2263   loop-aes is a patch for losetup. Possible problems and deviations
2264   from cryptsetup option syntax include:
2265
2266   - Offsets specified in bytes (cryptsetup: 512 byte sectors)
2267
2268   - The need to specify an IV offset
2269
2270   - Encryption mode needs specifying (e.g. "-c twofish-cbc-plain")
2271
2272   - Key size needs specifying (e.g. "-s 128" for 128 bit keys)
2273
2274   - Passphrase hash algorithm needs specifying
2275
2276   Also note that because plain dm-crypt and loop-aes format does not
2277   have metadata, and while the loopAES extension for cryptsetup tries
2278   autodetection (see command loopaesOpen), it may not always work.
2279   If you still have the old set-up, using a verbosity option (-v)
2280   on mapping with the old tool or having a look into the system logs
2281   after setup could give you the information you need. Below, there
2282   are also some things that worked for somebody.
2283
2284
2285  * 7.3 loop-aes patched into losetup on Debian 5.x, kernel 2.6.32
2286
2287   In this case, the main problem seems to be that this variant of
2288   losetup takes the offset (-o option) in bytes, while cryptsetup
2289   takes it in sectors of 512 bytes each. Example: The losetup command
2290
2291   losetup -e twofish -o 2560 /dev/loop0 /dev/sdb1 
2292   mount /dev/loop0 mount-point
2293  
2294   translates to
2295
2296   cryptsetup create -c twofish -o 5 --skip 5 e1 /dev/sdb1
2297   mount /dev/mapper/e1 mount-point
2298  
2299
2300  * 7.4 loop-aes with 160 bit key
2301
2302   This seems to be sometimes used with twofish and blowfish and
2303   represents a 160 bit ripemed160 hash output padded to 196 bit key
2304   length. It seems the corresponding options for cryptsetup are
2305
2306   --cipher twofish-cbc-null -s 192 -h ripemd160:20
2307  
2308
2309  * 7.5 loop-aes v1 format OpenSUSE
2310
2311   Apparently this is done by older OpenSUSE distros and stopped
2312   working from OpenSUSE 12.1 to 12.2. One user had success with the
2313   following:
2314
2315   cryptsetup create <target> <device> -c aes -s 128 -h sha256
2316  
2317
2318  * 7.6 Kernel encrypted loop device (cryptoloop)
2319
2320   There are a number of different losetup implementations for using
2321   encrypted loop devices so getting this to work may need a bit of
2322   experimentation.
2323
2324   NOTE: Do NOT use this for new containers! Some of the existing
2325   implementations are insecure and future support is uncertain.
2326
2327   Example for a compatible mapping:
2328
2329     losetup -e twofish -N /dev/loop0 /image.img
2330  
2331   translates to
2332
2333     cryptsetup create image_plain /image.img -c twofish-cbc-plain -H plain
2334  
2335   with the mapping being done to /dev/mapper/image_plain instead of
2336   to /dev/loop0.
2337
2338   More details:
2339
2340   Cipher, mode and pasword hash (or no hash):
2341
2342   -e cipher [-N]        => -c cipher-cbc-plain -H plain [-s 256]
2343   -e cipher             => -c cipher-cbc-plain -H ripemd160 [-s 256]
2344  
2345   Key size and offsets (losetup: bytes, cryptsetuop: sectors of 512
2346   bytes):
2347
2348   -k 128                 => -s 128
2349   -o 2560                => -o 5 -p 5       # 2560/512 = 5
2350  
2351   There is no replacement for --pass-fd, it has to be emulated using
2352   keyfiles, see the cryptsetup man-page.
2353
2354
2355 8. Issues with Specific Versions of cryptsetup 
2356
2357
2358  * 8.1 When using the create command for plain dm-crypt with
2359    cryptsetup 1.1.x, the mapping is incompatible and my data is not
2360    accessible anymore!
2361
2362   With cryptsetup 1.1.x, the distro maintainer can define different
2363   default encryption modes. You can check the compiled-in defaults
2364   using "cryptsetup --help". Moreover, the plain device default
2365   changed because the old IV mode was vulnerable to a watermarking
2366   attack.
2367
2368   If you are using a plain device and you need a compatible mode, just
2369   specify cipher, key size and hash algorithm explicitly. For
2370   compatibility with cryptsetup 1.0.x defaults, simple use the
2371   following:
2372
2373     cryptsetup create -c aes-cbc-plain -s 256 -h ripemd160 <name> <dev>
2374  
2375   LUKS stores cipher and mode in the metadata on disk, avoiding this
2376   problem.
2377
2378
2379  * 8.2 cryptsetup on SLED 10 has problems...
2380
2381   SLED 10 is missing an essential kernel patch for dm-crypt, which
2382   is broken in its kernel as a result. There may be a very old
2383   version of cryptsetup (1.0.x) provided by SLED, which should also
2384   not be used anymore as well. My advice would be to drop SLED 10.
2385
2386
2387  * 8.3 Gcrypt after 1.5.3 breaks Whirlpool
2388
2389   It is the other way round: In gcrypt 1.5.3 and before Whirlpool is
2390   broken and it was fixed in the next version. If you selected
2391   whirlpool as hash on creation of a LUKS container, it does not work
2392   anymore with the fixed library. This shows one serious risk of
2393   using rarely used settings.
2394
2395   The only two ways to deal with this are either to decrypt with an
2396   old gcrypt version that has the flaw or to use a compatibility
2397   feature introduced in cryptsetup 1.6.4 and gcrypt 1.6.1 or later.
2398   Versions of gcrypt between 1.5.4 and 1.6.0 cannot be used.
2399
2400   Steps:
2401
2402   - Make a least a header backup or better, refresh your full
2403   backup. (You have a full backup, right? See Item 6.1 and
2404   following.)
2405
2406   - Make sure you have cryptsetup 1.6.4 or later and check the gcrypt
2407   version:
2408
2409  
2410      cryptsetup luksDump <your luks device> --debug | grep backend
2411  
2412   If gcrypt is at version 1.5.3 or before:
2413
2414   - Reencrypt the LUKS header with a different hash. (Requires
2415   entering all keyslot passphrases. If you do not have all, remove
2416   the ones you do not have before.):
2417
2418      cryptsetup-reencrypt --keep-key --hash sha256 <your luks device>
2419  
2420   If gcrypt is at version 1.6.1 or later:
2421
2422   - Patch the hash name in the LUKS header from "whirlpool" to
2423   "whirlpool_gcryptbug". This activates the broken implementation.
2424   The detailed header layout is in Item 6.12 of this FAQ and in the
2425   LUKS on-disk format specification. One way to change the hash is
2426   with the following command:
2427
2428      echo -n -e 'whirlpool_gcryptbug\0' | dd of=<luks device> bs=1 seek=72 conv=notrunc
2429  
2430   - You can now open the device again. It is highly advisable to
2431   change the hash now with cryptsetup-reencrypt as described above.
2432   While you can reencrypt to use the fixed whirlpool, that may not
2433   be a good idea as almost nobody seems to use it and hence the long
2434   time until the bug was discovered.
2435
2436
2437 9. References and Further Reading 
2438
2439
2440  * Purpose of this Section
2441
2442   The purpose of this section is to collect references to all
2443   materials that do not fit the FAQ but are relevant in some fashion.
2444   This can be core topics like the LUKS spec or disk encryption, but
2445   it can also be more tangential, like secure storage management or
2446   cryptography used in LUKS. It should still have relevance to
2447   cryptsetup and its applications.
2448
2449   If you wan to see something added here, send email to the
2450   maintainer (or the cryptsetup mailing list) giving an URL, a
2451   description (1-3 lines preferred) and a section to put it in. You
2452   can also propose new sections.
2453
2454   At this time I would like to limit the references to things that
2455   are available on the web.
2456
2457
2458  * Specifications
2459
2460   - LUKS on-disk format spec:
2461   https://gitlab.com/cryptsetup/cryptsetup/wikis/Specification
2462
2463  * Code Examples
2464
2465   - Some code examples are in the source package under docs/examples
2466
2467
2468  * Brute-forcing passphrases
2469
2470   -
2471   http://news.electricalchemy.net/2009/10/password-cracking-in-cloud-part-5.html
2472
2473   -
2474   http://it.slashdot.org/story/12/12/05/0623215/new-25-gpu-monster-devours-strong-passwords-in-minutes
2475
2476
2477  * Tools
2478
2479
2480  * SSD and Flash Disk Related
2481
2482
2483  * Disk Encryption
2484
2485
2486  * Attacks Against Disk Encryption
2487
2488
2489  * Risk Management as Relevant for Disk Encryption
2490
2491
2492  * Cryptography
2493
2494
2495  * Secure Storage
2496
2497  A. Contributors In no particular order:
2498
2499   - Arno Wagner
2500
2501   - Milan Broz
2502