Skip to content

Commit

Permalink
crypto: omap/des - switch to new verification routines
Browse files Browse the repository at this point in the history
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Ard Biesheuvel authored and herbertx committed Aug 22, 2019
1 parent d4b90db commit 304daa4
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions drivers/crypto/omap-des.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <linux/crypto.h>
#include <linux/interrupt.h>
#include <crypto/scatterwalk.h>
#include <crypto/des.h>
#include <crypto/internal/des.h>
#include <crypto/algapi.h>
#include <crypto/engine.h>

Expand Down Expand Up @@ -650,20 +650,13 @@ static int omap_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
unsigned int keylen)
{
struct omap_des_ctx *ctx = crypto_ablkcipher_ctx(cipher);
struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
int err;

pr_debug("enter, keylen: %d\n", keylen);

/* Do we need to test against weak key? */
if (tfm->crt_flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS) {
u32 tmp[DES_EXPKEY_WORDS];
int ret = des_ekey(tmp, key);

if (!ret) {
tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
return -EINVAL;
}
}
err = verify_ablkcipher_des_key(cipher, key);
if (err)
return err;

memcpy(ctx->key, key, keylen);
ctx->keylen = keylen;
Expand All @@ -672,20 +665,16 @@ static int omap_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
}

static int omap_des3_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
unsigned int keylen)
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);
err = verify_ablkcipher_des3_key(cipher, key);
if (err)
return err;
}

memcpy(ctx->key, key, keylen);
ctx->keylen = keylen;
Expand Down

0 comments on commit 304daa4

Please sign in to comment.