15256a62fSLinlin Zhang============== 25256a62fSLinlin Zhangdm-inlinecrypt 35256a62fSLinlin Zhang============== 45256a62fSLinlin Zhang 55256a62fSLinlin ZhangDevice-Mapper's "inlinecrypt" target provides transparent encryption of block devices 65256a62fSLinlin Zhangusing the inline encryption hardware. 75256a62fSLinlin Zhang 85256a62fSLinlin ZhangFor a more detailed description of inline encryption, see: 95256a62fSLinlin Zhanghttps://docs.kernel.org/block/inline-encryption.html 105256a62fSLinlin Zhang 115256a62fSLinlin ZhangParameters:: 125256a62fSLinlin Zhang 135256a62fSLinlin Zhang <cipher> <key> <iv_offset> <device path> \ 145256a62fSLinlin Zhang <offset> [<#opt_params> <opt_params>] 155256a62fSLinlin Zhang 165256a62fSLinlin Zhang<cipher> 175256a62fSLinlin Zhang Encryption cipher type. 185256a62fSLinlin Zhang 195256a62fSLinlin Zhang The cipher specifications format is:: 205256a62fSLinlin Zhang 215256a62fSLinlin Zhang cipher 225256a62fSLinlin Zhang 235256a62fSLinlin Zhang Examples:: 245256a62fSLinlin Zhang 255256a62fSLinlin Zhang aes-xts-plain64 265256a62fSLinlin Zhang 275256a62fSLinlin Zhang The cipher type corresponds to the encryption modes supported by 285256a62fSLinlin Zhang inline crypto in the block layer. Currently, only 295256a62fSLinlin Zhang BLK_ENCRYPTION_MODE_AES_256_XTS (i.e. aes-xts-plain64) is supported. 305256a62fSLinlin Zhang 315256a62fSLinlin Zhang<key> 325256a62fSLinlin Zhang Key used for encryption. It is encoded either as a hexadecimal number 335256a62fSLinlin Zhang or it can be passed as <key_string> prefixed with single colon 345256a62fSLinlin Zhang character (':') for keys residing in kernel keyring service. 355256a62fSLinlin Zhang You can only use key sizes that are valid for the selected cipher. 365256a62fSLinlin Zhang Note that the size in bytes of a valid key must be in bellow range. 375256a62fSLinlin Zhang 385256a62fSLinlin Zhang [BLK_CRYPTO_KEY_TYPE_RAW, BLK_CRYPTO_KEY_TYPE_HW_WRAPPED] 395256a62fSLinlin Zhang 405256a62fSLinlin Zhang<key_string> 415256a62fSLinlin Zhang The kernel keyring key is identified by string in following format: 42*f9f57971SLinlin Zhang <key_size>:<keyring_type>:<key_description>. 435256a62fSLinlin Zhang 445256a62fSLinlin Zhang<key_size> 455256a62fSLinlin Zhang The encryption key size in bytes. The kernel key payload size must match 465256a62fSLinlin Zhang the value passed in <key_size>. 475256a62fSLinlin Zhang 48*f9f57971SLinlin Zhang<keyring_type> 49*f9f57971SLinlin Zhang The type of the key inside the kernel keyring. It can be either 'logon', 50*f9f57971SLinlin Zhang or 'trusted' kernel key type. 515256a62fSLinlin Zhang 525256a62fSLinlin Zhang<key_description> 535256a62fSLinlin Zhang The kernel keyring key description inlinecrypt target should look for 54*f9f57971SLinlin Zhang when loading key of <keyring_type>. 555256a62fSLinlin Zhang 565256a62fSLinlin Zhang<iv_offset> 575256a62fSLinlin Zhang The IV offset is a sector count that is added to the sector number 585256a62fSLinlin Zhang before creating the IV. 595256a62fSLinlin Zhang 605256a62fSLinlin Zhang<device path> 615256a62fSLinlin Zhang This is the device that is going to be used as backend and contains the 625256a62fSLinlin Zhang encrypted data. You can specify it as a path like /dev/xxx or a device 635256a62fSLinlin Zhang number <major>:<minor>. 645256a62fSLinlin Zhang 655256a62fSLinlin Zhang<offset> 665256a62fSLinlin Zhang Starting sector within the device where the encrypted data begins. 675256a62fSLinlin Zhang 685256a62fSLinlin Zhang<#opt_params> 695256a62fSLinlin Zhang Number of optional parameters. If there are no optional parameters, 705256a62fSLinlin Zhang the optional parameters section can be skipped or #opt_params can be zero. 715256a62fSLinlin Zhang Otherwise #opt_params is the number of following arguments. 725256a62fSLinlin Zhang 735256a62fSLinlin Zhang Example of optional parameters section: 74*f9f57971SLinlin Zhang keytype:raw allow_discards sector_size:4096 iv_large_sectors 75*f9f57971SLinlin Zhang 76*f9f57971SLinlin Zhang<key_type> 77*f9f57971SLinlin Zhang The type of the key as seen by the block layer, either standard or 78*f9f57971SLinlin Zhang hardware-wrapped. The string is supplied in the table as <keytype:raw> 79*f9f57971SLinlin Zhang or <keytype:hw-wrapped>. 805256a62fSLinlin Zhang 815256a62fSLinlin Zhangallow_discards 825256a62fSLinlin Zhang Block discard requests (a.k.a. TRIM) are passed through the inlinecrypt 835256a62fSLinlin Zhang device. The default is to ignore discard requests. 845256a62fSLinlin Zhang 855256a62fSLinlin Zhang WARNING: Assess the specific security risks carefully before enabling this 865256a62fSLinlin Zhang option. For example, allowing discards on encrypted devices may lead to 875256a62fSLinlin Zhang the leak of information about the ciphertext device (filesystem type, 885256a62fSLinlin Zhang used space etc.) if the discarded blocks can be located easily on the 895256a62fSLinlin Zhang device later. 905256a62fSLinlin Zhang 915256a62fSLinlin Zhangsector_size:<bytes> 925256a62fSLinlin Zhang Use <bytes> as the encryption unit instead of 512 bytes sectors. 935256a62fSLinlin Zhang This option can be in range 512 - 4096 bytes and must be power of two. 945256a62fSLinlin Zhang Virtual device will announce this size as a minimal IO and logical sector. 955256a62fSLinlin Zhang 965256a62fSLinlin Zhangiv_large_sectors 975256a62fSLinlin Zhang Use <sector_size>-based sector numbers for IV generation instead of 985256a62fSLinlin Zhang 512-byte sectors. 995256a62fSLinlin Zhang 1005256a62fSLinlin Zhang For dm-inlinecrypt, this flag must be specified when <sector_size> 1015256a62fSLinlin Zhang is larger than 512 bytes. The legacy 512-byte-based IV behavior is 1025256a62fSLinlin Zhang not supported. 1035256a62fSLinlin Zhang 1045256a62fSLinlin Zhang When specified, if <sector_size> is 4096 bytes, plain64 IV for the 1055256a62fSLinlin Zhang second sector will be 1, and <iv_offset> must be a multiple of 1065256a62fSLinlin Zhang <sector_size> (in 512-byte units). 1075256a62fSLinlin Zhang 1085256a62fSLinlin ZhangExample scripts 1095256a62fSLinlin Zhang=============== 1105256a62fSLinlin ZhangCurrently, dm-inlinecrypt devices must be set up directly using dmsetup. 1115256a62fSLinlin ZhangThere is no userspace support yet to integrate dm-inlinecrypt with LUKS 1125256a62fSLinlin Zhangor cryptsetup. In particular, cryptsetup currently only supports 1135256a62fSLinlin Zhangdm-crypt, and cannot be used to create dm-inlinecrypt mappings. 1145256a62fSLinlin Zhang 1155256a62fSLinlin ZhangThe following examples demonstrate how to create dm-inlinecrypt devices 1165256a62fSLinlin Zhangusing dmsetup 1175256a62fSLinlin Zhang 1185256a62fSLinlin Zhang:: 1195256a62fSLinlin Zhang 1205256a62fSLinlin Zhang #!/bin/sh 1215256a62fSLinlin Zhang # Create a inlinecrypt device using dmsetup 122*f9f57971SLinlin Zhang dmsetup create inlinecrypt1 --table "0 `blockdev --getsz $1` inlinecrypt aes-xts-plain64 babebabebabebabebabebabebabebabebabebabebabebabebabebabebabebabe 0 0 $1 0 1 keytype:raw" 1235256a62fSLinlin Zhang 1245256a62fSLinlin Zhang:: 1255256a62fSLinlin Zhang 1265256a62fSLinlin Zhang #!/bin/sh 1275256a62fSLinlin Zhang # Create a inlinecrypt device using dmsetup when encryption key is stored in keyring service 128*f9f57971SLinlin Zhang dmsetup create inlinecrypt2 --table "0 `blockdev --getsz $1` inlinecrypt aes-xts-plain64 :64:logon:fde:dminlinecrypt_test_key 0 0 $1 0 1 keytype:raw" 1295256a62fSLinlin Zhang 130