dm-crypt.rst 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. ========
  2. dm-crypt
  3. ========
  4. Device-Mapper's "crypt" target provides transparent encryption of block devices
  5. using the kernel crypto API.
  6. For a more detailed description of supported parameters see:
  7. https://gitlab.com/cryptsetup/cryptsetup/wikis/DMCrypt
  8. Parameters::
  9. <cipher> <key> <iv_offset> <device path> \
  10. <offset> [<#opt_params> <opt_params>]
  11. <cipher>
  12. Encryption cipher, encryption mode and Initial Vector (IV) generator.
  13. The cipher specifications format is::
  14. cipher[:keycount]-chainmode-ivmode[:ivopts]
  15. Examples::
  16. aes-cbc-essiv:sha256
  17. aes-xts-plain64
  18. serpent-xts-plain64
  19. Cipher format also supports direct specification with kernel crypt API
  20. format (selected by capi: prefix). The IV specification is the same
  21. as for the first format type.
  22. This format is mainly used for specification of authenticated modes.
  23. The crypto API cipher specifications format is::
  24. capi:cipher_api_spec-ivmode[:ivopts]
  25. Examples::
  26. capi:cbc(aes)-essiv:sha256
  27. capi:xts(aes)-plain64
  28. Examples of authenticated modes::
  29. capi:gcm(aes)-random
  30. capi:authenc(hmac(sha256),xts(aes))-random
  31. capi:rfc7539(chacha20,poly1305)-random
  32. The /proc/crypto contains a list of curently loaded crypto modes.
  33. <key>
  34. Key used for encryption. It is encoded either as a hexadecimal number
  35. or it can be passed as <key_string> prefixed with single colon
  36. character (':') for keys residing in kernel keyring service.
  37. You can only use key sizes that are valid for the selected cipher
  38. in combination with the selected iv mode.
  39. Note that for some iv modes the key string can contain additional
  40. keys (for example IV seed) so the key contains more parts concatenated
  41. into a single string.
  42. <key_string>
  43. The kernel keyring key is identified by string in following format:
  44. <key_size>:<key_type>:<key_description>.
  45. <key_size>
  46. The encryption key size in bytes. The kernel key payload size must match
  47. the value passed in <key_size>.
  48. <key_type>
  49. Either 'logon', 'user' or 'encrypted' kernel key type.
  50. <key_description>
  51. The kernel keyring key description crypt target should look for
  52. when loading key of <key_type>.
  53. <keycount>
  54. Multi-key compatibility mode. You can define <keycount> keys and
  55. then sectors are encrypted according to their offsets (sector 0 uses key0;
  56. sector 1 uses key1 etc.). <keycount> must be a power of two.
  57. <iv_offset>
  58. The IV offset is a sector count that is added to the sector number
  59. before creating the IV.
  60. <device path>
  61. This is the device that is going to be used as backend and contains the
  62. encrypted data. You can specify it as a path like /dev/xxx or a device
  63. number <major>:<minor>.
  64. <offset>
  65. Starting sector within the device where the encrypted data begins.
  66. <#opt_params>
  67. Number of optional parameters. If there are no optional parameters,
  68. the optional paramaters section can be skipped or #opt_params can be zero.
  69. Otherwise #opt_params is the number of following arguments.
  70. Example of optional parameters section:
  71. 3 allow_discards same_cpu_crypt submit_from_crypt_cpus
  72. allow_discards
  73. Block discard requests (a.k.a. TRIM) are passed through the crypt device.
  74. The default is to ignore discard requests.
  75. WARNING: Assess the specific security risks carefully before enabling this
  76. option. For example, allowing discards on encrypted devices may lead to
  77. the leak of information about the ciphertext device (filesystem type,
  78. used space etc.) if the discarded blocks can be located easily on the
  79. device later.
  80. same_cpu_crypt
  81. Perform encryption using the same cpu that IO was submitted on.
  82. The default is to use an unbound workqueue so that encryption work
  83. is automatically balanced between available CPUs.
  84. submit_from_crypt_cpus
  85. Disable offloading writes to a separate thread after encryption.
  86. There are some situations where offloading write bios from the
  87. encryption threads to a single thread degrades performance
  88. significantly. The default is to offload write bios to the same
  89. thread because it benefits CFQ to have writes submitted using the
  90. same context.
  91. no_read_workqueue
  92. Bypass dm-crypt internal workqueue and process read requests synchronously.
  93. no_write_workqueue
  94. Bypass dm-crypt internal workqueue and process write requests synchronously.
  95. This option is automatically enabled for host-managed zoned block devices
  96. (e.g. host-managed SMR hard-disks).
  97. integrity:<bytes>:<type>
  98. The device requires additional <bytes> metadata per-sector stored
  99. in per-bio integrity structure. This metadata must by provided
  100. by underlying dm-integrity target.
  101. The <type> can be "none" if metadata is used only for persistent IV.
  102. For Authenticated Encryption with Additional Data (AEAD)
  103. the <type> is "aead". An AEAD mode additionally calculates and verifies
  104. integrity for the encrypted device. The additional space is then
  105. used for storing authentication tag (and persistent IV if needed).
  106. sector_size:<bytes>
  107. Use <bytes> as the encryption unit instead of 512 bytes sectors.
  108. This option can be in range 512 - 4096 bytes and must be power of two.
  109. Virtual device will announce this size as a minimal IO and logical sector.
  110. iv_large_sectors
  111. IV generators will use sector number counted in <sector_size> units
  112. instead of default 512 bytes sectors.
  113. For example, if <sector_size> is 4096 bytes, plain64 IV for the second
  114. sector will be 8 (without flag) and 1 if iv_large_sectors is present.
  115. The <iv_offset> must be multiple of <sector_size> (in 512 bytes units)
  116. if this flag is specified.
  117. Example scripts
  118. ===============
  119. LUKS (Linux Unified Key Setup) is now the preferred way to set up disk
  120. encryption with dm-crypt using the 'cryptsetup' utility, see
  121. https://gitlab.com/cryptsetup/cryptsetup
  122. ::
  123. #!/bin/sh
  124. # Create a crypt device using dmsetup
  125. dmsetup create crypt1 --table "0 `blockdev --getsz $1` crypt aes-cbc-essiv:sha256 babebabebabebabebabebabebabebabe 0 $1 0"
  126. ::
  127. #!/bin/sh
  128. # Create a crypt device using dmsetup when encryption key is stored in keyring service
  129. dmsetup create crypt2 --table "0 `blockdev --getsize $1` crypt aes-cbc-essiv:sha256 :32:logon:my_prefix:my_key 0 $1 0"
  130. ::
  131. #!/bin/sh
  132. # Create a crypt device using cryptsetup and LUKS header with default cipher
  133. cryptsetup luksFormat $1
  134. cryptsetup luksOpen $1 crypt1