xref: /linux/Documentation/admin-guide/device-mapper/dm-crypt.rst (revision cb8fef4b07f71da01843457b66e579ad248a625e)
1========
2dm-crypt
3========
4
5Device-Mapper's "crypt" target provides transparent encryption of block devices
6using the kernel crypto API.
7
8For a more detailed description of supported parameters see:
9https://gitlab.com/cryptsetup/cryptsetup/wikis/DMCrypt
10
11Parameters::
12
13	      <cipher> <key> <iv_offset> <device path> \
14	      <offset> [<#opt_params> <opt_params>]
15
16<cipher>
17    Encryption cipher, encryption mode and Initial Vector (IV) generator.
18
19    The cipher specifications format is::
20
21       cipher[:keycount]-chainmode-ivmode[:ivopts]
22
23    Examples::
24
25       aes-cbc-essiv:sha256
26       aes-xts-plain64
27       serpent-xts-plain64
28
29    Cipher format also supports direct specification with kernel crypt API
30    format (selected by capi: prefix). The IV specification is the same
31    as for the first format type.
32    This format is mainly used for specification of authenticated modes.
33
34    The crypto API cipher specifications format is::
35
36        capi:cipher_api_spec-ivmode[:ivopts]
37
38    Examples::
39
40        capi:cbc(aes)-essiv:sha256
41        capi:xts(aes)-plain64
42
43    Examples of authenticated modes::
44
45        capi:gcm(aes)-random
46        capi:authenc(hmac(sha256),xts(aes))-random
47        capi:rfc7539(chacha20,poly1305)-random
48
49    The /proc/crypto contains a list of currently loaded crypto modes.
50
51<key>
52    Key used for encryption. It is encoded either as a hexadecimal number
53    or it can be passed as <key_string> prefixed with single colon
54    character (':') for keys residing in kernel keyring service.
55    You can only use key sizes that are valid for the selected cipher
56    in combination with the selected iv mode.
57    Note that for some iv modes the key string can contain additional
58    keys (for example IV seed) so the key contains more parts concatenated
59    into a single string.
60
61<key_string>
62    The kernel keyring key is identified by string in following format:
63    <key_size>:<key_type>:<key_description>.
64
65<key_size>
66    The encryption key size in bytes. The kernel key payload size must match
67    the value passed in <key_size>.
68
69<key_type>
70    Either 'logon', 'user', 'encrypted' or 'trusted' kernel key type.
71
72<key_description>
73    The kernel keyring key description crypt target should look for
74    when loading key of <key_type>.
75
76<keycount>
77    Multi-key compatibility mode. You can define <keycount> keys and
78    then sectors are encrypted according to their offsets (sector 0 uses key0;
79    sector 1 uses key1 etc.).  <keycount> must be a power of two.
80
81<iv_offset>
82    The IV offset is a sector count that is added to the sector number
83    before creating the IV.
84
85<device path>
86    This is the device that is going to be used as backend and contains the
87    encrypted data.  You can specify it as a path like /dev/xxx or a device
88    number <major>:<minor>.
89
90<offset>
91    Starting sector within the device where the encrypted data begins.
92
93<#opt_params>
94    Number of optional parameters. If there are no optional parameters,
95    the optional parameters section can be skipped or #opt_params can be zero.
96    Otherwise #opt_params is the number of following arguments.
97
98    Example of optional parameters section:
99        3 allow_discards same_cpu_crypt submit_from_crypt_cpus
100
101allow_discards
102    Block discard requests (a.k.a. TRIM) are passed through the crypt device.
103    The default is to ignore discard requests.
104
105    WARNING: Assess the specific security risks carefully before enabling this
106    option.  For example, allowing discards on encrypted devices may lead to
107    the leak of information about the ciphertext device (filesystem type,
108    used space etc.) if the discarded blocks can be located easily on the
109    device later.
110
111same_cpu_crypt
112    Perform encryption using the same cpu that IO was submitted on.
113    The default is to use an unbound workqueue so that encryption work
114    is automatically balanced between available CPUs.
115
116high_priority
117    Set dm-crypt workqueues and the writer thread to high priority. This
118    improves throughput and latency of dm-crypt while degrading general
119    responsiveness of the system.
120
121submit_from_crypt_cpus
122    Disable offloading writes to a separate thread after encryption.
123    There are some situations where offloading write bios from the
124    encryption threads to a single thread degrades performance
125    significantly.  The default is to offload write bios to the same
126    thread because it benefits CFQ to have writes submitted using the
127    same context.
128
129no_read_workqueue
130    Bypass dm-crypt internal workqueue and process read requests synchronously.
131
132no_write_workqueue
133    Bypass dm-crypt internal workqueue and process write requests synchronously.
134    This option is automatically enabled for host-managed zoned block devices
135    (e.g. host-managed SMR hard-disks).
136
137integrity:<bytes>:<type>
138    The device requires additional <bytes> metadata per-sector stored
139    in per-bio integrity structure. This metadata must by provided
140    by underlying dm-integrity target.
141
142    The <type> can be "none" if metadata is used only for persistent IV.
143
144    For Authenticated Encryption with Additional Data (AEAD)
145    the <type> is "aead". An AEAD mode additionally calculates and verifies
146    integrity for the encrypted device. The additional space is then
147    used for storing authentication tag (and persistent IV if needed).
148
149integrity_key_size:<bytes>
150    Optionally set the integrity key size if it differs from the digest size.
151    It allows the use of wrapped key algorithms where the key size is
152    independent of the cryptographic key size.
153
154sector_size:<bytes>
155    Use <bytes> as the encryption unit instead of 512 bytes sectors.
156    This option can be in range 512 - PAGE_SIZE bytes, further limited by
157    the block layer's maximum block size, and must be power of two.
158    Virtual device will announce this size as a minimal IO and logical sector.
159
160    An encryption unit larger than 4096 bytes can only be used on a system
161    whose PAGE_SIZE is at least that large, so such a mapping is not
162    portable across architectures and is unsuitable for portable on-disk
163    formats such as LUKS.
164
165    An encryption sector larger than the unit the underlying device writes
166    atomically can be torn by a power failure, leaving part of the sector
167    written and part not. A device that advertises no atomic write unit
168    gives no such guarantee beyond a single logical block, so this is
169    already possible at 4096 bytes; a larger sector widens the window.
170    With XTS and ECB the torn sector decrypts to a mixture of old and new
171    data, as a torn write does on an unencrypted device. With chaining
172    modes the block at the tear also decrypts to garbage, with AEAD the
173    whole sector fails authentication, and with the wide-block diffusers
174    the whole sector decrypts to garbage. Use a large sector only where
175    losing a sector to a power failure is acceptable.
176
177iv_large_sectors
178   IV generators will use sector number counted in <sector_size> units
179   instead of default 512 bytes sectors.
180
181   For example, if <sector_size> is 4096 bytes, plain64 IV for the second
182   sector will be 8 (without flag) and 1 if iv_large_sectors is present.
183   The <iv_offset> must be multiple of <sector_size> (in 512 bytes units)
184   if this flag is specified.
185
186integrity_key_size:<bytes>
187   Use an integrity key of <bytes> size instead of using an integrity key size
188   of the digest size of the used HMAC algorithm.
189
190
191Module parameters::
192   max_read_size
193      Maximum size of read requests. When a request larger than this size
194      is received, dm-crypt will split the request. The splitting improves
195      concurrency (the split requests could be encrypted in parallel by multiple
196      cores), but it also causes overhead. The user should tune this parameters to
197      fit the actual workload.
198
199   max_write_size
200      Maximum size of write requests. When a request larger than this size
201      is received, dm-crypt will split the request. The splitting improves
202      concurrency (the split requests could be encrypted in parallel by multiple
203      cores), but it also causes overhead. The user should tune this parameters to
204      fit the actual workload.
205
206
207Example scripts
208===============
209LUKS (Linux Unified Key Setup) is now the preferred way to set up disk
210encryption with dm-crypt using the 'cryptsetup' utility, see
211https://gitlab.com/cryptsetup/cryptsetup
212
213::
214
215	#!/bin/sh
216	# Create a crypt device using dmsetup
217	dmsetup create crypt1 --table "0 `blockdev --getsz $1` crypt aes-cbc-essiv:sha256 babebabebabebabebabebabebabebabe 0 $1 0"
218
219::
220
221	#!/bin/sh
222	# Create a crypt device using dmsetup when encryption key is stored in keyring service
223	dmsetup create crypt2 --table "0 `blockdev --getsize $1` crypt aes-cbc-essiv:sha256 :32:logon:my_prefix:my_key 0 $1 0"
224
225::
226
227	#!/bin/sh
228	# Create a crypt device using cryptsetup and LUKS header with default cipher
229	cryptsetup luksFormat $1
230	cryptsetup luksOpen $1 crypt1
231