diff mbox series

[v2,11/30] crypto: hifn/des - switch to new verification routines

Message ID 20190627120314.7197-12-ard.biesheuvel@linaro.org (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show
Series crypto: DES/3DES cleanup | expand

Commit Message

Ard Biesheuvel June 27, 2019, 12:02 p.m. UTC
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 drivers/crypto/hifn_795x.c | 30 +++++---------------
 1 file changed, 7 insertions(+), 23 deletions(-)

Comments

Eric Biggers June 27, 2019, 4:19 p.m. UTC | #1
On Thu, Jun 27, 2019 at 02:02:55PM +0200, Ard Biesheuvel wrote:
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  drivers/crypto/hifn_795x.c | 30 +++++---------------
>  1 file changed, 7 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
> index d656be0a142b..000477e4a429 100644
> --- a/drivers/crypto/hifn_795x.c
> +++ b/drivers/crypto/hifn_795x.c
> @@ -30,7 +30,7 @@
>  #include <linux/ktime.h>
>  
>  #include <crypto/algapi.h>
> -#include <crypto/des.h>
> +#include <crypto/internal/des.h>
>  
>  static char hifn_pll_ref[sizeof("extNNN")] = "ext";
>  module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
> @@ -1948,25 +1948,13 @@ static void hifn_flush(struct hifn_device *dev)
>  static int hifn_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
>  		unsigned int len)
>  {
> -	struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
>  	struct hifn_context *ctx = crypto_tfm_ctx(tfm);
>  	struct hifn_device *dev = ctx->dev;
> +	int err;

Also a build error here:

drivers/crypto/hifn_795x.c: In function 'hifn_setkey':
drivers/crypto/hifn_795x.c:1951:44: error: 'tfm' undeclared (first use in this function); did you mean 'tm'?
  struct hifn_context *ctx = crypto_tfm_ctx(tfm);
                                            ^~~
                                            tm
drivers/crypto/hifn_795x.c:1951:44: note: each undeclared identifier is reported only once for each function it appears in
Ard Biesheuvel June 27, 2019, 4:34 p.m. UTC | #2
On Thu, 27 Jun 2019 at 18:19, Eric Biggers <ebiggers@kernel.org> wrote:
>
> On Thu, Jun 27, 2019 at 02:02:55PM +0200, Ard Biesheuvel wrote:
> > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > ---
> >  drivers/crypto/hifn_795x.c | 30 +++++---------------
> >  1 file changed, 7 insertions(+), 23 deletions(-)
> >
> > diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
> > index d656be0a142b..000477e4a429 100644
> > --- a/drivers/crypto/hifn_795x.c
> > +++ b/drivers/crypto/hifn_795x.c
> > @@ -30,7 +30,7 @@
> >  #include <linux/ktime.h>
> >
> >  #include <crypto/algapi.h>
> > -#include <crypto/des.h>
> > +#include <crypto/internal/des.h>
> >
> >  static char hifn_pll_ref[sizeof("extNNN")] = "ext";
> >  module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
> > @@ -1948,25 +1948,13 @@ static void hifn_flush(struct hifn_device *dev)
> >  static int hifn_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
> >               unsigned int len)
> >  {
> > -     struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
> >       struct hifn_context *ctx = crypto_tfm_ctx(tfm);
> >       struct hifn_device *dev = ctx->dev;
> > +     int err;
>
> Also a build error here:
>
> drivers/crypto/hifn_795x.c: In function 'hifn_setkey':
> drivers/crypto/hifn_795x.c:1951:44: error: 'tfm' undeclared (first use in this function); did you mean 'tm'?
>   struct hifn_context *ctx = crypto_tfm_ctx(tfm);
>                                             ^~~
>                                             tm
> drivers/crypto/hifn_795x.c:1951:44: note: each undeclared identifier is reported only once for each function it appears in

Hum, I built allmodconfig for a bunch of architectures, but apparently
I missed this one and another one. I will double check these for the
next rev
diff mbox series

Patch

diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
index d656be0a142b..000477e4a429 100644
--- a/drivers/crypto/hifn_795x.c
+++ b/drivers/crypto/hifn_795x.c
@@ -30,7 +30,7 @@ 
 #include <linux/ktime.h>
 
 #include <crypto/algapi.h>
-#include <crypto/des.h>
+#include <crypto/internal/des.h>
 
 static char hifn_pll_ref[sizeof("extNNN")] = "ext";
 module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
@@ -1948,25 +1948,13 @@  static void hifn_flush(struct hifn_device *dev)
 static int hifn_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
 		unsigned int len)
 {
-	struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
 	struct hifn_context *ctx = crypto_tfm_ctx(tfm);
 	struct hifn_device *dev = ctx->dev;
+	int err;
 
-	if (len > HIFN_MAX_CRYPT_KEY_LENGTH) {
-		crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
-		return -1;
-	}
-
-	if (len == HIFN_DES_KEY_LENGTH) {
-		u32 tmp[DES_EXPKEY_WORDS];
-		int ret = des_ekey(tmp, key);
-
-		if (unlikely(ret == 0) &&
-		    (tfm->crt_flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) {
-			tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
-			return -EINVAL;
-		}
-	}
+	err = crypto_des_verify_key(crypto_ablkcipher_tfm(cipher), key);
+	if (unlikely(err))
+		return err;
 
 	dev->flags &= ~HIFN_FLAG_OLD_KEY;
 
@@ -1981,15 +1969,11 @@  static int hifn_des3_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
 {
 	struct hifn_context *ctx = crypto_ablkcipher_ctx(cipher);
 	struct hifn_device *dev = ctx->dev;
-	u32 flags;
 	int err;
 
-	flags = crypto_ablkcipher_get_flags(cipher);
-	err = __des3_verify_key(&flags, key);
-	if (unlikely(err)) {
-		crypto_ablkcipher_set_flags(cipher, flags);
+	err = crypto_des3_ede_verify_key(crypto_ablkcipher_tfm(cipher), key);
+	if (unlikely(err))
 		return err;
-	}
 
 	dev->flags &= ~HIFN_FLAG_OLD_KEY;