]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
crypto: shash - allow essiv and hmac to use OPTIONAL_KEY algorithms
authorEric Biggers <ebiggers@google.com>
Fri, 29 Nov 2019 19:35:22 +0000 (11:35 -0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Wed, 11 Dec 2019 08:36:57 +0000 (16:36 +0800)
The essiv and hmac templates refuse to use any hash algorithm that has a
->setkey() function, which includes not just algorithms that always need
a key, but also algorithms that optionally take a key.

Previously the only optionally-keyed hash algorithms in the crypto API
were non-cryptographic algorithms like crc32, so this didn't really
matter.  But that's changed with BLAKE2 support being added.  BLAKE2
should work with essiv and hmac, just like any other cryptographic hash.

Fix this by allowing the use of both algorithms without a ->setkey()
function and algorithms that have the OPTIONAL_KEY flag set.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/essiv.c
crypto/hmac.c
crypto/shash.c
include/crypto/internal/hash.h

index 808f2b3621068f6db28e7c3083f3176aeb111c09..e4b32c2ea7ec166a0f4f78f317686c844a0a2491 100644 (file)
@@ -442,7 +442,7 @@ static bool essiv_supported_algorithms(const char *essiv_cipher_name,
        if (ivsize != alg->cra_blocksize)
                goto out;
 
-       if (crypto_shash_alg_has_setkey(hash_alg))
+       if (crypto_shash_alg_needs_key(hash_alg))
                goto out;
 
        ret = true;
index 8b2a212eb0ad412e1d8a34d178c53d6eefb71342..377f07733e2fa86c3f5476a951909cd3ca40a40d 100644 (file)
@@ -185,9 +185,9 @@ static int hmac_create(struct crypto_template *tmpl, struct rtattr **tb)
                return PTR_ERR(salg);
        alg = &salg->base;
 
-       /* The underlying hash algorithm must be unkeyed */
+       /* The underlying hash algorithm must not require a key */
        err = -EINVAL;
-       if (crypto_shash_alg_has_setkey(salg))
+       if (crypto_shash_alg_needs_key(salg))
                goto out_put_alg;
 
        ds = salg->digestsize;
index e83c5124f6eb1d610e914de7833a9688a2fe0b05..7989258a46b4cc2ba4da5f1d85a78609a56024e6 100644 (file)
@@ -50,8 +50,7 @@ static int shash_setkey_unaligned(struct crypto_shash *tfm, const u8 *key,
 
 static void shash_set_needkey(struct crypto_shash *tfm, struct shash_alg *alg)
 {
-       if (crypto_shash_alg_has_setkey(alg) &&
-           !(alg->base.cra_flags & CRYPTO_ALG_OPTIONAL_KEY))
+       if (crypto_shash_alg_needs_key(alg))
                crypto_shash_set_flags(tfm, CRYPTO_TFM_NEED_KEY);
 }
 
index bfc9db7b100d61f3ed7307bcf787cc8583244ffe..f68dab38f160c17ef701db49ea1cbf541ed353f4 100644 (file)
@@ -85,6 +85,12 @@ static inline bool crypto_shash_alg_has_setkey(struct shash_alg *alg)
        return alg->setkey != shash_no_setkey;
 }
 
+static inline bool crypto_shash_alg_needs_key(struct shash_alg *alg)
+{
+       return crypto_shash_alg_has_setkey(alg) &&
+               !(alg->base.cra_flags & CRYPTO_ALG_OPTIONAL_KEY);
+}
+
 bool crypto_hash_alg_has_setkey(struct hash_alg_common *halg);
 
 int crypto_init_ahash_spawn(struct crypto_ahash_spawn *spawn,