Skip to contentSkip to conversation

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

PATCH In review Eric Biggers 2 participants 2 messages Jan 7, 2019 – Jan 18, 2019 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: shash - require neither or both ->export() and ->import()

From: Eric Biggers <[email protected]>

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.

---
 crypto/shash.c | 3 +++
 1 file changed, 3 insertions(+)
crypto/shash.c +3 -0
index 40311ccad3fae..2bffdecf1f837 100644
@@ -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;
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 7 lines · Eric Biggers

From: Eric Biggers <[email protected]>

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().

Quoted 7 lines

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

---
 crypto/shash.c | 3 +++
 1 file changed, 3 insertions(+)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt