← Documents Documentation/admin-guide/device-mapper/dm-crypt.rst GitHub 원문 ↗

Linux 6.18.37 · Administration / Device Mapper

dm-crypt target

Kernel crypto API로 block device를 투명하게 암호화하는 dm-crypt의 cipher·IV·keyring·integrity·sector·workqueue option과 LUKS 예제입니다.

Source pathDocumentation/admin-guide/device-mapper/dm-crypt.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

Cipher와 key 형식

dm-crypt.rst:1-92

Target parameter, 일반·Crypto API cipher specification, IV와 kernel keyring key 형식을 정리합니다.

성능·integrity option

dm-crypt.rst:93-188

Discard 보안, CPU/workqueue, AEAD metadata, sector-size IV와 request split 설정을 설명합니다.

dmsetup과 LUKS

dm-crypt.rst:189-212

Hex key, keyring key를 사용한 dmsetup table과 권장 cryptsetup LUKS 절차를 제공합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 ========
2 dm-crypt
3 ========
4
5 Device-Mapper's "crypt" target provides transparent encryption of block devices
6 using the kernel crypto API.
7
8 For a more detailed description of supported parameters see:
9 https://gitlab.com/cryptsetup/cryptsetup/wikis/DMCrypt
10
11 Parameters::
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
101 allow_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
111 same_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
116 high_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
121 submit_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
129 no_read_workqueue
130 Bypass dm-crypt internal workqueue and process read requests synchronously.
131
132 no_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
137 integrity:<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
149 integrity_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
154 sector_size:<bytes>
155 Use <bytes> as the encryption unit instead of 512 bytes sectors.
156 This option can be in range 512 - 4096 bytes and must be power of two.
157 Virtual device will announce this size as a minimal IO and logical sector.
158
159 iv_large_sectors
160 IV generators will use sector number counted in <sector_size> units
161 instead of default 512 bytes sectors.
162
163 For example, if <sector_size> is 4096 bytes, plain64 IV for the second
164 sector will be 8 (without flag) and 1 if iv_large_sectors is present.
165 The <iv_offset> must be multiple of <sector_size> (in 512 bytes units)
166 if this flag is specified.
167
168 integrity_key_size:<bytes>
169 Use an integrity key of <bytes> size instead of using an integrity key size
170 of the digest size of the used HMAC algorithm.
171
172
173 Module parameters::
174 max_read_size
175 Maximum size of read requests. When a request larger than this size
176 is received, dm-crypt will split the request. The splitting improves
177 concurrency (the split requests could be encrypted in parallel by multiple
178 cores), but it also causes overhead. The user should tune this parameters to
179 fit the actual workload.
180
181 max_write_size
182 Maximum size of write requests. When a request larger than this size
183 is received, dm-crypt will split the request. The splitting improves
184 concurrency (the split requests could be encrypted in parallel by multiple
185 cores), but it also causes overhead. The user should tune this parameters to
186 fit the actual workload.
187
188
189 Example scripts
190 ===============
191 LUKS (Linux Unified Key Setup) is now the preferred way to set up disk
192 encryption with dm-crypt using the 'cryptsetup' utility, see
193 https://gitlab.com/cryptsetup/cryptsetup
194
195 ::
196
197 #!/bin/sh
198 # Create a crypt device using dmsetup
199 dmsetup create crypt1 --table "0 `blockdev --getsz $1` crypt aes-cbc-essiv:sha256 babebabebabebabebabebabebabebabe 0 $1 0"
200
201 ::
202
203 #!/bin/sh
204 # Create a crypt device using dmsetup when encryption key is stored in keyring service
205 dmsetup create crypt2 --table "0 `blockdev --getsize $1` crypt aes-cbc-essiv:sha256 :32:logon:my_prefix:my_key 0 $1 0"
206
207 ::
208
209 #!/bin/sh
210 # Create a crypt device using cryptsetup and LUKS header with default cipher
211 cryptsetup luksFormat $1
212 cryptsetup luksOpen $1 crypt1
213

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Transparent block-device encryption

1-15

Device-Mapper의 `crypt` target은 kernel crypto API를 사용해 block device를 투명하게 암호화합니다.

지원 parameter의 더 자세한 설명은 `https://gitlab.com/cryptsetup/cryptsetup/wikis/DMCrypt`에서 볼 수 있습니다.

Target parameter의 기본 형식은 다음과 같습니다.

	      <cipher> <key> <iv_offset> <device path> \
	      <offset> [<#opt_params> <opt_params>]
dm-crypt I/O 경로
Filesystem or applicationdm-crypt virtual deviceKernel crypto APIEncrypted backend device

Virtual crypt device가 block I/O와 backend의 encrypted data 사이에서 변환합니다.

Cipher와 IV generator 형식

16-50

`<cipher>`는 encryption cipher, encryption mode와 Initial Vector(IV) generator를 지정합니다. 일반 cipher specification 형식은 다음과 같습니다.

       cipher[:keycount]-chainmode-ivmode[:ivopts]

일반 형식의 예는 다음과 같습니다.

       aes-cbc-essiv:sha256
       aes-xts-plain64
       serpent-xts-plain64

`capi:` prefix를 사용하면 kernel crypt API 형식으로 cipher를 직접 지정할 수도 있습니다. IV specification은 첫 형식과 같고, 이 형식은 주로 authenticated mode를 지정할 때 사용합니다.

        capi:cipher_api_spec-ivmode[:ivopts]

Crypto API cipher specification의 예는 다음과 같습니다.

        capi:cbc(aes)-essiv:sha256
        capi:xts(aes)-plain64

Authenticated mode의 예는 다음과 같습니다.

        capi:gcm(aes)-random
        capi:authenc(hmac(sha256),xts(aes))-random
        capi:rfc7539(chacha20,poly1305)-random

현재 load된 crypto mode 목록은 `/proc/crypto`에서 확인할 수 있습니다.

Cipher specification 형식
형식형태용도
일반`cipher[:keycount]-chainmode-ivmode[:ivopts]`CBC, XTS 등 일반 mode
Crypto API`capi:cipher_api_spec-ivmode[:ivopts]`Authenticated mode와 API algorithm 직접 지정

일반 dm-crypt 이름과 kernel crypto API 직접 지정 방식을 비교합니다.

Authenticated cipher 예
Specification구성
`capi:gcm(aes)-random`AES-GCM + random IV
`capi:authenc(hmac(sha256),xts(aes))-random`HMAC-SHA256 + AES-XTS + random IV
`capi:rfc7539(chacha20,poly1305)-random`ChaCha20-Poly1305 + random IV

Cipher, authenticator와 IV mode 조합을 그대로 지정합니다.

Keyring key와 multi-key mode

51-92

`<key>`는 encryption에 사용할 key입니다. Hexadecimal number로 encode하거나, kernel keyring service에 있는 key는 single colon(`:`)을 앞에 붙인 `<key_string>`으로 전달합니다.

선택한 cipher와 IV mode 조합에 유효한 key size만 사용할 수 있습니다. 일부 IV mode에서는 key string에 IV seed 같은 추가 key가 들어가 여러 부분을 하나의 문자열로 연결할 수 있습니다.

Kernel keyring key는 `<key_size>:<key_type>:<key_description>` 형식의 문자열로 식별합니다.

Kernel keyring key string
Field설명
`key_size`Byte 단위 encryption key 크기; kernel key payload 크기와 정확히 일치해야 함
`key_type``logon`, `user`, `encrypted`, `trusted` 중 하나
`key_description`crypt target이 해당 key type을 load할 때 찾을 keyring description

Key payload와 lookup 정보를 한 문자열로 지정합니다.

`<keycount>`는 multi-key compatibility mode입니다. 지정한 수만큼 key를 정의하고 sector offset에 따라 key를 순환해 사용합니다. Sector 0은 key0, sector 1은 key1을 사용합니다. `keycount`는 2의 거듭제곱이어야 합니다.

`<iv_offset>`은 IV를 만들기 전에 sector number에 더하는 sector count입니다. `<device path>`는 encrypted data를 보관할 backend로 `/dev/xxx` path 또는 `<major>:<minor>` device number를 쓸 수 있습니다. `<offset>`은 encrypted data가 시작되는 device 내부 sector입니다.

Multi-key sector 선택
Sector numberApply keycount maskSelect key0, key1, ...Add iv_offsetGenerate IV and encrypt

Sector offset에 따라 key를 순환 선택하며 keycount는 power of two입니다.

Optional performance와 discard parameter

93-136

`<#opt_params>`는 optional parameter 수입니다. Parameter가 없으면 이 구간을 생략하거나 0으로 지정합니다. 그 외에는 뒤따르는 argument 수를 적습니다.

Optional parameter 구간의 예는 다음과 같습니다.

        3 allow_discards same_cpu_crypt submit_from_crypt_cpus
dm-crypt optional parameter
Option동작
`allow_discards`Block discard(TRIM)를 crypt device 아래로 전달; 기본값은 무시
`same_cpu_crypt`I/O가 submit된 같은 CPU에서 encryption 수행; 기본값은 unbound workqueue로 CPU 간 균형
`high_priority`dm-crypt workqueue와 writer thread를 high priority로 설정; throughput/latency 개선 대신 system responsiveness 저하
`submit_from_crypt_cpus`Encryption 뒤 별도 thread로 write를 offload하지 않음
`no_read_workqueue`내부 workqueue를 우회해 read를 synchronous 처리
`no_write_workqueue`내부 workqueue를 우회해 write를 synchronous 처리; host-managed zoned block device에서 자동 활성화

Discard 전달과 crypto/write execution context를 조정합니다.

`allow_discards`를 활성화하기 전에 구체적인 보안 위험을 신중히 평가해야 합니다. Encrypted device에서 discard를 허용하면 나중에 discarded block 위치를 쉽게 알아낼 수 있을 때 filesystem type, used space 같은 ciphertext device 정보가 누출될 수 있습니다.

기본적으로 write bio는 encryption thread에서 같은 context의 단일 thread로 offload합니다. 이는 동일 context에서 write를 submit하는 것이 CFQ에 유리하기 때문입니다. 하지만 일부 상황에서는 단일 thread로 offload하는 동작이 성능을 크게 떨어뜨려 `submit_from_crypt_cpus`가 유용합니다.

`no_write_workqueue`는 host-managed SMR hard disk 같은 host-managed zoned block device에서 자동으로 활성화됩니다.

allow_discards 보안 경계
Filesystem issues discarddm-crypt passes TRIMBackend locations become observableFilesystem type or used-space pattern may leak

TRIM 전달은 storage 효율을 높이지만 encrypted layout 정보를 드러낼 수 있습니다.

Integrity metadata와 encryption sector

137-171

`integrity:<bytes>:<type>`은 device가 sector마다 추가 `<bytes>` metadata를 per-bio integrity structure에 요구함을 나타냅니다. 이 metadata는 아래의 dm-integrity target이 제공해야 합니다.

Metadata를 persistent IV 용도로만 사용하면 `<type>`을 `none`으로 지정할 수 있습니다. Authenticated Encryption with Additional Data(AEAD)에서는 `<type>`이 `aead`입니다. AEAD mode는 encrypted device의 integrity도 계산·검증하고 추가 공간에 authentication tag와 필요하면 persistent IV를 저장합니다.

`integrity_key_size:<bytes>`로 integrity key 크기가 digest size와 다를 때 값을 지정할 수 있습니다. Cryptographic key size와 독립된 key size를 갖는 wrapped key algorithm을 사용할 수 있게 합니다. 아래에서 이 option은 사용한 HMAC algorithm의 digest size 대신 지정 byte 크기의 integrity key를 쓴다는 의미로 다시 설명됩니다.

`sector_size:<bytes>`는 기본 512-byte sector 대신 지정 byte를 encryption unit으로 사용합니다. 범위는 512-4096 byte이고 2의 거듭제곱이어야 합니다. Virtual device는 이 값을 minimal I/O와 logical sector size로 알립니다.

`iv_large_sectors`를 지정하면 IV generator가 기본 512-byte sector가 아니라 `<sector_size>` 단위로 센 sector number를 사용합니다. 예를 들어 `sector_size`가 4096 byte이면 두 번째 sector의 plain64 IV는 flag가 없을 때 8이고 `iv_large_sectors`가 있으면 1입니다.

`iv_large_sectors`를 사용할 때 `<iv_offset>`은 512-byte 단위로 표현한 `<sector_size>`의 배수여야 합니다.

Integrity와 sector option
Option의미
`integrity:<bytes>:none`dm-integrity가 제공하는 metadata를 persistent IV에만 사용
`integrity:<bytes>:aead`Authentication tag, integrity 검증과 persistent IV에 사용
`integrity_key_size:<bytes>`Digest size와 다른 integrity/HMAC key 크기 지정
`sector_size:<bytes>`512-4096 byte의 power-of-two encryption unit
`iv_large_sectors`IV sector number를 sector_size 단위로 계산

Per-sector metadata, key 크기와 encryption unit을 지정합니다.

4096-byte sector의 plain64 IV
설정두 번째 sector IV
기본 512-byte counting8
`iv_large_sectors`1

두 번째 4096-byte sector는 512-byte 단위로는 index 8, large-sector 단위로는 index 1입니다.

Read/write request split 크기

172-188
dm-crypt module parameter
Parameter동작절충
`max_read_size`이 값보다 큰 read request를 splitConcurrency 향상, split overhead 증가
`max_write_size`이 값보다 큰 write request를 splitConcurrency 향상, split overhead 증가
undefinedundefined

큰 request를 나눠 여러 core에서 병렬 encryption할 수 있습니다.

dmsetup, keyring과 LUKS 예제

189-212

현재 dm-crypt disk encryption 설정에는 `cryptsetup` utility와 LUKS(Linux Unified Key Setup)를 사용하는 방법이 권장됩니다. 자세한 내용은 `https://gitlab.com/cryptsetup/cryptsetup`을 참고합니다.

첫 script는 hexadecimal key와 `aes-cbc-essiv:sha256`을 사용해 dmsetup으로 `crypt1` device를 만듭니다.

	#!/bin/sh
	# Create a crypt device using dmsetup
	dmsetup create crypt1 --table "0 `blockdev --getsz $1` crypt aes-cbc-essiv:sha256 babebabebabebabebabebabebabebabe 0 $1 0"

두 번째 script는 kernel keyring service에 저장된 32-byte `logon` key `my_prefix:my_key`를 사용해 `crypt2` device를 만듭니다.

	#!/bin/sh
	# Create a crypt device using dmsetup when encryption key is stored in keyring service
	dmsetup create crypt2 --table "0 `blockdev --getsize $1` crypt aes-cbc-essiv:sha256 :32:logon:my_prefix:my_key 0 $1 0"

세 번째 script는 cryptsetup으로 기본 cipher를 사용하는 LUKS header를 만들고 이를 `crypt1` 이름으로 엽니다.

	#!/bin/sh
	# Create a crypt device using cryptsetup and LUKS header with default cipher
	cryptsetup luksFormat $1
	cryptsetup luksOpen $1 crypt1
권장 LUKS 설정
Block devicecryptsetup luksFormatLUKS header initializedcryptsetup luksOpen/dev/mapper/crypt1

직접 dmsetup table을 구성할 수도 있지만 일반 disk encryption은 cryptsetup과 LUKS를 사용합니다.