imageNice blog https://wiki.archlinux.org/title/Data-at-rest_encryption

Ways of Encryption

image


All data-at-rest encryption methods operate in such a way that even though the disk actually holds encrypted data, the operating system and applications “see” it as the corresponding normal readable data as long as the cryptographic container (i.e. the logical part of the disk that holds the encrypted data) has been “unlocked” and mounted. Ref: https://wiki.archlinux.org/title/Data-at-rest_encryption

For this to happen, some “secret information” (usually in the form of a keyfile and/or passphrase) needs to be supplied by the user, from which the actual encryption key can be derived (and stored in the kernel keyring for the duration of the session).

image

image

Device Mapper - Framework provided by the Linux Kernel, used to map physical block devices to higher level virtual block devices

DM-Crypt - A target used with device mapper that provides transparent encryption. Allows us to create a virtual block device and have all data be encrypted on the fly before being committed to disk and can decrypt in the same way for reads.

LUKS - Linux Unified Key Setup Provides an efficient user-friendly way to store and manage keys. Without LUKS, DM-Crypt can be more cumbersome and error-prone.

image

Device Mapper

The device mapper is a framework provided by the Linux kernel for mapping physical block devices onto higher-level virtual block devices.

It forms the foundation of the logical volume manager (LVM), software RAIDs and dm-crypt disk encryption, and offers additional features such as file system snapshots.

image

dm-crypt

dm-crypt is the Linux kernel’s device mapper(dm) crypto target. A transparent disk encryption subsystem in the Linux kernel. It is implemented as a device mapper target and may be stacked on top of other device mapper transformations.

dm-crypt is a transparent disk encryption subsystem. That being said, it’s better suited to encrypt disks and partitions. It can encrypt files, but they have to be mapped as devices for this to work. You can still encrypt files by using loop devices, cryptsetup will even automatically create those loop devices as needed. https://unix.stackexchange.com/questions/275707/how-can-i-encrypt-a-file-with-dm-crypt

Ref: https://wiki.gentoo.org/wiki/Custom_Initramfs#Encrypted_keyfile

If you want to encrypt only one file, GnuPG could be a better tool. Example: gpg -c filename

image

https://gitlab.com/cryptsetup/cryptsetup

When you unlock an encrypted volume, cryptsetup creates a new device mapping that applications can access like any regular storage device. The actual encryption and decryption work is performed transparently by the kernel’s device-mapper dm-crypt driver.

image

image

Raw DM-Crypt requires manual key management. You have to handle key derivation, storage, and potential header formats yourself, which is prone to errors like weak key generation or incompatibility across systems.

Linux Unified Key Setup (LUKS)

LUKS builds on DM-Crypt by standardizing the on-disk format for encrypted volumes, focusing on key management. It’s essentially a header format that stores metadata (like encryption parameters and key slots) at the beginning of the block device.

LUKS is the standard on-disk format for disk encryption on Linux systems, based on the dm-crypt kernel module.

LUKS, the Linux Unified Key Setup, is a standard for disk encryption.

Demo

image

cryptsetup --verbose --cipher aes-xts-plain64 --key-size 512 --iter-time=4000 --hash sha512 --key-file=pw.txt luksFormat /dev/sdc
time cryptsetup open --type luks /dev/sdc cryptdemo --key-file=pw.txt

image

luksDump Dumps the LUKS header information from the physical device. This works even if the volume is locked. It shows you the configuration (cipher, hash, etc.) and information about the key slots.

cryptsetup luksDump /dev/sdc

image

Storing data on unencrypted and encrypted volumes image

Trusted Platform Module (TPM)

image

In Linux, a TPM is a hardware chip on your computer’s motherboard that acts as a secure cryptoprocessor to store cryptographic keys, perform cryptographic operations, and ensure the integrity of the system’s boot process.

Linux systems use TPMs for key management, device authentication, and to bind secrets, like disk encryption keys, to the system’s secure state through Platform Configuration Registers (PCRs).

The TPM specification is an operating system agnostic, international standard (from the Trusted Computing Group and International Standards Organization) for a secure cryptoprocessor, which is a dedicated microprocessor designed to secure hardware by integrating cryptographic keys into devices.