Skip to contentSkip to conversation

dm-crypt: Reimplement elephant diffuser using AES library

PATCH New Eric Biggers 1 participant 3 messages Mar 21

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover dm-crypt: Reimplement elephant diffuser using AES library

This series simplifies and optimizes dm-crypt's implementation of Bitlocker's "elephant diffuser" to use the AES library instead of an "ecb(aes)" crypto_skcipher.

This series is targeting linux-dm/for-next

Eric Biggers (2):
dm-crypt: Reimplement elephant diffuser using AES library
dm-crypt: Make crypt_iv_operations::wipe return void

 drivers/md/Kconfig    |   1 +
 drivers/md/dm-crypt.c | 103 ++++++++++++++----------------------------
 2 files changed, 36 insertions(+), 68 deletions(-)

base-commit: 23e6e57a93bcabe86d5f0eab1df0c44706ab18f3

Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/2 dm-crypt: Reimplement elephant diffuser using AES library

Simplify and optimize dm-crypt's implementation of Bitlocker's "elephant diffuser" to use the AES library instead of an "ecb(aes)" crypto_skcipher.

Note: struct aes_enckey is fixed-size, so it could be embedded directly in struct iv_elephant_private. But I kept it as a separate allocation so that the size of struct crypt_config doesn't increase. The elephant diffuser is rarely used in dm-crypt.

---
 drivers/md/Kconfig    |  1 +
 drivers/md/dm-crypt.c | 85 +++++++++++++++----------------------------
 2 files changed, 31 insertions(+), 55 deletions(-)
drivers/md/Kconfig +1 -0
index 53351048d3ec..a3fcdca7e6db 100644
@@ -298,10 +298,11 @@ config DM_CRYPT
 	depends on (TRUSTED_KEYS || TRUSTED_KEYS=n)
 	select CRC32
 	select CRYPTO
 	select CRYPTO_CBC
 	select CRYPTO_ESSIV
+	select CRYPTO_LIB_AES
 	select CRYPTO_LIB_MD5 # needed by lmk IV mode
 	help
 	  This device-mapper target allows you to create a device that
 	  transparently encrypts the data on it. You'll need to activate
 	  the ciphers you're going to use in the cryptoapi configuration.
drivers/md/dm-crypt.c +30 -55

178 lines not on this page · raw message

Signature · 1 line
2.53.0
#2 lore raw

PATCH 2/2 dm-crypt: Make crypt_iv_operations::wipe return void

In reply to Eric Biggers

Since all implementations of crypt_iv_operations::wipe now return 0, change the return type to void.

---
 drivers/md/dm-crypt.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)
drivers/md/dm-crypt.c +6 -14
index 76b0c6bfd45c..885208a82c55 100644
@@ -108,11 +108,11 @@ struct crypt_config;
 struct crypt_iv_operations {
 	int (*ctr)(struct crypt_config *cc, struct dm_target *ti,
 		   const char *opts);
 	void (*dtr)(struct crypt_config *cc);
 	int (*init)(struct crypt_config *cc);
-	int (*wipe)(struct crypt_config *cc);
+	void (*wipe)(struct crypt_config *cc);
 	int (*generator)(struct crypt_config *cc, u8 *iv,
 			 struct dm_crypt_request *dmreq);
 	int (*post)(struct crypt_config *cc, u8 *iv,
 		    struct dm_crypt_request *dmreq);
 };
@@ -506,18 +506,16 @@ static int crypt_iv_lmk_init(struct crypt_config *cc)
 		       MD5_DIGEST_SIZE);
 
 	return 0;
 }
 
-static int crypt_iv_lmk_wipe(struct crypt_config *cc)
+static void crypt_iv_lmk_wipe(struct crypt_config *cc)
 {
 	struct iv_lmk_private *lmk = &cc->iv_gen_private.lmk;
 
 	if (lmk->seed)
 		memset(lmk->seed, 0, LMK_SEED_SIZE);
-
-	return 0;
 }
 
 static void crypt_iv_lmk_one(struct crypt_config *cc, u8 *iv,
 			     struct dm_crypt_request *dmreq, u8 *data)
 {
@@ -627,18 +625,16 @@ static int crypt_iv_tcw_init(struct crypt_config *cc)
 	       TCW_WHITENING_SIZE);
 
 	return 0;
 }
 
-static int crypt_iv_tcw_wipe(struct crypt_config *cc)
+static void crypt_iv_tcw_wipe(struct crypt_config *cc)
 {
 	struct iv_tcw_private *tcw = &cc->iv_gen_private.tcw;
 
 	memset(tcw->iv_seed, 0, cc->iv_size);
 	memset(tcw->whitening, 0, TCW_WHITENING_SIZE);
-
-	return 0;
 }
 
 static void crypt_iv_tcw_whitening(struct crypt_config *cc,
 				   struct dm_crypt_request *dmreq, u8 *data)
 {
@@ -1013,16 +1009,15 @@ static int crypt_iv_elephant_init(struct crypt_config *cc)
 	int key_offset = cc->key_size - cc->key_extra_size;
 
 	return aes_prepareenckey(elephant->key, &cc->key[key_offset], cc->key_extra_size);
 }
 
-static int crypt_iv_elephant_wipe(struct crypt_config *cc)
+static void crypt_iv_elephant_wipe(struct crypt_config *cc)
 {
 	struct iv_elephant_private *elephant = &cc->iv_gen_private.elephant;
 
 	memzero_explicit(elephant->key, sizeof(*elephant->key));
-	return 0;
 }
 
 static const struct crypt_iv_operations crypt_iv_plain_ops = {
 	.generator = crypt_iv_plain_gen
 };
@@ -2646,15 +2641,12 @@ static int crypt_wipe_key(struct crypt_config *cc)
 
 	clear_bit(DM_CRYPT_KEY_VALID, &cc->flags);
 	get_random_bytes(&cc->key, cc->key_size);
 
 	/* Wipe IV private keys */
-	if (cc->iv_gen_ops && cc->iv_gen_ops->wipe) {
-		r = cc->iv_gen_ops->wipe(cc);
-		if (r)
-			return r;
-	}
+	if (cc->iv_gen_ops && cc->iv_gen_ops->wipe)
+		cc->iv_gen_ops->wipe(cc);
 
 	kfree_sensitive(cc->key_string);
 	cc->key_string = NULL;
 	r = crypt_setkey(cc);
 	memset(&cc->key, 0, cc->key_size * sizeof(u8));
Signature · 1 line
2.53.0