linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] dm-crypt: replace custom implementation of hex2bin()
@ 2016-05-10 23:24 Andy Shevchenko
  2016-12-30 21:51 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2016-05-10 23:24 UTC (permalink / raw)
  To: dm-devel, Mike Snitzer, linux-raid; +Cc: Andy Shevchenko

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

Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
 drivers/md/dm-crypt.c | 27 ++-------------------------
 1 file changed, 2 insertions(+), 25 deletions(-)

diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 4f3cb35..eb30284 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] dm-crypt: replace custom implementation of hex2bin()
  2016-05-10 23:24 Andy Shevchenko
@ 2016-12-30 21:51 ` Andy Shevchenko
  0 siblings, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2016-12-30 21:51 UTC (permalink / raw)
  To: dm-devel, Mike Snitzer, linux-raid; +Cc: Andy Shevchenko

On Wed, May 11, 2016 at 2:24 AM, Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> There is no need to have a duplication of the generic library, i.e. hex2bin().
> Replace the open coded variant.
>

Ping?

> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> ---
>  drivers/md/dm-crypt.c | 27 ++-------------------------
>  1 file changed, 2 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
> index 4f3cb35..eb30284 100644
> --- a/drivers/md/dm-crypt.c
> +++ b/drivers/md/dm-crypt.c
> @@ -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
>



-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v1] dm-crypt: replace custom implementation of hex2bin()
@ 2017-04-27 13:52 Andy Shevchenko
  0 siblings, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2017-04-27 13:52 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, dm-devel, Shaohua Li, linux-raid
  Cc: Andy Shevchenko

From: Andy Shevchenko <andy.shevchenko@gmail.com>

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

Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
 drivers/md/dm-crypt.c | 27 ++-------------------------
 1 file changed, 2 insertions(+), 25 deletions(-)

diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 70f765f50c59..ebf9e72d479b 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -1814,30 +1814,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_aead(struct crypt_config *cc)
 {
 	if (!cc->cipher_tfm.tfms_aead)
@@ -2136,7 +2112,8 @@ static int crypt_set_key(struct crypt_config *cc, char *key)
 	kzfree(cc->key_string);
 	cc->key_string = NULL;
 
-	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;
 
 	r = crypt_setkey(cc);
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-27 13:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-27 13:52 [PATCH v1] dm-crypt: replace custom implementation of hex2bin() Andy Shevchenko
  -- strict thread matches above, loose matches on Subject: below --
2016-05-10 23:24 Andy Shevchenko
2016-12-30 21:51 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).