crypto: shash - require neither or both ->export() and ->import()
diff mbox series

Message ID 20190107030720.9971-1-ebiggers@kernel.org
State Accepted
Delegated to: Herbert Xu
Headers show
Series
  • crypto: shash - require neither or both ->export() and ->import()
Related show

Commit Message

Eric Biggers Jan. 7, 2019, 3:07 a.m. UTC
From: Eric Biggers <ebiggers@google.com>

Prevent registering shash algorithms that implement ->export() but not
->import(), or ->import() but not ->export().  Such cases don't make
sense and could confuse the check that shash_prepare_alg() does for just
->export().

I don't believe this affects any existing algorithms; this is just
preventing future mistakes.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/shash.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Herbert Xu Jan. 18, 2019, 10:55 a.m. UTC | #1
On Sun, Jan 06, 2019 at 07:07:20PM -0800, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> Prevent registering shash algorithms that implement ->export() but not
> ->import(), or ->import() but not ->export().  Such cases don't make
> sense and could confuse the check that shash_prepare_alg() does for just
> ->export().
> 
> I don't believe this affects any existing algorithms; this is just
> preventing future mistakes.
> 
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
>  crypto/shash.c | 3 +++
>  1 file changed, 3 insertions(+)

Patch applied.  Thanks.

Patch
diff mbox series

diff --git a/crypto/shash.c b/crypto/shash.c
index 40311ccad3fae..2bffdecf1f837 100644
--- a/crypto/shash.c
+++ b/crypto/shash.c
@@ -472,6 +472,9 @@  static int shash_prepare_alg(struct shash_alg *alg)
 	    alg->statesize > HASH_MAX_STATESIZE)
 		return -EINVAL;
 
+	if ((alg->export && !alg->import) || (alg->import && !alg->export))
+		return -EINVAL;
+
 	base->cra_type = &crypto_shash_type;
 	base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
 	base->cra_flags |= CRYPTO_ALG_TYPE_SHASH;