Linux Unified Key Setup

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

The Linux Unified Key Setup (LUKS) is a disk encryption specification created by Clemens Fruhwirth in 2004 and was originally intended for Linux.

While most disk encryption software implements different, incompatible, and undocumented formats[citation needed], LUKS implements a platform-independent standard on-disk format for use in various tools. This not only facilitates compatibility and interoperability among different programs, but also assures that they all implement password management in a secure and documented manner.[1]

Description[edit]

LUKS is used to encrypt a block device. The contents of the encrypted device are arbitrary, and therefore any filesystem can be encrypted, including swap partitions.[2] There is an unencrypted header at the beginning of an encrypted volume, which allows up to 8 (LUKS1) or 32 (LUKS2) encryption keys to be stored along with encryption parameters such as cipher type and key size.[3][4]

The presence of this header is a major difference between LUKS and plain dm-crypt, since the header allows multiple different passphrases to be used, with the ability to change and remove them with ease. However, if the header is lost or corrupted, the device will no longer be decryptable.[5]

Encryption is done with a multi-layer approach. First, the block device is encrypted using multiple master keys, each of which is encrypted with an active user key in each keyslot.[6] While keyslots often contain a passphrase, other kinds of keys include OpenPGP public keys or X.509 certificates. PGP public keys can be used in combination with an OpenPGP smart card which is inserted into the host.[7][8] This layered scheme is known as TKS1.[9]

There are two versions of LUKS, with LUKS2 having features such as resilience to header corruption, and using the Argon2 encryption algorithm by default, whereas LUKS1 uses PBKDF2.[10] Conversion between both versions of LUKS is possible in certain situations, but some features may not be available with LUKS1 such as Argon2.[3] LUKS2 uses JSON as a metadata format.[3][11]

Available cryptographic algorithms depends on individual kernel support of the host. Libgcrypt can be used as a backend for hashing, which supports all of its algorithms.[12] It is up to the operating system vendor to choose the default algorithm.[13] LUKS1 makes use of an anti-forensics technique called AFsplitter, allowing for secure data erasure and protection.[14]

Using LUKS with LVM[edit]

Logical Volume Management can be used alongside LUKS.[15]

LVM on LUKS
When LVM is used on an unlocked LUKS container, all underlying partitions (which are LVM logical volumes) can be encrypted with a single key. This is akin to splitting a LUKS container into multiple partitions. The LVM structure is not visible until the disk is decrypted.[16]
LUKS on LVM
When LUKS is used to encrypt LVM logical volumes, an encrypted volume can span multiple devices. The underlying LVM volume group is visible without decrypting the encrypted volumes.[17]

Full disk encryption[edit]

Debian-Installer showing an option for automated partitioning with LVM on LUKS

A common usage of LUKS is to provide full disk encryption, which involves encrypting the root partition of an operating system installation, which protects the operating system files from being tampered with or read by unauthorized parties.[15]

On a Linux system, the boot partition (/boot) may be encrypted if the bootloader itself supports LUKS (e.g. GRUB). This is undertaken to prevent tampering of the Linux kernel. However, the first stage bootloader or an EFI system partition cannot be encrypted (see Full disk encryption#The boot key problem).[15]

On mobile Linux systems, postmarketOS has developed osk-sdl to allow a full disk encrypted system to be unlocked using a touch screen.

Encrypted home directories[edit]

On systems running systemd, the systemd-homed component can be used to encrypt individual home directories.[18]

Operating system support[edit]

The reference implementation for LUKS operates on Linux and is based on an enhanced version of cryptsetup, using dm-crypt as the disk encryption backend. Under Microsoft Windows, LUKS-encrypted disks can be used via the Windows Subsystem for Linux.[19] (Formerly, this was possible with LibreCrypt,[20] which currently has fundamental security holes, and which succeeded FreeOTFE, formerly DoxBox.)

DragonFly BSD supports LUKS.[21]

Installer support[edit]

Several Linux distributions allow the root device to be encrypted upon OS installation. These installers include Calamares,[22] Ubiquity,[23] Debian-Installer,[24] and more.

On-disk format[edit]

LUKS headers are forward compatible; newer versions of LUKS should be able to read headers of previous versions.[25]

LUKS1[edit]

LUKS1 Header[25]
Offset Data type Description
000 000hex char[6] Magic number {'L', 'U', 'K', 'S', 0xBA, 0xBE }
006 006hex uint16_t LUKS Version (0x0001 for LUKS1)
008 008hex char[32] Cipher Algorithm (e.g. "twofish", "aes")
040 028hex char[32] Cipher mode (e.g. "cbc-essiv:sha256")
072 048hex char[32] Cryptographic hash function (e.g. "sha1", "ripemd160")
104 068hex uint32_t Payload offset (position of encrypted data) in 512 byte offsets
108 06Chex uint32_t Number of key bytes
112 070hex char[20] PBKDF2 master key checksum
132 084hex char[32] PBKDF2 master key salt parameter
164 0A4hex uint32_t PBKDF2 master key iterations (Default: 10)
168 0A8hex char[40] UUID of the partition (e.g. "504c9fa7-d080-4acf-a829-73227b48fb89")
208 0D0hex (48 Bytes) Keyslot 1
544 220hex (48 Bytes) Keyslot 8
592 Bytes total
Format of each keyslot
Offset Data type Description
00 uint32_t State of keyslot: Active=0x00AC71F3; Disabled=0x0000DEAD
04 uint32_t PBKDF2 iteration parameter
08 char[32] PBKDF2 salt parameter
40 uint32_t Start sector of key
44 uint32_t Number of anti-forensic stripes (Default: 4000)
48 Bytes total

LUKS2[edit]

LUKS2 devices begin with a binary header intended to allow recognition and fast detection by blkid, which also contains information such as checksums. All strings used in a LUKS2 header are null-terminated strings. Directly after the binary header comes the JSON area, containing the objects config (configuration), keyslots, digests, segments (describes encrypted areas on the disk), and tokens containing extra metadata.[11]

The binary format for regular luks2 keyslots are mostly similar to their predecessor, with the addition of different per-keyslot algorithms. Another type of key exists to allow redundancy in the case that a re-encryption process is interrupted.[11]

Examples[edit]

Cryptsetup is the reference implementation of the LUKS frontend.

To encrypt a device with the path /dev/sda1:

# cryptsetup luksFormat /dev/sda1

To unlock an encrypted device, where name is the mapped device name:

# cryptsetup luksOpen /dev/sda1 name

Re-encrypting[edit]

Re-encrypting a LUKS container can be done either with the cryptsetup tool itself, or with a legacy tool called cryptsetup-reencrypt. These tools can also be used to add encryption to an existing unencrypted filesystem, or remove encryption from a block device.[12][26]

Both methods have similar syntax:

# cryptsetup reencrypt /dev/sda1
# cryptsetup-reencrypt /dev/sda1

See also[edit]

References[edit]

  1. ^ Fruhwirth, Clemens (2018-01-20). "LUKS On-Disk Format Specification Version 1.2.3" (PDF). Retrieved 2021-09-23.
  2. ^ "Encrypting drives using LUKS". Fedora Docs. Retrieved 6 May 2022.
  3. ^ a b c "Chapter 12. Encrypting block devices using LUKS". Red Hat Customer Portal.
  4. ^ "How to Encrypt Hard Disk (partition) using LUKS in Linux".
  5. ^ "How to Encrypt Your Data with dm-crypt". Linode.
  6. ^ Bossi, Simone; Visconti, Andrea (2015). "What Users Should Know About Full Disk Encryption Based on LUKS" (PDF). {{cite journal}}: Cite journal requires |journal= (help)
  7. ^ "Full-Disk Encryption With cryptsetup/LUKS". Retrieved 6 May 2022.
  8. ^ "How to encrypt a LUKS container using a smart card or token".
  9. ^ Fruhwirth, Clemens (2004-07-15). "TKS1 – An anti-forensic, two level, and iterated key setup scheme" (PDF). Draft. Retrieved 2021-09-23.
  10. ^ "How LUKS works with Full Disk Encryption in Linux".
  11. ^ a b c "on-disk-format-luks2.pdf" (PDF).
  12. ^ a b cryptsetup(8) – Linux Administration and Privileged Commands Manual
  13. ^ "Breaking LUKS Encryption". eForensics.
  14. ^ "AFsplitter".
  15. ^ a b c "dm-crypt/Encrypting an entire system". Retrieved 6 May 2022.
  16. ^ "Arch with LVM on LUKS".
  17. ^ "LUKS on LVM: encrypted logical volumes and secure backups".
  18. ^ "Home Directories". systemd.
  19. ^ "Servicing the Windows Subsystem for Linux (WSL) 2 Linux Kernel". Microsoft Developer Blogs.
  20. ^ "LibreCrypt". GitHub.
  21. ^ "DragonFly's Major Features List". Retrieved 6 May 2022.
  22. ^ Michael Larabel (8 May 2016). "Calamares Installer Adds LUKS Encryption Support". Phoronix.
  23. ^ "How to Encrypt Your Hard Disk in Ubuntu". Make Tech Easier.
  24. ^ "PartmanCrypto". Debian Wiki. Retrieved 6 May 2022.
  25. ^ a b "LUKS On-Disk Format Specification" (PDF).
  26. ^ cryptsetup-reencrypt(8) – Linux Administration and Privileged Commands Manual

External links[edit]