From patchwork Fri Mar 25 16:01:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamal Mostafa X-Patchwork-Id: 602029 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3qWp2J6l3kz9sD5; Sat, 26 Mar 2016 03:01:28 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1ajUAt-0007WE-P0; Fri, 25 Mar 2016 16:01:23 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1ajUAj-0007SV-0V for kernel-team@lists.ubuntu.com; Fri, 25 Mar 2016 16:01:13 +0000 Received: from 1.general.kamal.us.vpn ([10.172.68.52] helo=fourier) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1ajUAi-0005W5-J8 for kernel-team@lists.ubuntu.com; Fri, 25 Mar 2016 16:01:12 +0000 Received: from kamal by fourier with local (Exim 4.86) (envelope-from ) id 1ajUAf-0007WL-Tc for kernel-team@lists.ubuntu.com; Fri, 25 Mar 2016 09:01:09 -0700 From: Kamal Mostafa To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/4 v2] crypto: skcipher - Add crypto_skcipher_has_setkey Date: Fri, 25 Mar 2016 09:01:04 -0700 Message-Id: <1458921667-28870-2-git-send-email-kamal@whence.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1458921667-28870-1-git-send-email-kamal@whence.com> References: <1458921667-28870-1-git-send-email-kamal@whence.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com From: Herbert Xu BugLink: http://bugs.launchpad.net/bugs/1556562 commit a1383cd86a062fc798899ab20f0ec2116cce39cb upstream. This patch adds a way for skcipher users to determine whether a key is required by a transform. Signed-off-by: Herbert Xu [bwh: Backported to 3.2: add to ablkcipher API instead] Signed-off-by: Ben Hutchings Signed-off-by: Luis Henriques [kamal: plus bwh http://article.gmane.org/gmane.linux.kernel.stable/169083] Signed-off-by: Kamal Mostafa --- crypto/ablkcipher.c | 2 ++ crypto/blkcipher.c | 1 + include/linux/crypto.h | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c index e5b5721..13836be 100644 --- a/crypto/ablkcipher.c +++ b/crypto/ablkcipher.c @@ -377,6 +377,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; } @@ -458,6 +459,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; } diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c index 8cc1622..79978da 100644 --- a/crypto/blkcipher.c +++ b/crypto/blkcipher.c @@ -472,6 +472,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; } diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 81ef938..ab5f912 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -552,6 +552,7 @@ struct ablkcipher_tfm { unsigned int ivsize; unsigned int reqsize; + bool has_setkey; }; struct blkcipher_tfm { @@ -922,6 +923,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; +} + /** * crypto_ablkcipher_reqtfm() - obtain cipher handle from request * @req: ablkcipher_request out of which the cipher handle is to be obtained