linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Linux Crypto Mailing List <linux-crypto@vger.kernel.org>
Subject: [PATCH 17/24] crypto: omap - Forbid 2-key 3DES in FIPS mode
Date: Thu, 11 Apr 2019 16:51:14 +0800	[thread overview]
Message-ID: <E1hEVQQ-0006ny-FS@gondobar> (raw)
In-Reply-To: 20190411084707.h56mz2z7jxusnr7u@gondor.apana.org.au

This patch forbids the use of 2-key 3DES (K1 == K3) in FIPS mode.

It also removes a couple of unnecessary key length checks that
are already performed by the crypto API.
   
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---

 drivers/crypto/omap-des.c |   29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/drivers/crypto/omap-des.c b/drivers/crypto/omap-des.c
index 1ba2633e90d6..3d82d18ff810 100644
--- a/drivers/crypto/omap-des.c
+++ b/drivers/crypto/omap-des.c
@@ -656,9 +656,6 @@ static int omap_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
 	struct omap_des_ctx *ctx = crypto_ablkcipher_ctx(cipher);
 	struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
 
-	if (keylen != DES_KEY_SIZE && keylen != (3*DES_KEY_SIZE))
-		return -EINVAL;
-
 	pr_debug("enter, keylen: %d\n", keylen);
 
 	/* Do we need to test against weak key? */
@@ -678,6 +675,28 @@ static int omap_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
 	return 0;
 }
 
+static int omap_des3_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
+			   unsigned int keylen)
+{
+	struct omap_des_ctx *ctx = crypto_ablkcipher_ctx(cipher);
+	u32 flags;
+	int err;
+
+	pr_debug("enter, keylen: %d\n", keylen);
+
+	flags = crypto_ablkcipher_get_flags(cipher);
+	err = __des3_verify_key(&flags, key);
+	if (unlikely(err)) {
+		crypto_ablkcipher_set_flags(cipher, flags);
+		return err;
+	}
+
+	memcpy(ctx->key, key, keylen);
+	ctx->keylen = keylen;
+
+	return 0;
+}
+
 static int omap_des_ecb_encrypt(struct ablkcipher_request *req)
 {
 	return omap_des_crypt(req, FLAGS_ENCRYPT);
@@ -788,7 +807,7 @@ static struct crypto_alg algs_ecb_cbc[] = {
 	.cra_u.ablkcipher = {
 		.min_keysize	= 3*DES_KEY_SIZE,
 		.max_keysize	= 3*DES_KEY_SIZE,
-		.setkey		= omap_des_setkey,
+		.setkey		= omap_des3_setkey,
 		.encrypt	= omap_des_ecb_encrypt,
 		.decrypt	= omap_des_ecb_decrypt,
 	}
@@ -811,7 +830,7 @@ static struct crypto_alg algs_ecb_cbc[] = {
 		.min_keysize	= 3*DES_KEY_SIZE,
 		.max_keysize	= 3*DES_KEY_SIZE,
 		.ivsize		= DES_BLOCK_SIZE,
-		.setkey		= omap_des_setkey,
+		.setkey		= omap_des3_setkey,
 		.encrypt	= omap_des_cbc_encrypt,
 		.decrypt	= omap_des_cbc_decrypt,
 	}

  parent reply	other threads:[~2019-04-11  8:51 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-11  8:47 [PATCH 0/24] Forbid 2-key 3DES in FIPS mode Herbert Xu
2019-04-11  8:50 ` [PATCH 1/24] crypto: des_generic - Forbid 2-key in 3DES and add helpers Herbert Xu
2019-04-11  8:50 ` [PATCH 2/24] crypto: s390 - Forbid 2-key 3DES in FIPS mode Herbert Xu
2019-04-11  8:50 ` [PATCH 3/24] crypto: sparc " Herbert Xu
2019-04-11  8:51 ` [PATCH 4/24] crypto: atmel " Herbert Xu
2019-04-11  8:51 ` [PATCH 5/24] crypto: bcm " Herbert Xu
2019-04-11  8:51 ` [PATCH 6/24] crypto: caam " Herbert Xu
2019-04-16 12:52   ` Horia Geanta
2019-04-16 12:53   ` Iuliana Prodan
2019-04-11  8:51 ` [PATCH 7/24] crypto: cavium " Herbert Xu
2019-04-11  8:51 ` [PATCH 8/24] crypto: nitrox " Herbert Xu
2019-04-11  8:51 ` [PATCH 9/24] crypto: ccp " Herbert Xu
2019-04-11  8:51 ` [PATCH 10/24] crypto: ccree " Herbert Xu
2019-04-11  9:27   ` Stephan Mueller
2019-04-11  9:30     ` Herbert Xu
2019-04-11 11:07   ` Gilad Ben-Yossef
2019-04-11  8:51 ` [PATCH 11/24] crypto: hifn_795x " Herbert Xu
2019-04-11  8:51 ` [PATCH 12/24] crypto: hisilicon " Herbert Xu
2019-04-11  8:51 ` [PATCH 13/24] crypto: inside-secure " Herbert Xu
2019-04-11  8:51 ` [PATCH 14/24] crypto: ixp4xx " Herbert Xu
2019-04-11  8:51 ` [PATCH 15/24] crypto: marvell " Herbert Xu
2019-04-11  8:51 ` [PATCH 16/24] crypto: n2 " Herbert Xu
2019-04-11  8:51 ` Herbert Xu [this message]
2019-04-11  8:51 ` [PATCH 18/24] crypto: picoxcell " Herbert Xu
2019-04-11  8:51 ` [PATCH 19/24] crypto: qce " Herbert Xu
2019-04-11  8:51 ` [PATCH 20/24] crypto: rockchip " Herbert Xu
2019-04-11  8:51 ` [PATCH 21/24] crypto: stm32 " Herbert Xu
2019-04-12 13:36   ` Lionel DEBIEVE
2019-04-13 13:50     ` Herbert Xu
2019-04-15  9:45       ` Lionel DEBIEVE
2019-04-11  8:51 ` [PATCH 22/24] crypto: sun4i-ss " Herbert Xu
2019-04-11 13:51   ` Corentin Labbe
2019-04-11  8:51 ` [PATCH 23/24] crypto: talitos " Herbert Xu
2019-04-11  8:51 ` [PATCH 24/24] crypto: ux500 " Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1hEVQQ-0006ny-FS@gondobar \
    --to=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).