crypto: sun4i-ss - Forbid 2-key 3DES in FIPS mode
authorHerbert Xu <herbert@gondor.apana.org.au>
Thu, 11 Apr 2019 08:51:19 +0000 (16:51 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 18 Apr 2019 14:15:01 +0000 (22:15 +0800)
This patch forbids the use of 2-key 3DES (K1 == K3) in FIPS mode.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Acked-by: Corentin Labbe <clabbe.montjoie@gmail.com>
Tested-by: Corentin Labbe <clabbe.montjoie@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/sunxi-ss/sun4i-ss-cipher.c

index 54fd714d53cae19edbd22315dbba6e7b8603f805..06df336488fbc3dd12cb73e2997411b9b6479dc5 100644 (file)
@@ -533,13 +533,12 @@ int sun4i_ss_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,
                         unsigned int keylen)
 {
        struct sun4i_tfm_ctx *op = crypto_skcipher_ctx(tfm);
-       struct sun4i_ss_ctx *ss = op->ss;
+       int err;
+
+       err = des3_verify_key(tfm, key);
+       if (unlikely(err))
+               return err;
 
-       if (unlikely(keylen != 3 * DES_KEY_SIZE)) {
-               dev_err(ss->dev, "Invalid keylen %u\n", keylen);
-               crypto_skcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
-               return -EINVAL;
-       }
        op->keylen = keylen;
        memcpy(op->key, key, keylen);
        return 0;