Skip to contentSkip to conversation

dm-crypt: replace custom implementation of hex2bin()

PATCH In review Andy Shevchenko 1 participant 2 messages May 10, 2016 – Dec 30, 2016

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

PATCH 1/1 dm-crypt: replace custom implementation of hex2bin()

There is no need to have a duplication of the generic library, i.e. hex2bin(). Replace the open coded variant.

---
 drivers/md/dm-crypt.c | 27 ++-------------------------
 1 file changed, 2 insertions(+), 25 deletions(-)
drivers/md/dm-crypt.c +2 -25
index 4f3cb35..eb30284 100644
@@ -1407,30 +1407,6 @@ static void kcryptd_queue_crypt(struct dm_crypt_io *io)
 	queue_work(cc->crypt_queue, &io->work);
 }
 
-/*
- * Decode key from its hex representation
- */
-static int crypt_decode_key(u8 *key, char *hex, unsigned int size)
-{
-	char buffer[3];
-	unsigned int i;
-
-	buffer[2] = '\0';
-
-	for (i = 0; i < size; i++) {
-		buffer[0] = *hex++;
-		buffer[1] = *hex++;
-
-		if (kstrtou8(buffer, 16, &key[i]))
-			return -EINVAL;
-	}
-
-	if (*hex != '\0')
-		return -EINVAL;
-
-	return 0;
-}
-
 static void crypt_free_tfms(struct crypt_config *cc)
 {
 	unsigned i;
@@ -1502,7 +1478,8 @@ static int crypt_set_key(struct crypt_config *cc, char *key)
 	if (!cc->key_size && strcmp(key, "-"))
 		goto out;
 
-	if (cc->key_size && crypt_decode_key(cc->key, key, cc->key_size) < 0)
+	/* Decode key from its hex representation. */
+	if (cc->key_size && hex2bin(cc->key, key, cc->key_size) < 0)
 		goto out;
 
 	set_bit(DM_CRYPT_KEY_VALID, &cc->flags);
Signature · 1 line
2.8.2
#1 lore raw
Quoted 3 lines · Andy Shevchenko

There is no need to have a duplication of the generic library, i.e. hex2bin(). Replace the open coded variant.

Ping?

Quoted 53 lines
---
 drivers/md/dm-crypt.c | 27 ++-------------------------
 1 file changed, 2 insertions(+), 25 deletions(-)
drivers/md/dm-crypt.c +2 -26
index 4f3cb35..eb30284 100644
@@ -1407,30 +1407,6 @@ static void kcryptd_queue_crypt(struct dm_crypt_io *io)
        queue_work(cc->crypt_queue, &io->work);
 }
 
-/*
- * Decode key from its hex representation
- */
-static int crypt_decode_key(u8 *key, char *hex, unsigned int size)
-{
-       char buffer[3];
-       unsigned int i;
-
-       buffer[2] = '\0';
-
-       for (i = 0; i < size; i++) {
-               buffer[0] = *hex++;
-               buffer[1] = *hex++;
-
-               if (kstrtou8(buffer, 16, &key[i]))
-                       return -EINVAL;
-       }
-
-       if (*hex != '\0')
-               return -EINVAL;
-
-       return 0;
-}
-
 static void crypt_free_tfms(struct crypt_config *cc)
 {
        unsigned i;
@@ -1502,7 +1478,8 @@ static int crypt_set_key(struct crypt_config *cc, char *key)
        if (!cc->key_size && strcmp(key, "-"))
                goto out;
 
-       if (cc->key_size && crypt_decode_key(cc->key, key, cc->key_size) < 0)
+       /* Decode key from its hex representation. */
+       if (cc->key_size && hex2bin(cc->key, key, cc->key_size) < 0)
                goto out;
 
        set_bit(DM_CRYPT_KEY_VALID, &cc->flags);
--

2.8.2

Signature · 2 lines
With Best Regards,
Andy Shevchenko