Commit f96c897c authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Herbert Xu

crypto: qce/des - switch to new verification routines

Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 0157fb26
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/types.h> #include <linux/types.h>
#include <crypto/aes.h> #include <crypto/aes.h>
#include <crypto/des.h> #include <crypto/internal/des.h>
#include <crypto/internal/skcipher.h> #include <crypto/internal/skcipher.h>
#include "cipher.h" #include "cipher.h"
...@@ -154,13 +154,11 @@ static int qce_ablkcipher_setkey(struct crypto_ablkcipher *ablk, const u8 *key, ...@@ -154,13 +154,11 @@ static int qce_ablkcipher_setkey(struct crypto_ablkcipher *ablk, const u8 *key,
{ {
struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablk); struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablk);
struct qce_cipher_ctx *ctx = crypto_tfm_ctx(tfm); struct qce_cipher_ctx *ctx = crypto_tfm_ctx(tfm);
unsigned long flags = to_cipher_tmpl(tfm)->alg_flags;
int ret; int ret;
if (!key || !keylen) if (!key || !keylen)
return -EINVAL; return -EINVAL;
if (IS_AES(flags)) {
switch (keylen) { switch (keylen) {
case AES_KEYSIZE_128: case AES_KEYSIZE_128:
case AES_KEYSIZE_256: case AES_KEYSIZE_256:
...@@ -168,14 +166,6 @@ static int qce_ablkcipher_setkey(struct crypto_ablkcipher *ablk, const u8 *key, ...@@ -168,14 +166,6 @@ static int qce_ablkcipher_setkey(struct crypto_ablkcipher *ablk, const u8 *key,
default: default:
goto fallback; goto fallback;
} }
} else if (IS_DES(flags)) {
u32 tmp[DES_EXPKEY_WORDS];
ret = des_ekey(tmp, key);
if (!ret && (crypto_ablkcipher_get_flags(ablk) &
CRYPTO_TFM_REQ_FORBID_WEAK_KEYS))
goto weakkey;
}
ctx->enc_keylen = keylen; ctx->enc_keylen = keylen;
memcpy(ctx->enc_key, key, keylen); memcpy(ctx->enc_key, key, keylen);
...@@ -185,24 +175,32 @@ static int qce_ablkcipher_setkey(struct crypto_ablkcipher *ablk, const u8 *key, ...@@ -185,24 +175,32 @@ static int qce_ablkcipher_setkey(struct crypto_ablkcipher *ablk, const u8 *key,
if (!ret) if (!ret)
ctx->enc_keylen = keylen; ctx->enc_keylen = keylen;
return ret; return ret;
weakkey: }
crypto_ablkcipher_set_flags(ablk, CRYPTO_TFM_RES_WEAK_KEY);
return -EINVAL; static int qce_des_setkey(struct crypto_ablkcipher *ablk, const u8 *key,
unsigned int keylen)
{
struct qce_cipher_ctx *ctx = crypto_ablkcipher_ctx(ablk);
int err;
err = verify_ablkcipher_des_key(ablk, key);
if (err)
return err;
ctx->enc_keylen = keylen;
memcpy(ctx->enc_key, key, keylen);
return 0;
} }
static int qce_des3_setkey(struct crypto_ablkcipher *ablk, const u8 *key, static int qce_des3_setkey(struct crypto_ablkcipher *ablk, const u8 *key,
unsigned int keylen) unsigned int keylen)
{ {
struct qce_cipher_ctx *ctx = crypto_ablkcipher_ctx(ablk); struct qce_cipher_ctx *ctx = crypto_ablkcipher_ctx(ablk);
u32 flags;
int err; int err;
flags = crypto_ablkcipher_get_flags(ablk); err = verify_ablkcipher_des3_key(ablk, key);
err = __des3_verify_key(&flags, key); if (err)
if (unlikely(err)) {
crypto_ablkcipher_set_flags(ablk, flags);
return err; return err;
}
ctx->enc_keylen = keylen; ctx->enc_keylen = keylen;
memcpy(ctx->enc_key, key, keylen); memcpy(ctx->enc_key, key, keylen);
...@@ -374,8 +372,9 @@ static int qce_ablkcipher_register_one(const struct qce_ablkcipher_def *def, ...@@ -374,8 +372,9 @@ static int qce_ablkcipher_register_one(const struct qce_ablkcipher_def *def,
alg->cra_ablkcipher.ivsize = def->ivsize; alg->cra_ablkcipher.ivsize = def->ivsize;
alg->cra_ablkcipher.min_keysize = def->min_keysize; alg->cra_ablkcipher.min_keysize = def->min_keysize;
alg->cra_ablkcipher.max_keysize = def->max_keysize; alg->cra_ablkcipher.max_keysize = def->max_keysize;
alg->cra_ablkcipher.setkey = IS_3DES(def->flags) ? alg->cra_ablkcipher.setkey = IS_3DES(def->flags) ? qce_des3_setkey :
qce_des3_setkey : qce_ablkcipher_setkey; IS_DES(def->flags) ? qce_des_setkey :
qce_ablkcipher_setkey;
alg->cra_ablkcipher.encrypt = qce_ablkcipher_encrypt; alg->cra_ablkcipher.encrypt = qce_ablkcipher_encrypt;
alg->cra_ablkcipher.decrypt = qce_ablkcipher_decrypt; alg->cra_ablkcipher.decrypt = qce_ablkcipher_decrypt;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment