diff options
author | Tero Kristo | 2017-05-24 09:35:24 +0200 |
---|---|---|
committer | Herbert Xu | 2017-06-10 06:04:14 +0200 |
commit | a636fdce55c6ad12b07436424ceffad1045714db (patch) | |
tree | 00923fcec0914633ec6c462778f085012892b1b1 /drivers/crypto/omap-des.c | |
parent | crypto: omap-aes - fix context handling for multiple cores (diff) | |
download | kernel-qcow2-linux-a636fdce55c6ad12b07436424ceffad1045714db.tar.gz kernel-qcow2-linux-a636fdce55c6ad12b07436424ceffad1045714db.tar.xz kernel-qcow2-linux-a636fdce55c6ad12b07436424ceffad1045714db.zip |
crypto: omap-des - add check for weak keys
OMAP DES crypto accelerator itself is unable to detect weak keys, so
add a specific call to the generic des driver to check the key strength
if requested.
Signed-off-by: Tero Kristo <t-kristo@ti.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/omap-des.c')
-rw-r--r-- | drivers/crypto/omap-des.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/drivers/crypto/omap-des.c b/drivers/crypto/omap-des.c index a6f65532fd16..0d68f77ea53a 100644 --- a/drivers/crypto/omap-des.c +++ b/drivers/crypto/omap-des.c @@ -699,16 +699,28 @@ static int omap_des_crypt(struct ablkcipher_request *req, unsigned long mode) /* ********************** ALG API ************************************ */ -static int omap_des_setkey(struct crypto_ablkcipher *tfm, const u8 *key, +static int omap_des_setkey(struct crypto_ablkcipher *cipher, const u8 *key, unsigned int keylen) { - struct omap_des_ctx *ctx = crypto_ablkcipher_ctx(tfm); + 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? */ + if (tfm->crt_flags & CRYPTO_TFM_REQ_WEAK_KEY) { + u32 tmp[DES_EXPKEY_WORDS]; + int ret = des_ekey(tmp, key); + + if (!ret) { + tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; + return -EINVAL; + } + } + memcpy(ctx->key, key, keylen); ctx->keylen = keylen; |