crypto: skcipher - Add crypto_skcipher_has_setkey
authorHerbert Xu <herbert@gondor.apana.org.au>
Thu, 27 Oct 2016 14:29:40 +0000 (17:29 +0300)
committerDanny Wood <danwood76@gmail.com>
Tue, 29 Jan 2019 13:14:07 +0000 (13:14 +0000)
commit a1383cd86a062fc798899ab20f0ec2116cce39cb upstream.

This patch adds a way for skcipher users to determine whether a key
is required by a transform.

Cc: stable@vger.kernel.org
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
crypto/ablkcipher.c
crypto/blkcipher.c
include/linux/crypto.h

index ebcec7439a1a367f6dbf862788f2cf0064e0fd04..2b6dd740163254361b8dc421bab0d971a10cb2da 100644 (file)
@@ -379,6 +379,7 @@ static int crypto_init_ablkcipher_ops(struct crypto_tfm *tfm, u32 type,
        }
        crt->base = __crypto_ablkcipher_cast(tfm);
        crt->ivsize = alg->ivsize;
+       crt->has_setkey = alg->max_keysize;
 
        return 0;
 }
@@ -460,6 +461,7 @@ static int crypto_init_givcipher_ops(struct crypto_tfm *tfm, u32 type,
        crt->givdecrypt = alg->givdecrypt ?: no_givdecrypt;
        crt->base = __crypto_ablkcipher_cast(tfm);
        crt->ivsize = alg->ivsize;
+       crt->has_setkey = alg->max_keysize;
 
        return 0;
 }
index 0122bec38564d6c5de533d0e80b03d23e95f673b..496557a15f713899b2c81419b973abf09f77c515 100644 (file)
@@ -471,6 +471,7 @@ static int crypto_init_blkcipher_ops_async(struct crypto_tfm *tfm)
        }
        crt->base = __crypto_ablkcipher_cast(tfm);
        crt->ivsize = alg->ivsize;
+       crt->has_setkey = alg->max_keysize;
 
        return 0;
 }
index 2b00d92a6e6fcec18b0ccf532b25839813d0868e..61dd0b15d21ca915750aa399befe33bd968329e9 100644 (file)
@@ -354,6 +354,7 @@ struct ablkcipher_tfm {
 
        unsigned int ivsize;
        unsigned int reqsize;
+       bool has_setkey;
 };
 
 struct aead_tfm {
@@ -664,6 +665,13 @@ static inline int crypto_ablkcipher_setkey(struct crypto_ablkcipher *tfm,
        return crt->setkey(crt->base, key, keylen);
 }
 
+static inline bool crypto_ablkcipher_has_setkey(struct crypto_ablkcipher *tfm)
+{
+       struct ablkcipher_tfm *crt = crypto_ablkcipher_crt(tfm);
+
+       return crt->has_setkey;
+}
+
 static inline struct crypto_ablkcipher *crypto_ablkcipher_reqtfm(
        struct ablkcipher_request *req)
 {