All of lore.kernel.org
 help / color / mirror / Atom feed
* [dm-crypt] [PATCH] crypt_plain_hash: Remove dead code
@ 2019-01-18 14:14 Richard Weinberger
  2019-01-20  9:33 ` Milan Broz
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Weinberger @ 2019-01-18 14:14 UTC (permalink / raw)
  To: dm-crypt; +Cc: gmazyland, Richard Weinberger

Since commit 31a4d552a2d9 ("Support keyfile offset and keyfile size option even for plain volumes.")
params.hash is set to NULL when the requested hash function is
"plain". Therfore the code to handle the "plain" hasher in
crypt_plain_hash() is no longer reachable and can be removed.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 lib/crypt_plain.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/lib/crypt_plain.c b/lib/crypt_plain.c
index f89c7747649d..66339bdbf2c9 100644
--- a/lib/crypt_plain.c
+++ b/lib/crypt_plain.c
@@ -99,17 +99,7 @@ int crypt_plain_hash(struct crypt_device *cd,
 		pad_size = 0;
 	}
 
-	/* No hash, copy passphrase directly */
-	if (!strcmp(hash_name_buf, "plain")) {
-		if (passphrase_size < hash_size) {
-			log_dbg(cd, "Too short plain passphrase.");
-			return -EINVAL;
-		}
-		memcpy(key, passphrase, hash_size);
-		r = 0;
-	} else
-		r = hash(hash_name_buf, hash_size, key, passphrase_size, passphrase);
-
+	r = hash(hash_name_buf, hash_size, key, passphrase_size, passphrase);
 	if (r == 0 && pad_size)
 		memset(key + hash_size, 0, pad_size);
 
-- 
2.20.1

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

* Re: [dm-crypt] [PATCH] crypt_plain_hash: Remove dead code
  2019-01-18 14:14 [dm-crypt] [PATCH] crypt_plain_hash: Remove dead code Richard Weinberger
@ 2019-01-20  9:33 ` Milan Broz
  2019-01-20  9:53   ` Richard Weinberger
  0 siblings, 1 reply; 3+ messages in thread
From: Milan Broz @ 2019-01-20  9:33 UTC (permalink / raw)
  To: Richard Weinberger, dm-crypt

On 18/01/2019 15:14, Richard Weinberger wrote:
> Since commit 31a4d552a2d9 ("Support keyfile offset and keyfile size option even for plain volumes.")
> params.hash is set to NULL when the requested hash function is
> "plain". Therfore the code to handle the "plain" hasher in
> crypt_plain_hash() is no longer reachable and can be removed.

Hi,

thanks for the patch, but unfortunately it is not the correct fix.

While cryptsetup set params.hash to NULL, other users can still use "plain" to indicate no hashing
(I think systemd-cryptsetup is one of them).

IOW: /lib/* is libcryptsetup API, your code modifies how the libcryptsetup API works now.
(Despite "plain" hash is legacy code, and I wish it to be removed...)

You referenced commit that modifies cryptsetup binary, cryptsetup is only one user of libcryptsetup API,
so the conclusion that the code is no longer used is misleading.

(My bad that there was no test for it in libcryptsetup api-test, I just added such a test to the git.)

Thanks,
Milan


> 
> Signed-off-by: Richard Weinberger <richard@nod.at>
> ---
>  lib/crypt_plain.c | 12 +-----------
>  1 file changed, 1 insertion(+), 11 deletions(-)
> 
> diff --git a/lib/crypt_plain.c b/lib/crypt_plain.c
> index f89c7747649d..66339bdbf2c9 100644
> --- a/lib/crypt_plain.c
> +++ b/lib/crypt_plain.c
> @@ -99,17 +99,7 @@ int crypt_plain_hash(struct crypt_device *cd,
>  		pad_size = 0;
>  	}
>  
> -	/* No hash, copy passphrase directly */
> -	if (!strcmp(hash_name_buf, "plain")) {
> -		if (passphrase_size < hash_size) {
> -			log_dbg(cd, "Too short plain passphrase.");
> -			return -EINVAL;
> -		}
> -		memcpy(key, passphrase, hash_size);
> -		r = 0;
> -	} else
> -		r = hash(hash_name_buf, hash_size, key, passphrase_size, passphrase);
> -
> +	r = hash(hash_name_buf, hash_size, key, passphrase_size, passphrase);
>  	if (r == 0 && pad_size)
>  		memset(key + hash_size, 0, pad_size);
>  
> 

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

* Re: [dm-crypt] [PATCH] crypt_plain_hash: Remove dead code
  2019-01-20  9:33 ` Milan Broz
@ 2019-01-20  9:53   ` Richard Weinberger
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Weinberger @ 2019-01-20  9:53 UTC (permalink / raw)
  To: Milan Broz; +Cc: dm-crypt

Milan,

Am Sonntag, 20. Januar 2019, 10:33:46 CET schrieb Milan Broz:
> On 18/01/2019 15:14, Richard Weinberger wrote:
> > Since commit 31a4d552a2d9 ("Support keyfile offset and keyfile size option even for plain volumes.")
> > params.hash is set to NULL when the requested hash function is
> > "plain". Therfore the code to handle the "plain" hasher in
> > crypt_plain_hash() is no longer reachable and can be removed.
> 
> Hi,
> 
> thanks for the patch, but unfortunately it is not the correct fix.
> 
> While cryptsetup set params.hash to NULL, other users can still use "plain" to indicate no hashing
> (I think systemd-cryptsetup is one of them).
> 
> IOW: /lib/* is libcryptsetup API, your code modifies how the libcryptsetup API works now.
> (Despite "plain" hash is legacy code, and I wish it to be removed...)
> 
> You referenced commit that modifies cryptsetup binary, cryptsetup is only one user of libcryptsetup API,
> so the conclusion that the code is no longer used is misleading.
> 
> (My bad that there was no test for it in libcryptsetup api-test, I just added such a test to the git.)

Ahhh, stupid me. I completely forgot that libcryptsetup is supposed to be used by
programs outside of the cryptsetup code base.

Thanks,
//richard

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

end of thread, other threads:[~2019-01-20 10:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-18 14:14 [dm-crypt] [PATCH] crypt_plain_hash: Remove dead code Richard Weinberger
2019-01-20  9:33 ` Milan Broz
2019-01-20  9:53   ` Richard Weinberger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.