Skip to content

Commit 4441686

Browse files
ifranzkiMikulas Patocka
authored andcommitted
dm-crypt: Allow to specify the integrity key size as option
For the MAC based integrity operation, the integrity key size (i.e. key_mac_size) is currently set to the digest size of the used digest. For wrapped key HMAC algorithms, the key size is independent of the cryptographic key size. So there is no known size of the mac key in such cases. The desired key size can optionally be specified as argument when the dm-crypt device is configured via 'integrity_key_size:%u'. If no integrity_key_size argument is specified, the mac key size is still set to the digest size, as before. Increase version number to 1.28.0 so that support for the new argument can be detected by user space (i.e. cryptsetup). Signed-off-by: Ingo Franzki <[email protected]> Reviewed-by: Milan Broz <[email protected]> Signed-off-by: Mikulas Patocka <[email protected]>
1 parent f3631ae commit 4441686

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Documentation/admin-guide/device-mapper/dm-crypt.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ iv_large_sectors
160160
The <iv_offset> must be multiple of <sector_size> (in 512 bytes units)
161161
if this flag is specified.
162162

163+
integrity_key_size:<bytes>
164+
Use an integrity key of <bytes> size instead of using an integrity key size
165+
of the digest size of the used HMAC algorithm.
166+
163167

164168
Module parameters::
165169

drivers/md/dm-crypt.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ enum cipher_flags {
147147
CRYPT_MODE_INTEGRITY_AEAD, /* Use authenticated mode for cipher */
148148
CRYPT_IV_LARGE_SECTORS, /* Calculate IV from sector_size, not 512B sectors */
149149
CRYPT_ENCRYPT_PREPROCESS, /* Must preprocess data for encryption (elephant) */
150+
CRYPT_KEY_MAC_SIZE_SET, /* The integrity_key_size option was used */
150151
};
151152

152153
/*
@@ -2937,7 +2938,8 @@ static int crypt_ctr_auth_cipher(struct crypt_config *cc, char *cipher_api)
29372938
if (IS_ERR(mac))
29382939
return PTR_ERR(mac);
29392940

2940-
cc->key_mac_size = crypto_ahash_digestsize(mac);
2941+
if (!test_bit(CRYPT_KEY_MAC_SIZE_SET, &cc->cipher_flags))
2942+
cc->key_mac_size = crypto_ahash_digestsize(mac);
29412943
crypto_free_ahash(mac);
29422944

29432945
cc->authenc_key = kmalloc(crypt_authenckey_size(cc), GFP_KERNEL);
@@ -3219,6 +3221,13 @@ static int crypt_ctr_optional(struct dm_target *ti, unsigned int argc, char **ar
32193221
cc->cipher_auth = kstrdup(sval, GFP_KERNEL);
32203222
if (!cc->cipher_auth)
32213223
return -ENOMEM;
3224+
} else if (sscanf(opt_string, "integrity_key_size:%u%c", &val, &dummy) == 1) {
3225+
if (!val) {
3226+
ti->error = "Invalid integrity_key_size argument";
3227+
return -EINVAL;
3228+
}
3229+
cc->key_mac_size = val;
3230+
set_bit(CRYPT_KEY_MAC_SIZE_SET, &cc->cipher_flags);
32223231
} else if (sscanf(opt_string, "sector_size:%hu%c", &cc->sector_size, &dummy) == 1) {
32233232
if (cc->sector_size < (1 << SECTOR_SHIFT) ||
32243233
cc->sector_size > 4096 ||
@@ -3607,10 +3616,10 @@ static void crypt_status(struct dm_target *ti, status_type_t type,
36073616
num_feature_args += test_bit(DM_CRYPT_NO_OFFLOAD, &cc->flags);
36083617
num_feature_args += test_bit(DM_CRYPT_NO_READ_WORKQUEUE, &cc->flags);
36093618
num_feature_args += test_bit(DM_CRYPT_NO_WRITE_WORKQUEUE, &cc->flags);
3619+
num_feature_args += !!cc->used_tag_size;
36103620
num_feature_args += cc->sector_size != (1 << SECTOR_SHIFT);
36113621
num_feature_args += test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags);
3612-
if (cc->used_tag_size)
3613-
num_feature_args++;
3622+
num_feature_args += test_bit(CRYPT_KEY_MAC_SIZE_SET, &cc->cipher_flags);
36143623
if (num_feature_args) {
36153624
DMEMIT(" %d", num_feature_args);
36163625
if (ti->num_discard_bios)
@@ -3631,6 +3640,8 @@ static void crypt_status(struct dm_target *ti, status_type_t type,
36313640
DMEMIT(" sector_size:%d", cc->sector_size);
36323641
if (test_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags))
36333642
DMEMIT(" iv_large_sectors");
3643+
if (test_bit(CRYPT_KEY_MAC_SIZE_SET, &cc->cipher_flags))
3644+
DMEMIT(" integrity_key_size:%u", cc->key_mac_size);
36343645
}
36353646
break;
36363647

@@ -3758,7 +3769,7 @@ static void crypt_io_hints(struct dm_target *ti, struct queue_limits *limits)
37583769

37593770
static struct target_type crypt_target = {
37603771
.name = "crypt",
3761-
.version = {1, 27, 0},
3772+
.version = {1, 28, 0},
37623773
.module = THIS_MODULE,
37633774
.ctr = crypt_ctr,
37643775
.dtr = crypt_dtr,

0 commit comments

Comments
 (0)