Re: Slow unlock of the LUKS device at boot

Ondrej Kozina <[email protected]>
Newsgroups dev.linux.lists.cryptsetup
Message-ID <[email protected]>
On 29. 11. 22 20:50, Lamy Geier wrote:
> My boot partition (/dev/nvme0n1p1) is using LUKS1. And another partition
> (/dev/nvme0n1p5) is using LUKS2 which has LVM with root volume,  home
> volume and swap volumes. Both of these have same passphrase.
> 
> I am using Grub. While booting I enter the passphrase to unlock the boot
> partition. To automatically unlock the partition with LVM volumes, I
> have created a keyfile (boot_os.keyfile) which is stored in the device
> itself, which is used to unlock it. I have created it as follows:
> 
> ```bash
> # echo "KEYFILE_PATTERN=/etc/luks/*.keyfile" >>
> /etc/cryptsetup-initramfs/conf-hook
> # echo "UMASK=0077" >> /etc/initramfs-tools/initramfs.conf
> ```
> 
> - Create a randomised key-file of 4096 bits (512 bytes), secure it, and
> add it to the LUKS volumes (Man-pages for dd chmod):
> 
> ```bash
> # mkdir /etc/luks
> # dd if=/dev/urandom of=/etc/luks/boot_os.keyfile bs=512 count=1
> 1+0 records in u=rx,go-rwx /etc/luks
> 1+0 records out
> 512 bytes (0.5 kB, 0.5 KiB) copied, 0.0002368 s, 17.3 MB/s
> 
> # chmod u=rx,go-rwx /etc/luks
> # chmod u=r,go-rwx /etc/luks/boot_os.keyfile
> 
> # cryptsetup luksAddKey /dev/nvme0n1p1 /etc/luks/boot_os.keyfile
> Enter any existing passphrase:
> 
> # cryptsetup luksAddKey /dev/nvme0n1p5 /etc/luks/boot_os.keyfile
> Enter any existing passphrase:
> ```
> 
> Add the keys to the crypttab:
> 
> ```bash
> # echo "LUKS_BOOT UUID=$(blkid -s UUID -o value ${DEVP}1)
> /etc/luks/boot_os.keyfile luks,discard" >> /etc/crypttab
> # echo "${DM}5_crypt UUID=$(blkid -s UUID -o value ${DEVP}5)
> /etc/luks/boot_os.keyfile luks,discard" >> /etc/crypttab
> ```
> 
> The above is taken from: [Full_Disk_Encryption_Howto_2019 - Community
> Help
> Wiki](https://help.ubuntu.com/community/Full_Disk_Encryption_Howto_2019#Post-Installation_Steps)
> 
> ---
> 
> # Issue
> 
> The boot partition unlocks very quickly (5 seconds) but the LVM volume
> takes about 6 minutes to unlock.
> 
> Following are the key dump of both these partitions. With the keyslot 0
> in both being the same passphrase, and keyslot 1 being the key file:
> 
> ```
> $ sudo cryptsetup luksDump /dev/nvme0n1p1
> Place your right index finger on the fingerprint reader
> LUKS header information for /dev/nvme0n1p1
> 
> Version:        1
> Cipher name:    aes
> Cipher mode:    xts-plain64
> Hash spec:      sha256
> Payload offset: 4096
> MK bits:        512
> MK digest:      ec 22 27 de c1 ef 40 0f a5 cf 37 d3 96 5c d5 b2 6e c8 dd 90
> MK salt:        62 1a 05 81 ba 60 3b 0d b1 8a 9f f0 04 98 27 54
>                   06 b6 8d 72 53 23 09 47 ea 5f 80 1d d7 c5 ca 50
> MK iterations:  305173
> UUID:           586de9a0-14c7-40d7-b721-7fdba2e3b184
> 
> Key Slot 0: ENABLED
>           Iterations:             1000
>           Salt:                   4b f1 99 85 84 a5 00 d6 a4 e8 e1 07 35
> b4 da a1
>                                   fc 97 59 5f 4c f8 e1 9b 49 71 29 af e5
> 56 b1 19
>           Key material offset:    8
>           AF stripes:             4000
> Key Slot 1: ENABLED
>           Iterations:             4848906
>           Salt:                   91 70 85 49 f3 31 e8 53 1f 39 aa 6d 7a
> 3e 84 de
>                                   e4 3f bd 3d 65 bf f6 b1 e6 8c 15 fa 34
> b9 e3 e0
>           Key material offset:    512
>           AF stripes:             4000
> ```
> 
> ```
> $ sudo cryptsetup luksDump /dev/nvme0n1p5
> LUKS header information
> Version:        2
> Epoch:          10
> Metadata area:  16384 [bytes]
> Keyslots area:  16744448 [bytes]
> UUID:           ee8854e8-54f6-4f7b-b326-02fdee357d0e
> Label:          (no label)
> Subsystem:      (no subsystem)
> Flags:          (no flags)
> 
> Data segments:
>     0: crypt
>           offset: 16777216 [bytes]
>           length: (whole device)
>           cipher: aes-xts-plain64
>           sector: 512 [bytes]
> 
> Keyslots:
>     0: luks2
>           Key:        512 bits
>           Priority:   normal
>           Cipher:     aes-xts-plain64
>           Cipher key: 512 bits
>           PBKDF:      argon2id
>           Time cost:  1000
                         ^^^^
This is insane value for argon2 and it would explain your 6 minutes 
unlock time. Usually on my 2 years old laptop I get values in range 6-9 
iterations (Time cost) with 4 threads and 1GiB ram used when I let 
cryptsetup do the benchmark with default target time ~2 seconds. Are you 
sure you did not add --pbkdf-force-iterations parameter in your 
luksAddKey command earlier?

With regards
O.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.