3

luks1 has limit of 8. But I just accidentally add 9 slots to luks2 (from 0 to 8). I wonder what is the limit for luks2?

Keyslots:
  0: luks2
        Key:        512 bits
        Priority:   normal
        Cipher:     aes-xts-plain64
        Cipher key: 512 bits
        PBKDF:      argon2i
        Time cost:  5
        Memory:     1048576
        Threads:    4
        Salt:       32 ff 35 1e a2 b5 64 a7 fe f9 6e 7d 12 75 75 d5 
                    a4 e7 47 39 80 96 1d 76 b1 35 b3 77 0a 85 46 ac 
        AF stripes: 4000
        AF hash:    sha256
        Area offset:32768 [bytes]
        Area length:258048 [bytes]
        Digest ID:  0
  1: luks2
        Key:        512 bits
        Priority:   normal
        Cipher:     aes-xts-plain64
        Cipher key: 512 bits
        PBKDF:      argon2i
        Time cost:  5
        Memory:     1048576
        Threads:    4
        Salt:       55 7b 9a 4c d8 53 2b bb 90 af 57 44 67 b5 0c 03 
                    85 a1 5d 70 e4 1e b0 5f 97 1a f3 0e f2 8c dc b2 
        AF stripes: 4000
        AF hash:    sha256
        Area offset:290816 [bytes]
        Area length:258048 [bytes]
        Digest ID:  0
  2: luks2
        Key:        512 bits
        Priority:   normal
        Cipher:     aes-xts-plain64
        Cipher key: 512 bits
        PBKDF:      argon2i
        Time cost:  5
        Memory:     1048576
        Threads:    4
        Salt:       ac 24 09 ca f9 24 52 3d 49 d3 c9 89 63 d0 1d 61 
                    83 4a aa ed 75 a2 39 ec 3f f8 ab 95 5d 0c 49 aa 
        AF stripes: 4000
        AF hash:    sha256
        Area offset:1064960 [bytes]
        Area length:258048 [bytes]
        Digest ID:  0
  3: luks2
        Key:        512 bits
        Priority:   normal
        Cipher:     aes-xts-plain64
        Cipher key: 512 bits
        PBKDF:      argon2i
        Time cost:  5
        Memory:     1048576
        Threads:    4
        Salt:       3d 37 41 20 93 44 55 62 c6 19 fe e0 7d ae 14 0d 
                    67 86 6a 44 5e c8 8a f0 97 01 1d c7 c6 83 02 22 
        AF stripes: 4000
        AF hash:    sha256
        Area offset:1323008 [bytes]
        Area length:258048 [bytes]
        Digest ID:  0
  4: luks2
        Key:        512 bits
        Priority:   normal
        Cipher:     aes-xts-plain64
        Cipher key: 512 bits
        PBKDF:      argon2i
        Time cost:  5
        Memory:     1048576
        Threads:    4
        Salt:       bf 6d a0 15 c9 8e 9b 49 12 84 86 6b 13 93 95 7d 
                    cf cf 8f 3a e2 b7 42 42 4c 59 a1 5c 23 cd e6 1a 
        AF stripes: 4000
        AF hash:    sha256
        Area offset:1581056 [bytes]
        Area length:258048 [bytes]
        Digest ID:  0
  5: luks2
        Key:        512 bits
        Priority:   normal
        Cipher:     aes-xts-plain64
        Cipher key: 512 bits
        PBKDF:      argon2i
        Time cost:  5
        Memory:     1048576
        Threads:    4
        Salt:       bd 76 ae e1 33 d3 7a 83 5b 59 d4 bc 46 17 36 ec 
                    e6 94 a5 b1 85 2d 00 9f a4 ff f4 02 cc b6 ca bc 
        AF stripes: 4000
        AF hash:    sha256
        Area offset:1839104 [bytes]
        Area length:258048 [bytes]
        Digest ID:  0
  6: luks2
        Key:        512 bits
        Priority:   normal
        Cipher:     aes-xts-plain64
        Cipher key: 512 bits
        PBKDF:      argon2i
        Time cost:  5
        Memory:     1048576
        Threads:    4
        Salt:       ab 7f dd e5 2c eb 32 51 97 9a 10 5e 70 75 1e 15 
                    91 35 10 63 f5 8b b6 8c 7a 97 16 40 50 e6 89 fb 
        AF stripes: 4000
        AF hash:    sha256
        Area offset:2097152 [bytes]
        Area length:258048 [bytes]
        Digest ID:  0
  7: luks2
        Key:        512 bits
        Priority:   normal
        Cipher:     aes-xts-plain64
        Cipher key: 512 bits
        PBKDF:      argon2i
        Time cost:  5
        Memory:     1048576
        Threads:    4
        Salt:       aa 02 fd a2 fd 4a ee 84 1a 41 93 58 7a 25 c2 d4 
                    0d 65 bc b4 5b 18 1a 05 4b 0a 81 f7 68 8c 9a 26 
        AF stripes: 4000
        AF hash:    sha256
        Area offset:548864 [bytes]
        Area length:258048 [bytes]
        Digest ID:  0
  8: luks2
        Key:        512 bits
        Priority:   normal
        Cipher:     aes-xts-plain64
        Cipher key: 512 bits
        PBKDF:      argon2i
        Time cost:  5
        Memory:     1048576
        Threads:    4
        Salt:       2b 04 62 29 e2 dc 42 b4 3a 28 8d 46 28 17 05 26 
                    a1 05 86 62 95 8e 50 98 91 67 18 15 71 1c 8a f9 
        AF stripes: 4000
        AF hash:    sha256
        Area offset:806912 [bytes]
        Area length:258048 [bytes]
        Digest ID:  0

2 Answers 2

5

For LUKS1, it's 8 key-slots, fixed.

For LUKS2, currently it's at most 32 key-slots:

#define LUKS2_KEYSLOTS_MAX       32

Trying to add more simply results in the error message "All key slots full.".

However, the answer might not be so simple after all. The limit of 32 exists in code but is not mentioned at all in the LUKS2 On-Disk Format Specification.

The LUKS2 header is actually capable of storing more than just 32 key-slots. Or it might not even be able to store 8 of them. It depends on the data offset, the size of the keyslots area, as well as the size required by each individual key.

For a newly formatted header, it defaults to a large data offset so you might easily get 32 key-slots. If you converted from LUKS1 (with only 2MiB data offset), it's unchanged at 8 key-slots. If the data offset is smaller, it might be less than 8 key-slots.

With a data offset of 1MiB, you only get 3 key-slots (cryptsetup emits a warning about it):

# truncate -s 100M foobar.img
# cryptsetup luksFormat --offset=2048 foobar.img
WARNING: keyslots area (1015808 bytes) is very small,
available LUKS2 keyslot count is very limited.
# cryptsetup luksAddKey foobar.img 
# cryptsetup luksAddKey foobar.img 
# cryptsetup luksAddKey foobar.img 
No space for new keyslot.

In this particular example, only 3 key-slots could be used before the header ran out of space to store more:

# cryptsetup luksDump foobar.img
LUKS header information
Version:        2
Epoch:          5
Metadata area:  16384 [bytes]
Keyslots area:  1015808 [bytes]
[...]
Keyslots:
  0: luks2
    [...]
    Area offset:32768 [bytes]
    Area length:258048 [bytes]
    Digest ID:  0
  1: luks2
    [...]
    Area offset:290816 [bytes]
    Area length:258048 [bytes]
    Digest ID:  0
  2: luks2
    [...]
    Area offset:548864 [bytes]
    Area length:258048 [bytes]
    Digest ID:  0

Here the total available keyslots area is only 1015808 bytes. Each key has a size of 257048 bytes. To store an additional key, 1032192 bytes would be required at minimum so, it just doesn't fit more keys in this particular case.

If you don't care about MiB alignment, it's possible to make the offset even smaller, leaving you with only a single key-slot.

1

Luks2 doesn't have fixed keyslots like Luks1. How many You can store depends on:
* luks2-metadata-size (max. 4MB can be reserved according to spec) where the key slot definitions are stored together with all the other metadata (in JSON format, so no definite area reserver for keys and also no absolute size requirement per key).
* luks2-keyslots-size (max. 128MB can be reserver according to spec) where the actual cryptograhic content of the key slots is saved. Here it also is a loose structure so it depends on actual slots data how many keys You could get with a specific size.
I did not calculate but I think there can be a lot of slots in most cases.

1
  • 1
    Yes, this is how the man page describes it, until you run into the limit of 32 slots anyway. Nov 22, 2019 at 23:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.